<?php // этот модуль необходимо делать тольео для крупных проектов, для небольшых описание пунктов меню и файлов меню лучше делать в init.php
$__functions['init'][]      ='_event_admin_vars' ;
$__functions['boot_admin'][] ='_event_admin_boot' ;
//$__functions['alert'][]   ='_event_admin_alert' ;
$__functions['install'][]	='_event_install_modul' ;



function _event_admin_vars() //
{   //-----------------------------------------------------------------------------------------------------------------------------
	// описание переменных модуля
	//-----------------------------------------------------------------------------------------------------------------------------
    //$_SESSION['ARR_roll'][9]=array('obj_name'=>'Франчайзер',   'index_page'=>'/cab/bill/') ;

	//-----------------------------------------------------------------------------------------------------------------------------
	// описание классов модуля
	//-----------------------------------------------------------------------------------------------------------------------------


    //----------------------------------------------------------------------------------------------------

	$_SESSION['descr_clss'][222]['name']='Мероприятие' ;
    $_SESSION['descr_clss'][222]['table_code']='events' ;
    $_SESSION['descr_clss'][222]['parent']=0 ;
    $_SESSION['descr_clss'][222]['fields']['obj_name']=array('type'=>'varchar(255)') ; //  название файла документа
    $_SESSION['descr_clss'][222]['fields']['status']=array('type'=>'indx_select','array'=>'ARR_events_status') ; //  статус события
    $_SESSION['descr_clss'][222]['fields']['type']=array('type'=>'indx_select','array'=>'ARR_events_type') ; //  тип событмя
    $_SESSION['descr_clss'][222]['fields']['mode']=array('type'=>'indx_select','array'=>'ARR_events_mode') ; //  тип событмя
    $_SESSION['descr_clss'][222]['fields']['alert']=array('type'=>'indx_select','array'=>'ARR_events_alert') ; //  за сколько уведомлять
    $_SESSION['descr_clss'][222]['fields']['alert_from']=array('type'=>'timedata','default'=>0) ;  // до
    $_SESSION['descr_clss'][222]['fields']['alert_to']=array('type'=>'timedata','default'=>0) ;  // до
    $_SESSION['descr_clss'][222]['fields']['block_from']=array('type'=>'timedata','default'=>0) ;  // до
    $_SESSION['descr_clss'][222]['fields']['block_to']=array('type'=>'timedata','default'=>0) ;  // до
    $_SESSION['descr_clss'][222]['fields']['date_to']=array('type'=>'timedata','default'=>0) ;  // от
    $_SESSION['descr_clss'][222]['fields']['date_from']=array('type'=>'timedata','default'=>0) ;  // до
    $_SESSION['descr_clss'][222]['fields']['date_to']=array('type'=>'timedata','default'=>0) ;  // от
    $_SESSION['descr_clss'][222]['fields']['date_alert']=array('type'=>'timedata','default'=>0) ;  // от
    $_SESSION['descr_clss'][222]['fields']['ext_info']=array('type'=>'serialize') ;  // от
    $_SESSION['descr_clss'][222]['fields']['group_id']=array('type'=>'int(11)') ;  // от
    $_SESSION['descr_clss'][222]['fields']['doc_code']=array('type'=>'varchar(32)','index'=>'doc_code') ;  // от
    $_SESSION['descr_clss'][222]['fields']['ext']=array('type'=>'varchar(128)') ;  // от
    $_SESSION['descr_clss'][222]['fields']['dyn_pass']=array('type'=>'int(1)','index'=>'dyn_pass','default'=>0) ;  // признак добавления в event_pass по мере участия в мероприятии
    $_SESSION['descr_clss'][222]['fields']['rating']=array('type'=>'int(11)','index'=>'rating') ;  // рейтинг мероприятия, чем выше значение, тем важнее
    $_SESSION['descr_clss'][222]['fields']['viewer_name']=array('type'=>'varchar(32)');
    $_SESSION['descr_clss'][222]['fields']['info_filter']=array('type'=>'text');
    $_SESSION['descr_clss'][222]['fields']['account_id']=array('type'=>'int(11)') ; //  кто добавил


    $_SESSION['descr_clss'][222]['list']['field']['pkey']			=array('title'=>'pkey') ;
    $_SESSION['descr_clss'][222]['list']['field']['obj_name']			=array('title'=>'obj_name') ;
    $_SESSION['descr_clss'][222]['list']['field']['status']			=array('title'=>'status') ;
    $_SESSION['descr_clss'][222]['list']['field']['mode']			=array('title'=>'mode') ;
    $_SESSION['descr_clss'][222]['list']['field']['date_alert']			=array('title'=>'date_alert') ;
    $_SESSION['descr_clss'][222]['list']['field']['date_from']			=array('title'=>'date_from') ;
    $_SESSION['descr_clss'][222]['list']['field']['date_to']			=array('title'=>'date_to') ;
    $_SESSION['descr_clss'][222]['list']['field']['ext_info']			=array('title'=>'ext_info') ;

    $_SESSION['descr_clss'][222]['no_show_in_tree']=0 ; // не показывать объекты класса в дереве
    $_SESSION['descr_clss'][222]['icons']=_PATH_TO_BASED_CLSS_IMG.'/98.png' ;


    $_SESSION['descr_clss'][223]['name']='Участик мероприятия' ;
    $_SESSION['descr_clss'][223]['parent']=0 ;
    $_SESSION['descr_clss'][223]['fields']['event_id']=array('type'=>'int(11)','index'=>'event_id') ; //  источник документа
    $_SESSION['descr_clss'][223]['fields']['personal_id']=array('type'=>'int(11)','index'=>'personal_id') ; //  источник документа
    $_SESSION['descr_clss'][223]['fields']['account_id']=array('type'=>'int(11)','index'=>'account_id') ; //  кто добавил
    $_SESSION['descr_clss'][223]['fields']['group_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][223]['fields']['status']=array('type'=>'int(11)') ; //
    $_SESSION['descr_clss'][223]['fields']['fname']=array('type'=>'varchar(200)') ; //
    $_SESSION['descr_clss'][223]['fields']['time_print']=array('type'=>'int(11)') ; //
    $_SESSION['descr_clss'][223]['fields']['mess_id']=array('type'=>'int(11)','index'=>'mess_id') ; //
    $_SESSION['descr_clss'][223]['fields']['doc_id']=array('type'=>'int(11)','index'=>'doc_id') ; //
    $_SESSION['descr_clss'][223]['fields']['scan_id']=array('type'=>'int(11)','index'=>'scan_id') ; //
    $_SESSION['descr_clss'][223]['fields']['block_data']=array('type'=>'int(11)','default'=>0) ; //
    $_SESSION['descr_clss'][223]['fields']['close_data']=array('type'=>'int(11)','default'=>0) ; //
    $_SESSION['descr_clss'][223]['fields']['data_from']=array('type'=>'int(11)','default'=>0) ; //
    $_SESSION['descr_clss'][223]['fields']['data_to']=array('type'=>'int(11)','default'=>0) ; //
    $_SESSION['descr_clss'][223]['fields']['period']=array('type'=>'int(11)','default'=>0) ; //

    $_SESSION['descr_clss'][223]['fields']['result']=array('type'=>'int(11)') ; //
    $_SESSION['descr_clss'][223]['index']['event_id']='event_id' ;
    $_SESSION['descr_clss'][223]['index']['personal_id']='personal_id' ;
    $_SESSION['descr_clss'][223]['index']['account_id']='account_id' ;
    $_SESSION['descr_clss'][223]['index']['mess_id']='mess_id' ;
    $_SESSION['descr_clss'][223]['index']['doc_id']='doc_id' ;
    $_SESSION['descr_clss'][223]['index']['scan_id']='scan_id' ;

    $_SESSION['descr_clss'][224]['name']='Изменение статуса участника события' ;
    $_SESSION['descr_clss'][224]['parent']=0 ;
    $_SESSION['descr_clss'][224]['fields']['event_id']=array('type'=>'int(11)','index'=>'event_id') ; //  источник документа
    $_SESSION['descr_clss'][224]['fields']['personal_id']=array('type'=>'int(11)','index'=>'personal_id') ; //  источник документа
    $_SESSION['descr_clss'][224]['fields']['status_old']=array('type'=>'int(11)') ; //
    $_SESSION['descr_clss'][224]['fields']['status_new']=array('type'=>'int(11)') ; //
    $_SESSION['descr_clss'][224]['fields']['doc_id']=array('type'=>'int(11)','index'=>'scan_id') ; //
    $_SESSION['descr_clss'][224]['fields']['scan_id']=array('type'=>'int(11)','index'=>'scan_id') ; //
    $_SESSION['descr_clss'][224]['fields']['data_from']=array('type'=>'int(11)') ; //
    $_SESSION['descr_clss'][224]['fields']['data_to']=array('type'=>'int(11)') ; //
    $_SESSION['descr_clss'][224]['fields']['group_id']=array('type'=>'int(11)') ; //   место прохождения инструктажа
    $_SESSION['descr_clss'][224]['fields']['person_name']=array('type'=>'varchar(255)') ; //
    $_SESSION['descr_clss'][224]['fields']['person_org']=array('type'=>'varchar(255)') ; //
    $_SESSION['descr_clss'][224]['fields']['person_otdel']=array('type'=>'varchar(255)') ; //
    $_SESSION['descr_clss'][224]['fields']['person_working']=array('type'=>'varchar(255)') ; //
    $_SESSION['descr_clss'][224]['fields']['account_id']=array('type'=>'int(11)','index'=>'account_id') ; //  кто добавил

    $_SESSION['descr_clss'][225]['name']='Тема занятия' ;
    $_SESSION['descr_clss'][225]['parent']=0 ;
    $_SESSION['descr_clss'][225]['fields']['account_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][225]['fields']['length']=array('type'=>'int(11)') ; //  кто добавил

    $_SESSION['descr_clss'][226]['name']='Занятие' ;
    $_SESSION['descr_clss'][226]['parent']=0 ;
    $_SESSION['descr_clss'][226]['fields']['account_id']=array('type'=>'int(11)') ; //  кто создал
    $_SESSION['descr_clss'][226]['fields']['event_id']=array('type'=>'int(11)','index'=>'status') ; //  кто создал
    $_SESSION['descr_clss'][226]['fields']['theme_id']=array('type'=>'int(11)') ; //  кто создал
    $_SESSION['descr_clss'][226]['fields']['time_from']=array('type'=>'int(11)') ;  // время начала занятия
    $_SESSION['descr_clss'][226]['fields']['time_to']=array('type'=>'int(11)') ;    // время окончания занятия
    $_SESSION['descr_clss'][226]['fields']['status']=array('type'=>'int(11)','index'=>'status') ;    // статус занятия
    $_SESSION['descr_clss'][226]['fields']['group_id']=array('type'=>'int(11)','index'=>'group_id') ;    // статус занятия
    $_SESSION['descr_clss'][226]['fields']['guest_info']=array('type'=>'text') ;    // статус занятия

    $_SESSION['descr_clss'][227]['name']='Участник занятия' ;
    $_SESSION['descr_clss'][227]['parent']=0 ;
    $_SESSION['descr_clss'][227]['fields']['event_id']=array('type'=>'int(11)') ; //  кто создал
    $_SESSION['descr_clss'][227]['fields']['account_id']=array('type'=>'int(11)') ; //  кто создал
    $_SESSION['descr_clss'][227]['fields']['personal_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][227]['fields']['pass_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][227]['fields']['status']=array('type'=>'int(11)') ;    // статус занятия
    $_SESSION['descr_clss'][227]['fields']['sign_fname']=array('type'=>'varchar(32)') ;    // статус занятия
	$_SESSION['descr_clss'][227]['fields']['lession_org_id']=array('type'=>'int(11)') ;    // статус занятия
    $_SESSION['descr_clss'][227]['fields']['lession_otdel_id']=array('type'=>'int(11)') ;    // статус занятия
    $_SESSION['descr_clss'][227]['fields']['lession_work_id']=array('type'=>'int(11)') ;    // статус занятия


    $_SESSION['descr_clss'][228]['name']='Используемая тема занятия' ;
    $_SESSION['descr_clss'][228]['parent']=0 ;
    $_SESSION['descr_clss'][228]['fields']['event_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][228]['fields']['theme_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][228]['fields']['account_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][228]['fields']['status']=array('type'=>'int(11)') ; //  кто добавил

    $_SESSION['descr_clss'][236]['name']='Задание на генерацию пакета документов ПМО' ;
    $_SESSION['descr_clss'][236]['parent']=0 ;
    $_SESSION['descr_clss'][236]['fields']['event_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][236]['fields']['personal_ids']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][236]['fields']['account_id']=array('type'=>'int(11)') ; //  кто добавил
    $_SESSION['descr_clss'][236]['fields']['status']=array('type'=>'int(11)') ; //  кто добавил


	//----------------------------------------------------------------------------------------------------------------------
	// описание пунктов меню админа сайта
	//-----------------------------------------------------------------------------------------------------------------------
}

function _event_admin_boot($options)
{
    create_system_modul_obj('event',$options) ;

}


function _event_install_modul($DOT_root)
{
    ENGINE()->reg_cron('Обновление сотрудников мероприятий','EVENTS/CRON_events_update_personals_status','0 */2 * * *',array('enabled'=>1)) ;
	ENGINE()->reg_cron('Проверка дубликатов сообщений в инструктажах','EVENTS/check_dublikate_message','*/5 * * * *') ;

	SETUP()->reg_event_lister('personal_medic_group_change','EVENTS','on_event_personal_medic_group_change') ;         //
	SETUP()->reg_event_lister('lession_personal_sign','EVENTS','on_event_lession_personal_sign') ;         //
	SETUP()->reg_event_lister('save_doc_signature','EVENTS','on_event_save_doc_signature') ;         //
    SETUP()->reg_event_lister('server_check_access_success','EVENTS','on_event_server_check_access_success') ;         //
    SETUP()->reg_event_lister('server_examination_result_success','EVENTS','on_event_server_examination_result_success') ;         //
    SETUP()->reg_event_lister('get_active_mess_to_personal','EVENTS','on_event_get_active_mess_to_personal') ;         //


  //SETUP()->reg_report('Служебные отчеты','events/report_events.php') ;         //
      SETUP()->reg_report('Мероприятия','events_docs/report_personals_in_event_docs_put.php') ;         //
      SETUP()->reg_report('Мероприятия','events_docs/report_personals_in_event_docs_get.php') ;         //
      SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_lessions_jurnal1.php') ;         //
      SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_lessions_jurnal2.php') ;         //
      SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_lessions_jurnal3.php') ;         //
      SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_person_training.php') ;         //
      SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_training.php') ;         //
      SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_lessions_training.php') ;         //
	  SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_training.php') ;         //
	  SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_training2.php') ;         //
	  SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_training3.php') ;         //
	  SETUP()->reg_report('Мероприятия','esmo_magnit_instruction/report_training4.php') ;         //
	  SETUP()->reg_report('Мероприятия','events_meeting/report_meeting_lessions_full.php') ;         //
      SETUP()->reg_report('Мероприятия','events_meeting/report_meeting_persons_full.php') ;         //
      SETUP()->reg_report('Мероприятия','esmo_magnit_pmo/report_personals_pmo_completed.php') ;


	  REPORTS()->reg_doc('ПМО','esmo_magnit_pmo/doc_scan_napravlenie_ag.php','Скан направления по АГ') ;         //
      REPORTS()->reg_doc('ПМО','esmo_magnit_pmo/doc_napravlenie_pmo.php','Направление на ПМО') ;         //
      REPORTS()->reg_doc('ПМО','esmo_magnit_pmo/doc_zakluchenie.php','Заключение ПМО') ;         //
      REPORTS()->reg_doc('ПМО','esmo_magnit_pmo/doc_soglasie_pd1.php','Cогласие на обработку и передачу ПД третьей стороне') ;         //
      REPORTS()->reg_doc('ПМО','esmo_magnit_pmo/doc_soglasie_pd2.php','Cогласие на обработку ПД') ;         //
REPORTS()->reg_doc('ПМО','esmo_magnit_pmo/doc_history_mo.php','История МО сотрудника') ;         //


      REPORTS()->reg_doc('ОПО','events_opo/doc_napravlenie_opo.php','Направление на ПМО') ;         //
      REPORTS()->reg_doc('ОПО','events_opo/doc_zakluchenie_opo.php','Заключение ПМО') ;         //

      REPORTS()->reg_doc('Инструктажи','events/doc_lession_personal_status.php','Ведомость прохождения занятия') ;         //
      REPORTS()->reg_doc('Собрания','events_meeting/doc_meeting_lession_registr.php','Ведомость собрания') ;         //


    // График событий
    $pattern=array() ;
    $pattern['table_title']		        = 	'Мероприятия' ;
    $pattern['use_clss']		        = 	'222' ;
    $pattern['table_name']				= 	'obj_site_events_schedule' ;
    $pattern['def_recs'][]		        =	array ('parent'=>0,	'clss'=>1,	'enabled'=>1,	'indx'=>0,	'obj_name'=>'События') ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    $id=create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Темы занятий мероприятий' ;
    $pattern['use_clss']		        = 	'225' ;
    $pattern['table_name']				= 	'obj_site_events_themes' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$id;
    $id2=create_table_by_pattern($pattern) ;

    $pattern=array() ;
       $pattern['table_title']		        = 	'Методические материалы' ;
       $pattern['use_clss']		        = 	'5' ;
       $pattern['table_name']				= 	'obj_site_events_themes_files' ;
       $pattern['table_clss']				= 	101 ;
       $pattern['table_parent']			= 	$id2;
       create_table_by_pattern($pattern) ;


    // сканы
    $pattern=array() ;
    $pattern['table_title']		        = 	'Участие в событие' ;
    $pattern['use_clss']		        = 	'223' ;
    $pattern['table_name']				= 	'obj_site_events_pass' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    $id=create_table_by_pattern($pattern) ;

    // Отчеты
    $pattern=array() ;
    $pattern['table_title']		        = 	'Статусы событий' ;
    $pattern['use_clss']		        = 	'224' ;
    $pattern['table_name']				= 	'obj_site_events_pass_status' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$id;
    create_table_by_pattern($pattern) ;

    // Занятия
    $pattern=array() ;
    $pattern['table_title']		        = 	'Занятия' ;
    $pattern['use_clss']		        = 	'226' ;
    $pattern['table_name']				= 	'obj_site_lession' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    $id=create_table_by_pattern($pattern) ;

    //
    $pattern=array() ;
    $pattern['table_title']		        = 	'Темы занятий' ;
    $pattern['use_clss']		        = 	'228' ;
    $pattern['table_name']				= 	'obj_site_lession_themes' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$id;
    $id2=create_table_by_pattern($pattern) ;


    //
    $pattern=array() ;
    $pattern['table_title']		        = 	'Участие в занятиях' ;
    $pattern['use_clss']		        = 	'227' ;
    $pattern['table_name']				= 	'obj_site_lession_persons' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$id;
    create_table_by_pattern($pattern) ;

        $sql='create view view_event_personals as
                    select  t2.*,
                            t1.pkey as event_person_id,
                            t1.pkey as event_pass_id,
                            t1.tkey as event_person_tkey,
                            t1.tkey as event_pass_tkey,     
                            t1.group_id as event_group_id,
                            t1.event_id,
                            t1.personal_id,
                            t1.mess_id,
                            t1.result,
                            t1.fname as event_doc_fname,
                            t1.status as event_status,
                            t1.status as pass_status,
                            t1.status as event_pass_status,
                            t1.time_print as time_print,
                            t1.c_data as event_c_data,
                            t1.data_from as data_from,
                            t1.data_to as data_to,
                            t4.type as event_type,
                            t4.obj_name as event_name,
                            t4.status as event_status2,
                            t4.enabled as event_enabled
                            
                            
                            
                    from obj_site_events_pass t1
                    left join view_personals_org_group t2 on t2.pkey=t1.personal_id
                    left join obj_site_events_schedule t4 on t4.pkey=t1.event_id
                    where t2.clss=211 and t2.enabled=1 and t1.enabled=1
                    
                    ' ;
	  create_viewer('view_event_personals',$sql) ;

        $sql='create view view_event_personals_docs as
                    select  t2.*,
                            t1.pkey as event_person_id,
                            t1.pkey as event_pass_id,
                            t1.tkey as event_person_tkey,
                            t1.c_data as event_pass_c_data,
                            t1.event_id,
                            t1.personal_id,
                            t1.mess_id,
                            t1.doc_id,
                            t1.result,
                            t1.fname as event_doc_fname,
                            t1.group_id as event_group_id,
                            t1.status as event_status,
                            t1.scan_id,
                            t1.data_from as data_from,
                            t1.data_to as data_to,
                            t1.time_print as time_print,
                            t1.close_data as event_close_data,
                            t3.pkey as mess_doc_id,
                            t3.obj_name as mess_doc_name,
                            t3.c_data as doc_c_data,
                            t3.group_id as doc_group_id,
                            t4.type as event_type,
                            t5.view_from as mess_view_from,
                            t5.view_to as mess_view_to,
                            t5.block_from as mess_block_from,
                            t5.block_to as mess_block_to,
                            t5.auto_close as mess_auto_close,
                            t5.view_cnt as mess_view_cnt,
                            t5.view_data as mess_view_data,
                            t5.view_mesto as mess_view_mesto,
                            t5.status as mess_status,
                            t5.enabled as mess_enabled,
                            t5.close_data as mess_close_data,
                            t5.group_id as mess_group_id,
                            t6.obj_name as event_pass_group_name
                            
                            
                            
                            
                    from obj_site_events_pass t1
                    left join view_personals t2 on t2.pkey=t1.personal_id
                    left join obj_site_docs t3 on t3.pkey=t1.doc_id
                    left join obj_site_events_schedule t4 on t4.pkey=t1.event_id
                    left join obj_site_personal_mess t5 on t5.pkey=t1.mess_id
                    left join obj_site_account t6 on t6.pkey=t1.group_id
                    where t2.clss=211 and t2.enabled=1 
                    ' ;
        create_viewer('view_event_personals_docs',$sql) ;

        $sql='create view view_lession_personals as
                    select  t3.*,
                            t1.pkey as lession_person_pkey,
                            t1.tkey as lession_person_tkey,
                            t1.status as lession_person_status,
                            t1.lession_org_id,
                            t1.lession_otdel_id,
                            t1.lession_work_id,
                            t2.event_id as event_id,
                            t2.time_from as lession_time_from,
                            t2.group_id as lession_group_id,
                            t2.account_id as lession_account_id,
                            t1.parent as lession_id,
                            t1.status as lession_status,
                            t1.personal_id,
                            t1.sign_fname,
                            t5.ext as  event_ext
                            
                    from obj_site_lession_persons t1
                    left join obj_site_lession t2 on t2.pkey=t1.parent
                    left join view_personals t3 on t3.pkey=t1.personal_id
                    left join obj_site_events_schedule t5 on t5.pkey=t1.event_id
                    where t3.clss=211 
                    ' ;
		create_viewer('view_lession_personals',$sql) ;

        $sql='create view view_lessions as
                    select  t1.*,
                            t2.obj_name as group_name,
                            t3.obj_name as account_name,
                            t4.obj_name as doc1_name,
                            t4.pkey as doc1_id,
                            t4.sign_data as doc1_sign_data,
                            t5.obj_name as event_name
                    from obj_site_lession t1
                    left join obj_site_account t2 on t2.pkey=t1.group_id
                    left join obj_site_account t3 on t3.pkey=t1.account_id
                    left join obj_site_docs t4 on t4.lession_id=t1.pkey
                    left join obj_site_events_schedule t5 on t5.pkey=t1.event_id
                    ' ;
		create_viewer('view_lessions',$sql) ;

		// создаем вьюверы для участников по всем мероприятиям
    if (_sizeof($GLOBALS['install_options']) and $GLOBALS['install_options']['viewers']) EVENTS()->update_events_viewers() ;

	   $id_sect=SETUP_add_section_to_site_setting('Мероприятия') ;
	   SETUP_add_rec_to_site_setting($id_sect,"ID мероприятия выдачи документов по АГ",0,'LS_esmo_ag_event') ;
	   SETUP_add_rec_to_site_setting($id_sect,"ID мероприятия ПМО",0,'LS_esmo_PMO_event') ;
	   SETUP_add_rec_to_site_setting($id_sect,"ID мероприятия ОПО",0,'LS_esmo_OPO_event') ;
       SETUP_add_rec_to_site_setting($id_sect,"ПМО - должность уполномоченного представителя","",'LS_esmo_PMO_sign_person_work') ;
       SETUP_add_rec_to_site_setting($id_sect,"ПМО - ФИО уполномоченного представителя","",'LS_esmo_PMO_sign_person_name') ;

    //execSQL_update('update obj_site_events_pass t1 set t1.scan_id=(select t2.pkey from obj_site_scan t2 where t2.doc_id=t1.doc_id order by pkey desc limit 1) where t1.doc_id>0',2) ;
    //execSQL_update('update obj_site_events_pass set status=5 where scan_id>0',2) ;
    //$recs=execSQL_row('select event_pass_id,doc_group_id from view_event_personals_docs where doc_group_id>0 and (event_group_id is null or event_group_id=0)',1) ;
    //if (_sizeof($recs)) foreach($recs as $id=>$group_id) execSQL_update('update obj_site_events_pass set group_id='.$group_id.' where pkey='.$id,array('debug'=>0)) ;
    //$recs=execSQL('select event_pass_id,obj_name,event_status,mess_status from view_event_personals_docs where event_id='.$GLOBALS['LS_esmo_ag_event'] .' and mess_id>0 and event_status!=5 and event_status!=(mess_status+1)',1) ;
    //if (_sizeof($recs)) foreach($recs as $rec) execSQL_update('update obj_site_events_pass set status='.($rec['mess_status']+1).' where pkey='.$rec['event_pass_id'],array('debug'=>0)) ;



	if (_sizeof($GLOBALS['install_options']) and $GLOBALS['install_options']['db_updates'] and ESMO_STATUS!='SETUP_FIRST') EVENTS()->check_dublicate_event_napravlenie() ;

}




?>
