1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// ------------------------------------------------------------------------ // |
3
|
|
|
// BOOKSHOP - MODULE FOR XOOPS 2 // |
4
|
|
|
// Copyright (c) 2007, 2008 Instant Zero // |
5
|
|
|
// <http://www.instant-zero.com/> // |
6
|
|
|
// ------------------------------------------------------------------------- // |
7
|
|
|
// This program is free software; you can redistribute it and/or modify // |
8
|
|
|
// it under the terms of the GNU General Public License as published by // |
9
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
10
|
|
|
// (at your option) any later version. // |
11
|
|
|
// // |
12
|
|
|
// You may not change or alter any portion of this comment or credits // |
13
|
|
|
// of supporting developers from this source code or any supporting // |
14
|
|
|
// source code which is considered copyrighted (c) material of the // |
15
|
|
|
// original comment or credit authors. // |
16
|
|
|
// // |
17
|
|
|
// This program is distributed in the hope that it will be useful, // |
18
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
19
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
20
|
|
|
// GNU General Public License for more details. // |
21
|
|
|
// // |
22
|
|
|
// You should have received a copy of the GNU General Public License // |
23
|
|
|
// along with this program; if not, write to the Free Software // |
24
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
25
|
|
|
// ------------------------------------------------------------------------ // |
26
|
|
|
|
27
|
|
|
include_once __DIR__ . '/../../../include/cp_header.php'; |
28
|
|
|
include_once __DIR__ . '/../include/common.php'; |
29
|
|
|
|
30
|
|
|
include_once __DIR__ . '/admin_header.php'; |
31
|
|
|
|
32
|
|
|
include_once BOOKSHOP_PATH . 'admin/functions.php'; |
33
|
|
|
include_once XOOPS_ROOT_PATH . '/class/tree.php'; |
34
|
|
|
include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
35
|
|
|
include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
36
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
37
|
|
|
|
38
|
|
|
$op = 'default'; |
39
|
|
View Code Duplication |
if (isset($_POST['op'])) { |
|
|
|
|
40
|
|
|
$op = $_POST['op']; |
41
|
|
|
} else { |
42
|
|
|
if (isset($_GET['op'])) { |
43
|
|
|
$op = $_GET['op']; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
$destname = ''; |
47
|
|
|
|
48
|
|
|
// TODO: TVA par d�faut, Langue par d�faut |
49
|
|
|
|
50
|
|
|
// Mise � jour automatique pour ajouter les nouveaux champs |
51
|
|
|
if (!booksop_FieldExists('book_recommended', $xoopsDB->prefix('bookshop_books'))) { |
52
|
|
|
booksop_AddField('`book_recommended` DATE NOT NULL', $xoopsDB->prefix('bookshop_books')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
if (!booksop_FieldExists('book_metakeywords', $xoopsDB->prefix('bookshop_books'))) { |
|
|
|
|
56
|
|
|
booksop_AddField('`book_metakeywords` VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('bookshop_books')); |
57
|
|
|
booksop_AddField('`book_metadescription` VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('bookshop_books')); |
58
|
|
|
booksop_AddField('`book_metatitle` VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('bookshop_books')); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
if (!booksop_FieldExists('cat_metatitle', $xoopsDB->prefix('bookshop_cat'))) { |
|
|
|
|
62
|
|
|
booksop_AddField('`cat_metakeywords` VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('bookshop_cat')); |
63
|
|
|
booksop_AddField('`cat_metadescription` VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('bookshop_cat')); |
64
|
|
|
booksop_AddField('`cat_metatitle` VARCHAR( 255 ) NOT NULL', $xoopsDB->prefix('bookshop_cat')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (!booksop_FieldExists('disc_shipping_amount', $xoopsDB->prefix('bookshop_discounts'))) { |
68
|
|
|
booksop_AddField('`disc_shipping_amount` DOUBLE( 7, 2 ) NOT NULL', $xoopsDB->prefix('bookshop_discounts')); |
69
|
|
|
booksop_AddField('`disc_shipping_amount_next` DOUBLE( 7, 2 ) NOT NULL', $xoopsDB->prefix('bookshop_discounts')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (!booksop_FieldExists('disc_qty_criteria', $xoopsDB->prefix('bookshop_discounts'))) { |
73
|
|
|
booksop_AddField('`disc_qty_criteria` tinyint(1) unsigned NOT NULL', $xoopsDB->prefix('bookshop_discounts')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
if (!booksop_FieldExists('disc_qty_value', $xoopsDB->prefix('bookshop_discounts'))) { |
77
|
|
|
booksop_AddField('`disc_qty_value` mediumint(8) unsigned NOT NULL', $xoopsDB->prefix('bookshop_discounts')); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param $indice |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
function bookshop_upload($indice) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
global $destname; |
|
|
|
|
88
|
|
|
if (isset($_POST['xoops_upload_file'])) { |
89
|
|
|
include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
90
|
|
|
$fldname = $_FILES[$_POST['xoops_upload_file'][$indice]]; |
91
|
|
|
$fldname = get_magic_quotes_gpc() ? stripslashes($fldname['name']) : $fldname['name']; |
92
|
|
|
if (xoops_trim($fldname != '')) { |
93
|
|
|
$dstpath = XOOPS_UPLOAD_PATH; |
94
|
|
|
$destname = bookshop_createUploadName($dstpath, $fldname, true); |
95
|
|
|
|
96
|
|
|
$permittedtypes = explode("\n", str_replace("\r", '', bookshop_getmoduleoption('mimetypes'))); |
97
|
|
|
array_walk($permittedtypes, 'trim'); |
98
|
|
|
|
99
|
|
|
$uploader = new XoopsMediaUploader($dstpath, $permittedtypes, bookshop_getmoduleoption('maxuploadsize')); |
100
|
|
|
$uploader->setTargetFileName($destname); |
101
|
|
|
if ($uploader->fetchMedia($_POST['xoops_upload_file'][$indice])) { |
102
|
|
|
if ($uploader->upload()) { |
103
|
|
|
return true; |
104
|
|
|
} else { |
105
|
|
|
echo _AM_BOOKSHOP_ERROR_3 . $uploader->getErrors(); |
106
|
|
|
} |
107
|
|
|
} else { |
108
|
|
|
echo $uploader->getErrors(); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return false; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
function show_footer() |
117
|
|
|
{ |
118
|
|
|
echo "<br><br><div align='center'><a href='http://www.instant-zero.com' target='_blank'><img src='../assets/images/instantzero.gif'></a></div>"; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$limit = bookshop_getmoduleoption('items_count'); // Nombre maximum d'�l�ments � afficher dans l'admin |
122
|
|
|
$baseurl = BOOKSHOP_URL . 'admin/' . basename(__FILE__); // URL de ce script |
123
|
|
|
$conf_msg = bookshop_JavascriptLinkConfirm(_AM_BOOKSHOP_CONF_DELITEM); |
124
|
|
|
$manual_meta = bookshop_getmoduleoption('manual_meta'); |
125
|
|
|
|
126
|
|
|
global $xoopsConfig; |
|
|
|
|
127
|
|
View Code Duplication |
if (file_exists(BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/modinfo.php')) { |
|
|
|
|
128
|
|
|
include_once BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/modinfo.php'; |
129
|
|
|
} else { |
130
|
|
|
include_once BOOKSHOP_PATH . 'language/english/modinfo.php'; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
View Code Duplication |
if (file_exists(BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/main.php')) { |
|
|
|
|
134
|
|
|
include_once BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/main.php'; |
135
|
|
|
} else { |
136
|
|
|
include_once BOOKSHOP_PATH . 'language/english/main.php'; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
// ****************************************************************************************************************************************** |
140
|
|
|
// **** Main ******************************************************************************************************************************** |
141
|
|
|
// ****************************************************************************************************************************************** |
142
|
|
|
switch ($op) { |
143
|
|
|
|
144
|
|
|
// **************************************************************************************************************** |
145
|
|
|
case 'texts': // Gestion de la page d'index |
146
|
|
|
// **************************************************************************************************************** |
147
|
|
|
xoops_cp_header(); |
148
|
|
|
// bookshop_adminMenu(9); |
|
|
|
|
149
|
|
|
$indexAdmin = new ModuleAdmin(); |
150
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=texts'); |
151
|
|
|
|
152
|
|
|
include_once BOOKSHOP_PATH . 'class/registryfile.php'; |
153
|
|
|
$registry = new bookshop_registryfile(); |
154
|
|
|
|
155
|
|
|
$sform = new XoopsThemeForm(_MI_BOOKSHOP_ADMENU8, 'frmatxt', $baseurl); |
156
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'savetexts')); |
157
|
|
|
$editor1 = bookshop_getWysiwygForm(_AM_BOOKSHOP_INDEX_PAGE, 'welcome1', $registry->getfile('bookshop_index.txt'), 5, 60, 'hometext1_hidden'); |
158
|
|
|
if ($editor1) { |
159
|
|
|
$sform->addElement($editor1, false); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$editor2 = bookshop_getWysiwygForm(_BOOKSHOP_CGV, 'welcome2', $registry->getfile('bookshop_cgv.txt'), 5, 60, 'hometext2_hidden'); |
163
|
|
|
if ($editor2) { |
164
|
|
|
$sform->addElement($editor2, false); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$editor3 = bookshop_getWysiwygForm(_AM_BOOKSHOP_RECOMM_TEXT, 'welcome3', $registry->getfile('bookshop_recomm.txt'), 5, 60, 'hometext3_hidden'); |
168
|
|
|
if ($editor3) { |
169
|
|
|
$sform->addElement($editor3, false); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
173
|
|
|
$submit_btn = new XoopsFormButton('', 'post', _AM_BOOKSHOP_MODIFY, 'submit'); |
174
|
|
|
$button_tray->addElement($submit_btn); |
175
|
|
|
$sform->addElement($button_tray); |
176
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
177
|
|
|
$sform->display(); |
178
|
|
|
break; |
179
|
|
|
|
180
|
|
|
// **************************************************************************************************************** |
181
|
|
|
case 'savetexts': // Sauvegarde des textes d'accueil ******************************************************** |
182
|
|
|
// **************************************************************************************************************** |
183
|
|
|
include_once BOOKSHOP_PATH . 'class/registryfile.php'; |
184
|
|
|
$registry = new bookshop_registryfile(); |
185
|
|
|
$registry->savefile($myts->stripSlashesGPC($_POST['welcome1']), 'bookshop_index.txt'); |
186
|
|
|
$registry->savefile($myts->stripSlashesGPC($_POST['welcome2']), 'bookshop_cgv.txt'); |
187
|
|
|
$registry->savefile($myts->stripSlashesGPC($_POST['welcome3']), 'bookshop_recomm.txt'); |
188
|
|
|
bookshop_updateCache(); |
189
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl, 2); |
190
|
|
|
break; |
191
|
|
|
|
192
|
|
|
// **************************************************************************************************************** |
193
|
|
|
// case 'xoops'; // Publicit� |
|
|
|
|
194
|
|
|
// **************************************************************************************************************** |
195
|
|
|
/* |
|
|
|
|
196
|
|
|
xoops_cp_header(); |
197
|
|
|
// bookshop_adminMenu(11); |
198
|
|
|
echo "<iframe src='http://xoops.org/modules/contact/' width='100%' height='600' frameborder='0'></iframe>"; |
199
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
200
|
|
|
break; |
201
|
|
|
*/ |
202
|
|
|
// **************************************************************************************************************** |
203
|
|
View Code Duplication |
case 'lang': // Gestion des langues |
|
|
|
|
204
|
|
|
// **************************************************************************************************************** |
205
|
|
|
xoops_cp_header(); |
206
|
|
|
// bookshop_adminMenu(1); |
|
|
|
|
207
|
|
|
$indexAdmin = new ModuleAdmin(); |
208
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=lang'); |
209
|
|
|
|
210
|
|
|
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
211
|
|
|
$tbl_lang = array(); |
212
|
|
|
echo "<form method='post' action='$baseurl' name='frmaddlang' id='frmaddlang'><input type='hidden' name='op' id='op' value='addlang' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form>"; |
213
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU0, 4); |
214
|
|
|
$tbl_lang = $h_bookshop_lang->GetAllLang($start, $limit); |
215
|
|
|
$class = ''; |
216
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
217
|
|
|
echo "<tr><th align='center'>" . _AM_BOOKSHOP_ID . "</th><th align='center'>" . _BOOKSHOP_LANG . "</th><th align='center'>" . _AM_BOOKSHOP_ACTION . '</th></tr>'; |
218
|
|
|
foreach ($tbl_lang as $item) { |
219
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
220
|
|
|
$action_edit = "<a href='$baseurl?op=editlang&id=" . $item->getVar('lang_id') . "' title='" . _BOOKSHOP_EDIT . "'>" . $icones['edit'] . '</a>'; |
221
|
|
|
$action_delete = "<a href='$baseurl?op=deletelang&id=" . $item->getVar('lang_id') . "' title='" . _BOOKSHOP_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
222
|
|
|
echo "<tr class='" . $class . "'>\n"; |
223
|
|
|
echo '<td>' . $item->getVar('lang_id') . "</td><td align='center'>" . $item->getVar('lang_lang') . "</td><td align='center'>" . $action_edit . ' ' . $action_delete . "</td>\n"; |
224
|
|
|
echo "<tr>\n"; |
225
|
|
|
} |
226
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
227
|
|
|
echo "<tr class='" . $class . "'>\n"; |
228
|
|
|
echo "<td colspan='3' align='center'><form method='post' action='$baseurl' name='frmaddlang' id='frmaddlang'><input type='hidden' name='op' id='op' value='addlang' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form></td>\n"; |
229
|
|
|
echo "</tr>\n"; |
230
|
|
|
echo '</table>'; |
231
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
232
|
|
|
break; |
233
|
|
|
|
234
|
|
|
// **************************************************************************************************************** |
235
|
|
|
case 'addlang': // Ajout d'une langue |
236
|
|
View Code Duplication |
case 'editlang': // Edition d'une langue |
|
|
|
|
237
|
|
|
// **************************************************************************************************************** |
238
|
|
|
xoops_cp_header(); |
239
|
|
|
// bookshop_adminMenu(1); |
|
|
|
|
240
|
|
|
$indexAdmin = new ModuleAdmin(); |
241
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=addlang'); |
242
|
|
|
if ($op === 'editlang') { |
243
|
|
|
$title = _AM_BOOKSHOP_EDIT_LANG; |
244
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
245
|
|
|
if (empty($id)) { |
246
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
247
|
|
|
} |
248
|
|
|
// Item exits ? |
249
|
|
|
$item = null; |
250
|
|
|
$item = $h_bookshop_lang->get($id); |
251
|
|
|
if (!is_object($item)) { |
252
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
253
|
|
|
} |
254
|
|
|
$edit = true; |
255
|
|
|
$label_submit = _AM_BOOKSHOP_MODIFY; |
256
|
|
|
} else { |
257
|
|
|
$title = _AM_BOOKSHOP_ADD_LANG; |
258
|
|
|
$item = $h_bookshop_lang->create(true); |
259
|
|
|
$label_submit = _AM_BOOKSHOP_ADD; |
260
|
|
|
$edit = false; |
261
|
|
|
} |
262
|
|
|
$sform = new XoopsThemeForm($title, 'frmaddlang', $baseurl); |
263
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'saveeditlang')); |
264
|
|
|
$sform->addElement(new XoopsFormHidden('lang_id', $item->getVar('lang_id'))); |
265
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_LANG, 'lang_lang', 50, 150, $item->getVar('lang_lang', 'e')), true); |
266
|
|
|
|
267
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
268
|
|
|
$submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
269
|
|
|
$button_tray->addElement($submit_btn); |
270
|
|
|
$sform->addElement($button_tray); |
271
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
272
|
|
|
$sform->display(); |
273
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
274
|
|
|
break; |
275
|
|
|
|
276
|
|
|
// **************************************************************************************************************** |
277
|
|
View Code Duplication |
case 'saveeditlang': // Sauvegarde d'une langue (�dition et ajout) |
|
|
|
|
278
|
|
|
// **************************************************************************************************************** |
279
|
|
|
xoops_cp_header(); |
280
|
|
|
$id = isset($_POST['lang_id']) ? (int)$_POST['lang_id'] : 0; |
281
|
|
|
if (!empty($id)) { |
282
|
|
|
$edit = true; |
283
|
|
|
$item = $h_bookshop_lang->get($id); |
284
|
|
|
if (!is_object($item)) { |
285
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
286
|
|
|
} |
287
|
|
|
$item->unsetNew(); |
288
|
|
|
} else { |
289
|
|
|
$item = $h_bookshop_lang->create(true); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
$item->setVars($_POST); |
293
|
|
|
$res = $h_bookshop_lang->insert($item); |
294
|
|
|
if ($res) { |
295
|
|
|
bookshop_updateCache(); |
296
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=lang', 2); |
297
|
|
|
} else { |
298
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=lang', 5); |
299
|
|
|
} |
300
|
|
|
break; |
301
|
|
|
|
302
|
|
|
// **************************************************************************************************************** |
303
|
|
|
case 'deletelang': // Suppression d'une langue |
304
|
|
|
// **************************************************************************************************************** |
305
|
|
|
xoops_cp_header(); |
306
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
307
|
|
|
if (empty($id)) { |
308
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
309
|
|
|
} |
310
|
|
|
// On v�rifie que cette langue n'est pas utilis�e par un livre |
311
|
|
|
$criteria = new Criteria('book_lang_id', $id, '='); |
312
|
|
|
$cnt = $h_bookshop_books->getCount($criteria); |
313
|
|
|
if ($cnt == 0) { |
314
|
|
|
$item = null; |
315
|
|
|
$item = $h_bookshop_lang->get($id); |
316
|
|
View Code Duplication |
if (is_object($item)) { |
|
|
|
|
317
|
|
|
$res = $h_bookshop_lang->delete($item, true); |
318
|
|
|
if ($res) { |
319
|
|
|
bookshop_updateCache(); |
320
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=lang', 2); |
321
|
|
|
} else { |
322
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=lang', 5); |
323
|
|
|
} |
324
|
|
|
} else { |
325
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=lang', 5); |
326
|
|
|
} |
327
|
|
|
} else { |
328
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_6, $baseurl . '?op=lang', 5); |
329
|
|
|
} |
330
|
|
|
break; |
331
|
|
|
|
332
|
|
|
// **************************************************************************************************************** |
333
|
|
View Code Duplication |
case 'vat': // Gestion des TVA |
|
|
|
|
334
|
|
|
// **************************************************************************************************************** |
335
|
|
|
xoops_cp_header(); |
336
|
|
|
// bookshop_adminMenu(2); |
|
|
|
|
337
|
|
|
$indexAdmin = new ModuleAdmin(); |
338
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=vat'); |
339
|
|
|
|
340
|
|
|
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
341
|
|
|
$tbl_vat = array(); |
342
|
|
|
echo "<form method='post' action='$baseurl' name='frmaddvat' id='frmaddvat'><input type='hidden' name='op' id='op' value='addvat' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form>"; |
343
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU1, 4); |
344
|
|
|
$tbl_vat = $h_bookshop_vat->GetAllVats($start, $limit); |
345
|
|
|
$class = ''; |
346
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
347
|
|
|
echo "<tr><th align='center'>" . _AM_BOOKSHOP_ID . "</th><th align='center'>" . _AM_BOOKSHOP_RATE . "</th><th align='center'>" . _AM_BOOKSHOP_ACTION . '</th></tr>'; |
348
|
|
|
foreach ($tbl_vat as $item) { |
349
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
350
|
|
|
$action_edit = "<a href='$baseurl?op=editvat&id=" . $item->getVar('vat_id') . "' title='" . _BOOKSHOP_EDIT . "'>" . $icones['edit'] . '</a>'; |
351
|
|
|
$action_delete = "<a href='$baseurl?op=deletevat&id=" . $item->getVar('vat_id') . "' title='" . _BOOKSHOP_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
352
|
|
|
echo "<tr class='" . $class . "'>\n"; |
353
|
|
|
echo '<td>' . $item->getVar('vat_id') . "</td><td align='right'>" . $item->getVar('vat_rate') . "</td><td align='center'>" . $action_edit . ' ' . $action_delete . "</td>\n"; |
354
|
|
|
echo "<tr>\n"; |
355
|
|
|
} |
356
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
357
|
|
|
echo "<tr class='" . $class . "'>\n"; |
358
|
|
|
echo "<td colspan='3' align='center'><form method='post' action='$baseurl' name='frmaddvat' id='frmaddvat'><input type='hidden' name='op' id='op' value='addvat' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form></td>\n"; |
359
|
|
|
echo "</tr>\n"; |
360
|
|
|
echo '</table>'; |
361
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
362
|
|
|
break; |
363
|
|
|
|
364
|
|
|
// **************************************************************************************************************** |
365
|
|
View Code Duplication |
case 'saveeditvat': // Sauvegarde d'une TVA |
|
|
|
|
366
|
|
|
// **************************************************************************************************************** |
367
|
|
|
xoops_cp_header(); |
368
|
|
|
$id = isset($_POST['vat_id']) ? (int)$_POST['vat_id'] : 0; |
369
|
|
|
if (!empty($id)) { |
370
|
|
|
$edit = true; |
371
|
|
|
$item = $h_bookshop_vat->get($id); |
372
|
|
|
if (!is_object($item)) { |
373
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
374
|
|
|
} |
375
|
|
|
$item->unsetNew(); |
376
|
|
|
} else { |
377
|
|
|
$item = $h_bookshop_vat->create(true); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
$item->setVars($_POST); |
381
|
|
|
$res = $h_bookshop_vat->insert($item); |
382
|
|
|
if ($res) { |
383
|
|
|
bookshop_updateCache(); |
384
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=vat', 2); |
385
|
|
|
} else { |
386
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=vat', 5); |
387
|
|
|
} |
388
|
|
|
break; |
389
|
|
|
|
390
|
|
|
// **************************************************************************************************************** |
391
|
|
View Code Duplication |
case 'deletevat': // Suppression d'une TVA |
|
|
|
|
392
|
|
|
// **************************************************************************************************************** |
393
|
|
|
xoops_cp_header(); |
394
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
395
|
|
|
if (empty($id)) { |
396
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
397
|
|
|
} |
398
|
|
|
// On v�rifie que cette TVA n'est pas utilis�e par un livre |
399
|
|
|
$criteria = new Criteria('book_vat_id', $id, '='); |
400
|
|
|
$cnt = $h_bookshop_books->getCount($criteria); |
401
|
|
|
if ($cnt == 0) { |
402
|
|
|
$item = null; |
403
|
|
|
$item = $h_bookshop_vat->get($id); |
404
|
|
|
if (is_object($item)) { |
405
|
|
|
$critere = new Criteria('vat_id', $id, '='); |
406
|
|
|
$res = $h_bookshop_vat->deleteAll($critere); |
407
|
|
|
if ($res) { |
408
|
|
|
bookshop_updateCache(); |
409
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=vat', 2); |
410
|
|
|
} else { |
411
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=vat', 5); |
412
|
|
|
} |
413
|
|
|
} else { |
414
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=vat', 5); |
415
|
|
|
} |
416
|
|
|
} else { |
417
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_2, $baseurl . '?op=vat', 5); |
418
|
|
|
} |
419
|
|
|
break; |
420
|
|
|
|
421
|
|
|
// **************************************************************************************************************** |
422
|
|
|
case 'addvat': // Ajout d'une TVA |
423
|
|
View Code Duplication |
case 'editvat': // Edition d'une TVA |
|
|
|
|
424
|
|
|
// **************************************************************************************************************** |
425
|
|
|
xoops_cp_header(); |
426
|
|
|
// bookshop_adminMenu(2); |
|
|
|
|
427
|
|
|
$indexAdmin = new ModuleAdmin(); |
428
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=vat'); |
429
|
|
|
if ($op === 'editvat') { |
430
|
|
|
$title = _AM_BOOKSHOP_EDIT_VAT; |
431
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
432
|
|
|
if (empty($id)) { |
433
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
434
|
|
|
} |
435
|
|
|
// Item exits ? |
436
|
|
|
$item = null; |
437
|
|
|
$item = $h_bookshop_vat->get($id); |
438
|
|
|
if (!is_object($item)) { |
439
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
440
|
|
|
} |
441
|
|
|
$edit = true; |
442
|
|
|
$label_submit = _AM_BOOKSHOP_MODIFY; |
443
|
|
|
} else { |
444
|
|
|
$title = _AM_BOOKSHOP_ADD_VAT; |
445
|
|
|
$item = $h_bookshop_vat->create(true); |
446
|
|
|
$label_submit = _AM_BOOKSHOP_ADD; |
447
|
|
|
$edit = false; |
448
|
|
|
} |
449
|
|
|
$sform = new XoopsThemeForm($title, 'frmaddvat', $baseurl); |
450
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'saveeditvat')); |
451
|
|
|
$sform->addElement(new XoopsFormHidden('vat_id', $item->getVar('vat_id'))); |
452
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_RATE, 'vat_rate', 10, 15, $item->getVar('vat_rate', 'e')), true); |
453
|
|
|
|
454
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
455
|
|
|
$submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
456
|
|
|
$button_tray->addElement($submit_btn); |
457
|
|
|
$sform->addElement($button_tray); |
458
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
459
|
|
|
$sform->display(); |
460
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
461
|
|
|
break; |
462
|
|
|
|
463
|
|
|
// **************************************************************************************************************** |
464
|
|
|
case 'savechunks': // Save chunks order |
465
|
|
|
// **************************************************************************************************************** |
466
|
|
|
bookshop_set_module_option('chunk1', (int)$_POST['chunk1']); |
467
|
|
|
bookshop_set_module_option('chunk2', (int)$_POST['chunk2']); |
468
|
|
|
bookshop_set_module_option('chunk3', (int)$_POST['chunk3']); |
469
|
|
|
bookshop_set_module_option('chunk4', (int)$_POST['chunk4']); |
470
|
|
|
bookshop_updateCache(); |
471
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=categories'); |
472
|
|
|
break; |
473
|
|
|
|
474
|
|
|
// **************************************************************************************************************** |
475
|
|
|
case 'addcategory': // Ajout d'une cat�gorie |
476
|
|
|
case 'editcategory': // Edition d'une cat�gorie |
477
|
|
|
// **************************************************************************************************************** |
478
|
|
|
xoops_cp_header(); |
479
|
|
|
// bookshop_adminMenu(3); |
|
|
|
|
480
|
|
|
$indexAdmin = new ModuleAdmin(); |
481
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=categories'); |
482
|
|
|
|
483
|
|
|
if ($op === 'editcategory') { |
484
|
|
|
$title = _AM_BOOKSHOP_EDIT_CATEG; |
485
|
|
|
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0; |
486
|
|
|
if (empty($id)) { |
487
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
488
|
|
|
} |
489
|
|
|
// Item exits ? |
490
|
|
|
$item = null; |
491
|
|
|
$item = $h_bookshop_cat->get($id); |
492
|
|
|
if (!is_object($item)) { |
493
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
494
|
|
|
} |
495
|
|
|
$edit = true; |
496
|
|
|
$label_submit = _AM_BOOKSHOP_MODIFY; |
497
|
|
|
} else { |
498
|
|
|
$title = _AM_BOOKSHOP_ADD_CATEG; |
499
|
|
|
$item = $h_bookshop_cat->create(true); |
500
|
|
|
$label_submit = _AM_BOOKSHOP_ADD; |
501
|
|
|
$edit = false; |
502
|
|
|
} |
503
|
|
|
$tbl_categories = $h_bookshop_cat->GetAllCategories(); |
504
|
|
|
$mytree = new XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
505
|
|
|
$select_categ = $mytree->makeSelBox('cat_pid', 'cat_title', '-', $item->getVar('cat_pid'), true); |
506
|
|
|
|
507
|
|
|
$sform = new XoopsThemeForm($title, 'frmcategory', $baseurl); |
508
|
|
|
$sform->setExtra('enctype="multipart/form-data"'); |
509
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'saveeditcategory')); |
510
|
|
|
$sform->addElement(new XoopsFormHidden('cat_cid', $item->getVar('cat_cid'))); |
511
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_CATEG_TITLE, 'cat_title', 50, 255, $item->getVar('cat_title', 'e')), true); |
512
|
|
|
$sform->addElement(new XoopsFormLabel(_AM_BOOKSHOP_PARENT_CATEG, $select_categ), false); |
513
|
|
|
|
514
|
|
|
if ($op === 'editcategory' && trim($item->getVar('cat_imgurl')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('cat_imgurl')))) { |
515
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_CURRENT_PICTURE, '<br>'); |
516
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('cat_imgurl') . "' alt='' border='0' />")); |
517
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture'); |
518
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
519
|
|
|
$pictureTray->addElement($deleteCheckbox); |
520
|
|
|
$sform->addElement($pictureTray); |
521
|
|
|
} |
522
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_PICTURE, 'attachedfile', bookshop_getmoduleoption('maxuploadsize')), false); |
523
|
|
|
$editor = bookshop_getWysiwygForm(_AM_BOOKSHOP_DESCRIPTION, 'cat_description', $item->getVar('cat_description', 'e'), 15, 60, 'description_hidden'); |
524
|
|
|
if ($editor) { |
525
|
|
|
$sform->addElement($editor, false); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
$editor2 = bookshop_getWysiwygForm(_MI_BOOKSHOP_ADVERTISEMENT, 'cat_advertisement', $item->getVar('cat_advertisement', 'e'), 15, 60, 'advertisement_hidden'); |
529
|
|
|
if ($editor2) { |
530
|
|
|
$sform->addElement($editor2, false); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
// META Data |
534
|
|
View Code Duplication |
if ($manual_meta) { |
|
|
|
|
535
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_META_KEYWORDS, 'cat_metakeywords', 50, 255, $item->getVar('cat_metakeywords', 'e')), false); |
536
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_META_DESCRIPTION, 'cat_metadescription', 50, 255, $item->getVar('cat_metadescription', 'e')), false); |
537
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_META_PAGETITLE, 'cat_metatitle', 50, 255, $item->getVar('cat_metatitle', 'e')), false); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
541
|
|
|
$button_tray->addElement(new XoopsFormButton('', 'post', $label_submit, 'submit')); |
542
|
|
|
$sform->addElement($button_tray); |
543
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
544
|
|
|
$sform->display(); |
545
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
546
|
|
|
break; |
547
|
|
|
|
548
|
|
|
// **************************************************************************************************************** |
549
|
|
|
case 'saveeditcategory': // Sauvegarde d'une cat�gorie |
550
|
|
|
// **************************************************************************************************************** |
551
|
|
|
xoops_cp_header(); |
552
|
|
|
$id = isset($_POST['cat_cid']) ? (int)$_POST['cat_cid'] : 0; |
553
|
|
View Code Duplication |
if (!empty($id)) { |
|
|
|
|
554
|
|
|
$edit = true; |
555
|
|
|
$item = $h_bookshop_cat->get($id); |
556
|
|
|
if (!is_object($item)) { |
557
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
558
|
|
|
} |
559
|
|
|
$item->unsetNew(); |
560
|
|
|
$add = false; |
561
|
|
|
} else { |
562
|
|
|
$item = $h_bookshop_cat->create(true); |
563
|
|
|
$add = true; |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
$item->setVars($_POST); |
567
|
|
|
|
568
|
|
|
// Suppression de l'image ? |
569
|
|
|
if (isset($_POST['delpicture']) && (int)$_POST['delpicture'] == 1) { |
570
|
|
|
$item->setVar('cat_imgurl', ''); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
// Upload du fichier |
574
|
|
|
if (bookshop_upload(0)) { |
575
|
|
|
$item->setVar('cat_imgurl', basename($destname)); |
576
|
|
|
} |
577
|
|
|
$res = $h_bookshop_cat->insert($item); |
578
|
|
|
if ($res) { |
579
|
|
|
bookshop_updateCache(); |
580
|
|
|
if ($add) { |
581
|
|
|
$notification_handler = xoops_getHandler('notification'); |
582
|
|
|
$tags['CATEGORY_NAME'] = $item->getVar('cat_title'); |
583
|
|
|
$tags['CATEGORY_URL'] = BOOKSHOP_URL . 'category.php?cat_cid=' . $item->getVar('cat_cid'); |
584
|
|
|
$tags['X_MODULE_URL'] = BOOKSHOP_URL; |
585
|
|
|
$notification_handler->triggerEvent('global', 0, 'new_category', $tags); |
586
|
|
|
} |
587
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=categories', 2); |
588
|
|
|
} else { |
589
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=categories', 5); |
590
|
|
|
} |
591
|
|
|
break; |
592
|
|
|
|
593
|
|
|
// **************************************************************************************************************** |
594
|
|
|
case 'categories': // List categories |
595
|
|
|
// **************************************************************************************************************** |
596
|
|
|
xoops_cp_header(); |
597
|
|
|
// bookshop_adminMenu(3); |
|
|
|
|
598
|
|
|
$indexAdmin = new ModuleAdmin(); |
599
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=categories'); |
600
|
|
|
|
601
|
|
|
// Display categories ********************************************************************** |
602
|
|
|
$tbl_categories = array(); |
603
|
|
|
bookshop_htitle(_AM_BOOKSHOP_CATEGORIES, 4); |
604
|
|
|
|
605
|
|
|
$tbl_categories = $h_bookshop_cat->GetAllCategories(); |
606
|
|
|
$mytree = new XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
607
|
|
|
$select_categ = $mytree->makeSelBox('id', 'cat_title'); |
608
|
|
|
|
609
|
|
|
echo "<div class='even'><form method='post' name='quickaccess' id='quickaccess' action='$baseurl' >" . _AM_BOOKSHOP_LIST . " $select_categ<input type='radio' name='op' id='op' value='editcategory' />" . _EDIT . " <input type='radio' name='op' id='op' value='deletecategory' />" . _DELETE |
610
|
|
|
. " <input type='submit' name='btnquick' id='btnquick' value='" . _GO . "' /></form></div>"; |
611
|
|
|
echo "<div class='odd' align='center'><form method='post' name='frmadd' id='frmadd' action='$baseurl' ><input type='hidden' name='op' id='op' value='addcategory' /><input type='submit' name='btnadd' id='btnadd' value='" . _AM_BOOKSHOP_ADD_CATEG . "' /></form></div>"; |
612
|
|
|
echo '<br><br>'; |
613
|
|
|
|
614
|
|
|
// Categories preferences ***************************************************************** |
615
|
|
|
$chunk1 = bookshop_getmoduleoption('chunk1'); |
616
|
|
|
$chunk2 = bookshop_getmoduleoption('chunk2'); |
617
|
|
|
$chunk3 = bookshop_getmoduleoption('chunk3'); |
618
|
|
|
$chunk4 = bookshop_getmoduleoption('chunk4'); |
619
|
|
|
$tbl_positions = array(0 => _AM_BOOKSHOP_INVISIBLE, 1 => '1', 2 => '2', 3 => '3', 4 => '4'); |
620
|
|
|
|
621
|
|
|
$sform = new XoopsThemeForm(_AM_BOOKSHOP_CATEG_CONFIG, 'frmchunk', $baseurl); |
622
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'savechunks')); |
623
|
|
|
$sform->addElement(new XoopsFormLabel(_AM_BOOKSHOP_CHUNK, _AM_BOOKSHOP_POSITION)); |
624
|
|
|
|
625
|
|
|
$chunk = null; |
626
|
|
|
$chunk = new XoopsFormSelect(_MI_BOOKSHOP_CHUNK1, 'chunk1', $chunk1, 1, false); |
627
|
|
|
$chunk->addOptionArray($tbl_positions); |
628
|
|
|
$sform->addElement($chunk, true); |
629
|
|
|
|
630
|
|
|
unset($chunk); |
631
|
|
|
$chunk = new XoopsFormSelect(_MI_BOOKSHOP_CHUNK2, 'chunk2', $chunk2, 1, false); |
632
|
|
|
$chunk->addOptionArray($tbl_positions); |
633
|
|
|
$sform->addElement($chunk, true); |
634
|
|
|
|
635
|
|
|
unset($chunk); |
636
|
|
|
$chunk = new XoopsFormSelect(_MI_BOOKSHOP_CHUNK3, 'chunk3', $chunk3, 1, false); |
637
|
|
|
$chunk->addOptionArray($tbl_positions); |
638
|
|
|
$sform->addElement($chunk, true); |
639
|
|
|
|
640
|
|
|
unset($chunk); |
641
|
|
|
$chunk = new XoopsFormSelect(_MI_BOOKSHOP_CHUNK4, 'chunk4', $chunk4, 1, false); |
642
|
|
|
$chunk->addOptionArray($tbl_positions); |
643
|
|
|
$sform->addElement($chunk, true); |
644
|
|
|
|
645
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
646
|
|
|
$submit_btn = new XoopsFormButton('', 'post', _AM_BOOKSHOP_OK, 'submit'); |
647
|
|
|
$button_tray->addElement($submit_btn); |
648
|
|
|
$sform->addElement($button_tray); |
649
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
650
|
|
|
$sform->display(); |
651
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
652
|
|
|
break; |
653
|
|
|
|
654
|
|
|
// **************************************************************************************************************** |
655
|
|
|
case 'deletecategory': // Demande de confirmation de suppression d'une cat�gorie |
656
|
|
|
// **************************************************************************************************************** |
657
|
|
|
xoops_cp_header(); |
658
|
|
|
// bookshop_adminMenu(3); |
|
|
|
|
659
|
|
|
$indexAdmin = new ModuleAdmin(); |
660
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=categories'); |
661
|
|
|
|
662
|
|
|
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0; |
663
|
|
|
if (empty($id)) { |
664
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
665
|
|
|
} |
666
|
|
|
$category = null; |
667
|
|
|
$category = $h_bookshop_cat->get($id); |
668
|
|
|
if (!is_object($category)) { |
669
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_10, $baseurl, 5); |
670
|
|
|
} |
671
|
|
|
$msg = sprintf(_AM_BOOKSHOP_CONF_DEL_CATEG, $category->getVar('cat_title')); |
672
|
|
|
xoops_confirm(array('op' => 'confdeletecategory', 'id' => $id), 'index.php', $msg); |
673
|
|
|
break; |
674
|
|
|
|
675
|
|
|
// **************************************************************************************************************** |
676
|
|
|
case 'confdeletecategory': // Suppression effective d'une cat�gorie |
677
|
|
|
// **************************************************************************************************************** |
678
|
|
|
xoops_cp_header(); |
679
|
|
|
// bookshop_adminMenu(3); |
|
|
|
|
680
|
|
|
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0; |
681
|
|
|
if (empty($id)) { |
682
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
683
|
|
|
} |
684
|
|
|
// On v�rifie que cette cat�gorie n'est pas utilis�e par des livres |
685
|
|
|
$tbl_categories = $tbl_childs = $tbl_chids_ids = array(); |
686
|
|
|
$cnt = 0; |
687
|
|
|
$lst_ids = ''; |
688
|
|
|
// Recherche des sous cat�gories de cette cat�gorie |
689
|
|
|
$tbl_categories = $h_bookshop_cat->GetAllCategories(); |
690
|
|
|
$mytree = new XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
691
|
|
|
$tbl_childs = $mytree->getAllChild($id); |
692
|
|
|
$tbl_chids_ids[] = $id; |
693
|
|
|
if (count($tbl_childs) > 0) { |
694
|
|
|
foreach ($tbl_childs as $onechild) { |
695
|
|
|
$tbl_chids_ids[] = $onechild->getVar('cat_cid'); |
696
|
|
|
} |
697
|
|
|
} |
698
|
|
|
$lst_ids = implode(',', $tbl_chids_ids); |
699
|
|
|
$criteria = new Criteria('book_cid', '(' . $lst_ids . ')', 'IN'); |
700
|
|
|
$cnt = $h_bookshop_books->getCount($criteria); |
701
|
|
|
if ($cnt == 0) { |
702
|
|
|
$item = null; |
703
|
|
|
$item = $h_bookshop_cat->get($id); |
704
|
|
|
if (is_object($item)) { |
705
|
|
|
$critere = new Criteria('cat_cid', $id, '='); |
706
|
|
|
xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'new_category', $id); |
707
|
|
|
$res = $h_bookshop_cat->deleteAll($critere); |
708
|
|
|
if ($res) { |
709
|
|
|
bookshop_updateCache(); |
710
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=categories', 2); |
711
|
|
|
} else { |
712
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=categories', 5); |
713
|
|
|
} |
714
|
|
|
} else { |
715
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=categories', 5); |
716
|
|
|
} |
717
|
|
|
} else { |
718
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_4, $baseurl . '?op=categories', 5); |
719
|
|
|
} |
720
|
|
|
break; |
721
|
|
|
|
722
|
|
|
// **************************************************************************************************************** |
723
|
|
|
case 'authors': // Liste des auteurs / traducteurs |
724
|
|
|
// **************************************************************************************************************** |
725
|
|
|
xoops_cp_header(); |
726
|
|
|
// bookshop_adminMenu(4); |
|
|
|
|
727
|
|
|
$indexAdmin = new ModuleAdmin(); |
728
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=authors'); |
729
|
|
|
|
730
|
|
|
$tbl_vat = array(); |
731
|
|
|
echo "<form method='post' action='$baseurl' name='frmaddauthor' id='frmaddauthor'><input type='hidden' name='op' id='op' value='addauthor' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form>"; |
732
|
|
|
$authorsCount = $h_bookshop_authors->getCount(new Criteria('auth_type', 1, '=')); |
733
|
|
|
$translatorsCount = $h_bookshop_authors->getCount(new Criteria('auth_type', 2, '=')); |
734
|
|
|
|
735
|
|
|
bookshop_htitle(sprintf(_AM_BOOKSHOP_AT_COUNT, $authorsCount, $translatorsCount), 4); |
736
|
|
|
|
737
|
|
|
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
738
|
|
|
$filter = 0; |
739
|
|
View Code Duplication |
if (isset($_POST['filter'])) { |
|
|
|
|
740
|
|
|
$filter = (int)$_POST['filter']; |
741
|
|
|
} elseif (isset($_SESSION['filter'])) { |
742
|
|
|
$filter = (int)$_SESSION['filter']; |
743
|
|
|
} |
744
|
|
|
$_SESSION['filter'] = $filter; |
745
|
|
|
$selected = array('', '', '', ''); |
746
|
|
|
$selected[$filter] = " selected='selected'"; |
747
|
|
|
|
748
|
|
|
$criteria = new CriteriaCompo(); |
749
|
|
|
$criteria->add(new Criteria('auth_id', 0, '<>')); |
750
|
|
|
|
751
|
|
View Code Duplication |
if ($filter == 1) { // Ne voir que les auteurs |
|
|
|
|
752
|
|
|
$criteria->add(new Criteria('auth_type', 1, '=')); |
753
|
|
|
} elseif ($filter == 2) { // Ne voir que les traducteurs |
754
|
|
|
$criteria->add(new Criteria('auth_type', 2, '=')); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
$authors_count = $h_bookshop_authors->getCount($criteria); // Recherche du nombre total d'auteurs |
758
|
|
|
$pagenav = new XoopsPageNav($authors_count, $limit, $start, 'start', 'op=authors'); |
759
|
|
|
|
760
|
|
|
$criteria->setLimit($limit); |
761
|
|
|
$criteria->setStart($start); |
762
|
|
|
$criteria->setSort('auth_name, auth_firstname'); |
763
|
|
|
|
764
|
|
|
$tbl_autheurs = $h_bookshop_authors->getObjects($criteria); |
765
|
|
|
$class = ''; |
766
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
767
|
|
|
$form = "<form method='post' name='frmfilter' id='frmfilter' action='$baseurl'>" . _AM_BOOKSHOP_LIMIT_TO . " <select name='filter' id='filter'><option value='0'" . $selected[0] . '>' . _AM_BOOKSHOP_ALL . "</option><option value='1'" . $selected[1] . '>' . _AM_BOOKSHOP_AUTHORS |
768
|
|
|
. "</option><option value='2'" . $selected[2] . '>' . _AM_BOOKSHOP_TRANSLATORS . "</option></select> <input type='hidden' name='op' id='op' value='authors' /><input type='submit' name='btnfilter' id='btnfilter' value='" . _AM_BOOKSHOP_FILTER . "' /></form>"; |
769
|
|
|
|
770
|
|
|
echo "<tr><td colspan='2' align='left'>" . $pagenav->renderNav() . "</td><td align='right' colspan='3'>" . $form . "</td></tr>\n"; |
771
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_LASTNAME . "</th><th align='center'>" . _BOOKSHOP_FIRSTNAME . "</th><th align='center'>" . _BOOKSHOP_EMAIL . "</th><th align='center'>" . _BOOKSHOP_TYPE . "</th><th align='center'>" . _AM_BOOKSHOP_ACTION . '</th></tr>'; |
772
|
|
|
foreach ($tbl_autheurs as $item) { |
773
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
774
|
|
|
$action_edit = "<a href='$baseurl?op=editauthor&id=" . $item->getVar('auth_id') . "' title='" . _BOOKSHOP_EDIT . "'>" . $icones['edit'] . '</a>'; |
775
|
|
|
$action_delete = "<a href='$baseurl?op=deleteauthor&id=" . $item->getVar('auth_id') . "' title='" . _BOOKSHOP_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
776
|
|
|
$type = $item->getVar('auth_type') == 1 ? _BOOKSHOP_AUTHOR : _BOOKSHOP_TRANSLATOR; |
777
|
|
|
echo "<tr class='" . $class . "'>\n"; |
778
|
|
|
echo '<td>' . $item->getVar('auth_name') . "</td><td align='left'>" . $item->getVar('auth_firstname') . "</td><td align='center'>" . $item->getVar('auth_email') . "</td><td align='center'>" . $type . "</td><td align='center'>" . $action_edit . ' ' . $action_delete . "</td>\n"; |
779
|
|
|
echo "<tr>\n"; |
780
|
|
|
} |
781
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
782
|
|
|
echo "<tr class='" . $class . "'>\n"; |
783
|
|
|
echo "<td colspan='5' align='center'><form method='post' action='$baseurl' name='frmaddauthor' id='frmaddauthor'><input type='hidden' name='op' id='op' value='addauthor' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form></td>\n"; |
784
|
|
|
echo "</tr>\n"; |
785
|
|
|
echo '</table>'; |
786
|
|
|
echo "<div align='right'>" . $pagenav->renderNav() . '</div>'; |
787
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
788
|
|
|
break; |
789
|
|
|
|
790
|
|
|
// **************************************************************************************************************** |
791
|
|
|
case 'saveeditauthor': // Sauvegarde d'un auteur / traducteur |
792
|
|
|
// **************************************************************************************************************** |
793
|
|
|
xoops_cp_header(); |
794
|
|
|
$id = isset($_POST['auth_id']) ? (int)$_POST['auth_id'] : 0; |
795
|
|
|
if (!empty($id)) { |
796
|
|
|
$edit = true; |
797
|
|
|
$item = $h_bookshop_authors->get($id); |
798
|
|
|
if (!is_object($item)) { |
799
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
800
|
|
|
} |
801
|
|
|
$item->unsetNew(); |
802
|
|
|
} else { |
803
|
|
|
$item = $h_bookshop_authors->create(true); |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
$item->setVars($_POST); |
807
|
|
|
|
808
|
|
View Code Duplication |
if (isset($_POST['delpicture1']) && (int)$_POST['delpicture1'] == 1) { |
|
|
|
|
809
|
|
|
$item->setVar('auth_photo1', ''); |
810
|
|
|
} |
811
|
|
View Code Duplication |
if (isset($_POST['delpicture2']) && (int)$_POST['delpicture2'] == 1) { |
|
|
|
|
812
|
|
|
$item->setVar('auth_photo2', ''); |
813
|
|
|
} |
814
|
|
|
if (isset($_POST['delpicture3']) && (int)$_POST['delpicture3'] == 1) { |
815
|
|
|
$item->setVar('auth_photo3', ''); |
816
|
|
|
} |
817
|
|
|
if (isset($_POST['delpicture4']) && (int)$_POST['delpicture4'] == 1) { |
818
|
|
|
$item->setVar('auth_photo4', ''); |
819
|
|
|
} |
820
|
|
|
if (isset($_POST['delpicture5']) && (int)$_POST['delpicture5'] == 1) { |
821
|
|
|
$item->setVar('auth_photo5', ''); |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
// Upload du fichier |
825
|
|
|
if (bookshop_upload(0)) { |
826
|
|
|
$item->setVar('auth_photo1', basename($destname)); |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
if (bookshop_upload(1)) { |
830
|
|
|
$item->setVar('auth_photo2', basename($destname)); |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
if (bookshop_upload(2)) { |
834
|
|
|
$item->setVar('auth_photo3', basename($destname)); |
835
|
|
|
} |
836
|
|
|
|
837
|
|
|
if (bookshop_upload(3)) { |
838
|
|
|
$item->setVar('auth_photo4', basename($destname)); |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
if (bookshop_upload(4)) { |
842
|
|
|
$item->setVar('auth_photo5', basename($destname)); |
843
|
|
|
} |
844
|
|
|
$res = $h_bookshop_authors->insert($item); |
845
|
|
|
if ($res) { |
846
|
|
|
bookshop_updateCache(); |
847
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=authors', 2); |
848
|
|
|
} else { |
849
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=authors', 5); |
850
|
|
|
} |
851
|
|
|
break; |
852
|
|
|
|
853
|
|
|
// **************************************************************************************************************** |
854
|
|
View Code Duplication |
case 'deleteauthor': // Suppression d'un auteur |
|
|
|
|
855
|
|
|
// **************************************************************************************************************** |
856
|
|
|
xoops_cp_header(); |
857
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
858
|
|
|
if (empty($id)) { |
859
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
860
|
|
|
} |
861
|
|
|
// On v�rifie que cet auteur n'est pas utilis�e par un livre |
862
|
|
|
$criteria = new Criteria('ba_auth_id', $id, '='); |
863
|
|
|
$cnt = $h_bookshop_booksauthors->getCount($criteria); |
864
|
|
|
if ($cnt == 0) { |
865
|
|
|
$item = null; |
866
|
|
|
$item = $h_bookshop_authors->get($id); |
867
|
|
|
if (is_object($item)) { |
868
|
|
|
$critere = new Criteria('auth_id', $id, '='); |
869
|
|
|
$res = $h_bookshop_authors->deleteAll($critere); |
870
|
|
|
if ($res) { |
871
|
|
|
bookshop_updateCache(); |
872
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=authors', 2); |
873
|
|
|
} else { |
874
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=authors', 5); |
875
|
|
|
} |
876
|
|
|
} else { |
877
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=authors', 5); |
878
|
|
|
} |
879
|
|
|
} else { |
880
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_5, $baseurl . '?op=authors', 5); |
881
|
|
|
} |
882
|
|
|
break; |
883
|
|
|
|
884
|
|
|
// **************************************************************************************************************** |
885
|
|
|
case 'addauthor': // Ajout d'un auteur / traducteur |
886
|
|
|
case 'editauthor': // Edition d'un auteur / traducteur |
887
|
|
|
// **************************************************************************************************************** |
888
|
|
|
xoops_cp_header(); |
889
|
|
|
// bookshop_adminMenu(4); |
|
|
|
|
890
|
|
|
$indexAdmin = new ModuleAdmin(); |
891
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=authors'); |
892
|
|
|
|
893
|
|
|
if ($op === 'editauthor') { |
894
|
|
|
$title = _AM_BOOKSHOP_EDIT_AUTH; |
895
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
896
|
|
|
if (empty($id)) { |
897
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
898
|
|
|
} |
899
|
|
|
// Item exits ? |
900
|
|
|
$item = null; |
901
|
|
|
$item = $h_bookshop_authors->get($id); |
902
|
|
|
if (!is_object($item)) { |
903
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
904
|
|
|
} |
905
|
|
|
$edit = true; |
906
|
|
|
$label_submit = _AM_BOOKSHOP_MODIFY; |
907
|
|
|
} else { |
908
|
|
|
$title = _AM_BOOKSHOP_ADD_AUTH; |
909
|
|
|
$item = $h_bookshop_authors->create(true); |
910
|
|
|
$item->setVar('auth_type', 1); |
911
|
|
|
$label_submit = _AM_BOOKSHOP_ADD; |
912
|
|
|
$edit = false; |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
$sform = new XoopsThemeForm($title, 'frmauteur', $baseurl); |
916
|
|
|
$sform->setExtra('enctype="multipart/form-data"'); |
917
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'saveeditauthor')); |
918
|
|
|
$sform->addElement(new XoopsFormHidden('auth_id', $item->getVar('auth_id'))); |
919
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_LASTNAME, 'auth_name', 50, 255, $item->getVar('auth_name', 'e')), true); |
920
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_FIRSTNAME, 'auth_firstname', 50, 255, $item->getVar('auth_firstname', 'e')), false); |
921
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_EMAIL, 'auth_email', 50, 255, $item->getVar('auth_email', 'e')), false); |
922
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_SITEURL, 'auth_url', 50, 255, $item->getVar('auth_url', 'e')), false); |
923
|
|
|
$radio_type = new XoopsFormRadio(_BOOKSHOP_TYPE, 'auth_type', $item->getVar('auth_type', 'e')); |
924
|
|
|
$radio_type->addOptionArray(array('1' => _BOOKSHOP_AUTHOR, '2' => _BOOKSHOP_TRANSLATOR)); |
925
|
|
|
$sform->addElement($radio_type, true); |
926
|
|
|
|
927
|
|
|
$editor = bookshop_getWysiwygForm(_BOOKSHOP_BIO, 'auth_bio', $item->getVar('auth_bio', 'e'), 15, 60, 'bio_hidden'); |
928
|
|
|
if ($editor) { |
929
|
|
|
$sform->addElement($editor, false); |
930
|
|
|
} |
931
|
|
|
|
932
|
|
View Code Duplication |
if ($op === 'editauthor' && trim($item->getVar('auth_photo1')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('auth_photo1')))) { |
|
|
|
|
933
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_CURRENT_PICTURE, '<br>'); |
934
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('auth_photo1') . "' alt='' border='0' />")); |
935
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture1'); |
936
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
937
|
|
|
$pictureTray->addElement($deleteCheckbox); |
938
|
|
|
$sform->addElement($pictureTray); |
939
|
|
|
unset($pictureTray, $deleteCheckbox); |
940
|
|
|
} |
941
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_PICTURE, 'attachedfile1', bookshop_getmoduleoption('maxuploadsize')), false); |
942
|
|
|
|
943
|
|
View Code Duplication |
if ($op === 'editauthor' && trim($item->getVar('auth_photo2')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('auth_photo2')))) { |
|
|
|
|
944
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_CURRENT_PICTURE, '<br>'); |
945
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('auth_photo2') . "' alt='' border='0' />")); |
946
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture2'); |
947
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
948
|
|
|
$pictureTray->addElement($deleteCheckbox); |
949
|
|
|
$sform->addElement($pictureTray); |
950
|
|
|
unset($pictureTray, $deleteCheckbox); |
951
|
|
|
} |
952
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_PICTURE, 'attachedfile2', bookshop_getmoduleoption('maxuploadsize')), false); |
953
|
|
|
|
954
|
|
View Code Duplication |
if ($op === 'editauthor' && trim($item->getVar('auth_photo3')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('auth_photo3')))) { |
|
|
|
|
955
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_CURRENT_PICTURE, '<br>'); |
956
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('auth_photo3') . "' alt='' border='0' />")); |
957
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture3'); |
958
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
959
|
|
|
$pictureTray->addElement($deleteCheckbox); |
960
|
|
|
$sform->addElement($pictureTray); |
961
|
|
|
unset($pictureTray, $deleteCheckbox); |
962
|
|
|
} |
963
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_PICTURE, 'attachedfile3', bookshop_getmoduleoption('maxuploadsize')), false); |
964
|
|
|
|
965
|
|
View Code Duplication |
if ($op === 'editauthor' && trim($item->getVar('auth_photo4')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('auth_photo4')))) { |
|
|
|
|
966
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_CURRENT_PICTURE, '<br>'); |
967
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('auth_photo4') . "' alt='' border='0' />")); |
968
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture4'); |
969
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
970
|
|
|
$pictureTray->addElement($deleteCheckbox); |
971
|
|
|
$sform->addElement($pictureTray); |
972
|
|
|
unset($pictureTray, $deleteCheckbox); |
973
|
|
|
} |
974
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_PICTURE, 'attachedfile4', bookshop_getmoduleoption('maxuploadsize')), false); |
975
|
|
|
|
976
|
|
View Code Duplication |
if ($op === 'editauthor' && trim($item->getVar('auth_photo5')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('auth_photo5')))) { |
|
|
|
|
977
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_CURRENT_PICTURE, '<br>'); |
978
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('auth_photo5') . "' alt='' border='0' />")); |
979
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture5'); |
980
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
981
|
|
|
$pictureTray->addElement($deleteCheckbox); |
982
|
|
|
$sform->addElement($pictureTray); |
983
|
|
|
unset($pictureTray, $deleteCheckbox); |
984
|
|
|
} |
985
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_PICTURE, 'attachedfile5', bookshop_getmoduleoption('maxuploadsize')), false); |
986
|
|
|
|
987
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
988
|
|
|
$submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
989
|
|
|
$button_tray->addElement($submit_btn); |
990
|
|
|
$sform->addElement($button_tray); |
991
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
992
|
|
|
$sform->display(); |
993
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
994
|
|
|
break; |
995
|
|
|
|
996
|
|
|
// **************************************************************************************************************** |
997
|
|
|
case 'books': // Gestion des livres |
998
|
|
|
// **************************************************************************************************************** |
999
|
|
|
xoops_cp_header(); |
1000
|
|
|
// bookshop_adminMenu(5); |
|
|
|
|
1001
|
|
|
|
1002
|
|
|
$indexAdmin = new ModuleAdmin(); |
1003
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=books'); |
1004
|
|
|
|
1005
|
|
|
$tbl_books = $tbl_categories = $tbl_number = $tbl_tome = $tbl_author = array(); |
1006
|
|
|
|
1007
|
|
|
// R�cup�ration des donn�es uniques |
1008
|
|
|
$tbl_categories = $h_bookshop_cat->GetAllCategories(0, 0, 'cat_title', 'ASC', true); |
1009
|
|
|
$tbl_numbers = $h_bookshop_books->getDistincts('book_number'); |
1010
|
|
|
$tbl_tome = $h_bookshop_books->getDistincts('book_tome'); |
1011
|
|
|
$tbl_author = $h_bookshop_authors->getDistincts('auth_name'); |
1012
|
|
|
|
1013
|
|
|
$mytree = new XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
1014
|
|
|
$select_categ = $mytree->makeSelBox('id', 'cat_title'); |
1015
|
|
|
|
1016
|
|
|
echo "<form method='post' action='$baseurl' name='frmaddbook' id='frmaddbook'><input type='hidden' name='op' id='op' value='addbook' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form>"; |
1017
|
|
|
echo "<br><form method='get' action='$baseurl' name='frmaddeditbook' id='frmaddeditbook'>" . _BOOKSHOP_BOOK_ID . " <input type='text' name='id' id='id' value='' size='4'/> <input type='radio' name='op' id='op' value='editbook' />" . _BOOKSHOP_EDIT |
1018
|
|
|
. " <input type='radio' name='op' id='op' value='deletebook' />" . _BOOKSHOP_DELETE . " <input type='submit' name='btngo' id='btngo' value='" . _GO . "' /></form>"; |
1019
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU4, 4); |
1020
|
|
|
|
1021
|
|
|
//TODO: Ajouter les listes permettant de filtrer les livres |
1022
|
|
|
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
1023
|
|
|
$filter = 0; |
1024
|
|
|
|
1025
|
|
|
$filter2 = 0; |
1026
|
|
View Code Duplication |
if (isset($_POST['filter2'])) { |
|
|
|
|
1027
|
|
|
$filter2 = (int)$_POST['filter2']; |
1028
|
|
|
} elseif (isset($_SESSION['filter2'])) { |
1029
|
|
|
$filter2 = (int)$_SESSION['filter2']; |
1030
|
|
|
} |
1031
|
|
|
$_SESSION['filter2'] = $filter2; |
1032
|
|
|
$selected = array('', '', '', ''); |
1033
|
|
|
$selected[$filter2] = " selected='selected'"; |
1034
|
|
|
|
1035
|
|
|
$criteria = new CriteriaCompo(); |
1036
|
|
|
$criteria->add(new Criteria('book_id', 0, '<>')); |
1037
|
|
|
|
1038
|
|
View Code Duplication |
if ($filter2 == 1) { // Ne voir que les auteurs |
|
|
|
|
1039
|
|
|
$criteria->add(new Criteria('auth_type', 1, '=')); |
1040
|
|
|
} elseif ($filter2 == 2) { // Ne voir que les traducteurs |
1041
|
|
|
$criteria->add(new Criteria('auth_type', 2, '=')); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
$books_count = $h_bookshop_books->getCount($criteria); // Recherche du nombre total d'auteurs |
1045
|
|
|
$pagenav = new XoopsPageNav($books_count, $limit, $start, 'start', 'op=books'); |
1046
|
|
|
|
1047
|
|
|
$criteria->setLimit($limit); |
1048
|
|
|
$criteria->setStart($start); |
1049
|
|
|
$criteria->setSort('book_title'); |
1050
|
|
|
|
1051
|
|
|
$tbl_vat = array(); |
1052
|
|
|
$tbl_vat = $h_bookshop_vat->GetAllVats(); |
1053
|
|
|
$tbl_books = $h_bookshop_books->getObjects($criteria); |
1054
|
|
|
$class = ''; |
1055
|
|
|
echo "<div align='left'>" . $pagenav->renderNav() . '</div>'; |
1056
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
1057
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_TITLE . "</th><th align='center'>" . _BOOKSHOP_CATEGORY . "</th><th align='center'>" . _BOOKSHOP_NUMBER . '<br>' . _BOOKSHOP_TOME . "</th><th align='center'>" . _AM_BOOKSHOP_RECOMMENDED . "</th><th align='center'>" . _BOOKSHOP_ONLINE |
1058
|
|
|
. "</th><th align='center'>" . _BOOKSHOP_DATE . "</th><th align='center'>" . _BOOKSHOP_PRICE . "</th><th align='center'>" . _AM_BOOKSHOP_ACTION . '</th></tr>'; |
1059
|
|
|
foreach ($tbl_books as $item) { |
1060
|
|
|
$id = $item->getVar('book_id'); |
1061
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
1062
|
|
|
$action_edit = "<a href='$baseurl?op=editbook&id=" . $id . "' title='" . _BOOKSHOP_EDIT . "'>" . $icones['edit'] . '</a>'; |
1063
|
|
|
$action_duplicate = "<a href='$baseurl?op=copybook&id=" . $id . "' title='" . _BOOKSHOP_DUPLICATE_BOOK . "'>" . $icones['copy'] . '</a>'; |
1064
|
|
|
$action_delete = "<a href='$baseurl?op=deletebook&id=" . $id . "' title='" . _BOOKSHOP_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
1065
|
|
|
$online = $item->getVar('book_online') == 1 ? _YES : _NO; |
1066
|
|
|
echo "<tr class='" . $class . "'>\n"; |
1067
|
|
|
$prix = $item->getVar('book_price'); |
1068
|
|
|
$vatId = $item->getVar('book_vat_id'); |
1069
|
|
|
if (isset($tbl_vat[$vatId])) { |
1070
|
|
|
$vatItem = $tbl_vat[$vatId]; |
1071
|
|
|
$tva = $vatItem->getVar('vat_rate'); |
1072
|
|
|
$TTC = bookshop_getTTC($prix, $tva, false); |
1073
|
|
|
} else { |
1074
|
|
|
$TTC = _AM_BOOKSHOP_ERROR_11; |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
if ((float)$item->getVar('book_discount_price') > 0) { |
1078
|
|
|
if (isset($tbl_vat[$vatId])) { |
1079
|
|
|
$vatItem = $tbl_vat[$vatId]; |
1080
|
|
|
$tva = $vatItem->getVar('vat_rate'); |
1081
|
|
|
$TTC2 = bookshop_getTTC($item->getVar('book_discount_price'), $tva, false); |
1082
|
|
|
$TTC = '<s>' . $TTC . '</s> ' . $TTC2; |
1083
|
|
|
} |
1084
|
|
|
} |
1085
|
|
|
if ($item->isRecommended()) { // Si le livre est recommand�, on affiche le lien qui permet d'arr�ter de le recommander |
1086
|
|
|
$recommended = "<a href='" . $baseurl . '?op=unrecommendbook&book_id=' . $id . "' title='" . _AM_BOOKSHOP_DONOTRECOMMEND_IT . "'><img alt='" . _AM_BOOKSHOP_DONOTRECOMMEND_IT . "' src='" . BOOKSHOP_IMAGES_URL . "heart_delete.png' alt='' /></a>"; |
1087
|
|
|
} else { // Sinon on affiche le lien qui permet de le recommander |
1088
|
|
|
$recommended = "<a href='" . $baseurl . '?op=recommendbook&book_id=' . $id . "' title='" . _AM_BOOKSHOP_RECOMMEND_IT . "'><img alt='" . _AM_BOOKSHOP_RECOMMEND_IT . "' src='" . BOOKSHOP_IMAGES_URL . "heart_add.png' alt='' /></a>"; |
1089
|
|
|
} |
1090
|
|
|
echo '<td>' . $item->getVar('book_title') . "</td><td align='left'>" . $tbl_categories[$item->getVar('book_cid')]->getVar('cat_title') . "</td><td align='center'>" . $item->getVar('book_number') . ' / ' . $item->getVar('book_tome') . "</td><td align='center'>" . $recommended |
1091
|
|
|
. "</td><td align='center'>" . $online . "</td><td align='center'>" . $item->getVar('book_date') . "</td><td align='right'>" . $TTC . "</td><td align='center'>" . $action_edit . ' ' . $action_duplicate . ' ' . $action_delete . "</td>\n"; |
1092
|
|
|
echo "<tr>\n"; |
1093
|
|
|
} |
1094
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
1095
|
|
|
echo "<tr class='" . $class . "'>\n"; |
1096
|
|
|
echo "<td colspan='8' align='center'><form method='post' action='$baseurl' name='frmaddbook' id='frmaddbook'><input type='hidden' name='op' id='op' value='addbook' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form></td>\n"; |
1097
|
|
|
echo "</tr>\n"; |
1098
|
|
|
echo '</table>'; |
1099
|
|
|
echo "<div align='right'>" . $pagenav->renderNav() . '</div>'; |
1100
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
1101
|
|
|
break; |
1102
|
|
|
|
1103
|
|
|
// **************************************************************************************************************** |
1104
|
|
View Code Duplication |
case 'recommendbook': // Recommander un livre |
|
|
|
|
1105
|
|
|
// **************************************************************************************************************** |
1106
|
|
|
$opRedirect = '?op=books'; |
1107
|
|
|
if (isset($_GET['book_id'])) { |
1108
|
|
|
$book_id = (int)$_GET['book_id']; |
1109
|
|
|
$book = null; |
1110
|
|
|
$book = $h_bookshop_books->get($book_id); |
1111
|
|
|
if (is_object($book)) { |
1112
|
|
|
$book->setRecommended(); |
1113
|
|
|
if ($h_bookshop_books->insert($book, true)) { |
1114
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . $opRedirect, 1); |
1115
|
|
|
} else { |
1116
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . $opRedirect, 4); |
1117
|
|
|
} |
1118
|
|
|
} else { |
1119
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . $opRedirect, 4); |
1120
|
|
|
} |
1121
|
|
|
} else { |
1122
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl . $opRedirect, 4); |
1123
|
|
|
} |
1124
|
|
|
break; |
1125
|
|
|
|
1126
|
|
|
// **************************************************************************************************************** |
1127
|
|
View Code Duplication |
case 'unrecommendbook': // Arr�ter de recommender un livre |
|
|
|
|
1128
|
|
|
// **************************************************************************************************************** |
1129
|
|
|
$opRedirect = '?op=books'; |
1130
|
|
|
if (isset($_GET['book_id'])) { |
1131
|
|
|
$book_id = (int)$_GET['book_id']; |
1132
|
|
|
$book = null; |
1133
|
|
|
$book = $h_bookshop_books->get($book_id); |
1134
|
|
|
if (is_object($book)) { |
1135
|
|
|
$book->unsetRecommended(); |
1136
|
|
|
if ($h_bookshop_books->insert($book, true)) { |
1137
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . $opRedirect, 1); |
1138
|
|
|
} else { |
1139
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . $opRedirect, 4); |
1140
|
|
|
} |
1141
|
|
|
} else { |
1142
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . $opRedirect, 4); |
1143
|
|
|
} |
1144
|
|
|
} else { |
1145
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl . $opRedirect, 4); |
1146
|
|
|
} |
1147
|
|
|
break; |
1148
|
|
|
|
1149
|
|
|
// **************************************************************************************************************** |
1150
|
|
|
case 'addbook': // Ajout d'un livre |
1151
|
|
|
case 'editbook': // Edition d'un livre |
1152
|
|
|
// **************************************************************************************************************** |
1153
|
|
|
xoops_cp_header(); |
1154
|
|
|
// bookshop_adminMenu(5); |
|
|
|
|
1155
|
|
|
$indexAdmin = new ModuleAdmin(); |
1156
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=books'); |
1157
|
|
|
|
1158
|
|
|
global $xoopsUser; |
|
|
|
|
1159
|
|
|
|
1160
|
|
|
if ($op === 'editbook') { |
1161
|
|
|
$title = _AM_BOOKSHOP_EDIT_BOOK; |
1162
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
1163
|
|
|
if (empty($id)) { |
1164
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
1165
|
|
|
} |
1166
|
|
|
// Item exits ? |
1167
|
|
|
$item = null; |
1168
|
|
|
$item = $h_bookshop_books->get($id); |
1169
|
|
|
if (!is_object($item)) { |
1170
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
1171
|
|
|
} |
1172
|
|
|
$edit = true; |
1173
|
|
|
$label_submit = _AM_BOOKSHOP_MODIFY; |
1174
|
|
|
} else { |
1175
|
|
|
$title = _AM_BOOKSHOP_ADD_BOOK; |
1176
|
|
|
$item = $h_bookshop_books->create(true); |
1177
|
|
|
$label_submit = _AM_BOOKSHOP_ADD; |
1178
|
|
|
$edit = false; |
1179
|
|
|
} |
1180
|
|
|
|
1181
|
|
|
$tbl_categories = $h_bookshop_cat->GetAllCategories(0, 0, 'cat_title', 'ASC', true); |
1182
|
|
|
if (count($tbl_categories) == 0) { |
1183
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_8, $baseurl, 5); |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
|
$tbl_vat = $tbl_vat_display = array(); |
1187
|
|
|
$tbl_vat = $h_bookshop_vat->GetAllVats(0, 0); |
1188
|
|
|
if (count($tbl_vat) == 0) { |
1189
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_9, $baseurl, 5); |
1190
|
|
|
} |
1191
|
|
|
foreach ($tbl_vat as $onevat) { |
1192
|
|
|
$tbl_vat_display[$onevat->getVar('vat_id')] = $onevat->getVar('vat_rate'); |
1193
|
|
|
} |
1194
|
|
|
|
1195
|
|
|
$mytree = new XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
1196
|
|
|
$select_categ = $mytree->makeSelBox('book_cid', 'cat_title', '-', $item->getVar('book_cid')); |
1197
|
|
|
|
1198
|
|
|
$sform = new XoopsThemeForm($title, 'frmbook', $baseurl); |
1199
|
|
|
$sform->setExtra('enctype="multipart/form-data"'); |
1200
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'saveeditbook')); |
1201
|
|
|
$sform->addElement(new XoopsFormHidden('book_id', $item->getVar('book_id'))); |
1202
|
|
|
$sform->addElement(new XoopsFormHidden('book_submitter', $xoopsUser->getVar('uid'))); |
1203
|
|
|
|
1204
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_TITLE, 'book_title', 50, 255, $item->getVar('book_title', 'e')), true); |
1205
|
|
|
|
1206
|
|
|
// Langues ************************************************************* |
1207
|
|
|
$tbl_lang = $tbl_lang_display = array(); |
1208
|
|
|
$tbl_lang = $h_bookshop_lang->GetAllLang(); |
1209
|
|
|
foreach ($tbl_lang as $onelang) { |
1210
|
|
|
$tbl_lang_display[$onelang->getVar('lang_id')] = $onelang->getVar('lang_lang'); |
1211
|
|
|
} |
1212
|
|
|
$lang_select = new XoopsFormSelect(_BOOKSHOP_LANG, 'book_lang_id', $item->getVar('book_lang_id')); |
1213
|
|
|
$lang_select->addOptionArray($tbl_lang_display); |
1214
|
|
|
$sform->addElement($lang_select, true); |
1215
|
|
|
|
1216
|
|
|
$sform->addElement(new XoopsFormLabel(_AM_BOOKSHOP_CATEG_HLP, $select_categ), true); |
1217
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_NUMBER, 'book_number', 10, 60, $item->getVar('book_number', 'e')), false); |
1218
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_TOME, 'book_tome', 10, 50, $item->getVar('book_tome', 'e')), false); |
1219
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_VOLUMES, 'book_volumes_count', 10, 50, $item->getVar('book_volumes_count', 'e')), false); |
1220
|
|
|
|
1221
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_FORMAT_HLP, 'book_format', 50, 100, $item->getVar('book_format', 'e')), false); |
1222
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_ISBN, 'book_isbn', 13, 13, $item->getVar('book_isbn', 'e')), false); |
1223
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_EAN, 'book_ean', 13, 13, $item->getVar('book_ean', 'e')), false); |
1224
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_PAGES, 'book_pages', 13, 13, $item->getVar('book_pages', 'e')), false); |
1225
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_PAGES_COLLECTION, 'book_pages_collection', 13, 13, $item->getVar('book_pages_collection', 'e')), false); |
1226
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_URL_HLP, 'book_url', 50, 255, $item->getVar('book_url', 'e')), false); |
1227
|
|
|
|
1228
|
|
|
// Images ************************************************************* |
1229
|
|
View Code Duplication |
if ($op === 'editbook' && trim($item->getVar('book_image_url')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('book_image_url')))) { |
|
|
|
|
1230
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_IMAGE1_HELP, '<br>'); |
1231
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('book_image_url') . "' alt='' border='0' />")); |
1232
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture1'); |
1233
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
1234
|
|
|
$pictureTray->addElement($deleteCheckbox); |
1235
|
|
|
$sform->addElement($pictureTray); |
1236
|
|
|
unset($pictureTray, $deleteCheckbox); |
1237
|
|
|
} |
1238
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_IMAGE1_CHANGE, 'attachedfile1', bookshop_getmoduleoption('maxuploadsize')), false); |
1239
|
|
|
|
1240
|
|
View Code Duplication |
if ($op === 'editbook' && trim($item->getVar('book_thumb_url')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('book_thumb_url')))) { |
|
|
|
|
1241
|
|
|
$pictureTray = new XoopsFormElementTray(_AM_BOOKSHOP_IMAGE2_HELP, '<br>'); |
1242
|
|
|
$pictureTray->addElement(new XoopsFormLabel('', "<img src='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('book_thumb_url') . "' alt='' border='0' />")); |
1243
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delpicture2'); |
1244
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
1245
|
|
|
$pictureTray->addElement($deleteCheckbox); |
1246
|
|
|
$sform->addElement($pictureTray); |
1247
|
|
|
unset($pictureTray, $deleteCheckbox); |
1248
|
|
|
} |
1249
|
|
|
$sform->addElement(new XoopsFormFile(_AM_BOOKSHOP_IMAGE2_CHANGE, 'attachedfile2', bookshop_getmoduleoption('maxuploadsize')), false); |
1250
|
|
|
|
1251
|
|
|
// En ligne ? ********************************************************* |
1252
|
|
|
$sform->addElement(new XoopsFormRadioYN(_BOOKSHOP_ONLINE_HLP, 'book_online', $item->getVar('book_online')), true); |
1253
|
|
|
|
1254
|
|
|
// Recommand� ? |
1255
|
|
|
$sform->addElement(new XoopsFormRadioYN(_AM_BOOKSHOP_RECOMMENDED, 'book_isrecommended', $item->isRecommended()), false); |
1256
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_DATE, 'book_date', 50, 255, $item->getVar('book_date', 'e')), false); |
1257
|
|
|
|
1258
|
|
|
$date_submit = new XoopsFormTextDateSelect(_BOOKSHOP_DATE_SUBMIT, 'book_submitted', 15, $item->getVar('book_submitted', 'e')); |
1259
|
|
|
$date_submit->setDescription(_AM_BOOKSHOP_SUBDATE_HELP); |
1260
|
|
|
$sform->addElement($date_submit, false); |
1261
|
|
|
|
1262
|
|
|
$sform->addElement(new XoopsFormHidden('book_hits', $item->getVar('book_hits'))); |
1263
|
|
|
$sform->addElement(new XoopsFormHidden('book_rating', $item->getVar('book_rating'))); |
1264
|
|
|
$sform->addElement(new XoopsFormHidden('book_votes', $item->getVar('book_votes'))); |
1265
|
|
|
$sform->addElement(new XoopsFormHidden('book_comments', $item->getVar('book_comments'))); |
1266
|
|
|
|
1267
|
|
|
// Auteurs ************************************************************ |
1268
|
|
|
$tbl_authors = $tbl_book_authors = $tbl_authors_d = $tbl_book_authors_d = array(); |
1269
|
|
|
// Recherche de tous les auteurs |
1270
|
|
|
$criteria = new Criteria('auth_type', 1, '='); |
1271
|
|
|
$criteria->setSort('auth_name'); |
1272
|
|
|
$tbl_authors = $h_bookshop_authors->getObjects($criteria); |
1273
|
|
View Code Duplication |
foreach ($tbl_authors as $oneitem) { |
|
|
|
|
1274
|
|
|
$tbl_authors_d[$oneitem->getVar('auth_id')] = xoops_trim($oneitem->getVar('auth_name')) . ' ' . xoops_trim($oneitem->getVar('auth_firstname')); |
1275
|
|
|
} |
1276
|
|
|
// Recherche des auteurs de ce livre |
1277
|
|
View Code Duplication |
if ($edit) { |
|
|
|
|
1278
|
|
|
$criteria = new CriteriaCompo(); |
1279
|
|
|
$criteria->add(new Criteria('ba_type', 1, '=')); |
1280
|
|
|
$criteria->add(new Criteria('ba_book_id', $item->getVar('book_id'), '=')); |
1281
|
|
|
$tbl_book_authors = $h_bookshop_booksauthors->getObjects($criteria); |
1282
|
|
|
foreach ($tbl_book_authors as $onebook) { |
1283
|
|
|
$tbl_book_authors_d[] = $onebook->getVar('ba_auth_id'); |
1284
|
|
|
} |
1285
|
|
|
} |
1286
|
|
|
$author_select = new XoopsFormSelect(_BOOKSHOP_AUTHORS, 'authors', $tbl_book_authors_d, 5, true); |
1287
|
|
|
$author_select->addOptionArray($tbl_authors_d); |
1288
|
|
|
$author_select->setDescription(_AM_BOOKSHOP_SELECT_HLP); |
1289
|
|
|
$sform->addElement($author_select, true); |
1290
|
|
|
|
1291
|
|
|
// Traducteurs ******************************************************** |
1292
|
|
|
$tbl_translators = $tbl_book_translators = $tbl_translators_d = $tbl_book_translators_d = array(); |
1293
|
|
|
// Recherche de tous les auteurs |
1294
|
|
|
$criteria = new Criteria('auth_type', 2, '='); |
1295
|
|
|
$criteria->setSort('auth_name'); |
1296
|
|
|
$tbl_translators = $h_bookshop_authors->getObjects($criteria); |
1297
|
|
View Code Duplication |
foreach ($tbl_translators as $oneitem) { |
|
|
|
|
1298
|
|
|
$tbl_translators_d[$oneitem->getVar('auth_id')] = xoops_trim($oneitem->getVar('auth_name')) . ' ' . xoops_trim($oneitem->getVar('auth_firstname')); |
1299
|
|
|
} |
1300
|
|
|
// Recherche des traducteurs du livre ********************************* |
1301
|
|
View Code Duplication |
if ($edit) { |
|
|
|
|
1302
|
|
|
$criteria = new CriteriaCompo(); |
1303
|
|
|
$criteria->add(new Criteria('ba_type', 2, '=')); |
1304
|
|
|
$criteria->add(new Criteria('ba_book_id', $item->getVar('book_id'), '=')); |
1305
|
|
|
$tbl_book_translators = $h_bookshop_booksauthors->getObjects($criteria); |
1306
|
|
|
foreach ($tbl_book_translators as $onebook) { |
1307
|
|
|
$tbl_book_translators_d[] = $onebook->getVar('ba_auth_id'); |
1308
|
|
|
} |
1309
|
|
|
} |
1310
|
|
|
$translator_select = new XoopsFormSelect(_BOOKSHOP_TRANSLATORS, 'translators', $tbl_book_translators_d, 5, true); |
1311
|
|
|
$translator_select->addOptionArray($tbl_translators_d); |
1312
|
|
|
$translator_select->setDescription(_AM_BOOKSHOP_SELECT_HLP); |
1313
|
|
|
$sform->addElement($translator_select, false); |
1314
|
|
|
|
1315
|
|
|
// Livres relatifs **************************************************** |
1316
|
|
|
$tbl_related = $tbl_book_related = $tbl_related_d = $tbl_book_related_d = array(); |
1317
|
|
|
// Recherche de tous les livres sauf celui-l� |
1318
|
|
|
$criteria = new Criteria('book_id', $item->getVar('book_id'), '<>'); |
1319
|
|
|
$criteria->setSort('book_title'); |
1320
|
|
|
$tbl_related = $h_bookshop_books->getObjects($criteria); |
1321
|
|
|
foreach ($tbl_related as $oneitem) { |
1322
|
|
|
$tbl_related_d[$oneitem->getVar('book_id')] = xoops_trim($oneitem->getVar('book_title')); |
1323
|
|
|
} |
1324
|
|
|
// Recherche des livres relatifs � ce livre |
1325
|
|
|
if ($edit) { |
1326
|
|
|
$criteria = new CriteriaCompo(); |
1327
|
|
|
$criteria->add(new Criteria('related_book_id', $item->getVar('book_id'), '=')); |
1328
|
|
|
$tbl_book_related = $h_bookshop_related->getObjects($criteria); |
1329
|
|
|
foreach ($tbl_book_related as $onebook) { |
1330
|
|
|
$tbl_book_related_d[] = $onebook->getVar('related_book_related'); |
1331
|
|
|
} |
1332
|
|
|
} |
1333
|
|
|
$related_select = new XoopsFormSelect(_BOOKSHOP_RELATED_BOOKS, 'relatedbooks', $tbl_book_related_d, 5, true); |
1334
|
|
|
$related_select->setDescription(_AM_BOOKSHOP_RELATED_HELP . '<br>' . _AM_BOOKSHOP_SELECT_HLP); |
1335
|
|
|
$related_select->addOptionArray($tbl_related_d); |
1336
|
|
|
$sform->addElement($related_select, false); |
1337
|
|
|
// ******************************************************************** |
1338
|
|
|
|
1339
|
|
|
// TVA **************************************************************** |
1340
|
|
|
$vat_select = new XoopsFormSelect(_BOOKSHOP_VAT, 'book_vat_id', $item->getVar('book_vat_id')); |
1341
|
|
|
$vat_select->addOptionArray($tbl_vat_display); |
1342
|
|
|
$sform->addElement($vat_select, true); |
1343
|
|
|
|
1344
|
|
|
$TTC1 = $item->getVar('book_price', 'e'); |
1345
|
|
|
$TTC2 = $item->getVar('book_discount_price', 'e'); |
1346
|
|
|
if ($op === 'editbook') { |
1347
|
|
|
$bookVat = null; |
1348
|
|
|
$bookVat = $h_bookshop_vat->get($item->getVar('book_vat_id')); |
1349
|
|
|
if (is_object($bookVat)) { |
1350
|
|
|
$TTC1 = bookshop_getTTC((float)$TTC1, $bookVat->getVar('vat_rate'), true); |
1351
|
|
|
$TTC2 = bookshop_getTTC((float)$TTC2, $bookVat->getVar('vat_rate'), true); |
1352
|
|
|
} |
1353
|
|
|
} |
1354
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_PRICE, 'book_price', 20, 20, $TTC1), false); |
1355
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_DISCOUNT_HLP, 'book_discount_price', 20, 20, $TTC2), false); |
1356
|
|
|
|
1357
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_SHIPPING_PRICE, 'book_shipping_price', 20, 20, $item->getVar('book_shipping_price', 'e')), false); |
1358
|
|
|
$sform->addElement(new XoopsFormText(_BOOKSHOP_STOCK_QUANTITY, 'book_stock', 10, 10, $item->getVar('book_stock', 'e')), false); |
1359
|
|
|
|
1360
|
|
|
$alertStock = new XoopsFormText(_BOOKSHOP_STOCK_ALERT, 'book_alert_stock', 10, 10, $item->getVar('book_alert_stock', 'e')); |
1361
|
|
|
$alertStock->setDescription(_AM_BOOKSHOP_STOCK_HLP); |
1362
|
|
|
$sform->addElement($alertStock, false); |
1363
|
|
|
|
1364
|
|
|
$editor2 = bookshop_getWysiwygForm(_BOOKSHOP_SUMMARY, 'book_summary', $item->getVar('book_summary', 'e'), 15, 60, 'summary_hidden'); |
1365
|
|
|
if ($editor2) { |
1366
|
|
|
$sform->addElement($editor2, false); |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
$editor = bookshop_getWysiwygForm(_BOOKSHOP_DESCRIPTION, 'book_description', $item->getVar('book_description', 'e'), 15, 60, 'description_hidden'); |
1370
|
|
|
if ($editor) { |
1371
|
|
|
$sform->addElement($editor, false); |
1372
|
|
|
} |
1373
|
|
|
|
1374
|
|
|
// META Data |
1375
|
|
View Code Duplication |
if ($manual_meta) { |
|
|
|
|
1376
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_META_KEYWORDS, 'book_metakeywords', 50, 255, $item->getVar('book_metakeywords', 'e')), false); |
1377
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_META_DESCRIPTION, 'book_metadescription', 50, 255, $item->getVar('book_metadescription', 'e')), false); |
1378
|
|
|
$sform->addElement(new XoopsFormText(_AM_BOOKSHOP_META_PAGETITLE, 'book_metatitle', 50, 255, $item->getVar('book_metatitle', 'e')), false); |
1379
|
|
|
} |
1380
|
|
|
|
1381
|
|
|
if ($op === 'editbook' && trim($item->getVar('book_attachment')) != '' && file_exists(XOOPS_UPLOAD_PATH . '/' . trim($item->getVar('book_attachment')))) { |
1382
|
|
|
$attachedTray = new XoopsFormElementTray(_BOOKSHOP_ATTACHED_FILE, '<br>'); |
1383
|
|
|
$attachedTray->addElement(new XoopsFormLabel('', "<a href='" . XOOPS_UPLOAD_URL . '/' . $item->getVar('book_attachment') . "' target='_blank'>" . XOOPS_UPLOAD_URL . '/' . $item->getVar('book_attachment') . '</a>')); |
1384
|
|
|
$deleteCheckbox = new XoopsFormCheckBox('', 'delattach'); |
1385
|
|
|
$deleteCheckbox->addOption(1, _DELETE); |
1386
|
|
|
$attachedTray->addElement($deleteCheckbox); |
1387
|
|
|
$sform->addElement($attachedTray); |
1388
|
|
|
unset($attachedTray, $deleteCheckbox); |
1389
|
|
|
} |
1390
|
|
|
|
1391
|
|
|
// Attached file |
1392
|
|
|
$downloadFile = new XoopsFormFile(_BOOKSHOP_ATTACHED_FILE, 'attachedfile3', bookshop_getmoduleoption('maxuploadsize')); |
1393
|
|
|
$downloadFile->setDescription(_AM_BOOKSHOP_ATTACHED_HLP); |
1394
|
|
|
$sform->addElement($downloadFile, false); |
1395
|
|
|
|
1396
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
1397
|
|
|
$submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
1398
|
|
|
$button_tray->addElement($submit_btn); |
1399
|
|
|
$sform->addElement($button_tray); |
1400
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
1401
|
|
|
$sform->display(); |
1402
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
1403
|
|
|
break; |
1404
|
|
|
|
1405
|
|
|
// **************************************************************************************************************** |
1406
|
|
|
case 'saveeditbook': // Sauvegarde des informations d'un livre |
1407
|
|
|
// **************************************************************************************************************** |
1408
|
|
|
xoops_cp_header(); |
1409
|
|
|
$id = isset($_POST['book_id']) ? (int)$_POST['book_id'] : 0; |
1410
|
|
View Code Duplication |
if ($id > 0) { |
|
|
|
|
1411
|
|
|
$edit = true; |
1412
|
|
|
$item = $h_bookshop_books->get($id); |
1413
|
|
|
if (!is_object($item)) { |
1414
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
1415
|
|
|
} |
1416
|
|
|
$item->unsetNew(); |
1417
|
|
|
$add = false; |
1418
|
|
|
} else { |
1419
|
|
|
$item = $h_bookshop_books->create(true); |
1420
|
|
|
$edit = false; |
1421
|
|
|
$add = true; |
1422
|
|
|
} |
1423
|
|
|
|
1424
|
|
|
$item->setVars($_POST); |
1425
|
|
View Code Duplication |
if (isset($_POST['delpicture1']) && (int)$_POST['delpicture1'] == 1) { |
|
|
|
|
1426
|
|
|
$item->setVar('book_image_url', ''); |
1427
|
|
|
} |
1428
|
|
|
|
1429
|
|
View Code Duplication |
if (isset($_POST['delpicture2']) && (int)$_POST['delpicture2'] == 1) { |
|
|
|
|
1430
|
|
|
$item->setVar('book_thumb_url', ''); |
1431
|
|
|
} |
1432
|
|
|
|
1433
|
|
|
if (isset($_POST['delattach']) && (int)$_POST['delattach'] == 1) { |
1434
|
|
|
$item->setVar('book_attachment', ''); |
1435
|
|
|
} |
1436
|
|
|
|
1437
|
|
|
$item->setVar('book_submitted', strtotime($_POST['book_submitted'])); |
1438
|
|
|
// Calcul des HT |
1439
|
|
|
// On commence par r�cup�rer la TVA |
1440
|
|
|
$bookVat = null; |
1441
|
|
|
$bookVat = $h_bookshop_vat->get((int)$_POST['book_vat_id']); |
1442
|
|
|
if (is_object($bookVat)) { |
1443
|
|
|
$item->setVar('book_price', bookshop_getHT((float)$_POST['book_price'], $bookVat->getVar('vat_rate'))); |
1444
|
|
|
$item->setVar('book_discount_price', bookshop_getHT((float)$_POST['book_discount_price'], $bookVat->getVar('vat_rate'))); |
1445
|
|
|
} |
1446
|
|
|
|
1447
|
|
|
// Upload du fichier |
1448
|
|
|
if (bookshop_upload(0)) { |
1449
|
|
|
$item->setVar('book_image_url', basename($destname)); |
1450
|
|
|
} |
1451
|
|
|
|
1452
|
|
|
if (bookshop_upload(1)) { |
1453
|
|
|
$item->setVar('book_thumb_url', basename($destname)); |
1454
|
|
|
} |
1455
|
|
|
|
1456
|
|
|
if (bookshop_upload(2)) { |
1457
|
|
|
$item->setVar('book_attachment', basename($destname)); |
1458
|
|
|
} |
1459
|
|
|
|
1460
|
|
|
$res = $h_bookshop_books->insert($item); |
1461
|
|
|
if ($res) { |
1462
|
|
|
$id = $item->getVar('book_id'); |
1463
|
|
|
// Notifications ****************************************************** |
1464
|
|
|
if ($add == true) { |
|
|
|
|
1465
|
|
|
if ((int)$item->getVar('book_online') == 1) { |
1466
|
|
|
$notification_handler = xoops_getHandler('notification'); |
1467
|
|
|
$tags['BOOK_NAME'] = $item->getVar('book_title'); |
1468
|
|
|
$tags['BOOK_SUMMARY'] = strip_tags($item->getVar('book_summary')); |
1469
|
|
|
$tags['BOOK_URL'] = $h_bookshop_books->GetBookLink($item->getVar('book_id'), $item->getVar('book_title')); |
1470
|
|
|
$notification_handler->triggerEvent('global', 0, 'new_book', $tags); |
1471
|
|
|
} |
1472
|
|
|
} |
1473
|
|
|
// Gestion des auteurs ************************************************ |
1474
|
|
View Code Duplication |
if ($edit) { |
|
|
|
|
1475
|
|
|
// Suppression pr�alable |
1476
|
|
|
$criteria = new CriteriaCompo(); |
1477
|
|
|
$criteria->add(new Criteria('ba_book_id', $id, '=')); |
1478
|
|
|
$criteria->add(new Criteria('ba_type', 1, '=')); |
1479
|
|
|
$h_bookshop_booksauthors->deleteAll($criteria); |
1480
|
|
|
} |
1481
|
|
|
// Puis sauvegarde des donn�es |
1482
|
|
View Code Duplication |
if (isset($_POST['authors'])) { |
|
|
|
|
1483
|
|
|
foreach ($_POST['authors'] as $id2) { |
1484
|
|
|
$item2 = $h_bookshop_booksauthors->create(true); |
1485
|
|
|
$item2->setVar('ba_book_id', $id); |
1486
|
|
|
$item2->setVar('ba_auth_id', (int)$id2); |
1487
|
|
|
$item2->setVar('ba_type', 1); |
1488
|
|
|
$res = $h_bookshop_booksauthors->insert($item2); |
1489
|
|
|
} |
1490
|
|
|
} |
1491
|
|
|
|
1492
|
|
|
// Gestion des traducteurs ******************************************** |
1493
|
|
View Code Duplication |
if ($edit) { |
|
|
|
|
1494
|
|
|
// Suppression pr�alable |
1495
|
|
|
$criteria = new CriteriaCompo(); |
1496
|
|
|
$criteria->add(new Criteria('ba_book_id', $id, '=')); |
1497
|
|
|
$criteria->add(new Criteria('ba_type', 2, '=')); |
1498
|
|
|
$h_bookshop_booksauthors->deleteAll($criteria); |
1499
|
|
|
} |
1500
|
|
|
// Puis sauvegarde des donn�es |
1501
|
|
View Code Duplication |
if (isset($_POST['translators'])) { |
|
|
|
|
1502
|
|
|
foreach ($_POST['translators'] as $id2) { |
1503
|
|
|
$item2 = $h_bookshop_booksauthors->create(true); |
1504
|
|
|
$item2->setVar('ba_book_id', $id); |
1505
|
|
|
$item2->setVar('ba_auth_id', (int)$id2); |
1506
|
|
|
$item2->setVar('ba_type', 2); |
1507
|
|
|
$res = $h_bookshop_booksauthors->insert($item2); |
1508
|
|
|
} |
1509
|
|
|
} |
1510
|
|
|
|
1511
|
|
|
// Gestion des livres relatifs **************************************** |
1512
|
|
|
if ($edit) { |
1513
|
|
|
// Suppression pr�alable |
1514
|
|
|
$criteria = new CriteriaCompo(); |
1515
|
|
|
$criteria->add(new Criteria('related_book_id', $id, '=')); |
1516
|
|
|
$h_bookshop_related->deleteAll($criteria); |
1517
|
|
|
} |
1518
|
|
|
// Puis sauvegarde des donn�es |
1519
|
|
|
if (isset($_POST['relatedbooks'])) { |
1520
|
|
|
foreach ($_POST['relatedbooks'] as $id2) { |
1521
|
|
|
$item2 = $h_bookshop_related->create(true); |
1522
|
|
|
$item2->setVar('related_book_id', $id); |
1523
|
|
|
$item2->setVar('related_book_related', (int)$id2); |
1524
|
|
|
$res = $h_bookshop_related->insert($item2); |
1525
|
|
|
} |
1526
|
|
|
} |
1527
|
|
|
bookshop_updateCache(); |
1528
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=books', 2); |
1529
|
|
|
} else { |
1530
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=books', 5); |
1531
|
|
|
} |
1532
|
|
|
break; |
1533
|
|
|
|
1534
|
|
|
// **************************************************************************************************************** |
1535
|
|
|
case 'copybook': // Copier un livre |
1536
|
|
|
// **************************************************************************************************************** |
1537
|
|
|
xoops_cp_header(); |
1538
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
1539
|
|
|
if (empty($id)) { |
1540
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
1541
|
|
|
} |
1542
|
|
|
$book = null; |
1543
|
|
|
$book = $h_bookshop_books->get($id); |
1544
|
|
|
if (is_object($book)) { |
1545
|
|
|
$newBook = $book->xoopsClone(); |
1546
|
|
|
$newBook->setVar('book_title', $book->getvar('book_title') . ' ' . _AM_BOOKSHOP_DUPLICATED); |
1547
|
|
|
$newBook->setVar('book_id', 0); |
1548
|
|
|
$newBook->setNew(); |
1549
|
|
|
$res = $h_bookshop_books->insert($newBook, true); |
1550
|
|
|
if ($res) { |
1551
|
|
|
$newBookId = $newBook->getVar('book_id'); |
1552
|
|
|
// Copie des auteurs |
1553
|
|
|
$tblTmp = array(); |
1554
|
|
|
$criteria = new Criteria('ba_book_id', $book->getVar('book_id'), '='); |
1555
|
|
|
$tblTmp = $h_bookshop_booksauthors->getObjects($criteria); |
1556
|
|
View Code Duplication |
foreach ($tblTmp as $bookAuthor) { |
|
|
|
|
1557
|
|
|
$newBookAuthor = $bookAuthor->xoopsClone(); |
1558
|
|
|
$newBookAuthor->setVar('ba_book_id', $newBookId); |
1559
|
|
|
$newBookAuthor->setVar('ba_id', 0); |
1560
|
|
|
$newBookAuthor->setNew(); |
1561
|
|
|
$h_bookshop_booksauthors->insert($newBookAuthor, true); |
1562
|
|
|
} |
1563
|
|
|
// Copie des livres relatifs |
1564
|
|
|
$tblTmp = array(); |
1565
|
|
|
$criteria = new Criteria('related_book_id', $book->getVar('book_id'), '='); |
1566
|
|
|
$tblTmp = $h_bookshop_related->getObjects($criteria); |
1567
|
|
View Code Duplication |
foreach ($tblTmp as $related) { |
|
|
|
|
1568
|
|
|
$newRelated = $related->xoopsClone(); |
1569
|
|
|
$newRelated->setVar('related_book_id', $newBookId); |
1570
|
|
|
$newRelated->setVar('related_id', 0); |
1571
|
|
|
$newRelated->setNew(); |
1572
|
|
|
$h_bookshop_related->insert($newRelated, true); |
1573
|
|
|
} |
1574
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=books', 2); |
1575
|
|
|
} else { |
1576
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=books', 5); |
1577
|
|
|
} |
1578
|
|
|
} |
1579
|
|
|
break; |
1580
|
|
|
|
1581
|
|
|
// **************************************************************************************************************** |
1582
|
|
|
case 'deletebook': // Suppression d'un livre |
1583
|
|
|
// **************************************************************************************************************** |
1584
|
|
|
xoops_cp_header(); |
1585
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
1586
|
|
|
if ($id == 0) { |
1587
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
1588
|
|
|
} |
1589
|
|
|
$tblTmp = array(); |
1590
|
|
|
$tblTmp = $h_bookshop_caddy->getCommandIdFromBook($id); |
1591
|
|
|
if (count($tblTmp) == 0) { |
1592
|
|
|
// On commence par supprimer les commentaires |
1593
|
|
|
$mid = $xoopsModule->getVar('mid'); |
1594
|
|
|
xoops_comment_delete($mid, $id); |
1595
|
|
|
// Puis les votes |
1596
|
|
|
$criteria = new Criteria('vote_book_id', $id, '='); |
1597
|
|
|
$h_bookshop_votedata->deleteAll($criteria); |
1598
|
|
|
// Puis les livres relatifs |
1599
|
|
|
unset($criteria); |
1600
|
|
|
$criteria = new Criteria('related_book_id', $id, '='); |
1601
|
|
|
$h_bookshop_related->deleteAll($criteria); |
1602
|
|
|
// Puis le livre |
1603
|
|
|
$item = null; |
1604
|
|
|
$item = $h_bookshop_books->get($id); |
1605
|
|
|
if (is_object($item)) { |
1606
|
|
|
$res = $h_bookshop_books->delete($item, true); |
1607
|
|
|
if ($res) { |
1608
|
|
|
bookshop_updateCache(); |
1609
|
|
|
xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'new_book', $id); |
1610
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=books', 2); |
1611
|
|
|
} else { |
1612
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=books', 5); |
1613
|
|
|
} |
1614
|
|
|
} else { |
1615
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=books', 5); |
1616
|
|
|
} |
1617
|
|
|
} else { |
1618
|
|
|
// bookshop_adminMenu(5); |
|
|
|
|
1619
|
|
|
bookshop_htitle(_AM_BOOKSHOP_SORRY_NOREMOVE, 4); |
1620
|
|
|
$tblTmp2 = array(); |
1621
|
|
|
$tblTmp2 = $h_bookshop_commands->getObjects(new Criteria('cmd_id', '(' . implode(',', $tblTmp) . ')', 'IN'), true); |
1622
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
1623
|
|
|
$class = ''; |
1624
|
|
|
echo "<tr><th align='center'>" . _AM_BOOKSHOP_ID . "</th><th align='center'>" . _AM_BOOKSHOP_DATE . "</th><th align='center'>" . _AM_BOOKSHOP_CLIENT . "</th><th align='center'>" . _AM_BOOKSHOP_TOTAL_SHIPP . '</th></tr>'; |
1625
|
|
|
foreach ($tblTmp2 as $item) { |
1626
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
1627
|
|
|
$date = formatTimestamp(strtotime($item->getVar('cmd_date')), 's'); |
1628
|
|
|
echo "<tr class='" . $class . "'>\n"; |
1629
|
|
|
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') . ' ' |
1630
|
|
|
. bookshop_getmoduleoption('money_short') . ' / ' . $item->getVar('cmd_shipping') . ' ' . bookshop_getmoduleoption('money_short') . "</td>\n"; |
1631
|
|
|
echo "<tr>\n"; |
1632
|
|
|
} |
1633
|
|
|
echo '</table>'; |
1634
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
1635
|
|
|
} |
1636
|
|
|
break; |
1637
|
|
|
|
1638
|
|
|
// **************************************************************************************************************** |
1639
|
|
|
case 'discount': // Gestion des r�ductions |
1640
|
|
|
// **************************************************************************************************************** |
1641
|
|
|
xoops_cp_header(); |
1642
|
|
|
// bookshop_adminMenu(7); |
|
|
|
|
1643
|
|
|
$indexAdmin = new ModuleAdmin(); |
1644
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=discount'); |
1645
|
|
|
|
1646
|
|
|
echo "<form method='post' action='$baseurl' name='frmadddiscount' id='frmadddiscount'><input type='hidden' name='op' id='op' value='adddiscount' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form>"; |
1647
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU6, 4); |
1648
|
|
|
|
1649
|
|
|
$tbl_discount = $tbl_groups = $tbl_on = $tbl_when = array(); |
1650
|
|
|
$discount_count = 0; |
1651
|
|
|
|
1652
|
|
|
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
1653
|
|
|
$tbl_on = array(_BOOKSHOP_DISCOUNT4, _BOOKSHOP_DISCOUNT5, _BOOKSHOP_DISCOUNT6, _BOOKSHOP_DISCOUNT7); |
1654
|
|
|
$tbl_when = array(_BOOKSHOP_DISCOUNT8, _BOOKSHOP_DISCOUNT9, _BOOKSHOP_DISCOUNT10, _BOOKSHOP_DISCOUNT15); |
1655
|
|
|
|
1656
|
|
|
$discount_count = $h_bookshop_discounts->getCount(); // Recherche du nombre total d'auteurs |
1657
|
|
|
$pagenav = new XoopsPageNav($discount_count, $limit, $start, 'start', 'op=discount'); |
1658
|
|
|
|
1659
|
|
|
$criteria = new Criteria('disc_id', 0, '<>'); |
1660
|
|
|
$criteria->setLimit($limit); |
1661
|
|
|
$criteria->setStart($start); |
1662
|
|
|
|
1663
|
|
|
// Chargement de la liste des groupes Xoops |
1664
|
|
|
$member_handler = xoops_getHandler('member'); |
1665
|
|
|
$tbl_groups = $member_handler->getGroupList(); |
1666
|
|
|
|
1667
|
|
|
$tbl_discount = $h_bookshop_discounts->getObjects($criteria); |
1668
|
|
|
$class = ''; |
1669
|
|
|
$money = bookshop_getmoduleoption('money_short'); |
1670
|
|
|
|
1671
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
1672
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_GROUP . "</th><th align='center'>" . _BOOKSHOP_DISCOUNT1 . "</th><th align='center'>" . _BOOKSHOP_DISCOUNT3 . "</th><th align='center'>" . _BOOKSHOP_DISCOUNT14 . "</th><th align='center'>" . _BOOKSHOP_DISCOUNT7 . "</th><th align='center'>" |
1673
|
|
|
. _AM_BOOKSHOP_ACTION . '</th></tr>'; |
1674
|
|
|
foreach ($tbl_discount as $item) { |
1675
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
1676
|
|
|
$action_edit = "<a href='$baseurl?op=editdiscount&id=" . $item->getVar('disc_id') . "' title='" . _BOOKSHOP_EDIT . "'>" . $icones['edit'] . '</a>'; |
1677
|
|
|
$action_delete = "<a href='$baseurl?op=deletediscount&id=" . $item->getVar('disc_id') . "' title='" . _BOOKSHOP_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
1678
|
|
|
echo "<tr class='" . $class . "'>\n"; |
1679
|
|
|
$nature = $item->getVar('disc_percent_monney') == 0 ? _BOOKSHOP_DISCOUNT2 : $money; |
1680
|
|
|
if ($item->getVar('disc_shipping') == 0) { |
1681
|
|
|
$shippings = _BOOKSHOP_DISCOUNT11; |
1682
|
|
|
} else { |
1683
|
|
|
$shippings = _BOOKSHOP_DISCOUNT12; |
1684
|
|
|
if ($item->getVar('disc_if_amount') > 0) { |
1685
|
|
|
$amount = bookshop_formatMoney($item->getVar('disc_if_amount')); |
1686
|
|
|
$shippings .= ' ' . sprintf(_BOOKSHOP_DISCOUNT13, $amount, $money); |
1687
|
|
|
} |
1688
|
|
|
} |
1689
|
|
|
if ($item->getVar('disc_when') != DISCOUNT_WHEN4) { |
1690
|
|
|
$on_when = $tbl_when[$item->getVar('disc_when')]; |
1691
|
|
|
} else { |
1692
|
|
|
$tblCriteriaQty = array('=', '>', '>=', '<', '<='); |
1693
|
|
|
$on_when = $tbl_when[$item->getVar('disc_when')] . $tblCriteriaQty[$item->getVar('disc_qty_criteria')] . ' ' . $item->getVar('disc_qty_value'); |
1694
|
|
|
} |
1695
|
|
|
echo '<td>' . $tbl_groups[$item->getVar('disc_group')] . "</td><td align='left'>" . $item->getVar('disc_amount') . ' ' . $nature . "</td><td align='center'>" . $tbl_on[$item->getVar('disc_on_what')] . "</td><td align='center'>" . $on_when . "</td><td align='center'>" . $shippings |
1696
|
|
|
. "</td><td align='center'>" . $action_edit . ' ' . $action_delete . "</td>\n"; |
1697
|
|
|
echo "<tr>\n"; |
1698
|
|
|
} |
1699
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
1700
|
|
|
echo "<tr class='" . $class . "'>\n"; |
1701
|
|
|
echo "<td colspan='6' align='center'><form method='post' action='$baseurl' name='frmadddiscount' id='frmadddiscount'><input type='hidden' name='op' id='op' value='adddiscount' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_ADD_ITEM . "' /></form></td>\n"; |
1702
|
|
|
echo "</tr>\n"; |
1703
|
|
|
echo '</table>'; |
1704
|
|
|
echo "<div align='right'>" . $pagenav->renderNav() . '</div>'; |
1705
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
1706
|
|
|
break; |
1707
|
|
|
|
1708
|
|
|
// **************************************************************************************************************** |
1709
|
|
|
case 'adddiscount': // Ajout d'une promotion |
1710
|
|
|
case 'editdiscount': // Edition d'une promo |
1711
|
|
|
// **************************************************************************************************************** |
1712
|
|
|
xoops_cp_header(); |
1713
|
|
|
// bookshop_adminMenu(7); |
|
|
|
|
1714
|
|
|
$indexAdmin = new ModuleAdmin(); |
1715
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=discount'); |
1716
|
|
|
|
1717
|
|
|
if ($op === 'editdiscount') { |
1718
|
|
|
$title = _AM_BOOKSHOP_EDIT_DISCOUNT; |
1719
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
1720
|
|
|
if (empty($id)) { |
1721
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
1722
|
|
|
} |
1723
|
|
|
// Item exits ? |
1724
|
|
|
$item = null; |
1725
|
|
|
$item = $h_bookshop_discounts->get($id); |
1726
|
|
|
if (!is_object($item)) { |
1727
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
1728
|
|
|
} |
1729
|
|
|
$edit = true; |
1730
|
|
|
$label_submit = _AM_BOOKSHOP_MODIFY; |
1731
|
|
|
} else { |
1732
|
|
|
$title = _AM_BOOKSHOP_ADD_DSICOUNT; |
1733
|
|
|
$item = $h_bookshop_discounts->create(true); |
1734
|
|
|
$label_submit = _AM_BOOKSHOP_ADD; |
1735
|
|
|
$edit = false; |
1736
|
|
|
} |
1737
|
|
|
$money = bookshop_getmoduleoption('money_full'); |
1738
|
|
|
$sform = new XoopsThemeForm($title, 'frmadddiscount', $baseurl); |
1739
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'saveeditdiscount')); |
1740
|
|
|
$sform->addElement(new XoopsFormHidden('disc_id', $item->getVar('disc_id'))); |
1741
|
|
|
|
1742
|
|
|
$group_select = new XoopsFormSelect(_BOOKSHOP_GROUP, 'disc_group', $item->getVar('disc_group')); |
1743
|
|
|
$member_handler = xoops_getHandler('member'); |
1744
|
|
|
$tbl_groups = array(); |
1745
|
|
|
$tbl_groups = $member_handler->getGroupList(); |
1746
|
|
|
$group_select->addOptionArray($tbl_groups); |
1747
|
|
|
$sform->addElement($group_select, true); |
1748
|
|
|
|
1749
|
|
|
$apply_tray = new XoopsFormElementTray(_BOOKSHOP_DISCOUNT1, ''); |
1750
|
|
|
$zone1 = new XoopsFormText('', 'disc_amount', 10, 15, $item->getVar('disc_amount', 'e')); |
1751
|
|
|
$apply_tray->addElement($zone1, true); |
1752
|
|
|
|
1753
|
|
|
$radio_type = new XoopsFormRadio('', 'disc_percent_monney', $item->getVar('disc_percent_monney', 'e')); |
1754
|
|
|
$radio_type->addOptionArray(array(DISCOUNT_TYPE1 => _BOOKSHOP_DISCOUNT2, DISCOUNT_TYPE2 => $money)); |
1755
|
|
|
$apply_tray->addElement($radio_type, true); |
1756
|
|
|
$sform->addElement($apply_tray); |
1757
|
|
|
|
1758
|
|
|
$radio_on = new XoopsFormRadio(_BOOKSHOP_DISCOUNT3, 'disc_on_what', $item->getVar('disc_on_what', 'e')); |
1759
|
|
|
$radio_on->addOptionArray(array(DISCOUNT_ON1 => _BOOKSHOP_DISCOUNT4 . '<br>', DISCOUNT_ON2 => _BOOKSHOP_DISCOUNT5 . '<br>', DISCOUNT_ON3 => _BOOKSHOP_DISCOUNT6 . '<br>', DISCOUNT_ON4 => _BOOKSHOP_DISCOUNT7 . '<br>', DISCOUNT_ON5 => _BOOKSHOP_DISCOUNT71 . '<br>')); |
1760
|
|
|
$sform->addElement($radio_on, true); |
1761
|
|
|
|
1762
|
|
|
$when_tray = new XoopsFormElementTray(_BOOKSHOP_DISCOUNT14, ''); |
1763
|
|
|
$radio_when = new XoopsFormRadio('', 'disc_when', $item->getVar('disc_when', 'e')); |
1764
|
|
|
$radio_when->addOptionArray(array(DISCOUNT_WHEN1 => _BOOKSHOP_DISCOUNT8 . '<br>', DISCOUNT_WHEN2 => _BOOKSHOP_DISCOUNT9 . '<br>', DISCOUNT_WHEN3 => _BOOKSHOP_DISCOUNT10 . '<br>', DISCOUNT_WHEN4 => _BOOKSHOP_DISCOUNT15)); |
1765
|
|
|
$when_tray->addElement($radio_when, true); |
1766
|
|
|
|
1767
|
|
|
$qty_when_select = new XoopsFormSelect('', 'disc_qty_criteria', $item->getVar('disc_qty_criteria')); |
1768
|
|
|
$qty_when_select->addOptionArray(array('=', '>', '>=', '<', '<=')); |
1769
|
|
|
$when_tray->addElement($qty_when_select, false); |
1770
|
|
|
|
1771
|
|
|
$disc_qty_value = new XoopsFormText('', 'disc_qty_value', 10, 10, $item->getVar('disc_qty_value', 'e')); |
1772
|
|
|
$when_tray->addElement($disc_qty_value, false); |
1773
|
|
|
$sform->addElement($when_tray, true); |
1774
|
|
|
|
1775
|
|
|
$shipping_tray = new XoopsFormElementTray(_BOOKSHOP_DISCOUNT7, ''); |
1776
|
|
|
$radio_shipping = new XoopsFormRadio('', 'disc_shipping', $item->getVar('disc_shipping', 'e')); |
1777
|
|
|
$radio_shipping->addOptionArray(array(DISCOUNT_SHIPPING1 => _BOOKSHOP_DISCOUNT11 . '<br>', DISCOUNT_SHIPPING2 => _BOOKSHOP_DISCOUNT12 . '<br>', DISCOUNT_SHIPPING3 => _BOOKSHOP_DISCOUNT121)); |
1778
|
|
|
$shipping_tray->addElement($radio_shipping); |
1779
|
|
|
$shipping_tray->addElement(new XoopsFormText('', 'disc_shipping_amount', 10, 10, $item->getVar('disc_shipping_amount', 'e')), false); |
1780
|
|
|
$shipping_tray->addElement(new XoopsFormText(sprintf(_BOOKSHOP_DISCOUNT1212, bookshop_getmoduleoption('money_full')), 'disc_shipping_amount_next', 10, 10, $item->getVar('disc_shipping_amount_next', 'e')), false); |
1781
|
|
|
$shipping_tray->addElement(new XoopsFormLabel(sprintf('<br>' . _BOOKSHOP_DISCOUNT1213, bookshop_getmoduleoption('money_full')), ''), false); |
1782
|
|
|
|
1783
|
|
|
$sform->addElement($shipping_tray, true); |
1784
|
|
|
|
1785
|
|
|
$libelle = sprintf(_BOOKSHOP_DISCOUNT131, $money); |
1786
|
|
|
$sform->addElement(new XoopsFormText($libelle, 'disc_if_amount', 10, 15, $item->getVar('disc_if_amount', 'e')), false); |
1787
|
|
|
|
1788
|
|
|
$editor = bookshop_getWysiwygForm(_AM_BOOKSHOP_DISCOUNT_DESCR, 'disc_description', $item->getVar('disc_description', 'e'), 15, 60, 'description_hidden'); |
1789
|
|
|
if ($editor) { |
1790
|
|
|
$sform->addElement($editor, false); |
1791
|
|
|
} |
1792
|
|
|
|
1793
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
1794
|
|
|
$submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
1795
|
|
|
$button_tray->addElement($submit_btn); |
1796
|
|
|
$sform->addElement($button_tray); |
1797
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
1798
|
|
|
$sform->display(); |
1799
|
|
|
|
1800
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
1801
|
|
|
break; |
1802
|
|
|
|
1803
|
|
|
// **************************************************************************************************************** |
1804
|
|
View Code Duplication |
case 'saveeditdiscount': |
|
|
|
|
1805
|
|
|
// **************************************************************************************************************** |
1806
|
|
|
xoops_cp_header(); |
1807
|
|
|
$id = isset($_POST['disc_id']) ? (int)$_POST['disc_id'] : 0; |
1808
|
|
|
if (!empty($id)) { |
1809
|
|
|
$edit = true; |
1810
|
|
|
$item = $h_bookshop_discounts->get($id); |
1811
|
|
|
if (!is_object($item)) { |
1812
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl, 5); |
1813
|
|
|
} |
1814
|
|
|
$item->unsetNew(); |
1815
|
|
|
} else { |
1816
|
|
|
$item = $h_bookshop_discounts->create(true); |
1817
|
|
|
} |
1818
|
|
|
$item->setVars($_POST); |
1819
|
|
|
$res = $h_bookshop_discounts->insert($item, true); |
1820
|
|
|
if ($res) { |
1821
|
|
|
bookshop_updateCache(); |
1822
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=discount', 2); |
1823
|
|
|
} else { |
1824
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=discount', 5); |
1825
|
|
|
} |
1826
|
|
|
break; |
1827
|
|
|
|
1828
|
|
|
// **************************************************************************************************************** |
1829
|
|
|
case 'deletediscount': |
1830
|
|
|
// **************************************************************************************************************** |
1831
|
|
|
xoops_cp_header(); |
1832
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
1833
|
|
|
if (empty($id)) { |
1834
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
1835
|
|
|
} |
1836
|
|
|
$item = $h_bookshop_discounts->get($id); |
1837
|
|
View Code Duplication |
if (is_object($item)) { |
|
|
|
|
1838
|
|
|
$res = $h_bookshop_discounts->delete($item, true); |
1839
|
|
|
if ($res) { |
1840
|
|
|
bookshop_updateCache(); |
1841
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=discount', 2); |
1842
|
|
|
} else { |
1843
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=discount', 5); |
1844
|
|
|
} |
1845
|
|
|
} else { |
1846
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=discount', 5); |
1847
|
|
|
} |
1848
|
|
|
break; |
1849
|
|
|
|
1850
|
|
|
// **************************************************************************************************************** |
1851
|
|
|
case 'deletecommand': // Suppression d'une commande |
1852
|
|
|
// **************************************************************************************************************** |
1853
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
1854
|
|
|
if (empty($id)) { |
1855
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
1856
|
|
|
} |
1857
|
|
|
$item = $h_bookshop_commands->get($id); |
1858
|
|
|
if (is_object($item)) { |
1859
|
|
|
$res = $h_bookshop_commands->delete($item, true); |
1860
|
|
|
if ($res) { |
1861
|
|
|
// Suppression des caddy associ�s |
1862
|
|
|
$criteria = new Criteria('caddy_cmd_id', $id, '='); |
1863
|
|
|
$h_bookshop_caddy->deleteAll($criteria); |
1864
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=commands', 2); |
1865
|
|
|
} else { |
1866
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=commands', 5); |
1867
|
|
|
} |
1868
|
|
|
} else { |
1869
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=commands', 5); |
1870
|
|
|
} |
1871
|
|
|
break; |
1872
|
|
|
|
1873
|
|
|
// **************************************************************************************************************** |
1874
|
|
|
case 'validatecmd': // Validation d'une commande |
1875
|
|
|
// **************************************************************************************************************** |
1876
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
1877
|
|
|
if (empty($id)) { |
1878
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
1879
|
|
|
} |
1880
|
|
|
$item = $h_bookshop_commands->get($id); |
1881
|
|
View Code Duplication |
if (is_object($item)) { |
|
|
|
|
1882
|
|
|
$res = $h_bookshop_commands->validateCommand($id); |
1883
|
|
|
if ($res) { |
1884
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=commands', 2); |
1885
|
|
|
} else { |
1886
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=commands', 5); |
1887
|
|
|
} |
1888
|
|
|
} else { |
1889
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=commands', 5); |
1890
|
|
|
} |
1891
|
|
|
break; |
1892
|
|
|
|
1893
|
|
|
// **************************************************************************************************************** |
1894
|
|
|
case 'commands': // Gestion des commandes |
1895
|
|
|
// **************************************************************************************************************** |
1896
|
|
|
xoops_cp_header(); |
1897
|
|
|
// bookshop_adminMenu(6); |
|
|
|
|
1898
|
|
|
$indexAdmin = new ModuleAdmin(); |
1899
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=commands'); |
1900
|
|
|
|
1901
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU5, 4); |
1902
|
|
|
|
1903
|
|
|
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
1904
|
|
|
$filter3 = 0; |
1905
|
|
View Code Duplication |
if (isset($_POST['filter3'])) { |
|
|
|
|
1906
|
|
|
$filter3 = (int)$_POST['filter3']; |
1907
|
|
|
} elseif (isset($_SESSION['filter3'])) { |
1908
|
|
|
$filter3 = (int)$_SESSION['filter3']; |
1909
|
|
|
} else { |
1910
|
|
|
$filter3 = 1; |
1911
|
|
|
} |
1912
|
|
|
$_SESSION['filter3'] = $filter3; |
1913
|
|
|
$selected = array('', '', '', '', '', ''); |
1914
|
|
|
$tblConditions = array(COMMAND_STATE_NOINFORMATION, COMMAND_STATE_VALIDATED, COMMAND_STATE_PENDING, COMMAND_STATE_FAILED, COMMAND_STATE_CANCELED, COMMAND_STATE_FRAUD); |
1915
|
|
|
$selected[$filter3] = " selected='selected'"; |
1916
|
|
|
|
1917
|
|
|
$criteria = new CriteriaCompo(); |
1918
|
|
|
$criteria->add(new Criteria('cmd_id', 0, '<>')); |
1919
|
|
|
$criteria->add(new Criteria('cmd_state', $tblConditions[$filter3], '=')); |
1920
|
|
|
$commandsCount = $h_bookshop_commands->getCount($criteria); // Recherche du nombre total d'auteurs |
1921
|
|
|
$pagenav = new XoopsPageNav($commandsCount, $limit, $start, 'start', 'op=commands'); |
1922
|
|
|
$criteria->setSort('cmd_date'); |
1923
|
|
|
$criteria->setOrder('DESC'); |
1924
|
|
|
$criteria->setLimit($limit); |
1925
|
|
|
$criteria->setStart($start); |
1926
|
|
|
$tblCommands = $h_bookshop_commands->getObjects($criteria); |
1927
|
|
|
$class = ''; |
1928
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
1929
|
|
|
$form = |
1930
|
|
|
"<form method='post' name='frmfilter' id='frmfilter' action='$baseurl'>" . _AM_BOOKSHOP_LIMIT_TO . " <select name='filter3' id='filter3'><option value='0'" . $selected[0] . '>' . _BOOKSHOP_CMD_STATE1 . "</option><option value='1'" . $selected[1] . '>' . _BOOKSHOP_CMD_STATE2 |
1931
|
|
|
. "</option><option value='2'" . $selected[2] . '>' . _BOOKSHOP_CMD_STATE3 . "</option><option value='3'" . $selected[3] . '>' . _BOOKSHOP_CMD_STATE4 . "</option><option value='4'" . $selected[4] . '>' . _BOOKSHOP_CMD_STATE5 . "</option><option value='5'" . $selected[5] . '>' |
1932
|
|
|
. _BOOKSHOP_CMD_STATE6 . "</option></select> <input type='hidden' name='op' id='op' value='commands' /><input type='submit' name='btnfilter' id='btnfilter' value='" . _AM_BOOKSHOP_FILTER . "' /></form>"; |
1933
|
|
|
$confValidateCommand = bookshop_JavascriptLinkConfirm(_AM_BOOKSHOP_CONF_VALIDATE); |
1934
|
|
|
echo "<tr><td colspan='2' align='left'>" . $pagenav->renderNav() . "</td><td><a href='$baseurl?op=csv&cmdtype=" . $filter3 . "'>" . _AM_BOOKSHOP_CSV_EXPORT . "</a></td><td align='right' colspan='2'>" . $form . "</td></tr>\n"; |
1935
|
|
|
echo "<tr><th align='center'>" . _AM_BOOKSHOP_ID . "</th><th align='center'>" . _AM_BOOKSHOP_DATE . "</th><th align='center'>" . _AM_BOOKSHOP_CLIENT . "</th><th align='center'>" . _AM_BOOKSHOP_TOTAL_SHIPP . "</th><th align='center'>" . _AM_BOOKSHOP_ACTION . '</th></tr>'; |
1936
|
|
|
foreach ($tblCommands as $item) { |
1937
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
1938
|
|
|
$date = formatTimestamp(strtotime($item->getVar('cmd_date')), 's'); |
1939
|
|
|
$action_edit = "<a target='_blank' href='detailscmd.php?id=" . $item->getVar('cmd_id') . "' title='" . _BOOKSHOP_DETAILS . "'>" . $icones['details'] . '</a>'; |
1940
|
|
|
$action_delete = "<a href='$baseurl?op=deletecommand&id=" . $item->getVar('cmd_id') . "' title='" . _BOOKSHOP_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
1941
|
|
|
$action_vaidate = "<a target='_blank' href='$baseurl?op=validatecmd&id=" . $item->getVar('cmd_id') . "' " . $confValidateCommand . " title='" . _BOOKSHOP_VALIDATE_COMMAND . "'>" . $icones['ok'] . '</a>'; |
1942
|
|
|
echo "<tr class='" . $class . "'>\n"; |
1943
|
|
|
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') . ' ' |
1944
|
|
|
. bookshop_getmoduleoption('money_short') . ' / ' . $item->getVar('cmd_shipping') . ' ' . bookshop_getmoduleoption('money_short') . "</td><td align='center'>" . $action_vaidate . ' ' . $action_edit . ' ' . $action_delete . "</td>\n"; |
1945
|
|
|
echo "<tr>\n"; |
1946
|
|
|
} |
1947
|
|
|
echo '</table>'; |
1948
|
|
|
echo "<div align='right'>" . $pagenav->renderNav() . '</div>'; |
1949
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
1950
|
|
|
break; |
1951
|
|
|
|
1952
|
|
|
// **************************************************************************************************************** |
1953
|
|
|
case 'csv': // Export des commandes au format CSV |
1954
|
|
|
// **************************************************************************************************************** |
1955
|
|
|
xoops_cp_header(); |
1956
|
|
|
// bookshop_adminMenu(6); |
|
|
|
|
1957
|
|
|
$indexAdmin = new ModuleAdmin(); |
1958
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=csv'); |
1959
|
|
|
|
1960
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU5, 4); |
1961
|
|
|
$cmd_type = (int)$_GET['cmdtype']; |
1962
|
|
|
$fp = fopen(XOOPS_UPLOAD_PATH . '/bookshop.csv', 'w'); |
1963
|
|
|
if ($fp) { |
1964
|
|
|
// Cr�ation de l'ent�te du fichier |
1965
|
|
|
$entete1 = $entete2 = array(); |
1966
|
|
|
$s = '|'; |
1967
|
|
|
$cmd = new bookshop_commands(); |
1968
|
|
|
foreach ($cmd->getVars() as $fieldName => $properties) { |
1969
|
|
|
$entete1[] = $fieldName; |
1970
|
|
|
} |
1971
|
|
|
// Ajout des infos de caddy |
1972
|
|
|
$cart = new bookshop_caddy(); |
1973
|
|
|
foreach ($cart->getVars() as $fieldName => $properties) { |
1974
|
|
|
$entete2[] = $fieldName; |
1975
|
|
|
} |
1976
|
|
|
fwrite($fp, implode($s, array_merge($entete1, $entete2)) . "\n"); |
1977
|
|
|
|
1978
|
|
|
$criteria = new CriteriaCompo(); |
1979
|
|
|
$criteria->add(new Criteria('cmd_id', 0, '<>')); |
1980
|
|
|
$criteria->add(new Criteria('cmd_state', $cmd_type, '=')); |
1981
|
|
|
$criteria->setSort('cmd_date'); |
1982
|
|
|
$criteria->setOrder('DESC'); |
1983
|
|
|
$tblCommands = $h_bookshop_commands->getObjects($criteria); |
1984
|
|
|
foreach ($tblCommands as $commande) { |
1985
|
|
|
$tblTmp = array(); |
1986
|
|
|
$tblTmp = $h_bookshop_caddy->getObjects(new Criteria('caddy_cmd_id', $commande->getVar('cmd_id'), '=')); |
1987
|
|
|
$ligne = array(); |
1988
|
|
|
foreach ($tblTmp as $caddy) { |
1989
|
|
|
foreach ($entete1 as $commandField) { |
1990
|
|
|
$ligne[] = $commande->getVar($commandField); |
1991
|
|
|
} |
1992
|
|
|
foreach ($entete2 as $caddyField) { |
1993
|
|
|
$ligne[] = $caddy->getVar($caddyField); |
1994
|
|
|
} |
1995
|
|
|
} |
1996
|
|
|
fwrite($fp, implode($s, $ligne) . "\n"); |
1997
|
|
|
} |
1998
|
|
|
fclose($fp); |
1999
|
|
|
echo "<a target='_blank' href='" . XOOPS_UPLOAD_URL . "/bookshop.csv'>" . _AM_BOOKSHOP_CSV_READY . '</a>'; |
2000
|
|
|
} else { |
2001
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_7); |
2002
|
|
|
} |
2003
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
2004
|
|
|
break; |
2005
|
|
|
|
2006
|
|
|
// **************************************************************************************************************** |
2007
|
|
|
case 'newsletter': // Cr�ation de la newsletter |
2008
|
|
|
// **************************************************************************************************************** |
2009
|
|
|
xoops_cp_header(); |
2010
|
|
|
// bookshop_adminMenu(8); |
|
|
|
|
2011
|
|
|
$indexAdmin = new ModuleAdmin(); |
2012
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=newsletter'); |
2013
|
|
|
|
2014
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU7, 4); |
2015
|
|
|
include_once BOOKSHOP_PATH . 'class/tree.php'; |
2016
|
|
|
$sform = new XoopsThemeForm(_MI_BOOKSHOP_ADMENU7, 'frmnewsletter', $baseurl); |
2017
|
|
|
$dates_tray = new XoopsFormElementTray(_AM_BOOKSHOP_NEWSLETTER_BETWEEN); |
2018
|
|
|
$minDate = $maxDate = 0; |
2019
|
|
|
$h_bookshop_books->getMinMaxPublishedDate($minDate, $maxDate); |
2020
|
|
|
$date1 = new XoopsFormTextDateSelect('', 'date1', 15, $minDate); |
2021
|
|
|
$date2 = new XoopsFormTextDateSelect(_AM_BOOKSHOP_EXPORT_AND, 'date2', 15, $maxDate); |
2022
|
|
|
$dates_tray->addElement($date1); |
2023
|
|
|
$dates_tray->addElement($date2); |
2024
|
|
|
$sform->addElement($dates_tray); |
2025
|
|
|
$tbl_categories = $h_bookshop_cat->GetAllCategories(); |
2026
|
|
|
$mytree = new Bookshop_XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
2027
|
|
|
$htmlSelect = $mytree->makeSelBox('cat_cid', 'cat_title', '-', 0, _AM_BOOKSHOP_ALL); |
2028
|
|
|
$sform->addElement(new XoopsFormLabel(_AM_BOOKSHOP_IN_CATEGORY, $htmlSelect), true); |
2029
|
|
|
$sform->addElement(new XoopsFormHidden('op', 'launchnewsletter'), false); |
2030
|
|
|
$sform->addElement(new XoopsFormRadioYN(_AM_BOOKSHOP_REMOVE_BR, 'removebr', 1), false); |
2031
|
|
|
$sform->addElement(new XoopsFormRadioYN(_AM_BOOKSHOP_NEWSLETTER_HTML_TAGS, 'removehtml', 0), false); |
2032
|
|
|
$sform->addElement(new XoopsFormTextArea(_AM_BOOKSHOP_NEWSLETTER_HEADER, 'header', '', 4, 70), false); |
2033
|
|
|
$sform->addElement(new XoopsFormTextArea(_AM_BOOKSHOP_NEWSLETTER_FOOTER, 'footer', '', 4, 70), false); |
2034
|
|
|
$button_tray = new XoopsFormElementTray('', ''); |
2035
|
|
|
$submit_btn = new XoopsFormButton('', 'post', _SUBMIT, 'submit'); |
2036
|
|
|
$button_tray->addElement($submit_btn); |
2037
|
|
|
$sform->addElement($button_tray); |
2038
|
|
|
$sform = bookshop_formMarkRequiredFields($sform); |
2039
|
|
|
$sform->display(); |
2040
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
2041
|
|
|
break; |
2042
|
|
|
|
2043
|
|
|
// **************************************************************************************************************** |
2044
|
|
|
case 'launchnewsletter': // Cr�ation effective de la newsletter |
2045
|
|
|
// **************************************************************************************************************** |
2046
|
|
|
xoops_cp_header(); |
2047
|
|
|
// bookshop_adminMenu(8); |
|
|
|
|
2048
|
|
|
$indexAdmin = new ModuleAdmin(); |
2049
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=newsletter'); |
2050
|
|
|
|
2051
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU7, 4); |
2052
|
|
|
|
2053
|
|
|
$newslettertemplate = ''; |
2054
|
|
View Code Duplication |
if (file_exists(BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/newsletter.php')) { |
|
|
|
|
2055
|
|
|
include_once BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/newsletter.php'; |
2056
|
|
|
} else { |
2057
|
|
|
include_once BOOKSHOP_PATH . 'language/english/newsletter.php'; |
2058
|
|
|
} |
2059
|
|
|
echo '<br>'; |
2060
|
|
|
$removebr = $removehtml = false; |
2061
|
|
|
$removebr = isset($_POST['removebr']) ? (int)$_POST['removebr'] : 0; |
2062
|
|
|
$removehtml = isset($_POST['removehtml']) ? (int)$_POST['removehtml'] : 0; |
2063
|
|
|
$header = isset($_POST['header']) ? $_POST['header'] : ''; |
2064
|
|
|
$footer = isset($_POST['footer']) ? $_POST['footer'] : ''; |
2065
|
|
|
$date1 = strtotime($_POST['date1']); |
2066
|
|
|
$date2 = strtotime($_POST['date2']); |
2067
|
|
|
$cat_id = (int)$_POST['cat_cid']; |
2068
|
|
|
$tblBooks = $tblCategories = array(); |
2069
|
|
|
$tblBooks = $h_bookshop_books->getBooksForNewsletter($date1, $date2, $cat_id); |
2070
|
|
|
$newsfile = XOOPS_ROOT_PATH . '/uploads/bookshop_newsletter.txt'; |
2071
|
|
|
$tblCategories = $h_bookshop_cat->GetAllCategories(0, 0, 'cat_title', 'ASC', true); |
2072
|
|
|
$tblVat = $h_bookshop_vat->GetAllVats(); |
2073
|
|
|
|
2074
|
|
|
$fp = fopen($newsfile, 'w'); |
2075
|
|
|
if (!$fp) { |
2076
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_7, $baseurl . '?op=newsletter', 5); |
2077
|
|
|
} |
2078
|
|
|
if (xoops_trim($header) != '') { |
2079
|
|
|
fwrite($fp, $header); |
2080
|
|
|
} |
2081
|
|
|
foreach ($tblBooks as $item) { |
2082
|
|
|
$content = $newslettertemplate; |
2083
|
|
|
$tblTmp = $tblTmp2 = array(); |
2084
|
|
|
$criteria = new CriteriaCompo(); |
2085
|
|
|
$criteria->add(new Criteria('ba_book_id', $item->getVar('book_id'), '=')); |
2086
|
|
|
$criteria->add(new Criteria('ba_type', 1, '=')); |
2087
|
|
|
$tblTmp = $h_bookshop_booksauthors->getObjects($criteria); |
2088
|
|
|
foreach ($tblTmp as $bookAuthor) { |
2089
|
|
|
$tblTmp2[] = $bookAuthor->getVar('ba_auth_id'); |
2090
|
|
|
} |
2091
|
|
|
$tblAuthors = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tblTmp2) . ')', 'IN'), true); |
2092
|
|
|
$tblTmp = array(); |
2093
|
|
|
foreach ($tblAuthors as $auteur) { |
2094
|
|
|
$tblTmp[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
2095
|
|
|
} |
2096
|
|
|
|
2097
|
|
|
$search_pattern = array( |
2098
|
|
|
'%title%', |
2099
|
|
|
'%category%', |
2100
|
|
|
'%author%', |
2101
|
|
|
'%published%', |
2102
|
|
|
'%price%', |
2103
|
|
|
'%money%', |
2104
|
|
|
'%hometext%', |
2105
|
|
|
'%fulltext%', |
2106
|
|
|
'%discountprice%', |
2107
|
|
|
'%link%', |
2108
|
|
|
'%book_number%', |
2109
|
|
|
'%book_tome%', |
2110
|
|
|
'%book_format%', |
2111
|
|
|
'%book_date%', |
2112
|
|
|
'%book_shipping_price%', |
2113
|
|
|
'%book_stock%', |
2114
|
|
|
'%book_isbn%', |
2115
|
|
|
'%book_ean%', |
2116
|
|
|
'%book_pages%', |
2117
|
|
|
'%book_pages_collection%', |
2118
|
|
|
'%book_volumes_count%' |
2119
|
|
|
); |
2120
|
|
|
$replace_pattern = array( |
2121
|
|
|
$item->getVar('book_title'), |
2122
|
|
|
$tblCategories[$item->getVar('book_cid')]->getVar('cat_title'), |
2123
|
|
|
implode(', ', $tblTmp), |
2124
|
|
|
formatTimestamp($item->getVar('book_submitted'), 's'), |
2125
|
|
|
bookshop_getTTC($item->getVar('book_price'), $tblVat[$item->getVar('book_vat_id')]->getVar('vat_rate')), |
2126
|
|
|
bookshop_getmoduleoption('money_full'), |
2127
|
|
|
$item->getVar('book_summary'), |
2128
|
|
|
$item->getVar('book_description'), |
2129
|
|
|
bookshop_getTTC($item->getVar('book_discount_price'), $tblVat[$item->getVar('book_vat_id')]->getVar('vat_rate')), |
2130
|
|
|
$h_bookshop_books->GetBookLink($item->getVar('book_id'), $item->getVar('book_title')), |
2131
|
|
|
$item->getVar('book_number'), |
2132
|
|
|
$item->getVar('book_tome'), |
2133
|
|
|
$item->getVar('book_format'), |
2134
|
|
|
$item->getVar('book_date'), |
2135
|
|
|
$item->getVar('book_shipping_price'), |
2136
|
|
|
$item->getVar('book_stock'), |
2137
|
|
|
$item->getVar('book_isbn'), |
2138
|
|
|
$item->getVar('book_ean'), |
2139
|
|
|
$item->getVar('book_pages'), |
2140
|
|
|
$item->getVar('book_pages_collection'), |
2141
|
|
|
$item->getVar('book_volumes_count') |
2142
|
|
|
); |
2143
|
|
|
$content = str_replace($search_pattern, $replace_pattern, $content); |
2144
|
|
|
if ($removebr) { |
2145
|
|
|
$content = str_replace('<br>', "\r\n", $content); |
2146
|
|
|
} |
2147
|
|
|
if ($removehtml) { |
2148
|
|
|
$content = strip_tags($content); |
2149
|
|
|
} |
2150
|
|
|
fwrite($fp, $content); |
2151
|
|
|
} |
2152
|
|
|
if (xoops_trim($footer) != '') { |
2153
|
|
|
fwrite($fp, $footer); |
2154
|
|
|
} |
2155
|
|
|
fclose($fp); |
2156
|
|
|
$newsfile = XOOPS_URL . '/uploads/bookshop_newsletter.txt'; |
2157
|
|
|
echo "<a href='$newsfile' target='_blank'>" . _AM_BOOKSHOP_NEWSLETTER_READY . '</a>'; |
2158
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
2159
|
|
|
break; |
2160
|
|
|
|
2161
|
|
|
// **************************************************************************************************************** |
2162
|
|
|
case 'lowstock': // Stock bas |
2163
|
|
|
// **************************************************************************************************************** |
2164
|
|
|
xoops_cp_header(); |
2165
|
|
|
// bookshop_adminMenu(10); |
|
|
|
|
2166
|
|
|
$indexAdmin = new ModuleAdmin(); |
2167
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=lowstock'); |
2168
|
|
|
|
2169
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU9, 4); |
2170
|
|
|
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
2171
|
|
|
$criteria = new CriteriaCompo(); |
2172
|
|
|
// Recherche des livres dont la quantit� en stock est inf�rieure ou �gale � la quantit� d'alerte et ou la quantit� d'alerte est sup�rieure � 0 |
2173
|
|
|
$books_count = $h_bookshop_books->getLowStocksCount(); |
2174
|
|
|
$pagenav = new XoopsPageNav($books_count, $limit, $start, 'start', 'op=lowstock'); |
2175
|
|
|
$tbl_books = $h_bookshop_books->getLowStocks($start, $limit); |
2176
|
|
|
$class = $name = ''; |
2177
|
|
|
$names = array(); |
2178
|
|
|
echo "<form name='frmupdatequant' id='frmupdatequant' method='post' action='$baseurl'><input type='hidden' name='op' id='op' value='updatequantities' />"; |
2179
|
|
|
echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
2180
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_TITLE . "</th><th align='center'>" . _BOOKSHOP_STOCK_QUANTITY . "</th><th align='center'>" . _BOOKSHOP_STOCK_ALERT . "</th><th align='center'>" . _AM_BOOKSHOP_NEW_QUANTITY . '</th></tr>'; |
2181
|
|
|
foreach ($tbl_books as $item) { |
2182
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
2183
|
|
|
$link = "<a href='" . BOOKSHOP_URL . 'book.php?book_id=' . $item->getVar('book_id') . "'>" . $item->getVar('book_title') . '</a>'; |
2184
|
|
|
echo "<tr class='" . $class . "'>\n"; |
2185
|
|
|
$name = 'qty_' . $item->getVar('book_id'); |
2186
|
|
|
$names[] = $item->getVar('book_id'); |
2187
|
|
|
echo '<td>' . $link . "</td><td align='right'>" . $item->getVar('book_stock') . "</td><td align='right'>" . $item->getVar('book_alert_stock') . "</td><td align='center'><input type='text' name='$name' id='$name' size='3' maxlength='5' value='' /></td>\n"; |
2188
|
|
|
echo "<tr>\n"; |
2189
|
|
|
} |
2190
|
|
|
$class = ($class === 'even') ? 'odd' : 'even'; |
2191
|
|
|
if (count($names) > 0) { |
2192
|
|
|
echo "<tr class='$class'><td colspan='3' align='center'> </td><td align='center'><input type='hidden' name='names' id='names' value='" . implode('|', $names) . "' /><input type='submit' name='btngo' id='btngo' value='" . _AM_BOOKSHOP_UPDATE_QUANTITIES . "' /></td></tr>"; |
2193
|
|
|
} |
2194
|
|
|
echo '</table></form>'; |
2195
|
|
|
echo "<div align='right'>" . $pagenav->renderNav() . '</div>'; |
2196
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
2197
|
|
|
break; |
2198
|
|
|
|
2199
|
|
|
// **************************************************************************************************************** |
2200
|
|
|
case 'updatequantities': // Mise � jour des quantit�s des livres |
2201
|
|
|
// **************************************************************************************************************** |
2202
|
|
|
$names = array(); |
2203
|
|
|
if (isset($_POST['names'])) { |
2204
|
|
|
$names = explode('|', $_POST['names']); |
2205
|
|
|
foreach ($names as $item) { |
2206
|
|
|
$name = 'qty_' . $item; |
2207
|
|
|
if (isset($_POST[$name]) && xoops_trim($_POST[$name]) != '') { |
2208
|
|
|
$quantity = (int)$_POST[$name]; |
2209
|
|
|
$book_id = (int)$item; |
2210
|
|
|
$book = null; |
2211
|
|
|
$book = $h_bookshop_books->get($book_id); |
2212
|
|
|
if (is_object($book)) { |
2213
|
|
|
$h_bookshop_books->updateAll('book_stock', $quantity, new Criteria('book_id', $book_id, '='), true); |
2214
|
|
|
} |
2215
|
|
|
} |
2216
|
|
|
} |
2217
|
|
|
} |
2218
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=lowstock', 2); |
2219
|
|
|
break; |
2220
|
|
|
|
2221
|
|
|
// **************************************************************************************************************** |
2222
|
|
|
case 'deleterating': // Delete a rating |
2223
|
|
|
// **************************************************************************************************************** |
2224
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
2225
|
|
|
if (empty($id)) { |
2226
|
|
|
bookshop_redirect(_AM_BOOKSHOP_ERROR_1, $baseurl, 5); |
2227
|
|
|
} |
2228
|
|
|
$item = $h_bookshop_votedata->get($id); |
2229
|
|
|
if (is_object($item)) { |
2230
|
|
|
$res = $h_bookshop_votedata->delete($item, true); |
2231
|
|
|
if ($res) { |
2232
|
|
|
$book_id = $item->getVar('vote_book_id'); |
2233
|
|
|
$book = null; |
2234
|
|
|
$book = $h_bookshop_books->get($book_id); |
2235
|
|
|
if (is_object($book)) { // Update Book's rating |
2236
|
|
|
$totalVotes = $sumRating = $ret = $finalrating = 0; |
2237
|
|
|
$ret = $h_bookshop_votedata->getCountRecordSumRating($book->getVar('book_id'), $totalVotes, $sumRating); |
2238
|
|
|
if ($totalVotes > 0) { |
2239
|
|
|
$finalrating = $sumRating / $totalVotes; |
2240
|
|
|
$finalrating = number_format($finalrating, 4); |
2241
|
|
|
} |
2242
|
|
|
$h_bookshop_books->updateRating($book_id, $finalrating, $totalVotes); |
2243
|
|
|
} |
2244
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_OK, $baseurl . '?op=dashboard', 2); |
2245
|
|
|
} else { |
2246
|
|
|
bookshop_redirect(_AM_BOOKSHOP_SAVE_PB, $baseurl . '?op=dashboard', 5); |
2247
|
|
|
} |
2248
|
|
|
} else { |
2249
|
|
|
bookshop_redirect(_AM_BOOKSHOP_NOT_FOUND, $baseurl . '?op=dashboard', 5); |
2250
|
|
|
} |
2251
|
|
|
break; |
2252
|
|
|
|
2253
|
|
|
// **************************************************************************************************************** |
2254
|
|
|
case 'email': // Envoyer un email aux clients |
2255
|
|
|
// **************************************************************************************************************** |
2256
|
|
|
break; |
2257
|
|
|
|
2258
|
|
|
// **************************************************************************************************************** |
2259
|
|
|
case 'default': |
2260
|
|
|
case 'dashboard': |
2261
|
|
|
// **************************************************************************************************************** |
2262
|
|
|
xoops_cp_header(); |
2263
|
|
|
// bookshop_adminMenu(0); |
|
|
|
|
2264
|
|
|
$indexAdmin = new ModuleAdmin(); |
2265
|
|
|
echo $indexAdmin->addNavigation(basename(__FILE__) . '?op=dashboard'); |
2266
|
|
|
|
2267
|
|
|
bookshop_htitle(_MI_BOOKSHOP_ADMENU10, 4); |
2268
|
|
|
$itemsCount = 5; // Nombre d'�l�ments � afficher |
2269
|
|
|
echo "<table border='0' width='100%' cellpadding='2' cellspacing='2'>"; |
2270
|
|
|
echo "<tr>\n"; |
2271
|
|
|
// Derni�res commandes ************************************************ |
2272
|
|
|
echo "<td valign='top' width='50%'><b>" . _AM_BOOKSHOP_LAST_ORDERS . '</b>'; |
2273
|
|
|
$tblTmp = array(); |
2274
|
|
|
$criteria = new CriteriaCompo(); |
2275
|
|
|
$criteria->add(new Criteria('cmd_id', 0, '<>')); |
2276
|
|
|
$criteria->setSort('cmd_date'); |
2277
|
|
|
$criteria->setOrder('DESC'); |
2278
|
|
|
$criteria->setLimit($itemsCount); |
2279
|
|
|
$criteria->setStart(0); |
2280
|
|
|
$tblTmp = $h_bookshop_commands->getObjects($criteria); |
2281
|
|
|
echo "<table border='0' cellpadding='2' cellspacing='2' width='100%'>"; |
2282
|
|
|
echo "<tr><th align='center'>" . _AM_BOOKSHOP_DATE . "</th><th align='center'>" . _AM_BOOKSHOP_ID . "</th><th align='center'>" . _BOOKSHOP_TOTAL . "</th></tr>\n"; |
2283
|
|
|
foreach ($tblTmp as $item) { |
2284
|
|
|
$date = formatTimestamp(strtotime($item->getVar('cmd_date')), 's'); |
2285
|
|
|
echo "<tr><td align='center'>" . $date . "</td><td align='center'>" . $item->getVar('cmd_id') . "</td><td align='right'>" . $item->getVar('cmd_total') . ' ' . bookshop_getmoduleoption('money_short') . '</td></tr>'; |
2286
|
|
|
} |
2287
|
|
|
echo '</table>'; |
2288
|
|
|
|
2289
|
|
|
// Stocks bas ********************************************************* |
2290
|
|
|
echo "</td><td valign='top' width='50%'><b>" . _MI_BOOKSHOP_ADMENU9 . '</b>'; |
2291
|
|
|
$tblTmp = array(); |
2292
|
|
|
$tblTmp = $h_bookshop_books->getLowStocks(0, $itemsCount); |
2293
|
|
|
echo "<table border='0' cellpadding='2' cellspacing='2' width='100%'>"; |
2294
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_TITLE . "</th><th align='center'>" . _BOOKSHOP_STOCK_QUANTITY . "</th></tr>\n"; |
2295
|
|
View Code Duplication |
foreach ($tblTmp as $item) { |
|
|
|
|
2296
|
|
|
$link = "<a href='" . BOOKSHOP_URL . 'book.php?book_id=' . $item->getVar('book_id') . "'>" . $item->getVar('book_title') . '</a>'; |
2297
|
|
|
echo '<tr><td>' . $link . "</td><td align='right'>" . $item->getVar('book_stock') . '</td></tr>'; |
2298
|
|
|
} |
2299
|
|
|
echo '</table>'; |
2300
|
|
|
echo '</td></tr>'; |
2301
|
|
|
|
2302
|
|
|
echo "<tr><td colspan='2'> </td></tr>"; |
2303
|
|
|
|
2304
|
|
|
// Livres les plus vendus ********************************************* |
2305
|
|
|
echo "<td valign='top' width='50%'><b>" . _MI_BOOKSHOP_BNAME4 . '</b>'; |
2306
|
|
|
$tblTmp = $tblTmp2 = array(); |
2307
|
|
|
$tblTmp2 = $h_bookshop_caddy->getMostSoldBooksInCategory(0, 0, $itemsCount, true); |
2308
|
|
|
$tblTmp = $h_bookshop_books->getObjects(new Criteria('book_id', '(' . implode(',', array_keys($tblTmp2)) . ')', 'IN'), true); |
2309
|
|
|
echo "<table border='0' cellpadding='2' cellspacing='2' width='100%'>"; |
2310
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_TITLE . "</th><th align='center'>" . _BOOKSHOP_QUANTITY . "</th></tr>\n"; |
2311
|
|
|
foreach ($tblTmp2 as $key => $value) { |
2312
|
|
|
$item = $tblTmp[$key]; |
2313
|
|
|
$link = "<a href='" . BOOKSHOP_URL . 'book.php?book_id=' . $item->getVar('book_id') . "'>" . $item->getVar('book_title') . '</a>'; |
2314
|
|
|
echo '<tr><td>' . $link . "</td><td align='right'>" . $value . '</td></tr>'; |
2315
|
|
|
} |
2316
|
|
|
echo '</table>'; |
2317
|
|
|
// Livres les plus vus ************************************************ |
2318
|
|
|
$tblTmp = array(); |
2319
|
|
|
$tblTmp = $h_bookshop_books->getMostViewedBooks(0, $itemsCount); |
2320
|
|
|
echo "</td><td valign='top' width='50%'><b>" . _MI_BOOKSHOP_BNAME2 . '</b>'; |
2321
|
|
|
echo "<table border='0' cellpadding='2' cellspacing='2' width='100%'>"; |
2322
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_TITLE . "</th><th align='center'>" . _BOOKSHOP_HITS . "</th></tr>\n"; |
2323
|
|
View Code Duplication |
foreach ($tblTmp as $item) { |
|
|
|
|
2324
|
|
|
$link = "<a href='" . BOOKSHOP_URL . 'book.php?book_id=' . $item->getVar('book_id') . "'>" . $item->getVar('book_title') . '</a>'; |
2325
|
|
|
echo '<tr><td>' . $link . "</td><td align='right'>" . $item->getVar('book_hits') . '</td></tr>'; |
2326
|
|
|
} |
2327
|
|
|
echo '</table>'; |
2328
|
|
|
echo '</td></tr>'; |
2329
|
|
|
|
2330
|
|
|
echo "<tr><td colspan='2'> </td></tr>"; |
2331
|
|
|
|
2332
|
|
|
// Derniers votes ***************************************************** |
2333
|
|
|
echo "</td><td colspan='2' valign='top'><b>" . _AM_BOOKSHOP_LAST_VOTES . '</b>'; |
2334
|
|
|
$tblTmp = $tblTmp2 = $tblTmp3 = array(); |
2335
|
|
|
$tblTmp3 = $h_bookshop_votedata->getLastVotes(0, $itemsCount); |
2336
|
|
|
foreach ($tblTmp3 as $item) { |
2337
|
|
|
$tblTmp2[] = $item->getVar('vote_book_id'); |
2338
|
|
|
} |
2339
|
|
|
$tblTmp = $h_bookshop_books->getObjects(new Criteria('book_id', '(' . implode(',', $tblTmp2) . ')', 'IN'), true); |
2340
|
|
|
echo "<table border='0' cellpadding='2' cellspacing='2' width='100%'>"; |
2341
|
|
|
echo "<tr><th align='center'>" . _BOOKSHOP_TITLE . "</th><th align='center'>" . _AM_BOOKSHOP_DATE . "</th><th colspan='2' align='center'>" . _AM_BOOKSHOP_NOTE . '</th></tr>'; |
2342
|
|
|
foreach ($tblTmp3 as $vote) { |
2343
|
|
|
$item = $tblTmp[$vote->getVar('vote_book_id')]; |
2344
|
|
|
$link = "<a href='" . BOOKSHOP_URL . 'book.php?book_id=' . $item->getVar('book_id') . "'>" . $item->getVar('book_title') . '</a>'; |
2345
|
|
|
$action_delete = "<a href='$baseurl?op=deleterating&id=" . $vote->getVar('vote_ratingid') . "' title='" . _BOOKSHOP_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
2346
|
|
|
echo '<tr><td>' . $link . "</td><td align='right'>" . formatTimestamp($vote->getVar('vote_ratingtimestamp'), 's') . "</td><td align='right'>" . $vote->getVar('vote_rating') . '</td><td>' . $action_delete . '</td></tr>'; |
2347
|
|
|
} |
2348
|
|
|
echo '</table>'; |
2349
|
|
|
echo '</td></tr>'; |
2350
|
|
|
|
2351
|
|
|
echo '</table>'; |
2352
|
|
|
include_once __DIR__ . '/admin_footer.php'; //show_footer(); |
2353
|
|
|
break; |
2354
|
|
|
|
2355
|
|
|
} |
2356
|
|
|
xoops_cp_footer(); |
2357
|
|
|
|
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.