<?php
// специальный отчет для добавления сотрудников в группы
class report_groups_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 init($options=array())
 {
 // для новых настрокет просто добавить их сюда
   $this->arr_based_settings=array('at1'=>array('title'=>'Алкотестер1',
                                          'atn'=>'Наименование',
                                          'ats'=>'Серийный номер',
                                          'atp'=>'Дата поверки'
                                         ),
                             'at2'=>array('title'=>'Алкотестер2',
                                          'atn'=>'Наименование',
                                          'ats'=>'Серийный номер',
                                          'atp'=>'Дата поверки'
                                         ),
                             'at3'=>array('title'=>'Алкотестер3',
                                          'atn'=>'Наименование',
                                          'ats'=>'Серийный номер',
                                          'atp'=>'Дата поверки'
                                         ),
                             'ept'=>'Экспресс-тест - фирма-изготовитель',
                             'scan_email_login'=>'Сканер - email from - логин',
                             'pmo_medic_name'=>'Наименование поликлиники для ПМО'
                             )
           ;
 }



 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" id="person_info">
                           <section class="col col-2">
                               <label class="label">Группа ЭСМО:</label>
                               <label class="select">
                                   <?$arr_groups=execSQL_row('select pkey,obj_name from obj_site_account where clss=206')?>
                                   <select name="filter[group_ids][]" multiple="multiple"><?
                                     if (_sizeof($arr_groups)) foreach($arr_groups as $id=>$name) {?><option value="<?echo $id?>" <?if(isset($this->filter['group_ids'][$id])) echo 'selected'?>><?echo $name?></option><?}?>
                                   </select>
                               </label>
                           </section>
                  </fieldset>
                  <?$this->panel_button_apply();?>
              </form>
       </div><br>
     <?
  }


  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     $usl[]='clss=206' ;
     $usl[]='enabled=1' ;
     if ($this->filter['name'])              $usl[]='obj_name like "%'.$this->filter['name'].'%"' ;
     if (_sizeof($this->filter['group_ids'])) $usl[]='pkey in ('.implode(',',array_keys($this->filter['group_ids'])).')' ;
     $usl_res=implode(' and ',$usl) ;
     return($usl_res) ;
  }

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   if ($this->filter['name'])                  $info['Наименование группы']='"'.$this->filter['name'].'"' ;
   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  obj_site_account
                        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 obj_name' ;
    // запрос по сотрудникам, состоящим в группе на выданные направления по АГ
 	$list_rec=execSQL('select *
                       from  obj_site_account
                       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>
          <table class="basic fz_small full auto sky-form no_box_shadow"><tr><th>ID</th><th>Наименование</th><?if (_sizeof($this->arr_based_settings)) foreach($this->arr_based_settings as $title=>$value) echo '<th>'.(is_array($value)? $value['title']:$value).'</th>'?><th>Операция</th></tr>
           <?if ($list_recs) foreach($list_recs as $rec_RG)
             {
             if (isset($this->arr_based_settings['at']['atn']) and !isset($this->arr_based_settings['at1']['atn'])) $this->arr_based_settings['at1']=$this->arr_based_settings['at'] ;
                 ?><tr><td class="left"><?echo $rec_RG['pkey']?></td>
                     <td class="left" style="font-size:18px;"><?echo htmlspecialchars($rec_RG['obj_name'])?></td>
                     <? $arr=unserialize($rec_RG['settings']) ;
                        if ($arr==null) $arr=json_decode($rec_RG['settings'],true);

                                          //if (isset($arr['atn']) and !isset($arr['at1']['atn'])) $arr['at1']['atn']=$arr['atn'] ;
                                            //                   if (isset($arr['ats']) and !isset($arr['at1']['ats'])) $arr['at1']['ats']=$arr['ats'] ;
                                            //                                        if (isset($arr['atp']) and !isset($arr['at1']['atp'])) $arr['at1']['atp']=$arr['atp'] ;



                        if (_sizeof($this->arr_based_settings)) foreach($this->arr_based_settings as $title=>$value)
                        { if (!is_array($value)) {?><td><textarea style="width:100%;height:100px;" name="recs_group[<?echo $rec_RG['pkey']?>][settings][<?echo $title?>]" disabled="disabled"><?echo htmlspecialchars($arr[$title]) ?></textarea></td><?}
                          else
                          {  ?><td class="left"><?
                              foreach($value as $id=>$value) if ($id!='title')
                              { ?><div class="title""><? echo $value ?></div>
                                  <input type="text" style="width:100%;" name="recs_group[<?echo $rec_RG['pkey']?>][settings][<?echo $title?>][<?echo $id?>]" value="<?echo htmlspecialchars($arr[$title][$id]) ?>"  disabled="disabled">
                                <?

                              }
                             ?></td><?
                          }
                        }
                     ?>
                     <td><button class="button edit">Редактировать</button><input type="submit" class="v2 hidden button save" cmd="aspmo_setting/save_ESMO_group" no_reload_page="1" value="Сохранить" validate="form"></td>
                </tr><?
             }?>
         </table>
        </form>
         <script type="text/javascript">
             $j('input[type=text]').attr('disabled',true) ;
             $j('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).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 div.title{font-size:10px;color:#aaaaaa;}
             .sky-form input[type=text]:disabled{border:1px solid white;box-shadow:none;color:black;}
             .sky-form textarea:disabled{border:1px solid white;box-shadow:none;color:black;}
             .sky-form .button{float:none;margin:0 auto;}
             .sky-form .button.hidden{display:none;}
         </style>

    <?
  }


}

?>
