<?php
include_once("c_esmo_setting_mo.php");
class c_page_cab_esmo_setting_rules extends c_page_cab_esmo_setting_mo
{
  public $h1='Критерии медицинского осмотра' ;
  public $arr_method=array(0=>'',1=>'Терминал',2=>'РМВ') ;

 function block_main()
 { $this->page_title() ;
   $this->panel_rules_edit() ;
 }

function panel_rules_edit($options=array())
{ // $arr_groups=ACCOUNTS()->get_arr_tree_workgroups() ;

    
    $arr_groups=ACCOUNTS()->get_arr_groups_select_options() ;
    //print_r($arr_groups) ;
  ?><div id="panel_rules_edit">
    <form class="sky-form no_box_shadow">
        <table><tr><th>Выбор</th>
                     <th>Наименование</th>
                     <!--<th>Дата от</th>
                     <th>Дата до</th>-->
                     <th>Метод МО</th>
                     <th>Группа сотрудников</th>
                     <th>Группа ЭСМО</th>
                     <th>Возраст<br>от/до</th>
                     <?if ($GLOBALS['LS_check_sd']){?><th>Давление<br>систолическое<br>мин/макс</th><?}?>
                     <?if ($GLOBALS['LS_check_sd']){?><th>Давление<br>диастолическое<br>мин/макс</th><?}?>
                     <?if ($GLOBALS['LS_check_t']){?><th>Температура<br>мин/макс</th><?}?>
                     <?if ($GLOBALS['LS_check_p']){?><th>Пульс<br>мин/макс</th><?}?>
                     <?if ($GLOBALS['LS_check_a']){?><th>Алкотест</th><?}?>
                     <?if ($GLOBALS['LS_check_a']){?><th>ЦНС</th><?}?>
                     <?if ($GLOBALS['LS_check_v']){?><th>ТКТ</th><?}?>
            </tr>
    <? if (_sizeof(_IL('IL_dg')->recs)) foreach(_IL('IL_dg')->recs as $id=>$rec)  if ($rec['enabled'] && !unserialize($rec['settings'])['hidden'])
    { ?><tr reffer="<?echo $rec['_reffer']?>">
            <td><input type="checkbox" name="rec[<?echo $id?>][check]" value="<?echo $rec['id']?>"></td>
            <td><label class="input"><input type="text" class=name name="rec[<?echo $id?>][name]" value="<?echo $rec['obj_name']?>"></label></td>
            <td><label class="select"><select name="rec[<?echo $id?>][method]">
                         <?  if (_sizeof($this->arr_method)) foreach($this->arr_method as $key=>$value) {?><option value="<?echo $key?>" <?if ($rec['method']==$key) echo 'selected'?>><?echo $value?></option><?}?>
                    </select><i></i></label></td>
            <td><label class="select"><select name="rec[<?echo $id?>][group]"><option value="0"></option>
                 <?  if (_sizeof(_IL('IL_groups')->recs)) foreach(_IL('IL_groups')->recs as $rec_list) if ($rec_list['enabled']) {?><option value="<?echo $rec_list['id']?>" <?if ($rec['group_id']==$rec_list['id']) echo 'selected'?>><?echo $rec_list['obj_name']?></option><?}?>
                    </select><i></i></label></td>
            <td><label class="select"><select multiple="multiple"  name="rec[<?echo $id?>][_esmo_groups][]">
                 <? $esmo_groups_ids=array_flip(explode(',',$rec['esmo_groups'])) ;
                    if (_sizeof($arr_groups)) foreach($arr_groups as $pkey=>$name) {?><option value="<?echo $pkey?>" <?if (isset($esmo_groups_ids[$pkey])) echo 'selected'?>><?echo $name?></option><?}?>
                    </select></label></td>
            <? $age_value=($rec['age_min']>0 or $rec['age_max']>0)?  $rec['age_min'].'-'.$rec['age_max']:'' ;
               $s_value=($rec['s_min']>0 or $rec['s_max']>0)?  sprintf('%03d',$rec['s_min']).'-'.sprintf('%03d',$rec['s_max']):'' ;
               $d_value=($rec['d_min']>0 or $rec['d_max']>0)?  sprintf('%02d',$rec['d_min']).'-'.sprintf('%03d',$rec['d_max']):'' ;
               $t_value=($rec['t_min']>0 or $rec['t_max']>0)?  sprintf('%02.1f',$rec['t_min']).'-'.sprintf('%02.1f',$rec['t_max']):'' ;
               $p_value=($rec['p_min']>0 or $rec['p_max']>0)?  sprintf('%02d',$rec['p_min']).'-'.sprintf('%03d',$rec['p_max']):'' ;

            ?>
            <td><label class="input inline"><input type="text" class="age" name="rec[<?echo $id?>][age]" value="<?echo $age_value?>" data-mask="00-00" placeholder="__-__"></label></td>
            <?if ($GLOBALS['LS_check_sd']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="rec[<?echo $id?>][_s]" value="1" <?if ($rec['s']) echo 'checked'?>>&nbsp;<label class="input inline"><input type="text" class="s" name="rec[<?echo $id?>][s]" value="<?echo $s_value?>" <?if (!$rec['s']) echo 'disabled'?> data-mask="000-000" placeholder="___-___"></label></td><?}?>
            <?if ($GLOBALS['LS_check_sd']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="rec[<?echo $id?>][_d]" value="1" <?if ($rec['d']) echo 'checked'?>>&nbsp;<label class="input inline"><input type="text" class="d" name="rec[<?echo $id?>][d]" value="<?echo $d_value?>" <?if (!$rec['d']) echo 'disabled'?> data-mask="00-000" placeholder="__-___"></label></td><?}?>
            <?if ($GLOBALS['LS_check_t']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="rec[<?echo $id?>][_t]" value="1" <?if ($rec['t']) echo 'checked'?>>&nbsp;<label class="input inline"><input type="text" class="t" name="rec[<?echo $id?>][t]" value="<?echo $t_value?>"  <?if (!$rec['t']) echo 'disabled'?> data-mask="00.0-00.0" placeholder="__._-__._"></label></td><?}?>
            <?if ($GLOBALS['LS_check_p']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="rec[<?echo $id?>][_p]" value="1" <?if ($rec['p']) echo 'checked'?>>&nbsp;<label class="input inline"><input type="text" class="p" name="rec[<?echo $id?>][p]" value="<?echo $p_value?>"  <?if (!$rec['p']) echo 'disabled'?> data-mask="00-000" placeholder="__-___"></label></td><?}?>
            <?if ($GLOBALS['LS_check_a']){?><td><input type="checkbox" name="rec[<?echo $id?>][_a]" value="1" <?if ($rec['a']) echo 'checked'?>></td><?}?>
            <?if ($GLOBALS['LS_check_n']){?><td><input type="checkbox" name="rec[<?echo $id?>][_n]" value="1" <?if ($rec['n']) echo 'checked'?>></td><?}?>
            <?if ($GLOBALS['LS_check_v']){?><td><input type="checkbox" name="rec[<?echo $id?>][_v]" value="1" <?if ($rec['v']) echo 'checked'?>><?if ($rec['v']) echo ' <i class="fa fa-sliders v2" rule_id='.$id.' cmd="esmo_setting/get_panel_v_setting" aria-hidden="true"></i>'?></td><?}?>
       </tr>
      <?
    }     ?><tr><td colspan="12" class="buttons">
                          <button class="button v2 fa fa-floppy-o" cmd="esmo_setting/list_rec_rules_save">Сохранить</button>
                          <button class="button v2 fa fa-files-o" cmd="esmo_setting/list_rec_rules_copy" list_name="IL_dg" list_rec_id="<?echo $id?>">Копировать</button>
                          <button class="button v2 fa fa-times" cmd="esmo_setting/list_rec_rules_delete" list_name="IL_dg" list_rec_id="<?echo $id?>">Удалить</button>
            </td></tr>
            <tr><td colspan="12" class="title">Новое правило</td></tr>
            <tr>
                  <td></td>
                  <td><label class="input"><input type="text" class=name name="new_rec[name]" value=""></label></td>
                  <td><label class="select"><select name="new_rec[method]"><option value="0"></option>
                      <?  if (_sizeof($this->arr_method)) foreach($this->arr_method as $key=>$value) {?><option value="<?echo $key?>"><?echo $value?></option><?}?>
                      </select><i></i></label></td>
                  <td><label class="select"><select name="new_rec[group]"><option value="0"></option>
                     <?  if (_sizeof(_IL('IL_groups')->recs)) foreach(_IL('IL_groups')->recs as $rec_list) if ($rec_list['enabled']) {?><option value="<?echo $rec_list['id']?>"><?echo $rec_list['obj_name']?></option><?}?>
                        </select><i></i></label></td>
                  <td><label class="select"><select multiple="multiple" name="new_rec[_esmo_groups][]">
                     <?  if (_sizeof($arr_groups)) foreach($arr_groups as $pkey=>$name) {?><option value="<?echo $pkey?>"><?echo $name?></option><?}?>
                        </select></label></td>
                  <td><label class="input inline"><input type="text" class="age" name="new_rec[age]" value="" data-mask="00-00" placeholder="__-__"></label></td>
                  <?if ($GLOBALS['LS_check_sd']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="new_rec[_s]">&nbsp;<label class="input inline"><input type="text" class="s" name="new_rec[s]" value="" disabled data-mask="000-000" placeholder="___-___"></label></td><?}?>
                  <?if ($GLOBALS['LS_check_sd']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="new_rec[_d]">&nbsp;<label class="input inline"><input type="text" class="d" name="new_rec[d]" value="" disabled data-mask="00-000" placeholder="__-___"></label></td><?}?>
                  <?if ($GLOBALS['LS_check_t']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="new_rec[_t]">&nbsp;<label class="input inline"><input type="text" class="t" name="new_rec[t]" value="" disabled data-mask="00.0-00.0" placeholder="__._-__._"></label></td><?}?>
                  <?if ($GLOBALS['LS_check_p']){?><td class="nowrap"><input class="toogle_enabled" type="checkbox" name="new_rec[_p]">&nbsp;<label class="input inline"><input type="text" class="p" name="new_rec[p]" value="" disabled data-mask="00-000" placeholder="__-___"></label></td><?}?>
                  <?if ($GLOBALS['LS_check_a']){?><td><input type="checkbox" name="new_rec[_a]"></td><?}?>
                  <?if ($GLOBALS['LS_check_n']){?><td><input type="checkbox" name="new_rec[_n]"></td><?}?>
                  <?if ($GLOBALS['LS_check_v']){?><td></td><?} // настройка контроля внимания только после создания правила?>
             </tr>
            <tr><td colspan="12" class="buttons"><button class="button v2 submit fa fa-plus" cmd="esmo_setting/list_rec_rules_create">Добавить</button></td>
            </tr>
            <?



    ?>
     <!--<tr><td><?echo $options['title_create']?>:</td><td><input type="text" name="new_rec"  value="" class="big"> <button class="v2" cmd="list_rec_create" list_name="IL_dg">Добавить</button></td></tr>
     <tr><td></td><td><input type="submit" class="v2" cmd="list_rec_update" value="Сохранить" list_name="IL_dg"></td></tr>-->
   </table> </form>
   </div>
   <style type="text/css">
       div#panel_rules_edit{}
       div#panel_rules_edit .sky-form .input input, div#panel_rules_edit .sky-form .select select, div#panel_rules_edit .sky-form .textarea textarea {display:inline;}
       div#panel_rules_edit table{table-layout:auto;border-collapse:collapse;width:100%;}
       div#panel_rules_edit table th{text-align:center;font-weight:bold;color:black;font-size:10px;}
       div#panel_rules_edit table td{text-align:center;padding:5px;}
       div#panel_rules_edit table label > input[type="text"]{width:80px;text-align:center;}
       div#panel_rules_edit table input[type="text"].name{width:100%;text-align:left;}
       div#panel_rules_edit table input[type="text"].t{width:100px;}
       div#panel_rules_edit table input[disabled]{opacity:0.1}
       div#panel_rules_edit table select{width:100%;}
       div#panel_rules_edit table select[multiple]{width:auto;}
       div#panel_rules_edit table label.inline{display:inline;}
       div#panel_rules_edit table td.title{text-align:left;font-weight:bold;padding:5px 0;text-transform:uppercase;color:black;}
       div#panel_rules_edit table td.nowrap{white-space:nowrap;}
       div#panel_rules_edit table td.buttons{text-align:center;padding:10px 0;}
       div#panel_rules_edit table td.buttons button{margin:0 10px;float:none;display:inline;}
       div#panel_rules_edit table td.buttons button span{position:relative;top:-5px;}
       div#panel_rules_edit table td.buttons button img{position:relative;bottom:-7px;margin-right:5px;}
       
   </style>
   <script type="text/javascript">
       $j(document).ready(function ()
         {  //$j("input.p").mask("99-999");
            
            $j('div#panel_rules_edit').on('click','input.toogle_enabled',function()
            { if ($j(this).closest('td').find('input[type=text]').attr('disabled')) $j(this).closest('td').find('input[type=text]').attr('disabled',false).css('opacity','1').focus() ;
              else $j(this).closest('td').find('input[type=text]').attr('disabled',true).css('opacity','0.1') ;});
         }) ;</script>
   <?
}

}



?>
