From fb02f0b58019458b10893eff6b5c5e3135b53cc1 Mon Sep 17 00:00:00 2001 From: tbrehm Date: Tue, 18 Nov 2008 19:20:35 +0000 Subject: [PATCH] Fixed missing translation in lists. --- interface/lib/classes/listform.inc.php | 711 +++++++++--------- .../lib/classes/listform_actions.inc.php | 340 +++++---- 2 files changed, 533 insertions(+), 518 deletions(-) diff --git a/interface/lib/classes/listform.inc.php b/interface/lib/classes/listform.inc.php index e1284bccfb..33ec36ef1b 100644 --- a/interface/lib/classes/listform.inc.php +++ b/interface/lib/classes/listform.inc.php @@ -1,347 +1,366 @@ -listDef = $liste; - $this->module = $module; - - //* Fill datasources - foreach($this->listDef['item'] as $key => $field) { - if(@is_array($field['datasource'])) { - $this->listDef['item'][$key]['value'] = $this->getDatasourceData($field); - } - } - return true; - } - - /** - * Get the key => value array of a form filed from a datasource definitiom - * - * @param field = array with field definition - * @param record = Dataset as array - * @return array key => value array for the value field of a form - */ - private function getDatasourceData($field) - { - global $app; - $values = array(); - - if($field['datasource']['type'] == 'SQL') { - - //** Preparing SQL string. We will replace some common placeholders - $querystring = $field['datasource']['querystring']; - $querystring = str_replace('{USERID}', $_SESSION['s']['user']['userid'], $querystring); - $querystring = str_replace('{GROUPID}', $_SESSION['s']['user']['default_group'], $querystring); - $querystring = str_replace('{GROUPS}', $_SESSION['s']['user']['groups'], $querystring); - //TODO: - //$table_idx = $this->formDef['db_table_idx']; - //$querystring = str_replace("{RECORDID}",$record[$table_idx],$querystring); - $app->uses('tform'); - $querystring = str_replace("{AUTHSQL}",$app->tform->getAuthSQL('r'),$querystring); - - //* Getting the records - $tmp_records = $app->db->queryAllRecords($querystring); - if($app->db->errorMessage != '') die($app->db->errorMessage); - if(is_array($tmp_records)) { - $key_field = $field['datasource']['keyfield']; - $value_field = $field['datasource']['valuefield']; - foreach($tmp_records as $tmp_rec) { - $tmp_id = $tmp_rec[$key_field]; - $values[$tmp_id] = $tmp_rec[$value_field]; - } - } - } - - if($field['datasource']['type'] == 'CUSTOM') { - //* Calls a custom class to validate this record - if($field['datasource']['class'] != '' and $field['datasource']['function'] != '') { - $datasource_class = $field['datasource']['class']; - $datasource_function = $field['datasource']['function']; - $app->uses($datasource_class); - $record = array(); - $values = $app->$datasource_class->$datasource_function($field, $record); - } else { - $this->errorMessage .= "Custom datasource class or function is empty
\r\n"; - } - } - return $values; - } - - public function getSearchSQL($sql_where = '') - { - global $db; - - //* Get config variable - $list_name = $this->listDef['name']; - $search_prefix = $this->listDef['search_prefix']; - - //* store retrieval query - foreach($this->listDef['item'] as $i) { - $field = $i['field']; - - //*TODO: comment = hat sich die suche ge�ndert - if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){ - $this->searchChanged = 1; - } - - //* Store field in session - if(isset($_REQUEST[$search_prefix.$field])){ - $_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field]; - } - - if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){ - if(is_array($i['value'])) { - $out = ''; - foreach($i['value'] as $k => $v) { - // TODO: this could be more elegant - $selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field]) - && $k == $_SESSION['search'][$list_name][$search_prefix.$field] - && $_SESSION['search'][$list_name][$search_prefix.$field] != '') - ? ' SELECTED' : ''; - $out .= "\r\n"; - } - } - $this->searchValues[$search_prefix.$field] = $out; - } else { - if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){ - $this->searchValues[$search_prefix.$field] = $_SESSION['search'][$list_name][$search_prefix.$field]; - } - } - } - - //* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name]; - foreach($this->listDef['item'] as $i) { - $field = $i['field']; - // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and"; - if(isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_SESSION['search'][$list_name][$search_prefix.$field] != ''){ - $sql_where .= " $field ".$i['op']." '".$i['prefix'].$_SESSION['search'][$list_name][$search_prefix.$field].$i['suffix']."' and"; - } - } - - return ( $sql_where != '' ) ? $sql_where = substr($sql_where,0,-3) : '1'; - } - - public function getPagingSQL($sql_where = '1') - { - global $app, $conf; - - //* Get Config variables - $list_name = $this->listDef['name']; - $search_prefix = $this->listDef['search_prefix']; - $records_per_page = $this->listDef['records_per_page']; - $table = $this->listDef['table']; - - //* set PAGE to zero, if in session not set - if(!isset($_SESSION['search'][$list_name]['page']) || $_SESSION['search'][$list_name]['page'] == ''){ - $_SESSION['search'][$list_name]['page'] = 0; - } - - //* set PAGE to worth request variable "PAGE" - ? setze page auf wert der request variablen "page" - if(isset($_REQUEST["page"])) $_SESSION["search"][$list_name]["page"] = $_REQUEST["page"]; - - //* PAGE to 0 set, if look for themselves ? page auf 0 setzen, wenn suche sich ge�ndert hat. - if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0; - - $sql_von = $_SESSION['search'][$list_name]['page'] * $records_per_page; - $record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM $table WHERE $sql_where"); - $pages = intval(($record_count['anzahl'] - 1) / $records_per_page); - - - $vars['list_file'] = $_SESSION['s']['module']['name'].'/'.$this->listDef['file']; - $vars['page'] = $_SESSION['search'][$list_name]['page']; - $vars['last_page'] = $_SESSION['search'][$list_name]['page'] - 1; - $vars['next_page'] = $_SESSION['search'][$list_name]['page'] + 1; - $vars['pages'] = $pages; - $vars['max_pages'] = $pages + 1; - $vars['records_gesamt'] = $record_count['anzahl']; - $vars['page_params'] = (isset($this->listDef['page_params'])) ? $this->listDef['page_params'] : ''; - //$vars['module'] = $_SESSION['s']['module']['name']; - - if($_SESSION['search'][$list_name]['page'] > 0) $vars['show_page_back'] = 1; - if($_SESSION['search'][$list_name]['page'] <= $vars['pages'] - 1) $vars['show_page_next'] = 1; - - $this->pagingValues = $vars; - $this->pagingHTML = $this->getPagingHTML($vars); - - //* Return limit sql - return "LIMIT $sql_von, $records_per_page"; - } - - public function getPagingHTML($vars) - { - global $app; - $content = '' - .'   '; - //* Show Back - if(isset($vars['show_page_back']) && $vars['show_page_back'] == 1){ - $content .= '' - .' '; - } - $content .= ' '.$app->lng('Page').' '.$vars['next_page'].' '.$app->lng('of').' '.$vars['max_pages'].' '; - //* Show Next - if(isset($vars['show_page_next']) && $vars['show_page_next'] == 1){ - $content .= '' - .'   '; - } - $content .= '' - .''; - return $content; - } - - public function getPagingHTMLasTXT($vars) - { - global $app; - $content = '[|<< ]'; - if($vars['show_page_back'] == 1){ - $content .= '[<< '.$app->lng('Back').'] '; - } - $content .= ' '.$app->lng('Page').' '.$vars['next_page'].' '.$app->lng('of').' '.$vars['max_pages'].' '; - if($vars['show_page_next'] == 1){ - $content .= '['.$app->lng('Next').' >>] '; - } - $content .= '[ >>|]'; - return $content; - } - - public function getSortSQL() - { - global $app, $conf; - //* Get config vars - $sort_field = $this->listDef['sort_field']; - $sort_direction = $this->listDef['sort_direction']; - return ($sort_field != '' && $sort_direction != '') ? "ORDER BY $sort_field $sort_direction" : ''; - } - - public function decode($record) - { - if(is_array($record)) { - foreach($this->listDef['item'] as $field){ - $key = $field['field']; - if(isset($record[$key])) { - switch ($field['datatype']){ - case 'VARCHAR': - case 'TEXT': - $record[$key] = stripslashes($record[$key]); - break; - - case 'DATE': - $record[$key] = ($record[$key] > 0) ? date($this->dateformat,$record[$key]) : ''; - break; - - case 'INTEGER': - $record[$key] = intval($record[$key]); - break; - - case 'DOUBLE': - $record[$key] = $record[$key]; - break; - - case 'CURRENCY': - $record[$key] = number_format($record[$key], 2, ',', ''); - break; - - default: - $record[$key] = stripslashes($record[$key]); - } - } - } - } - return $record; - } - - public function encode($record) - { - if(is_array($record)) { - foreach($this->listDef['item'] as $field){ - $key = $field['field']; - switch($field['datatype']){ - - case 'VARCHAR': - case 'TEXT': - if(!is_array($record[$key])) { - $record[$key] = mysql_real_escape_string($record[$key]); - } else { - $record[$key] = implode($this->tableDef[$key]['separator'],$record[$key]); - } - break; - - case 'DATE': - if($record[$key] > 0) { - list($tag,$monat,$jahr) = explode('.',$record[$key]); - $record[$key] = mktime(0,0,0,$monat,$tag,$jahr); - } - break; - - case 'INTEGER': - $record[$key] = intval($record[$key]); - break; - - case 'DOUBLE': - $record[$key] = mysql_real_escape_string($record[$key]); - break; - - case 'CURRENCY': - $record[$key] = str_replace(',', '.', $record[$key]); - break; - } - } - } - return $record; - } - -} - +listDef = $liste; + $this->module = $module; + + //* Fill datasources + foreach($this->listDef['item'] as $key => $field) { + if(@is_array($field['datasource'])) { + $this->listDef['item'][$key]['value'] = $this->getDatasourceData($field); + } + } + + //* Set local Language File + $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_'.$this->listDef['name'].'_list.lng'; + if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$this->listDef['name'].'_list.lng'; + include($lng_file); + + $this->wordbook = $wb; + + return true; + } + + /** + * Get the key => value array of a form filed from a datasource definitiom + * + * @param field = array with field definition + * @param record = Dataset as array + * @return array key => value array for the value field of a form + */ + private function getDatasourceData($field) + { + global $app; + $values = array(); + + if($field['datasource']['type'] == 'SQL') { + + //** Preparing SQL string. We will replace some common placeholders + $querystring = $field['datasource']['querystring']; + $querystring = str_replace('{USERID}', $_SESSION['s']['user']['userid'], $querystring); + $querystring = str_replace('{GROUPID}', $_SESSION['s']['user']['default_group'], $querystring); + $querystring = str_replace('{GROUPS}', $_SESSION['s']['user']['groups'], $querystring); + //TODO: + //$table_idx = $this->formDef['db_table_idx']; + //$querystring = str_replace("{RECORDID}",$record[$table_idx],$querystring); + $app->uses('tform'); + $querystring = str_replace("{AUTHSQL}",$app->tform->getAuthSQL('r'),$querystring); + + //* Getting the records + $tmp_records = $app->db->queryAllRecords($querystring); + if($app->db->errorMessage != '') die($app->db->errorMessage); + if(is_array($tmp_records)) { + $key_field = $field['datasource']['keyfield']; + $value_field = $field['datasource']['valuefield']; + foreach($tmp_records as $tmp_rec) { + $tmp_id = $tmp_rec[$key_field]; + $values[$tmp_id] = $tmp_rec[$value_field]; + } + } + } + + if($field['datasource']['type'] == 'CUSTOM') { + //* Calls a custom class to validate this record + if($field['datasource']['class'] != '' and $field['datasource']['function'] != '') { + $datasource_class = $field['datasource']['class']; + $datasource_function = $field['datasource']['function']; + $app->uses($datasource_class); + $record = array(); + $values = $app->$datasource_class->$datasource_function($field, $record); + } else { + $this->errorMessage .= "Custom datasource class or function is empty
\r\n"; + } + } + return $values; + } + + public function getSearchSQL($sql_where = '') + { + global $db; + + //* Get config variable + $list_name = $this->listDef['name']; + $search_prefix = $this->listDef['search_prefix']; + + //* store retrieval query + foreach($this->listDef['item'] as $i) { + $field = $i['field']; + + //*TODO: comment = hat sich die suche ge�ndert + if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){ + $this->searchChanged = 1; + } + + //* Store field in session + if(isset($_REQUEST[$search_prefix.$field])){ + $_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field]; + } + + if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){ + if(is_array($i['value'])) { + $out = ''; + foreach($i['value'] as $k => $v) { + // TODO: this could be more elegant + $selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field]) + && $k == $_SESSION['search'][$list_name][$search_prefix.$field] + && $_SESSION['search'][$list_name][$search_prefix.$field] != '') + ? ' SELECTED' : ''; + $out .= "\r\n"; + } + } + $this->searchValues[$search_prefix.$field] = $out; + } else { + if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){ + $this->searchValues[$search_prefix.$field] = $_SESSION['search'][$list_name][$search_prefix.$field]; + } + } + } + + //* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name]; + foreach($this->listDef['item'] as $i) { + $field = $i['field']; + // if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and"; + if(isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_SESSION['search'][$list_name][$search_prefix.$field] != ''){ + $sql_where .= " $field ".$i['op']." '".$i['prefix'].$_SESSION['search'][$list_name][$search_prefix.$field].$i['suffix']."' and"; + } + } + + return ( $sql_where != '' ) ? $sql_where = substr($sql_where,0,-3) : '1'; + } + + public function getPagingSQL($sql_where = '1') + { + global $app, $conf; + + //* Get Config variables + $list_name = $this->listDef['name']; + $search_prefix = $this->listDef['search_prefix']; + $records_per_page = $this->listDef['records_per_page']; + $table = $this->listDef['table']; + + //* set PAGE to zero, if in session not set + if(!isset($_SESSION['search'][$list_name]['page']) || $_SESSION['search'][$list_name]['page'] == ''){ + $_SESSION['search'][$list_name]['page'] = 0; + } + + //* set PAGE to worth request variable "PAGE" - ? setze page auf wert der request variablen "page" + if(isset($_REQUEST["page"])) $_SESSION["search"][$list_name]["page"] = $_REQUEST["page"]; + + //* PAGE to 0 set, if look for themselves ? page auf 0 setzen, wenn suche sich ge�ndert hat. + if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0; + + $sql_von = $_SESSION['search'][$list_name]['page'] * $records_per_page; + $record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM $table WHERE $sql_where"); + $pages = intval(($record_count['anzahl'] - 1) / $records_per_page); + + + $vars['list_file'] = $_SESSION['s']['module']['name'].'/'.$this->listDef['file']; + $vars['page'] = $_SESSION['search'][$list_name]['page']; + $vars['last_page'] = $_SESSION['search'][$list_name]['page'] - 1; + $vars['next_page'] = $_SESSION['search'][$list_name]['page'] + 1; + $vars['pages'] = $pages; + $vars['max_pages'] = $pages + 1; + $vars['records_gesamt'] = $record_count['anzahl']; + $vars['page_params'] = (isset($this->listDef['page_params'])) ? $this->listDef['page_params'] : ''; + //$vars['module'] = $_SESSION['s']['module']['name']; + + if($_SESSION['search'][$list_name]['page'] > 0) $vars['show_page_back'] = 1; + if($_SESSION['search'][$list_name]['page'] <= $vars['pages'] - 1) $vars['show_page_next'] = 1; + + $this->pagingValues = $vars; + $this->pagingHTML = $this->getPagingHTML($vars); + + //* Return limit sql + return "LIMIT $sql_von, $records_per_page"; + } + + public function getPagingHTML($vars) + { + global $app; + $content = '' + .'   '; + //* Show Back + if(isset($vars['show_page_back']) && $vars['show_page_back'] == 1){ + $content .= '' + .' '; + } + $content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; + //* Show Next + if(isset($vars['show_page_next']) && $vars['show_page_next'] == 1){ + $content .= '' + .'   '; + } + $content .= '' + .''; + return $content; + } + + public function getPagingHTMLasTXT($vars) + { + global $app; + $content = '[|<< ]'; + if($vars['show_page_back'] == 1){ + $content .= '[<< '.$app->lng('page_back_txt').'] '; + } + $content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; + if($vars['show_page_next'] == 1){ + $content .= '['.$app->lng('page_next_txt').' >>] '; + } + $content .= '[ >>|]'; + return $content; + } + + public function getSortSQL() + { + global $app, $conf; + //* Get config vars + $sort_field = $this->listDef['sort_field']; + $sort_direction = $this->listDef['sort_direction']; + return ($sort_field != '' && $sort_direction != '') ? "ORDER BY $sort_field $sort_direction" : ''; + } + + public function decode($record) + { + if(is_array($record)) { + foreach($this->listDef['item'] as $field){ + $key = $field['field']; + if(isset($record[$key])) { + switch ($field['datatype']){ + case 'VARCHAR': + case 'TEXT': + $record[$key] = stripslashes($record[$key]); + break; + + case 'DATE': + $record[$key] = ($record[$key] > 0) ? date($this->dateformat,$record[$key]) : ''; + break; + + case 'INTEGER': + $record[$key] = intval($record[$key]); + break; + + case 'DOUBLE': + $record[$key] = $record[$key]; + break; + + case 'CURRENCY': + $record[$key] = number_format($record[$key], 2, ',', ''); + break; + + default: + $record[$key] = stripslashes($record[$key]); + } + } + } + } + return $record; + } + + public function encode($record) + { + if(is_array($record)) { + foreach($this->listDef['item'] as $field){ + $key = $field['field']; + switch($field['datatype']){ + + case 'VARCHAR': + case 'TEXT': + if(!is_array($record[$key])) { + $record[$key] = mysql_real_escape_string($record[$key]); + } else { + $record[$key] = implode($this->tableDef[$key]['separator'],$record[$key]); + } + break; + + case 'DATE': + if($record[$key] > 0) { + list($tag,$monat,$jahr) = explode('.',$record[$key]); + $record[$key] = mktime(0,0,0,$monat,$tag,$jahr); + } + break; + + case 'INTEGER': + $record[$key] = intval($record[$key]); + break; + + case 'DOUBLE': + $record[$key] = mysql_real_escape_string($record[$key]); + break; + + case 'CURRENCY': + $record[$key] = str_replace(',', '.', $record[$key]); + break; + } + } + } + return $record; + } + + function lng($msg) { + global $app; + + if(isset($this->wordbook[$msg])) { + return $this->wordbook[$msg]; + } else { + return $app->lng($msg); + } + } + +} + ?> \ No newline at end of file diff --git a/interface/lib/classes/listform_actions.inc.php b/interface/lib/classes/listform_actions.inc.php index ea0f47692c..e90bdc81b7 100644 --- a/interface/lib/classes/listform_actions.inc.php +++ b/interface/lib/classes/listform_actions.inc.php @@ -1,173 +1,169 @@ - -* @copyright Copyright © 2005, Till Brehm -*/ - -class listform_actions { - - private $id; - public $idx_key; - public $DataRowColor; - public $SQLExtWhere = ''; - public $SQLOrderBy = ''; - - public function onLoad() - { - global $app, $conf, $list_def_file; - - $app->uses('tpl,listform,tform'); - - //* Clear session variable that is used when lists are embedded with the listview plugin - $_SESSION['s']['form']['return_to'] = ''; - - // Load list definition - $app->listform->loadListDef($list_def_file); - - if(!is_file('templates/'.$app->listform->listDef["name"].'_list.htm')) { - $app->uses('listform_tpl_generator'); - $app->listform_tpl_generator->buildHTML($app->listform->listDef); - } - - $app->tpl->newTemplate("listpage.tpl.htm"); - $app->tpl->setInclude('content_tpl','templates/'.$app->listform->listDef["name"].'_list.htm'); - - // Getting Datasets from DB - $records = $app->db->queryAllRecords($this->getQueryString()); - - $this->DataRowColor = "#FFFFFF"; - $records_new = ''; - if(is_array($records)) { - $this->idx_key = $app->listform->listDef["table_idx"]; - foreach($records as $rec) { - $records_new[] = $this->prepareDataRow($rec); - } - } - - $app->tpl->setLoop('records',$records_new); - - $this->onShow(); - - - } - - public function prepareDataRow($rec) - { - global $app; - - $rec = $app->listform->decode($rec); - - //* Alternating datarow colors - $this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF'; - $rec['bgcolor'] = $this->DataRowColor; - - //* substitute value for select fields - foreach($app->listform->listDef['item'] as $field) { - $key = $field['field']; - if(isset($field['formtype']) && $field['formtype'] == 'SELECT') { - if(strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') { - // Set a additional image variable for bolean fields - $rec['_'.$key.'_'] = (strtolower($rec[$key]) == 'y')?'x16/tick_circle.png':'x16/cross_circle.png'; - } - //* substitute value for select field - $rec[$key] = @$field['value'][$rec[$key]]; - } - } - - //* The variable "id" contains always the index variable - $rec['id'] = $rec[$this->idx_key]; - return $rec; - } - - private function getQueryString() { - global $app; - $sql_where = ''; - - //* Generate the search sql - if($app->listform->listDef['auth'] != 'no') { - if($_SESSION['s']['user']['typ'] == "admin") { - $sql_where = ''; - } else { - $sql_where = $app->tform->getAuthSQL('r').' and'; - } - } - if($this->SQLExtWhere != '') { - $sql_where .= ' '.$this->SQLExtWhere.' and'; - } - - $sql_where = $app->listform->getSearchSQL($sql_where); - $app->tpl->setVar($app->listform->searchValues); - - $order_by_sql = $this->SQLOrderBy; - - //* Generate SQL for paging - $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"; - } - - - private function onShow() - { - global $app; - - //* Set global Language File - $lng_file = ISPC_LIB_PATH.'/lang/'.$_SESSION['s']['language'].'.lng'; - if(!file_exists($lng_file)) - $lng_file = ISPC_LIB_PATH.'/lang/en.lng'; - include($lng_file); - $app->tpl->setVar($wb); - - //* Set local Language File - $lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_'.$app->listform->listDef['name'].'_list.lng'; - if(!file_exists($lng_file)) - $lng_file = 'lib/lang/en_'.$app->listform->listDef['name'].'_list.lng'; - include($lng_file); - $app->tpl->setVar($wb); - $app->tpl->setVar('form_action', $app->listform->listDef['file']); - - //* Parse the templates and send output to the browser - $this->onShowEnd(); - } - - private function onShowEnd() - { - global $app; - $app->tpl_defaults(); - $app->tpl->pparse(); - } -} - + +* @copyright Copyright © 2005, Till Brehm +*/ + +class listform_actions { + + private $id; + public $idx_key; + public $DataRowColor; + public $SQLExtWhere = ''; + public $SQLOrderBy = ''; + + public function onLoad() + { + global $app, $conf, $list_def_file; + + $app->uses('tpl,listform,tform'); + + //* Clear session variable that is used when lists are embedded with the listview plugin + $_SESSION['s']['form']['return_to'] = ''; + + // Load list definition + $app->listform->loadListDef($list_def_file); + + if(!is_file('templates/'.$app->listform->listDef["name"].'_list.htm')) { + $app->uses('listform_tpl_generator'); + $app->listform_tpl_generator->buildHTML($app->listform->listDef); + } + + $app->tpl->newTemplate("listpage.tpl.htm"); + $app->tpl->setInclude('content_tpl','templates/'.$app->listform->listDef["name"].'_list.htm'); + + // Getting Datasets from DB + $records = $app->db->queryAllRecords($this->getQueryString()); + + $this->DataRowColor = "#FFFFFF"; + $records_new = ''; + if(is_array($records)) { + $this->idx_key = $app->listform->listDef["table_idx"]; + foreach($records as $rec) { + $records_new[] = $this->prepareDataRow($rec); + } + } + + $app->tpl->setLoop('records',$records_new); + + $this->onShow(); + + + } + + public function prepareDataRow($rec) + { + global $app; + + $rec = $app->listform->decode($rec); + + //* Alternating datarow colors + $this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF'; + $rec['bgcolor'] = $this->DataRowColor; + + //* substitute value for select fields + foreach($app->listform->listDef['item'] as $field) { + $key = $field['field']; + if(isset($field['formtype']) && $field['formtype'] == 'SELECT') { + if(strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') { + // Set a additional image variable for bolean fields + $rec['_'.$key.'_'] = (strtolower($rec[$key]) == 'y')?'x16/tick_circle.png':'x16/cross_circle.png'; + } + //* substitute value for select field + $rec[$key] = @$field['value'][$rec[$key]]; + } + } + + //* The variable "id" contains always the index variable + $rec['id'] = $rec[$this->idx_key]; + return $rec; + } + + private function getQueryString() { + global $app; + $sql_where = ''; + + //* Generate the search sql + if($app->listform->listDef['auth'] != 'no') { + if($_SESSION['s']['user']['typ'] == "admin") { + $sql_where = ''; + } else { + $sql_where = $app->tform->getAuthSQL('r').' and'; + } + } + if($this->SQLExtWhere != '') { + $sql_where .= ' '.$this->SQLExtWhere.' and'; + } + + $sql_where = $app->listform->getSearchSQL($sql_where); + $app->tpl->setVar($app->listform->searchValues); + + $order_by_sql = $this->SQLOrderBy; + + //* Generate SQL for paging + $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"; + } + + + private function onShow() + { + global $app; + + //* Set global Language File + $lng_file = ISPC_LIB_PATH.'/lang/'.$_SESSION['s']['language'].'.lng'; + if(!file_exists($lng_file)) + $lng_file = ISPC_LIB_PATH.'/lang/en.lng'; + include($lng_file); + $app->tpl->setVar($wb); + + + $app->tpl->setVar($app->listform->wordbook); + $app->tpl->setVar('form_action', $app->listform->listDef['file']); + + //* Parse the templates and send output to the browser + $this->onShowEnd(); + } + + private function onShowEnd() + { + global $app; + $app->tpl_defaults(); + $app->tpl->pparse(); + } +} + ?> \ No newline at end of file -- GitLab