From c839c968255e7ad8241eb9000c96132d961034cf Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Mon, 26 Oct 2009 07:26:53 +0000 Subject: [PATCH] e_modeLinterface now handles batches and search/filtering with ease. :-) --- e107_admin/newspost.php | 25 +-- e107_handlers/form_handler.php | 31 +++- e107_handlers/model_class.php | 223 +++++++++++++++++++++++--- e107_plugins/release/admin_config.php | 83 +++++++--- 4 files changed, 295 insertions(+), 67 deletions(-) diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 5887c01a6..b58685dcd 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -9,9 +9,9 @@ * News Administration * * $Source: /cvs_backup/e107_0.8/e107_admin/newspost.php,v $ - * $Revision: 1.60 $ - * $Date: 2009-10-23 18:14:41 $ - * $Author: secretr $ + * $Revision: 1.61 $ + * $Date: 2009-10-26 07:26:47 $ + * $Author: e107coders $ */ require_once("../class2.php"); @@ -259,7 +259,7 @@ class admin_newspost $this->fieldpref = varset($user_pref['admin_news_columns'], array('news_id', 'news_title', 'news_author', 'news_render_type', 'options')); - $this->_fields = array( + $this->fields = array( 'checkboxes' => array('title' => '', 'type' => null, 'width' => '3%', 'thclass' => 'center first', 'class' => 'center', 'nosort' => true, 'toggle' => 'news_selected', 'forced' => TRUE), 'news_id' => array('title' => LAN_NEWS_45, 'type' => 'number', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false), 'news_title' => array('title' => NWSLAN_40, 'type' => 'text', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), @@ -1054,7 +1054,7 @@ class admin_newspost } - $field_columns = $this->_fields; + $field_columns = $this->fields; $e107 = e107::getInstance(); @@ -1117,8 +1117,8 @@ class admin_newspost
".NWSLAN_4." - ".$frm->colGroup($this->_fields, $this->fieldpref)." - ".$frm->thead($this->_fields, $this->fieldpref, 'main.[FIELD].[ASC].[FROM]')." + ".$frm->colGroup($this->fields, $this->fieldpref)." + ".$frm->thead($this->fields, $this->fieldpref, 'main.[FIELD].[ASC].[FROM]')." "; $ren_type = array("default","title","other-news","other-news 2"); @@ -1143,7 +1143,7 @@ class admin_newspost } // AUTO RENDER - $text .= $frm->trow($this->_fields, $this->fieldpref, $row); + $text .= $frm->trow($this, $row); } $text .= " @@ -2262,7 +2262,7 @@ class admin_newspost function ajax_exec_searchValue() { $frm = e107::getForm(); - echo $frm->filterValue($_POST['filtertype'], $this->_fields); + echo $frm->filterValue($_POST['filtertype'], $this->fields); } */ @@ -2564,12 +2564,13 @@ class admin_newspost $var['pref']['link'] = e_SELF."?pref"; $var['pref']['perm'] = "0"; - $c = $e107->sql->db_Count('submitnews'); - if ($c) { +//TODO remove commented code before release. + // $c = $e107->sql->db_Count('submitnews'); + // if ($c) { $var['sn']['text'] = NWSLAN_47." ({$c})"; $var['sn']['link'] = e_SELF."?sn"; $var['sn']['perm'] = "N"; - } + // } if (getperms('0')) { diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 5e6a90232..9c8656aa4 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -9,8 +9,8 @@ * Form Handler * * $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ - * $Revision: 1.57 $ - * $Date: 2009-10-26 01:23:19 $ + * $Revision: 1.58 $ + * $Date: 2009-10-26 07:26:47 $ * $Author: e107coders $ * */ @@ -802,13 +802,19 @@ class e_form } - function trow($fieldarray, $currentlist, $fieldvalues) + function trow($obj, $fieldvalues) { $cnt = 0; $ret = ''; + $fieldarray = $obj->fields; + $currentlist = $obj->fieldpref; + $pid = $obj->pid; + + foreach ($fieldarray as $field => $data) { + //Not found if(!$data['forced'] && !in_array($field, $currentlist)) { @@ -834,20 +840,22 @@ class e_form $value = $fieldvalues[$field]; $parms = array(); - if(isset($data['colparms'])) + if(isset($data['colparms'])) //TODO rename to 'parms'. { if(!is_array($data['colparms'])) parse_str($data['colparms'], $data['colparms']); $parms = $data['colparms']; } - switch($field) + switch($field) // special fields { case 'options': + $value = ""; + $value .= ""; $data['type'] = 'text'; break; case 'checkboxes': - $value = $this->checkbox(vartrue($data['toggle'], 'multiselect').'[]', $value); + $value = $this->checkbox(vartrue($data['toggle'], 'multiselect').'['.$fieldvalues[$pid].']', $fieldvalues[$pid]); $data['type'] = 'text'; break; } @@ -887,6 +895,15 @@ class e_form case 'boolean': $value = $value ? ADMIN_TRUE_ICON : '';// TODO - ADMIN_FALSE_ICON break; + + case 'url': + $value = "".$value.""; + break; + + case 'method': // Custom Function + $meth = $field; + $value = $obj->$meth($value,$obj->mode); + break; //TODO - form_userclass, order,... and maybe more types @@ -895,7 +912,7 @@ class e_form break; } - //TODO - this should be done per type! + //TODO - this should be done per type! if(vartrue($parms['truncate'])) { $value = e107::getParser()->text_truncate($value, $parms['truncate'], '...'); diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index 419934da8..bc01f1ea7 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -9,8 +9,8 @@ * e107 Base Model * * $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $ - * $Revision: 1.21 $ - * $Date: 2009-10-23 04:25:13 $ + * $Revision: 1.22 $ + * $Date: 2009-10-26 07:26:47 $ * $Author: e107coders $ */ @@ -1651,7 +1651,7 @@ class e_model_interface var $fieldpref; var $listQry; var $table; - var $primary; + var $pid; var $mode; // as found in the URL query. $_GET['mode] function __construct() @@ -1676,6 +1676,33 @@ class e_model_interface } $this->fieldpref = (varset($user_pref[$column_pref_name])) ? $user_pref[$column_pref_name] : array_keys($this->fields); + + foreach($this->fields as $k=>$v) // Find Primary table ID field (before checkboxes is run. ). + { + if(vartrue($v['primary'])) + { + $this->pid = $k; + } + } + + + if(varset($_POST['execute_batch'])) + { + if(vartrue($_POST['multiselect'])) + { + list($tmp,$field,$value) = explode('__',$_POST['execute_batch']); + $this->processBatch($field,$_POST['multiselect'],$value); + } + $this->mode = 'list'; + } + + if(varset($_POST['execute_filter'])) // Filter the db records. + { + list($tmp,$filterField,$filterValue) = explode('__',$_POST['filter_options']); + $this->modifyListQry($_POST['searchquery'],$filterField,$filterValue); + $this->mode = 'list'; + } + if(varset($_POST['update']) || varset($_POST['create'])) { @@ -1696,13 +1723,163 @@ class e_model_interface $this->saveSettings(); } - if($this->mode) + if(varset($_POST['edit'])) + { + $this->mode = 'create'; + } + + + if($this->mode) // Render Page. { $method = $this->mode."Page"; $this->$method(); } } + + + function modifyListQry($search,$filterField,$filterValue) + { + $searchQry = array(); + + if(vartrue($filterField) && vartrue($filterValue)) + { + $searchQry[] = $filterField." = '".$filterValue."'"; + } + + $filter = array(); + + foreach($this->fields as $key=>$var) + { + if(($var['type'] == 'text' || $var['type'] == 'method') && vartrue($search)) + { + $filter[] = "(".$key." REGEXP ('".$search."'))"; + } + } + if(count($filter)>0) + { + $searchQry[] = " (".implode(" OR ",$filter)." )"; + } + if(count($searchQry)>0) + { + $this->listQry .= " WHERE ".implode(" AND ",$searchQry); + } + } + + + + + function processBatch($field,$ids,$value) + { + $sql = e107::getDb(); + + if($field == 'delete') + { + return $sql->db_Delete($this->table,$this->pid." IN (".implode(",",$ids).")"); + } + + if(!is_numeric($value)) + { + $value = "'".$value."'"; + } + + $query = $field." = ".$value." WHERE ".$this->pid." IN (".implode(",",$ids).") "; + $count = $sql->db_Update($this->table,$query); + } + + function renderFilter() + { + $frm = e107::getForm(); + $text = " +
\n"; //TODO assign CSS + $text .= "\n"; + $text .= $frm->select_open('filter_options', array('class' => 'tbox select e-filter-options', 'id' => false)); + $text .= $frm->option('Display All', ''); + $text .= $this->renderBatchFilter('filter'); + + $text .= $frm->admin_button('execute_filter', ADLAN_142); + $text .= "
\n"; + return $text; + } + + function renderBatch() + { + $frm = e107::getForm(); + + + if(!varset($this->fields['checkboxes'])) + { + return; + } + + $text = "
+ "; + $text .= $frm->select_open('execute_batch', array('class' => 'tbox select e-execute-batch', 'id' => false)). + $frm->option('With selected...', ''); + $frm->option(LAN_DELETE, 'batch__delete'); + $text .= $this->renderBatchFilter('batch'); + $text .= "
"; + + return $text; + + } + + function renderBatchFilter($type='batch') // Common function used for both batches and filters. + { + $frm = e107::getForm(); + + $optdiz = array('batch' => 'Modify ', 'filter'=> 'Filter by '); + + foreach($this->fields as $key=>$val) + { + if(!varset($val[$type])) + { + continue; + } + $text .= "\t".$frm->optgroup_open($optdiz[$type].$val['title'], $disabled)."\n"; + if(!is_array($val[$type])) + { + switch($val['type']) + { + case 'boolean': //TODO modify description based on $val['parm] + $text .= $frm->option(LAN_YES, $type.'__'.$key."__1"); + $text .= $frm->option(LAN_NO, $type.'__'.$key."__0"); + break; + + case 'dropdown': // use the array $parm; + foreach($val['parm'] as $k=>$name) + { + $text .= $frm->option($name, $type.'__'.$key."__".$k); + } + break; + + case 'userclass': + $classes = e107::getUserClass()->uc_required_class_list($val['parm']); + foreach($classes as $k=>$name) + { + $text .= $frm->option($name, $type. '__'.$key."__".$k); + } + break; + + case 'method': + $method = $key; + $list = $this->$method('',$type); + foreach($list as $k=>$name) + { + $text .= $frm->option($name, $type.'__'.$key."__".$k); + } + break; + } + } + $text .= $frm->optgroup_close()."\n"; + + } + + $text .= ""; + + return $text; + + } /** @@ -1720,8 +1897,8 @@ class e_model_interface $amount = 20; // do we hardcode or let the plugin developer decide.. OR - a pref in admin? $from = vartrue($_GET['frm']) ? $_GET['frm'] : 0; //TODO sanitize?. - - $text = " + $text = $this->renderFilter(); + $text .= "
".$this->pluginTitle."
". @@ -1743,29 +1920,27 @@ class e_model_interface $sql->db_Select_gen($query); $row = $sql->db_getList('ALL', FALSE, FALSE); - + foreach($row as $field) { - $text .= "\n"; - foreach($this->fields as $key=>$att) - { - $class = vartrue($this->fields[$key]['thclass']) ? "class='".$this->fields[$key]['thclass']."'" : ""; - $text .= (in_array($key,$this->fieldpref) || $att['forced']==TRUE) ? "\t\n" : ""; - } - $text .= "\n"; + $text .= $frm->trow($this, $field); } + } $text .= " -
".$this->renderValue($key,$field)."
+ "; + + $text .= $this->renderBatch(); + + $text .= "
"; - //TODO Auto next/prev - $parms = $total.",".$amount.",".$from.",".e_SELF.'?action='.$this->mode.'&frm=[FROM]'; - $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); + $parms = $total.",".$amount.",".$from.",".e_SELF.'?action='.$this->mode.'&frm=[FROM]'; + $text .= $tp->parseTemplate("{NEXTPREV={$parms}}"); $ns->tablerender($this->pluginTitle." :: ".$this->adminMenu['list']['caption'], $mes->render().$text); } @@ -1949,7 +2124,7 @@ class e_model_interface * @param object $row * @return */ - function renderValue($key,$row) + function renderValue($key,$row) // NO LONGER REQUIRED. use $frm->trow(); { $att = $this->fields[$key]; //TODO add checkbox. @@ -1964,9 +2139,9 @@ class e_model_interface if($key == "options") { $id = $this->primary; - $text = ""; - $text .= ""; - return $text; + // $text = ""; + // $text .= ""; + // return $text; } switch($att['type']) @@ -2052,10 +2227,10 @@ class e_model_interface * @param object $action * @return */ - function show_options($action) + function show_options() { - $action = varset($_GET['mode'],'list'); + $action = $this->mode; foreach($this->adminMenu as $key=>$val) { diff --git a/e107_plugins/release/admin_config.php b/e107_plugins/release/admin_config.php index 4859b03a9..8d5ca5622 100644 --- a/e107_plugins/release/admin_config.php +++ b/e107_plugins/release/admin_config.php @@ -9,8 +9,8 @@ * e107 Release Plugin * * $Source: /cvs_backup/e107_0.8/e107_plugins/release/admin_config.php,v $ - * $Revision: 1.7 $ - * $Date: 2009-10-23 04:25:19 $ + * $Revision: 1.8 $ + * $Date: 2009-10-26 07:26:53 $ * $Author: e107coders $ * */ @@ -23,20 +23,25 @@ class releasePlugin extends e_model_interface { function __construct() - { + { + + $this->pluginTitle = "e107 Release"; + + $this->table = "release"; + $this->fields = array( - - 'release_id' => array('title'=> ID, 'width'=>'5%', 'forced'=> TRUE, 'primary'=>TRUE), - 'release_type' => array('title'=> 'type', 'type' => 'method', 'width'=>'auto'), - 'release_folder' => array('title'=> 'folder', 'type' => 'text', 'width' => 'auto'), // User name - 'release_name' => array('title'=> 'name', 'type' => 'text', 'width' => 'auto'), - 'release_version' => array('title'=> 'version', 'type' => 'text', 'width' => 'auto'), - 'release_author' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left'), - 'release_authorURL' => array('title'=> LAN_AUTHOR.'URL', 'type' => 'url', 'width' => 'auto', 'thclass' => 'left'), - 'release_date' => array('title'=> LAN_DATE, 'type' => 'text', 'width' => 'auto'), - 'release_compatibility' => array('title'=> 'compatib', 'type' => 'text', 'width' => '10%', 'thclass' => 'center' ), - 'release_url' => array('title'=> 'URL', 'type' => 'url', 'width' => '10%', 'thclass' => 'center' ), - 'options' => array('title'=> LAN_OPTIONS, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last') + 'checkboxes' => array('title'=> '', 'type' => '', 'width'=>'5%', 'thclass' =>'center', 'forced'=> TRUE, 'class'=>'center'), + 'release_id' => array('title'=> ID, 'type' => '', 'width'=>'5%', 'thclass' => '', 'forced'=> TRUE, 'primary'=>TRUE), + 'release_type' => array('title'=> 'Type', 'type' => 'method', 'width'=>'auto', 'thclass' => '', 'batch' => TRUE, 'filter'=>TRUE), + 'release_folder' => array('title'=> 'Folder', 'type' => 'text', 'width' => 'auto', 'thclass' => ''), + 'release_name' => array('title'=> 'Name', 'type' => 'text', 'width' => 'auto', 'thclass' => ''), + 'release_version' => array('title'=> 'Version', 'type' => 'text', 'width' => 'auto', 'thclass' => ''), + 'release_author' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left'), + 'release_authorURL' => array('title'=> LAN_AUTHOR.'URL', 'type' => 'url', 'width' => 'auto', 'thclass' => 'left'), + 'release_date' => array('title'=> LAN_DATE, 'type' => 'text', 'width' => 'auto', 'thclass' => ''), + 'release_compatibility' => array('title'=> 'compatib', 'type' => 'text', 'width' => '10%', 'thclass' => 'center' ), + 'release_url' => array('title'=> 'URL', 'type' => 'userclass', 'width' => '10%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE), + 'options' => array('title'=> LAN_OPTIONS, 'type' => '', 'width' => '10%', 'thclass' => 'center last', 'class' => 'center last', 'forced'=>TRUE) ); $this->prefs = array( //TODO add option for core or plugin pref. @@ -45,13 +50,10 @@ class releasePlugin extends e_model_interface 'pref_folder' => array('title'=> 'folder', 'type' => 'boolean'), 'pref_name' => array('title'=> 'name', 'type' => 'text') ); - + $this->listQry = "SELECT * FROM #release"; // without any Order or Limit. $this->editQry = "SELECT * FROM #release WHERE release_id = {ID}"; - $this->table = "release"; - $this->primary = "release_id"; - $this->pluginTitle = "e107 Release"; - + $this->adminMenu = array( 'list' => array('caption'=>'Release List', 'perm'=>'0'), 'create' => array('caption'=>LAN_CREATE."/".LAN_EDIT, 'perm'=>'0'), @@ -61,11 +63,23 @@ class releasePlugin extends e_model_interface } // Custom View/Form-Element method. ie. Naming should match field/key with type=method. - function release_type($curVal) + + + function release_type($curVal,$mode) // not really necessary since we can use 'dropdown' - but just an example of a custom function. { - if($this->mode == 'list') + if($mode == 'list') { - return $curVal; + return $curVal.' (custom!)'; + } + + if($mode == 'batch') // Custom Batch List for release_type + { + return array('theme'=>"Theme","plugin"=>'Plugin'); + } + + if($mode == 'filter') // Custom Filter List for release_type + { + return array('theme'=>"Theme","plugin"=>'Plugin'); } $types = array("theme","plugin"); @@ -96,7 +110,28 @@ require_once(e_ADMIN."footer.php"); function admin_config_adminmenu() //TODO move this into e_model_interface { global $rp; - $rp->show_options($action); + $rp->show_options(); } + +function headerjs() // needed for the checkboxes - how can we remove the need to duplicate this code? +{ + require_once (e_HANDLER.'js_helper.php'); + $ret = " + + + "; + + return $ret; +} ?> \ No newline at end of file