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
|
|
|
include_once BOOKSHOP_PATH . 'admin/functions.php'; |
30
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
31
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
32
|
|
|
|
33
|
|
|
$cmd_id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
34
|
|
|
if ($cmd_id == 0) { |
35
|
|
|
exit(_AM_BOOKSHOP_ERROR_1); |
36
|
|
|
} |
37
|
|
|
$commande = null; |
38
|
|
|
$commande = $h_bookshop_commands->get($cmd_id); |
39
|
|
|
if (!is_object($commande)) { |
40
|
|
|
exit(_BOOKSHOP_ERROR11); |
41
|
|
|
} |
42
|
|
|
xoops_header(); |
43
|
|
|
//********************************************************************************************************************* |
44
|
|
|
//********************************************************************************************************************* |
45
|
|
|
//********************************************************************************************************************* |
46
|
|
|
//$url = BOOKSHOP_URL.'invoice.php?command='.$commande->getVar('cmd_id').'&pass='.$commande->getVar('cmd_password').'&cancel='.$commande->getVar('cmd_cancel'); |
47
|
|
|
//echo "<iframe width='100%' height='600' align='top' frameborder='0' marginwidth='0' marginheight='0' scrolling='yes' src='$url'></iframe>"; |
48
|
|
|
//********************************************************************************************************************* |
49
|
|
|
//********************************************************************************************************************* |
50
|
|
|
//********************************************************************************************************************* |
51
|
|
|
$xoopsTpl = new XoopsTpl(); |
52
|
|
|
$urlCSS = BOOKSHOP_URL . 'assets/css/bookshop.css'; |
53
|
|
|
echo "<link rel='stylesheet' type='text/css' href='$urlCSS' />"; |
54
|
|
|
$dec = bookshop_getmoduleoption('decimals_count'); |
55
|
|
|
$tblCaddy = $tblTmp = $tblBooks = $tblVat = $tblAuthors = $tblTmp2 = $tbl_country = array(); |
56
|
|
|
|
57
|
|
|
$tbl_country = XoopsLists::getCountryList(); |
58
|
|
|
|
59
|
|
|
// Retrieving all VAT ********************************************************************************************* |
60
|
|
|
$tblVat = $h_bookshop_vat->GetAllVats(); |
61
|
|
|
// Retrieving associated shopping cart ************************************************************************************ |
62
|
|
|
$tblCaddy = $h_bookshop_caddy->getObjects(new Criteria('caddy_cmd_id', $cmd_id, '='), true); |
63
|
|
|
if (count($tblCaddy) == 0) { |
64
|
|
|
bookshop_redirect(_BOOKSHOP_ERROR11, 'index.php', 6); |
65
|
|
|
} |
66
|
|
|
foreach ($tblCaddy as $item) { |
67
|
|
|
$tblTmp[] = $item->getVar('caddy_book_id'); |
68
|
|
|
} |
69
|
|
|
// Recherche des livres *********************************************************************************************** |
70
|
|
|
$tblBooks = $h_bookshop_books->getObjects(new Criteria('book_id', '(' . implode(',', $tblTmp) . ')', 'IN'), true); |
71
|
|
|
|
72
|
|
|
// Recherche des auteurs ********************************************************************************************** |
73
|
|
|
// On ne prend pas en compte les traducteurs pour cette partie |
74
|
|
|
$tblAuthors = $tblTmpAuth = array(); |
75
|
|
|
$criteria = new CriteriaCompo(); |
76
|
|
|
$criteria->add(new Criteria('ba_book_id', '(' . implode(',', $tblTmp) . ')', 'IN')); |
77
|
|
|
$criteria->add(new Criteria('ba_type', 1, '=')); |
78
|
|
|
$tblTmp2 = $h_bookshop_booksauthors->getObjects($criteria, true); |
79
|
|
|
$tblTmp = array(); |
80
|
|
View Code Duplication |
foreach ($tblTmp2 as $item) { |
|
|
|
|
81
|
|
|
$tblTmp[] = $item->getVar('ba_auth_id'); |
82
|
|
|
$tblTmpAuth[$item->getVar('ba_book_id')][] = $item; |
83
|
|
|
} |
84
|
|
|
$tblAuthors = $h_bookshop_authors->getObjects(new Criteria('auth_id', '(' . implode(',', $tblTmp) . ')', 'IN'), true); |
85
|
|
|
|
86
|
|
|
// Informations sur la commande *************************************************************************************** |
87
|
|
|
$tblTmp = $commande->toArray(); |
88
|
|
|
$tblTmp['country_label'] = $tbl_country[$commande->getVar('cmd_country')]; |
89
|
|
|
$tblTmp['cmd_date_timestamp'] = strtotime($commande->getVar('cmd_date')); |
90
|
|
|
$xoopsTpl->assign('commande', $tblTmp); |
91
|
|
|
|
92
|
|
|
// Boucle sur le caddy ************************************************************************************************ |
93
|
|
View Code Duplication |
foreach ($tblCaddy as $itemCaddy) { |
|
|
|
|
94
|
|
|
$tblTmp = array(); |
95
|
|
|
$item = $tblBooks[$itemCaddy->getVar('caddy_book_id')]; |
96
|
|
|
$tblTmp = $item->toArray(); |
97
|
|
|
$tblTmp2 = $tblTmpAuth[$itemCaddy->getVar('caddy_book_id')]; |
98
|
|
|
$tblJoin = array(); |
99
|
|
|
foreach ($tblTmp2 as $item2) { |
100
|
|
|
$auteur = $tblAuthors[$item2->getVar('ba_auth_id')]; |
101
|
|
|
$tblJoin[] = $auteur->getVar('auth_firstname') . ' ' . $auteur->getVar('auth_name'); |
102
|
|
|
} |
103
|
|
|
if (count($tblJoin) > 0) { |
104
|
|
|
$tblTmp['book_joined_authors'] = implode(', ', $tblJoin); |
105
|
|
|
} |
106
|
|
|
$tblTmp['book_price_ttc'] = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $itemCaddy->getVar('caddy_price')); |
107
|
|
|
$tblTmp['book_shipping_amount'] = sprintf('%0.' . bookshop_getmoduleoption('decimals_count') . 'f', $itemCaddy->getVar('caddy_shipping')); |
108
|
|
|
$tblTmp['book_qty'] = $itemCaddy->getVar('caddy_qte'); |
109
|
|
|
$xoopsTpl->append('books', $tblTmp); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$xoopsTpl->assign('commandAmountTTC', sprintf('%0.' . $dec . 'f', $commande->getVar('cmd_total'))); // Taxes in the ordre |
113
|
|
|
$xoopsTpl->assign('shippingAmount', sprintf('%0.' . $dec . 'f', $commande->getVar('cmd_shipping'))); // Taxes in Shipping cost |
114
|
|
|
$xoopsTpl->assign('discountsDescription', nl2br($commande->getVar('cmd_text'))); // List of discounts given |
115
|
|
|
$xoopsTpl->display('db:bookshop_bill.tpl'); |
116
|
|
|
xoops_footer(); |
117
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.