<?php
include_once(_DIR_TO_CLASS."/c_page.php");
class c_page_cab_client_orgs extends c_page
{
 public $h1='Справочник организаций' ;
 public $rec_org=array() ;

 function select_obj_info()
 { if (_CUR_ID)
   { $this->rec_org=PERSONAL()->get_org_by_id(_CUR_ID,array('get_ext_info'=>1)) ;
     if (!$this->rec_org['pkey']) $this->result=404 ;
   }
   //damp_array($this->rec_org) ;
 }

    function get_cur_page_meta_tags()
    {
      if ($this->rec_org['pkey']) $this->h1='Карточка компании "'.$this->rec_org['obj_name'].'"' ;
    }
    
    function block_main()
    { //damp_array($_POST) ;
      $this->page_title() ;
      if ($this->rec_org['pkey']) $this->panel_card_org_view() ;
      else                        $this->panel_list_org() ;
    }

    function panel_card_org_view()
    {
      print_template($this->rec_org,'aspmo_personal/panel_org_edit') ;
    }

    function panel_list_org()
    {
      ?><div id="panel_org_list"><button class="v2 button_green" id="new_org" cmd="aspmo_personal/get_panel_create_org" org_id="new" client_id="<?echo MEMBER()->id?>">Добавить</button><?
      $list_org=execSQL('select * from obj_site_personals where clss=207 and enabled=1 and client_id='.MEMBER()->id.' order by obj_name') ;
      print_template($list_org,'aspmo_personal/list_org_full') ;
      ?></div><?
    }

    function CMD_save_org()
     { //damp_array($_FILES) ;
       //damp_array($_POST) ;
       $res=PERSONAL()->save_org($this->rec_org['pkey'],$_POST['org']) ;
       reboot_engine() ;

       if (_sizeof($_FILES))
        { $recs_files=conver_FILES_to_recs($_FILES['upload_file']) ;  //damp_array($recs_files) ;
          if (_sizeof($recs_files[0]))
            { if ($recs_files[0]['type']=='image/gif')
              { ?><h2>Загружаем изображение из файла "<?echo $recs_files[0]['name']?>"</h2><?
                include_once(_DIR_TO_ENGINE.'/admin/i_admin_system.php') ;
                execSQL_update('delete from obj_site_personals_image where parent='.$this->rec_org['pkey'].' and alt="stamp"') ;
                $res_img=obj_upload_image($this->rec_org['_reffer'],$recs_files[0],array('view_upload'=>1,'img_alt'=>'stamp')) ;
                //damp_array($res_img) ;
                $res_img=array('type'=>'success','no_default_panel'=>1) ;
              }
              else $res_img=array('type'=>'error','code'=>'failed_type','text'=>'Неверный тип файла. Загрузите файл в формате GIF.') ;
            }
          //else $res_img=array('type'=>'error','code'=>'not_uploaded_file','text'=>'Не был выбран файл') ;
          if ($res_img['type']=='error') echo '<div class="alert">'.$res_img['text'].'</div>' ;
        }
        //else $res_img=array('type'=>'error','code'=>'not_uploaded_file','text'=>'Не был выбран файл') ;

       //damp_array($_FILES) ;
       if (!$res) echo '<div class="red">Изменений не обнаружено</div>' ;
       else { echo '<div class="green">Данные сохранены</div>' ;
              $this->rec_org=PERSONAL()->get_org_by_id($this->rec_org['pkey']) ;
            }
     }

}



?>
