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/ |
Upload File : |
<?php
// <a href="https://www.freepik.com/free-photo/abstract-golden-sparkle-background_890771.htm#from_element=cross_selling__photo">Image by starline on Freepik</a>
namespace modules\storeDistribution;
class main extends \moduleMain {
use \modules\input\traits {
\modules\input\traits::__construct as __ConstructInput;
}
use \modules\database\traits {
\modules\database\traits::__construct as __ConstructDatabase;
}
use \modules\output\traits {
\modules\output\traits::__construct as __ConstructOutput;
}
private $view;
private $distrib_id;
private $firsttime;
public function __construct() {
parent::__construct(__DIR__);
$this->firsttime = TRUE;
$this->__ConstructInput();
$this->__ConstructDatabase();
$this->__ConstructOutput();
}
public function Activate() {
$this->view = $GLOBALS['loader']->getView('storedist_view', __DIR__);
hook_add('controller.store.distribution', [$this, '__distributions']);
hook_add('list.store.distribution', [$this, '__distributionlist'], 40);
hook_add('template.store.product.COL9', [$this, '__addcurrency'], 20); // add currency abbr to the price
hook_add('order.initialize', [$this, '__orderInitialize']); // add the Distribution Centre to the saved order
hook_add('order.array', [$this, '__orderGet']); // add distribution center to the order data
hook_add('fulfillment.field.list', [$this, '__fulfillment_fields'], 50); // display the distribution center in fulfillment
hook_add('fulfillment.field.sql', [$this, '__fulfillment_sql']); // update the query to include distribution center
hook_add('store.currency', [$this, '__getCurrency']);
hook_add('distribution.tab', [$this, '__distribution_tabs'], 1); // must be priority 1
hook_add('distribution.tab.general', [$this, '__distribution_general']);
hook_add('distribution.tab.country', [$this, '__distribution_country']);
hook_add('distribution.tab.module', [$this, '__distribution_module']);
hook_add('cart.display', [$this, '__loadDistributionFromOrder'], 1);
hook_add('store.tab', [$this, '__settings_tabs40'], 40); // store settings
hook_add('store.tab.distribution', [$this, '__settings_distribution']);
hook_add('output.errordetail', [$this, '__error']);
hook_add('global.load', [$this, 'Startup'], 90);
hook_add('uri', [$this, '__geofence'], 90);
hook_add('url.store.homepage', [$this, '__filter'], 10);
hook_add('uri.intercept', [$this, '__intercept'], 10); // "/~/..." urls
hook_add('config.get', [$this, '__getconfigitem'], 90);
}
public function __distribution_tabs(&$tabs, $uri) {
// extract the auth from the uri
if (($p = strpos($uri, '?')) !== FALSE) {
parse_str(substr($uri, $p + 1), $param);
$uri = substr($uri, 0, $p);
$auth = $param['auth'] ?? '';
} else {
$auth = '';
}
$tabs['_tab'][] = [
'name' => 'General',
'icon' => '<i class="fas fa-newspaper"></i>',
'fragment' => 'general',
'className' => '',
];
$tabs['_tab'][] = [
'name' => 'Countries',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'country',
'className' => '',
];
$tabs['_tab'][] = [
'name' => 'Modules',
'icon' => '<i class="fas fa-cogs"></i>',
'fragment' => 'module',
'className' => '',
];
$tabs['uri'] = $uri;
$tabs['default'] = 'general';
$tabs['auth'] = $auth;
}
public function __distribution_general(&$data, $ephemeral) {
$_GET['auth'] = $ephemeral['auth'];
$data = hook_execute('execute.internal', NULL, '/admin/store/distribution/gen' );
}
public function __distribution_country(&$data, $ephemeral) {
$_GET['auth'] = $ephemeral['auth'];
$data = hook_execute('execute.internal', NULL, '/admin/store/distribution/ctry');
}
public function __distribution_module(&$data, $ephemeral) {
$_GET['auth'] = $ephemeral['auth'];
$data = hook_execute('execute.internal', NULL, '/admin/store/distribution/mod');
}
public function __distributionlist(&$res) {
$model_distrib = $this->LoadModel('distribution_model');
$rep = new \ReportObject;
hook_execute('distribution.field.list', $rep);
$res = $model_distrib->DistributionList($rep);
}
public function __addcurrency(&$html) {
$model_distrib = $this->LoadModel('distribution_model');
if ($model_distrib->ShowCurrency()) {
$text = '<span style="font-size: 0.7em">' . $model_distrib->Currency() . '</span>';
$this->view->UpdateHTML($html, 'COL9', $text);
}
}
public function __getCurrency(&$res) {
$model_distrib = $this->LoadModel('distribution_model');
$res = $model_distrib->Currency();
}
private function _distributions_editable(&$res, $auth) { // $auth is for the field, not the distribution
$model_distrib = $this->LoadModel('distribution_model');
$info = hook_execute( 'nonce.verify', FALSE, 'modedit', FALSE, $auth );
if ($info === FALSE) {
$res = [
'result' => -2,
'message' => 'You do not have permission to change this setting',
];
return;
}
[$hash, $setting_name] = explode('-', $info, 2);
$distrib_id = substr($hash, 32);
$model_distrib->DistribId($distrib_id);
$hash = substr($hash, 0, 32);
$payload = $model_distrib->moduleSettingsUpdate($this->post(), $hash, $setting_name);
header('Content-type: application/json');
die(json_encode($payload, JSON_UNESCAPED_SLASHES));
}
public function __distributions(&$res, $auth, $param1, $param2, $param3, $param4, $param5, $param6) {
$isPost = $this->method() == 'POST';
if ($isPost && $param1 == 'modules-edit' && preg_match('~[0-9a-f]{32}~i', $param2)) { // auth is in a diff location when editing module-specific settings
return $this->_distributions_editable($res, $param3);
}
$distrib_id = hook_execute( 'nonce.verify', FALSE, 'distrib', FALSE, $auth );
if ($distrib_id === FALSE) {
$res = [
'result' => -2,
'message' => 'You do not have permission to access this function',
'auth' => $auth,
'param1' => $param1,
'param2' => $param2,
'param3' => $param3,
];
return;
}
$model_distrib = $this->LoadModel('distribution_model');
$model_distrib->DistribId($distrib_id);
if ($isPost) {
$payload = [];
switch($param1) {
case 'modules-edit':
$payload = $model_distrib->moduleSettingsEnable($this->post(), $param2);
break;
default:
$model_distrib->saveDetails($this->post());
$distrib_id = $model_distrib->DistribId();
$auth = hook_execute('nonce.create', FALSE, 'distrib', $distrib_id, 1800);
$this->Redirect('/admin/store/distribution?auth=' . $auth . '#general');
break;
}
header('Content-type: application/json');
die(json_encode($payload, JSON_UNESCAPED_SLASHES));
}
switch($param1) {
case '':
$res['template'] = 'store_dist_edit';
$id = $GLOBALS['loader']->CreateEphemeral(
[
'action' => 'tabs',
'hook' => 'distribution.tab',
'distrib' => $distrib_id,
], '', 1800 // normally 600 = 10min?
);
$res['tabauth'] = $id;
break;
case 'gen':
$data = $model_distrib->page_general();
$res = array_merge($res, $data);
$res['auth'] = hook_execute('nonce.create', FALSE, 'distrib', $distrib_id, 1800);
break;
case 'ctry':
$data = $model_distrib->page_country();
$res = array_merge($res, $data);
$res['auth'] = hook_execute('nonce.create', FALSE, 'distrib', $distrib_id, 1800);
break;
case 'mod':
$data = $model_distrib->page_modules();
$res = array_merge($res, $data);
$res['auth'] = hook_execute('nonce.create', FALSE, 'distrib', $distrib_id, 1800);
break;
case 'modules-list':
$settings = $this->LoadModel('settings_model', 'config');
$GLOBALS['loader']->Unscanned(TRUE);
// to do: add in current status
$data = $model_distrib->page_modules_list($settings);
header('Content-type: application/json');
die(json_encode($data, JSON_UNESCAPED_SLASHES));
break;
}
}
private function _initialize() {
$distrib_id = $_SESSION['_distrib'] ?? 0;
$model_distrib = $this->LoadModel('distribution_model');
$change = FALSE;
if (!$distrib_id) { // if distrib_id missing from local session:
$cookie = $_COOKIE['region'] ?? '';
$country = '';
if ($cookie != '') { // - load it, and decode.
$country = hook_execute('nonce.verify', FALSE, 'country', FALSE, $cookie, TRUE); // no expiry date for this
}
if ($country == '' || $country === FALSE) {
// - get ip address and look up country
$ip = $this->getClientIP();
$info = hook_execute('geoip.lookup', [], $ip);
$country = $info['country'] ?? 'ZZ';
$cookie = hook_execute('nonce.create', FALSE, 'country', $country, 1800);
// - save cookie - encrypted content
setcookie('region', $cookie, time() + 365 * 86400, '/', '', TRUE, TRUE);
}
$distrib_id = $model_distrib->MapToDistribution($country);
$change = TRUE;
}
$override = $_GET['C'] ?? '';
if ($override != '') {
$distrib_id = $model_distrib->MapToDistribution(strtoupper($override));
$change = TRUE;
}
// if country query param present, override country with specified value
// and save distrib_id in local session, not in region cookie
if ($change) {
$_SESSION['_distrib'] = $distrib_id;
}
$this->distrib_id = $distrib_id;
// load distrib modules and settings
// or Store not available in your country
return $model_distrib;
}
// this should only be for the first html page displayed
public function Startup() {
$accept = $_SERVER['HTTP_ACCEPT'] ?? '';
if (strpos($accept, 'text/html') === FALSE) return;
$redirect = $_SERVER['REDIRECT_URL'] ?? '';
if (substr($redirect, 0, 2) == '/~' || substr($redirect, 0, 7) == '/static') return;
$this->_initialize();
// if (substr($redirect, 0, 7) != '/store/' && $redirect != '/store') return;
}
public function __geofence(&$uri, $__INPUT, $__OUTPUT) {
$accept = $_SERVER['HTTP_ACCEPT'] ?? '';
if (strpos($accept, 'text/html') === FALSE) return;
$myuri = $uri;
if (($p = strpos($myuri, '?')) !== FALSE) {
$param = substr($myuri, $p);
$myuri = substr($myuri, 0, $p);
} else {
$param = '';
}
if (($myuri == '/store' || substr($myuri, 0, 7) == '/store/') && ($myuri != '/store/snafu') && (substr($myuri, 0, 13) != '/store/snafu/')) {
if ($this->distrib_id == -1) {
$uri = '/store/snafu/560';
} else {
$model_distrib = $this->LoadModel('distribution_model');
$model_distrib->DistribId($this->distrib_id);
$model_distrib->loadModuleSettings();
}
}
}
public function __error(&$data, $http_status) {
if ($http_status->status() == 560) {
$data['message'] = 'Store Unavailable';
$data['desc'] = 'We are sorry, the Online Store is not available in your country.';
}
}
public function __filter(&$uri) {
// return a store key:value pair
$model_distrib = $this->LoadModel('distribution_model');
$model_distrib->DistribId($this->distrib_id);
$temp = $model_distrib->HomePage();
if ($temp != '') $uri = $temp;
}
public function __getconfigitem(&$data, $module_name) {
if ($this->distrib_id) {
$model_distrib = $this->LoadModel('distribution_model');
$model_distrib->DistribId($this->distrib_id);
$data = $model_distrib->loadModuleSettings($data, $module_name);
}
}
public function __intercept($module_name) {
if ($this->firsttime) {
$model_distrib = $this->_initialize();
if ($this->distrib_id) {
$this->firsttime = FALSE;
$model_distrib->DistribId($this->distrib_id);
$model_distrib->loadModuleSettings(); // we have to enable all modules
}
}
}
public function __orderInitialize(&$payload) {
$payload['so_distribution'] = $this->distrib_id;
}
public function __fulfillment_fields($rep) {
$col = $rep->InsertBefore('so_name');
$col->name('so_distribution')
->className('so-distribution')
->caption('Center')
->render([$this, '__orderDistrib'])
->width(60);
}
public function __fulfillment_sql(&$sql, $rep) {
$sql .= ' left join `distribution` on dc_id = so_distribution';
}
public function __orderDistrib($value, $item) {
return [
'val' => $value,
'disp' => $item->dc_name,
];
}
public function __orderGet(&$result, $row) {
$result['distribution'] = (int) $row->so_distribution;
}
public function __loadDistributionFromOrder(&$res, $type = '') {
if ($type == 'fulfill' && $res['distribution']) {
$model_distrib = $this->LoadModel('distribution_model');
$model_distrib->DistribId($res['distribution']);
$model_distrib->loadModuleSettings();
}
}
public function __settings_tabs40(&$tabs, $uri) {
$tabs['_tab'][] = [
'name' => 'Distribution Centres',
'icon' => '<i class="fas fa-globe-americas"></i>',
'fragment' => 'distribution',
'className' => '',
];
}
public function __settings_distribution(&$data, $ephemeral) {
$data = hook_execute('execute.internal', NULL, '/admin/store-distribution');
}
}