This repository was archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseven.class.php
More file actions
executable file
·172 lines (139 loc) · 5.48 KB
/
seven.class.php
File metadata and controls
executable file
·172 lines (139 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
class seven {
protected $_language_strings = [];
protected $_module_config = [];
protected $_name;
public function setNavItem(array &$navItems): void {
$navItems[$this->_name] = '?_g=plugin&name=' . $this->_name;
}
public function getName(): string {
return $this->_name;
}
public function getModuleConfig(): array {
return $this->_module_config;
}
public function __construct() {
$this->_name = get_class($this);
$this->_module_config = $GLOBALS['config']->get($this->_name);
$GLOBALS['language']->loadDefinitions($this->_name, CC_ROOT_DIR . '/modules/plugins/'
. $this->_name . '/language', 'module.definitions.xml');
$this->_language_strings = $GLOBALS['language']->getStrings($this->_name);
}
public function renderCustomerListScript(): void {
$title = $GLOBALS['language']->seven['sms_send'];
echo <<<HTML
<script>
document.addEventListener('DOMContentLoaded', () => {
Array.from(document.querySelectorAll(`#customer-list > table > tbody tr`)).forEach(row => {
const url = new URL(row.querySelector(':nth-child(4) > a').getAttribute('href'))
const customerId = url.searchParams.get('customer_id')
row.querySelector(':nth-child(8)').insertAdjacentHTML('beforeend', `<a
href='?_g=plugin&name=$this->_name&customer_id=\${customerId}'
title='$title'>
<i class='fa fa-envelope'</i>
</a>`)
})
})
</script>
HTML;
}
protected function getDefaultAddress(int $id, bool $removeEmpty): array {
$address = [];
if ($id > 0) {
$address = $GLOBALS['db']
->select('CubeCart_addressbook', [
'company_name',
'country',
'description',
'first_name',
'last_name',
'line1',
'line2',
'postcode',
'state',
'title',
'town',
], [
'customer_id' => $id,
'default' => 1,
], false, 1);
if (is_array($address)) {
$address = reset($address);
if ($removeEmpty) {
foreach ($address as $k => $v) {
if (empty($v)) {
unset($address[$k]);
continue;
}
switch ($k) {
case 'country':
$address[$k] = getCountryFormat($v);
break;
case 'state':
$address[$k] = getStateFormat($v);
break;
}
}
}
}
}
return $address;
}
public function getCustomer(int $id, bool $removeEmpty = true): array {
$customer = [];
if ($id > 0) {
$customer = $GLOBALS['db']
->select('CubeCart_customer', [
'email',
'first_name',
'ip_address',
'last_name',
'mobile',
'notes',
'order_count',
'phone',
'title',
], ['customer_id' => $id], false, 1);
if (is_array($customer)) {
$customer = reset($customer);
if ($removeEmpty)
foreach ($customer as $k => $v)
if (empty($v)) unset($customer[$k]);
foreach ($this->getDefaultAddress($id, $removeEmpty) as $k => $v)
$customer['default_address_' . $k] = $v;
}
}
return $customer;
}
protected function callAPI(string $endpoint, array $params, string $apiKey = null): stdClass {
if (!$apiKey) $apiKey = $this->_module_config['token'];
$ch = curl_init('https://gateway.seven.io/api/' . $endpoint);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json',
'Content-Type: application/json',
'X-Api-Key: ' . $apiKey,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
public function display() {
if (isset($_POST['sms'])) {
$params = $_POST;
unset($params['sms'], $params['sms'], $params['token']);
$result = $this->callAPI('sms', $params);
$GLOBALS['gui']->setNotify(json_encode($result, JSON_PRETTY_PRINT));
}
$GLOBALS['gui']->addBreadcrumb($this->_name, '?_g=plugin&name=' . $this->_name);
$GLOBALS['gui']->changeTemplateDir('modules/plugins/' . $this->_name . '/skin/admin');
$GLOBALS['smarty']->assign('MODULE_LANG', $this->_language_strings);
$GLOBALS['main']->addTabControl('SMS', 'sms');
$GLOBALS['main']->addTabControl(
'Plugin Configuration', '', '?_g=plugins&type=plugins&module=' . $this->_name);
$html_out = $GLOBALS['smarty']->fetch('sms.tpl');
$GLOBALS['gui']->changeTemplateDir();
return $html_out;
}
}