<?php
class doc_spravka extends c_doc
{
 public $view_by_space_filter=1 ;
 var $title='Справка' ;
 public $PDF_page_orientation='P' ;
 public $PDF_page_format='A4' ;
 var $footer_right='' ;
 public $show_on_page_peports=0 ;


 var $rec_mo=array() ;
 var $rec_personal=array() ;

 var $mo_id=0 ;
 var $personal_id=0 ;
 var $db_report_code='napravlenie' ; // Имя директории в таблице документов для сохранения докумена. только для магнита - направление по АГ, справка и направление в наркодиспансер должны иметь общую нумерацию.

 function init($create_options=array())
 { //damp_array($this->rec_doc) ;
   //if ($this->filter['mo_id']) $this->rec_mo=ESMO()->get_mo_by_id($this->filter['mo_id']) ;
   //if ($_POST['mo_id']) $this->rec_mo=ESMO()->get_mo_by_id($_POST['mo_id']) ;
   //if ($this->rec_mo['pkey']) $this->mo_id=$this->rec_mo['pkey'] ;
   //if ($this->rec_mo['pkey'] and $this->rec_mo['member_id']) $this->rec_personal=PERSONAL()->get_personal_by_id($this->rec_mo['member_id']) ;
   //if ($this->rec_personal['pkey']) $this->personal_id=$this->rec_personal['pkey'] ;
   //if (!$this->rec_personal['name1']) list($this->rec_personal['name1'],$this->rec_personal['name2'],$this->rec_personal['name3'])=explode(' ',$this->rec_personal['obj_name']) ;
//     if ($this->filter['doc_id']) $this->rec_doc=DOCS()->get_doc_by_id($this->filter['doc_id']) ;
//     if ($this->rec_doc['pkey']) $this->content=unserialize($this->rec_doc['content']) ;

     // приведено в единый вид по всем документам
   if ($this->filter['mo_id']) $this->rec_mo=ESMO()->get_mo_by_id($this->filter['mo_id']) ;
   if ($_POST['mo_id']) $this->rec_mo=ESMO()->get_mo_by_id($_POST['mo_id']) ;

     if (!$this->rec_mo['pkey'] and $this->filter['personal_id']) $this->rec_mo=ESMO()->get_last_mo_rec_to_personal($this->filter['personal_id']) ;

     if ($this->rec_mo['pkey'])
     { $this->mo_id=$this->rec_mo['pkey'] ;
       if ($this->rec_mo['member_id']) $this->rec_personal=PERSONAL()->get_personal_by_id($this->rec_mo['member_id']) ;
     }

     if ($this->filter['doc_id']) $this->rec_doc=DOCS()->get_doc_by_id($this->filter['doc_id']) ;
     if ($this->rec_doc['pkey'])
     { $this->content=unserialize($this->rec_doc['content']) ;
       if ($this->rec_doc['mo_id'] and !_sizeof($this->rec_mo)) $this->rec_mo=ESMO()->get_mo_by_id($this->rec_doc['mo_id']) ;
       if ($this->rec_doc['personal_id'] and !_sizeof($this->rec_personal)) $this->rec_personal=PERSONAL()->get_personal_by_id($this->rec_doc['personal_id']) ;
     }

     if ($this->filter['personal_id']) $this->rec_personal=PERSONAL()->get_personal_by_id($this->filter['personal_id']) ;
     if ($this->rec_personal['pkey'])
     { $this->personal_id=$this->rec_personal['pkey'] ;
      //  if (!$this->rec_personal['name1'])
       list($this->rec_personal['name1'],$this->rec_personal['name2'],$this->rec_personal['name3'])=explode(' ',$this->rec_personal['obj_name']) ;
     }

 }


function content_edit($options=array())
{   $this->init() ;
    ?><form><input type="hidden" name="doc_id" value="<?echo $this->filter['doc_id']?>">
    <table class="content_edit">
        <tr><td>Фамилия, имя и отчество:</td><td><?echo htmlspecialchars($this->rec_personal['obj_name'])?></td></tr>
        <tr><td>Дата рождения</td><td><?echo $this->rec_personal['dr']?></td></tr>
        <tr><td>Место работы</td><td><?echo $this->rec_personal['_org_name'].'<br>'.$this->rec_personal['_otdel_name']?></td></tr>
        <tr><td>Цель направления</td><td><textarea name="content[p1]"><?echo htmlspecialchars(($this->content['p1']) ? $this->content['p1']:'ОБСЛЕДОВАНИЕ')?></textarea></td></tr>
        <tr><td>Предварительный диагноз</td><td><textarea name="content[p2]"><?echo htmlspecialchars($this->content['p2'])?></textarea></td></tr>
    </table>
     <input type="hidden" name="filter[doc_id]" value="<?echo $this->rec_doc['pkey']?>">
     <input type="hidden" name="filter[mo_id]" value="<?echo $this->rec_mo['pkey']?>">
     <div class="center"><!--<input type="submit" class="v2" cmd="docs/save_content" value="Сохранить">&nbsp;&nbsp;&nbsp;-->
                       <button class="v2" cmd="docs/doc_recreate" doc_id="<?echo $this->rec_doc['pkey']?>"  url_page_doc_view="<? echo _CUR_PAGE_DIR?>" pdf_options=" --copies <?echo $this->copies?>" > Сохранить "<?echo $this->title?>"</button>
     </div></form>
     <style type="text/css">
          *{line-height:1em;}
          h1{font-size:16px;text-align:center;font-weight:normal;border-bottom:none;color:black;;}
          p{font-size:12px;margin:5px 0;line-height:2em;}
          div.small{font-size:8px;text-align:center;margin-top:-10px;}
          table.content_edit{width:100%;}
          table.content_edit td:first-child{width:400px;vertical-align:top;padding-top:10px;font-size:14px;border-bottom:1px solid #dddddd;}
          table.content_edit td{text-align:left;padding:5px 0;}
          table.content_edit td input{width:100%;}
          table.content_edit td textarea{width:100%;height:50px;}
    </style>

   <?

}




function view_as_HTML($options=array())
{  $this->init() ;
   //damp_array($this->rec_doc) ;
   //damp_array($this->filter) ;
   ?><h1 class="center"><?echo $this->title?></h1>
    <table class="setting">
       <tr><td class="col1">Фамилия</td><td><?echo $this->rec_personal['name1']?>&nbsp;</td></tr>
       <tr><td class="col1">Имя</td><td><?echo $this->rec_personal['name2']?>&nbsp;</td></tr>
       <tr><td class="col1">Отчество</td><td><?echo $this->rec_personal['name3']?>&nbsp;</td></tr>
       <tr><td class="col1">Дата рождения</td><td><?echo $this->rec_personal['dr']?></td></tr>
       <tr><td class="col1">Место работы</td><td><?echo $this->rec_personal['_org_name']?>&nbsp;</td></tr>
       <tr><td class="col1"></td><td><?echo $this->rec_personal['_otdel_name']?>&nbsp;</td></tr>
       <tr><td class="col1"></td><td><?echo $this->rec_personal['_work_name']?>&nbsp;</td></tr>
       <tr><td class="col1">Цель направления</td><td><span  class="content"><?echo $this->content['p1']?></td></tr>
       <tr><td class="col1"></td><td>&nbsp;</td></tr>
       <tr><td class="col1">Предварительный диагноз</td><td><span  class="content"><?echo $this->content['p2']?></td></tr>
        <tr><td class="col1"></td><td>&nbsp;</td></tr>
       <tr><td class="col1" rowspan="3">Объем оказанной помощи</td><td>&nbsp;</td></tr>
       <tr><td>&nbsp;</td></tr>
       <tr><td>&nbsp;</td></tr>
       <tr><td>&nbsp;</td></tr>
    </table>
    <table class="sign">
        <tr>
            <td style="width:300px;">Должностное лицо,<br>выдавшее справку</td>
            <td style="width:200px;"><br><br>_______________</td>
            <td style="width:30px;">&nbsp;&nbsp;</td>
            <td style="width:300px;"><br><br><?echo MEMBER()->name?></td>
        </tr>
        <tr>
            <td></td>
            <td>(подпись)</td>
            <td></td>
            <td>(расшифровка подписи)</td>
        </tr>
    </table>
    <p class="mark_1">М.П.</p>
    <?echo date('d.m.Y H:i')?>
    <style>
        h1{font-size:18px;text-align:center;font-weight:normal;border-bottom:none;color:black;;}
        p{font-size:14px;margin:5px 0;line-height:2em;}
        p.mark_1{text-align:center;font-weight:bold;font-size:15px;;}
        table.setting{font-size:14px;}
        table.setting td{text-align:left;border-bottom:1px solid #777777;}
        table.setting td.col1{border-bottom:none;width:200px;}
    </style>
   <?

}


}


?>
