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
|
|
|
/** |
28
|
|
|
* @param int $currentoption |
29
|
|
|
* @param string $breadcrumb |
30
|
|
|
*/ |
31
|
|
|
function bookshop_adminMenu($currentoption = 0, $breadcrumb = '') |
32
|
|
|
{ |
33
|
|
|
global $xoopsConfig, $xoopsModule; |
34
|
|
View Code Duplication |
if (file_exists(XOOPS_ROOT_PATH . '/modules/bookshop/language/' . $xoopsConfig['language'] . '/modinfo.php')) { |
|
|
|
|
35
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/bookshop/language/' . $xoopsConfig['language'] . '/modinfo.php'; |
36
|
|
|
} else { |
37
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/bookshop/language/english/modinfo.php'; |
38
|
|
|
} |
39
|
|
|
global $adminmenu; |
40
|
|
|
include __DIR__ . '/menu.php'; |
41
|
|
|
|
42
|
|
|
echo "<style type=\"text/css\">\n"; |
43
|
|
|
echo "#buttontop { float:left; width:100%; background: #e7e7e7; font-size:93%; line-height:normal; border-top: 1px solid black; border-left: 1px solid black; border-right: 1px solid black; margin: 0; }\n"; |
44
|
|
|
echo "#buttonbar { float:left; width:100%; background: #e7e7e7 url('../assets/images/modadminbg.gif') repeat-x left bottom; font-size:93%; line-height:normal; border-left: 1px solid black; border-right: 1px solid black; margin-bottom: 12px; }\n"; |
45
|
|
|
echo "#buttonbar ul { margin:0; margin-top: 15px; padding:10px 10px 0; list-style:none; }\n"; |
46
|
|
|
echo '#buttonbar li { display:inline; margin:0; padding:0; }'; |
47
|
|
|
echo "#buttonbar a { float:left; background:url('../assets/images/left_both.gif') no-repeat left top; margin:0; padding:0 0 0 9px; border-bottom:1px solid #000; text-decoration:none; }\n"; |
48
|
|
|
echo "#buttonbar a span { float:left; display:block; background:url('../assets/images/right_both.gif') no-repeat right top; padding:5px 15px 4px 6px; font-weight:bold; color:#765; }\n"; |
49
|
|
|
echo "/* Commented Backslash Hack hides rule from IE5-Mac \*/\n"; |
50
|
|
|
echo "#buttonbar a span {float:none;}\n"; |
51
|
|
|
echo "/* End IE5-Mac hack */\n"; |
52
|
|
|
echo "#buttonbar a:hover span { color:#333; }\n"; |
53
|
|
|
echo "#buttonbar .current a { background-position:0 -150px; border-width:0; }\n"; |
54
|
|
|
echo "#buttonbar .current a span { background-position:100% -150px; padding-bottom:5px; color:#333; }\n"; |
55
|
|
|
echo "#buttonbar a:hover { background-position:0% -150px; }\n"; |
56
|
|
|
echo "#buttonbar a:hover span { background-position:100% -150px; }\n"; |
57
|
|
|
echo "</style>\n"; |
58
|
|
|
|
59
|
|
|
echo "<div id=\"buttontop\">\n"; |
60
|
|
|
echo "<table style=\"width: 100%; padding: 0; \" cellspacing=\"0\">\n"; |
61
|
|
|
echo "<tr>\n"; |
62
|
|
|
echo "<td style=\"width: 70%; font-size: 10px; text-align: left; color: #2F5376; padding: 0 6px; line-height: 18px;\">\n"; |
63
|
|
|
echo "<a href=\"../index.php\">" . _AM_BOOKSHOP_GO_TO_MODULE . "</a> | <a href=\"" . XOOPS_URL . '/modules/system/admin.php?fct=preferences&op=showmod&mod=' . $xoopsModule->getVar('mid') . "\">" . _AM_BOOKSHOP_PREFERENCES . "</a>\n"; |
64
|
|
|
echo "</td>\n"; |
65
|
|
|
echo "<td style=\"width: 30%; font-size: 10px; text-align: right; color: #2F5376; padding: 0 6px; line-height: 18px;\">\n"; |
66
|
|
|
echo '<b>' . $xoopsModule->getVar('name') . ' ' . _AM_BOOKSHOP_ADMINISTRATION . '</b> ' . $breadcrumb . "\n"; |
67
|
|
|
echo "</td>\n"; |
68
|
|
|
echo "</tr>\n"; |
69
|
|
|
echo "</table>\n"; |
70
|
|
|
echo "</div>\n"; |
71
|
|
|
echo "<div id=\"buttonbar\">\n"; |
72
|
|
|
echo "<ul>\n"; |
73
|
|
|
foreach ($GLOBALS['adminmenu'] as $key => $link) { |
74
|
|
|
if ($key == $currentoption) { |
75
|
|
|
echo "<li class=\"current\">\n"; |
76
|
|
|
} else { |
77
|
|
|
echo "<li>\n"; |
78
|
|
|
} |
79
|
|
|
echo "<a href=\"" . XOOPS_URL . '/modules/bookshop/' . $link['link'] . "\"><span>" . $link['title'] . "</span></a>\n"; |
80
|
|
|
echo "</li>\n"; |
81
|
|
|
} |
82
|
|
|
echo "</ul>\n"; |
83
|
|
|
echo "</div>\n"; |
84
|
|
|
echo "<br style=\"clear:both;\" />\n"; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Internal function |
89
|
|
|
*/ |
90
|
|
|
function bookshop_get_mid() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
global $xoopsModule; |
93
|
|
|
|
94
|
|
|
return $xoopsModule->getVar('mid'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Internal function |
99
|
|
|
*/ |
100
|
|
|
function bookshop_get_config_handler() |
101
|
|
|
{ |
102
|
|
|
$config_handler = null; |
|
|
|
|
103
|
|
|
$config_handler = xoops_getHandler('config'); |
104
|
|
|
if (!is_object($config_handler)) { |
105
|
|
|
trigger_error('Error, unable to get and handler on the Config object'); |
106
|
|
|
exit; |
107
|
|
|
} else { |
108
|
|
|
return $config_handler; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Returns a module option |
114
|
|
|
* |
115
|
|
|
* @param string $option_name |
116
|
|
|
* @param bool $as_object |
117
|
|
|
* |
118
|
|
|
* @return mixed |
119
|
|
|
*/ |
120
|
|
|
function bookshop_get_module_option($option_name = '', $as_object = false) |
121
|
|
|
{ |
122
|
|
|
$tbl_options = array(); |
|
|
|
|
123
|
|
|
$mid = bookshop_get_mid(); |
124
|
|
|
$config_handler = bookshop_get_config_handler(); |
125
|
|
|
$critere = new CriteriaCompo(); |
126
|
|
|
$critere->add(new Criteria('conf_modid', $mid, '=')); |
127
|
|
|
$critere->add(new Criteria('conf_name', $option_name, '=')); |
128
|
|
|
$tbl_options = $config_handler->getConfigs($critere, false, false); |
129
|
|
|
if (count($tbl_options) > 0) { |
130
|
|
|
$option = $tbl_options[0]; |
131
|
|
|
if (!$as_object) { |
132
|
|
|
return $option->getVar('conf_value'); |
133
|
|
|
} else { |
134
|
|
|
return $option; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set a module's option |
141
|
|
|
* @param string $option_name |
142
|
|
|
* @param string $option_value |
143
|
|
|
* @return mixed |
144
|
|
|
*/ |
145
|
|
|
function bookshop_set_module_option($option_name = '', $option_value = '') |
146
|
|
|
{ |
147
|
|
|
$config_handler = bookshop_get_config_handler(); |
148
|
|
|
$option = bookshop_get_module_option($option_name, true); |
149
|
|
|
$option->setVar('conf_value', $option_value); |
150
|
|
|
$retval = $config_handler->insertConfig($option, true); |
151
|
|
|
|
152
|
|
|
return $retval; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Create a unique upload filename |
157
|
|
|
* |
158
|
|
|
* @package Bookshop |
159
|
|
|
* @author Instant Zero http://www.instant-zero.com |
160
|
|
|
* @copyright (c) Instant Zero http://www.instant-zero.com |
161
|
|
|
* @param $folder |
162
|
|
|
* @param $filename |
163
|
|
|
* @param bool $trimname |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
|
167
|
|
|
function bookshop_createUploadName($folder, $filename, $trimname = false) |
168
|
|
|
{ |
169
|
|
|
$workingfolder = $folder; |
170
|
|
|
if (xoops_substr($workingfolder, strlen($workingfolder) - 1, 1) !== '/') { |
171
|
|
|
$workingfolder .= '/'; |
172
|
|
|
} |
173
|
|
|
$ext = basename($filename); |
174
|
|
|
$ext = explode('.', $ext); |
175
|
|
|
$ext = '.' . $ext[count($ext) - 1]; |
176
|
|
|
$true = true; |
177
|
|
|
while ($true) { |
178
|
|
|
$ipbits = explode('.', $_SERVER['REMOTE_ADDR']); |
179
|
|
|
list($usec, $sec) = explode(' ', microtime()); |
180
|
|
|
$usec = (integer)($usec * 65536); |
181
|
|
|
$sec = ((integer)$sec) & 0xFFFF; |
182
|
|
|
|
183
|
|
|
if ($trimname) { |
184
|
|
|
$uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
185
|
|
|
} else { |
186
|
|
|
$uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
187
|
|
|
} |
188
|
|
|
if (!file_exists($workingfolder . $uid . $ext)) { |
189
|
|
|
$true = false; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $uid . $ext; |
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param string $title |
198
|
|
|
* @param int $level |
199
|
|
|
*/ |
200
|
|
|
function bookshop_htitle($title = '', $level = 1) |
201
|
|
|
{ |
202
|
|
|
printf('<h%01d>%s</h%01d>', $level, $title, $level); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Verify that a field exists inside a mysql table |
207
|
|
|
* @param $fieldname |
208
|
|
|
* @param $table |
209
|
|
|
* @return bool |
210
|
|
|
*/ |
211
|
|
|
function booksop_FieldExists($fieldname, $table) |
212
|
|
|
{ |
213
|
|
|
global $xoopsDB; |
214
|
|
|
$result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
215
|
|
|
|
216
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Add a field to a mysql table |
221
|
|
|
* @param $field |
222
|
|
|
* @param $table |
223
|
|
|
* @return resource |
224
|
|
|
*/ |
225
|
|
|
function booksop_AddField($field, $table) |
226
|
|
|
{ |
227
|
|
|
global $xoopsDB; |
228
|
|
|
$result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field;"); |
229
|
|
|
|
230
|
|
|
return $result; |
231
|
|
|
} |
232
|
|
|
|
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.