<?php
class report_otdels extends c_report
{
 var $title='Подразделения' ;
 var $view_by_space_filter=1 ;
 var $allow_org_ids=1 ;
 var $usl_select_org='' ;
 public $use_datepicker=1 ;
 public $org_id=1 ;

 function setting($options=array())
    {   if ($this->filter['personal_id'] and !$this->filter['name']) $this->filter['name']=PERSONAL()->get_name_by_id($this->filter['personal_id']) ;
        ?><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="input">
                                       <input type="text" name="filter[name]" placeholder="" value="<?echo $this->filter['name']?>">
                                  </label>
                              </section>
                           </div>
                     </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=208' ;
     $usl[]='parent='.$this->org_id ;
     if ($this->filter['name'])              $usl[]='obj_name like "%'.$this->filter['name'].'%"' ;

     $usl_res=implode(' and ',$usl) ;
     //damp_array($usl,1,-1) ;
     return($usl_res) ;
  }

 function panel_info_filter()
 { $_str=array() ; $info=array() ; $title='' ;
   //damp_array($this->filter) ;
   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())
  { $cnt=execSQL_value('select count(pkey)
                        from  obj_site_personals
                        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' ;
    //echo $usl ;
    //  $options['debug']=2 ;
 	$list_rec=execSQL('select *
                       from  obj_site_personals
                       where '.$usl.$order.$limit,$options) ;
    if (_sizeof($list_rec))
    { //foreach($list_rec as $id=>$rec) PERSONAL()->prepare_public_info_to_personal($list_rec[$id],$options) ;
    }
    return($list_rec) ;
  }


    // шаблон - вывод ссылками без разделителя
    function print_template_HTML($list_recs,$options=array())
      { $id=($options['id'])? 'id='.$options['id']:'' ;
        ?><table class="list_personal_table_img basic fz_small full auto"<?echo $id?>>
            <colgroup><col id="c1"><col id="c2"><col id="c3"><col id="c4"></colgroup>
            <tr><th>ID</th><th>Наименование организации</th><th>Число сотрудников</th><th>Группа приписки</th><th>Операции</th></tr><? ;
            if (_sizeof($list_recs)) foreach($list_recs as $rec)
            {   $stats=execSQL_value('select count(pkey) from obj_site_personals where parent'.$rec['level'].'='.$rec['pkey'].' and clss=211') ;
                ?><tr class=item>
                    <td><?echo $rec['pkey']?></td>
                    <td class="left"><a href="/window/personal/otdel/<?echo $rec['pkey']?>/" class=new_window><?echo $rec['obj_name']?></td>
                    <td><?echo $stats?></td>
                    <td></td>
                    <td>
                        <?if ($stats == 0 and MEMBER()->rol==1) {?>
                            <button class="v2" cmd="aspmo_personal/after_delete_otdel" otdel_id="<?echo $rec['pkey']?>" title="Удалить подразделение можно только в случае если в подразделении нет сотрудников">Удалить подразделение</button>
                        <?} elseif (MEMBER()->rol==1) {?>
                            <button class="v2" cmd="aspmo_personal/after_transfer_personals" org_id="<?echo $this->org_id?>" otdel_id="<?echo $rec['pkey']?>" title="Перевести сотрудников из подразделения в другую организацию или подразделение">Переместить сотрудников</button>
                        <?}?>
                    </td>
                </tr><?
            }
          ?></table>
          <script type="text/javascript">
              $j('select.select_group').on('change',function()
              {   send_ajax_request({cmd:'aspmo_personal/set_org_group',org_id:$j(this).attr('org_id'),group_id:$j(this).val()});

              })  ;
          </script>

          <?
          //print_2x_arr($list_recs) ;
      }
}
?>
