diff --git a/e107_handlers/admin_handler.php b/e107_handlers/admin_handler.php
index 319917701..246e97dd3 100644
--- a/e107_handlers/admin_handler.php
+++ b/e107_handlers/admin_handler.php
@@ -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 .= "
+
".$this->textarea($name, $value, $rows, 50, $options)."
@@ -207,50 +204,49 @@ class e_form
{$bbbar}
";
-
+
return $ret;
}
-
+
function checkbox($name, $value, $checked = false, $options = array())
{
$options = $this->format_options('checkbox', $name, $options);
$options['checked'] = $checked; //comes as separate argument just for convenience
return "
'.$this->_uc->vetted_tree($name, array($this, '_uc_checkbox_cb'), $current_value, $uc_options, $field_options).'
';
}
-
+
function _uc_checkbox_cb($treename, $classnum, $current_value, $nest_level, $field_options)
{
if($classnum == e_UC_BLANK)
return '';
-
+
$tmp = explode(',', $current_value); //TODO add support for when $current_value is an array.
$class = $style = '';
@@ -260,86 +256,82 @@ class e_form
}
else
{
- $style = " style='text-indent:".(1.2 * $nest_level)."em'";
+ $style = " style='text-indent:" . (1.2 * $nest_level) . "em'";
}
$descr = varset($field_options['description']) ? ' ".$this->checkbox($treename.'[]', $classnum, in_array($classnum, $tmp), $field_options).$this->label($this->_uc->uc_get_classname($classnum).$descr,
- $treename.'[]', $classnum)."
\n";
- }
+ return "".$this->checkbox($treename.'[]', $classnum, in_array($classnum, $tmp), $field_options).$this->label($this->_uc->uc_get_classname($classnum).$descr, $treename.'[]', $classnum)."
\n";
+ }
+
function uc_label($classnum)
{
- return $this->_uc->uc_get_classname($classnum);
+ return $this->_uc->uc_get_classname($classnum);
}
-
+
function radio($name, $value, $checked = false, $options = array())
{
$options = $this->format_options('radio', $name, $options);
$options['checked'] = $checked; //comes as separate argument just for convenience
return "
-
"." "."
+
"
+ ." "
+ ."
";
- unset($columnsArray['options'], $columnsArray['checkboxes']);
-
- foreach ($columnsArray as $key=>$fld)
+ unset($columnsArray['options'], $columnsArray['checkboxes']);
+
+ foreach($columnsArray as $key => $fld)
{
if(!varset($fld['forced']))
{
- $checked = (in_array($key, $columnsDefault)) ? TRUE : FALSE;
+ $checked = (in_array($key,$columnsDefault)) ? TRUE : FALSE;
$text .= "
".$this->checkbox_label(varset($fld['title'], $key), 'e-columns[]', $key, $checked)."
@@ -720,27 +685,27 @@ class e_form
";
}
}
-
+
// has issues with the checkboxes.
- $text .= "
+ $text .= "
".$this->admin_button('submit-e-columns', LAN_SAVE, 'update')."
- ";
-
+ ";
+
$text .= "";
return $text;
}
-
+
function colGroup($fieldarray, $columnPref = '')
{
- $text = "";
- $count = 0;
- foreach ($fieldarray as $key=>$val)
+ $text = "";
+ $count = 0;
+ foreach($fieldarray as $key=>$val)
{
- if(in_array($key, $columnPref) || $key == 'options' || varsettrue($val['forced']))
+ if(in_array($key, $columnPref) || $key=='options' || varsettrue($val['forced']))
{
$class = vartrue($val['class']) ? ' class="'.$val['class'].'"' : '';
$text .= '
@@ -749,112 +714,106 @@ class e_form
$count++;
}
}
-
+
return '
'.$text.'
';
}
-
- function thead($fieldarray, $columnPref = array(), $querypattern = '', $requeststr = '')
+
+ function thead($fieldarray, $columnPref=array(), $querypattern = '', $requeststr = '')
{
- $text = "";
-
+ $text = "";
+
// Recommended pattern: ?mode=list&fld=[FIELD]&asc=[ASC]&frm=[FROM]
- if(strpos($querypattern, '&') !== FALSE)
+ if(strpos($querypattern,'&')!==FALSE)
{
- // we can assume it's always $_GET since that's what it will generate
+ // we can assume it's always $_GET since that's what it will generate
// more flexible (e.g. pass default values for order/field when they can't be found in e_QUERY) & secure
- $tmp = $requeststr ? $requeststr : str_replace('&', '&', e_QUERY);
+ $tmp = $requeststr ? $requeststr : str_replace('&', '&', e_QUERY);
parse_str($tmp, $tmp);
$etmp = array();
- parse_str($querypattern, $etmp);
+ parse_str($querypattern,$etmp);
}
else // Legacy Queries. eg. main.[FIELD].[ASC].[FROM]
{
- $tmp = explode(".", ($requeststr ? $requeststr : e_QUERY));
+ $tmp = explode(".", ($requeststr ? $requeststr : e_QUERY));
$etmp = explode(".", $querypattern);
}
-
- foreach ($etmp as $key=>$val) // I'm sure there's a more efficient way to do this, but too tired to see it right now!.
+
+ foreach($etmp as $key => $val) // I'm sure there's a more efficient way to do this, but too tired to see it right now!.
{
- if($val == "[FIELD]")
+ if($val == "[FIELD]")
{
- $field = $tmp[$key];
+ $field = $tmp[$key];
}
-
+
if($val == "[ASC]")
{
- $ascdesc = $tmp[$key];
+ $ascdesc = $tmp[$key];
}
if($val == "[FROM]")
{
- $fromval = $tmp[$key];
+ $fromval = $tmp[$key];
}
}
-
- if(!varset($fromval))
+
+ if(!varset($fromval)){ $fromval = 0; }
+
+ $ascdesc = (varset($ascdesc) == 'desc') ? 'asc' : 'desc';
+ foreach($fieldarray as $key=>$val)
{
- $fromval = 0;
- }
-
- $ascdesc = (varset($ascdesc) == 'desc') ? 'asc' : 'desc';
- foreach ($fieldarray as $key=>$val)
- {
- if(in_array($key, $columnPref) || $key == 'options' || (vartrue($val['forced'])))
+ if(in_array($key,$columnPref) || $key == 'options' || (vartrue($val['forced'])))
{
$cl = (vartrue($val['thclass'])) ? " class='".$val['thclass']."'" : "";
$text .= "
";
-
- if($querypattern != "" && !varsettrue($val['nosort']) && $key != "options" && $key != "checkboxes")
+
+ if($querypattern!="" && !varsettrue($val['nosort']) && $key != "options" && $key != "checkboxes")
{
$from = ($key == $field) ? $fromval : 0;
- $srch = array("[FIELD]",
- "[ASC]",
- "[FROM]");
- $repl = array($key,
- $ascdesc,
- $from);
- $val['url'] = e_SELF."?".str_replace($srch, $repl, $querypattern);
+ $srch = array("[FIELD]","[ASC]","[FROM]");
+ $repl = array($key,$ascdesc,$from);
+ $val['url'] = e_SELF."?".str_replace($srch,$repl,$querypattern);
}
-
- $text .= (vartrue($val['url'])) ? "" : ""; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js.
- $text .= vartrue($val['title'], '');
+
+ $text .= (vartrue($val['url'])) ? " " : ""; // Really this column-sorting link should be auto-generated, or be autocreated via unobtrusive js.
+ $text .= vartrue($val['title'], '');
$text .= ($val['url']) ? " " : "";
- $text .= ($key == "options") ? $this->columnSelector($fieldarray, $columnPref) : "";
+ $text .= ($key == "options") ? $this->columnSelector($fieldarray,$columnPref) : "";
$text .= ($key == "checkboxes") ? $this->checkbox_toggle('e-column-toggle', vartrue($val['toggle'], 'multiselect')) : "";
-
- $text .= "
+
+ $text .= "
";
}
}
-
+
return "
".$text."
";
-
+
}
- function trow($obj, $fieldvalues)
+ // FIXME - newspost.php
+ function trow($fieldarray, $currentlist, $fieldvalues, $pid)
{
$cnt = 0;
$ret = '';
- $fieldarray = $obj->fields;
- $currentlist = $obj->fieldpref;
- $pid = $obj->pid;
-
+ /*$fieldarray = $obj->fields;
+ $currentlist = $obj->fieldpref;
+ $pid = $obj->pid;*/
+
- foreach ($fieldarray as $field=>$data)
+ foreach ($fieldarray as $field => $data)
{
//Not found
@@ -882,13 +841,12 @@ class e_form
$value = $fieldvalues[$field];
$parms = array();
- if(isset($data['colparms'])) //TODO rename to 'parms'.
+ if(isset($data['colparms'])) //TODO rename to 'parms'.
{
- if(!is_array($data['colparms']))
- parse_str($data['colparms'], $data['colparms']);
+ if(!is_array($data['colparms'])) parse_str($data['colparms'], $data['colparms']);
$parms = $data['colparms'];
}
-
+
switch($field) // special fields
{
case 'options':
@@ -896,7 +854,7 @@ class e_form
$value .= "
";
$data['type'] = 'text';
break;
-
+
case 'checkboxes':
$value = $this->checkbox(vartrue($data['toggle'], 'multiselect').'['.$fieldvalues[$pid].']', $fieldvalues[$pid]);
$data['type'] = 'text';
@@ -929,56 +887,55 @@ class e_form
{
$value = $value[$data['type']] ? $value[$data['type']] : $value['user_name'];
}
- else
+ else
{
$value = 'not found';
}
break;
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
-
- default:
- continue; //unknown type
- break;
- }
+ $value = $value ? ADMIN_TRUE_ICON : '';// TODO - ADMIN_FALSE_ICON
+ break;
+
+ case 'url':
+ $value = "
".$value." ";
+ break;
- //TODO - this should be done per type!
- if(vartrue($parms['truncate']))
- {
- $value = e107::getParser()->text_truncate($value, $parms['truncate'], '...');
- }
- elseif(vartrue($parms['htmltruncate']))
- {
- $value = e107::getParser()->html_truncate($value, $parms['htmltruncate'], '...');
- }
+ case 'method': // Custom Function
+ $meth = $field;
+ $value = $obj->$meth($value,$obj->mode);
+ break;
- $ret .= '
+ //TODO - form_userclass, order,... and maybe more types
+
+ default:
+ continue; //unknown type
+ break;
+ }
+
+ //TODO - this should be done per type!
+ if(vartrue($parms['truncate']))
+ {
+ $value = e107::getParser()->text_truncate($value, $parms['truncate'], '...');
+ }
+ elseif(vartrue($parms['htmltruncate']))
+ {
+ $value = e107::getParser()->html_truncate($value, $parms['htmltruncate'], '...');
+ }
+
+ $ret .= '
'.$value.'
';
- $cnt++;
- }
-
- if($cnt)
- {
- $trclass = vartrue($fieldvalues['trclass']) ? ' class="'.$trclass.'"' : '';
- return '
+ $cnt++;
+ }
+
+ if($cnt)
+ {
+ $trclass = vartrue($fieldvalues['trclass']) ? ' class="'.$trclass.'"' : '';
+ return '
'.$ret.'
@@ -1054,208 +1011,189 @@ class e_form
$text = "
- ".$this->select_open('execute_batch', array('class'=>'tbox select e-execute-batch', 'id'=>false))."
+ ".$this->select_open('execute_batch', array('class' => 'tbox select e-execute-batch', 'id' => false))."
".$this->option('With selected...', '')."
";
-
- //used for getperms() check
- $permissions = vartrue($options['__permissions'], array());
- //used for check_classs() check
- $classes = vartrue($options['__check_class'], array());
- unset($options['__permissions'], $options['__check_class']);
-
- foreach ($options as $key=>$val)
+
+ //used for getperms() check
+ $permissions = vartrue($options['__permissions'], array());
+ //used for check_classs() check
+ $classes = vartrue($options['__check_class'], array());
+ unset($options['__permissions'], $options['__check_class']);
+
+ foreach ($options as $key => $val)
+ {
+ if(isset($permissions[$key]) && !getperms($permissions[$key]))
{
- if(isset($permissions[$key]) && !getperms($permissions[$key]))
- {
- continue;
- }
- $disabled = false;
- if(isset($classes[$key]) && !is_array($classes[$key]) && !check_class($classes[$key]))
- {
- $disabled = true;
- }
- if(!is_array($val))
- {
- if($disabled)
- $val = $val.' ('.LAN_NOPERMISSION.')';
- $text .= "\t".$this->option(' '.$val, $key, false, array('disabled'=>$disabled))."\n";
- }
- else
- {
- if($disabled)
- $val[0] = $val[0].' ('.LAN_NOPERMISSION.')';
-
- $text .= "\t".$this->optgroup_open($val[0], $disabled)."\n";
- foreach ($val[1] as $k=>$v)
- {
- $disabled = false;
- if(isset($classes[$key][$k]) && !check_class($classes[$key][$k]))
- {
- $disabled = true;
- $v = $v.' ('.LAN_NOPERMISSION.')';
- }
- $text .= "\t\t".$this->option($v, $key.'_selected_'.$k, false, array('disabled'=>$disabled))."\n";
- }
- $text .= $this->optgroup_close()."\n";
-
- }
+ continue;
}
-
-
- if($ucOptions) // Userclass List.
+ $disabled = false;
+ if(isset($classes[$key]) && !is_array($classes[$key]) && !check_class($classes[$key]))
{
- foreach ($ucOptions as $ucKey=>$ucVal)
- {
- $text .= "\t".$this->optgroup_open($ucVal[0])."\n";
- foreach ($ucVal[1] as $key=>$val)
- {
- $text .= "\t\t".$this->option($val['userclass_name']['userclass_name'], $ucKey.'_selected_'.$val['userclass_name']['userclass_id'])."\n";
- }
- $text .= $this->optgroup_close()."\n";
- }
+ $disabled = true;
}
+ if(!is_array($val))
+ {
+ if($disabled) $val = $val.' ('.LAN_NOPERMISSION.')';
+ $text .= "\t".$this->option(' '.$val, $key, false, array('disabled' => $disabled))."\n";
+ }
+ else
+ {
+ if($disabled) $val[0] = $val[0].' ('.LAN_NOPERMISSION.')';
+
+ $text .= "\t".$this->optgroup_open($val[0], $disabled)."\n";
+ foreach ($val[1] as $k => $v)
+ {
+ $disabled = false;
+ if(isset($classes[$key][$k]) && !check_class($classes[$key][$k]))
+ {
+ $disabled = true;
+ $v = $v.' ('.LAN_NOPERMISSION.')';
+ }
+ $text .= "\t\t".$this->option($v, $key.'_selected_'.$k, false, array('disabled' => $disabled))."\n";
+ }
+ $text .= $this->optgroup_close()."\n";
+
+ }
+ }
-
- $text .= "
+
+ if ($ucOptions) // Userclass List.
+ {
+ foreach ($ucOptions as $ucKey => $ucVal)
+ {
+ $text .= "\t".$this->optgroup_open($ucVal[0])."\n";
+ foreach ($ucVal[1] as $key => $val)
+ {
+ $text .= "\t\t".$this->option($val['userclass_name']['userclass_name'], $ucKey.'_selected_'.$val['userclass_name']['userclass_id'])."\n";
+ }
+ $text .= $this->optgroup_close()."\n";
+ }
+ }
+
+
+ $text .= "
".$this->select_close()."
".$this->admin_button('trigger_execute_batch', 'trigger_execute_batch', 'submit multi e-hide-if-js', 'Go')."
";
- return $text;
- }
+ return $text;
}
-
- class form
- {
-
- function form_open($form_method, $form_action, $form_name = "", $form_target = "", $form_enctype = "", $form_js = "")
- {
- $method = ($form_method ? "method='".$form_method."'" : "");
- $target = ($form_target ? " target='".$form_target."'" : "");
- $name = ($form_name ? " id='".$form_name."' " : " id='myform'");
- return "\n
";
- }
- }
-
- /*
- Usage
- echo $rs->form_open("post", e_SELF, "_blank");
- echo $rs->form_text("testname", 100, "this is the value", 100, 0, "tooltip");
- echo $rs->form_button("submit", "testsubmit", "SUBMIT!", "", "Click to submit");
- echo $rs->form_button("reset", "testreset", "RESET!", "", "Click to reset");
- echo $rs->form_textarea("textareaname", 10, 10, "Value", "overflow:hidden");
- echo $rs->form_checkbox("testcheckbox", 1, 1);
- echo $rs->form_checkbox("testcheckbox2", 2);
- echo $rs->form_hidden("hiddenname", "hiddenvalue");
- echo $rs->form_radio("testcheckbox", 1, 1);
- echo $rs->form_radio("testcheckbox", 1);
- echo $rs->form_file("testfile", "20");
- echo $rs->form_select_open("testselect");
- echo $rs->form_option("Option 1");
- echo $rs->form_option("Option 2");
- echo $rs->form_option("Option 3", 1, "defaultvalue");
- echo $rs->form_option("Option 4");
- echo $rs->form_select_close();
- echo $rs->form_close();
- */
-
+}
-?>
+class form {
+
+ function form_open($form_method, $form_action, $form_name = "", $form_target = "", $form_enctype = "", $form_js = "") {
+ $method = ($form_method ? "method='".$form_method."'" : "");
+ $target = ($form_target ? " target='".$form_target."'" : "");
+ $name = ($form_name ? " id='".$form_name."' " : " id='myform'");
+ return "\n
";
+ }
+
+ function form_text($form_name, $form_size, $form_value, $form_maxlength = FALSE, $form_class = "tbox", $form_readonly = "", $form_tooltip = "", $form_js = "") {
+ $name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
+ $value = (isset($form_value) ? " value='".$form_value."'" : "");
+ $size = ($form_size ? " size='".$form_size."'" : "");
+ $maxlength = ($form_maxlength ? " maxlength='".$form_maxlength."'" : "");
+ $readonly = ($form_readonly ? " readonly='readonly'" : "");
+ $tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
+ return "\n ";
+ }
+
+ function form_password($form_name, $form_size, $form_value, $form_maxlength = FALSE, $form_class = "tbox", $form_readonly = "", $form_tooltip = "", $form_js = "") {
+ $name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
+ $value = (isset($form_value) ? " value='".$form_value."'" : "");
+ $size = ($form_size ? " size='".$form_size."'" : "");
+ $maxlength = ($form_maxlength ? " maxlength='".$form_maxlength."'" : "");
+ $readonly = ($form_readonly ? " readonly='readonly'" : "");
+ $tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
+ return "\n ";
+ }
+
+ function form_button($form_type, $form_name, $form_value, $form_js = "", $form_image = "", $form_tooltip = "") {
+ $name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
+ $image = ($form_image ? " src='".$form_image."' " : "");
+ $tooltip = ($form_tooltip ? " title='".$form_tooltip."' " : "");
+ return "\n ";
+ }
+
+ function form_textarea($form_name, $form_columns, $form_rows, $form_value, $form_js = "", $form_style = "", $form_wrap = "", $form_readonly = "", $form_tooltip = "") {
+ $name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
+ $readonly = ($form_readonly ? " readonly='readonly'" : "");
+ $tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
+ $wrap = ($form_wrap ? " wrap='".$form_wrap."'" : "");
+ $style = ($form_style ? " style='".$form_style."'" : "");
+ return "\n".$form_value." ";
+ }
+
+ function form_checkbox($form_name, $form_value, $form_checked = 0, $form_tooltip = "", $form_js = "") {
+ $name = ($form_name ? " id='".$form_name.$form_value."' name='".$form_name."'" : "");
+ $checked = ($form_checked ? " checked='checked'" : "");
+ $tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
+ return "\n ";
+
+ }
+
+ function form_radio($form_name, $form_value, $form_checked = 0, $form_tooltip = "", $form_js = "") {
+ $name = ($form_name ? " id='".$form_name.$form_value."' name='".$form_name."'" : "");
+ $checked = ($form_checked ? " checked='checked'" : "");
+ $tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
+ return "\n ";
+
+ }
+
+ function form_file($form_name, $form_size, $form_tooltip = "", $form_js = "") {
+ $name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
+ $tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
+ return " ";
+ }
+
+ function form_select_open($form_name, $form_js = "") {
+ return "\n";
+ }
+
+ function form_select_close() {
+ return "\n ";
+ }
+
+ function form_option($form_option, $form_selected = "", $form_value = "", $form_js = "") {
+ $value = ($form_value !== FALSE ? " value='".$form_value."'" : "");
+ $selected = ($form_selected ? " selected='selected'" : "");
+ return "\n".$form_option." ";
+ }
+
+ function form_hidden($form_name, $form_value) {
+ return "\n ";
+ }
+
+ function form_close() {
+ return "\n ";
+ }
+}
+
+/*
+Usage
+echo $rs->form_open("post", e_SELF, "_blank");
+echo $rs->form_text("testname", 100, "this is the value", 100, 0, "tooltip");
+echo $rs->form_button("submit", "testsubmit", "SUBMIT!", "", "Click to submit");
+echo $rs->form_button("reset", "testreset", "RESET!", "", "Click to reset");
+echo $rs->form_textarea("textareaname", 10, 10, "Value", "overflow:hidden");
+echo $rs->form_checkbox("testcheckbox", 1, 1);
+echo $rs->form_checkbox("testcheckbox2", 2);
+echo $rs->form_hidden("hiddenname", "hiddenvalue");
+echo $rs->form_radio("testcheckbox", 1, 1);
+echo $rs->form_radio("testcheckbox", 1);
+echo $rs->form_file("testfile", "20");
+echo $rs->form_select_open("testselect");
+echo $rs->form_option("Option 1");
+echo $rs->form_option("Option 2");
+echo $rs->form_option("Option 3", 1, "defaultvalue");
+echo $rs->form_option("Option 4");
+echo $rs->form_select_close();
+echo $rs->form_close();
+*/
+
+
+?>
\ No newline at end of file
diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php
index 6b6153e4e..b253027d2 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.25 $
- * $Date: 2009-10-27 17:49:12 $
+ * $Revision: 1.26 $
+ * $Date: 2009-10-28 17:05:34 $
* $Author: secretr $
*/
@@ -87,13 +87,23 @@ class e_model
}
/**
- * Predefined data fields in format key => type
+ * Get data fields array
* @return array
*/
public function getDataFields()
{
return $this->_data_fields;
}
+
+ /**
+ * Set Predefined data fields in format key => type
+ * @return e_model
+ */
+ public function setDataFields($data_fields)
+ {
+ $this->_data_fields = $data_fields;
+ return $this;
+ }
/**
* Set name of object's field id
@@ -977,6 +987,18 @@ class e_admin_model extends e_model
{
return $this->_FIELD_TYPES;
}
+
+ /**
+ * Predefined data fields types, passed to DB handler
+ *
+ * @param array $field_types
+ * @return e_admin_model
+ */
+ public function setFieldTypes($field_types)
+ {
+ $this->_FIELD_TYPES = $field_types;
+ return $this;
+ }
/**
* Retrieves data from the object ($_posted_data) without
@@ -1525,6 +1547,36 @@ class e_admin_model extends e_model
$this->addMessageDebug('SQL Error #'.$this->_db_errno.': '.e107::getDb()->getLastErrorText());
}
}
+
+ return $res;
+ }
+
+ /**
+ * Delete DB data
+ *
+ * @param boolean $force force query even if $data_has_changed is false
+ * @param boolean $session_messages to use or not session to store system messages
+ */
+ public function dbDelete($session_messages = false)
+ {
+ $this->_db_errno = 0;
+ if(!$this->getId())
+ {
+ $this->addMessageError('Record not found', $session_messages); //TODO - Lan
+ return 0;
+ }
+ $res = e107::getDb()->db_Delete($this->getModelTable(), $this->getFieldIdName().'='.intval($this->getId()));
+ if(!$res)
+ {
+ $this->_db_errno = e107::getDb()->getLastErrorNumber();
+ if($this->_db_errno)
+ {
+ $this->addMessageError('SQL Delete Error', $session_messages); //TODO - Lan
+ $this->addMessageDebug('SQL Error #'.$this->_db_errno.': '.e107::getDb()->getLastErrorText());
+ }
+ }
+
+ return $res;
}
/**
@@ -1640,6 +1692,274 @@ class e_admin_model extends e_model
}
}
+/**
+ * Model collection handler
+ */
+class e_tree_model extends e_model
+{
+ /**
+ * @var array
+ */
+ protected $_params = array();
+
+ /**
+ * Current model DB table, used in all db calls
+ * This can/should be overwritten by extending the class
+ *
+ * @var string
+ */
+ protected $_db_table;
+
+ /**
+ * All records (no limit) cache
+ *
+ * @var string
+ */
+ protected $_total = 0;
+
+ public function getTotal()
+ {
+ return $this->_total;
+ }
+
+ public function setTotal($num)
+ {
+ $this->_total = $num;
+ return $this;
+ }
+
+ /**
+ * Set table name
+ * @param object $table
+ * @return e_admin_tree_model
+ */
+ public function setModelTable($table)
+ {
+ $this->_db_table = $table;
+ return $this;
+ }
+
+ /**
+ * Get table name
+ * @return string
+ */
+ public function getModelTable()
+ {
+ return $this->_db_table;
+ }
+
+ /**
+ * Constructor
+ *
+ */
+ function __construct($tree_data = array())
+ {
+ if($tree_data)
+ {
+ $this->setTree($tree_data);
+ }
+ }
+
+ /**
+ * Set array of models
+ * @return array
+ */
+ function getTree($force = false)
+ {
+ return $this->get('__tree');
+ }
+
+ /**
+ * Set array of models
+ * @return e_tree_model
+ */
+ function setTree($tree_data, $force = false)
+ {
+ if($force || !$this->is('__tree'))
+ {
+ $this->set('__tree', $tree_data);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Default load method
+ *
+ * @return e_tree_model
+ */
+ public function load()
+ {
+ if($this->getParam('db_query') && $this->getParam('model_class') && class_exists($this->getParam('model_class')))
+ {
+ $sql = e107::getDb();
+ $class_name = $this->getParam('model_class');
+ if($sql->db_Select_gen($this->getParam('db_query')))
+ {
+ $this->_total = $sql->total_results; //requires SQL_CALC_FOUND_ROWS in query - see db handler
+ while($tmp = $sql->db_Fetch())
+ {
+ $tmp = new $class_name($tmp);
+ $this->setNode($tmp->getId(), $tmp);
+ }
+ unset($tmp);
+ }
+ }
+ return $this;
+ }
+
+ /**
+ * Get single model instance from the collection
+ * @param integer $node_id
+ * @return e_model
+ */
+ function getNode($node_id)
+ {
+ return $this->getData('__tree/'.$node_id);
+ }
+
+ /**
+ * Add or remove (when $node is null) model to the collection
+ *
+ * @param integer $node_id
+ * @param e_model $node
+ * @return e_tree_model
+ */
+ function setNode($node_id, $node)
+ {
+ if(null === $node)
+ {
+ $this->removeData('__tree/'.$node_id);
+ return $this;
+ }
+
+ $this->setData('__tree/'.$node_id, $node);
+ return $this;
+ }
+
+ /**
+ * Check if model with passed id exists in the collection
+ *
+ * @param integer $node_id
+ * @return boolean
+ */
+ public function isNode($node_id)
+ {
+ return $this->isData('__tree/'.$node_id);
+ }
+
+ /**
+ * Check if model with passed id exists in the collection and is not empty
+ *
+ * @param integer $node_id
+ * @return boolean
+ */
+ public function hasNode($node_id)
+ {
+ return $this->hasData('__tree/'.$node_id);
+ }
+
+ /**
+ * Check if collection is empty
+ *
+ * @return boolean
+ */
+ function isEmpty()
+ {
+ return $this->has('__tree');
+ }
+
+ /**
+ * Set parameter array
+ * Core parameters:
+ * - db_query: string db query to be passed to $sql->db_Select_gen();
+ * - model_class: string class name for creating nodes inside default load() method
+ *
+ * @param array $params
+ * @return e_tree_model
+ */
+ public function setParams(array $params)
+ {
+ $this->_params = $params;
+ return $this;
+ }
+
+
+ /**
+ * Get parameter array
+ *
+ * @return array parameters
+ */
+ public function getParams()
+ {
+ return $this->_params;
+ }
+
+ /**
+ * Set parameter
+ *
+ * @param string $key
+ * @param mixed $value
+ * @return e_tree_model
+ */
+ public function setParam($key, $value)
+ {
+ $this->_params[$key] = $value;
+ return $this;
+ }
+
+ /**
+ * Get parameter
+ *
+ * @param string $key
+ * @param mixed $default
+ */
+ public function getParam($key, $default = null)
+ {
+ return (isset($this->_params[$key]) ? $this->_params[$key] : $default);
+ }
+}
+
+class e_admin_tree_model extends e_tree_model
+{
+ /**
+ * Delete records
+ * @param mixed $ids
+ * @param boolean $destroy [optional] destroy object instance after db delete
+ * @param boolean $session_messages [optional]
+ * @return mixed integer deleted records or false on DB error
+ */
+ public function delete($ids, $destroy = true, $session_messages = false)
+ {
+ if(is_string($ids))
+ {
+ $ids = explode(',', $ids);
+ }
+
+ $ids = e107::getParser()->toDB($ids);
+ $sql = e107::getDb();
+ $res = $sql->db_Delete($this->getModelTable(), $this->getFieldIdName().' IN ('.$ids.')');
+ if(!$res)
+ {
+ if($sql->getLastErrorNumber())
+ {
+ $this->addMessageError('SQL Delete Error', $session_messages); //TODO - Lan
+ $this->addMessageDebug('SQL Error #'.$sql->getLastErrorNumber().': '.$sql->getLastErrorText());
+ }
+ }
+ elseif($destroy)
+ {
+ foreach ($ids as $id)
+ {
+ call_user_func(array($this->getNode($id), 'destroy')); // first call model destroy method if any
+ $this->setNode($id, null);
+ }
+ }
+
+ return $res;
+ }
+}
+
// Experimental admin interface class. //TODO integrate with the above.
// see e107_plugins/release/admin_config.php.
diff --git a/e107_plugins/release/admin_config.php b/e107_plugins/release/admin_config.php
index 96070e02b..ca3b9b73f 100644
--- a/e107_plugins/release/admin_config.php
+++ b/e107_plugins/release/admin_config.php
@@ -9,16 +9,130 @@
* e107 Release Plugin
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/release/admin_config.php,v $
- * $Revision: 1.9 $
- * $Date: 2009-10-26 08:16:09 $
- * $Author: e107coders $
+ * $Revision: 1.10 $
+ * $Date: 2009-10-28 17:05:35 $
+ * $Author: secretr $
*
*/
require_once("../../class2.php");
if (!getperms("P")) { header("location:".e_BASE."index.php"); exit; }
+
+require_once(e_HANDLER.'admin_handler.php');
+
+class plugin_release_admin_dispatcher extends e_admin_dispatcher
+{
+ /**
+ * Format: 'MODE' => array('controller' =>'CONTROLLER_CLASS'[, 'path' => 'CONTROLLER SCRIPT PATH', 'ui' => 'UI CLASS NAME child of e_admin_ui', 'uipath' => 'UI SCRIPT PATH']);
+ * @var array
+ */
+ protected $controllerList = array(
+ 'main' => array('controller' => 'plugin_release_admin_controller_main', 'path' => null, 'ui' => 'plugin_release_admin_ui_main', 'uipath' => null)
+ );
+ /**
+ * Format: 'MODE/ACTION' => array('caption' => 'Menu link title'[, 'url' => '{e_PLUGIN}release/admin_config.php', 'perm' => '0']);
+ * Additionally, any valid e_admin_menu() key-value pair could be added to the above array
+ * @var array
+ */
+ protected $adminMenu = array(
+ 'main/list' => array('caption'=> 'Release List', 'perm'=>'0'),
+ 'main/create' => array('caption'=> LAN_CREATE, 'perm'=>'0'),
+ 'main/options' => array('caption'=> LAN_OPTIONS, 'perm'=>'0'),
+ 'main/custom' => array('caption'=> 'Custom Page', 'perm'=>0)
+ );
+
+ /**
+ * Navigation menu title
+ * @var string
+ */
+ protected $menuTitle = 'Release Menu';
+}
+
+class plugin_release_admin_controller_main extends e_admin_controller_main
+{
+ // required
+ protected $pluginTitle = "e107 Release";
+
+ // required
+ protected $pluginName = 'release';
+
+ // required - if no custom model is set in init()
+ protected $table = "release";
+
+ // required - if no custom model is set in init() (primary id)
+ protected $pid = "release_id";
+
+ // optional
+ protected $perPage = 20;
+
+ //TODO change the release_url type back to URL before release.
+ // required
+ protected $fields = array(
+ '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'=> 'Userclass', '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)
+ );
+
+ //required - default column user prefs
+ protected $fieldpref = array('checkboxes', 'release_id', 'release_type', 'release_compatibility', 'options');
+
+ // required if no custom model is set in init()
+ protected $dataFields = array(
+ 'release_id' => 'int',
+ 'release_type' => 'str',
+ 'release_folder' => 'str',
+ 'release_name' => 'str',
+ 'release_version' => 'str',
+ 'release_author' => 'str',
+ 'release_authorURL' => 'str',
+ 'release_date' => 'int',
+ 'release_compatibility' => 'str',
+ 'release_url' => 'str',
+ );
+
+ // optional
+ protected $validationRules = array();
+
+ // optional
+ protected $prefs = array( //TODO add option for core or plugin pref.
+
+ 'pref_type' => array('title'=> 'type', 'type'=>'text'),
+ 'pref_folder' => array('title'=> 'folder', 'type' => 'boolean'),
+ 'pref_name' => array('title'=> 'name', 'type' => 'text')
+ );
+
+ // required if no custom model is set in init()
+ protected $listQry = "SELECT * FROM #release"; // without any Order or Limit.
+
+ // required if no custom model is set in init()
+ protected $editQry = "SELECT * FROM #release WHERE release_id = {ID}";
+
+ // optional
+ public function init()
+ {
+ }
+}
+
+$dispatcher = new plugin_release_admin_dispatcher();
+$dispatcher->runObservers(true);
+e107::setRegistry('admin/release_dispatcher', $dispatcher);
+
require_once(e_ADMIN."auth.php");
+e107::getRegistry('admin/release_dispatcher')->runPage();
+
+require_once(e_ADMIN."footer.php");
+
+/*
class releasePlugin extends e_model_interface
{
@@ -103,37 +217,35 @@ class releasePlugin extends e_model_interface
}
}
+*/
+//$rp = new releasePlugin;
+//$rp->init();
-$rp = new releasePlugin;
-$rp->init();
-
-require_once(e_ADMIN."footer.php");
function admin_config_adminmenu() //TODO move this into e_model_interface
{
- global $rp;
- $rp->show_options();
+ //global $rp;
+ //$rp->show_options();
+ e107::getRegistry('admin/release_dispatcher')->renderMenu();
}
function headerjs() // needed for the checkboxes - how can we remove the need to duplicate this code?
{
- require_once (e_HANDLER.'js_helper.php');
+ /*require_once (e_HANDLER.'js_helper.php');
$ret = "
- ";
+ ";*/
+ return e107::getRegistry('admin/release_dispatcher')->getController()->getHeader();
- return $ret;
+ //return $ret;
}
?>
\ No newline at end of file