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



function _to_admin_vars() //
{  $_SESSION['descr_clss'][360]['name']='Проверка автомобиля' ;
   $_SESSION['descr_clss'][360]['parent']=0 ;
   $_SESSION['descr_clss'][360]['fields']['obj_name']=array('type'=>'text') ;
   $_SESSION['descr_clss'][360]['fields']['member_id']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['personal_id']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['personal_uuid']=array('type'=>'varchar(128)') ;
   $_SESSION['descr_clss'][360]['fields']['driving']=array('type'=>'varchar(32)') ;
   $_SESSION['descr_clss'][360]['fields']['permit']=array('type'=>'varchar(32)') ;
   $_SESSION['descr_clss'][360]['fields']['car_uuid']=array('type'=>'varchar(128)') ;
   $_SESSION['descr_clss'][360]['fields']['car_id']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['car_number']=array('type'=>'varchar(12)') ;
   $_SESSION['descr_clss'][360]['fields']['mo_id']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['terminal_id']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['mo_status']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['doctor_id']=array('type'=>'int(11)') ;  // доктор, подписаший МО
   $_SESSION['descr_clss'][360]['fields']['status']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['probeg']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['fuel']=array('type'=>'int(11)') ;
   $_SESSION['descr_clss'][360]['fields']['doc_name']=array('type'=>'varchar(255)') ;  // - на удаление
   $_SESSION['descr_clss'][360]['fields']['doc_id']=array('type'=>'int(11)') ;       // id документа
   $_SESSION['descr_clss'][360]['fields']['doc_number']=array('type'=>'int(11)') ;   // номер документа по общему списку
   $_SESSION['descr_clss'][360]['fields']['e_data']=array('type'=>'timedata') ;
   $_SESSION['descr_clss'][360]['fields']['_image_name']=array('type'=>'varchar(128)','default'=>'') ;

   $_SESSION['descr_clss'][360]['fields']['result']=array('type'=>'text') ;
   $_SESSION['descr_clss'][360]['fields']['access_type']=array('type'=>'text') ;
   $_SESSION['descr_clss'][360]['fields']['sign_tech']=array('type'=>'varchar(128)') ;
   $_SESSION['descr_clss'][360]['fields']['sign_driver']=array('type'=>'varchar(128)') ;
   $_SESSION['descr_clss'][360]['fields']['car_model']=array('type'=>'varchar(128)') ;

    $_SESSION['descr_clss'][360]['name']='Проверка автомобиля' ;
    $_SESSION['descr_clss'][360]['parent']=0 ;
    $_SESSION['descr_clss'][360]['fields']['obj_name']=array('type'=>'text') ;
    $_SESSION['descr_clss'][360]['fields']['member_id']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['personal_id']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['personal_uuid']=array('type'=>'varchar(128)') ;
    $_SESSION['descr_clss'][360]['fields']['driving']=array('type'=>'varchar(32)') ;
    $_SESSION['descr_clss'][360]['fields']['permit']=array('type'=>'varchar(32)') ;
    $_SESSION['descr_clss'][360]['fields']['car_uuid']=array('type'=>'varchar(128)') ;
    $_SESSION['descr_clss'][360]['fields']['car_id']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['car_number']=array('type'=>'varchar(12)') ;
    $_SESSION['descr_clss'][360]['fields']['mo_id']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['terminal_id']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['mo_status']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['doctor_id']=array('type'=>'int(11)') ;  // доктор, подписаший МО
    $_SESSION['descr_clss'][360]['fields']['status']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['probeg']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['fuel']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][360]['fields']['doc_name']=array('type'=>'varchar(255)') ;  // - на удаление
    $_SESSION['descr_clss'][360]['fields']['doc_id']=array('type'=>'int(11)') ;       // id документа
    $_SESSION['descr_clss'][360]['fields']['doc_number']=array('type'=>'int(11)') ;   // номер документа по общему списку
    $_SESSION['descr_clss'][360]['fields']['e_data']=array('type'=>'timedata') ;
    $_SESSION['descr_clss'][360]['fields']['_image_name']=array('type'=>'varchar(128)','default'=>'') ;

    $_SESSION['descr_clss'][360]['fields']['result']=array('type'=>'text') ;
    $_SESSION['descr_clss'][360]['fields']['access_type']=array('type'=>'text') ;
    $_SESSION['descr_clss'][360]['fields']['sign_tech']=array('type'=>'varchar(128)') ;
    $_SESSION['descr_clss'][360]['fields']['sign_driver']=array('type'=>'varchar(128)') ;
    $_SESSION['descr_clss'][360]['fields']['car_model']=array('type'=>'varchar(128)') ;

    $_SESSION['descr_clss'][360]['fields']['i1']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i2']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i3']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i4']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i5']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i6']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i7']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i8']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i9']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i10']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i11']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i12']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i13']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i14']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i15']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i16']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i17']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i18']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][360]['fields']['i19']=array('type'=>'int(1)') ;

    $_SESSION['descr_clss'][360]['list']['field']['pkey']=array('title'=>'ID') ;
    $_SESSION['descr_clss'][360]['list']['field']['c_data']=array('title'=>'Дата создания') ;
    $_SESSION['descr_clss'][360]['list']['field']['obj_name']=array('title'=>'ФИО водителя') ;
    $_SESSION['descr_clss'][360]['list']['field']['personal_uuid']=array('title'=>'UID водителя') ;
    $_SESSION['descr_clss'][360]['list']['field']['personal_id']=array('title'=>'ID водителя') ;
    $_SESSION['descr_clss'][360]['list']['field']['driving']=array('title'=>'Права') ;
    $_SESSION['descr_clss'][360]['list']['field']['permit']=array('title'=>'Разрешение') ;

    $_SESSION['descr_clss'][360]['list']['field']['mo_id']=array('title'=>'ID МО') ;
    $_SESSION['descr_clss'][360]['list']['field']['mo_status']=array('title'=>'Статус МО') ;
    $_SESSION['descr_clss'][360]['list']['field']['status']=array('title'=>'Статус путевого листа') ;

    $_SESSION['descr_clss'][360]['list']['field']['i1']=array('title'=>'Cветовые приборы') ;
    $_SESSION['descr_clss'][360]['list']['field']['i2']=array('title'=>'Тормоза') ;
    $_SESSION['descr_clss'][360]['list']['field']['i3']=array('title'=>'Фонарь Такси') ;
    $_SESSION['descr_clss'][360]['list']['field']['i4']=array('title'=>'Автомобиль чист') ;
    $_SESSION['descr_clss'][360]['list']['field']['i5']=array('title'=>'Нет царапин') ;
    $_SESSION['descr_clss'][360]['list']['field']['i6']=array('title'=>'Салон чист') ;
    $_SESSION['descr_clss'][360]['list']['field']['i7']=array('title'=>'Салон исправен') ;
    $_SESSION['descr_clss'][360]['list']['field']['i8']=array('title'=>'Нет запахов') ;
    $_SESSION['descr_clss'][360]['list']['field']['i9']=array('title'=>'Документы') ;
    $_SESSION['descr_clss'][360]['list']['field']['i10']=array('title'=>'Знак АО') ;
    $_SESSION['descr_clss'][360]['list']['field']['i11']=array('title'=>'Запаска') ;
    $_SESSION['descr_clss'][360]['list']['field']['i11']=array('title'=>'Огнетушитель') ;
    $_SESSION['descr_clss'][360]['list']['field']['i12']=array('title'=>'Инструменты') ;
    $_SESSION['descr_clss'][360]['list']['field']['i13']=array('title'=>'Платшет') ;
    $_SESSION['descr_clss'][360]['list']['field']['i14']=array('title'=>'Мобильник') ;
    $_SESSION['descr_clss'][360]['list']['field']['i15']=array('title'=>'Фото слева') ;
    $_SESSION['descr_clss'][360]['list']['field']['i16']=array('title'=>'Фото справа') ;
    $_SESSION['descr_clss'][360]['list']['field']['i17']=array('title'=>'Фото спереди') ;
    $_SESSION['descr_clss'][360]['list']['field']['i18']=array('title'=>'Фото сзади') ;
    $_SESSION['descr_clss'][360]['list']['field']['i19']=array('title'=>'Фото салон') ;



    $_SESSION['descr_clss'][361]['name']='Параметр проверки' ;
    $_SESSION['descr_clss'][361]['parent']=0 ;
    $_SESSION['descr_clss'][361]['fields']['obj_name']=array('type'=>'text') ;
    $_SESSION['descr_clss'][361]['fields']['type']=array('type'=>'int(11)') ;
    $_SESSION['descr_clss'][361]['fields']['notnull']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][361]['fields']['photo']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][361]['fields']['access']=array('type'=>'int(1)') ;
    $_SESSION['descr_clss'][361]['fields']['comment']=array('type'=>'text') ;
    $_SESSION['descr_clss'][361]['fields']['car_type']=array('type'=>'varchar(64)') ;
    $_SESSION['descr_clss'][361]['fields']['group_name']=array('type'=>'varchar(64)') ;

    $_SESSION['descr_clss'][363]['name']='Автомобиль' ;
    $_SESSION['descr_clss'][363]['parent']=0 ;
    $_SESSION['descr_clss'][363]['fields']['uid']=array('type'=>'varchar(128)') ;     // гос номер
    $_SESSION['descr_clss'][363]['fields']['obj_name']=array('type'=>'varchar(40)') ;     // гос номер
    $_SESSION['descr_clss'][363]['fields']['model']=array('type'=>'varchar(128)') ;     // гос номер
    $_SESSION['descr_clss'][363]['fields']['type']=array('type'=>'varchar(64)') ;     // класс авто
    $_SESSION['descr_clss'][363]['fields']['e_osago']=array('type'=>'timedata') ; // дата окончания ОСАГО
    $_SESSION['descr_clss'][363]['fields']['e_sts']=array('type'=>'timedata') ;//  Дата окончания СТС
    $_SESSION['descr_clss'][363]['fields']['e_gto']=array('type'=>'timedata') ;  //  Дата окончания тех. осмотра
    $_SESSION['descr_clss'][363]['fields']['permit']=array('type'=>'varchar(32)') ; // номер лицензии
    $_SESSION['descr_clss'][363]['fields']['year']=array('type'=>'int(11)') ; // номер лицензии
    $_SESSION['descr_clss'][363]['fields']['ext_info']=array('type'=>'serialize') ; // доп.инфо
    $_SESSION['descr_clss'][363]['fields']['upl_img']=array('type'=>'serialize') ; // доп.инфо

    $_SESSION['descr_clss'][363]['index']['uid']='uid' ;
    $_SESSION['descr_clss'][363]['index']['obj_name']='obj_name' ;
    $_SESSION['descr_clss'][363]['index']['type']='type' ;

    $_SESSION['descr_clss'][364]['name']='Связь водитель-автомобиль' ;
    $_SESSION['descr_clss'][364]['parent']=0 ;
    $_SESSION['descr_clss'][364]['fields']['personal_id']=array('type'=>'int(11)') ;     // водитель
    $_SESSION['descr_clss'][364]['fields']['car_id']=array('type'=>'int(11)') ;     // авто
    $_SESSION['descr_clss'][364]['fields']['time_from']=array('type'=>'timedata') ;     // начало действия связи
    $_SESSION['descr_clss'][364]['fields']['time_to']=array('type'=>'timedata') ;     // окончание действия связи
    $_SESSION['descr_clss'][364]['fields']['active']=array('type'=>'tinyint(1)','default'=>0) ;

    $_SESSION['descr_clss'][364]['index']['personal_id']='personal_id' ;
    $_SESSION['descr_clss'][364]['index']['car_id']='car_id' ;

}

function _to_admin_boot($options)
{
    create_system_modul_obj('to',$options) ;

}


function _to_install_modul($DOT_root)
{
    check_exists_dir('/public/to_sign') ;
    check_exists_dir('/public/to_photo') ;

    SETUP()->reg_report('ТО','rmt/report_cars.php') ;         //
    SETUP()->reg_report('ТО','rmt/report_relationcar.php') ;         //
    SETUP()->reg_report('ТО','rmt/report_to.php') ;         //

    SETUP()->reg_cron('Проверка активных связей водитель-автомобиль','TO/disable_relation','*/1 * * * *',array('enabled'=>1)) ;

	SETUP()->reg_rol(5,'Техник','/cab/rmt/',array('use_auch_as_smena'=>1,'report_template'=>'report_to_smena')) ;         //

	SETUP()->reg_report('ТО','rmt/report_to.php') ;         //

    $id_sect=SETUP_add_section_to_site_setting('Тех. осмотры') ;
    SETUP_add_rec_to_site_setting($id_sect,"Использовать разные группы параметров ТО для разных видов техники",0,'LS_TO_use_diff_TO_car_type',['el'=>'checkbox']) ;
    SETUP_add_rec_to_site_setting($id_sect,"Срок действия ТО,час",3,'LS_TO_time_enable',['descr'=>'Время в течении которого будет действительно ТО проведенное без водителя','human'=>'hour']) ;

    // рабочее место техника
    $pattern=array() ;
    $pattern['table_title']		        = 	'Техосмотры авто' ;
    $pattern['use_clss']		        = 	'1,360' ;
    //$pattern['def_recs'][]		        =	array ('parent'=>0,	'clss'=>1,	'enabled'=>1,	'indx'=>0,	'obj_name'=>'Аккаунты') ;
    $pattern['table_name']				= 	'obj_site_cars_to' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Параметры проверки' ;
    $pattern['use_clss']		        = 	'361' ;
    //$pattern['def_recs'][]		        =	array ('parent'=>0,	'clss'=>1,	'enabled'=>1,	'indx'=>0,	'obj_name'=>'Параметры проверки') ;
    //$pattern['def_recs'][]		        =	array ('parent'=>1,	'clss'=>1,	'enabled'=>1,	'indx'=>1,	'obj_name'=>'Въезд') ;
    //$pattern['def_recs'][]		        =	array ('parent'=>1,	'clss'=>1,	'enabled'=>1,	'indx'=>1,	'obj_name'=>'Выезд') ;
    $pattern['table_name']				= 	'obj_site_to_params' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

    // рабочее место техника - автомобили

    $pattern=array() ;
    $pattern['table_title']		        = 	'Автомобили' ;
    $pattern['use_clss']		        = 	'363' ;
    $pattern['table_name']				= 	'obj_site_personals_cars' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Связь водитель-автомобиль' ;
    $pattern['use_clss']		        = 	'364' ;
    $pattern['table_name']				= 	'personal_car_relations' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

    $sql='create view view_personals_cars as
                select  t1.*,
                        t2.obj_name as _org_name
                from obj_site_personals_cars t1
                    left join obj_site_personals t2 on t2.pkey=t1.parent' ;
    create_viewer('view_personals_cars',$sql) ;

    $sql='create view view_relationcars as
                select  t1.*,
                        t2.obj_name as _personal_name,
                        t3.obj_name as _personal_org_name,
                        t3.pkey as _personal_org_id,
                        t4.obj_name as _car_number,
                        t5.obj_name as _car_org_name,
                        t5.pkey as _car_org_id
                from personal_car_relations t1
                    left join obj_site_personals        t2 on t2.pkey=t1.personal_id
                    left join obj_site_personals        t3 on t3.pkey=t2.parent2
                    left join obj_site_personals_cars   t4 on t4.pkey=t1.car_id
                    left join obj_site_personals        t5 on t5.pkey=t4.parent' ;
    create_viewer('view_relationcars',$sql) ;
}




?>