From b9143f45d0c2b668c9a4fdb73801432acb5d5f20 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Thu, 22 Oct 2009 04:15:32 +0000 Subject: [PATCH] experimental admin inteface class added. --- e107_handlers/model_class.php | 250 +++++++++++++++++++++++++- e107_plugins/release/admin_config.php | 69 +++---- 2 files changed, 270 insertions(+), 49 deletions(-) diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index 4c9c651f5..0c4f86160 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -9,9 +9,9 @@ * e107 Base Model * * $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $ - * $Revision: 1.15 $ - * $Date: 2009-10-21 19:34:18 $ - * $Author: e107steved $ + * $Revision: 1.16 $ + * $Date: 2009-10-22 04:15:27 $ + * $Author: e107coders $ */ if (!defined('e107_INIT')) { exit; } @@ -1596,3 +1596,247 @@ class e_model_admin extends e_model return null; } } + + +// 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 $primary; + + function __construct() + { + + } + + function init() + { + + global $user_pref; + + if(varset($_POST['update']) || varset($_POST['create'])) + { + + $id = intval($_POST['record_id']); + $this->submitPage($id); + } + + if(varset($_POST['delete'])) + { + $id = key($_POST['delete']); + $this->deleteRecord($id); + $_GET['mode'] = "list"; + } + + if(varset($_GET['mode'])=='create') + { + $id = varset($_POST['edit']) ? key($_POST['edit']) : ""; + $this->createRecord($id); + } + else + { + $this->listRecords(); + } + + if(isset($_POST['submit-e-columns'])) + { + $column_pref_name = "admin_".$this->table."_columns"; + $user_pref[$column_pref_name] = $_POST['e-columns']; + save_prefs('user'); + } + } + + + /** + * Generic DB Record Listing Function. + * @param object $mode [optional] + * @return + */ + function listRecords($mode=FALSE) + { + $ns = e107::getRender(); + $sql = e107::getDb(); + $frm = e107::getForm(); + $mes = e107::getMessage(); + + global $pref; + + + $text = "
+
+ ".$this->pluginTitle." + ". + $frm->colGroup($this->fields,$this->fieldpref). + $frm->thead($this->fields,$this->fieldpref). + + ""; + + + if(!$sql->db_Select_gen($this->listQry)) + { + $text .= "\n\n"; + } + else + { + $row = $sql->db_getList('ALL', FALSE, FALSE); + + foreach($row as $field) + { + $text .= "\n"; + foreach($this->fields as $key=>$att) + { + $class = vartrue($this->fields[$key]['thclass']) ? "class='".$this->fields[$key]['thclass']."'" : ""; + $text .= (in_array($key,$this->fieldpref) || $att['forced']==TRUE) ? "\t\n" : ""; + } + $text .= "\n"; + } + } + + $text .= " + +
".CUSLAN_42."
".$this->renderValue($key,$field)."
+
+
+ "; + + $ns->tablerender($this->pluginTitle." :: ".$this->listCaption, $mes->render().$text); + } + + + /** + * + * @param object $id [optional] + * @return + */ + function createRecord($id=FALSE) + { + global $frm, $e_userclass, $e_event; + + $tp = e107::getParser(); + $ns = e107::getRender(); + $sql = e107::getDb(); + + if($id) + { + $query = str_replace("{ID}",$id,$this->editQry); + $sql->db_Select_gen($query); + $row = $sql->db_Fetch(MYSQL_ASSOC); + } + else + { + $row = array(); + } + + $text = " +
+
+ ".$this->pluginTitle." + + + + + + "; + + foreach($this->fields as $key=>$att) + { + if($att['forced']!==TRUE) + { + $text .= " + + + + "; + } + + } + + $text .= " + +
".$att['title']."".$this->renderElement($key,$row)."
+
"; + + if($id) + { + $text .= $frm->admin_button('update', LAN_UPDATE, 'update'); + $text .= ""; + } + else + { + $text .= $frm->admin_button('create', LAN_CREATE, 'create'); + } + + $text .= " +
+
+
"; + + $ns->tablerender($this->pluginTitle." :: ".$this->createCaption, $text); + } + + + /** + * Generic Save DB Record Function. + * @param object $id [optional] + * @return + */ + function submitPage($id=FALSE) + { + global $sql, $tp, $e107cache, $admin_log, $e_event; + $emessage = eMessage::getInstance(); + + $insert_array = array(); + + 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; + + } + else + { + $status = $sql->db_Insert($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $message = LAN_CREATED; + } + + + $emessage->add($message, $status); + } + + /** + * Generic Save DB Record Function. + * @param object $id + * @return + */ + function deleteRecord($id) + { + if(!$id || !$this->primary || !$this->table) + { + return; + } + + $emessage = eMessage::getInstance(); + $sql = e107::getDb(); + + $query = $this->primary." = ".$id; + $status = $sql->db_Delete($this->table,$query) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED; + $message = LAN_DELETED; + $emessage->add($message, $status); + } + + +} + diff --git a/e107_plugins/release/admin_config.php b/e107_plugins/release/admin_config.php index 253f6953b..a40bc65b8 100644 --- a/e107_plugins/release/admin_config.php +++ b/e107_plugins/release/admin_config.php @@ -9,8 +9,8 @@ * e107 Release Plugin * * $Source: /cvs_backup/e107_0.8/e107_plugins/release/admin_config.php,v $ - * $Revision: 1.2 $ - * $Date: 2009-10-20 21:02:02 $ + * $Revision: 1.3 $ + * $Date: 2009-10-22 04:15:32 $ * $Author: e107coders $ * */ @@ -20,46 +20,10 @@ if (!getperms("P")) { header("location:".e_BASE."index.php"); exit; } require_once(e_ADMIN."auth.php"); require_once(e_HANDLER."form_handler.php"); $frm = new e_form(true); - -$ef = new efeed; +require_once(e_HANDLER."model_class.php"); -if(varset($_POST['update']) || varset($_POST['create'])) -{ - - $id = intval($_POST['record_id']); - $ef->submitPage($id); -} - -if(varset($_POST['delete'])) -{ - $id = key($_POST['delete']); - $ef->deleteRecord($id); - $_GET['mode'] = "list"; -} - -if(varset($_GET['mode'])=='create') -{ - $id = varset($_POST['edit']) ? key($_POST['edit']) : ""; - $ef->createRecord($id); -} -else -{ - $ef->listRecords(); -} - -if(isset($_POST['submit-e-columns'])) -{ - $user_pref['admin_release_columns'] = $_POST['e-columns']; - save_prefs('user'); -} - - -require_once(e_ADMIN."footer.php"); - - - -class efeed +class efeed extends e_model_interface { var $fields; var $fieldpref; @@ -105,7 +69,7 @@ class efeed * @param object $mode [optional] * @return */ - function listRecords($mode=FALSE) + /*function listRecords($mode=FALSE) { $ns = e107::getRender(); $sql = e107::getDb(); @@ -153,7 +117,7 @@ class efeed $ns->tablerender($this->pluginTitle." :: ".$this->listCaption, $emessage->render().$text); } - +*/ /** * Render Field value (listing page) * @param object $key @@ -221,7 +185,7 @@ class efeed } - function createRecord($id=FALSE) + /*function createRecord($id=FALSE) { global $frm, $e_userclass, $e_event; @@ -285,14 +249,14 @@ class efeed "; $ns->tablerender($this->pluginTitle." :: ".$this->createCaption, $text); - } + }*/ /** * Generic Save DB Record Function. * @param object $id [optional] * @return */ - function submitPage($id=FALSE) + /*function submitPage($id=FALSE) { global $sql, $tp, $e107cache, $admin_log, $e_event; $emessage = eMessage::getInstance(); @@ -339,7 +303,7 @@ class efeed $message = LAN_DELETED; $emessage->add($message, $status); } - +*/ function optionsPage() { global $e107, $pref, $frm, $emessage; @@ -421,6 +385,19 @@ class efeed } } + +$ef = new efeed; +$ef->init(); + + + + + +require_once(e_ADMIN."footer.php"); + + + + function admin_config_adminmenu() { global $ef;