<?php
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_tabel extends c_page
{
 public $h1='Табель' ;

 function tabs_config()
 { $this->tabs['/tabel/']='Табель' ;
   if (is_member_right('import_tabel')) $this->tabs['/tabel/upload/']='Загрузка' ;
   //if (is_member_right('edit_tabel')) $this->tabs['/tabel/editor/']='Редактор' ;
 }

 function block_main()
 {
   $this->page_title() ;
   if (!$GLOBALS['LS_setting_use_tabel']) {?><div class="alert">Внимание! Допуск к работе осуществляется без учета табеля</div><?}
   //$recs=select_db_recs(PERSONAL()->table_name,'clss=211 and enabled=1',array('order'=>'obj_name')) ;

   // получаем все дни табеля в заданном диапазоне
   $now=getdate() ;
   $from_time=mktime(0,0,0,$now['mon'],$now['mday'],$now['year']);
   $to_time=mktime(23,59,59,$now['mon'],$now['mday']+7,$now['year']);
   // получаем массив дат от $from_time до $to_time
   for($t=$from_time;$t<=$to_time;$t=mktime(0,0,0,$cur['mon'],$cur['mday']+1,$cur['year'])) { $arr_dates[$t]=date('d.m.Y',$t) ; $cur=getdate($t) ; }
   //damp_array($arr_dates) ;

   $recs_tabel=execSQL('select pkey,member_id,data,smena from '.PERSONAL()->table_tabel.' where data>='.$from_time.' and data<='.$to_time) ;
   $recs_tabel_my_member=group_by_field('member_id',$recs_tabel,'data') ; //damp_array($recs_tabel_my_member) ;
   $members_id=execSQL_line('select distinct(member_id) from '.PERSONAL()->table_tabel.' where data>='.$from_time.' and data<='.$to_time) ;


   if (_sizeof($members_id)) $recs_members=PERSONAL()->get_personal_list(array('id'=>$members_id)) ;

   //damp_array($recs_members) ;
   //print_template($list_members,'aspmo_personal/list_personal_table_img') ;
   //echo '$from_time='.date('d.m.Y H:i:s',$from_time).'<br>' ;
   //echo '$to_time='.date('d.m.Y H:i:s',$to_time).'<br>' ;
   if (_sizeof($recs_members))
        { ?><h2>Показаны 7 дней от текущего числа</h2>
            ?><table class=list_tabel>
            <tr><th>№ пропуска</th><th>ФИО</th><? if (_sizeof($arr_dates)) foreach($arr_dates as $date)  echo '<th>'.$date.'</th>' ;?></tr><? ;
            foreach($recs_members as $member_id=>$rec)
            { ?><tr class=item>
                    <td class="id"><?echo $rec['propusk']?></td>
                    <td class="name"><a href="/members/<?echo $rec['pkey']?>/"><?echo $rec['obj_name']?></a></td>
                    <? if (_sizeof($arr_dates)) foreach($arr_dates as $tm=>$date) echo '<td>'.$recs_tabel_my_member[$member_id][$tm]['smena'].'</td>' ;?>
                </tr><?
            }
            ?></table><?
        } else echo '<div class=alert>Табель не заполнен</div>' ;
 }

}



?>
