mcramer
2013-07-05 65d91d24f06d8c731fdb0afa4f492f9d238c2d8a
interface/lib/classes/listform_actions.inc.php
@@ -33,8 +33,9 @@
   private $id;
   public $idx_key;
   public $DataRowColor;
   public  $SQLExtWhere = '';
   public  $SQLOrderBy = '';
   public $SQLExtWhere = '';
   public $SQLOrderBy = '';
   public $SQLExtSelect = '';
   
   public function onLoad()
    {
@@ -55,7 +56,48 @@
      
      $app->tpl->newTemplate("listpage.tpl.htm");
      $app->tpl->setInclude('content_tpl','templates/'.$app->listform->listDef["name"].'_list.htm');
      //* Manipulate order by for sorting / Every list has a stored value
      //* Against notice error
      if(!isset($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'])){
        $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = '';
      }
      if(!empty($_GET['orderby'])){
        $order = str_replace('tbl_col_','',$_GET['orderby']);
        //* Check the css class submited value
        if (preg_match("/^[a-z\_]{1,}$/",$order)) {
          // prepend correct table
         $prepend_table = $app->listform->listDef['table'];
         if(trim($app->listform->listDef['additional_tables']) != '' && is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) {
            foreach($app->listform->listDef['item'] as $field) {
               if($field['field'] == $order && $field['table'] != ''){
                  $prepend_table = $field['table'];
                  break;
               }
            }
          }
         $order = $prepend_table.'.'.$order;
          if($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] == $order){
            $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = $order.' DESC';
          } else {
            $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = $order;
          }
        }
      }
      // If a manuel oder by like customers isset the sorting will be infront
      if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'])){
        if(empty($this->SQLOrderBy)){
          $this->SQLOrderBy = "ORDER BY ".$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'];
        } else {
          $this->SQLOrderBy = str_replace("ORDER BY ","ORDER BY ".$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'].', ',$this->SQLOrderBy);
        }
      }
      // Getting Datasets from DB
      $records = $app->db->queryAllRecords($this->getQueryString());
@@ -105,7 +147,7 @@
      return $rec;
   }
   
   private function getQueryString() {
   public function getQueryString() {
      global $app;
      $sql_where = '';
@@ -114,14 +156,16 @@
         if($_SESSION['s']['user']['typ'] == "admin") {
            $sql_where = '';
         } else {
            $sql_where = $app->tform->getAuthSQL('r').' and';
            $sql_where = $app->tform->getAuthSQL('r', $app->listform->listDef['table']).' and';
                //$sql_where = $app->tform->getAuthSQL('r').' and';
         }
      }      
      if($this->SQLExtWhere != '') {
         $sql_where .= ' '.$this->SQLExtWhere.' and';
      }
      $sql_where = $app->listform->getSearchSQL($sql_where);
      if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql'];
      $app->tpl->setVar($app->listform->searchValues);
      
      $order_by_sql = $this->SQLOrderBy;
@@ -130,7 +174,28 @@
      $limit_sql = $app->listform->getPagingSQL($sql_where);
      $app->tpl->setVar('paging',$app->listform->pagingHTML);
      return 'SELECT * FROM '.$app->listform->listDef['table']." WHERE $sql_where $order_by_sql $limit_sql";
      $extselect = '';
      $join = '';
      if($this->SQLExtSelect != '') {
         if(substr($this->SQLExtSelect,0,1) != ',') $this->SQLExtSelect = ','.$this->SQLExtSelect;
         $extselect .= $this->SQLExtSelect;
      }
      $table_selects = array();
      $table_selects[] = trim($app->listform->listDef['table']).'.*';
      $app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']);
      if($app->listform->listDef['additional_tables'] != ''){
         $additional_tables = explode(',', $app->listform->listDef['additional_tables']);
         foreach($additional_tables as $additional_table){
            $table_selects[] = trim($additional_table).'.*';
         }
      }
      $select = implode(', ', $table_selects);
      $sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql $limit_sql";
      //echo $sql;
      return $sql;
   }
   
   
@@ -145,15 +210,35 @@
      include($lng_file);
      $app->tpl->setVar($wb);
      
      //* Limit each page
      $limits = array('5'=>'5','15'=>'15','25'=>'25','50'=>'50','100'=>'100','999999999' => 'all');
      //* create options and set selected, if default -> 15 is selected
      $options = '';
      foreach($limits as $key => $val){
        $options .= '<option value="'.$key.'" '.(isset($_SESSION['search']['limit']) &&  $_SESSION['search']['limit'] == $key ? 'selected="selected"':'' ).(!isset($_SESSION['search']['limit']) && $key == '15' ? 'selected="selected"':'').'>'.$val.'</option>';
      }
      $app->tpl->setVar('search_limit','<select name="search_limit" class="search_limit">'.$options.'</select>');
      $app->tpl->setVar('toolsarea_head_txt',$app->lng('toolsarea_head_txt'));
      $app->tpl->setVar($app->listform->wordbook);
      $app->tpl->setVar('form_action', $app->listform->listDef['file']);
      
        if(isset($_SESSION['show_info_msg'])) {
            $app->tpl->setVar('show_info_msg', $_SESSION['show_info_msg']);
            unset($_SESSION['show_info_msg']);
        }
        if(isset($_SESSION['show_error_msg'])) {
            $app->tpl->setVar('show_error_msg', $_SESSION['show_error_msg']);
            unset($_SESSION['show_error_msg']);
        }
      //* Parse the templates and send output to the browser
      $this->onShowEnd();
   }
   
   private function onShowEnd()
   public function onShowEnd()
    {
      global $app;
      $app->tpl_defaults();