<?php
include_once("c_events_meeting_lession.php");
class c_page_cab_events_meeting_lession_sign extends c_page_cab_events_meeting_lession
{
  public $h1='Собрание - подтверждение участников' ;
  public $rec_event=array() ;
  public $rec_lession=array() ;

  function block_main()
  { $this->h1.=' - подтверждение участников собрания' ;
	$this->page_title() ;
    $this->panel_lession_info() ;
    $this->panel_lession_themes() ;
    if ($this->rec_lession['status']<5) $this->panel_select_personal() ;
    $this->panel_person_sign_info() ;
  }

  function panel_select_personal($options=array())
   {   if (!is_array($options['disabled_filter'])) $options['disabled_filter']=array() ;
       ?><div id="panel_filter">
               <form id="sky-form" class="sky-form">
                   <fieldset>
                      <div class="row">
                          <section class="col col-3">
                                 <label class="label">Пропуск</label>
                                 <label class="input"><input type="text" id=propusk  name="propusk" value=""></label>
                          </section>
                          <section class="col col-2">
                                 <label class="label">&nbsp;</label>
                                 <button class="button v2" event_id="<?echo $this->rec_event['pkey']?>" lession_id="<?echo $this->rec_lession['pkey']?>" cmd="events_meeting/seach_personal_to_sign" style="margin:0;float:none;">Поиск</button>
                          </section>
                          <section class="col col-4">
                                  <label class="label">&nbsp;</label>
                                 <?$all_is_sign=$this->panel_sign_stats() ; ?>
                          </section>
                          <section class="col col-3">
                              <?
                              $doc_rec=execSQL_van('select * from obj_site_docs where lession_id="'.$this->rec_lession['pkey'].'" order by pkey desc limit 1') ;
                              //echo '$doc_rec='.$doc_rec['pkey'].'<br>' ;
                              if ($this->rec_lession['status']==4 and !$doc_rec['pkey'])
                              {
                              ?>  <label class="label">&nbsp;</label>
                                  <input type="hidden" name="url_page_doc_view" value="/window/events_meeting/lession/<?echo $this->rec_lession['pkey']?>/report/">
                                  <input type="hidden" name="filter[lession_id]" value="<?echo $this->rec_lession['pkey']?>">
                                  <input type="hidden" name="obj_reffer" value="<?echo $this->rec_lession['_reffer']?>">
                                  <input type="hidden" name="event_id"   value="<?echo $this->rec_event['pkey']?>">
                                  <input type="hidden" name="source_pkey" value="<?echo $this->rec_event['pkey']?>">
                                  <input type="hidden" name="source_tkey" value="<?echo $this->rec_event['tkey']?>">
                                  <input type="hidden" name="source_obj" value="<?echo $this->rec_event['ext']?>">
                                  <input type="hidden" name="lession_id" value="<?echo $this->rec_lession['pkey']?>">
                                  <input type="hidden" name="report_seria" value="<?echo htmlspecialchars(MEMBER()->cur_group_name)?>">
                                  <input type="hidden" name="report_code" value="meeting_lession_registr">
                              <?

                                  if ($all_is_sign){?><button class="button v2" cmd="docs/doc_create">Сформировать ведомость</button><?}
                                else {?><button class="button v2" cmd="events_meeting/check_lession_sign_before_report_create" lession_id="<?echo $this->rec_lession['pkey']?>">Сформировать ведомость</button><?}?>
                              <?
                              }
                              else
                                  {?><button class="button v1" href="<? echo $this->rec_lession['__href'].'report/'?>"><?echo $doc_rec['obj_name']?></button><?}
                              ?>
                          </section>
                      </div>
                  </fieldset>
                </form>
         </div><br>
	     <script type="text/javascript">
	            $j(document).ready(function()
	              {   $j('#propusk').focus() ;
                      $j('body').everyTime(1000,'set_focus',function(){$j('#propusk').focus();})
	                  $j('#propusk').on('keyup',function()
	                                        {   console.log($j(this).val().length) ;
	                                            if ($j(this).val().length==14) send_ajax_request({cmd:"events_meeting/seach_personal_to_sign",
	                                                                                             event_id:<?echo $this->rec_event['pkey']?>,
	                                                                                             lession_id:<?echo $this->rec_lession['pkey']?>,
	                                                                                             propusk:$j(this).val()
	                                                                                            }) ;

	                                                                                             $j('#propusk').focus() ;

	                                        }) ;
	               });
	            </script>
       <?
   }

   function panel_sign_stats()
   {
       $stats=execSQL_row('select status,count(pkey) from obj_site_lession_persons where parent='.$this->rec_lession['pkey'].' group by status') ;
       $cnt_sign=($stats[4])? $stats[4]:0 ;
       echo '<div id="sign_stats">Подтвердило участие в собрании <br><strong>'.$cnt_sign.'</strong> сотрудников из <strong>'.array_sum($stats).'</strong></div>' ;
       $result=($cnt_sign>=array_sum($stats))? 1:0 ;
       ?><div class="alert" style="text-align:center">Для завершения собрания Вам необходимо сформировать и подписать ведомость собрания</div>
         <style type="text/css">
             div#sign_stats{text-align:center;}
             div#sign_stats strong{font-size:22px;}
         </style>
       <?
       return($result) ;

   }

   function panel_person_sign_info()
   {  ?><div id="panel_person_sign_info"><?
	  ?><br><br><br><h2>Ведомость участия сотрудников в собрании</h2><?
	  $list_recs=execSQL('select * from view_lession_personals where lession_id='.$this->rec_lession['pkey'].' order by obj_name') ;
	  ?><table class="list_personal_table_img basic fz_small full auto">
		          <colgroup><col id="c1"><col id="c2"><col id="c3"></colgroup>
		          <tr><th>ФИО, дата рождения</th>
		              <th>Организация, подразделение</th>
		              <th>Должность</th>
		              <th>Подтверждение участия сотрудника</th>
		          </tr>
		          <?
		          if (_sizeof($list_recs)) foreach($list_recs as $rec) if ($rec['pkey'])
		          {   ?><tr class=item>
		                  <td class="left"><?echo $rec['obj_name']?>
		                      <?  if ($rec['propusk']) echo '<br><span class="nowrap small">PASS: '.$rec['propusk'].'</span>' ;
		                          if ($rec['uid']) echo '<br><span class="nowrap small">UID: '.$rec['uid'].'</span>' ;
		                          if (!$rec['enabled'])echo '<br><br><span class="red bold">УВОЛЕН</span> ('.date('d.m.Y H:i',$rec['fired_data']).')' ;
		                          if ($rec['dr'])echo '<br>'.$rec['dr'] ;
		                      ?>
		                  </td>
		                  <td class="left"><?echo '<strong>'.$rec['_org_name'].'</strong><br><div class="small">'.$rec['_otdel_name'].'</div>'?></td>
		                  <td class="left"><?echo _IL('IL_works')->recs[$rec['working']]['obj_name'] ?></td>
		                  <td><?echo ($rec['lession_person_status']==4)? 'Да':'-' ?></td>

		              </tr><?
		          }
	?></table></div><?
   }
}



?>
