mirror of
https://github.com/e107inc/e107.git
synced 2025-08-06 06:38:00 +02:00
More model interface stuff.
This commit is contained in:
@@ -9,8 +9,8 @@
|
||||
* e107 Base Model
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $
|
||||
* $Revision: 1.17 $
|
||||
* $Date: 2009-10-22 05:14:07 $
|
||||
* $Revision: 1.18 $
|
||||
* $Date: 2009-10-22 07:23:17 $
|
||||
* $Author: e107coders $
|
||||
*/
|
||||
|
||||
@@ -1607,7 +1607,7 @@ class e_model_interface
|
||||
var $listQry;
|
||||
var $table;
|
||||
var $primary;
|
||||
var $mode; // to work with $_GET and admin menu.
|
||||
var $mode; // as found in the URL query. $_GET['mode]
|
||||
|
||||
function __construct()
|
||||
{
|
||||
@@ -1617,32 +1617,9 @@ class e_model_interface
|
||||
function init()
|
||||
{
|
||||
|
||||
global $user_pref;
|
||||
global $user_pref; // e107::getConfig('user') ??
|
||||
|
||||
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();
|
||||
}
|
||||
//TODO add options 'preferences page'.
|
||||
$this->mode = varset($_GET['mode']) ? $_GET['mode'] : 'list';
|
||||
|
||||
if(isset($_POST['submit-e-columns']))
|
||||
{
|
||||
@@ -1650,26 +1627,49 @@ class e_model_interface
|
||||
$user_pref[$column_pref_name] = $_POST['e-columns'];
|
||||
save_prefs('user');
|
||||
}
|
||||
|
||||
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($this->mode)
|
||||
{
|
||||
$method = $this->mode."Page";
|
||||
$this->$method();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic DB Record Listing Function.
|
||||
* @param object $mode [optional]
|
||||
* @return
|
||||
*/
|
||||
function listRecords($mode=FALSE)
|
||||
function listPage()
|
||||
{
|
||||
$ns = e107::getRender();
|
||||
$sql = e107::getDb();
|
||||
$frm = e107::getForm();
|
||||
$mes = e107::getMessage();
|
||||
|
||||
global $pref;
|
||||
|
||||
$pref = e107::getConfig()->getPref();
|
||||
|
||||
$text = "<form method='post' action='".e_SELF."?mode=create'>
|
||||
<fieldset id='core-release-list'>
|
||||
<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).
|
||||
@@ -1680,7 +1680,7 @@ class e_model_interface
|
||||
|
||||
if(!$sql->db_Select_gen($this->listQry))
|
||||
{
|
||||
$text .= "\n<tr><td colspan='".count($this->fields)."' class='center middle'>".CUSLAN_42."</td></tr>\n";
|
||||
$text .= "\n<tr><td colspan='".count($this->fields)."' class='center middle'>".LAN_NO_RECORDS."</td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1714,9 +1714,11 @@ class e_model_interface
|
||||
* @param object $id [optional]
|
||||
* @return
|
||||
*/
|
||||
function createRecord($id=FALSE)
|
||||
function createPage()
|
||||
{
|
||||
global $e_userclass, $e_event;
|
||||
|
||||
$id = varset($_POST['edit']) ? key($_POST['edit']) : "";
|
||||
|
||||
$tp = e107::getParser();
|
||||
$ns = e107::getRender();
|
||||
@@ -1788,13 +1790,13 @@ class e_model_interface
|
||||
* @param object $id [optional]
|
||||
* @return
|
||||
*/
|
||||
function submitPage($id=FALSE)
|
||||
function saveRecord($id=FALSE)
|
||||
{
|
||||
global $e107cache, $admin_log, $e_event;
|
||||
$emessage = eMessage::getInstance();
|
||||
|
||||
$sql = e107::getDb();
|
||||
$tp = e107::getParser();
|
||||
|
||||
$mes = e107::getMessage();
|
||||
|
||||
$insert_array = array();
|
||||
|
||||
@@ -1822,11 +1824,11 @@ class e_model_interface
|
||||
}
|
||||
|
||||
|
||||
$emessage->add($message, $status);
|
||||
$mes->add($message, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic Save DB Record Function.
|
||||
* Generic Delete DB Record Function.
|
||||
* @param object $id
|
||||
* @return
|
||||
*/
|
||||
@@ -1837,13 +1839,13 @@ class e_model_interface
|
||||
return;
|
||||
}
|
||||
|
||||
$emessage = eMessage::getInstance();
|
||||
$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;
|
||||
$emessage->add($message, $status);
|
||||
$mes->add($message, $status);
|
||||
}
|
||||
|
||||
|
||||
@@ -1858,7 +1860,7 @@ class e_model_interface
|
||||
{
|
||||
$frm = e107::getForm();
|
||||
|
||||
$att = $this->fields[$key];
|
||||
$att = ($this->mode == 'options') ? $this->prefs[$key] : $this->fields[$key];
|
||||
$value = $row[$key];
|
||||
|
||||
if($att['type']=='method')
|
||||
@@ -1867,6 +1869,11 @@ class e_model_interface
|
||||
return $this->$meth($value);
|
||||
}
|
||||
|
||||
if($att['type']=='boolean')
|
||||
{
|
||||
return $frm->radio_switch($key, $row[$key]);
|
||||
}
|
||||
|
||||
return $frm->text($key, $row[$key], 50);
|
||||
|
||||
}
|
||||
@@ -1884,6 +1891,14 @@ class e_model_interface
|
||||
{
|
||||
$att = $this->fields[$key];
|
||||
//TODO add checkbox.
|
||||
|
||||
if($att['type']=='method')
|
||||
{
|
||||
$meth = $key;
|
||||
return $this->$meth($row[$key]);
|
||||
}
|
||||
|
||||
|
||||
if($key == "options")
|
||||
{
|
||||
$id = $this->primary;
|
||||
@@ -1906,6 +1921,76 @@ class e_model_interface
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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() // Non Functional.. needs to use native e_model functions.
|
||||
{
|
||||
global $pref, $admin_log;
|
||||
|
||||
$mes = e107::getMessage();
|
||||
|
||||
$temp['listPages'] = $_POST['listPages'];
|
||||
|
||||
if ($admin_log->logArrayDiffs($temp, $pref, 'CPAGE_04'))
|
||||
{
|
||||
save_prefs(); // Only save if changes
|
||||
// e107::getConfig()->
|
||||
$mes->add(LAN_SAVED, E_MESSAGE_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mes->add(CUSLAN_46);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generic Admin Menu Generator
|
||||
* @param object $action
|
||||
|
@@ -9,8 +9,8 @@
|
||||
* e107 Release Plugin
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_plugins/release/admin_config.php,v $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2009-10-22 05:14:11 $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2009-10-22 07:23:22 $
|
||||
* $Author: e107coders $
|
||||
*
|
||||
*/
|
||||
@@ -19,8 +19,7 @@ require_once("../../class2.php");
|
||||
if (!getperms("P")) { header("location:".e_BASE."index.php"); exit; }
|
||||
require_once(e_ADMIN."auth.php");
|
||||
|
||||
|
||||
class efeed extends e_model_interface
|
||||
class releasePlugin extends e_model_interface
|
||||
{
|
||||
var $fields;
|
||||
var $fieldpref;
|
||||
@@ -33,6 +32,7 @@ class efeed extends e_model_interface
|
||||
{
|
||||
|
||||
$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
|
||||
@@ -47,10 +47,11 @@ class efeed extends e_model_interface
|
||||
'options' => array('title'=> LAN_OPTIONS, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last')
|
||||
);
|
||||
|
||||
$this->prefs = array(
|
||||
$this->prefs = array( //TODO add option for core or plugin pref.
|
||||
|
||||
'pref_type' => array('title'=> 'type', 'type'=>'text'),
|
||||
'pref_folder' => array('title'=> 'folder', 'type' => 'text', 'width' => 'auto'), // User name
|
||||
'pref_name' => array('title'=> 'name', 'type' => 'text', 'width' => 'auto'),
|
||||
'pref_folder' => array('title'=> 'folder', 'type' => 'boolean'),
|
||||
'pref_name' => array('title'=> 'name', 'type' => 'text')
|
||||
|
||||
);
|
||||
|
||||
@@ -65,14 +66,21 @@ class efeed extends e_model_interface
|
||||
|
||||
$this->adminMenu = array(
|
||||
'list' => array('caption'=>'Release List', 'perm'=>'0'),
|
||||
'create' => array('caption'=>LAN_CREATE."/".LAN_EDIT, 'perm'=>'0')
|
||||
'create' => array('caption'=>LAN_CREATE."/".LAN_EDIT, 'perm'=>'0'),
|
||||
'options' => array('caption'=>LAN_OPTIONS, 'perm'=>'0'),
|
||||
'custom' => array('caption'=>'Custom Page', 'perm'=>0)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// custom method. (matches field/key name)
|
||||
// Custom View/Form-Element method. ie. Naming should match field/key with type=method.
|
||||
function release_type($curVal)
|
||||
{
|
||||
if($this->mode == 'list')
|
||||
{
|
||||
return $curVal;
|
||||
}
|
||||
|
||||
$types = array("theme","plugin");
|
||||
$text = "<select class='tbox' name='release_type' >";
|
||||
foreach($types as $val)
|
||||
@@ -83,118 +91,28 @@ class efeed extends e_model_interface
|
||||
$text .= "</select>";
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
//TODO move this to the model class.. and make generic.
|
||||
function optionsPage()
|
||||
|
||||
//custom Page = Naming should match $this->adminMenu key + 'Page'.
|
||||
function customPage()
|
||||
{
|
||||
global $e107, $pref,$emessage;
|
||||
|
||||
$frm = e107::getForm();
|
||||
|
||||
|
||||
if(!isset($pref['pageCookieExpire'])) $pref['pageCookieExpire'] = 84600;
|
||||
|
||||
//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>
|
||||
<tr>
|
||||
<td class='label'>".CUSLAN_29."</td>
|
||||
<td class='control'>
|
||||
".$frm->radio_switch('listPages', $pref['listPages'])."
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='label'>".CUSLAN_30."</td>
|
||||
<td class='control'>
|
||||
".$frm->text('pageCookieExpire', $pref['pageCookieExpire'], 10)."
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class='buttons-bar center'>
|
||||
".$frm->admin_button('saveOptions', CUSLAN_40, 'submit')."
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
";
|
||||
|
||||
$e107->ns->tablerender(LAN_OPTIONS, $emessage->render().$text);
|
||||
$ns = e107::getRender();
|
||||
$ns->tablerender("Custom","This is a custom Page");
|
||||
}
|
||||
|
||||
|
||||
function saveSettings()
|
||||
{
|
||||
global $pref, $admin_log, $emessage;
|
||||
$temp['listPages'] = $_POST['listPages'];
|
||||
$temp['pageCookieExpire'] = $_POST['pageCookieExpire'];
|
||||
if ($admin_log->logArrayDiffs($temp, $pref, 'CPAGE_04'))
|
||||
{
|
||||
save_prefs(); // Only save if changes
|
||||
$emessage->add(CUSLAN_45, E_MESSAGE_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
$emessage->add(CUSLAN_46);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$ef = new efeed;
|
||||
$ef->init();
|
||||
|
||||
|
||||
|
||||
|
||||
$rp = new releasePlugin;
|
||||
$rp->init();
|
||||
|
||||
require_once(e_ADMIN."footer.php");
|
||||
|
||||
|
||||
|
||||
|
||||
function admin_config_adminmenu()
|
||||
{
|
||||
global $ef;
|
||||
global $rp;
|
||||
global $action;
|
||||
$ef->show_options($action);
|
||||
$rp->show_options($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle page DOM within the page header
|
||||
*
|
||||
* @return string JS source
|
||||
*/
|
||||
function headerjs()
|
||||
{
|
||||
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;
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user