<?php
class report_personals_sign extends c_report
{
 var $title='Подписи сотрудников' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;

 function setting($options=array())
 {    $recs_org=PERSONAL()->get_list_personal_section(1,'',$this->usl_select_org) ; // получаем список организаций
      $recs_otdels=array() ;
      if ($this->filter['org_id'])
          {   $otdels_ids=PERSONAL()->get_org_otdel_ids($this->filter['org_id']) ;
              if (_sizeof($otdels_ids)) $recs_otdels=execSQL_row('select pkey,obj_name from '.PERSONAL()->table_personal.' where pkey in ('.implode(',',$otdels_ids).')') ;
          }
      //trace() ;

     list($arr_orgs_ids,$arr_otdel_ids,$arr_works_ids)=PERSONAL()->get_org_otdels_works_to_cur_account($this->filter) ;

      // внимание! для не администратора тут только сам оператор
      ?><div id="panel_filter">
             <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                  <fieldset>
                      <div class="row" id="person_info">
                           <section class="col col-2">
                               <label class="label">ФИО</label>
                               <label class="input">
                                    <input type="text" name="filter[name]" placeholder="" SetAutoComplete cmd="autocomplette_personal_name" value="<?echo $this->filter['name']?>">
                               </label>
                           </section>
                          <? $this->filter_section_select('org_id','Организация:',3,$arr_orgs_ids) ;
                             $this->filter_section_select('otdel_id','Подразделение:',3,$arr_otdel_ids) ;
                             //$this->filter_section_select_multiple('working_ids','Должность:',3,$arr_workd_ids) ;
                          ?>
                          <section class="col col-2">
                              <label class="label">Номер пропуска</label>
                              <label class="input">
                                  <input type="text" name="filter[propusk]" placeholder="" LANG="LAT" value="<?echo $this->filter['propusk']?>">
                              </label>
                          </section>
                        </div>
                  </fieldset>
                  <?$this->panel_button_apply();?>
              </form>
       </div><br>
     <?
  }

  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     $usl[]='clss=211' ;
     //$usl[]='model>1' ;
     if ($this->filter['name'])              $usl[]='obj_name like "'.$this->filter['name'].'%"' ;
     if ($this->filter['org_id'])            $usl[]='_org_id="'.$this->filter['org_id'].'"' ;
     if ($this->filter['otdel_id'])          $usl[]='_otdel_id in ('.$this->filter['otdel_id'].')' ;
     if ($this->filter['propusk'])          $usl[]='propusk="'.$this->filter['propusk'].'"' ;

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

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   //damp_array($this->filter) ;
   if ($this->filter['name'])                            $info['ФИО']='"'.$this->filter['name'].'"' ;
   if ($this->filter['org_id'])                          $info['организация']=PERSONAL()->get_name_by_id($this->filter['org_id']) ;
   if ($this->filter['otdel_id'])                        $info['отдел']=PERSONAL()->get_name_by_id($this->filter['otdel_id']) ;
   if ($this->filter['propusk'])                         $info['номер пропуска']='"'.$this->filter['propusk'].'"' ;
   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())
  { $options['debug']=0 ;
    $cnt=execSQL_value('select count(DISTINCT(pkey)) 
                        from view_personal_mo 
                        where '.$usl,$options);
    return($cnt) ;
  }

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:'' ;
    $order=($this->filter['order'])? ' order by '.$this->filter['order']:' order by last_mo_time desc' ;
    $options['debug']=0 ;
   /* $list_rec=execSQL('select * from mos.member_id,count(mos.pkey) as mo_count, if (pers.sign_id > 0, 1, 0) as has_standart_sign from obj_site_mo_session as mos '.
                      'inner join obj_site_mo_session_DTW as mos_DTW on mos_DTW.parent = mos.pkey '.
                      'inner join obj_site_personals as pers on pers.pkey = mos.member_id '.
                      'where '.$usl.' group by mos.member_id '.$order.$limit,$options);
    */
    $list_rec=execSQL('select * from view_personal_mo '.
                      'where '.$usl.$order.$limit,$options);

    return($list_rec) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;
    $arr_perosnals_ids=array() ; $mo_stats=array() ;
    if (_sizeof($list_recs)) foreach($list_recs as $rec) $arr_perosnals_ids[]=$rec['personal_id'] ;
    if (_sizeof($arr_perosnals_ids))
      //$mo_stats=execSQL_row('select member_id,count(pkey) from obj_site_mo_session where member_id in ('.implode(',',$arr_perosnals_ids).') group by member_id') ;
    ?><table class="basic full fz_small auto"><tr><th>Сотрудник</th><th>Возраст</th><th>Пол</th><th>Кол-во<br>мо</th><th>Эталон</th><th>Комментарий</th></tr>
                 <? foreach ($list_recs as $rec)
                   {?><tr>
                        <td class="left"><a href="/cab/personal/person/<?echo $rec['personal_id']?>/sv/" class="new_window"><?echo $rec['obj_name'];?></a></td>
                        <td><?echo $rec['age']?></td>
                        <td><?echo ($rec['pol'])? 'женский':'мужской';?></td>
                        <td><?echo $rec['cnt_mo'];?></td>
                        <td><?if($rec['sign_id'] > 0){?><div class="green">ДА</div><?}?></td>
                     <td><textarea class="v2" cmd="aspmo_pp/save_comment" event="change" no_send_form="1" personal_id="<?echo $rec['personal_id']?>"><?echo $rec['comment']?></textarea></td>
                 </tr>
             <?}?>
       </table><?
      //damp_array($rec) ;
  }





}

?>
