mirror of
https://github.com/e107inc/e107.git
synced 2025-01-29 18:47:54 +01:00
e_model obsolete code removal
This commit is contained in:
parent
0acdaaf867
commit
026c834c76
@ -9,8 +9,8 @@
|
||||
* e107 Base Model
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $
|
||||
* $Revision: 1.34 $
|
||||
* $Date: 2009-11-06 12:27:41 $
|
||||
* $Revision: 1.35 $
|
||||
* $Date: 2009-11-09 12:21:17 $
|
||||
* $Author: secretr $
|
||||
*/
|
||||
|
||||
@ -2184,631 +2184,4 @@ class e_admin_tree_model extends e_tree_model
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Experimental admin interface class. //TODO integrate with the above.
|
||||
// see e107_plugins/release/admin_config.php.
|
||||
class e_model_interface
|
||||
{
|
||||
var $fields;
|
||||
var $fieldpref;
|
||||
var $listQry;
|
||||
var $table;
|
||||
var $pid;
|
||||
var $mode; // as found in the URL query. $_GET['mode]
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
|
||||
global $user_pref; // e107::getConfig('user') ??
|
||||
|
||||
$this->mode = varset($_GET['mode']) ? $_GET['mode'] : 'list';
|
||||
|
||||
$column_pref_name = "admin_".$this->table."_columns";
|
||||
|
||||
if(isset($_POST['submit-e-columns']))
|
||||
{
|
||||
$user_pref[$column_pref_name] = $_POST['e-columns'];
|
||||
save_prefs('user');
|
||||
$this->mode = 'list';
|
||||
}
|
||||
|
||||
$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']))
|
||||
{
|
||||
// $_SESSION[$this->table."_batch"] = $_POST['execute_batch']; // DO we want this to 'stick'?
|
||||
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.
|
||||
{
|
||||
$_SESSION[$this->table."_filter"] = $_POST['filter_options'];
|
||||
list($tmp,$filterField,$filterValue) = explode('__',$_POST['filter_options']);
|
||||
$this->modifyListQry($_POST['searchquery'],$filterField,$filterValue);
|
||||
$this->mode = 'list';
|
||||
}
|
||||
|
||||
|
||||
if(varset($_POST['update']) || varset($_POST['create']))
|
||||
{
|
||||
|
||||
$id = intval($_POST['record_id']);
|
||||
$this->saveRecord($id);
|
||||
}
|
||||
|
||||
if(varset($_POST['delete']))
|
||||
{
|
||||
$id = key($_POST['delete']);
|
||||
$this->deleteRecord($id);
|
||||
$this->mode = "list";
|
||||
}
|
||||
|
||||
if(varset($_POST['saveOptions']))
|
||||
{
|
||||
$this->saveSettings();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$option = array();
|
||||
|
||||
switch($val['type'])
|
||||
{
|
||||
case 'boolean': //TODO modify description based on $val['parm]
|
||||
$option[$type.'__'.$key."__1"] = LAN_YES;
|
||||
$option[$type.'__'.$key."__0"] = LAN_NO;
|
||||
break;
|
||||
|
||||
case 'dropdown': // use the array $parm;
|
||||
foreach($val['parm'] as $k=>$name)
|
||||
{
|
||||
$option[$type.'__'.$key."__".$k] = $name;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'date': // use $parm to determine unix-style or YYYY-MM-DD
|
||||
//TODO last hour, today, yesterday, this-month, last-month etc.
|
||||
/* 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)
|
||||
{
|
||||
$option[$type. '__'.$key."__".$k] = $name;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'method':
|
||||
$method = $key;
|
||||
$list = $this->$method('',$type);
|
||||
foreach($list as $k=>$name)
|
||||
{
|
||||
$option[$type.'__'.$key."__".$k] = $name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(count($option)>0)
|
||||
{
|
||||
$text .= "\t".$frm->optgroup_open($optdiz[$type].$val['title'], $disabled)."\n";
|
||||
foreach($option as $okey=>$oval)
|
||||
{
|
||||
$sel = ($_SESSION[$this->table."_".$type] == $okey) ? TRUE : FALSE;
|
||||
$text .= $frm->option($oval, $okey,$sel)."\n";
|
||||
}
|
||||
$text .= "\t".$frm->optgroup_close()."\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$text .= "</select>";
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic DB Record Listing Function.
|
||||
* @return
|
||||
*/
|
||||
function listPage()
|
||||
{
|
||||
$ns = e107::getRender();
|
||||
$sql = e107::getDb();
|
||||
$frm = e107::getForm();
|
||||
$mes = e107::getMessage();
|
||||
$pref = e107::getConfig()->getPref();
|
||||
$tp = e107::getParser();
|
||||
|
||||
$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 = $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'>".
|
||||
$frm->colGroup($this->fields,$this->fieldpref).
|
||||
$frm->thead($this->fields,$this->fieldpref, 'mode='.$this->mode.'&fld=[FIELD]&asc=[ASC]&frm=[FROM]').
|
||||
|
||||
"<tbody>";
|
||||
|
||||
|
||||
if(!$total = $sql->db_Select_gen($this->listQry))
|
||||
{
|
||||
$text .= "\n<tr><td colspan='".count($this->fields)."' class='center middle'>".LAN_NO_RECORDS."</td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $this->listQry;
|
||||
$query .= ($_GET['fld'] && $_GET['asc']) ? " ORDER BY ".$_GET['fld']." ".$_GET['asc'] : "";
|
||||
$query .= " LIMIT ".$from.",".$amount;
|
||||
|
||||
$sql->db_Select_gen($query);
|
||||
$row = $sql->db_getList('ALL', FALSE, FALSE);
|
||||
|
||||
foreach($row as $field)
|
||||
{
|
||||
$text .= $frm->trow($this, $field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>";
|
||||
|
||||
$text .= $this->renderBatch();
|
||||
|
||||
$text .= "
|
||||
</fieldset>
|
||||
</form>
|
||||
";
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic DB Record Creation Form.
|
||||
* @param object $id [optional]
|
||||
* @return
|
||||
*/
|
||||
function createPage()
|
||||
{
|
||||
global $e_userclass, $e_event;
|
||||
|
||||
$id = varset($_POST['edit']) ? key($_POST['edit']) : "";
|
||||
|
||||
$tp = e107::getParser();
|
||||
$ns = e107::getRender();
|
||||
$sql = e107::getDb();
|
||||
$frm = e107::getForm();
|
||||
|
||||
|
||||
if($id)
|
||||
{
|
||||
$query = str_replace("{ID}",$id,$this->editQry);
|
||||
$sql->db_Select_gen($query);
|
||||
$row = $sql->db_Fetch(MYSQL_ASSOC);
|
||||
}
|
||||
else
|
||||
{
|
||||
$row = array();
|
||||
}
|
||||
|
||||
$text = "
|
||||
<form method='post' action='".e_SELF."?mode=list' id='dataform' enctype='multipart/form-data'>
|
||||
<fieldset id='core-cpage-create-general'>
|
||||
<legend class='e-hideme'>".$this->pluginTitle."</legend>
|
||||
<table cellpadding='0' cellspacing='0' class='adminedit'>
|
||||
<colgroup span='2'>
|
||||
<col class='col-label' />
|
||||
<col class='col-control' />
|
||||
</colgroup>
|
||||
<tbody>";
|
||||
|
||||
foreach($this->fields as $key=>$att)
|
||||
{
|
||||
if($att['forced']!==TRUE)
|
||||
{
|
||||
$text .= "
|
||||
<tr>
|
||||
<td class='label'>".$att['title']."</td>
|
||||
<td class='control'>".$this->renderElement($key,$row)."</td>
|
||||
</tr>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
<div class='buttons-bar center'>";
|
||||
|
||||
if($id)
|
||||
{
|
||||
$text .= $frm->admin_button('update', LAN_UPDATE, 'update');
|
||||
$text .= "<input type='hidden' name='record_id' value='".$id."' />";
|
||||
}
|
||||
else
|
||||
{
|
||||
$text .= $frm->admin_button('create', LAN_CREATE, 'create');
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>";
|
||||
|
||||
$ns->tablerender($this->pluginTitle." :: ".$this->adminMenu['create']['caption'], $text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic Save DB Record Function.
|
||||
* @param object $id [optional]
|
||||
* @return
|
||||
*/
|
||||
function saveRecord($id=FALSE)
|
||||
{
|
||||
global $e107cache, $admin_log, $e_event;
|
||||
|
||||
$sql = e107::getDb();
|
||||
$tp = e107::getParser();
|
||||
$mes = e107::getMessage();
|
||||
|
||||
$insert_array = array();
|
||||
|
||||
//TODO validation and sanitizing using above classes.
|
||||
|
||||
foreach($this->fields as $key=>$att)
|
||||
{
|
||||
if($att['forced']!=TRUE)
|
||||
{
|
||||
$insert_array[$key] = $_POST[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if($id)
|
||||
{
|
||||
$insert_array['WHERE'] = $this->primary." = ".$id;
|
||||
$status = $sql->db_Update($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED;
|
||||
$message = LAN_UPDATED; // deliberately ambiguous - to be used on success or error.
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = $sql->db_Insert($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED;
|
||||
$message = LAN_CREATED;
|
||||
}
|
||||
|
||||
|
||||
$mes->add($message, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic Delete DB Record Function.
|
||||
* @param object $id
|
||||
* @return
|
||||
*/
|
||||
function deleteRecord($id)
|
||||
{
|
||||
if(!$id || !$this->primary || !$this->table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$mes = e107::getMessage();
|
||||
$sql = e107::getDb();
|
||||
|
||||
$query = $this->primary." = ".$id;
|
||||
$status = $sql->db_Delete($this->table,$query) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED;
|
||||
$message = LAN_DELETED;
|
||||
$mes->add($message, $status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Render Form Element (edit page)
|
||||
* @param object $key
|
||||
* @param object $row
|
||||
* @return
|
||||
*/
|
||||
function renderElement($key,$row)
|
||||
{
|
||||
$frm = e107::getForm();
|
||||
|
||||
$att = ($this->mode == 'options') ? $this->prefs[$key] : $this->fields[$key];
|
||||
$value = $row[$key];
|
||||
|
||||
if($att['type']=='method')
|
||||
{
|
||||
$meth = $key;
|
||||
return $this->$meth($value);
|
||||
}
|
||||
|
||||
if($att['type']=='boolean')
|
||||
{
|
||||
return $frm->radio_switch($key, $row[$key]);
|
||||
}
|
||||
|
||||
return $frm->text($key, $row[$key], 50);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Render Field value (listing page)
|
||||
* @param object $key
|
||||
* @param object $row
|
||||
* @return
|
||||
*/
|
||||
function renderValue($key,$row) // NO LONGER REQUIRED. use $frm->trow();
|
||||
{
|
||||
$att = $this->fields[$key];
|
||||
//TODO add checkbox.
|
||||
|
||||
if($att['type']=='method')
|
||||
{
|
||||
$meth = $key;
|
||||
return $this->$meth($row[$key]);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
switch($att['type'])
|
||||
{
|
||||
case 'url':
|
||||
return "<a href='".$row[$key]."'>".$row[$key]."</a>";
|
||||
break;
|
||||
|
||||
default:
|
||||
return $row[$key];
|
||||
break;
|
||||
}
|
||||
return $row[$key] .$att['type'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic Options/Preferences Form.
|
||||
* @return
|
||||
*/
|
||||
function optionsPage()
|
||||
{
|
||||
$pref = e107::getConfig()->getPref();
|
||||
$frm = e107::getForm();
|
||||
$ns = e107::getRender();
|
||||
$mes = e107::getMessage();
|
||||
|
||||
//XXX Lan - Options
|
||||
$text = "
|
||||
<form method='post' action='".e_SELF."?".e_QUERY."'>
|
||||
<fieldset id='core-cpage-options'>
|
||||
<legend class='e-hideme'>".LAN_OPTIONS."</legend>
|
||||
<table cellpadding='0' cellspacing='0' class='adminform'>
|
||||
<colgroup span='2'>
|
||||
<col class='col-label' />
|
||||
<col class='col-control' />
|
||||
</colgroup>
|
||||
<tbody>\n";
|
||||
|
||||
|
||||
foreach($this->prefs as $key => $var)
|
||||
{
|
||||
$text .= "
|
||||
<tr>
|
||||
<td class='label'>".$var['title']."</td>
|
||||
<td class='control'>
|
||||
".$this->renderElement($key,$pref)."
|
||||
</td>
|
||||
</tr>\n";
|
||||
}
|
||||
|
||||
$text .= "</tbody>
|
||||
</table>
|
||||
<div class='buttons-bar center'>
|
||||
".$frm->admin_button('saveOptions', LAN_SAVE, 'submit')."
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
";
|
||||
|
||||
$ns->tablerender($this->pluginTitle." :: ".LAN_OPTIONS, $mes->render().$text);
|
||||
}
|
||||
|
||||
|
||||
function saveSettings() //TODO needs to use native e_model functions, validation etc.
|
||||
{
|
||||
global $pref, $admin_log;
|
||||
|
||||
unset($_POST['saveOptions'],$_POST['e-columns']);
|
||||
|
||||
foreach($_POST as $key=>$val)
|
||||
{
|
||||
e107::getConfig('core')->set($key,$val);
|
||||
}
|
||||
|
||||
e107::getConfig('core')->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generic Admin Menu Generator
|
||||
* @param object $action
|
||||
* @return
|
||||
*/
|
||||
function show_options()
|
||||
{
|
||||
|
||||
$action = $this->mode;
|
||||
|
||||
foreach($this->adminMenu as $key=>$val)
|
||||
{
|
||||
$var[$key]['text'] = $val['caption'];
|
||||
$var[$key]['link'] = e_SELF."?mode=".$key;
|
||||
$var[$key]['perm'] = $val['perm'];
|
||||
}
|
||||
|
||||
e_admin_menu($this->pluginTitle, $action, $var);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user