<?php
class report_med_directors extends c_report
{
 var $title='Справочник директоров медицинских организаций' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 var $allow_export_to_csv=1 ;
 var $group_ids=0 ;
 var $arr_status=[] ;

 function setting($options=array())
 {   ?><div id="panel_filter">
             <form id="sky-form" class="sky-form"><input type="hidden" name="filter_dir" value="<?echo _CUR_REPORT_DIR?>">
                  <fieldset>
                      <div class="row">
                          <? $this->filter_section_input_text('obj_name','ФИО:',2,array('_auto_complete'=>"autocomplette_personal_name")) ;
                             $this->filter_section_input_text('email','Email:',2) ;
                             $this->filter_section_input_text('phone','Телефон:',2) ;
                             $this->filter_section_input_text('inn','ИНН:',2) ;
                             $this->filter_section_input_text('address','Адрес:',2) ;
                          ?>
                        </div>
                  </fieldset>
                  <?$this->panel_buttons();?>
              </form>
       </div><br>
     <?
  }

  function create_usl_select_obj($_params=array(),&$options=array())
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     $usl[]='true' ;
     //damp_array($this->arr_status);
     if (_sizeof($this->arr_status)) $usl[]='status in ('.implode(',',$this->arr_status).')' ;
     //$usl[]='skd_id>0' ;
     if ($this->filter['obj_name'])          $usl[]='t1.obj_name like "%'.$this->filter['obj_name'].'%"' ;
     if ($this->filter['inn'])           $usl[]='t1.inn="'.$this->filter['inn'].'"' ;
     if ($this->filter['email'])           $usl[]='t1.email like "%'.$this->filter['email'].'%"' ;
     if ($this->filter['phone'])           $usl[]='t1.phone like "%'.$this->filter['phone'].'%"' ;
     if ($this->filter['address'])           $usl[]='t1.client_info like "%'.$this->filter['address'].'%"' ;
     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl,1,-1) ;
     return($usl_res) ;
  }

 function get_arr_info_filters()
 { $info=parent::get_arr_info_filters() ;
   if ($this->filter['obj_name'])                 $info['Наименование']=$this->filter['obj_name'] ;
   if ($this->filter['inn'])                 $info['ИНН']=$this->filter['inn'] ;
   if ($this->filter['email'])                 $info['Email']=$this->filter['email'] ;
   if ($this->filter['phone'])                 $info['Телефон']=$this->filter['phone'] ;
   if ($this->filter['address'])                 $info['Адрес']=$this->filter['address'] ;
   return $info ;
 }

  function get_cnt_items($usl,$options=array())
  {  $cnt=execSQL_value('select count(pkey)
                         from  catalog_med_orgs t1
                         where '.$usl,$options) ;
    return($cnt) ;
  }

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:'' ;
    $order=' order by t1.pkey desc' ;
    $list_recs=execSQL('select t1.* 
                       from  catalog_med_orgs t1
                       where '.$usl.$order.$limit,$options) ;
    //if (_sizeof($list_recs)) foreach($list_recs as $id=>$rec) PL()->prepare_public_info_to_client($list_recs[$id]) ;
    return($list_recs) ;
  }


// шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
   { $id=($options['id'])? 'id='.$options['id']:'' ;
     ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
         <tr><th>ID</th><th>ФИО</th><th>ИНН</th><th>СНИЛС</th><th>Должность</th><!--<th>Дата рождения</th><th>Место рождения</th><th>Пол</th>--><th>email</th><th>Телефон</th><th></th></tr><? ;
         if (_sizeof($list_recs)) foreach($list_recs as $rec)
         {   ?><tr class=item>
                 <td><?echo $rec['pkey']?></td>
                 <td><?echo $rec['director_name']?></td>
                 <td><?echo $rec['director_inn']?></td>
                 <td><?echo $rec['director_snils']?></td>
                 <td><?echo $rec['director_job_title']?></td>
                 <!--<td><?echo $rec['director_date_birth']?></td>-->
                 <!--<td><?echo $rec['director_place_birth']?></td>-->
                 <!--<td><?echo PERSONAL()->arr_pol_filter[$rec['director_gender']]?></td>-->
                 <td><?echo $rec['director_email']?></td>
                 <td><?echo $rec['director_phone']?></td>
                 <td>
                       <button class="v1" href="/cab/medical_organizations/card/<?echo $rec['pkey']?>/">Редактировать</button><br>
                       UID: <?echo $rec['director_uid']?>
                   </td>
             </tr><?
         }
       ?></table><?
   }

	function view_as_XML($options=array())
    { header("Content-type: text/xml;charset=UTF-8") ;
      $imp = new DOMImplementation; // Creates an instance of the DOMImplementation class
      $this->xml_doc = $imp->createDocument("",""); // Creates a DOMDocument instance
      $this->xml_doc->encoding = 'utf-8';
      $this->xml_doc->formatOutput = true;
      //$this->xml = add_element($this->xml_doc,$this->xml_doc,'xml','',array('version'=>"1.0",'encoding'=>"utf-8",'date'=>date('Y-m-d H:i'))) ;
      $this->xml = add_element($this->xml_doc,$this->xml_doc,'report_med_directors','',array('date'=>date('Y-m-d H:i'))) ;
      $this->show_list_items('','print_template_XML',$options) ;
      echo $this->xml_doc->saveXML() ;
    }

	function print_template_XML($list_recs,$options=array())
	{ if (_sizeof($list_recs)) foreach($list_recs as $rec)
		{   $item=add_element($this->xml_doc,$this->xml,'item','',array('uid'=>$rec['director_uid'])) ;
            add_element($this->xml_doc,$item,'org_uid',$rec['uid']) ;
            add_element($this->xml_doc,$item,'org_uid_1c',$rec['uid_1c']) ;
            add_element($this->xml_doc,$item,'name',$rec['director_name']) ;
            add_element($this->xml_doc,$item,'inn',$rec['director_inn']) ;
            add_element($this->xml_doc,$item,'snils',$rec['director_snils']) ;
            add_element($this->xml_doc,$item,'job_title',$rec['director_job_title']) ;
            //add_element($this->xml_doc,$item,'date_birth',$rec['director_date_birth']) ;
            //add_element($this->xml_doc,$item,'place_birth',$rec['director_place_birth']) ;
            //add_element($this->xml_doc,$item,'gender',$rec['director_gender']) ;
            add_element($this->xml_doc,$item,'email',$rec['director_email']) ;
            add_element($this->xml_doc,$item,'phone',str_replace(['+','(',')','-'], '', $rec['director_phone'])) ;
		}
	}

}

?>
