forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax.php
185 lines (164 loc) · 5.83 KB
/
ajax.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
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* This file seems to be existing since a long time. Although ajax requests can be handled by our controller,
* some methods were forgotten here.
*
* They've been moved to the proper controller, but we keep this file for compatibility purpose.
* The content your see here is a proxy to the controller.
*/
use ToolsCore as Tools;
@trigger_error('Using '.__FILE__.' to make an ajax call is deprecated since 1.7.6.0 and will be removed in the next major version. Use a controller instead.', E_USER_DEPRECATED);
require_once dirname(__FILE__) . '/../classes/Tools.php';
/**
* Ajax calls to the controller AdminReferrers
* -> Moved to legacy
*/
if (Tools::isSubmit('ajaxReferrers')) {
$_GET['ajax'] = 1;
$_GET['controller'] = 'AdminReferrers';
if (Tools::isSubmit('ajaxProductFilter')) {
$_GET['action'] = 'productFilter';
}
if (Tools::isSubmit('ajaxFillProducts')) {
$_GET['action'] = 'fillProducts';
}
}
/**
* Return the list of a pack of products
* Not found
*
* -> Moved to legacy
*/
elseif (Tools::isSubmit('ajaxProductPackItems')) {
$_GET['ajax'] = 1;
$_GET['controller'] = 'AdminProducts';
$_GET['action'] = 'productPackItems';
}
/**
* Get all zones stored on the shop
* Json content with an html attribute in it.
*
* -> Moved in legacy
*/
elseif (Tools::isSubmit('getZones')) {
$_GET['ajax'] = 1;
$_GET['controller'] = 'AdminZones';
$_GET['action'] = 'zones';
}
elseif (Tools::isSubmit('getEmailHTML') && Tools::isSubmit('email')) {
$_GET['ajax'] = 1;
$_GET['controller'] = 'AdminTranslations';
$_GET['action'] = 'emailHTML';
}
if (1 === Tools::getValue('ajax')) {
require_once __DIR__ . '/index.php';
return;
}
/**
* From this line, the code could not be moved outside this file. It still requires the core to work.
*/
require_once __DIR__ . '/bootstrap.php';
$context = Context::getContext();
// Not used anymore, but kept just in case
if (Tools::getValue('page') == 'prestastore' && @fsockopen('addons.prestashop.com', 80, $errno, $errst, 3)) {
readfile('https://addons.prestashop.com/adminmodules.php?lang='.$context->language->iso_code);
}
/**
* Import controller: Fields available for a given entity
* -> Duplicated in Symfony
*/
elseif (Tools::isSubmit('getAvailableFields') && Tools::isSubmit('entity')) {
$import = new AdminImportController();
$fields = array_map(function ($elem) {
return ['field' => $elem];
}, $import->getAvailableFields(true));
echo json_encode($fields);
}
/**
* List notifications for an employee
* i.e: recent orders, new customers...
*
* -> Duplicated in Symfony
*/
elseif (Tools::isSubmit('getNotifications')) {
$notification = new Notification();
echo json_encode($notification->getLastElements());
}
/**
* Updates the last time a notification has been seen
*
* -> Duplicated in Symfony
*/
elseif (Tools::isSubmit('updateElementEmployee') && Tools::getValue('updateElementEmployeeType')) {
$notification = new Notification();
echo $notification->updateEmployeeLastElement(Tools::getValue('updateElementEmployeeType'));
}
/**
* Search for a category
*
* -> TODO in Symfony stack
*/
elseif (Tools::isSubmit('searchCategory')) {
$q = Tools::getValue('q');
$limit = Tools::getValue('limit');
$results = Db::getInstance()->executeS('SELECT c.`id_category`, cl.`name`
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.Shop::addSqlRestrictionOnLang('cl').')
WHERE cl.`id_lang` = '.(int)$context->language->id.' AND c.`level_depth` <> 0
AND cl.`name` LIKE \'%'.pSQL($q).'%\'
GROUP BY c.id_category
ORDER BY c.`position`
LIMIT '.(int)$limit
);
if ($results) {
foreach ($results as $result) {
echo trim($result['name']).'|'.(int)$result['id_category']."\n";
}
}
}
/**
* Used to display children of a given category, but flagged as deprecated since 1.6.0.4
* Not moved / Not duplicated
*/
elseif (Tools::isSubmit('getChildrenCategories') && Tools::isSubmit('id_category_parent')) {
$children_categories = Category::getChildrenWithNbSelectedSubCat(Tools::getValue('id_category_parent'), Tools::getValue('selectedCat'), Context::getContext()->language->id, null, Tools::getValue('use_shop_context'));
echo json_encode($children_categories);
}
/**
* Get all parents of a given category
*
* -> TODO in Symfony stack
*/
elseif (Tools::isSubmit('getParentCategoriesId') && $id_category = Tools::getValue('id_category')) {
$category = new Category((int)$id_category);
$results = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category` c WHERE c.`nleft` < '.(int)$category->nleft.' AND c.`nright` > '.(int)$category->nright.'');
$output = array();
foreach ($results as $result) {
$output[] = $result;
}
echo json_encode($output);
}