<?php
// специальный отчет для добавления сотрудников в группы
class report_vpf_opo_edit extends c_report
{
 var $title='Редактирование ВПФ ОПО' ;
 var $view_by_space_filter=0 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 var $allow_export_to_csv=1 ;
 var $arr_based_settings=1 ;


function setting($options=array())
{
    $recs_sections=execSQL('select t1.pkey,t1.parent,concat(number," ",obj_name) as obj_name,
                    (select count(t2.pkey) from opo_list_vpf t2 where t2.parent=t1.pkey) as cnt_child
                    from opo_list_vpf t1
                    having cnt_child>0
                    order by indx
                    ') ;

   $form=new i_form;
   $form->form_open();
   $form->fieldset_open() ;
   $form->row_open() ;
   $this->filter_section_select('section_id','Раздел ВПФ:',2,$recs_sections) ;
   $this->filter_section_input_text('content','Текст:',2) ;
   $form->row_close() ;

   $form->fieldset_close();
   $this->panel_button_apply();
   $form->form_close() ;
}

  function create_usl_select_obj($_params,&$options)
  {  $usl=array() ;
     $usl[]='level>1' ;
     if ($this->filter['number'])              $usl[]='number like "'.$this->filter['number'].'%"' ;
     if ($this->filter['content'])              $usl[]='(obj_name like "%'.$this->filter['content'].'%" or doctors like "%'.$this->filter['content'].'%"  or checked like "%'.$this->filter['content'].'%"   or comment like "%'.$this->filter['content'].'%" )' ;
     if ($this->filter['section_id'])
     { $level_section=execSQL_value('select level from opo_list_vpf where pkey='.$this->filter['section_id']) ;
       $usl[]='(parent'.$level_section.'='.$this->filter['section_id'].' or pkey='.$this->filter['section_id'].')' ;
     }
     $usl_res=implode(' and ',$usl) ;
     return($usl_res) ;
  }

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['number'])                  $info['Раздел ВПФ']='"'.$this->filter['number'].'"' ;
   if (_sizeof($info)) foreach($info as $title=>$value) $_str[]=$title.': <strong>'.$value.'</strong>' ;
   if (_sizeof($_str)) $title='<p class=center>'.implode(' ',$_str).'</p>' ;
   return $title ;
 }


  function get_cnt_items($usl,$options=array())
  { $options['debug']=0 ;
    $cnt=execSQL_value('select count(pkey)
                        from  opo_list_vpf
                        where '.$usl,$options) ;
    return($cnt) ;
  }

  function get_items($usl,$options=array())
  { $limit=($options['limit'])? ' '.$options['limit']:'' ;
    $order=($this->filter['order'])? ' order by '.$this->filter['order']:' order by indx' ;
    $options['debug']=0 ;
 	/*$list_rec=execSQL('select pkey,indx,number,obj_name,parent1,parent2,parent3,parent4,parent5,parent6,parent7,parent8,parent9
                       from  opo_list_vpf
                       where '.$usl.' order by indx',array('debug'=>2)) ;
    */
 	$list_rec=execSQL('select t1.*,(select count(t2.pkey) from opo_list_vpf t2 where t2.parent=t1.pkey) as cnt_child
                       from  opo_list_vpf t1
                       where '.$usl.$order.$limit,array('debug'=>$options['debug'])) ;
    return($list_rec) ;
  }


  // шаблон - вывод ссылками без разделитея
  function print_template_HTML($list_recs,$options=array())
  { $id=($options['id'])? 'id='.$options['id']:'' ;

    ?><form class="sky-form no_box_shadow">
          <table class="basic fz_small full auto sky-form no_box_shadow">
              <tr>
                  <th>ID</th>
                  <th style="width:100px;">Номер ВПФ</th>
                  <th colspan="3">Раздел ВПФ</th>
                  <th>Период ОПО</th>
                  <th>Комментарии</th>
                  <th style="width:100px;">Операция</th>
              </tr>
           <?if ($list_recs) foreach($list_recs as $rec)
            {
                $name_edit_el='<textarea name="recs_vpf['.$rec['pkey'].'][obj_name]" disabled="disabled" style="width:100%;">'.htmlspecialchars($rec['obj_name']).'</textarea>' ;
                ?><tr>
                        <td class="center"><?echo $rec['pkey']?></td>
                        <td class="left"><input type="text" name="recs_vpf[<?echo $rec['pkey']?>][number]" value="<?echo htmlspecialchars($rec['number'])?>"></td>
                        <?if ($rec['level']==2){?><td class="left" colspan="3"><? echo $name_edit_el;?></td><?}?>
                        <?if ($rec['level']==3){?><td>-</td><td class="left" colspan="2"><? echo $name_edit_el;?></td><?}?>
                        <?if ($rec['level']==4){?><td></td><td>-</td><td class="left"><? echo $name_edit_el;?></td><?}?>
                        <td class="center"  style="width:200px;"><?
                            $this->form->element_select(['name'=>'recs_vpf['.$rec['pkey'].'][period]',
                                                         'recs'=>OPO()->arr_opo_len,
                                                         'value'=>$rec['period'],
                                                         'disabled'=>1

                                                        ]);

                            ?></td>
                        <td class="left" style="width:200px;"><textarea name="recs_vpf[<?echo $rec['pkey']?>][comment]" disabled="disabled"><?echo htmlspecialchars($rec['comment'])?></textarea></td>
                       <td><button class="button edit">Редактировать</button><input type="submit" class="v2 hidden button save" cmd="ot/save_vpf" source="opo" no_reload_page="1" value="Сохранить" validate="form"></td>
                </tr><?
             }?>
         </table>
        </form>
         <script type="text/javascript">
             $j('table.basic input[type=text]').attr('disabled',true) ;
             $j('table.basic textarea').attr('disabled',true) ;
             $j('button.edit').on('click',function()
             { $j(this).closest('tr').find('input[type=text]').removeAttr('disabled') ;
               $j(this).closest('tr').find('textarea').removeAttr('disabled') ;
               $j(this).closest('tr').find('select').removeAttr('disabled') ;
               $j(this).hide() ;
               $j(this).closest('tr').find('input.save').removeClass('hidden').show() ;
               return(false) ;
             }) ;
             $j('input.save').on('click',function()
             { //$j(this).closest('tr').find('input[type=text]').attr('disabled','disabled') ;
               //$j(this).closest('tr').find('textarea').attr('disabled','disabled') ;
               //$j(this).hide() ;
               //$j(this).closest('tr').find('button.edit').show() ;
             }) ;

         </script>
         <style type="text/css">
             .sky-form table.basic input[type=text]{text-align:center;}
             .sky-form table.basic input[type=text]:disabled{border:1px solid white;box-shadow:none;color:black;}
             .sky-form table.basic select:disabled{border:1px solid white;box-shadow:none;color:black;}
             .sky-form table.basic select:disabled+i{display:none;}
             .sky-form table.basic select:disabled:hover{border:1px solid white;box-shadow:none;color:black;}
             .sky-form table.basic textarea{width:100%;height:100%;}
             .sky-form table.basic textarea:{border:1px solid white;box-shadow:none;color:black;}
             .sky-form table.basic textarea:disabled{border:1px solid white;box-shadow:none;color:black;}
             .sky-form table.basic .button{float:none;margin:0 auto;}
             .sky-form table.basic .button.hidden{display:none;}
         </style>

    <?
  }


}

?>
