<?php
include_once(_DIR_EXT."/events_meeting/i_event_meeting.php");
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_events_meeting_card extends c_page
{
  public $h1='Карточка собраний' ;
  var $rec_event ;
  var $rec_lession ;
  var $obj_event ;
  var $rec_theme ;

 function select_obj_info()
 { if (_CUR_ID)
   { $this->rec_event=EVENTS()->get_event_by_id(_CUR_ID) ;
     if ($this->rec_event['pkey'])
     { $this->obj_event=EVENTS()->get_event_obj_by_ext($this->rec_event['ext']) ;
       $this->obj_event->rec_event=$this->rec_event ;
       //$this->h1=$this->obj_event->name.' - '.$this->h1 ;
         //if (MEMBER()->rol!=1 and _CUR_PAGE_DIR==$this->rec_event['__href']) redirect_301_to($this->rec_event['__href'].'new_lession/') ;
     }
     if (!$this->rec_event['pkey']) $this->result=404 ;
   } else $this->result=404 ;

 }

 function menu_config()
 { if ($this->no_event_menu) { parent::menu_config() ; return ; }
   // вкладки для сотрудника

 //and group_id in ('.ACCOUNTS()->tree[MEMBER()->cur_group_id]->get_list_child().')
     //$GLOBALS['debug_db']=2;
   // _usl -
   $arr_cnt=EVENTS()->get_event_personals_status($this->rec_event['pkey'],array('only_active'=>1)) ;
     //$GLOBALS['debug_db']=0;
   //damp_array($arr_cnt,1,-1);
   $arr_cnt[2]=$arr_cnt[2]+$arr_cnt[3] ; // Приглашены на собрание = Пришлашены + Уведомлены
   $arr_cnt[6]=$arr_cnt[4]+$arr_cnt[5]+$arr_cnt[6]; // Прибыли на собрание = Прибыл + Проходит + Прочитано

   // проверяем статус последнего открытого собрания текущего пользвателя
   $last_lession=execSQL_van('select pkey,status,doc1_id from view_lessions where clss=226 and event_id='.$this->rec_event['pkey'].' and account_id='.MEMBER()->id.' order by pkey desc limit 1') ;
   if (   ($last_lession['status']==4 and $last_lession['doc1_id'])   // темы прочитаны и сформирована ведомость
       or  $last_lession['status']==5                                // занятие завершено
       or  $last_lession['status']==6                                // занятие отменено
      )  $last_lession=array() ;


   if ($this->rec_event['pkey'] and $this->rec_event['enabled'])
      { $this->menu[$this->rec_event['__href']]='Карточка собраний' ;
        $this->menu[$this->rec_event['__href'].'edit/step1/']=array('title'=>'Редактировать') ;
        //$this->menu[$this->rec_event['__href'].'edit/step3/']=array('title'=>'Темы занятий') ;
        if (!$last_lession['pkey']) $this->menu[$this->rec_event['__href'].'new_lession/']='Новое собрание' ;
        else
        {   switch($last_lession['status'])
            { case 1:  $url='/cab/events_meeting/lession/'.$last_lession['pkey'].'/register/' ; break ;
              case 4:  $url='/cab/events_meeting/lession/'.$last_lession['pkey'].'/sign/' ; break ;
              default : $url='/cab/events_meeting/lession/'.$last_lession['pkey'].'/' ; ;
            }
            $this->menu[$url]='Cобрание № '.$last_lession['pkey'] ;
        }

        $this->menu[$this->rec_event['__href'].'lessions/']=array('title'=>'Отчет по собраниям') ;
        $this->menu[$this->rec_event['__href'].'report/']=array('title'=>'Отчет по сотрудникам') ;

        //$this->menu[$this->rec_event['__href'].'new_lession/']=array('title'=>'Новое занятие','id'=>'show_window_monitor') ;
        //if ($this->rec_lession['status']==0 or $this->rec_lession['status']==1) $this->menu['/cab/events_meeting/lession/'.$this->rec_lession['pkey'].'/register/']=array('title'=>'Регистрация участников') ;
        //if ($this->rec_lession['status']==2 or $this->rec_lession['status']==3) $this->menu['/cab/events_meeting/lession/'.$this->rec_lession['pkey'].'/']=array('title'=>'Ход собрания') ;
        //if ($this->rec_lession['status']==4) $this->menu['/cab/events_meeting/lession/'.$this->rec_lession['pkey'].'/sign/']=array('title'=>'Завершение собрания') ;
        //if ($this->rec_lession['status']==5) $this->menu['/cab/events_meeting/lession/'.$this->rec_lession['pkey'].'/']=array('title'=>'Ход собрания') ;

        //$this->menu[$this->rec_event['__href'].'personals/free/']=array('title'=>'Подлежат собранию','info_value'=>(($arr_cnt[1])? '<span>'.$arr_cnt[1].'</span>':'')) ;
        //if ($this->obj_event->allow_send_invite) $this->menu[$this->rec_event['__href'].'personals/select/']=array('title'=>'Приглашены на собрание','info_value'=>(($arr_cnt[2])? '<span>'.$arr_cnt[2].'</span>':'')) ;
        //$this->menu[$this->rec_event['__href'].'personals/process/']=array('title'=>'Прибыли на собрание','info_value'=>(($arr_cnt[6])? '<span>'.$arr_cnt[6].'</span>':'')) ;
        //$this->menu[$this->rec_event['__href'].'personals/сompleted/']=array('title'=>'Прослушали собрание','info_value'=>(($arr_cnt[7])? '<span>'.$arr_cnt[7].'</span>':'')) ;
        //$this->menu[$this->rec_event['__href'].'personals/']='Все участники' ;

        //$this->menu['/cab/events_meeting/lession/'.$this->rec_lession['pkey'].'/report/']='Ведомость собрания' ;
        //$this->menu[$this->rec_event['__href'].'log/']='История' ;
        $this->menu[$this->rec_event['__href'].'db/']='Исходные данные' ;
        $this->page_type='window' ;
      }
   elseif ($this->rec_event['pkey'])
      { $this->menu[$this->rec_event['__href'].'edit/step1/']='Параметры собрания' ;
        $this->page_type='window' ;
      }
   else parent::menu_config() ;
 }

    function second_menu_config()
   { $this->second_menu[$this->rec_event['__href']]=array('title'=>'Карточка собраний') ;
     //$this->second_menu[$this->rec_event['__href'].'edit/step1/']=array('title'=>'Редактировать') ;
     $this->second_menu[$this->rec_event['__href'].'log/']='История' ;
     //$this->second_menu[$this->rec_event['__href'].'db/']='Исходные данные' ;
     //$this->second_menu[$this->rec_event['__href'].'check/']='Проверки' ;
   }

 function block_main()
 {
   $this->page_title() ;
   $this->panel_events_themes() ;
   ?><br><?
   $this->panel_stats_by_org() ;
 }

 function panel_stats_by_org()
 { ?><h2>Статистика прохождения по организациям:</h2><?
   include_once(_DIR_EXT.'/events_meeting/report_meeting_info_by_orgs.php') ;
   $report_obj=new report_meeting_info_by_orgs() ;
   $report_obj->event_id=$this->rec_event['pkey'] ;
   $report_obj->filter['group_id']=MEMBER()->cur_group_id ;
   //$report_obj->setting() ;
   $report_obj->view() ;
 }

  function panel_events_themes()
  { ?><div id="panel_events_themes"><h2><?echo $this->obj_event->card_theme_title?>:</h2><?
      $recs_docs_by_themes=array() ;
      $recs_themes=execSQL('select * from obj_site_events_themes where parent='.$this->rec_event['pkey'].' and clss=225 order by indx') ;
      if (_sizeof($recs_themes))
       { $recs_docs=execSQL('select pkey,parent,obj_name,file_name from obj_site_events_themes_files where parent in ('.implode(',',array_keys($recs_themes)).')',0,1) ;
         $recs_docs_by_themes=group_by_field('parent',$recs_docs) ;
       }

       ?><table class="basic fz_small full auto"><tr class="head"><th>№</th><th>Наименование</th><th>Методические материалы</th></tr><?
           if (_sizeof($recs_themes)) foreach($recs_themes as $rec)
           { ?><tr>
                 <td style="width:10%;" class="indx center"><?echo $rec['indx']?></td>
                 <td style="width:35%;" class="left"><?echo $rec['obj_name']?></td>
                 <td style="width:20%;text-align:left;"><?
                 if (_sizeof($recs_docs_by_themes[$rec['pkey']]))
                 {  ?><ul><?
                    foreach($recs_docs_by_themes[$rec['pkey']] as $rec_doc) {?><li><a href="<?echo _MAIN_PROTOCOL._MAIN_DOMAIN?>/public/instruktions_docs/<?echo $rec_doc['file_name']?>" class="new_window"><?echo $rec_doc['obj_name']?></a></li><?}
                    ?></ul><?
                 }
                 ?></td>
               </tr>
             <?
           }
           ?>
            </table>
            <style type="text/css">
               table.basic td.indx{text-align:center;}
               table.basic td.indx:hover i{display:inline;cursor:pointer;}
               table.basic ul{margin:0 0 0 20px;;padding:0;}
               table.basic ul li{padding:0;margin:0;}
            </style>
            </div>
           <?
  }
}



?>
