mirror of
https://github.com/e107inc/e107.git
synced 2025-08-08 07:36:32 +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.16 $
|
||||
* $Date: 2009-10-22 04:15:27 $
|
||||
* $Revision: 1.17 $
|
||||
* $Date: 2009-10-22 05:14:07 $
|
||||
* $Author: e107coders $
|
||||
*/
|
||||
|
||||
@@ -1607,6 +1607,7 @@ class e_model_interface
|
||||
var $listQry;
|
||||
var $table;
|
||||
var $primary;
|
||||
var $mode; // to work with $_GET and admin menu.
|
||||
|
||||
function __construct()
|
||||
{
|
||||
@@ -1641,6 +1642,7 @@ class e_model_interface
|
||||
{
|
||||
$this->listRecords();
|
||||
}
|
||||
//TODO add options 'preferences page'.
|
||||
|
||||
if(isset($_POST['submit-e-columns']))
|
||||
{
|
||||
@@ -1703,22 +1705,24 @@ class e_model_interface
|
||||
</form>
|
||||
";
|
||||
|
||||
$ns->tablerender($this->pluginTitle." :: ".$this->listCaption, $mes->render().$text);
|
||||
$ns->tablerender($this->pluginTitle." :: ".$this->adminMenu['list']['caption'], $mes->render().$text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generic DB Record Creation Form.
|
||||
* @param object $id [optional]
|
||||
* @return
|
||||
*/
|
||||
function createRecord($id=FALSE)
|
||||
{
|
||||
global $frm, $e_userclass, $e_event;
|
||||
global $e_userclass, $e_event;
|
||||
|
||||
$tp = e107::getParser();
|
||||
$ns = e107::getRender();
|
||||
$sql = e107::getDb();
|
||||
$frm = e107::getForm();
|
||||
|
||||
|
||||
if($id)
|
||||
{
|
||||
@@ -1775,7 +1779,7 @@ class e_model_interface
|
||||
</fieldset>
|
||||
</form>";
|
||||
|
||||
$ns->tablerender($this->pluginTitle." :: ".$this->createCaption, $text);
|
||||
$ns->tablerender($this->pluginTitle." :: ".$this->adminMenu['create']['caption'], $text);
|
||||
}
|
||||
|
||||
|
||||
@@ -1786,16 +1790,21 @@ class e_model_interface
|
||||
*/
|
||||
function submitPage($id=FALSE)
|
||||
{
|
||||
global $sql, $tp, $e107cache, $admin_log, $e_event;
|
||||
global $e107cache, $admin_log, $e_event;
|
||||
$emessage = eMessage::getInstance();
|
||||
$sql = e107::getDb();
|
||||
$tp = e107::getParser();
|
||||
|
||||
|
||||
$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];
|
||||
$insert_array[$key] = $_POST[$key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1803,7 +1812,7 @@ class e_model_interface
|
||||
{
|
||||
$insert_array['WHERE'] = $this->primary." = ".$id;
|
||||
$status = $sql->db_Update($this->table,$insert_array) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED;
|
||||
$message = LAN_UPDATED;
|
||||
$message = LAN_UPDATED; // deliberately ambiguous - to be used on success or error.
|
||||
|
||||
}
|
||||
else
|
||||
@@ -1833,10 +1842,90 @@ class e_model_interface
|
||||
|
||||
$query = $this->primary." = ".$id;
|
||||
$status = $sql->db_Delete($this->table,$query) ? E_MESSAGE_SUCCESS : E_MESSAGE_FAILED;
|
||||
$message = LAN_DELETED;
|
||||
$emessage->add($message, $status);
|
||||
$message = LAN_DELETED;
|
||||
$emessage->add($message, $status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Render Form Element (edit page)
|
||||
* @param object $key
|
||||
* @param object $row
|
||||
* @return
|
||||
*/
|
||||
function renderElement($key,$row)
|
||||
{
|
||||
$frm = e107::getForm();
|
||||
|
||||
$att = $this->fields[$key];
|
||||
$value = $row[$key];
|
||||
|
||||
if($att['type']=='method')
|
||||
{
|
||||
$meth = $key;
|
||||
return $this->$meth($value);
|
||||
}
|
||||
|
||||
return $frm->text($key, $row[$key], 50);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Render Field value (listing page)
|
||||
* @param object $key
|
||||
* @param object $row
|
||||
* @return
|
||||
*/
|
||||
function renderValue($key,$row)
|
||||
{
|
||||
$att = $this->fields[$key];
|
||||
//TODO add checkbox.
|
||||
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 Admin Menu Generator
|
||||
* @param object $action
|
||||
* @return
|
||||
*/
|
||||
function show_options($action)
|
||||
{
|
||||
|
||||
$action = varset($_GET['mode'],'list');
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -9,8 +9,8 @@
|
||||
* e107 Release Plugin
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_plugins/release/admin_config.php,v $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2009-10-22 04:15:32 $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2009-10-22 05:14:11 $
|
||||
* $Author: e107coders $
|
||||
*
|
||||
*/
|
||||
@@ -18,9 +18,6 @@
|
||||
require_once("../../class2.php");
|
||||
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);
|
||||
require_once(e_HANDLER."model_class.php");
|
||||
|
||||
|
||||
class efeed extends e_model_interface
|
||||
@@ -37,141 +34,44 @@ 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', 'width'=>'auto','method'=>'feed_type'),
|
||||
'release_type' => array('title'=> 'type', 'type' => 'method', 'width'=>'auto'),
|
||||
'release_folder' => array('title'=> 'folder', 'type' => 'text', 'width' => 'auto'), // User name
|
||||
'release_name' => array('title'=> 'name', 'type' => 'text', 'width' => 'auto'),
|
||||
'release_version' => array('title'=> 'version', 'type' => 'text', 'width' => 'auto'),
|
||||
'release_author' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left first'), // Display name
|
||||
'release_authorURL' => array('title'=> LAN_AUTHOR.'URL', 'type' => 'url', 'width' => 'auto', 'thclass' => 'left first'), // Display name
|
||||
'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'), // Photo
|
||||
'release_compatibility' => array('title'=> 'compatib', 'type' => 'text', 'width' => '10%', 'thclass' => 'center' ), // Real name (no real vetting)
|
||||
'release_url' => array('title'=> 'URL', 'type' => 'url', 'width' => '10%', 'thclass' => 'center' ), // No real vetting
|
||||
'release_date' => array('title'=> LAN_DATE, 'type' => 'text', 'width' => 'auto'),
|
||||
'release_compatibility' => array('title'=> 'compatib', 'type' => 'text', 'width' => '10%', 'thclass' => 'center' ),
|
||||
'release_url' => array('title'=> 'URL', 'type' => 'url', 'width' => '10%', 'thclass' => 'center' ),
|
||||
'options' => array('title'=> LAN_OPTIONS, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last')
|
||||
);
|
||||
|
||||
$this->prefs = array(
|
||||
'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'),
|
||||
|
||||
);
|
||||
|
||||
$this->fieldpref = (varset($user_pref['admin_release_columns'])) ? $user_pref['admin_release_columns'] : array_keys($this->fields);
|
||||
$this->table = "release";
|
||||
|
||||
$this->listQry = "SELECT * FROM #release ORDER BY release_id DESC";
|
||||
$this->editQry = "SELECT * FROM #release WHERE release_id = {ID}";
|
||||
|
||||
$this->table = "release";
|
||||
$this->primary = "release_id";
|
||||
$this->pluginTitle = "e107 Release";
|
||||
|
||||
$this->listCaption = "Release List";
|
||||
$this->createCaption = LAN_CREATE."/".LAN_EDIT;
|
||||
$this->adminMenu = array(
|
||||
'list' => array('caption'=>'Release List', 'perm'=>'0'),
|
||||
'create' => array('caption'=>LAN_CREATE."/".LAN_EDIT, 'perm'=>'0')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
/**
|
||||
* Generic DB Record Listing Function.
|
||||
* @param object $mode [optional]
|
||||
* @return
|
||||
*/
|
||||
/*function listRecords($mode=FALSE)
|
||||
{
|
||||
$ns = e107::getRender();
|
||||
$sql = e107::getDb();
|
||||
|
||||
global $frm, $pref;
|
||||
|
||||
$emessage = eMessage::getInstance();
|
||||
|
||||
$text = "<form method='post' action='".e_SELF."?mode=create'>
|
||||
<fieldset id='core-release-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).
|
||||
|
||||
"<tbody>";
|
||||
|
||||
|
||||
if(!$sql->db_Select_gen($this->listQry))
|
||||
{
|
||||
$text .= "\n<tr><td colspan='".count($this->fields)."' class='center middle'>".CUSLAN_42."</td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$row = $sql->db_getList('ALL', FALSE, FALSE);
|
||||
|
||||
foreach($row as $field)
|
||||
{
|
||||
$text .= "<tr>\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<td ".$class.">".$this->renderValue($key,$field)."</td>\n" : "";
|
||||
}
|
||||
$text .= "</tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
$text .= "
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</form>
|
||||
";
|
||||
|
||||
$ns->tablerender($this->pluginTitle." :: ".$this->listCaption, $emessage->render().$text);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Render Field value (listing page)
|
||||
* @param object $key
|
||||
* @param object $row
|
||||
* @return
|
||||
*/
|
||||
function renderValue($key,$row)
|
||||
{
|
||||
$att = $this->fields[$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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Form Element (edit page)
|
||||
* @param object $key
|
||||
* @param object $row
|
||||
* @return
|
||||
*/
|
||||
function renderElement($key,$row)
|
||||
{
|
||||
global $frm;
|
||||
$att = $this->fields[$key];
|
||||
$value = $row[$key];
|
||||
|
||||
if($att['method'])
|
||||
{
|
||||
$meth = $att['method'];
|
||||
return $this->$meth($value);
|
||||
}
|
||||
|
||||
return $frm->text($key, $row[$key], 50);
|
||||
|
||||
}
|
||||
|
||||
function feed_type($curVal)
|
||||
// custom method. (matches field/key name)
|
||||
function release_type($curVal)
|
||||
{
|
||||
$types = array("theme","plugin");
|
||||
$text = "<select class='tbox' name='release_type' >";
|
||||
@@ -185,128 +85,13 @@ class efeed extends e_model_interface
|
||||
}
|
||||
|
||||
|
||||
/*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 = "
|
||||
<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->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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
*/
|
||||
//TODO move this to the model class.. and make generic.
|
||||
function optionsPage()
|
||||
{
|
||||
global $e107, $pref, $frm, $emessage;
|
||||
global $e107, $pref,$emessage;
|
||||
|
||||
$frm = e107::getForm();
|
||||
|
||||
|
||||
if(!isset($pref['pageCookieExpire'])) $pref['pageCookieExpire'] = 84600;
|
||||
|
||||
@@ -364,25 +149,7 @@ class efeed extends e_model_interface
|
||||
}
|
||||
|
||||
|
||||
function show_options($action)
|
||||
{
|
||||
$action = varset($_GET['mode'],'list');
|
||||
|
||||
$var['list']['text'] = $this->listCaption;
|
||||
$var['list']['link'] = e_SELF."?mode=list";
|
||||
$var['list']['perm'] = "0";
|
||||
|
||||
$var['create']['text'] = $this->createCaption;
|
||||
$var['create']['link'] = e_SELF."?mode=create";
|
||||
$var['create']['perm'] = 0;
|
||||
|
||||
/*
|
||||
$var['options']['text'] = LAN_OPTIONS;
|
||||
$var['options']['link'] = e_SELF."?options";
|
||||
$var['options']['perm'] = "0";*/
|
||||
|
||||
e_admin_menu($this->pluginTitle, $action, $var);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user