<?php

class report_objects 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 $root_id=1 ;
 //public $view_clss=1 ;
 public $table_name='' ;

   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_<?echo $this->report_UID?>"><?
            $form=new i_megamenu_form($this,array('mode'=>'V','col_count'=>2,'col_count_title'=>1,'row_separator'=>'_dashed')) ;
            $form->form_open() ;
            ?><input type="hidden" name="table_name" value="<?echo $this->table_name?>"><?
            ?><input type="hidden" name="root_id" value="<?echo $this->root_id?>"><?
            ?><input type="hidden" name="view_clss" value="<?echo $this->view_clss?>"><?
            ?><input type="hidden" name="report_UID" value="<?echo $this->report_UID?>"><?
            $form->row_open() ;
               //$form->element_input(array('name'=>'filter[name]','title'=>'Наименование','value'=>$this->filter['name'])) ;
                $form->filter_section_input_text('name','ФИО:',4,array('auto_complete'=>"autocomplette_personal_name")) ;
               //$form->element_input(array('name'=>'filter[art]','title'=>'Артикул','value'=>$this->filter['art'])) ;
            $form->row_close() ;
            $form->panel_button_apply();
            $form->form_close() ;
        ?></div><?
     }


    function panel_button_apply()
    { ?><div id="panel_buttons" class="container text-center">
            <input type="submit" class="btn btn-success btn-sm v2" cmd="class/update_report_objects" value="<?echo ($this->editing)? 'Получить данные':'Применить'?>">
        </div><?
    }

  function create_usl_select_obj($_params,&$options)
  {  //damp_array($this->filter,1,-1) ;
     $usl=array() ;
     $usl[]=1 ;
     if ($this->view_clss) $usl[]='clss='.$this->view_clss ;
     if ($this->root_id) $usl[]='parent='.$this->root_id ;
     //$usl[]='t1.id>1023028' ;
     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 ($this->filter['personal_id'])                     $info['ФИО']='"'.PERSONAL()->get_name_by_id($this->filter['personal_id']).'"' ;
   //if ($this->filter['org_id'])                          $info['организация']=PERSONAL()->get_name_by_id($this->filter['org_id']) ;
   //if ($this->filter['otdel_id'])                        $info['отдел']=PERSONAL()->get_name_by_id($this->filter['otdel_id']) ;

   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  '.$this->table_name.' 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 pkey desc' ;
      //$options['debug']=2 ;
    $list_rec=execSQL('select * from  '.$this->table_name.' where '.$usl.$order.$limit,$options) ;
    //if ($list_rec) foreach($list_rec as $id=>$rec) GOODS()->prepare_public_info($list_rec[$id]) ;

    return($list_rec) ;
  }


    // шаблон - вывод ссылками без разделитея
    function print_template_HTML($list_recs,$options=array())
    {   ?><form><?
        ?><input type="hidden" name="table_name" value="<?echo $this->table_name?>"><?
                    ?><input type="hidden" name="root_id" value="<?echo $this->root_id?>"><?
                    ?><input type="hidden" name="view_clss" value="<?echo $this->view_clss?>"><?
                    ?><input type="hidden" name="report_UID" value="<?echo $this->report_UID?>"><?
        //damp_array($this->filter) ;
        if (_sizeof($this->filter)) foreach($this->filter as $name=>$value) {?><input type="hidden" name="filter[<?echo $name?>]" value="<?echo $value?>"><?}
        _CLSS($this->view_clss)->show_based_obj_list($list_recs) ;
        ?><div class="center"><button class="btn btn-success v2" cmd="class/save_objects">Сохранить</button></div>
        </form><?
    }


}
?>
