<?php

include_once("c_client.php");
class c_page_cab_client_personal_create extends c_page_cab_client
{
    public $h1='Добавление нового сотрудника' ;

    function block_main()
    { reboot_engine() ;
      $this->page_title() ;
      $this->panel_person_create() ;
    }

    function panel_person_create($options=array())
    {
      $rec=$options['rec'] ;
      //damp_array($rec) ;
      ?><div id="panel_personal_edit" <?if ($rec['_reffer']) echo 'reffer="'.$rec['_reffer'].'"'?>>
        <script src="<?echo _PATH_TO_EXT?>/jquery.autocomplete/jquery.autocomplete.js"></script>
        <link rel="stylesheet" type="text/css" href="<?echo _PATH_TO_EXT?>/jquery.autocomplete/styles.css" charset="utf-8">
        <form>
        <?if ($options['to_extlist']){?><input type="hidden" name="to_extlist" value="1"><?}?>
        <table id="panel_personal_edit" class="info">
         <?if ($GLOBALS['LS_person_use_propusk']){?><tr><td>Номер пропуска:</td><td><input type="text" name="propusk" id="propusk" is_checked="aspmo/check_propusk_to_unique" data-required value="<?echo addslashes($rec['propusk'])?>"> <div class=status></div></td></tr><?}?>
         <?if ($GLOBALS['LS_person_use_driving']){?><tr><td>Номер водительского удостоверения:</td><td><input type="text" name="driving" id="driving" _is_checked="aspmo/check_propusk_to_unique" value="<?echo addslashes($rec['driving'])?>"> <div class=status></div></td></tr><?}?>
         <?if ($GLOBALS['LS_person_use_tab_number']){?><tr><td>Табельный номер:</td><td><input type="text" name="tab_number" id="tab_number" _is_checked="aspmo/check_propusk_to_unique"  value="<?echo addslashes($rec['tab_number'])?>"> <div class=status></div></td></tr><?}?>
         <tr><td>ФИО:</td><td><input type="text" name="name" class="big" data-required value="<?echo addslashes($rec['obj_name'])?>"></td></tr>
         <?if ($GLOBALS['LS_person_use_dr']){?><tr><td>Дата рождения:</td><td><input type="text" name="dr" data-required value="<?echo addslashes($rec['dr'])?>" mask="99.99.9999"></td></tr><?}?>
         <tr><td>Пол:</td><td><label><input type="radio" name="pol" value="0" <?if (!$rec['pol']) echo 'checked'?>> Мужской</label>
                              <label><input type="radio" name="pol" value="1" <?if ($rec['pol']) echo 'checked'?>> Женский</label>
                         </td>
         </tr>
         <?if ($GLOBALS['LS_person_use_adres']){?><tr><td>Адрес:</td><td><textarea name="adres"><?echo htmlspecialchars($rec['adres'])?></textarea></td></tr><?}?>
         <?if (isset(PERSONAL()->tree[$rec['parent']])) {$arr_orgs=PERSONAL()->tree[$rec['parent']]->get_arr_parent() ; $cnt_levels=_sizeof($arr_orgs) ; }
           if ($GLOBALS['LS_person_use_otdel']){?><tr><td>Подразделение:</td><td><div style="position:relative;">
                <?if ($cnt_levels<=3){?><input type="text"  _data-required id="otdel_name" name="otdel_name" class="big" value="<?echo $rec['_otdel_name']?>"><?}else echo $rec['_otdel_name'];?>
                   </div></td></tr><?}
           if ($GLOBALS['LS_person_use_working']){?><tr><td>Должность:</td><td><div style="position:relative;"><input type="text"  _data-required id="working_name" name="working_name" class="big" value="<?echo addslashes($rec['_work_name'])?>"></div></td></tr><?}?>
         <tr><td>Проход всегда:</td><td><div style="position:relative;"><input type="checkbox"  name="full_access"  value="1" <?if ($rec['full_access']) echo 'checked'?>></div></td></tr>
         <tr><td>Без ограничений по МО:</td><td><div style="position:relative;"><input type="hidden"  name="demo_access"  value="0"><input type="checkbox"  name="demo_access"  value="1" <?if ($rec['demo_access']) echo 'checked'?>></div></td></tr>
         <!--<tr><td>Начало смены:</td><td><input type="text" name="smena_s" value="<?echo addslashes($rec['smena_s'])?>" mask="99:99"></td></tr>-->
         <!--<tr><td>Окончание смены:</td><td><input type="text" name="smena_e" value="<?echo addslashes($rec['smena_e'])?>" mask="99:99"></td></tr>-->
         <!--<tr><td>После создания перейти</td>
                 <td><label><input type="radio" name="after_create" value="list" <?if ($_SESSION['after_personal_create']=='list') echo 'checked'?>> общему списку </label><br>
                     <label><input type="radio" name="after_create" value="card" <?if (!$_SESSION['after_personal_create']) echo 'checked'?>> мед.карточке </label><br>
                     <label><input type="radio" name="after_create" value="photo" <?if ($_SESSION['after_personal_create']=='photo') echo 'checked'?>> фотографированию </label>
                 </td></tr>-->
       </table>
       <div class="buttons">
           <input type="submit" class="v1 fa-check-circle-o" cmd="create_person" value="Создать" validate="form">
       </div>
       <script type="text/javascript">$j(document).ready(function ()
             {  //$j('input[name="propusk"]').on('change',function() { send_ajax_request({cmd:'aspmo/check_propusk_value',id:$j(this).attr('id'),value:$j(this).val()})})
                //$j('select#org_id').on('change',function()
                //{   $j('#otdel_name').autocomplete({ serviceUrl:'/ajax.php?cmd=jquery.autocomplete/autocomplette_otdel&org_id='+$j(this).val(),autoSubmit:true,width:333});
                //}) ;
                $j('#working_name').autocomplete({ serviceUrl:'/ajax.php?cmd=jquery.autocomplete/autocomplette_working',autoSubmit:true,width:333});
                $j('#otdel_name').autocomplete({ serviceUrl:'/ajax.php?cmd=jquery.autocomplete/autocomplette_otdel&org_id='+$j('select#org_id').val(),autoSubmit:true,width:333});
                //$j('select#org_id').bind('change') ;
                $j('input#propusk').ajax_check({content_class:'alert',position:{x: ['right', 'outside'],y:'top'}}) ;
                $j('input#propusk').inputmask("A{1,9}");  //static mask

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

    function panel_person_create2()
    {
      ?><div id="panel_personal_edit">
        <script src="<?echo _PATH_TO_EXT?>/jquery.autocomplete/jquery.autocomplete.js"></script>
        <link rel="stylesheet" type="text/css" href="<?echo _PATH_TO_EXT?>/jquery.autocomplete/styles.css" charset="utf-8">
        <form>
        <table id="panel_personal_edit" class="info">
         <tr><td>ФИО:</td><td><input type="text" name="person[name]" class="big" data-required value=""></td></tr>
         <tr><td>Номер водительского удостоверения:</td><td><input type="text" name="person[driving]" id="driving" _is_checked="aspmo/check_propusk_to_unique" value=""> <div class=status></div>
         <tr><td>Дата выдачи мед.справки:</td><td><input type="text" name="person[s_medspravka]" data-required value="" mask="99.99.9999"></td></tr>
         <tr><td>Дата рождения:</td><td><input type="text" name="person[dr]" data-required value="" mask="99.99.9999"></td></tr>
         <tr><td>Пол:</td><td><label><input type="radio" name="person[pol]" value="0" checked>Мужской</label>
                              <label><input type="radio" name="person[pol]" value="1">Женский</label>
                         </td>
         </tr>
         <tr><td>Автопарк:</td><td><select name="person[park_id]"  id="park_id"><?
               if (_sizeof(PERSONAL()->tree[$this->client->main_org_id]->list_obj)) foreach(PERSONAL()->tree[$this->client->main_org_id]->list_obj as $org_id) {?><option value="<?echo $org_id?>"><?echo PERSONAL()->tree[$org_id]->name?></option><?}

            ?></select></td></tr>

         <tr><td>Новый автопарк:</td><td><div style="position:relative;"><input type="text" id="person[new_park_name]" name="new_park_name" class="big" value=""></td></tr>
       </table>
       <div class="buttons">
           <input type="submit" class="v1" cmd="create_person" value="Добавить водителя" validate="form">
       </div>
       <script type="text/javascript">$j(document).ready(function ()
             {  //$j('input[name="propusk"]').on('change',function() { send_ajax_request({cmd:'aspmo/check_propusk_value',id:$j(this).attr('id'),value:$j(this).val()})})
                $j('select#org_id').on('change',function()
                {   $j('#otdel_name').autocomplete({ serviceUrl:'/ajax.php?cmd=jquery.autocomplete/autocomplette_otdel&org_id='+$j(this).val(),autoSubmit:true,width:333});
                }) ;
                $j('#working_name').autocomplete({ serviceUrl:'/ajax.php?cmd=jquery.autocomplete/autocomplette_working',autoSubmit:true,width:333});
                $j('#otdel_name').autocomplete({ serviceUrl:'/ajax.php?cmd=jquery.autocomplete/autocomplette_otdel&org_id='+$j('select#org_id').val(),autoSubmit:true,width:333});
                $j('select#org_id').bind('change') ;
                $j('input#propusk').ajax_check({content_class:'alert',position:{x: ['right', 'outside'],y:'top'}}) ;
                $j('input#propusk').inputmask("A{1,9}");  //static mask

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


    function CMD_create_person2()
     { //damp_array($_POST) ;
       $data['clss']=211 ;
       $data['parent']=$_POST['person']['park_id'] ;
       $data['pol']=$_POST['person']['pol'] ;
       $data['obj_name']=$_POST['person']['name'] ;
       $data['driving']=$_POST['person']['driving'] ;

       //$data['typ']=$_POST['person']['typ'] ;
       //$data['permit']=$_POST['person']['permit'] ;
       $id=adding_rec_to_table('obj_site_personals',$data) ;
       if ($id) {?><div class="green center">Водитель успешно добавлен</div><?
                 update_rec_in_table('obj_site_personals',array('propusk'=>$id),'pkey='.$id) ;
                 $recs[]=PERSONAL()->get_personal_by_id($id) ;
                 print_template($recs,'aspmo_personal/list_personal_table_img') ;
                }
       else     {?><div class="red center">Не удалоль добавить водителя</div><?}
     }

    function CMD_create_person()
     { $_POST['client_id']=$this->client->id ;
       $_POST['org_id']=$this->client->main_org_id;
       //damp_array($_POST) ;
       $reffer=PERSONAL()->personal_create($_POST) ;
       if ($reffer) echo '<div class="green">Сотрудник добавлен</div>' ;
       return ;
       if ($reffer)     { $rec_personal=PERSONAL()->get_personal_by_id($reffer) ;
                          switch($_POST['after_create'])
                           { case 'list': if (!$_POST['to_extlist']) {?><script type="text/javascript">document.location="/cab/client/personals/";</script><?}
                                          else                       {?><script type="text/javascript">document.location="/cab/client/persons_ext/";</script><?}
                                          $_SESSION['after_personal_create']='list' ;
                                          break ;
                             case 'card': ob_start() ;
                                          ?><script type="text/javascript">var newWin=window.open("<?echo $rec_personal['__href']?>",'win_second','status=1,dependent=1,width=1920,height=1000,left=1920,top=200, resizable=1, scrollbars=yes') ;newWin.focus() ;</script><?
                                          $_SESSION['after_personal_create']='' ;
                                          break ;
                             case 'photo': if ($rec_personal['pkey'])
                                            { ?><script type="text/javascript">document.location="/cab/client/person/<?$rec_personal['pkey']?>/";</script><?
                                              //include(_DIR_EXT.'/webcamera_capture/panel_photo_capture.php') ;
                                              //panel_photo_capture(array('title'=>'Фото сотрудника','save_cmd'=>'save_personal_photo','rec'=>$rec_personal)) ;
                                              /*$this->add_element('show_modal_window','HTML',array('width'=>'700px','after_close_func'=>'stop_video_capture')) ;*/
                                            }
                                           $_SESSION['after_personal_create']='photo' ;
                                           break ;
                           }
                        }
        //else $this->add_element('show_notife','Не удалось добавить нового сотрудника',array('type'=>'error')) ;

     }



}



?>
