mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 12:20:44 +02:00
Admin tools - more work
This commit is contained in:
@@ -542,7 +542,7 @@ class e_admin_response
|
||||
*/
|
||||
function getBody($namespace = 'default', $reset = false, $glue = '')
|
||||
{
|
||||
$content = varset($this->_body[$namespace]);
|
||||
$content = vartrue($this->_body[$namespace], array());
|
||||
if($reset)
|
||||
{
|
||||
$this->_body[$namespace] = array();
|
||||
@@ -886,7 +886,7 @@ class e_admin_dispatcher
|
||||
/**
|
||||
* @var e_admin_controller
|
||||
*/
|
||||
protected $_current_controller;
|
||||
protected $_current_controller = null;
|
||||
|
||||
/**
|
||||
* Required (set by child class).
|
||||
@@ -1109,6 +1109,7 @@ class e_admin_dispatcher
|
||||
protected function _initController()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$response = $this->getResponse();
|
||||
if(isset($this->controllerList[$request->getModeName()]) && isset($this->controllerList[$request->getModeName()]['controller']))
|
||||
{
|
||||
$class_name = $this->controllerList[$request->getModeName()]['controller'];
|
||||
@@ -1120,7 +1121,7 @@ class e_admin_dispatcher
|
||||
}
|
||||
if($class_name && class_exists($class_name))//NOTE: autoload in the play
|
||||
{
|
||||
$this->_current_controller = new $class_name();
|
||||
$this->_current_controller = new $class_name($request, $response);
|
||||
//give access to current request object, user defined init
|
||||
$this->_current_controller->setRequest($this->getRequest())->init();
|
||||
}
|
||||
@@ -1149,7 +1150,7 @@ class e_admin_dispatcher
|
||||
public function getDefaultController()
|
||||
{
|
||||
$class_name = $this->getDefaultControllerName();
|
||||
return new $class_name();
|
||||
return new $class_name($this->getRequest(), $this->getResponse());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1202,8 +1203,8 @@ class e_admin_dispatcher
|
||||
$var[$key]['link'] = (vartrue($val['url']) ? $tp->replaceConstants($val['url'], 'abs') : e_SELF).'?mode='.$tmp[0].'&action='.$tmp[1];
|
||||
$var[$key]['perm'] = $val['perm']; */
|
||||
}
|
||||
|
||||
e_admin_menu($this->menuTitle, $this->getMode().'/'.$this->getAction(), $var);
|
||||
$request = $this->getRequest();
|
||||
e_admin_menu($this->menuTitle, $request->getMode().'/'.$request->getAction(), $var);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1436,6 +1437,21 @@ class e_admin_controller
|
||||
return $this->getResponse()->getHeaderContent();
|
||||
}
|
||||
|
||||
public function getMode()
|
||||
{
|
||||
return $this->getRequest()->getMode();
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
return $this->getRequest()->getAction();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->getRequest()->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get response owned JS Helper instance, response proxy method
|
||||
*
|
||||
@@ -1609,3 +1625,868 @@ class e_admin_controller
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME - move everything from e_admin_controller_main except model auto-create related code
|
||||
class e_admin_controller_base extends e_admin_controller
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class e_admin_controller_main extends e_admin_controller_base
|
||||
{
|
||||
protected $fields = array();
|
||||
protected $fieldpref = array();
|
||||
protected $fieldTypes = array();
|
||||
protected $dataFields = array();
|
||||
protected $validationRules = array();
|
||||
protected $prefs = array();
|
||||
protected $pluginName;
|
||||
protected $listQry;
|
||||
protected $editQry;
|
||||
protected $table;
|
||||
protected $pid;
|
||||
protected $pluginTitle;
|
||||
protected $perPage = 20;
|
||||
|
||||
|
||||
/**
|
||||
* @var e_admin_model
|
||||
*/
|
||||
protected $_model = null;
|
||||
|
||||
/**
|
||||
* @var e_admin_tree_model
|
||||
*/
|
||||
protected $_tree_model = null;
|
||||
|
||||
/**
|
||||
* @var e_admin_tree_model
|
||||
*/
|
||||
protected $_ui = null;
|
||||
|
||||
/**
|
||||
* @var e_plugin_pref|e_core_pref
|
||||
*/
|
||||
protected $_pref = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param e_admin_request $request
|
||||
* @param e_admin_response $response
|
||||
* @param array $params [optional]
|
||||
*/
|
||||
public function __construct($request, $response, $params = array())
|
||||
{
|
||||
parent::__construct($request, $response, $params);
|
||||
if(!$this->pluginName)
|
||||
{
|
||||
$this->pluginName = 'core';
|
||||
}
|
||||
$this->_pref = $this->pluginName == 'core' ? e107::getConfig() : e107::getPlugConfig($this->pluginName);
|
||||
|
||||
$ufieldpref = $this->getUserPref();
|
||||
if($ufieldpref)
|
||||
{
|
||||
$this->fieldpref = $ufieldpref;
|
||||
}
|
||||
|
||||
$this->addTitle($this->pluginTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default is List action page
|
||||
* @return string
|
||||
*/
|
||||
public function DefaultPage()
|
||||
{
|
||||
return $this->getUI()->getList();
|
||||
}
|
||||
|
||||
/**
|
||||
* List action observer
|
||||
* @return void
|
||||
*/
|
||||
public function ListObserver()
|
||||
{
|
||||
$this->getTreeModel()->load();
|
||||
}
|
||||
|
||||
/**
|
||||
* List action header
|
||||
* @return void
|
||||
*/
|
||||
public function ListHead()
|
||||
{
|
||||
e107::getJs()->headerCore('core/tabs.js')
|
||||
->headerCore('core/admin.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* List action page
|
||||
* @return string
|
||||
*/
|
||||
public function ListPage()
|
||||
{
|
||||
return $this->getUI()->getList();
|
||||
}
|
||||
|
||||
public function getPerPage()
|
||||
{
|
||||
return $this->perPage;
|
||||
}
|
||||
|
||||
public function getPrimaryName()
|
||||
{
|
||||
return $this->pid;
|
||||
}
|
||||
|
||||
public function getPluginName()
|
||||
{
|
||||
return $this->pluginName;
|
||||
}
|
||||
|
||||
public function getPluginTitle()
|
||||
{
|
||||
return $this->pluginTitle;
|
||||
}
|
||||
|
||||
public function getTableName()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
public function getFieldPref()
|
||||
{
|
||||
return $this->fieldpref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Config object
|
||||
* @return e_plugin_pref|e_core_pref
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->_pref;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get column preference array
|
||||
* @return array
|
||||
*/
|
||||
public function getUserPref()
|
||||
{
|
||||
global $user_pref;
|
||||
return vartrue($user_pref['admin_cols_'.$this->getTableName()], array());
|
||||
}
|
||||
|
||||
public function getModel()
|
||||
{
|
||||
if(null === $this->_model)
|
||||
{
|
||||
// default model
|
||||
$this->_model = new e_admin_model();
|
||||
$this->_model->setModelTable($this->table)
|
||||
->setFieldIdName($this->pid)
|
||||
->setValidationRules($this->validationRules)
|
||||
->setFieldTypes($this->fieldTypes)
|
||||
->setDataFields($this->dataFields)
|
||||
->load($this->getId());
|
||||
}
|
||||
return $this->_model;
|
||||
}
|
||||
|
||||
public function setModel($model)
|
||||
{
|
||||
$this->_model = $model;
|
||||
}
|
||||
|
||||
public function getTreeModel()
|
||||
{
|
||||
if(null === $this->_tree_model)
|
||||
{
|
||||
// default tree model
|
||||
$this->_tree_model = new e_admin_tree_model();
|
||||
$this->_tree_model->setModelTable($this->table)
|
||||
->setParams(array('model_class' => 'e_admin_model', 'db_query' => $this->listQry));
|
||||
}
|
||||
return $this->_tree_model;
|
||||
}
|
||||
|
||||
public function setTreeModel($tree_model)
|
||||
{
|
||||
$this->_tree_model = $tree_model;
|
||||
}
|
||||
|
||||
|
||||
public function getUI()
|
||||
{
|
||||
if(null === $this->_ui)
|
||||
{
|
||||
// default ui
|
||||
$this->_ui = new e_admin_ui($this);
|
||||
}
|
||||
return $this->_ui;
|
||||
}
|
||||
|
||||
public function setUI($ui)
|
||||
{
|
||||
$this->_ui = $ui;
|
||||
}
|
||||
}
|
||||
|
||||
class e_admin_ui extends e_form
|
||||
{
|
||||
/**
|
||||
* @var e_admin_controller_main
|
||||
*/
|
||||
protected $_controller = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param e_admin_controller_main $controller
|
||||
* @return
|
||||
*/
|
||||
function __construct($controller, $tabindex = false)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
parent::__construct($tabindex);
|
||||
}
|
||||
|
||||
/**
|
||||
* User defined init
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create list view
|
||||
* Search for the following GET variables:
|
||||
* - from: integer, current page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$controller = $this->getController();
|
||||
$request = $controller->getRequest();
|
||||
$tree = $controller->getTreeModel()->getTree();
|
||||
$total = $controller->getTreeModel()->getTotal();
|
||||
|
||||
$amount = $controller->getPerPage();
|
||||
$from = $controller->getQuery('from', 0);
|
||||
$field = $controller->getQuery('field', $controller->getPrimaryName());
|
||||
$asc = strtoupper($controller->getQuery('asc', 'desc'));
|
||||
$elid = ($controller->getPluginName() == 'core' ? 'core-' : '').str_replace('_', '-', $controller->getTableName());
|
||||
|
||||
$text = $tree ? $this->renderFilter() : '';
|
||||
$text .= "
|
||||
<form method='post' action='".e_SELF."?' id='{$elid}-list-form'>
|
||||
<fieldset id='{$elid}-list'>
|
||||
<legend class='e-hideme'>".$controller->getPluginTitle()."</legend>
|
||||
<table cellpadding='0' cellspacing='0' class='adminlist' id='{$elid}-list-table'>
|
||||
".$this->colGroup($controller->getFields(), $controller->getFieldPref())."
|
||||
".$this->thead($controller->getFields(), $controller->getFieldPref(), 'mode='.$request->buildQueryString('field=[FIELD]&asc=[ASC]&from=[FROM]'))."
|
||||
<tbody>
|
||||
";
|
||||
|
||||
|
||||
if(!$tree)
|
||||
{
|
||||
$text .= "
|
||||
<tr>
|
||||
<td colspan='".count($controller->getFieldPref())."' class='center middle'>".LAN_NO_RECORDS."</td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($tree as $model)
|
||||
{
|
||||
$text .= $this->trow($controller->getFields(), $controller->getFieldPref(), $field->getData(), $controller->getPrimaryName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
";
|
||||
|
||||
$text .= $tree ? $this->renderBatch() : '';
|
||||
|
||||
$text .= "
|
||||
</fieldset>
|
||||
</form>
|
||||
";
|
||||
|
||||
if($tree)
|
||||
{
|
||||
$parms = $total.",".$amount.",".$from.",".e_SELF.'?'.$request->buildQueryString('from=[FROM]');
|
||||
$text .= e107::getParser()->parseTemplate("{NEXTPREV={$parms}}");
|
||||
}
|
||||
|
||||
//e107::getRender()->tablerender($this->pluginTitle." :: ".$this->adminMenu['list']['caption'], $mes->render().$text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
function renderFilter($current_query, $input_options = array())
|
||||
{
|
||||
if(!$input_options) $input_options = array('size' => 20);
|
||||
$text = "
|
||||
<form method='get' action='".e_SELF."?".e_QUERY."'>
|
||||
<div class='left' style='padding-bottom:10px'>
|
||||
".$this->text('searchquery', $current_query, 50, $input_options)."
|
||||
".$this->select_open('filter_options', array('class' => 'tbox select e-filter-options', 'id' => false))."
|
||||
".$this->option('Display All', '')."
|
||||
".$this->renderBatchFilter('filter')."
|
||||
".$this->select_close()."
|
||||
".$this->admin_button('etrigger_filter', LAN_FILTER)."
|
||||
</div>
|
||||
</form>
|
||||
"; //TODO assign CSS
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
function renderBatch()
|
||||
{
|
||||
$fields = $this->getController()->getFields();
|
||||
if(!varset($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('etrigger_batch', array('class' => 'tbox select e-execute-batch', 'id' => false)).
|
||||
$this->option('With selected...', '').
|
||||
$this->option(LAN_DELETE, 'batch__delete');
|
||||
$text .= $this->renderBatchFilter('batch');
|
||||
$text .= "</div>";
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
|
||||
// TODO - do more
|
||||
function renderBatchFilter($type='batch') // Common function used for both batches and filters.
|
||||
{
|
||||
$optdiz = array('batch' => 'Modify ', 'filter'=> 'Filter by ');
|
||||
$table = $this->getController()->getTableName();
|
||||
|
||||
foreach($this->getController()->getFields() 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".$this->optgroup_open($optdiz[$type].$val['title'], $disabled)."\n";
|
||||
foreach($option as $okey=>$oval)
|
||||
{
|
||||
$sel = ($_SESSION[$table."_".$type] == $okey) ? TRUE : FALSE; //FIXME - GET
|
||||
$text .= $this->option($oval, $okey, $sel)."\n";
|
||||
}
|
||||
$text .= "\t".$this->optgroup_close()."\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return e_admin_controller_main
|
||||
*/
|
||||
public function getController()
|
||||
{
|
||||
return $this->_controller;
|
||||
}
|
||||
}
|
||||
|
||||
// One handler to rule them all
|
||||
// see e107_plugins/release/admin_config.php.
|
||||
class e_admin_ui_dummy extends e_form
|
||||
{
|
||||
/**
|
||||
* @var e_admin_controller_main
|
||||
*/
|
||||
protected $_controller = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param e_admin_controller_main $controller
|
||||
* @return
|
||||
*/
|
||||
function __construct($controller)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
parent::__construct(false);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return e_admin_controller_main
|
||||
*/
|
||||
public function getController()
|
||||
{
|
||||
return $this->_controller;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user