1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* oledrion |
14
|
|
|
* |
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
16
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
17
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
18
|
|
|
* @version $Id: attributes.php 12290 2014-02-07 11:05:17Z beckmi $ |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Gestion des attributs produits |
23
|
|
|
*/ |
24
|
|
|
if (!defined("OLEDRION_ADMIN")) exit(); |
25
|
|
|
global $baseurl; // Pour faire taire les warnings de Zend Studio |
|
|
|
|
26
|
|
|
$operation = 'attributes'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Suppression de l'attribut qui se trouve en session |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
function removeAttributInSession() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
if (isset($_SESSION['oledrion_attribute'])) { |
36
|
|
|
$_SESSION['oledrion_attribute'] = null; |
37
|
|
|
unset($_SESSION['oledrion_attribute']); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
switch ($action) { |
42
|
|
|
// **************************************************************************************************************** |
43
|
|
|
case 'default': // Liste des attributs produits |
44
|
|
|
// **************************************************************************************************************** |
45
|
|
|
xoops_cp_header(); |
46
|
|
|
|
47
|
|
|
global $xoopsConfig; |
|
|
|
|
48
|
|
|
$productsIds = $products = $productsIdsForList = $productsForList = array(); |
49
|
|
|
$class = ''; |
50
|
|
|
removeAttributInSession(); |
51
|
|
|
|
52
|
|
|
$form = "<form method='post' action='$baseurl' name='frmadd$operation' id='frmadd$operation'><input type='hidden' name='op' id='op' value='$operation' /><input type='hidden' name='action' id='action' value='add' /><input type='submit' name='btngo' id='btngo' value='" . _AM_OLEDRION_ADD_ITEM . "' /></form>"; |
53
|
|
|
echo $form; |
54
|
|
|
|
55
|
|
|
oledrion_utils::htitle(_AM_OLEDRION_ATTRIBUTES_LIST, 4); |
56
|
|
|
|
57
|
|
|
$start = isset($_GET['start']) ? intval($_GET['start']) : 0; |
58
|
|
|
$criteria = new CriteriaCompo(); |
59
|
|
|
$criteria->add(new Criteria('attribute_id', 0, '<>')); |
60
|
|
|
|
61
|
|
|
$filter_attribute_id = $filter_attribute_id = $filter_attribute_weight = $filter_attribute_type = $filter_attribute_product_id = 0; |
62
|
|
|
$filter_attribute_title = ''; |
63
|
|
|
|
64
|
|
|
$newFilter = false; |
65
|
|
|
|
66
|
|
View Code Duplication |
if (isset($_POST['filter_attribute_id'])) { |
|
|
|
|
67
|
|
|
if (intval($_POST['filter_attribute_id']) != 0) { |
68
|
|
|
$criteria->add(new Criteria('attribute_id', intval($_POST['filter_attribute_id']), '=')); |
69
|
|
|
} |
70
|
|
|
$filter_attribute_id = intval($_POST['filter_attribute_id']); |
71
|
|
|
$newFilter = true; |
72
|
|
|
} |
73
|
|
View Code Duplication |
if (isset($_POST['filter_attribute_title']) && xoops_trim($_POST['filter_attribute_title']) != '') { |
|
|
|
|
74
|
|
|
$criteria->add(new Criteria('attribute_title', '%' . $_POST['filter_attribute_title'] . '%', 'LIKE')); |
75
|
|
|
$filter_attribute_title = $_POST['filter_attribute_title']; |
76
|
|
|
$newFilter = true; |
77
|
|
|
} |
78
|
|
View Code Duplication |
if (isset($_POST['filter_attribute_product_id']) && intval($_POST['filter_attribute_product_id']) != 0) { |
|
|
|
|
79
|
|
|
$criteria->add(new Criteria('attribute_product_id', intval($_POST['filter_attribute_product_id']), '=')); |
80
|
|
|
$filter_attribute_product_id = intval($_POST['filter_attribute_product_id']); |
81
|
|
|
$newFilter = true; |
82
|
|
|
} |
83
|
|
View Code Duplication |
if (isset($_POST['filter_attribute_weight']) && intval($_POST['filter_attribute_weight']) != 0) { |
|
|
|
|
84
|
|
|
$criteria->add(new Criteria('attribute_weight', intval($_POST['filter_attribute_weight']), '=')); |
85
|
|
|
$filter_attribute_weight = intval($_POST['filter_attribute_weight']); |
86
|
|
|
$newFilter = true; |
87
|
|
|
} |
88
|
|
View Code Duplication |
if (isset($_POST['filter_attribute_type']) && intval($_POST['filter_attribute_type']) != 0) { |
|
|
|
|
89
|
|
|
$criteria->add(new Criteria('attribute_type', intval($_POST['filter_attribute_type']), '=')); |
90
|
|
|
$filter_attribute_type = intval($_POST['filter_attribute_type']); |
91
|
|
|
$newFilter = true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if ($filter_attribute_id == 0 && $filter_attribute_title == '' && $filter_attribute_weight == 0 && $filter_attribute_type == 0) { |
95
|
|
|
$newFilter = true; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (!$newFilter && isset($_SESSION['oledrion_filter_attributes'])) { |
99
|
|
|
$criteria = unserialize($_SESSION['oledrion_filter_attributes']); |
100
|
|
|
$filter_attribute_id = $_SESSION['filter_attribute_id']; |
101
|
|
|
$filter_attribute_title = $_SESSION['filter_attribute_title']; |
102
|
|
|
$filter_attribute_product_id = $_SESSION['filter_attribute_product_id']; |
103
|
|
|
$filter_attribute_weight = $_SESSION['filter_attribute_weight']; |
104
|
|
|
$filter_attribute_type = $_SESSION['filter_attribute_type']; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$_SESSION['oledrion_filter_attributes'] = serialize($criteria); |
108
|
|
|
$_SESSION['filter_attribute_id'] = $filter_attribute_id; |
109
|
|
|
$_SESSION['filter_attribute_title'] = $filter_attribute_title; |
110
|
|
|
$_SESSION['filter_attribute_product_id'] = $filter_attribute_product_id; |
111
|
|
|
$_SESSION['filter_attribute_weight'] = $filter_attribute_weight; |
112
|
|
|
$_SESSION['filter_attribute_type'] = $filter_attribute_type; |
113
|
|
|
|
114
|
|
|
$itemsCount = $oledrion_handlers->h_oledrion_attributes->getCount($criteria); |
115
|
|
|
if ($itemsCount > $limit) { |
116
|
|
|
$pagenav = new XoopsPageNav($itemsCount, $limit, $start, 'start', 'op=' . $operation); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$criteria->setLimit($limit); |
120
|
|
|
$criteria->setStart($start); |
121
|
|
|
$criteria->setSort('attribute_product_id, attribute_weight'); |
122
|
|
|
$items = $oledrion_handlers->h_oledrion_attributes->getObjects($criteria); |
123
|
|
|
if (count($items) > 0) { |
124
|
|
|
foreach ($items as $item) { |
125
|
|
|
if (!isset($productsIds[$item->getVar('attribute_product_id')])) { |
126
|
|
|
$productsIds[] = $item->getVar('attribute_product_id'); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
if (count($productsIds) > 0) { |
130
|
|
|
$products = $oledrion_handlers->h_oledrion_products->getProductsFromIDs($productsIds, true); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
$typeSelect = oledrion_utils::htmlSelect('filter_attribute_type', array(OLEDRION_ATTRIBUTE_RADIO => _AM_OLEDRION_TYPE_RADIO, OLEDRION_ATTRIBUTE_CHECKBOX => _AM_OLEDRION_TYPE_CHECKBOX, OLEDRION_ATTRIBUTE_SELECT => _AM_OLEDRION_TYPE_LIST), $filter_attribute_type); |
134
|
|
|
|
135
|
|
|
$productsIdsForList = $oledrion_handlers->h_oledrion_attributes->getDistinctsProductsIds(); |
136
|
|
|
if (count($productsIdsForList) > 0) { |
137
|
|
|
$productsForList = $oledrion_handlers->h_oledrion_products->getList(new Criteria('product_id', '(' . implode(',', $productsIdsForList) . ')', 'IN')); |
138
|
|
|
} |
139
|
|
|
$selectProduct = oledrion_utils::htmlSelect('filter_attribute_product_id', $productsForList, $filter_attribute_product_id); |
140
|
|
|
|
141
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
142
|
|
|
if (isset($pagenav) && is_object($pagenav)) { |
143
|
|
|
echo "<tr><td colspan='2' align='left'>" . $pagenav->renderNav() . "</td><td align='right' colspan='3'> </td></tr>\n"; |
144
|
|
|
} |
145
|
|
|
echo "<tr><th align='center'>" . _AM_OLEDRION_ID . "</th><th align='center'>" . _AM_OLEDRION_TITLE . "</th><th align='center'>" . _AM_OLEDRION_DISCOUNT_PRODUCT . "</th><th align='center'>" . _AM_OLEDRION_WEIGHT . "</th><th align='center'>" . _AM_OLEDRION_TYPE . "</th><th align='center'>" . _AM_OLEDRION_ACTION . "</th></tr>"; |
146
|
|
|
|
147
|
|
|
// Les filtres |
148
|
|
|
echo "<tr><form method='post' action='$baseurl'><th align='center'><input type='text' size='3' name='filter_attribute_id' id='filter_attribute_id' value='$filter_attribute_id' /></th>\n"; |
149
|
|
|
echo "<th align='center'><input type='text' size='25' name='filter_attribute_title' id='filter_attribute_title' value='$filter_attribute_title' /></th>\n"; |
150
|
|
|
echo "<th align='center'>" . $selectProduct . "</th>\n"; |
151
|
|
|
echo "<th align='center'><input type='text' size='5' name='filter_attribute_weight' id='filter_attribute_weight' value='$filter_attribute_weight' /></th>\n"; |
152
|
|
|
echo "<th align='center'>" . $typeSelect . "</th>\n"; |
153
|
|
|
echo "<th align='center'><input type='hidden' name='op' id='op' value='attributes' /><input type='submit' name='btngo' id='btngo' value='" . _GO . "' /></th></form></tr>\n"; |
154
|
|
|
|
155
|
|
|
foreach ($items as $item) { |
156
|
|
|
$class = ($class == 'even') ? 'odd' : 'even'; |
157
|
|
|
$id = $item->getVar('attribute_id'); |
158
|
|
|
$actions = array(); |
159
|
|
|
$actions[] = "<a href='$baseurl?op=$operation&action=edit&id=" . $id . "' title='" . _OLEDRION_EDIT . "'>" . $icones['edit'] . '</a>'; |
160
|
|
|
$actions[] = "<a href='$baseurl?op=$operation&action=copy&id=" . $id . "' title='" . _OLEDRION_DUPLICATE_ATTRIBUTE . "'>" . $icones['copy'] . '</a>'; |
161
|
|
|
$actions[] = "<a href='$baseurl?op=$operation&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . ">" . $icones['delete'] . '</a>'; |
162
|
|
|
$productTitle = isset($products[$item->getVar('attribute_product_id')]) ? $products[$item->getVar('attribute_product_id')]->getVar('product_title') : ''; |
163
|
|
|
$productLink = isset($products[$item->getVar('attribute_product_id')]) ? $products[$item->getVar('attribute_product_id')]->getLink() : ''; |
164
|
|
|
echo "<tr class='" . $class . "'>\n"; |
165
|
|
|
echo "<td align='right'>" . $item->attribute_id . "</a></td>"; |
166
|
|
|
echo "<td align='left'><a target='_blank' href='" . $productLink . "'>" . $item->attribute_title . "</a></td>"; |
167
|
|
|
$urlProductEdit = $baseurl . "?op=products&action=edit&id=" . $item->getVar('attribute_product_id'); |
168
|
|
|
|
169
|
|
|
echo "<td align='center'><a title='" . _EDIT . "' href='" . $urlProductEdit . "'><img src='" . OLEDRION_IMAGES_URL . "smalledit.png' /> " . $productTitle . "</a></td>"; |
170
|
|
|
echo "<td align='center'>" . $item->attribute_weight . "</td>\n"; |
171
|
|
|
echo "<td align='center'>" . $item->getTypeName() . "</td>\n"; |
172
|
|
|
echo "<td align='center'>" . implode(' ', $actions) . "</td>\n"; |
173
|
|
|
echo "<tr>\n"; |
174
|
|
|
} |
175
|
|
|
$class = ($class == 'even') ? 'odd' : 'even'; |
176
|
|
|
echo "<tr class='" . $class . "'>\n"; |
177
|
|
|
echo "<td colspan='6' align='center'>" . $form . "</td>\n"; |
178
|
|
|
echo "</tr>\n"; |
179
|
|
|
echo '</table>'; |
180
|
|
|
if (isset($pagenav) && is_object($pagenav)) { |
181
|
|
|
echo "<div align='right'>" . $pagenav->renderNav() . "</div>"; |
182
|
|
|
} |
183
|
|
|
include_once OLEDRION_ADMIN_PATH . 'admin_footer.php'; |
184
|
|
|
break; |
185
|
|
|
|
186
|
|
|
// **************************************************************************************************************** |
187
|
|
View Code Duplication |
case 'copy': // Dupliquer un attribut |
|
|
|
|
188
|
|
|
// **************************************************************************************************************** |
189
|
|
|
xoops_cp_header(); |
190
|
|
|
$id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
191
|
|
|
if (empty($id)) { |
192
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5); |
193
|
|
|
} |
194
|
|
|
$attribute = null; |
195
|
|
|
$attribute = $oledrion_handlers->h_oledrion_attributes->get($id); |
196
|
|
|
if (is_object($attribute)) { |
197
|
|
|
$newAttribute = $oledrion_handlers->h_oledrion_attributes->cloneAttribute($attribute); |
198
|
|
|
$newAttributeId = $newAttribute->attribute_id; |
199
|
|
|
if ($newAttribute !== false) { |
200
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $operation . "&action=edit&id=" . $newAttributeId, 2); |
201
|
|
|
} else { |
202
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $operation, 5); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
break; |
206
|
|
|
|
207
|
|
|
// **************************************************************************************************************** |
208
|
|
|
case 'delete': // Suppression d'un attribut |
209
|
|
|
// **************************************************************************************************************** |
210
|
|
|
xoops_cp_header(); |
211
|
|
|
$id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
212
|
|
|
if (empty($id)) { |
213
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5); |
214
|
|
|
} |
215
|
|
|
$attribute = null; |
216
|
|
|
$attribute = $oledrion_handlers->h_oledrion_attributes->get($id); |
217
|
|
|
if (!is_object($attribute)) { |
218
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $operation, 5); |
219
|
|
|
} |
220
|
|
|
$attributesCountInCaddy = $oledrion_handlers->h_oledrion_caddy_attributes->getCaddyCountFromAttributeId($id); |
221
|
|
|
if ($attributesCountInCaddy == 0) { |
222
|
|
|
$res = $oledrion_handlers->h_oledrion_attributes->deleteAttribute($attribute); |
223
|
|
|
if ($res) { |
224
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $operation, 2); |
225
|
|
|
} else { |
226
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $operation, 5); |
227
|
|
|
} |
228
|
|
View Code Duplication |
} else { |
|
|
|
|
229
|
|
|
oledrion_utils::htitle(_AM_OLEDRION_SORRY_NOREMOVE2, 4); |
230
|
|
|
$tblTmp = $oledrion_handlers->h_oledrion_caddy_attributes->getCommandIdFromAttribute($id); |
231
|
|
|
$tblTmp2 = $h_oledrion_commands->getObjects(new Criteria('cmd_id', '(' . implode(',', $tblTmp) . ')', 'IN'), true); |
232
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
233
|
|
|
$class = ''; |
234
|
|
|
echo "<tr><th align='center'>" . _AM_OLEDRION_ID . "</th><th align='center'>" . _AM_OLEDRION_DATE . "</th><th align='center'>" . _AM_OLEDRION_CLIENT . "</th><th align='center'>" . _AM_OLEDRION_TOTAL_SHIPP . "</th></tr>"; |
235
|
|
|
foreach ($tblTmp2 as $item) { |
236
|
|
|
$class = ($class == 'even') ? 'odd' : 'even'; |
237
|
|
|
$date = formatTimestamp(strtotime($item->getVar('cmd_date')), 's'); |
238
|
|
|
echo "<tr class='" . $class . "'>\n"; |
239
|
|
|
echo "<td align='right'>" . $item->getVar('cmd_id') . "</td><td align='center'>" . $date . "</td><td align='center'>" . $item->getVar('cmd_lastname') . ' ' . $item->getVar('cmd_firstname') . "</td><td align='center'>" . $item->getVar('cmd_total') . ' ' . oledrion_utils::getModuleOption('money_short') . ' / ' . $item->getVar('cmd_shipping') . ' ' . oledrion_utils::getModuleOption('money_short') . "</td>\n"; |
240
|
|
|
echo "<tr>\n"; |
241
|
|
|
} |
242
|
|
|
echo '</table>'; |
243
|
|
|
include_once OLEDRION_ADMIN_PATH . 'admin_footer.php'; |
244
|
|
|
} |
245
|
|
|
break; |
246
|
|
|
|
247
|
|
|
// **************************************************************************************************************** |
248
|
|
|
case 'add': // Ajout d'un attribut |
249
|
|
|
case 'edit': // Edition d'un attribut |
250
|
|
|
// **************************************************************************************************************** |
251
|
|
|
xoops_cp_header(); |
252
|
|
|
removeAttributInSession(); |
253
|
|
|
|
254
|
|
|
if ($action == 'edit') { |
255
|
|
|
$title = _AM_OLEDRION_EDIT_ATTRIBUTE; |
256
|
|
|
$id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
257
|
|
|
if (empty($id)) { |
258
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5); |
259
|
|
|
} |
260
|
|
|
// Item exits ? |
261
|
|
|
$item = null; |
262
|
|
|
$item = $oledrion_handlers->h_oledrion_attributes->get($id); |
263
|
|
|
if (!is_object($item)) { |
264
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
265
|
|
|
} |
266
|
|
|
$edit = true; |
267
|
|
|
$label_submit = _AM_OLEDRION_MODIFY; |
268
|
|
|
} else { |
269
|
|
|
$title = _AM_OLEDRION_ADD_ATTRIBUTE; |
270
|
|
|
$item = $oledrion_handlers->h_oledrion_attributes->create(true); |
271
|
|
|
$item->setVar('attribute_id', 0); |
272
|
|
|
$label_submit = _AM_OLEDRION_ADD; |
273
|
|
|
$edit = false; |
274
|
|
|
} |
275
|
|
|
// Appel à jQuery |
276
|
|
|
$xoTheme->addScript("browse.php?Frameworks/jquery/jquery.js"); |
277
|
|
|
oledrion_utils::callJavascriptFile('noconflict.js', false, true); |
278
|
|
|
// Appel du fichier langue |
279
|
|
|
oledrion_utils::callJavascriptFile('messages.js', true, true); |
280
|
|
|
|
281
|
|
|
$sform = new XoopsThemeForm($title, 'frm' . $operation, $baseurl); |
282
|
|
|
$sform->addElement(new XoopsFormHidden('op', $operation)); |
283
|
|
|
$sform->addElement(new XoopsFormHidden('action', 'saveedit')); |
284
|
|
|
$sform->addElement(new XoopsFormHidden('attribute_id', $item->getVar('attribute_id'))); |
285
|
|
|
$sform->addElement(new XoopsFormText(_AM_OLEDRION_TITLE, 'attribute_title', 50, 255, $item->getVar('attribute_title', 'e')), true); |
286
|
|
|
$sform->addElement(new XoopsFormText(_AM_OLEDRION_ATTRIBUTE_NAME, 'attribute_name', 50, 255, $item->getVar('attribute_name', 'e')), true); |
287
|
|
|
|
288
|
|
|
$products = array(); |
289
|
|
|
$products = $oledrion_handlers->h_oledrion_products->getList(); |
290
|
|
|
$productsSelect = $oledrion_handlers->h_oledrion_products->productSelector(new oledrion_parameters(array('caption' => _AM_OLEDRION_ATTRIBUTE_PRODUCT, 'name' => 'attribute_product_id', 'value' => $item->getVar('attribute_product_id', 'e'), 'size' => 1, 'multiple' => false, 'values' => null, 'showAll' => true, 'sort' => 'product_title', 'order' => 'ASC', 'formName' => 'frm' . $operation))); |
291
|
|
|
$sform->addElement($productsSelect); |
292
|
|
|
|
293
|
|
|
$sform->addElement(new XoopsFormText(_AM_OLEDRION_WEIGHT, 'attribute_weight', 10, 10, $item->getVar('attribute_weight', 'e')), true); |
294
|
|
|
|
295
|
|
|
$typeSelect = new XoopsFormSelect(_AM_OLEDRION_TYPE, 'attribute_type', $item->getVar('attribute_type', 'e')); |
296
|
|
|
$typeSelect->addOptionArray($item->getTypesList()); |
297
|
|
|
$sform->addElement($typeSelect, true); |
298
|
|
|
|
299
|
|
|
// Paramétrage (pour les boutons radio et cases à cocher, le délimiteur, pour les listes déroulantes, le nombre d'éléments visibles et la sélection multiple) |
300
|
|
|
// Les boutons radio et cases à cocher |
301
|
|
|
$attributeParameters = "<div name='attributeParameters' id='attributeParameters'>\n"; |
302
|
|
|
$defaultValue = OLEDRION_ATTRIBUTE_CHECKBOX_WHITE_SPACE; |
303
|
|
|
if ($edit) { |
304
|
|
|
if ($item->getVar('attribute_type') == OLEDRION_ATTRIBUTE_RADIO || $item->getVar('attribute_type') == OLEDRION_ATTRIBUTE_CHECKBOX) { |
305
|
|
|
$defaultValue = $item->getVar('attribute_option1', 'e'); |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
$options = array(OLEDRION_ATTRIBUTE_CHECKBOX_WHITE_SPACE => _AM_OLEDRION_ATTRIBUTE_DELIMITER1, OLEDRION_ATTRIBUTE_CHECKBOX_NEW_LINE => _AM_OLEDRION_ATTRIBUTE_DELIMITER2); |
309
|
|
|
$parameterButtonOption = _AM_OLEDRION_ATTRIBUTE_DELIMITER . ' ' . oledrion_utils::htmlSelect('option1', $options, $defaultValue, false); |
310
|
|
|
$attributeParameters .= "<div name='attributeParametersCheckbox' id='attributeParametersCheckbox'>\n"; |
311
|
|
|
$attributeParameters .= $parameterButtonOption . "\n"; |
312
|
|
|
$attributeParameters .= "</div>\n"; |
313
|
|
|
|
314
|
|
|
// Les listes déroulantes |
315
|
|
|
$attributeParameters .= "<div name='attributeParametersSelect' id='attributeParametersSelect'>\n"; |
316
|
|
|
$defaultValue1 = OLEDRION_ATTRIBUTE_SELECT_VISIBLE_OPTIONS; |
317
|
|
|
$defaultValue2 = OLEDRION_ATTRIBUTE_SELECT_MULTIPLE; |
318
|
|
|
if ($edit) { |
319
|
|
|
if ($item->getVar('attribute_type') == OLEDRION_ATTRIBUTE_SELECT) { |
320
|
|
|
$defaultValue1 = $item->getVar('attribute_option1', 'e'); |
321
|
|
|
$defaultValue2 = $item->getVar('attribute_option2', 'e'); |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
$checked1 = $checked2 = ''; |
325
|
|
|
if ($defaultValue2 == 1) { |
326
|
|
|
$checked1 = "checked='checked'"; |
327
|
|
|
} else { |
328
|
|
|
$checked2 = "checked='checked'"; |
329
|
|
|
} |
330
|
|
|
$attributeParameters .= _AM_OLEDRION_ATTRIBUTE_VISIBLE_OPTIONS . " <input type='text' name='option2' id='option2' size='3' maxlength='3' value='$defaultValue1' />"; |
331
|
|
|
$attributeParameters .= "<br />" . _AM_OLEDRION_ATTRIBUTE_MULTI_OPTIONS . " <input type='radio' name='option3' id='option3' value='1' $checked1 />" . _YES . " <input type='radio' name='option3' id='option3' value='0' $checked2 />" . _NO; |
332
|
|
|
$attributeParameters .= "</div>\n"; |
333
|
|
|
// **** |
334
|
|
|
$attributeParameters .= "</div>"; |
335
|
|
|
$sform->addElement(new XoopsFormLabel(_AM_OLEDRION_ATTRIBUTE_PARAMETERS, $attributeParameters)); |
336
|
|
|
// ******************************************* |
337
|
|
|
|
338
|
|
|
// Attribut requis |
339
|
|
|
$sform->addElement(new XoopsFormRadioYN(_AM_OLEDRION_ATTRIBUTE_REQUIRED, 'attribute_mandatory', $item->getVar('attribute_mandatory')), true); |
340
|
|
|
|
341
|
|
|
// Les options |
342
|
|
|
$divContent = "<div class='ajaxOptions' id='ajaxOptions'></div>"; |
343
|
|
|
$ajaxOptions = new XoopsFormLabel(_AM_OLEDRION_ATTRIBUTE_OPTIONS, $divContent); |
344
|
|
|
$sform->addElement($ajaxOptions, false); |
345
|
|
|
|
346
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
347
|
|
|
$submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
348
|
|
|
$button_tray->addElement($submit_btn); |
349
|
|
|
$sform->addElement($button_tray); |
350
|
|
|
oledrion_utils::callJavascriptFile('attributes.js', false, true); |
351
|
|
|
$sform = oledrion_utils::formMarkRequiredFields($sform); |
352
|
|
|
$sform->display(); |
353
|
|
|
include_once 'admin_footer.php'; |
354
|
|
|
break; |
355
|
|
|
|
356
|
|
|
// **************************************************************************************************************** |
357
|
|
|
case 'saveedit': // Sauvegarde de l'option |
358
|
|
|
// **************************************************************************************************************** |
359
|
|
|
xoops_cp_header(); |
360
|
|
|
$id = isset($_POST['attribute_id']) ? intval($_POST['attribute_id']) : 0; |
361
|
|
|
if (!empty($id)) { |
362
|
|
|
$edit = true; |
363
|
|
|
$item = $oledrion_handlers->h_oledrion_attributes->get($id); |
364
|
|
|
if (!is_object($item)) { |
365
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
366
|
|
|
} |
367
|
|
|
$item->unsetNew(); |
368
|
|
|
} else { |
369
|
|
|
$item = $oledrion_handlers->h_oledrion_attributes->create(true); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
$item->setVars($_POST); |
373
|
|
|
$attribute_type = isset($_POST['attribute_type']) ? intval($_POST['attribute_type']) : 0; |
374
|
|
|
if ($attribute_type == OLEDRION_ATTRIBUTE_SELECT) { // Liste déroulante |
375
|
|
|
$item->setVar('attribute_option1', intval($_POST['option2'])); |
376
|
|
|
$item->setVar('attribute_option2', intval($_POST['option3'])); |
377
|
|
|
} else { // Bouton radio ou case à cocher |
378
|
|
|
$item->setVar('attribute_option1', intval($_POST['option1'])); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
$default = isset($_POST['default']) ? intval($_POST['default']) : 0; |
382
|
|
|
$optionsCount = isset($_POST['optionsCount']) ? intval($_POST['optionsCount']) : 0; |
383
|
|
|
$item->resetOptions(); |
384
|
|
|
for ($i = 0; $i < $optionsCount; $i++) { |
385
|
|
|
$name = $value = $price = $stock = ''; |
386
|
|
|
$name = isset($_POST['name' . $i]) ? $_POST['name' . $i] : ''; |
387
|
|
|
$value = isset($_POST['value' . $i]) ? $_POST['value' . $i] : ''; |
388
|
|
|
$price = isset($_POST['price' . $i]) ? $_POST['price' . $i] : ''; |
389
|
|
|
$stock = isset($_POST['stock' . $i]) ? $_POST['stock' . $i] : ''; |
390
|
|
|
$item->addOption($name, $value, $price, $stock); |
391
|
|
|
if ($i == $default) { |
392
|
|
|
$item->setVar('attribute_default_value', $value); |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
$res = $oledrion_handlers->h_oledrion_attributes->insert($item); |
397
|
|
|
if ($res) { |
398
|
|
|
oledrion_utils::updateCache(); |
399
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $operation, 2); |
400
|
|
|
} else { |
401
|
|
|
oledrion_utils::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $operation, 5); |
402
|
|
|
} |
403
|
|
|
break; |
404
|
|
|
|
405
|
|
|
// **************************************************************************************************************** |
406
|
|
|
case 'ajaxoptions': // Traitement en Ajax des options |
407
|
|
|
// **************************************************************************************************************** |
408
|
|
|
if (!isset($xoopsUser) || !is_object($xoopsUser)) { |
409
|
|
|
exit; |
410
|
|
|
} |
411
|
|
|
if (!oledrion_utils::isAdmin()) { |
412
|
|
|
exit; |
413
|
|
|
} |
414
|
|
|
error_reporting(0); |
415
|
|
|
@$xoopsLogger->activated = false; |
|
|
|
|
416
|
|
|
$attribute_id = isset($_POST['attribute_id']) ? intval($_POST['attribute_id']) : 0; |
417
|
|
|
$content = $class = ''; |
418
|
|
|
$attribute = null; |
419
|
|
|
$counter = 0; |
420
|
|
|
$options = array(); |
421
|
|
|
$delete = _OLEDRION_DELETE; |
422
|
|
|
$span = 4; |
423
|
|
|
require_once OLEDRION_CLASS_PATH . 'oledrion_attributes.php'; |
424
|
|
|
|
425
|
|
|
if (!isset($_SESSION['oledrion_attribute'])) { |
426
|
|
|
if ($attribute_id == 0) { // Création, rajouter une zone |
427
|
|
|
$attribute = $oledrion_handlers->h_oledrion_attributes->create(true); |
428
|
|
|
} else { |
429
|
|
|
$attribute = $oledrion_handlers->h_oledrion_attributes->get($attribute_id); |
430
|
|
|
if (!is_object($attribute)) { |
431
|
|
|
return null; |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
$_SESSION['oledrion_attribute'] = serialize($attribute); |
435
|
|
|
} else { |
436
|
|
|
$attribute = unserialize($_SESSION['oledrion_attribute']); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
if (isset($_POST['formcontent'])) { // Traitement du contenu actuel |
440
|
|
|
$data = array(); |
441
|
|
|
parse_str(urldecode($_POST['formcontent']), $data); |
442
|
|
|
$optionsCount = isset($data['optionsCount']) ? intval($data['optionsCount']) : 0; |
443
|
|
|
for ($i = 0; $i < $optionsCount; $i++) { |
444
|
|
|
$name = $value = $price = $stock = ''; |
445
|
|
|
$name = isset($data['name' . $i]) ? $data['name' . $i] : ''; |
446
|
|
|
$value = isset($data['value' . $i]) ? $data['value' . $i] : ''; |
447
|
|
|
$price = isset($data['price' . $i]) ? $data['price' . $i] : ''; |
448
|
|
|
$stock = isset($data['stock' . $i]) ? $data['stock' . $i] : ''; |
449
|
|
|
$attribute->setOptionValue($i, $name, $value, $price, $stock); |
450
|
|
|
} |
451
|
|
|
if (isset($data['default'])) { |
452
|
|
|
$defaultIndex = intval($data['default']); |
453
|
|
|
$defaultValue = isset($data['value' . $defaultIndex]) ? $data['value' . $defaultIndex] : ''; |
454
|
|
|
$attribute->setVar('attribute_default_value', $defaultValue); |
455
|
|
|
unset($defaultValue); |
456
|
|
|
} |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
if (isset($_POST['subaction'])) { |
460
|
|
|
switch (xoops_trim(strtolower($_POST['subaction']))) { |
461
|
|
View Code Duplication |
case 'delete': // Suppression d'une option de l'attribut |
|
|
|
|
462
|
|
|
$option = isset($_POST['option']) ? intval($_POST['option']) : false; |
463
|
|
|
if ($option !== false) { |
464
|
|
|
$attribute->deleteOption($option); |
465
|
|
|
} |
466
|
|
|
break; |
467
|
|
|
|
468
|
|
|
case 'add': // Ajout d'une option vide (à la fin) |
469
|
|
|
$attribute->addEmptyOption(); |
470
|
|
|
break; |
471
|
|
|
|
472
|
|
View Code Duplication |
case 'up': // Déplacement d'une option vers le haut |
|
|
|
|
473
|
|
|
$option = isset($_POST['option']) ? intval($_POST['option']) : false; |
474
|
|
|
if ($option !== false) { |
475
|
|
|
$attribute->moveOptionUp($option); |
476
|
|
|
} |
477
|
|
|
break; |
478
|
|
|
|
479
|
|
View Code Duplication |
case 'down': // Déplacement d'une option vers le haut |
|
|
|
|
480
|
|
|
$option = isset($_POST['option']) ? intval($_POST['option']) : false; |
481
|
|
|
if ($option !== false) { |
482
|
|
|
$attribute->moveOptionDown($option); |
483
|
|
|
} |
484
|
|
|
break; |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
$_SESSION['oledrion_attribute'] = serialize($attribute); |
488
|
|
|
|
489
|
|
|
$content .= "<table border='0'>\n"; |
490
|
|
|
$content .= "<tr>\n"; |
491
|
|
|
$content .= "<th align='center'>" . _AM_OLEDRION_ATTRIBUTE_DEFAULT_VALUE . "</th><th align='center'>" . _AM_OLEDRION_ATTRIBUTE_TITLE . "</th><th align='center'>" . _AM_OLEDRION_ATTRIBUTE_VALUE . "</th>"; |
492
|
|
|
if (oledrion_utils::getModuleOption('use_price')) { |
493
|
|
|
$content .= "<th align='center'>" . _AM_OLEDRION_ATTRIBUTE_PRICE . "</th>"; |
494
|
|
|
$span++; |
495
|
|
|
} |
496
|
|
|
if (oledrion_utils::getModuleOption('attributes_stocks')) { |
497
|
|
|
$content .= "<th align='center'>" . _AM_OLEDRION_ATTRIBUTE_STOCK . "</th>"; |
498
|
|
|
$span++; |
499
|
|
|
} |
500
|
|
|
$content .= "<th align='center'>" . _AM_OLEDRION_ACTION . "</th>\n"; |
501
|
|
|
$content .= "</tr>\n"; |
502
|
|
|
|
503
|
|
|
$up = _AM_OLEDRION_ATTRIBUTE_MOVE_UP; |
504
|
|
|
$down = _AM_OLEDRION_ATTRIBUTE_MOVE_DOWN; |
505
|
|
|
$defaultValue = xoops_trim($attribute->getVar('attribute_default_value', 'e')); |
506
|
|
|
|
507
|
|
|
$options = $attribute->getAttributeOptions('e'); |
508
|
|
|
$optionsCount = count($options); |
509
|
|
|
|
510
|
|
|
if ($optionsCount > 0) { |
511
|
|
|
foreach ($options as $option) { |
512
|
|
|
$class = ($class == 'even') ? 'odd' : 'even'; |
513
|
|
|
$content .= "<tr class='" . $class . "'>\n"; |
514
|
|
|
$checked = ''; |
515
|
|
|
if ($option['value'] == $defaultValue) { |
516
|
|
|
$checked = "checked = 'checked' "; |
517
|
|
|
} |
518
|
|
|
$content .= "<td align='center'><input type='radio' name='default' id='default' value='$counter' $checked/></td>\n"; |
519
|
|
|
$content .= "<td align='center'><input type='text' name='name$counter' id='names$counter' size='15' maxlength='255' value='" . $option['name'] . "' /></td>\n"; |
520
|
|
|
$content .= "<td align='center'><input type='text' name='value$counter' id='value$counter' size='15' maxlength='255' value='" . $option['value'] . "' /></td>\n"; |
521
|
|
|
if (oledrion_utils::getModuleOption('use_price')) { |
522
|
|
|
$content .= "<td align='center'><input type='text' name='price$counter' id='price$counter' size='15' maxlength='10' value='" . $option['price'] . "' /></td>\n"; |
523
|
|
|
} |
524
|
|
|
if (oledrion_utils::getModuleOption('attributes_stocks')) { |
525
|
|
|
$content .= "<td align='center'><input type='text' name='stock$counter' id='stock$counter' size='15' maxlength='10' value='" . $option['stock'] . "' /></td>\n"; |
526
|
|
|
} |
527
|
|
|
// Les actions |
528
|
|
|
$content .= "<td align='center'>"; |
529
|
|
|
// Suppression |
530
|
|
|
$content .= "<img class='btnremove' alt='$delete' title='$delete' style='border: 0; cursor:pointer;' name='btnremove-$counter' id='btnremove-$counter' src='" . OLEDRION_IMAGES_URL . "smalldelete.png' />"; |
531
|
|
View Code Duplication |
if ($counter > 0) { // Up |
|
|
|
|
532
|
|
|
$content .= "<img class='btnUp' alt='$up' title='$up' style='border: 0; cursor:pointer;' name='btnUp-$counter' id='btnUp-$counter' src='" . OLEDRION_IMAGES_URL . "smallup.png' />"; |
533
|
|
|
} else { |
534
|
|
|
$content .= "<img src='" . OLEDRION_IMAGES_URL . "blankholder.png' />"; |
535
|
|
|
} |
536
|
|
View Code Duplication |
if ($counter < $optionsCount - 1) { // Down |
|
|
|
|
537
|
|
|
$content .= "<img class='btnDown' alt='$down' title='$down' style='border: 0; cursor:pointer;' name='btnDown-$counter' id='btnDown-$counter' src='" . OLEDRION_IMAGES_URL . "smalldown.png' />"; |
538
|
|
|
} else { |
539
|
|
|
$content .= "<img src='" . OLEDRION_IMAGES_URL . "blankholder.png' />"; |
540
|
|
|
} |
541
|
|
|
$content .= "</td>\n"; |
542
|
|
|
$content .= "</tr>\n"; |
543
|
|
|
$counter++; |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
$class = ($class == 'even') ? 'odd' : 'even'; |
547
|
|
|
$content .= "<tr class='" . $class . "'>\n"; |
548
|
|
|
$content .= "<td colspan='$span' align='center'><input type='button'' name='bntAdd'' id='bntAdd' value='" . _AM_OLEDRION_ATTRIBUTE_ADD_OPTION . "' /></td>\n"; |
549
|
|
|
$content .= "</tr>\n"; |
550
|
|
|
|
551
|
|
|
$content .= "</table>\n"; |
552
|
|
|
$content .= "<input type='hidden' name='optionsCount' id='optionsCount' value='$counter' />\n"; |
553
|
|
|
echo $content; |
554
|
|
|
exit; |
555
|
|
|
break; |
556
|
|
|
} |
557
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.