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



function _docs_admin_vars() //
{   //-----------------------------------------------------------------------------------------------------------------------------
	// описание переменных модуля
	//-----------------------------------------------------------------------------------------------------------------------------

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


    //-----------------------------------------------------------------------------------------------------
    $_SESSION['descr_clss'][215]['name']='Документ' ;
    $_SESSION['descr_clss'][215]['table_code']='docs' ;
    $_SESSION['descr_clss'][215]['parent']=0 ;
    $_SESSION['descr_clss'][215]['fields']['doc_name']=array('type'=>'varchar(255)') ; //  название файла документа
    $_SESSION['descr_clss'][215]['fields']['doc_dir']=array('type'=>'varchar(255)') ; //  название файла документа
    $_SESSION['descr_clss'][215]['fields']['obj_reffer']=array('type'=>'any_object') ; //  источник документа
    $_SESSION['descr_clss'][215]['fields']['member_id']=array('type'=>'int(11)') ; //  автор документа
    $_SESSION['descr_clss'][215]['fields']['event_id']=array('type'=>'int(11)','default'=>0) ; // объект документа
    $_SESSION['descr_clss'][215]['fields']['lession_id']=array('type'=>'int(11)','default'=>0,'index'=>'lession_id') ; // объект документа
    $_SESSION['descr_clss'][215]['fields']['mo_id']=array('type'=>'int(11)','default'=>0) ; // объект документа
    $_SESSION['descr_clss'][215]['fields']['personal_id']=array('type'=>'int(11)','default'=>0) ; // объект документа
    $_SESSION['descr_clss'][215]['fields']['group_id']=array('type'=>'int(11)','default'=>0) ; // объект документа
    $_SESSION['descr_clss'][215]['fields']['sign_member']=array('type'=>'int(11)','default'=>0) ;  // кто подписал документ
    $_SESSION['descr_clss'][215]['fields']['sign']=array('type'=>'serialize') ;  // подпись документ
    $_SESSION['descr_clss'][215]['fields']['sign_data']=array('type'=>'timedata','default'=>0) ;  // дата подписания документа
    $_SESSION['descr_clss'][215]['fields']['sert_id']=array('type'=>'varchar(255)') ;  // id подписи ЕЦП
    $_SESSION['descr_clss'][215]['fields']['code']=array('type'=>'varchar(32)') ;  // тип документа
    $_SESSION['descr_clss'][215]['fields']['edit']=array('type'=>'int(1)') ;  // режим редактирования
    $_SESSION['descr_clss'][215]['fields']['report_code']=array('type'=>'varchar(255)','index'=>'report_code') ;
	$_SESSION['descr_clss'][215]['fields']['report_seria']=array('type'=>'varchar(255)') ;
    $_SESSION['descr_clss'][215]['fields']['report_filter']=array('type'=>'serialize') ;
    $_SESSION['descr_clss'][215]['fields']['content']=array('type'=>'serialize') ;
    $_SESSION['descr_clss'][215]['fields']['source_pkey']=array('type'=>'int(11)','default'=>0) ; //
    $_SESSION['descr_clss'][215]['fields']['source_tkey']=array('type'=>'int(11)','default'=>0) ; //
    $_SESSION['descr_clss'][215]['fields']['source_obj']=array('type'=>'varchar(100)','default'=>'') ; //
    // 0 - не добавлено в мероприятие, 1 - добавлено при подписи документа,
    // 2 - добавлено при ручном добавлении6 есть сообщение, 3 - сообшения нет, событие есть, 4 - сообщения нет, события нет, добавлено событие и сообщение
    // 5 - добавляено автоматически для 
    $_SESSION['descr_clss'][215]['fields']['event_pass_type']=array('type'=>'int(11)','default'=>0) ;

    $_SESSION['descr_clss'][215]['index']['mo_id']='mo_id' ;
    $_SESSION['descr_clss'][215]['index']['personal_id']='personal_id' ;
    $_SESSION['descr_clss'][215]['index']['group_id']='group_id' ;
    $_SESSION['descr_clss'][215]['index']['report_code']='report_code' ;

    $_SESSION['descr_clss'][215]['list']['field']['pkey']			=array('title'=>'pkey') ;
    $_SESSION['descr_clss'][215]['list']['field']['indx']			=array('title'=>'indx') ;
    $_SESSION['descr_clss'][215]['list']['field']['obj_name']			=array('title'=>'obj_name') ;
    $_SESSION['descr_clss'][215]['list']['field']['doc_name']			=array('title'=>'doc_name') ;
    $_SESSION['descr_clss'][215]['list']['field']['code']			=array('title'=>'Тип документа') ;
    $_SESSION['descr_clss'][215]['list']['field']['obj_reffer']			        =array('title'=>'obj_reffer','readonly'=>1) ;
    $_SESSION['descr_clss'][215]['list']['field']['member_id']			=array('title'=>'member_id','readonly'=>1) ;
    $_SESSION['descr_clss'][215]['list']['field']['personal_id']		=array('title'=>'personal_id','readonly'=>1) ;
    $_SESSION['descr_clss'][215]['list']['field']['sign_member']			=array('title'=>'sign_member','readonly'=>1) ;
    $_SESSION['descr_clss'][215]['list']['field']['sign']		    =array('title'=>'sign','readonly'=>1) ;
    $_SESSION['descr_clss'][215]['list']['field']['sign_data']		    =array('title'=>'sign_data','readonly'=>1) ;
    $_SESSION['descr_clss'][215]['list']['field']['sert_id']		    =array('title'=>'sert_id','readonly'=>1) ;

    $_SESSION['descr_clss'][215]['no_show_in_tree']=0 ; // не показывать объекты класса в дереве
    $_SESSION['descr_clss'][215]['icons']=_PATH_TO_BASED_CLSS_IMG.'/98.png' ;
    
    
    $_SESSION['descr_clss'][218]['name']='Скан документа' ;
    $_SESSION['descr_clss'][218]['table_code']='scan' ;
    $_SESSION['descr_clss'][218]['parent']=0 ;
    $_SESSION['descr_clss'][218]['fields']['source']=array('type'=>'varchar(128)') ; //  источник документа
    $_SESSION['descr_clss'][218]['fields']['doc_id']=array('type'=>'int(11)') ; //  источник документа
    $_SESSION['descr_clss'][218]['fields']['doc_type']=array('type'=>'varchar(100)') ; //  источник документа
    $_SESSION['descr_clss'][218]['fields']['event_id']=array('type'=>'int(11)','default'=>0) ; // объект документа
    $_SESSION['descr_clss'][218]['fields']['event_pass_id']=array('type'=>'int(11)','default'=>0) ; // объект документа
    $_SESSION['descr_clss'][218]['fields']['personal_id']=array('type'=>'int(11)') ; //  источник документа
    $_SESSION['descr_clss'][218]['fields']['account_upload']=array('type'=>'int(11)') ; //  кто загрузил документ
    $_SESSION['descr_clss'][218]['fields']['group_upload']=array('type'=>'int(11)') ; // ID АТП где было загружено направление
    $_SESSION['descr_clss'][218]['fields']['account_work']=array('type'=>'int(11)') ; //  кто работал со сканом
    $_SESSION['descr_clss'][218]['fields']['data_work']=array('type'=>'int(11)') ; //  кто работал со сканом
    $_SESSION['descr_clss'][218]['fields']['data_set']=array('type'=>'int(11)') ; //  кто работал со сканом
    $_SESSION['descr_clss'][218]['fields']['data_doc']=array('type'=>'int(11)','default'=>0) ; //  дата документа
    $_SESSION['descr_clss'][218]['fields']['status']=array('type'=>'int(11)','default'=>0) ;
    $_SESSION['descr_clss'][218]['fields']['diagnoz']=array('type'=>'varchar(128)','default'=>"") ;
    $_SESSION['descr_clss'][218]['fields']['comment']=array('type'=>'varchar(256)','default'=>"") ;
    $_SESSION['descr_clss'][218]['fields']['source_obj']=array('type'=>'varchar(100)','default'=>'') ; //
	  $_SESSION['descr_clss'][218]['fields']['report_code']=array('type'=>'varchar(255)') ; // дублируем сюда код документа
    $_SESSION['descr_clss'][218]['fields']['qrcode']=array('type'=>'varchar(100)','default'=>'') ; // QR-код на документе
    $_SESSION['descr_clss'][218]['fields']['error']=array('type'=>'text') ; // QR-код на документе
    $_SESSION['descr_clss'][218]['fields']['after_block_mo']=array('type'=>'int(11)','default'=>'0') ; // заблокировано ли МО после приема скана
    $_SESSION['descr_clss'][218]['index']['status']='status' ;
    $_SESSION['descr_clss'][218]['index']['personal_id']='personal_id' ;
    $_SESSION['descr_clss'][218]['index']['doc_id']='doc_id' ;
    $_SESSION['descr_clss'][218]['index']['doc_type']='doc_type' ;
    $_SESSION['descr_clss'][218]['index']['account_upload']='account_upload' ;
    $_SESSION['descr_clss'][218]['index']['account_work']='account_work' ;
    $_SESSION['descr_clss'][218]['index']['group_upload']='group_upload' ;


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

function _docs_admin_boot($options)
{
    create_system_modul_obj('docs',$options) ;

}


function _docs_install_modul($DOT_root)
{   SETUP()->reg_report('Документы','docs/report_docs.php') ;         //
    SETUP()->reg_report('Документы','scan/report_scan.php') ;         //

    // документы
    $pattern=array() ;
    $pattern['table_title']		        = 	'Документы' ;
    $pattern['use_clss']		        = 	'1,215' ;
    $pattern['def_recs'][]		        =	array ('parent'=>0,	'clss'=>1,	'enabled'=>1,	'indx'=>0,	'obj_name'=>'Документы') ;
    $pattern['table_name']				= 	'obj_site_docs' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;
    
    // сканы
    $pattern=array() ;
    $pattern['table_title']		        = 	'Сканы' ;
    $pattern['use_clss']		        = 	'1,218' ;
    $pattern['def_recs'][]		        =	array ('parent'=>0,	'clss'=>1,	'enabled'=>1,	'indx'=>0,	'obj_name'=>'Сканы') ;
    $pattern['table_name']				= 	'obj_site_scan' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

	$id_sect=SETUP_add_section_to_site_setting('Хранилище') ;
	SETUP_add_rec_to_site_setting($id_sect,"Имя директории для хранения документов",'docs','LS_storage_docs') ;


        $sql='create view view_docs as
                    select  t1.*,
                            t2.obj_name as _personal_name,
                            t2.dr as _personal_dr,
                            t2._org_name as _personal_org_name,  
                            t2.working as _personal_work_id,
                            t2.uid as _personal_uid,
                            t3.obj_name as _group_name, 
                            t4.obj_name as _account_name 
                    from obj_site_docs t1
                    left join view_personals t2 on t2.pkey=t1.personal_id
                    left join obj_site_account t3 on t3.pkey=t1.group_id
                    left join obj_site_account t4 on t4.pkey=t1.member_id
                    ' ;
	create_viewer('view_docs',$sql) ;


	$sql='create view view_docs_scan as
                    select  t1.*,
                            t2.obj_name as _personal_name,
                            t2.dr as _personal_dr,
                            t2._org_name as _personal_org_name,  
                            t2.working as _personal_work_id,
                            t3.obj_name as _group_name, 
                            t4.obj_name as _account_name,
                            t5.pkey as scan_id,t5.data_set as scan_data_set 
                    from obj_site_docs t1
                    left join view_personals t2 on t2.pkey=t1.personal_id
                    left join obj_site_account t3 on t3.pkey=t1.group_id
                    left join obj_site_account t4 on t4.pkey=t1.member_id
                    left join obj_site_scan t5 on t5.doc_id=t1.pkey and t5.status=3
                    ' ;
	create_viewer('view_docs_scan',$sql) ;

        $sql='create view view_scan as
                    select  t1.*,
                            t2.obj_name as _account_upload_name, 
                            t3.obj_name as _account_work_name, 
                            t4.obj_name as _group_upload_name, 
                            t5.c_data as _doc_data, 
                            t5.obj_name as _doc_name, 
                            t5.report_code as _doc_report_code,
                            t5.source_obj as _doc_source_obj,
                            t5._group_name as _doc_group_name, 
                            t5._account_name as _doc_account_name, 
                            t6.pkey as _personal_id, 
                            t6.obj_name as _personal_name, 
                            t6.dr as _personal_dr, 
                            t6._org_name as _personal_org_name, 
                            t6._otdel_name as _personal_otdel_name, 
                            t6.	working as _personal_work_id 
                    from obj_site_scan t1
                    left join obj_site_account t2 on t2.pkey=t1.account_upload
                    left join obj_site_account t3 on t3.pkey=t1.account_work
                    left join obj_site_account t4 on t4.pkey=t1.group_upload
                    left join view_docs t5 on t5.pkey=t1.doc_id
                    left join view_personals t6 on t6.pkey=t1.personal_id
                    ' ;
	create_viewer('view_scan',$sql) ;

    //$id_list=SETUP_add_list_to_site_list(1,'Тарифы МО','tarif') ;

    //$id_sect=SETUP_add_section_to_site_setting('Биллинг') ;
    //SETUP_add_rec_to_site_setting($id_sect,"Стоимость допуска для клиента",50,'LS_bill_price_client') ;
    //SETUP_add_rec_to_site_setting($id_sect,"Стоимость допуска для ЭСМО",5,'LS_pp_bill_price_esmo') ;

}




?>