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/storeAccount/controller/ |
Upload File : |
<?php
class storeAccount_account extends controller {
private $model;
public function __construct() {
parent::__construct(dirname(__DIR__));
$this->level = isset($_SESSION['current_user']) ? $_SESSION['current_user']['u_level'] : 0;
$this->user_id = isset($_SESSION['current_user']) ? intval($_SESSION['current_user']['u_id']) : 0;
$this->model = $this->LoadModel('useraccount_model');
}
public function __Register() {
$this->RegisterView(__CLASS__ .'::menu', ['storeaccount_view' => ['storeaccount_menu']]);
$this->RegisterView(__CLASS__ .'::order', ['storeaccount_view' => ['storeaccount_order', 'storeaccount_tracking', 'storeaccount_detail', 'storeaccount_edit', 'storeaccount_cancel']]);
$this->RegisterView(__CLASS__ .'::address', ['storeaccount_view' => ['storeaccount_address']]);
}
/** member */
public function menu() {
$res = $this->DefaultResult(__METHOD__);
$res['template'] = 'storeaccount_menu';
return $res;
}
/** member */
public function order($ordernum = '', $action = '', $subaction = '') {
$res = $this->DefaultResult(__METHOD__);
if ($ordernum == '') {
$data = hook_execute('order.list', [], $this->user_id, 365);
foreach($data as &$order) {
$days = intval((time() - $order['dt']) / 86400);
$unshipped = count($order['tracking'] ?? []) > 0 ? 0 : 1;
//** TO DO: canceled orders cannot be edited - so make sure those are 'shipped' here
// $order['cart'][0]['flag_unshipped'] = $unshipped;
// $order['cart'][0]['flag_shipvalid'] = !$unshipped && ($days < 180) ? 1 : 0;
$order['flag_unshipped'] = $unshipped;
$order['flag_shipvalid'] = !$unshipped && ($days < 180) ? 1 : 0;
// $order['days'] = $days;
}
$res['template'] = 'storeaccount_order';
$res['order'] = $data;
return $res;
}
// load order
$model_order = $this->LoadModel('order_model', 'store');
$model_tracking = $this->LoadModel('tracking_model', 'store');
$model_order->OrderNumber($ordernum);
$model_tracking->OrderId($model_order->OrderId());
// perform appropriate action
switch($action) {
case 'track':
// load trackings for order
// display
$res['template'] = 'storeaccount_tracking';
$res['tracking'] = $model_tracking->AsHandlebars_full($subaction);
break;
case 'edit':
$res['refresh-page'] = 1;
break;
case 'cancel':
if ($this->isPost) {
$auth = $this->post('auth', '');
} else {
$auth = $this->param('auth', '');
}
$order_id = hook_execute('nonce.verify', FALSE, 'ordernum', FALSE, $auth);
if ($order_id === FALSE) {
return [
'result' => 5,
'message' => 'You are not permitted to access this function',
];
} elseif ($order_id != $model_order->OrderId()) {
return [
'result' => 7,
'message' => 'Not today',
];
}
$ordernum = $model_order->OrderNumber();
$key = 'order:' . $model_order->OrderId();
if ($this->isPost) {
$param = [
'key' => $key,
'reason' => $this->post('reason', ''),
'detail' => trim($this->post('detail', '')),
];
// make sure a reason is selected
if ($param['reason'] == '') {
return [
'result' => 73112,
'message' => 'Please select a Cancellation Reason from the list',
];
}
// save cancellation record
$this->model->CancelKey($param['key'])
->CancelReason($param['reason'])
->CancelDetail($param['detail'])
->Update();
// change order status
$model_order->CancelRequest(1)
->EditDate(time())
->Update();
// go to a status page
$this->Redirect('/account/order');
exit;
}
$this->model->CancelKey($key);
// display popup - cancellation reason
$res['popup'] = [
'template' => 'storeaccount_cancel',
'modal' => true,
'width' => 500,
'title' => 'Request Cancellation',
'ordernum' => $ordernum,
'reason' => $this->model->CancelReason(),
'detail' => $this->model->CancelDetail(),
'list_reason' => [
['key' => '' , 'value' => '(select a reason)'],
['key' => 'wrong' , 'value' => 'Wrong product ordered'],
['key' => 'late' , 'value' => 'Item would not arrive in time'],
['key' => 'cheap' , 'value' => 'Found a cheaper product elsewhere'],
['key' => 'other' , 'value' => 'Other'],
],
'auth' => hook_execute('nonce.create', FALSE, 'ordernum', $model_order->OrderId(), 1800),
'actions' => [
[
'action' => 'update',
'text' => 'Send Request',
]
],
];
break;
case '':
$res['template'] = 'storeaccount_detail';
$data = $model_order->AsHandlebars(TRUE);
$res = array_merge($res, $data);
$res['address'] = $model_order->asJson_Delivery();
$res = hook_execute('cart.display', $res, 'fulfill'); // add images
if ($model_order->getPhysicalFlag()) {
$res['tracking'] = $model_tracking->AsHandlebars_list(); // add tracking
}
break;
default:
$auth = $this->isPost ? $this->post('auth', '') : $this->param('auth', '');
$line_id = hook_execute('nonce.verify', FALSE, 'line.id', FALSE, $auth);
if ($line_id !== FALSE) { // variation, customize,
$res = hook_execute('store.account.' . $action, $res, $line_id, $this->isPost);
$display = $res['refresh-page'] ?? 0;
if ($display) $model_order->Load(); // reload the new settings
}
break;
}
$display = $res['refresh-page'] ?? 0;
if ($display) {
// allow order to be edited or canceled
// call other modules to display appropriate edit options for the products
$res['template'] = 'storeaccount_edit';
$data = $model_order->AsHandlebars(TRUE);
$res = array_merge($res, $data);
$res['address'] = $model_order->asJson_Delivery();
$res['cart'] = $model_order->AsHandleBars_Items();
$res['page_title'] = 'Edit Order - ' . $res['ordernum'];
$res['auth'] = hook_execute('nonce.create', FALSE, 'ordernum', $model_order->OrderId(), 1800);
$res = hook_execute('cart.display', $res, 'edit'); // add images
unset($res['refresh-page']);
}
return $res;
}
/** member */
public function address($guid = '') {
$res = $this->DefaultResult(__METHOD__);
if ($guid == '') {
$data = hook_execute('account.address.list', [], $this->user_id);
$res['template'] = 'storeaccount_address';
$res = array_merge($res, $data);
}
return $res;
}
/** member */
public function store_action_POST($action = '') {
switch($action) {
case 'set-default':
$default = trim($this->post('guid', ''));
$message = [
'result' => 57112,
'message' => 'cannot set Default Address',
];
if ($default != '') {
$message = hook_execute('account.address.set-default', $message, $this->user_id, $default);
}
return $message;
default:
return [
'result' => 57110,
'message' => 'Unknown action',
];
}
}
/** staff */
public function autocomplete_account() {
$term = $this->param('term', '');
$data = $this->model->generateAutocomplete($term);
header('Content-type: application/json');
die(json_encode($data, JSON_UNESCAPED_SLASHES));
}
}