'name'); /** * Action to use on our create link */ public $createAction = 'create'; /** * Initiates our template */ function __construct() { $this->tpl = new TemplateParser; $this->tpl->load('listview.html'); } /** * Will be called if there are no rows * */ function noRows() { $fields = array_keys($this->allowedFields); foreach($fields as $field) { $this->tpl->define('TITLE',translate($field)); $this->tpl->parse('titlecolumn'); } $this->tpl->define('columns',count($this->allowedFields)); $this->tpl->parse('none'); } /** * Generate WHERE part of the query * * @param $existing string Current or default where query WITHOUT "WHERE" * @param $keep bool Keep the default query when searching? * * @return string WHERE part of the query * */ function whereQuery($existing='',$keep=false) { $_GET['whereField'] = urldecode($_GET['whereField']); $_GET['whereValue'] = urldecode($_GET['whereValue']); if($this->allowedFields[$_GET['whereField']] && !empty($_GET['whereValue'])) { if(!$keep) $existing = ''; if(!empty($existing)) $existing .= ' AND'; $existing .= " `" . $this->allowedFields[$_GET['whereField']] . "` LIKE '%" . $_GET['whereValue'] . "%'"; } else { // clean our variables unset($_GET['whereValue'],$_GET['whereField']); } if(!empty($existing)) $existing = ' WHERE ' . $existing . ' '; return $existing; } /** * Generate ORDER BY part of the query * * @param $existing string Current or default order by query WITHOUT "ORDER BY" * @param $keep bool Keep the default query when searching? * * @return string ORDER BY part of the query * */ function orderByQuery($existing='',$keep=false) { $_GET['orderBy'] = urldecode($_GET['orderBy']); $_GET['order'] = strtoupper($_GET['order']); if($this->allowedFields[$_GET['orderBy']] && !empty($_GET['order'])) { if($_GET['order'] != 'ASC' && $_GET['order'] != 'DESC') $_GET['order'] = 'ASC'; if(!$keep) $existing = ''; if(!empty($existing)) $existing .= ', '; $existing .= " " . $this->allowedFields[$_GET['orderBy']] . " " . $_GET['order'] . " "; } else { // clean our variables unset($_GET['orderBy'],$_GET['order']); } if(!empty($existing)) $existing = ' ORDER BY ' . $existing . ' '; return $existing; } /** * Adds a row to our list * * @param array $values */ function addRow(array $values) { foreach($values as $title => $value) { if($this->rows % 2 == 0) $this->tpl->define('CLASS','lightrow'); else $this->tpl->define('CLASS','darkrow'); $this->tpl->define('VALUE',$value); $this->tpl->parse('column'); // title columns if($this->rows == 0) { // check whether we can sort on this field if(isset($this->allowedFields[$title])) { if($title == $_GET['orderBy']) { if($_GET['order'] == 'ASC') { $icon = ' '; $order = 'DESC'; } else { $icon = ' '; $order = 'ASC'; } } else { $icon = ''; $order = 'ASC'; } $title = '' . translate($title) . $icon . ''; } else { $title = translate($title); } $this->tpl->define('TITLE',$title); $this->tpl->parse('titlecolumn'); } } $this->tpl->parse('row'); $this->rows++; } /** * Builds our listview * * @return string HTML output */ function output() { $this->tpl->define('abcfield', $this->abcField); $this->tpl->define('module', $_GET['module']); $this->tpl->define('action', $_GET['action']); $this->tpl->define('wherevalue', $_GET['whereValue']); $this->tpl->define('order', $_GET['order']); $this->tpl->define('orderby', $_GET['orderby']); $this->tpl->define('createaction',$this->createAction); // parse searchfields foreach($this->allowedFields as $field => $tablefield) { if($field == $_GET['whereField']) $selected = 'selected="selected"'; else $selected = ''; $fields .= ''; } $this->tpl->define('wherefields',$fields); $abc = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); foreach($abc as $letter) { if($_GET['whereValue'] == $letter) $letter = '' . $letter . ''; $this->tpl->define('LETTER',$letter); $this->tpl->parse('abc'); } if($_GET['whereValue'] && $_GET['whereField']) { $this->tpl->define('wherefield',urldecode($_GET['whereField'])); $this->tpl->parse('searching'); } $this->tpl->define('TITLE',$this->title); return $this->tpl->publish(); } }