1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-21 05:02:02 +02:00

e_modeLinterface now handles batches and search/filtering with ease. :-)

This commit is contained in:
CaMer0n 2009-10-26 07:26:53 +00:00
parent ff87fb1fcb
commit c839c96825
4 changed files with 295 additions and 67 deletions

View File

@ -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
<fieldset id='core-newspost-list'>
<legend class='e-hideme'>".NWSLAN_4."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>
".$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]')."
<tbody>";
$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'))
{

View File

@ -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 = "<input type='image' class='action edit' name='edit[{$fieldvalues[$pid]}]' src='".ADMIN_EDIT_ICON_PATH."' title='".LAN_EDIT."' />";
$value .= "<input type='image' class='action delete' name='delete[{$fieldvalues[$pid]}]' src='".ADMIN_DELETE_ICON_PATH."' title='".LAN_DELETE." [ ID: {$fieldvalues[$pid]} ]' />";
$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 = "<a href='".$value ."'>".$value."</a>";
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'], '...');

View File

@ -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 = "<form method='post' action='".e_SELF."?".e_QUERY."'>
<div class='left' style='padding-bottom:10px'>\n"; //TODO assign CSS
$text .= "<input class='tbox' type='text' name='searchquery' size='20' value=\"".$_POST['searchquery']."\" maxlength='50' />\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 .= "</div></form>\n";
return $text;
}
function renderBatch()
{
$frm = e107::getForm();
if(!varset($this->fields['checkboxes']))
{
return;
}
$text = "<div class='buttons-bar left'>
<img src='".e_IMAGE_ABS."generic/branchbottom.gif' alt='' class='icon action' />";
$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 .= "</div>";
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 .= "</select>";
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 = "<form method='post' action='".e_SELF."?mode=create'>
$text = $this->renderFilter();
$text .= "<form method='post' action='".e_SELF."'>
<fieldset id='core-".$this->table."-list'>
<legend class='e-hideme'>".$this->pluginTitle."</legend>
<table cellpadding='0' cellspacing='0' class='adminlist'>".
@ -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 .= "<tr>\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<td ".$class.">".$this->renderValue($key,$field)."</td>\n" : "";
}
$text .= "</tr>\n";
$text .= $frm->trow($this, $field);
}
}
$text .= "
</tbody>
</table>
</table>";
$text .= $this->renderBatch();
$text .= "
</fieldset>
</form>
";
//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 = "<input type='image' class='action edit' name='edit[{$row[$id]}]' src='".ADMIN_EDIT_ICON_PATH."' title='".LAN_EDIT."' />";
$text .= "<input type='image' class='action delete' name='delete[{$row[$id]}]' src='".ADMIN_DELETE_ICON_PATH."' title='".LAN_DELETE." [ ID: {$row[$id]} ]' />";
return $text;
// $text = "<input type='image' class='action edit' name='edit[{$row[$id]}]' src='".ADMIN_EDIT_ICON_PATH."' title='".LAN_EDIT."' />";
// $text .= "<input type='image' class='action delete' name='delete[{$row[$id]}]' src='".ADMIN_DELETE_ICON_PATH."' title='".LAN_DELETE." [ ID: {$row[$id]} ]' />";
// 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)
{

View File

@ -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 = "
<script type='text/javascript'>
if(typeof e107Admin == 'undefined') var e107Admin = {}
/**
* OnLoad Init Control
*/
e107Admin.initRules = {
'Helper': true,
'AdminMenu': false
}
</script>
<script type='text/javascript' src='".e_FILE_ABS."jslib/core/admin.js'></script>
";
return $ret;
}
?>