Issues (2407)

administration/controller/design/custommenu.php (16 issues)

1
<?php
2
3
/* 	Divine CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Divine CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
class ControllerDesignCustomMenu extends \Divine\Engine\Core\Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    private $error = array();
26
27
    public function index()
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
29
        $this->load->language('design/custommenu');
30
        $this->document->setTitle($this->language->get('heading_title'));
31
32
        $this->load->model('setting/setting');
33
34
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
35
            $this->model_setting_setting->editSetting('configcustommenu', $this->request->post);
36
37
            $this->session->data['success'] = $this->language->get('text_success');
38
39
            $this->response->redirect($this->url->link('design/custommenu', 'token=' . $this->session->data['token'], true));
40
        }
41
42
        $data['heading_title'] = $this->language->get('heading_title');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
43
        $data['text_list'] = $this->language->get('text_list');
44
45
        $data['text_success'] = $this->language->get('text_success');
46
        $data['text_new_custommenu_item'] = $this->language->get('text_new_custommenu_item');
47
        $data['text_category'] = $this->language->get('text_category');
48
        $data['text_product'] = $this->language->get('text_product');
49
        $data['text_manufacturer'] = $this->language->get('text_manufacturer');
50
        $data['text_information'] = $this->language->get('text_information');
51
        $data['text_custom'] = $this->language->get('text_custom');
52
        $data['text_confirm'] = $this->language->get('text_confirm');
53
54
        $data['text_custommenu_title'] = $this->language->get('text_custommenu_title');
55
        $data['text_custommenu_description'] = $this->language->get('text_custommenu_description');
56
        $data['text_sub_item'] = $this->language->get('text_sub_item');
57
        $data['text_custommenu_name'] = $this->language->get('text_custommenu_name');
58
        $data['text_custommenu_link'] = $this->language->get('text_custommenu_link');
59
60
        $data['column_sort_order'] = $this->language->get('column_sort_order');
61
        $data['column_action'] = $this->language->get('column_action');
62
63
        $data['column_custom_name'] = $this->language->get('column_custom_name');
64
        $data['column_custom_link'] = $this->language->get('column_custom_link');
65
        $data['column_category_name'] = $this->language->get('column_category_name');
66
        $data['column_product_name'] = $this->language->get('column_product_name');
67
        $data['column_manufacturer_name'] = $this->language->get('column_manufacturer_name');
68
        $data['column_information_name'] = $this->language->get('column_information_name');
69
70
        $data['entry_name'] = $this->language->get('entry_name');
71
        $data['entry_link'] = $this->language->get('entry_link');
72
        $data['entry_columns'] = $this->language->get('entry_columns');
73
        $data['entry_sort_order'] = $this->language->get('entry_sort_order');
74
75
        $data['button_custom'] = $this->language->get('button_custom');
76
        $data['button_categories'] = $this->language->get('button_categories');
77
        $data['button_products'] = $this->language->get('button_products');
78
        $data['button_manufacturers'] = $this->language->get('button_manufacturers');
79
        $data['button_informations'] = $this->language->get('button_informations');
80
81
        $data['button_disable'] = $this->language->get('button_disable');
82
        $data['button_save'] = $this->language->get('button_save');
83
        $data['button_delete'] = $this->language->get('button_delete');
84
85
        $data['error_permission'] = $this->language->get('error_permission');
86
        $data['error_name'] = $this->language->get('error_name');
87
        $data['error_link'] = $this->language->get('error_link');
88
89
        $data['text_custommenu_enable'] = $this->language->get('text_custommenu_enable');
90
        $data['text_yes'] = $this->language->get('text_yes');
91
        $data['text_no'] = $this->language->get('text_no');
92
        $data['text_default'] = $this->language->get('text_default');
93
94
        $this->load->model('design/custommenu');
95
96
        $this->document->addStyle('/public_html/assets/css/administration/general/custommenu.css');
97
        $this->document->addScript('/public_html/assets/js/administration/general/custommenu.js');
98
99
        $data['changecustommenuPosition'] = $this->url->link('design/custommenu/changecustommenuPosition', 'token=' . $this->session->data['token'], true);
100
101
        $data['deletecustommenu'] = $this->url->link('design/custommenu/deletecustommenu', 'token=' . $this->session->data['token'], true);
102
        $data['deleteChildcustommenu'] = $this->url->link('design/custommenu/deleteChildcustommenu', 'token=' . $this->session->data['token'], true);
103
104
        $data['enablecustommenu'] = $this->url->link('design/custommenu/enablecustommenu', 'token=' . $this->session->data['token'], true);
105
        $data['enableChildcustommenu'] = $this->url->link('design/custommenu/enableChildcustommenu', 'token=' . $this->session->data['token'], true);
106
107
        $data['disablecustommenu'] = $this->url->link('design/custommenu/disablecustommenu', 'token=' . $this->session->data['token'], true);
108
        $data['disableChildcustommenu'] = $this->url->link('design/custommenu/disableChildcustommenu', 'token=' . $this->session->data['token'], true);
109
110
        $data['refresch'] = $this->url->link('design/custommenu', 'token=' . $this->session->data['token'], true);
111
        $data['add'] = $this->url->link('design/custommenu/add', 'token=' . $this->session->data['token'], true);
112
        $data['save'] = $this->url->link('design/custommenu/save', 'token=' . $this->session->data['token'], true);
113
114
        $data['custommenu_child'] = array();
115
116
        $custommenus = $this->model_design_custommenu->getcustommenus();
117
        $custommenu_child = $this->model_design_custommenu->getChildcustommenus();
118
119
        $rent_custommenu = array();
120
121
        $this->load->model('catalog/product');
122
        $this->load->model('localisation/language');
123
124
        $data['languages'] = $this->model_localisation_language->getLanguages();
125
126
        foreach ($custommenus as $id => $custommenu) {
127
            $rent_custommenu[] = array(
128
                'name'          => $custommenu['name'] ,
129
                'custommenu_id'       => $custommenu['custommenu_id'],
130
                'custommenu_type'     => $custommenu['custommenu_type'],
131
                'status'        => $custommenu['status'],
132
                'isSubcustommenu'     => ''
133
            );
134
135
            foreach ($custommenu_child as $child_id => $child_custommenu) {
136
                if (($custommenu['custommenu_id'] != $child_custommenu['custommenu_id']) or !is_numeric($child_id)) {
137
                    continue;
138
                }
139
140
                $rent_custommenu[] = array(
141
                    'name'          => $child_custommenu['name'],
142
                    'custommenu_id'       => $child_custommenu['custommenu_child_id'],
143
                    'custommenu_type'     => $child_custommenu['custommenu_type'],
144
                    'status'        => $child_custommenu['status'],
145
                    'isSubcustommenu'     => $custommenu['custommenu_id']
146
                );
147
            }
148
        }
149
150
        $data['custommenu_desc'] = $this->model_design_custommenu->getcustommenuDesc();
151
        $data['custommenu_child_desc'] = $this->model_design_custommenu->getcustommenuChildDesc();
152
153
        $data['custommenus'] = $rent_custommenu;
154
155
        if (isset($this->error['warning'])) {
156
            $data['error_warning'] = $this->error['warning'];
157
        } else {
158
            $data['error_warning'] = '';
159
        }
160
161
        if (isset($this->session->data['success'])) {
162
            $data['success'] = $this->session->data['success'];
163
164
            unset($this->session->data['success']);
165
        } else {
166
            $data['success'] = '';
167
        }
168
169
        $data['token'] = $this->session->data['token'];
170
171
        $data['action'] = $this->url->link('design/custommenu', 'token=' . $this->session->data['token'], true);
172
173
        if (isset($this->request->post['configcustommenu_custommenu'])) {
174
            $data['configcustommenu_custommenu'] = $this->request->post['configcustommenu_custommenu'];
175
        } else {
176
            $data['configcustommenu_custommenu'] = $this->config->get('configcustommenu_custommenu');
177
        }
178
179
        $data['header'] = $this->load->controller('common/header');
180
        $data['column'] = $this->load->controller('common/column_left');
181
        $data['footer'] = $this->load->controller('common/footer');
182
183
        $this->response->setOutput($this->load->view('design/custommenu', $data));
184
    }
185
186
    protected function validateForm()
187
    {
188
        if (!$this->user->hasPermission('modify', 'design/custommenu')) {
189
            $this->error['warning'] = $this->language->get('error_permission');
190
        }
191
192
        return !$this->error;
193
    }
194
195
    protected function validateDelete()
196
    {
197
        if (!$this->user->hasPermission('modify', 'design/custommenu')) {
198
            $this->error['warning'] = $this->language->get('error_permission');
199
        }
200
201
        return !$this->error;
202
    }
203
204
    public function add()
205
    {
206
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
207
            $this->load->model('design/custommenu');
208
            $this->load->model('localisation/language');
209
210
            $languages = $this->model_localisation_language->getLanguages();
211
212
            $custommenu = $this->model_design_custommenu->add($this->request->post, $languages);
213
214
            if (!empty($custommenu)) {
215
                echo $this->addHtml($custommenu, $languages);
216
            }
217
        }
218
    }
219
220
    protected function addHtml($custommenu, $languages)
221
    {
222
        $this->load->language('design/custommenu');
223
224
        $count = '0';
225
226
        $html  = '<li id="custommenu-item-' . $custommenu['custommenu_id'] . '" class="custommenu-item custommenu-item-depth-0 custommenu-item-page custommenu-item-edit-inactive pending">';
227
        $html .= '	<dl class="custommenu-item-bar">';
228
        $html .= '		<dt class="custommenu-item-handle">';
229
        $html .= '			<span class="item-title"><span class="custommenu-item-title">' . $custommenu['name'] .'</span> <span class="is-subcustommenu" style="display: none;">' . $this->language->get('text_sub_item') . '</span></span>';
230
        $html .= '          <span class="item-controls">';
231
        $html .= '			<span class="item-type">' . ucwords($custommenu['custommenu_type']) . '</span>';
232
        $html .= '				<a class="item-edit opencustommenuItem ' . $custommenu['custommenu_type'] . '" id="edit-' . $custommenu['custommenu_id'] . '" title="">';
233
        $html .= '                <i class="fa fa-caret-down"></i>';
234
        $html .= '              </a>';
235
        $html .= '			</span>';
236
        $html .= '      </dt>';
237
        $html .= ' </dl>';
238
239
        $custommenu_desc = $this->model_design_custommenu->getcustommenuDesc();
240
241
        $html .= '<div class="custommenu-item-settings" id="custommenu-item-settings-edit-' . $custommenu['custommenu_id'] . '">';
242
        $html .= $this->language->get('text_custommenu_name') . '</br>';
243
244
        foreach ($languages as $language) {
245
            $html .= '<div class="input-group"><span class="input-group-addon"><img src="language/' . $language["code"] . '/' . $language["code"] . '.png' . '" title="' . $language["name"] . '"/></span>';
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal code does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal name does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
246
            $html .= '   <input type="text" name="custommenu_name[' . $language['language_id'] . ']" value="' . $custommenu_desc[$custommenu['custommenu_id']][$language['language_id']]['name']. '" placeholder="' . $this->language->get('text_custommenu_name') . '" class="form-control" />';
247
            $html .= '</div>';
248
        }
249
        $html .= '<br>';
250
251
        if ($custommenu['custommenu_type'] == 'custom') {
252
            $html .= $this->language->get('text_custommenu_link') . '<br>';
253
254
            foreach ($languages as $language) {
255
                $html .= '<div class="input-group"><span class="input-group-addon"><img src="language/' . $language["code"] . '/' . $language['code'] . '.png' . '" title="' . $language['name'] . '" /></span>';
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal code does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
256
                $html .= '   <input type="text" name="custommenu_link[' . $language['language_id'] . ']" value="' . $custommenu_desc[$custommenu['custommenu_id']][$language['language_id']]['link'] . '" placeholder="' . $this->language->get('text_custommenu_link') . '" class="form-control" />';
257
                $html .= '</div>';
258
            }
259
260
            $html .= '<br>';
261
        }
262
263
        $html .= $this->language->get('entry_columns');
264
        $html .= '<div class="input-group">';
265
        $html .= '  <input type="text" name="custommenu_columns" value="1" placeholder="" id="input-columns" class="form-control" />';
266
        $html .= '</div>';
267
        $html .= '<br>';
268
        $html .= '<div class="pull-right">';
269
        $html .= ' <a id="disablecustommenu-'. $count . '" onclick="statuscustommenu(\'disable\', \'' . $custommenu['custommenu_id'] . '\', \'custommenu-item-' . $custommenu['custommenu_id'] . '\', \'disablecustommenu-' . $count .'\')" data-type="iframe" style="top:2px!important;font-size:1.2em !important;" title="' . $this->language->get('button_disable') . '" class="btn btn-danger btn-xs btn-edit btn-group"><i class="fa fa-times-circle"></i></a>';
270
        $html .= ' <a onclick="savecustommenu(\'custommenu-item-settings-edit-' . $custommenu['custommenu_id'] . '\', \'custommenu-item-' . $custommenu['custommenu_id'] . '\')" data-type="iframe" style="top:2px!important;font-size:1.2em !important;" title="' . $this->language->get('button_save') . '" class="btn btn-success btn-xs btn-edit btn-group"><i class="fa fa-save"></i></a>';
271
        $html .= ' <button type="button" title="" style="top:2px!important;font-size:1.2em !important;" class="btn btn-danger btn-xs btn-edit btn-group btn-loading" onclick="confirm(\'Are you sure?\') ? deletecustommenu(\'' . $custommenu['custommenu_id'] . '\', \'custommenu-item-' . $custommenu['custommenu_id'] . '\') : false;" data-original-title="Delete"><i class="fa fa-trash-o"></i></button>';
272
        $html .= '</div>';
273
        $html .= '<br><br>';
274
275
        $html .= '<input class="custommenu-item-data-typecustommenu" type="hidden" name="custommenu-item-typecustommenu[Maincustommenu-' . $custommenu['custommenu_id'].']" value="Maincustommenu">';
276
        $html .= '<input class="custommenu-item-data-db-id" type="hidden" name="custommenu-item-db-id[Maincustommenu-' . $custommenu['custommenu_id'] . ']" value="' . $custommenu['custommenu_id'] . '">';
277
        $html .= '<input class="custommenu-item-data-parent-id" type="hidden" name="custommenu-item-parent-id[Maincustommenu-' . $custommenu['custommenu_id'] .']" value="0">';
278
        $html .= '<input class="custommenu-item-data-position" type="hidden" name="custommenu-item-position[Maincustommenu-' . $custommenu['custommenu_id'] . ']" value="' . $custommenu['custommenu_id'] . '">';
279
        $html .= '<input class="custommenu-item-data-type" type="hidden" name="custommenu-item-type[Maincustommenu-' . $custommenu['custommenu_id'] . ']" value="post_type">';
280
281
        $html .= '</div>';
282
        $html .= '<ul class="custommenu-item-transport"></ul>';
283
        $html .= '</li>';
284
285
        return $html;
286
    }
287
288
    public function save()
289
    {
290
        $this->load->language('design/custommenu');
291
        $this->document->setTitle($this->language->get('heading_title'));
292
        $this->load->model('design/custommenu');
293
294
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
295
            if ($this->request->get['type'] == 'child') {
296
                $this->model_design_custommenu->saveChild($this->request->post);
297
            } else {
298
                $this->model_design_custommenu->save($this->request->post);
299
            }
300
301
            $this->session->data['success'] = $this->language->get('text_success');
302
        }
303
    }
304
305
    public function deletecustommenu()
306
    {
307
        $this->load->language('design/custommenu');
308
        $this->document->setTitle($this->language->get('heading_title'));
309
        $this->load->model('design/custommenu');
310
311
        if (isset($this->request->post['custommenu_id']) && $this->validateDelete()) {
312
            $this->model_design_custommenu->deletecustommenu($this->request->post['custommenu_id']);
313
314
            $this->session->data['success'] = $this->language->get('text_success');
315
316
            $json['success'] = $this->language->get('text_success');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.
Loading history...
317
            $json['error']   = $this->language->get('text_error');
318
        } else {
319
            $this->session->data['error'] = $this->language->get('text_error');
320
321
            $json['success'] = '';
322
            $json['error']   = $this->language->get('text_error');
323
        }
324
325
326
        $this->response->addHeader('Content-Type: application/json');
327
        $this->response->setOutput(json_encode($json));
328
    }
329
330
    public function deleteChildcustommenu()
331
    {
332
        $this->load->language('design/custommenu');
333
        $this->document->setTitle($this->language->get('heading_title'));
334
        $this->load->model('design/custommenu');
335
336
        if (isset($this->request->post['custommenu_id']) && $this->validateDelete()) {
337
            $this->model_design_custommenu->deleteChildcustommenu($this->request->post['custommenu_id']);
338
339
            $this->session->data['success'] = $this->language->get('text_success');
340
341
            $json['success'] = $this->language->get('text_success');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.
Loading history...
342
            $json['error']   = '';
343
        } else {
344
            $this->session->data['error'] = $this->language->get('text_error');
345
346
            $json['success'] = '';
347
            $json['error']   = $this->language->get('text_error');
348
        }
349
350
351
        $this->response->addHeader('Content-Type: application/json');
352
        $this->response->setOutput(json_encode($json));
353
    }
354
355
    public function enablecustommenu()
356
    {
357
        $this->load->language('design/custommenu');
358
        $this->document->setTitle($this->language->get('heading_title'));
359
        $this->load->model('design/custommenu');
360
361
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
362
            $this->model_design_custommenu->enablecustommenu($this->request->post['custommenu_id']);
363
            $this->session->data['success'] = $this->language->get('text_success');
364
        }
365
366
        $id = explode('-', $this->request->post['id']);
367
368
        $button = "<a id=\"disablecustommenu-" . $id[1] . "\" onclick=\"statuscustommenu('disable', '" . $this->request->post['custommenu_id'] . "', 'custommenu-item-" .  $this->request->post['custommenu_id'] . "', 'disablecustommenu-" . $id[1] . "')\" data-type=\"iframe\" data-toggle=\"tooltip\" style=\"top:2px!important;font-size:1.2em !important;\" title=\"\" class=\"btn btn-danger btn-xs btn-edit btn-group\"><i class=\"fa fa-times-circle\"></i></a>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <a id=\"disablecustommenu- does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
369
370
        echo $button;
371
        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
372
    }
373
374
    public function disablecustommenu()
375
    {
376
        $this->load->language('design/custommenu');
377
        $this->document->setTitle($this->language->get('heading_title'));
378
        $this->load->model('design/custommenu');
379
380
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
381
            $this->model_design_custommenu->disablecustommenu($this->request->post['custommenu_id']);
382
            $this->session->data['success'] = $this->language->get('text_success');
383
        }
384
385
        $id = explode('-', $this->request->post['id']);
386
387
        $button = "<a id=\"enablecustommenu-" . $id[1] . "\" onclick=\"statuscustommenu('enable', '" . $this->request->post['custommenu_id'] . "', 'custommenu-item-" .  $this->request->post['custommenu_id'] . "', 'enablecustommenu-" . $id[1] . "')\" data-type=\"iframe\" data-toggle=\"tooltip\" style=\"top:2px!important;font-size:1.2em !important;\" title=\"\" class=\"btn btn-success btn-xs btn-edit btn-group\"><i class=\"fa fa-check-circle\"></i></a>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <a id=\"enablecustommenu- does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
388
389
        echo $button;
390
        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
391
    }
392
393
    public function enableChildcustommenu()
394
    {
395
        $this->load->language('design/custommenu');
396
        $this->document->setTitle($this->language->get('heading_title'));
397
        $this->load->model('design/custommenu');
398
399
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
400
            $this->model_design_custommenu->enableChildcustommenu($this->request->post['custommenu_id']);
401
            $this->session->data['success'] = $this->language->get('text_success');
402
        }
403
404
        $id = explode('-', $this->request->post['id']);
405
406
        $button = "<a id=\"disablecustommenu-" . $id[1] . "\" onclick=\"statuscustommenu('disable', '" . $this->request->post['custommenu_id'] . "', 'custommenu-child-item-" .  $this->request->post['custommenu_id'] . "', 'disablecustommenu-" . $id[1] . "')\" data-type=\"iframe\" data-toggle=\"tooltip\" style=\"top:2px!important;font-size:1.2em !important;\" title=\"\" class=\"btn btn-danger btn-xs btn-edit btn-group\"><i class=\"fa fa-times-circle\"></i></a>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <a id=\"disablecustommenu- does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
407
408
        echo $button;
409
        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
410
    }
411
412
    public function disableChildcustommenu()
413
    {
414
        $this->load->language('design/custommenu');
415
        $this->document->setTitle($this->language->get('heading_title'));
416
        $this->load->model('design/custommenu');
417
418
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
419
            $this->model_design_custommenu->disableChildcustommenu($this->request->post['custommenu_id']);
420
            $this->session->data['success'] = $this->language->get('text_success');
421
        }
422
423
        $id = explode('-', $this->request->post['id']);
424
425
        $button = "<a id=\"enablecustommenu-" . $id[1] . "\" onclick=\"statuscustommenu('enable', '" . $this->request->post['custommenu_id'] . "', 'custommenu-child-item-" .  $this->request->post['custommenu_id'] . "', 'enablecustommenu-" . $id[1] . "')\" data-type=\"iframe\" data-toggle=\"tooltip\" style=\"top:2px!important;font-size:1.2em !important;\" title=\"\" class=\"btn btn-success btn-xs btn-edit btn-group\"><i class=\"fa fa-check-circle\"></i></a>";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal <a id=\"enablecustommenu- does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
426
427
        echo $button;
428
        exit();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
429
    }
430
431
    public function changecustommenuPosition()
432
    {
433
        $this->load->language('design/custommenu');
434
        $this->document->setTitle($this->language->get('heading_title'));
435
        $this->load->model('design/custommenu');
436
437
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
438
            $this->model_design_custommenu->changecustommenuPosition($this->request->post);
439
            $this->session->data['success'] = $this->language->get('text_success');
440
        }
441
    }
442
443
    public function autocomplete()
444
    {
445
        $json = array();
446
447
        #Category
448
        if (isset($this->request->get['filter_category_name'])) {
449
            $this->load->model('catalog/category');
450
451
            if (isset($this->request->get['filter_category_name'])) {
452
                $filter_name = $this->request->get['filter_category_name'];
453
            } else {
454
                $filter_name = '';
455
            }
456
457
            $filter_data = array(
458
                'filter_name' => $filter_name,
459
                'sort'        => 'name',
460
                'order'       => 'ASC',
461
                'start'       => 0,
462
                'limit'       => 5
463
            );
464
465
            $results = $this->model_catalog_category->getCategories($filter_data);
466
467
            foreach ($results as $result) {
468
                $result['index'] = $result['name'];
469
                if (strpos($result['name'], '&nbsp;&nbsp;&gt;&nbsp;&nbsp;')) {
470
                    $result['name'] = explode('&nbsp;&nbsp;&gt;&nbsp;&nbsp;', $result['name']);
471
                    $result['name'] = end($result['name']);
472
                }
473
474
                $json[] = array(
475
                    'category_id' => $result['category_id'],
476
                    'index'		  => $result['index'],
477
                    'name'		  => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
478
                );
479
            }
480
        }
481
482
        #Product
483
        if (isset($this->request->get['filter_product_name'])) {
484
            $this->load->model('catalog/product');
485
486
            if (isset($this->request->get['filter_product_name'])) {
487
                $filter_name = $this->request->get['filter_product_name'];
488
            } else {
489
                $filter_name = '';
490
            }
491
492
            $filter_data = array(
493
                'filter_name'  => $filter_name,
494
                'start'        => 0,
495
                'limit'        => 5
496
            );
497
498
            $results = $this->model_catalog_product->getProducts($filter_data);
499
500
            foreach ($results as $result) {
501
                $json[] = array(
502
                    'product_id' => $result['product_id'],
503
                    'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
504
                    'index'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
505
                );
506
            }
507
        }
508
509
        #Manufacturer
510
        if (isset($this->request->get['filter_manufacturer_name'])) {
511
            $this->load->model('catalog/manufacturer');
512
513
            if (isset($this->request->get['filter_manufacturer_name'])) {
514
                $filter_name = $this->request->get['filter_manufacturer_name'];
515
            } else {
516
                $filter_name = '';
517
            }
518
519
            $filter_data = array(
520
                'filter_name' => $filter_name,
521
                'start'       => 0,
522
                'limit'       => 5
523
            );
524
525
            $results = $this->model_catalog_manufacturer->getManufacturers($filter_data);
526
527
            foreach ($results as $result) {
528
                $json[] = array(
529
                    'manufacturer_id' => $result['manufacturer_id'],
530
                    'name'            => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
531
                    'index'           => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
532
                );
533
            }
534
        }
535
536
        #Information
537
        if (isset($this->request->get['filter_information_name'])) {
538
            $this->load->model('catalog/information');
539
540
            if (isset($this->request->get['filter_information_name'])) {
541
                $filter_name = $this->request->get['filter_information_name'];
542
            } else {
543
                $filter_name = '';
544
            }
545
546
            $filter_data = array(
547
                'filter_name' => $filter_name,
548
                'start'       => 0,
549
                'limit'       => 5
550
            );
551
552
            $results = $this->model_catalog_information->getInformations($filter_data);
553
554
            foreach ($results as $result) {
555
                $json[] = array(
556
                    'information_id' => $result['information_id'],
557
                    'name'            => strip_tags(html_entity_decode($result['title'], ENT_QUOTES, 'UTF-8')),
558
                    'index'           => strip_tags(html_entity_decode($result['title'], ENT_QUOTES, 'UTF-8'))
559
                );
560
            }
561
        }
562
563
        $sort_order = array();
564
565
        foreach ($json as $key => $value) {
566
            $sort_order[$key] = $value['name'];
567
        }
568
569
        array_multisort($sort_order, SORT_ASC, $json);
570
571
        $this->response->addHeader('Content-Type: application/json');
572
        $this->response->setOutput(json_encode($json));
573
    }
574
}
575