oct_stickers_settings.php
10.3 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
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
<?php
/**
 * @copyright    OCTemplates
 * @support      https://octemplates.net/
 * @license      LICENSE.txt
 */
class ControllerOCTemplatesStickersOCTStickersSettings extends Controller {
	private $error = [];
	public function index() {
		$this->load->language('octemplates/stickers/oct_stickers_settings');
		$this->document->addStyle('view/javascript/octemplates/spectrum/spectrum.css');
		$this->document->addScript('view/javascript/octemplates/spectrum/spectrum.js');
		$this->document->addScript('view/javascript/octemplates/bootstrap-notify/bootstrap-notify.min.js');
		$this->document->addScript('view/javascript/octemplates/oct_main.js');
		$this->document->addStyle('view/stylesheet/oct_deals.css');
		$this->document->setTitle($this->language->get('heading_title'));
        $this->load->model('setting/setting');
        $this->load->model('localisation/language');
		$this->load->model('octemplates/widgets/oct_seogeneration');
		$this->load->model('tool/image');
		$data['language_id'] = $this->config->get('config_language_id');
		$oct_stickers_info = $this->model_setting_setting->getSetting('oct_stickers');
		if (!$oct_stickers_info) {
            $this->response->redirect($this->url->link('octemplates/stickers/oct_stickers_settings/install', 'user_token=' . $this->session->data['user_token'], true));
        }
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
	        if (!isset($this->request->post['oct_stickers_status'])) {
				$this->request->post['oct_stickers_status'] = 0;
	        }
			if (isset($this->request->post['oct_stickers_data']['customer']) && !empty($this->request->post['oct_stickers_data']['customer'])) {
				$customers = $this->request->post['oct_stickers_data']['customer'];
				unset($this->request->post['oct_stickers_data']['customer']);
				foreach ($customers as $customer) {
					$index = $this->model_octemplates_widgets_oct_seogeneration->octTranslit($customer['title'][(int)$data['language_id']]);
					if (is_file(DIR_IMAGE . $customer['image'])) {
						$thumb = $this->model_tool_image->resize($customer['image'], 100, 100);
					} else {
						$thumb = $this->model_tool_image->resize('no_image.png', 100, 100);
					}
					$customer += ['thumb'	=>	$thumb];
					$this->request->post['oct_stickers_data']['customer'][$index] = $customer;
				}
			}
            $this->model_setting_setting->editSetting('oct_stickers', $this->request->post);
			$this->generateCss($this->request->post);
            $this->session->data['success'] = $this->language->get('text_success');
            $this->response->redirect($this->url->link('octemplates/stickers/oct_stickers_settings', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));
        }
		$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
        $data['breadcrumbs'] = [];
        $data['breadcrumbs'][] = [
            'text' => $this->language->get('text_home'),
            'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
        ];
        $data['breadcrumbs'][] = [
            'text' => $this->language->get('heading_title'),
            'href' => $this->url->link('octemplates/stickers/oct_stickers_settings', 'user_token=' . $this->session->data['user_token'], true)
        ];
        if (isset($this->error['warning'])) {
            $data['error_warning'] = $this->error['warning'];
        } else {
            $data['error_warning'] = '';
        }
		if (isset($this->session->data['success'])) {
            $data['success'] = $this->session->data['success'];
            unset($this->session->data['success']);
        } else {
            $data['success'] = '';
        }
        $data['action'] = $this->url->link('octemplates/stickers/oct_stickers_settings', 'user_token=' . $this->session->data['user_token'], true);
        $data['cancel'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);
        $data['user_token'] = $this->session->data['user_token'];
		$data['languages'] = $this->model_localisation_language->getLanguages();
		if (isset($this->request->post['oct_stickers_status'])) {
			$data['oct_stickers_status'] = $this->request->post['oct_stickers_status'];
		} else {
			$data['oct_stickers_status'] = $this->config->get('oct_stickers_status');
		}
        if (isset($this->request->post['oct_stickers_data'])) {
			$data['oct_stickers_data'] = $this->request->post['oct_stickers_data'];
		} else {
			$data['oct_stickers_data'] = $this->config->get('oct_stickers_data');
			if (isset($data['oct_stickers_data']['customer']) && $data['oct_stickers_data']['customer']) {
				foreach ($data['oct_stickers_data']['customer'] as $key => $thumb_value) {
					$thumb = '';
					if (isset($thumb_value['image'])) {
						if (is_file(DIR_IMAGE . $thumb_value['image'])) {
							$thumb = $this->model_tool_image->resize($thumb_value['image'], 100, 100);
						}
					} else {
						$thumb = $this->model_tool_image->resize('no_image.png', 100, 100);
					}
					$data['oct_stickers_data']['customer'][$key] += ['thumb'	=>	$thumb];
				}
			}
		}
        $data['header']      = $this->load->controller('common/header');
        $data['column_left'] = $this->load->controller('common/column_left');
        $data['footer']      = $this->load->controller('common/footer');
        $this->response->setOutput($this->load->view('octemplates/stickers/oct_stickers_settings', $data));
	}
	public function install() {
		$this->load->language('octemplates/stickers/oct_stickers_settings');
        $this->load->model('setting/setting');
		$this->load->model('user/user_group');
		$this->load->model('octemplates/main/oct_settings');
        $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'octemplates/module/oct_stickers');
        $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'octemplates/module/oct_stickers');
		$this->load->model('localisation/language');
		$results = $this->model_localisation_language->getLanguages();
		$stickers_title = [];
        foreach ($results as $result) {
            $stickers_title[$result['language_id']] = '';
        }
		$oct_stickers_data = [
			'oct_stickers_status' => '0',
            'oct_stickers_data' => [
	            'stickers' => [
		            'new' => [
						'status' => 0,
						'text_color' => 'rgb(255, 255, 255)',
						'fon_color' => 'rgb(79, 67, 227)',
						'title' => $stickers_title,
						'sort' => 1,
						'count' => 10,
						'auto' => 0,
					],
					'bestseller' => [
						'status' => 0,
						'text_color' => 'rgb(255, 255, 255)',
						'fon_color' => 'rgb(235, 80, 20)',
						'title' => $stickers_title,
						'sort' => 2,
						'count' => 10,
						'auto' => 0,
					],
					'popular' => [
						'status' => 0,
						'text_color' => 'rgb(255, 255, 255)',
						'fon_color' => 'rgb(53, 154, 238)',
						'title' => $stickers_title,
						'sort' => 3,
						'count' => 10,
						'auto' => 0,
					],
					'special' => [
						'status' => 0,
						'text_color' => 'rgb(255, 255, 255)',
						'fon_color' => 'rgb(255, 0, 96)',
						'title' => $stickers_title,
						'sort' => 4,
						'auto' => 0,
						'persent' => 1,
						'view_title' => 1
					],
					'sold' => [
						'status' => 0,
						'text_color' => 'rgb(255, 255, 255)',
						'fon_color' => 'rgb(0, 0, 0)',
						'title' => $stickers_title,
						'sort' => 5,
						'count' => 0,
						'auto' => 0,
					],
					'ends' => [
						'status' => 0,
						'text_color' => 'rgb(255, 255, 255)',
						'fon_color' => 'rgb(230, 12, 12)',
						'title' => $stickers_title,
						'sort' => 6,
						'count' => 5,
						'auto' => 0,
					],
					'featured' => [
						'status' => 0,
						'text_color' => 'rgb(255, 255, 255)',
						'fon_color' => 'rgb(150, 21, 170)',
						'title' => $stickers_title,
						'sort' => 7,
					]
	            ],
				'customer' => []
            ]
		];
        $this->model_setting_setting->editSetting('oct_stickers', $oct_stickers_data);
		$this->generateCss($oct_stickers_data);
        $this->session->data['success'] = $this->language->get('text_success_install');
        $this->response->redirect($this->url->link('octemplates/stickers/oct_stickers_settings', 'user_token=' . $this->session->data['user_token'], true));
	}
	private function generateCss($data) {
		$css = '';
		if (isset($data['oct_stickers_status']) && $data['oct_stickers_status']) {
			if (isset($data['oct_stickers_data']['stickers'])) {
				foreach ($data['oct_stickers_data']['stickers'] as $key => $stickers) {
					if (isset($stickers['status']) && $stickers['status']) {
						$text_color = $stickers['text_color'] ? $stickers['text_color'] : "#fff";
						$fon_color = $stickers['fon_color'] ? $stickers['fon_color'] : "#000";
						$css .= '.ds-module-sticker-stickers_'. $key .' {color:'. $text_color .';background:'. $fon_color .';}';
					}
				}
			}
			if (isset($data['oct_stickers_data']['customer'])) {
				foreach ($data['oct_stickers_data']['customer'] as $key_customer => $customer) {
					if (isset($customer['status']) && $customer['status']) {
						$text_color = $customer['text_color'] ? $customer['text_color'] : "#fff";
						$fon_color = $customer['fon_color'] ? $customer['fon_color'] : "#000";
						$css .= '.ds-module-sticker-stickers_'. $key_customer .' {color:'. $text_color .';background:'. $fon_color .';}';
					}
				}
			}
			file_put_contents(DIR_CATALOG . 'view/theme/oct_deals/stylesheet/oct_stickers.css', $css);
			if (is_dir($this->request->server['DOCUMENT_ROOT'] . '/min/cache/')) {
				$this->delTree($this->request->server['DOCUMENT_ROOT'] . '/min/cache/');
			}
		}
	}
	private function delTree($dir) {
		$files = array_diff(scandir($dir), ['.','..']);
		foreach ($files as $file) {
			(is_dir("$dir/$file")) ? $this->delTree("$dir/$file") : unlink("$dir/$file");
		}
		return rmdir($dir);
	}
	private function validate() {
		if (!$this->user->hasPermission('modify', 'octemplates/stickers/oct_stickers_settings')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		return !$this->error;
	}
	private function validateDelete() {
		if (!$this->user->hasPermission('modify', 'octemplates/stickers/oct_stickers_settings')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		return !$this->error;
	}
}