<?php
include_once("c_setting_members.php");
class c_page_cab_setting_members_new_group extends c_page_cab_setting_members
{
  public $h1='Новая группа ЭСМО' ;

  function block_main()
  { $this->page_title() ;
    $arr_groups=ACCOUNTS()->get_list_workgoups(array('_usl'=>'(clss=1 and parent=1)')) ;
    $last_term_id=execSQL_value('select max(id) from obj_site_account where clss=203') ;

    if ($last_term_id) $last_term_profil=execSQL_value('select profil from obj_site_account where clss=203 and id='.$last_term_id) ;
    $last_term_id++ ;
    $arr_IP=explode('.',$_SERVER['REMOTE_ADDR']) ;
    unset($arr_IP[3]) ;
    $ip_term=implode('.',$arr_IP).'.' ;

    ?><div id="panel_filter"><form id="sky-form" class="sky-form"><fieldset id="fieldset_group">
        <div class="row">
             <section class="col col-2">
                 <label class="label">Название группы:</label>
                 <label class="input"><input type="text" data-required name="filter[group_name]" value=""></label>
             </section>
            <section class="col col-2">
                <label class="label">Родительская группа</label>
                <label class="select">
                    <select name="filter[parent_group_id]">
                       <?if (_sizeof($arr_groups)) foreach($arr_groups as $id=>$rec){?><option value="<?echo $id?>" <?if ($this->filter['group_id']==$id) echo 'selected'?>><?echo $rec['obj_name']?></option><?}?>
                    </select>
                </label>
            </section>
        </div>
        <div class="row">
           <section class="col col-2">
               <label class="label">АРМ фельдшера, IP адрес:</label>
               <label class="input"><input type="text" name="filter[rmv_ip]" data-required  value="<?echo $_SERVER['REMOTE_ADDR']?>"></label>
           </section>
        </div>

        <div class="row" id="row_terminal">
           <section class="col col-2">
               <label class="label">ID терминала:</label>
               <label class="input"><input type="text" data-required name="filter[terminal_id][]" class=terminal_id value="<?echo $last_term_id?>"></label>
           </section>
           <section class="col col-2">
               <label class="label">IP адрес:</label>
               <label class="input"><input type="text" data-required name="filter[terminal_ip][]" value="<?echo $ip_term?>"></label>
           </section>
           <section class="col col-2">
            <label class="label">Профиль</label>
            <label class="select">
                <select name="filter[terminal_profil][]">
                   <?if (_sizeof(_IL('IL_term_prof')->recs)) foreach(_IL('IL_term_prof')->recs as $id=>$rec){?><option value="<?echo $id?>" <?if ($last_term_profil==$id) echo 'selected'?>><?echo $rec['obj_name']?></option><?}?>
                </select>
            </label>
           </section>
      </div>
          </fieldset>
          <fieldset>
      <div id="panel_buttons"><button class="button" id="append_term_row">Добавить терминал</button>&nbsp;<button class="button" id="delete_term_row">Удалить терминал</button>&nbsp;<input type="submit" class="button v2" cmd="aspmo_setting/group_device_create" value="Сохранить"  validate="form"></div><br>
    </fieldset>
      </form>
      </div>
      <script type="text/javascript">
          $j('button#append_term_row').click(function()
           { $j('#fieldset_group').append($j('div#row_terminal:last-child').eq(0).clone()) ;
             var last_id=$j('div#row_terminal:last-child input.terminal_id').val()*1 ;
             $j('div#row_terminal:last-child input.terminal_id').val(last_id+1) ;
           }) ;
          $j('button#delete_term_row').click(function(){if ($j('div#row_terminal').length>1) $j('div#row_terminal:last-child').remove()}) ;
      </script>
      <?
  }

}



?>
