<?php
include_once("c_client.php");
class c_page_cab_client_setting extends c_page_cab_client
{

public $h1='Карточка клиента' ;
   public $rec_org=array() ;

   function second_menu_config()
   { $this->second_menu['/cab/client/setting/']=array('title'=>'Карточка клиента','class'=>'fa fa-user-md') ;
     $this->second_menu['/cab/client/setting/rekvizit/']=array('title'=>'Реквизиты','class'=>'fa fa-user-md') ;
     $this->second_menu['/cab/client/setting/pass/']=array('title'=>'Смена пароля','class'=>'fa fa-user-md') ;
     $this->second_menu['/cab/client/setting/tech/']=array('title'=>'Дополнительные параметры') ;
     //$this->second_menu[$this->rec_member['__href'].'sert/']=array('title'=>'Сертификат','class'=>'fa fa-user-md') ;
   }

   function select_obj_info()
   {
      if (MEMBER()->rol!=6) { $this->access_denited=1 ; $this->access_denited_comment='Персонал #'._CUR_ID.' не является клиентом' ; }
      else
      { $client_org_id=execSQL_value('select pkey from obj_site_personals where clss=207 and enabled=1 and client_id='.MEMBER()->id.' order by c_data limit 1') ;
        if (!$client_org_id) $client_org_id=adding_rec_to_table('obj_site_personals',array('clss'=>207,'parent'=>1,'client_id'=>MEMBER()->id,'obj_name'=>MEMBER()->info['obj_name'])) ;
        $this->rec_org=PERSONAL()->get_org_by_id($client_org_id,array('get_ext_info'=>1)) ;
        if (MEMBER()->id==_CUR_ID) $this->allow_access_to_member=MEMBER()->id  ; // разрешаем доступ к странице для текущего пользователя
      }

   }


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

   function panel_member_edit()
   {  $rec=MEMBER()->info ;  //damp_array($this->rec_member) ; //damp_array($_SESSION['member']) ;
      if (!$rec['UID'])
      {  $rec['UID']=ENGINE()->generate_UID() ;
         MEMBER()->info['UID']=$rec['UID'] ;
         update_rec_in_table('obj_site_account',array('UID'=>$rec['UID']),'pkey='.$rec['pkey']) ;
      }
      ?><div id="panel_member_edit"><form enctype="multipart/form-data">
       <table class="info">
        <tr><td>Название организации:</td><td><?echo htmlspecialchars($rec['obj_name'])?></td></tr>
        <tr><td>Контактное лицо:</td><td><input data-required type="text" name="member_edit[contact_name]" class="big" value="<?echo htmlspecialchars($rec['contact_name'])?>"></td></tr>
        <tr><td>Контактный email:</td><td><input data-required type="text" name="member_edit[email]" class="big" value="<?echo htmlspecialchars($rec['email'])?>"></td></tr>
        <tr><td>Контактный телефон:</td><td><input data-required type="text" name="member_edit[phone]" class="big" value="<?echo htmlspecialchars($rec['phone'])?>"></td></tr>
        <tr><td>Логин:</td><td><?echo addslashes($rec['login'])?></td></tr>
        <tr><td>Пароль:</td><td><?echo ($rec['password'])? '********':''?></td></tr>
        <tr><td>UID:</td><td><?echo addslashes($rec['UID'])?></td></tr>
        <tr><td></td><td><input type="submit" class=v1 cmd="save_member" value="Сохранить" validate="form"></td></tr>
      </table>
      </form></div><?
     //damp_array(MEMBER());
   }

   function CMD_save_member()
    { $res=ACCOUNTS()->member_save(MEMBER()->id,$_POST['member_edit']) ;
      if (!$res) echo '<div class="red">Изменений не обнаружено</div>' ;
      else echo '<div class="green">Данные сохранены</div>' ;
      ACCOUNTS()->update_member_info(MEMBER()) ; // данные аккаунта будут заново прочитаны из базу
    }

}



?>