-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
334 lines (319 loc) · 12.9 KB
/
admin.php
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php
class plugins_transport_admin extends plugins_transport_db
{
public $edit, $action, $tabs, $search, $plugin, $controller;
protected $message, $template, $header, $data, $modelLanguage, $collectionLanguage, $order, $upload, $config, $modelPlugins, $routingUrl, $makeFiles, $finder, $plugins, $progress;
public $id_tr, $content, $pages, $iso, $ajax, $tableaction, $tableform, $offset, $transData, $importData;
public $tableconfig = [
'all' => [
'id_tr',
'name_tr' => ['title' => 'name'],
'postcode_tr' => ['title' => 'name'],
'country_tr' => ['title' => 'name','type' => 'enum', 'enum' => '', 'input' => null, 'class' => ''],
'price_tr' => ['type' => 'price','input' => null],
'date_register'
]
];
/**
* frontend_controller_home constructor.
*/
public function __construct($t = null){
$this->template = $t ? $t : new backend_model_template;
$this->message = new component_core_message($this->template);
$this->header = new http_header();
$this->data = new backend_model_data($this);
$formClean = new form_inputEscape();
$this->modelLanguage = new backend_model_language($this->template);
$this->collectionLanguage = new component_collections_language();
$this->modelPlugins = new backend_model_plugins();
$this->routingUrl = new component_routing_url();
$this->finder = new file_finder();
// --- GET
if(http_request::isGet('controller')) $this->controller = $formClean->simpleClean($_GET['controller']);
if (http_request::isGet('edit')) $this->edit = $formClean->numeric($_GET['edit']);
if (http_request::isGet('action')) $this->action = $formClean->simpleClean($_GET['action']);
elseif (http_request::isPost('action')) $this->action = $formClean->simpleClean($_POST['action']);
if (http_request::isGet('tabs')) $this->tabs = $formClean->simpleClean($_GET['tabs']);
if (http_request::isGet('ajax')) $this->ajax = $formClean->simpleClean($_GET['ajax']);
if (http_request::isGet('offset')) $this->offset = intval($formClean->simpleClean($_GET['offset']));
if (http_request::isGet('tableaction')) {
$this->tableaction = $formClean->simpleClean($_GET['tableaction']);
$this->tableform = new backend_controller_tableform($this,$this->template);
}
// --- Search
if (http_request::isGet('search')) {
$this->search = $formClean->arrayClean($_GET['search']);
$this->search = array_filter($this->search, function ($value) { return $value !== ''; });
}
// --- ADD or EDIT
if (http_request::isGet('id')) $this->id_tr = $formClean->simpleClean($_GET['id']);
elseif (http_request::isPost('id')) $this->id_tr = $formClean->simpleClean($_POST['id']);
if (http_request::isPost('content')) {
$array = $_POST['content'];
foreach($array as $key => $arr) {
foreach($arr as $k => $v) {
$array[$key][$k] = ($k == 'content_lead') ? $formClean->cleanQuote($v) : $formClean->simpleClean($v);
}
}
$this->content = $array;
}
if (http_request::isPost('transData')) $this->transData = $formClean->arrayClean($_POST['transData']);
// --- Recursive Actions
if (http_request::isGet('transport')) $this->pages = $formClean->arrayClean($_GET['transport']);
# ORDER PAGE
if (http_request::isPost('transport')) $this->order = $formClean->arrayClean($_POST['transport']);
if (http_request::isGet('plugin')) $this->plugin = $formClean->simpleClean($_GET['plugin']);
# JSON LINK (TinyMCE)
//if (http_request::isGet('iso')) $this->iso = $formClean->simpleClean($_GET['iso']);
}
/**
* Assign data to the defined variable or return the data
* @param string $type
* @param string|int|null $id
* @param string $context
* @param boolean $assign
* @param boolean $pagination
* @return mixed
*/
private function getItems($type, $id = null, $context = null, $assign = true, $pagination = false) {
return $this->data->getItems($type, $id, $context, $assign, $pagination);
}
/**
* Method to override the name of the plugin in the admin menu
* @return string
*/
public function getExtensionName()
{
return $this->template->getConfigVars('transport_plugin');
}
/**
* @param $ajax
* @return mixed
* @throws Exception
*/
public function tableSearch($ajax = false)
{
$results = $this->getItems('pages', NULL, 'all',false,true);
$params = array();
if($ajax) {
$params['section'] = 'pages';
$params['idcolumn'] = 'id_tr';
$params['activation'] = false;
$params['sortable'] = true;
$params['checkbox'] = true;
$params['edit'] = true;
$params['dlt'] = true;
$params['readonly'] = array();
$params['cClass'] = 'plugins_transport_admin';
}
$this->data->getScheme(array('mc_transport'),array('id_tr','name_tr','postcode_tr','price_tr','date_register'),$this->tableconfig['all']);
return array(
'data' => $results,
'var' => 'pages',
'tpl' => 'index.tpl',
'params' => $params
);
}
/**
* Update data
* @param $data
* @throws Exception
*/
private function add($data)
{
switch ($data['type']) {
case 'page':
parent::insert(
array(
'context' => $data['context'],
'type' => $data['type']
),
$data['data']
);
break;
}
}
/**
* Mise a jour des données
* @param $data
* @throws Exception
*/
private function upd($data)
{
switch ($data['type']) {
/*case 'order':
$p = $this->order;
for ($i = 0; $i < count($p); $i++) {
parent::update(
array(
'type'=>$data['type']
),array(
'id_cs' => $p[$i],
'order_cs' => $i + (isset($this->offset) ? ($this->offset + 1) : 0)
)
);
}
break;*/
case 'page':
parent::update(
array(
'context' => $data['context'],
'type' => $data['type']
),
$data['data']
);
break;
}
}
/**
* Insertion de données
* @param $data
* @throws Exception
*/
private function del($data)
{
switch($data['type']){
case 'delPages':
parent::delete(
array(
'type' => $data['type']
),
$data['data']
);
$this->message->json_post_response(true,'delete',$data['data']);
break;
}
}
private function setItemData($row)
{
$data = array();
if ($row != null) {
$data['lastname'] = $row['lastname_ct'];
$data['firstname'] = $row['firstname_ct'];
$data['street'] = $row['street_ct'];
$data['postcode'] = $row['postcode_ct'];
$data['city'] = $row['city_ct'];
$data['country'] = $row['country_tr'];
$data['name'] = $row['name_tr'];
$data['price'] = $row['price_tr'];
$data['type'] = $row['type_ct'];
}
return $data;
}
/**
* @param $idcart
* @return mixed
*/
public function getTransport($idcart){
$data = $this->getItems('cartOrder', array('id'=>$idcart), 'one',false,false);
return $this->setItemData($data);
}
/**
* @return string
*/
public function extendCartpayForm() : string{
$pluginsDir = component_core_system::basePath().'plugins'.DIRECTORY_SEPARATOR.'transport'.DIRECTORY_SEPARATOR.'skin'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR;
$dir = $pluginsDir.'form/transport.tpl';
return $dir;
}
/**
* @return array
*/
public function extendCartpayQuery() : array{
return [
'select' => [
'mct.type_ct',
'mct.lastname_ct',
'mct.firstname_ct',
'mct.street_ct',
'mct.city_ct',
'mct.postcode_ct',
'mct.event_ct',
'mct.delivery_date_ct',
'mct.timeslot_ct',
'mt.country_tr',
'mt.price_tr'
],
'join' => [
['type' => 'LEFT JOIN',
'table' => 'mc_cartpay_transport',
'as' => 'mct',
'on' => [
'table' => 'cart',
'key' => 'id_cart'
]
],
['type' => 'LEFT JOIN',
'table' => 'mc_transport',
'as' => 'mt',
'on' => [
'table' => 'mct',
'key' => 'id_tr'
]
]
]/*,
'where' => [
[
'type' => 'AND',
'condition' => 'mavc.id_lang = mcpc.id_lang'
]
]*/
];
}
/**
* @throws Exception
*/
public function run(){
if(isset($this->tableaction)) {
$this->tableform->run();
}
elseif(isset($this->action)) {
switch ($this->action) {
case 'add':
if(isset($this->transData)){
$newdata = array();
$newdata['name_tr'] = (!empty($this->transData['name_tr'])) ? $this->transData['name_tr'] : NULL;
$newdata['postcode_tr'] = (!empty($this->transData['postcode_tr'])) ? $this->transData['postcode_tr'] : NULL;
$newdata['price_tr'] = (!empty($this->transData['price_tr'])) ? number_format(str_replace(",", ".", $this->transData['price_tr']), 2, '.', '') : NULL;
$newdata['country_tr'] = (!empty($this->transData['country_tr'])) ? $this->transData['country_tr'] : NULL;
// Add data
$this->add(array(
'type' => 'page',
'data' => $newdata
));
$this->message->json_post_response(true, 'add_redirect');
}else{
$country = new component_collections_country();
$this->template->assign('countries',$country->getAllowedCountries());
$this->template->display('add.tpl');
}
break;
case 'edit':
if(isset($this->transData)){
$newdata = array();
$newdata['id_tr'] = $this->id_tr;
$newdata['name_tr'] = (!empty($this->transData['name_tr'])) ? $this->transData['name_tr'] : NULL;
$newdata['postcode_tr'] = (!empty($this->transData['postcode_tr'])) ? $this->transData['postcode_tr'] : NULL;
$newdata['price_tr'] = (!empty($this->transData['price_tr'])) ? number_format(str_replace(",", ".", $this->transData['price_tr']), 2, '.', '') : NULL;
$newdata['country_tr'] = (!empty($this->transData['country_tr'])) ? $this->transData['country_tr'] : NULL;
// Add data
$this->upd(array(
'type' => 'page',
'data' => $newdata
));
$this->message->json_post_response(true, 'update', $this->transData);
}else{
$country = new component_collections_country();
$this->template->assign('countries',$country->getAllowedCountries());
$this->getItems('page',array('id_tr'=>$this->edit),'one',true,true);
$this->template->display('edit.tpl');
}
break;
}
}else{
$this->getItems('pages',NULL,'all',true,true);
$this->data->getScheme(array('mc_transport'),array('id_tr','name_tr','postcode_tr','price_tr','date_register'),$this->tableconfig['all']);
$this->template->display('index.tpl');
}
}
}