<?php
class report_mo2 extends c_report
{
 var $title='Отчет по МО' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;

  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter) ;
     $usl=array() ;
     $usl[]=1 ;
     if ($this->filter['name'])              $usl[]='member_name like "'.$this->filter['name'].'%"' ;
     if ($this->filter['org_id'])            {  $otdels_ids=PERSONAL()->get_org_otdel_ids($this->filter['org_id']) ; if (_sizeof($otdels_ids)) $usl[]='parent in ('.implode(',',$otdels_ids).')' ;}
     if ($this->filter['otdel_id'])          $usl[]='parent='.$this->filter['otdel_id'] ;
     if ($this->filter['propusk'])           $usl[]='propusk='.$this->filter['propusk'] ;
     if ($this->filter['client_id'])        $usl[]='member_client_id='.$this->filter['client_id'] ;
     if ($this->filter['uid'])              $usl[]='member_uid="'.$this->filter['uid'].'"' ;
     if ($this->filter['data_from'])        $usl[]='c_data>='.strtotime($this->filter['data_from']) ;
     if ($this->filter['data_to'])          $usl[]='c_data<='.strtotime($this->filter['data_to']) ;
     if ($this->filter['mo_result'])            $usl[]='status='.$this->filter['mo_result'] ;
     if ($this->filter['dopusk'])            $usl[]='dopusk='.$this->filter['dopusk'] ;
     if ($this->filter['mo_type'])            $usl[]='mo_type='.$this->filter['mo_type'] ;


     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl) ;
     return($usl_res) ;
  }

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['name'])                            $info['ФИО']='"'.$this->filter['name'].'"' ;
   if ($this->filter['org_id']) {  $rec_obj=PERSONAL()->get_org_by_id($this->filter['org_id']) ; $info['организация']=$rec_obj['obj_name']  ; }
   if ($this->filter['otdel_id']){ $rec_obj=PERSONAL()->get_otdel_by_id($this->filter['otdel_id']) ; $info['отдел']=$rec_obj['obj_name']  ; }
   if ($this->filter['uid'])                             $info['UID сотрудника']='"'.$this->filter['uid'].'"' ;
   if ($this->filter['propusk'])                         $info['номер пропуска']='"'.$this->filter['propusk'].'"' ;
   if ($this->filter['mo_result'])                         $info['Результат МО']='"'.$_SESSION['ARR_status_sess'][$this->filter['mo_result']].'"' ;
   if ($this->filter['dopusk'])                         $info['Допуск']='"'.$_SESSION['ARR_status_dopusk'][$this->filter['dopusk']].'"' ;
   if ($this->filter['mo_type'])                         $info['Тип МО']='"'.$_SESSION['ARR_mo_type'][$this->filter['mo_type']].'"' ;
     if ($this->filter['data_from'])                     $info['дата от']='"'.$this->filter['data_from'].'"' ;
     if ($this->filter['data_to'])                     $info['дата до']='"'.$this->filter['data_to'].'"' ;
   if (_sizeof($info)) foreach($info as $title=>$value) $_str[]=$title.': <strong>'.$value.'</strong>' ;
   if (_sizeof($_str)) $title='<p class=center>'.implode(' ',$_str).'</p>' ;
   return $title ;
 }

  function get_cnt_items($usl,$options=array())
  { $cnt=execSQL_value('select count(pkey)
                        from  obj_site_mo_session
                        where '.$usl,$options) ;
    return($cnt) ;
  }

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:' limit 25000' ;
    $order=($this->filter['order'])? ' order by '.$this->filter['order']:' order by pkey desc' ;
    //echo $usl ;
 	$list_rec=execSQL('select *
                       from  obj_site_mo_session
                       where '.$usl.$order.$limit,$options) ;
    //if (_sizeof($list_rec)) foreach($list_rec as $id=>$rec) ESMO()->prepare_public_info_to_mo($list_rec[$id],$options) ;
    return($list_rec) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
        <colgroup><col id="c1"><col id="c2"><col id="c3"><col id="c4"></colgroup>
        <tr><th>Пропуск</th><th>Фото</th><th>ФИО</th><th>Дата рождения</th><th>Возраст</th><th>Организация</th><th>Подразделение</th><th>Должность</th></tr><? ;
        if (_sizeof($list_recs)) foreach($list_recs as $rec)
        { ?><tr class=item>
                <td class="id"><?echo $rec['propusk']?><?if ($rec['demo_access']){?><div class="demo_access" title="Сотрудник может проходить неограниченное число МО"></div><?}?></td>
                <td class="img"><a  href="<?echo $rec['__href']?>" class="new_window" target="_blank" title="win_second"><img src="<?echo img_clone($rec,'small')?>"></a></td>
                <td class="left"><a href="<?echo $rec['__href']?>" class="new_window" target="_blank" title="win_second"><?echo $rec['obj_name']?></a>
                    <br><?echo '<span class="nowrap small">'.$rec['uid'].'</span>'?>
                    <?if (!$rec['enabled'])echo '<br><br><span class="red bold">УВОЛЕН</span> ('.date('d.m.Y H:i',$rec['fired_data']).')'?>

                </td>
                <td class="dr"><?echo $rec['dr']?></td>
                <td class="age"><?echo $rec['age']?></td>
                <td class="left"><?echo $rec['_org_name']?></td>
                <td class="left"><?echo $rec['_otdel_name']?></td>
                <td class="left"><?echo _IL('IL_works')->recs[$rec['working']]['obj_name']?></td>
            </tr><?
        }
      ?></table><?
      //damp_array($rec) ;
  }

    function print_template_XML($list_recs,$options=array())
       { if (_sizeof($list_recs)) foreach($list_recs as $rec)
         {   $item=add_element($this->xml_doc,$this->xml,'item','',array('id'=>$rec['pkey'])) ;
             foreach($rec as $fname=>$fvalue) add_element($this->xml_doc,$item,$fname,$fvalue) ;
         }
       }

    function print_template_JSON($list_recs,$options=array())
    { $text_json_out=json_encode($list_recs) ;
      echo $text_json_out ;
    }

}

?>
