OSB enhancements to date

This commit is contained in:
Deon George
2010-11-30 09:41:08 +11:00
parent 8715a2059b
commit ec6a542bc3
478 changed files with 23423 additions and 9309 deletions

View File

@@ -25,6 +25,8 @@
* @subpackage Modules
*/
require_once(PATH_CORE.'xml.inc.php');
/**
* Module Abstract Class
* This abstract class provides the basic variables and methods for all modules.
@@ -35,11 +37,26 @@
abstract class OSB_module {
# Validation error array
public $val_error = array();
# Debug output to STDOUT
protected $debug = false;
# Inbound VAR value
protected $VAR = array();
# Object database ID & Record
private $record = array();
# Last Record ID read from DB
private $record_id = null;
/**
* Initialise the module
*/
public function __construct() {
public function __construct($id=null) {
global $VAR;
$this->VAR = $VAR;
if (isset($this->VAR['debug']) && $this->VAR['debug'])
$this->debug = true;
$f = sprintf('%s%s/%s_construct.xml',PATH_MODULES,get_class($this),get_class($this));
if (is_file($f)) {
@@ -64,6 +81,36 @@ abstract class OSB_module {
bindtextdomain($this->module,PATH_LANGUAGE);
bind_textdomain_codeset($this->module,'UTF-8');
}
$this->sql_LoadRecord($id);
}
/**
* Return this record from the database
*/
protected function getRecord() {
return isset($this->record) ? $this->record : null;
}
protected function clearRecord() {
$this->record = array();
}
protected function delRecordAttr($attr) {
if (isset($this->record[$attr]))
unset($this->record[$attr]);
}
/**
* Return a field from the database record
*/
protected function getRecordAttr($attr) {
return isset($this->record[$attr]) ? $this->record[$attr] : null;
}
protected function setRecordAttr($attr,$value) {
$this->record[$attr] = $value;
return $value;
}
public function getlist() {
@@ -98,7 +145,7 @@ abstract class OSB_module {
* Basic module helper when interacting with the database.
*/
private function database($type,$VAR,$method=null) {
if ($type)
if ($type && ! is_array($this->method[$type]))
$this->method[$type] = explode(',',$this->method[$type]);
if (is_null($method) && $type)
@@ -246,7 +293,11 @@ abstract class OSB_module {
public function user_search($VAR) {
if (! SESS_LOGGED) return false;
$VAR[$this->module.'_account_id'] = SESS_ACCOUNT;
if (get_class($this) == 'discount')
$VAR[$this->module.'_avail_account_id'] = SESS_ACCOUNT;
else
$VAR[$this->module.'_account_id'] = SESS_ACCOUNT;
$this->database('search',$VAR);
}
@@ -256,7 +307,7 @@ abstract class OSB_module {
public function user_search_show($VAR) {
if (! SESS_LOGGED) return false;
$this->database('search',$VAR,'search_show');
return $this->database('search',$VAR,'search_show');
}
/**
@@ -301,6 +352,8 @@ abstract class OSB_module {
list($class,$method) = explode(':',$VAR['_page']);
$method = strtolower($method);
if (! isset($this->tpl[$method]))
return;
@@ -325,7 +378,9 @@ abstract class OSB_module {
default:
printf('<td class="table_heading"%s>',isset($details['width']) ? sprintf(' style="width: %s;"',$details['width']) : '');
printf('<script type="text/javascript">document.write(search_heading(\'%s\',\'%s\'));</script>',
isset($details['translate']) ? $C_translate->translate($details['translate'],$this->module) : $C_translate->tf(array('module'=>$this->module,'field'=>$details['field']),null),
isset($details['translate'])
? $C_translate->translate($details['translate'],$this->module)
: $C_translate->tf(array('module'=>$this->module,'field'=>$details['field']),null),
$details['field']);
echo '</td>';
}
@@ -336,7 +391,7 @@ abstract class OSB_module {
# Loop through each record
if (is_array($args) && count($args[0])) {
foreach ($args[0] as $key => $values) {
printf('<tr id="row%s" onclick="row_sel(\'%s\',1);" ondblclick="window.location=\'?_page=%s:view&amp;id=%s,\';" onmouseover="row_mouseover(\'%s\',\'row_mouse_over_select\',\'row_mouse_over\');" onmouseout="row_mouseout(\'%s\',\'%s\',\'row_select\');" class="%s">',
printf('<tr id="row%s" onclick="row_sel(\'%s\',1);" ondblclick="window.location=\'?_page=%s:view&amp;id=%s\';" onmouseover="row_mouseover(\'%s\',\'row_mouse_over_select\',\'row_mouse_over\');" onmouseout="row_mouseout(\'%s\',\'%s\',\'row_select\');" class="%s">',
$values['id'],$values['id'],$this->module,$values['id'],$values['id'],$values['id'],$values['_C'],$values['_C']);
foreach ($this->tpl[$method] as $index => $details) {
@@ -457,5 +512,61 @@ abstract class OSB_module {
return $arr;
}
protected function sql_SaveRecord($noconvert=false,$ignoreval=false) {
global $VAR;
$lVAR = array();
if (is_array($VAR))
$lVAR = array_merge($VAR);
foreach ($this->record as $k => $v)
$lVAR[sprintf('%s_%s',$this->table,$k)] = $v;
$lVAR['_noredirect'] = true;
if ($noconvert)
$lVAR['_noconvert'] = true;
if ($ignoreval)
$lVAR['_ignoreval'] = true;
# Adding record
if (! isset($this->record['id']) || $this->record['id'] != $this->record_id)
return $this->add($lVAR);
else
return $this->update($lVAR);
}
protected function sql_LoadRecord($id) {
$record = $this->sql_GetRecords(array('where'=>array('id'=>$id)));
if (count($record) == 1) {
$this->record = array_pop($record);
$this->record_id = $id;
} else {
$this->record = null;
$this->record_id = null;
}
}
/**
* Get Data out of the tables for the module
*
* @return array Table records
*/
protected function sql_GetRecords($opt=array()) {
$db = &DB();
$data = array();
$result = $db->Execute(sqlSelect($this->table,'*',$opt));
if ($result && $result->RecordCount())
while (! $result->EOF) {
array_push($data,$result->fields);
$result->MoveNext();
}
return $data;
}
}
?>