Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/kjvdictionary_store/modules/storeDistribution/model/ |
Upload File : |
<?php
class Distribution_model extends Database_Model {
private $distrib_id;
private $dc_name;
private $dc_email;
private $dc_currency;
private $dc_show;
private $dc_postcode;
private $dc_country;
private $dc_homepage;
private $areas;
private $module;
private $x_data;
const MODULES = [
'holidaysAus', 'holidaysUsa',
'freightAuspost', 'freightFedex', 'freightUps', 'freightUsps',
// 'track123', 'trackUsps',
'storeStripe', 'storePaypal',
];
public function DistribId() {
if (func_num_args()) {
$old_id = $this->distrib_id;
$this->distrib_id = func_get_arg(0);
if ($old_id != $this->distrib_id) {
$this->Load();
}
return $this;
}
return $this->distrib_id;
}
public function HomePage() {
if (func_num_args()) {
$this->dc_homepage = func_get_arg(0);
return $this;
}
return $this->dc_homepage;
}
public function Currency() {
if (func_num_args()) {
$this->dc_currency = func_get_arg(0);
return $this;
}
return $this->dc_currency;
}
public function ShowCurrency() {
if (func_num_args()) {
$this->dc_show = func_get_arg(0);
return $this;
}
return $this->dc_show;
}
public function CustomFields($rep) {
$rep->pagesize(25);
$col = $rep->AddColumn();
$col->name('dc_name')
->caption('Location Name')
->render(function($value, $item) {
$safename = htmlspecialchars($value);
$auth = hook_execute('nonce.create', FALSE, 'distrib', $item->dc_id, 600);
return "<a href=\"/admin/store/distribution?auth={$auth}\">$safename</a>";
});
$col = $rep->AddColumn();
$col->name('dc_country')
->caption('Country')
->width(60);
}
public function DistributionList($rep) {
$data = $rep->Query('select dc_id, dc_name, dc_country from distribution')
->GroupBy('dc_id')
->Execute();
return ['data' => $data];
}
protected function Load() {
$row = $this->Query("select * from `distribution`")
->Where('dc_id=%d', $this->distrib_id)
->Get()
->First();
$this->dc_name = $row->dc_name ?? '';
$this->dc_email = $row->dc_email ?? '';
$this->dc_currency = $row->dc_currency ?? '';
$this->dc_postcode = $row->dc_postcode ?? '';
$this->dc_country = $row->dc_country ?? '';
$this->dc_homepage = $row->dc_homepage ?? '';
$this->dc_show = (int) $row->dc_show ?? 0;
// load service areas and modules
$this->areas = [];
$this->module = [];
if ($this->distrib_id) {
$rows = $this->Query("select country from `distrib_country` ")
->Where('distrib=%d', $this->distrib_id)
->Get();
foreach($rows as $row) {
$this->areas[] = $row->country;
}
$rows = $this->Query("select dm_module,dm_active,dm_payload from `distrib_module` ")
->Where('dm_distrib=%d', $this->distrib_id)
->Get();
foreach($rows as $row) {
$this->module[$row->dm_module] = [
'active' => (int) $row->dm_active,
'payload' => json_decode($row->dm_payload, TRUE),
];
}
}
}
public function saveDetails($post) {
$record = $this->distrib_id ? $this->distrib_id : NULL;
$tab = $post['tab'];
switch($tab) {
case 'gen':
$x = $this->TableName('distribution')
->AutoInc('dc_id')
->InsertOrUpdate([
'dc_id' => $record,
],[
'dc_name' => trim($post['dc_name'] ?? ''),
'dc_email' => trim($post['dc_email'] ?? ''),
'dc_currency' => strtoupper(trim($post['dc_currency'] ?? '')),
'dc_postcode' => trim($post['dc_postcode'] ?? ''),
'dc_country' => trim($post['dc_country'] ?? ''),
'dc_homepage' => trim($post['dc_homepage'] ?? ''),
'dc_show' => (int) ($post['dc_show'] ?? '0'),
]);
$this->distrib_id = $x->dc_id;
break;
case 'ctry':
$this->saveDetails_Country($post['country'] ?? []);
break;
}
return TRUE;
}
public function saveDetails_Country($country) {
header('Content-type: text/plain');
$oldlist = $this->areas;
$newlist = $country;
// ignore unchanged
foreach($newlist as $index => $cc) {
$ps = array_search($cc, $oldlist);
if ($ps !== FALSE) {
unset($newlist[$index], $oldlist[$ps]);
}
};
if (count($newlist)) { // insert new stuff
$val = '';
foreach($newlist as $item) {
if ($val != '') $val .= ',';
$val .= "({$this->distrib_id},'$item')";
}
$sql = "insert into distrib_country (distrib,country) values $val";
$this->Query($sql)->Get();
$this->DbErr();
}
if (count($oldlist)) { // remove old stuff
$this->Query("delete from distrib_country")
->Where('distrib=%d', $this->distrib_id)
->WhereIn('country', $oldlist)
->Get();
$this->DbErr();
}
}
public function page_general() {
$homepage = [
[ 'key' => '', 'value' => '(please select store homepage)' ]
];
$homepage = hook_execute('url.key.select', $homepage);
$data = [
'template' => 'store_dist_general',
'dc_name' => $this->dc_name,
'dc_email' => $this->dc_email,
'dc_currency' => $this->dc_currency,
'dc_show' => (int) $this->dc_show,
'dc_postcode' => $this->dc_postcode,
'dc_country' => $this->dc_country,
'dc_homepage' => $this->dc_homepage,
'list_country' => hook_execute('geoip.list', []),
'list_homepage' => $homepage,
];
return $data;
}
// pages 2 and 3 only active once general page saved
public function page_country() {
$list = hook_execute('geoip.list', []);
$existing = array_flip($this->areas);
// to do: disable countries serviced by another warehouse
foreach($list as &$item) {
if (isset($existing[$item['key']])) $item['sel'] = 1;
}
return [
'id' => $this->distrib_id,
'template' => 'store_dist_country',
'list_country' => $list,
];
}
public function __field_enabled($value, $item) {
$enabled = $item['enabled'];
$required = $item['r'];
$missing = $item['m'];
$sel = $enabled ? ' checked' : '';
$dis = $required ? ' disabled' : '';
$edt = $required ? '' : ' class="checkbox-edit"';
return "<input type=\"checkbox\"$edt name=\"cb|{$item['module']}|{$item['a']}\" value=\"1\"$dis$sel>";
}
protected function CustomFields_Modules($rep) {
$rep->pagesize(10);
$col = $rep->AddColumn();
$col->className('details-control')
->width(20)
->sort('none');
$col = $rep->AddColumn();
$col->name('enabled')
->width(40)
->sort('none')
->caption('Enabled')
->className('dt-center') // sClass
->render([$this, '__field_enabled']);
$col = $rep->AddColumn();
$col->name('name')
->width(110)
->caption('Name');
$col = $rep->AddColumn(); // hidden field
$col->name('data')
->width(0);
$col = $rep->AddColumn();
$col->name('desc')
->caption('Description');
}
public function page_modules() {
// generate field defs for module list - no upgrade
$rep = new ReportObject;
$this->CustomFields_Modules($rep);
$res = [];
$rep->asDataTablesDefinition($res);
$res['id'] = $this->distrib_id;
$res['template'] = 'store_dist_modules';
return $res;
}
// each module, description, and whether this has been enabled for this warehouse
public function page_modules_list($settings_model) {
$result = [];
$rep = new ReportObject;
$this->CustomFields_Modules($rep);
$modules = $GLOBALS['loader']->getModuleList();
foreach($modules as $module => $module_data) {
if (in_array($module, static::MODULES)) {
$module_data['current'] = $this->module[$module]['payload'] ?? [];
$enabled = $this->module[$module]['active'] ?? 0;
$node = [
'm' => 0,
'r' => 0,
'a' => '',
'enabled' => $enabled,
'name' => $module,
'desc' => $module_data['.info']['name'],
'data' => [],
'module' => $module,
];
$settings_model->generateSettingsDropdown($node, $module, $module_data, '/admin/store/distribution/modules-edit', $this->distrib_id);
$data[] = $node;
}
}
$this->x_data = $data;
$rep->onData([$this, '__ondata']);
$data = $rep->Execute();
unset($node);
foreach($data as &$node) {
if (!count($node['data'])) $node['DT_RowClass'] = 'nochild';
}
return [ 'data' => $data ];
}
public function __ondata($rep) {
return $this->x_data;
}
public function moduleSettingsEnable($post, $param2) {
if (isset($post['value'])) {
$this->TableName('distrib_module')
->InsertOrUpdate([
'dm_distrib' => $this->distrib_id,
'dm_module' => $param2,
], [
'dm_active' => $post['value'],
], [
'dm_payload' => '{}',
]);
return NULL;
}
return [
'result' => 29541,
'message' => 'Unknown update action',
];
/* header('Content-type: text/plain');
var_dump($param2);
var_dump($param3);
var_dump($post);
exit; */
}
private function _getModuleNameFromHash($modulehash) {
$salt = $GLOBALS['loader']->Salt();
foreach($this->module as $module_name => $stuff) {
$thishash = md5("{$salt}:$module_name:{$this->distrib_id}");
if ($thishash == $modulehash) return $module_name;
}
return FALSE;
}
public function moduleSettingsUpdate($post, $modulehash, $fieldname) {
$module_name = $this->_getModuleNameFromHash($modulehash);
if ($module_name === FALSE) return FALSE;
$value = $post['value'];
$payload = $this->module[$module_name]['payload'] ?? [];
$payload[$fieldname] = $value;
$this->TableName('distrib_module')
->InsertOrUpdate([
'dm_distrib' => $this->distrib_id,
'dm_module' => $module_name,
], [
'dm_payload' => json_encode($payload, JSON_UNESCAPED_SLASHES),
]);
return [
'refresh' => FALSE, // don't trigger 'loaded.template',
];
}
public function MapToDistribution($country) {
$row = $this->Query('select distrib from `distrib_country`')
->Where('country=%s', $country)
->First();
if ($row->empty()) return -1; // not found
return (int)$row->distrib;
}
public function loadModuleSettings($data = [], $modulename = '' ) {
if ($modulename != '') {
return $this->module[$modulename]['payload'] ?? $data;
} else {
foreach(static::MODULES as $modulename) {
$module_info = $GLOBALS['loader']->GetModuleInfo($modulename);
if (isset($this->module[$modulename]) && !empty($this->module[$modulename]['active'])) {
$module_info['active'] = true;
$module_info['current'] = $this->module[$modulename]['payload'];
$GLOBALS['loader']->LoadModule($modulename);
// enable the module,
// load distrib-specific settinsg
} else {
$module_info['active'] = false;
// disable the module
}
}
}
}
public function enableModule($modulename) {
if (isset($this->module[$modulename]) && !empty($this->module[$modulename]['active'])) {
$module_info = $GLOBALS['loader']->GetModuleInfo($modulename);
$module_info['active'] = true;
$module_info['current'] = $this->module[$modulename]['payload'];
$GLOBALS['loader']->LoadModule($modulename);
}
}
}