oct_slideshow_plus.php
17.7 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?php
/**
* @copyright OCTemplates
* @support https://octemplates.net/
* @license LICENSE.txt
*/
class ModelOCTemplatesDesignOctSlideshowPlus extends Model {
public function addSlideshow($data) {
$data['status'] = (isset($data['status']) && $data['status'] == 'on') ? 1 : 0;
$data['position_banners'] = (isset($data['position_banners']) && $data['position_banners'] == 1) ? 1 : 0;
$data['status_additional_banners'] = (isset($data['status_additional_banners']) && $data['status_additional_banners'] == 'on') ? 1 : 0;
$data['timer_view'] = (isset($data['timer_view']) && $data['timer_view'] == 'on') ? 1 : 0;
$data['full'] = (isset($data['full']) && $data['full'] == 'on') ? 1 : 0;
$this->db->query("
INSERT INTO " . DB_PREFIX . "oct_slideshow_plus
SET
name = '" . $this->db->escape($data['name']) . "',
status_additional_banners = '" . (int)$data['status_additional_banners'] . "',
timer_view = '" . (int)$data['timer_view'] . "',
full = '" . (int)$data['full'] . "',
position_banners = '" . (int)$data['position_banners'] . "',
status = '" . (int)$data['status'] . "'
");
$slideshow_id = $this->db->getLastId();
if (isset($data['oct_slideshow_plus_image'])) {
foreach ($data['oct_slideshow_plus_image'] as $oct_slideshow_plus_image) {
$this->db->query("
INSERT INTO " . DB_PREFIX . "oct_slideshow_plus_image
SET
slideshow_id = '" . (int)$slideshow_id . "',
image = '" . $this->db->escape(json_encode($oct_slideshow_plus_image['image'], true)) . "',
mobile_image = '" . $this->db->escape((isset($oct_slideshow_plus_image['mobile_image']) && !empty($oct_slideshow_plus_image['mobile_image'])) ? json_encode($oct_slideshow_plus_image['mobile_image'], true) : '') . "',
background_color = '" . $this->db->escape($oct_slideshow_plus_image['background_color']) . "',
title_color = '" . $this->db->escape($oct_slideshow_plus_image['title_color']) . "',
text_color = '" . $this->db->escape($oct_slideshow_plus_image['text_color']) . "',
button_color = '" . $this->db->escape($oct_slideshow_plus_image['button_color']) . "',
button_background = '" . $this->db->escape($oct_slideshow_plus_image['button_background']) . "',
button_color_hover = '" . $this->db->escape($oct_slideshow_plus_image['button_color_hover']) . "',
button_background_hover = '" . $this->db->escape($oct_slideshow_plus_image['button_background_hover']) . "',
sort_order = '" . (int)$oct_slideshow_plus_image['sort_order'] . "'
");
$slideshow_image_id = $this->db->getLastId();
foreach ($oct_slideshow_plus_image['oct_slideshow_plus_image_description'] as $language_id => $oct_slideshow_plus_image_description) {
$this->db->query("
INSERT INTO " . DB_PREFIX . "oct_slideshow_plus_image_description
SET
slideshow_image_id = '" . (int)$slideshow_image_id . "',
language_id = '" . (int)$language_id . "',
slideshow_id = '" . (int)$slideshow_id . "',
title = '" . $this->db->escape($oct_slideshow_plus_image_description['title']) . "',
link = '" . $this->db->escape($oct_slideshow_plus_image_description['link']) . "',
button = '" . $this->db->escape($oct_slideshow_plus_image_description['button']) . "',
description = '" . $this->db->escape($oct_slideshow_plus_image_description['description']) . "'
");
}
}
}
if (isset($data['oct_discount_products'])) {
$this->load->model('catalog/product');
foreach ($data['oct_discount_products'] as $product_id) {
$this->db->query("
DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_product
WHERE
slideshow_id = '" . (int)$slideshow_id . "'
AND product_id = '" . (int)$product_id . "'
");
$this->db->query("
INSERT INTO " . DB_PREFIX . "oct_slideshow_plus_product
SET
slideshow_id = '" . (int)$slideshow_id . "',
product_id = '" . (int)$product_id . "'
");
}
}
return $slideshow_id;
}
public function editSlideshow($slideshow_id, $data) {
$data['status'] = (isset($data['status']) && $data['status'] == 'on') ? 1 : 0;
$data['position_banners'] = (isset($data['position_banners']) && $data['position_banners'] == 1) ? 1 : 0;
$data['status_additional_banners'] = (isset($data['status_additional_banners']) && $data['status_additional_banners'] == 'on') ? 1 : 0;
$data['timer_view'] = (isset($data['timer_view']) && $data['timer_view'] == 'on') ? 1 : 0;
$data['full'] = (isset($data['full']) && $data['full'] == 'on') ? 1 : 0;
$this->db->query("
UPDATE " . DB_PREFIX . "oct_slideshow_plus
SET
name = '" . $this->db->escape($data['name']) . "',
status_additional_banners = '" . (int) $data['status_additional_banners'] . "',
timer_view = '" . (int)$data['timer_view'] . "',
full = '" . (int)$data['full'] . "',
position_banners = '" . (int) $data['position_banners'] . "',
status = '" . (int)$data['status'] . "'
WHERE
slideshow_id = '" . (int)$slideshow_id . "'
");
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_image WHERE slideshow_id = '" . (int)$slideshow_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_image_description WHERE slideshow_id = '" . (int)$slideshow_id . "'");
if (isset($data['oct_slideshow_plus_image'])) {
foreach ($data['oct_slideshow_plus_image'] as $oct_slideshow_plus_image) {
$oct_slideshow_plus_image['full'] = (isset($oct_slideshow_plus_image['full']) && $oct_slideshow_plus_image['full'] == 'on') ? 1 : 0;
$this->db->query("
INSERT INTO " . DB_PREFIX . "oct_slideshow_plus_image
SET
slideshow_id = '" . (int)$slideshow_id . "',
image = '" . $this->db->escape(json_encode($oct_slideshow_plus_image['image'], true)) . "',
mobile_image = '" . $this->db->escape((isset($oct_slideshow_plus_image['mobile_image']) && !empty($oct_slideshow_plus_image['mobile_image'])) ? json_encode($oct_slideshow_plus_image['mobile_image'], true) : '') . "',
background_color = '" . $this->db->escape($oct_slideshow_plus_image['background_color']) . "',
title_color = '" . $this->db->escape($oct_slideshow_plus_image['title_color']) . "',
text_color = '" . $this->db->escape($oct_slideshow_plus_image['text_color']) . "',
button_color = '" . $this->db->escape($oct_slideshow_plus_image['button_color']) . "',
button_background = '" . $this->db->escape($oct_slideshow_plus_image['button_background']) . "',
button_color_hover = '" . $this->db->escape($oct_slideshow_plus_image['button_color_hover']) . "',
button_background_hover = '" . $this->db->escape($oct_slideshow_plus_image['button_background_hover']) . "',
sort_order = '" . (int)$oct_slideshow_plus_image['sort_order'] . "'
");
$slideshow_image_id = $this->db->getLastId();
foreach ($oct_slideshow_plus_image['oct_slideshow_plus_image_description'] as $language_id => $oct_slideshow_plus_image_description) {
$this->db->query("
INSERT INTO " . DB_PREFIX . "oct_slideshow_plus_image_description
SET
slideshow_image_id = '" . (int)$slideshow_image_id . "',
language_id = '" . (int)$language_id . "',
slideshow_id = '" . (int)$slideshow_id . "',
title = '" . $this->db->escape($oct_slideshow_plus_image_description['title']) . "',
link = '" . $this->db->escape($oct_slideshow_plus_image_description['link']) . "',
button = '" . $this->db->escape($oct_slideshow_plus_image_description['button']) . "',
description = '" . $this->db->escape($oct_slideshow_plus_image_description['description']) . "'
");
}
}
}
$this->db->query("
DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_product
WHERE
slideshow_id = '" . (int)$slideshow_id . "'
");
if (isset($data['oct_discount_products'])) {
$this->load->model('catalog/product');
foreach ($data['oct_discount_products'] as $product_id) {
$this->db->query("
DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_product
WHERE
slideshow_id = '" . (int)$slideshow_id . "'
AND product_id = '" . (int)$product_id . "'
");
$this->db->query("
INSERT INTO " . DB_PREFIX . "oct_slideshow_plus_product
SET
slideshow_id = '" . (int)$slideshow_id . "',
product_id = '" . (int)$product_id . "'
");
}
}
}
public function deleteSlideshow($slideshow_id) {
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_slideshow_plus WHERE slideshow_id = '" . (int)$slideshow_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_image WHERE slideshow_id = '" . (int)$slideshow_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_image_description WHERE slideshow_id = '" . (int)$slideshow_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_slideshow_plus_product WHERE slideshow_id = '" . (int)$slideshow_id . "'");
}
public function getSlideshow($slideshow_id) {
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "oct_slideshow_plus WHERE slideshow_id = '" . (int)$slideshow_id . "'");
return $query->row;
}
public function getSlideshows($data = []) {
$sql = "SELECT * FROM " . DB_PREFIX . "oct_slideshow_plus";
$sort_data = [
'name',
'status'
];
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY name";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql);
return $query->rows;
}
public function getSlideshowImages($slideshow_id) {
$oct_slideshow_plus_image_data = [];
$oct_slideshow_plus_image_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "oct_slideshow_plus_image WHERE slideshow_id = '" . (int)$slideshow_id . "' ORDER BY sort_order ASC");
foreach ($oct_slideshow_plus_image_query->rows as $oct_slideshow_plus_image) {
$oct_slideshow_plus_image_description_data = [];
$oct_slideshow_plus_image_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "oct_slideshow_plus_image_description WHERE slideshow_image_id = '" . (int)$oct_slideshow_plus_image['slideshow_image_id'] . "' AND slideshow_id = '" . (int)$slideshow_id . "'");
foreach ($oct_slideshow_plus_image_description_query->rows as $oct_slideshow_plus_image_description) {
$oct_slideshow_plus_image_description_data[$oct_slideshow_plus_image_description['language_id']] = [
'title' => $oct_slideshow_plus_image_description['title'],
'link' => $oct_slideshow_plus_image_description['link'],
'button' => $oct_slideshow_plus_image_description['button'],
'description' => $oct_slideshow_plus_image_description['description']
];
}
$oct_slideshow_plus_image_data[] = [
'oct_slideshow_plus_image_description' => $oct_slideshow_plus_image_description_data,
'image' => json_decode($oct_slideshow_plus_image['image'], true),
'mobile_image' => (isset($oct_slideshow_plus_image['mobile_image']) && !empty($oct_slideshow_plus_image['mobile_image'])) ? json_decode($oct_slideshow_plus_image['mobile_image'], true) : '',
'background_color' => $oct_slideshow_plus_image['background_color'],
'title_color' => $oct_slideshow_plus_image['title_color'],
'text_color' => $oct_slideshow_plus_image['text_color'],
'button_color' => $oct_slideshow_plus_image['button_color'],
'button_background' => $oct_slideshow_plus_image['button_background'],
'button_color_hover' => $oct_slideshow_plus_image['button_color_hover'],
'button_background_hover' => $oct_slideshow_plus_image['button_background_hover'],
'sort_order' => $oct_slideshow_plus_image['sort_order']
];
}
return $oct_slideshow_plus_image_data;
}
public function getDiscountProduct($slideshow_id) {
$discount_products_data = [];
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "oct_slideshow_plus_product WHERE slideshow_id = '" . (int)$slideshow_id . "'");
foreach ($query->rows as $result) {
$discount_products_data[] = $result['product_id'];
}
return $discount_products_data;
}
public function getTotalSlideshows() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "oct_slideshow_plus");
return $query->row['total'];
}
public function createDBTables() {
$sql_01 = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "oct_slideshow_plus` ( ";
$sql_01 .= "`slideshow_id` int(11) NOT NULL AUTO_INCREMENT, ";
$sql_01 .= "`name` varchar(64) NOT NULL, ";
$sql_01 .= "`status_additional_banners` tinyint(1) NOT NULL DEFAULT '1', ";
$sql_01 .= "`timer_view` tinyint(1) NOT NULL DEFAULT '1', ";
$sql_01 .= "`full` tinyint(1) NOT NULL DEFAULT '1', ";
$sql_01 .= "`position_banners` tinyint(1) NOT NULL DEFAULT '1', ";
$sql_01 .= "`status` tinyint(1) NOT NULL, ";
$sql_01 .= "PRIMARY KEY (`slideshow_id`) ";
$sql_01 .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ; ";
$this->db->query($sql_01);
$sql_02 = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "oct_slideshow_plus_image` ( ";
$sql_02 .= "`slideshow_image_id` int(11) NOT NULL AUTO_INCREMENT, ";
$sql_02 .= "`slideshow_id` int(11) NOT NULL, ";
$sql_02 .= "`image` text NOT NULL, ";
$sql_02 .= "`mobile_image` text NOT NULL, ";
$sql_02 .= "`background_color` varchar(255) COLLATE 'utf8_general_ci' NOT NULL, ";
$sql_02 .= "`title_color` varchar(255) COLLATE 'utf8_general_ci' NOT NULL, ";
$sql_02 .= "`text_color` varchar(255) COLLATE 'utf8_general_ci' NOT NULL, ";
$sql_02 .= "`button_color` varchar(255) COLLATE 'utf8_general_ci' NOT NULL, ";
$sql_02 .= "`button_background` varchar(255) COLLATE 'utf8_general_ci' NOT NULL, ";
$sql_02 .= "`button_color_hover` varchar(255) COLLATE 'utf8_general_ci' NOT NULL, ";
$sql_02 .= "`button_background_hover` varchar(255) COLLATE 'utf8_general_ci' NOT NULL, ";
$sql_02 .= "`sort_order` int(3) NOT NULL DEFAULT '0', ";
$sql_02 .= "PRIMARY KEY (`slideshow_image_id`) ";
$sql_02 .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ; ";
$this->db->query($sql_02);
$sql_03 = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "oct_slideshow_plus_image_description` ( ";
$sql_03 .= "`slideshow_image_id` int(11) NOT NULL, ";
$sql_03 .= "`language_id` int(11) NOT NULL, ";
$sql_03 .= "`slideshow_id` int(11) NOT NULL, ";
$sql_03 .= "`title` varchar(64) NOT NULL, ";
$sql_03 .= "`link` varchar(255) NOT NULL, ";
$sql_03 .= "`button` varchar(64) NOT NULL, ";
$sql_03 .= "`description` text NOT NULL, ";
$sql_03 .= "PRIMARY KEY (`slideshow_image_id`,`language_id`) ";
$sql_03 .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8 ; ";
$this->db->query($sql_03);
$sql_04 = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "oct_slideshow_plus_product` (";
$sql_04 .= "`slideshow_id` int(11) NOT NULL, ";
$sql_04 .= "`product_id` int(11) NOT NULL, ";
$sql_04 .= "PRIMARY KEY (`slideshow_id`,`product_id`) ";
$sql_04 .= ") ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$this->db->query($sql_04);
}
public function updateTypeColumn() {
$this->db->query("
ALTER TABLE `" . DB_PREFIX . "oct_slideshow_plus_image`
CHANGE `image` `image` text COLLATE 'utf8_general_ci' NOT NULL AFTER `slideshow_id`,
CHANGE `mobile_image` `mobile_image` text COLLATE 'utf8_general_ci' NOT NULL AFTER `image`
");
}
public function updateImages() {
$this->load->model('localisation/language');
$languages = $this->model_localisation_language->getLanguages();
$query = $this->db->query("SELECT `slideshow_image_id`, `slideshow_id`, `image`, `mobile_image` FROM " . DB_PREFIX . "oct_slideshow_plus_image");
foreach ($query->rows as $oct_sp_images) {
$image = $mobile_image = [];
foreach ($languages as $lang) {
$image[(int)$lang['language_id']] = $oct_sp_images['image'];
$mobile_image[(int)$lang['language_id']] = $oct_sp_images['mobile_image'];
}
$this->db->query("
UPDATE `" . DB_PREFIX . "oct_slideshow_plus_image`
SET
image = '" . $this->db->escape(json_encode($image, true)) . "',
mobile_image = '" . $this->db->escape(json_encode($mobile_image, true)) . "'
WHERE
slideshow_image_id = '" . (int)$oct_sp_images['slideshow_image_id'] . "'
AND
slideshow_id = '". (int)$oct_sp_images['slideshow_id'] ."'
");
}
}
}