This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * $Id: hotelcity.php,v 1.42 2007/02/04 15:01:40 malanciault Exp $ |
||
4 | * Module:martin |
||
5 | * Licence: GNU |
||
6 | */ |
||
7 | |||
8 | if (!defined("XOOPS_ROOT_PATH")) { |
||
9 | die("XOOPS root path not defined"); |
||
10 | } |
||
11 | |||
12 | include_once XOOPS_ROOT_PATH . '/modules/martin/include/common.php'; |
||
13 | |||
14 | /** |
||
15 | * Class MartinHotelcity |
||
16 | */ |
||
17 | class MartinHotelcity extends XoopsObject |
||
18 | { |
||
19 | public function MartinHotelcity() |
||
20 | { |
||
21 | $this->initVar("city_id", XOBJ_DTYPE_INT, null, false); |
||
22 | $this->initVar("city_parentid", XOBJ_DTYPE_INT, null, false); |
||
23 | $this->initVar("city_name", XOBJ_DTYPE_TXTBOX, null, true, 45); |
||
24 | $this->initVar("city_alias", XOBJ_DTYPE_TXTBOX, null, false, 255); |
||
25 | $this->initVar("city_level", XOBJ_DTYPE_TXTBOX, null, true, 45); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @return mixed |
||
30 | */ |
||
31 | public function city_id() |
||
32 | { |
||
33 | return $this->getVar("city_id"); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return mixed |
||
38 | */ |
||
39 | public function city_parentid() |
||
40 | { |
||
41 | return $this->getVar("city_parentid"); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param string $format |
||
46 | * @return mixed |
||
47 | */ |
||
48 | public function city_name($format = 'S') |
||
49 | { |
||
50 | return $this->getVar("city_name", $format); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param string $format |
||
55 | * @return mixed |
||
56 | */ |
||
57 | public function city_alias($format = 'S') |
||
58 | { |
||
59 | return $this->getVar("city_alias", $format); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param string $format |
||
64 | * @return mixed |
||
65 | */ |
||
66 | public function city_level($format = 'S') |
||
67 | { |
||
68 | return $this->getVar("city_level", $format); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @method: HotelCityHandler |
||
74 | * @license http://www.blags.org/ |
||
75 | * @created :2010年05月21日 20时40分 |
||
76 | * @copyright 1997-2010 The Martin Group |
||
77 | * @author Martin <[email protected]> |
||
78 | * */ |
||
79 | class MartinHotelCityHandler extends XoopsObjectHandler |
||
80 | { |
||
81 | /** |
||
82 | * create a new hotel city |
||
83 | * @param bool $isNew flag the new objects as "new"? |
||
84 | * @return object HotelCity |
||
85 | */ |
||
86 | public function &create($isNew = true) |
||
87 | { |
||
88 | $hotelcity = new MartinHotelcity(); |
||
89 | if ($isNew) { |
||
90 | $hotelcity->setNew(); |
||
91 | } |
||
92 | |||
93 | return $hotelcity; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * retrieve a hotel city |
||
98 | * |
||
99 | * @param int $id hotelcityid of the hotelcity |
||
100 | * @return mixed reference to the {@link HotelCity} object, FALSE if failed |
||
101 | */ |
||
102 | View Code Duplication | public function &get($id) |
|
103 | { |
||
104 | if ((int)($id) <= 0) { |
||
105 | return false; |
||
106 | } |
||
107 | |||
108 | $criteria = new CriteriaCompo(new Criteria('city_id', $id)); |
||
109 | $criteria->setLimit(1); |
||
110 | $obj_array = $this->getObjects($criteria); |
||
111 | if (count($obj_array) != 1) { |
||
112 | $obj =& $this->create(); |
||
113 | |||
114 | return $obj; |
||
115 | } |
||
116 | |||
117 | return $obj_array[0]; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * @得到列表 |
||
122 | * @method: |
||
123 | * @license http://www.blags.org/ |
||
124 | * @created :2010年05月23日 14时59分 |
||
125 | * @copyright 1997-2010 The Martin Group |
||
126 | * @author Martin <[email protected]> |
||
127 | * @param int $limit |
||
128 | * @param int $start |
||
129 | * @param int $city_parentid |
||
130 | * @param string $sort |
||
131 | * @param string $order |
||
132 | * @param bool $id_as_key |
||
133 | * @return array |
||
134 | */ |
||
135 | public function &getHotelCitys($limit = 0, $start = 0, $city_parentid = 0, $sort = 'city_id', $order = 'ASC', $id_as_key = true) |
||
136 | { |
||
137 | $criteria = new CriteriaCompo(); |
||
138 | |||
139 | $criteria->setSort($sort); |
||
140 | $criteria->setOrder($order); |
||
141 | |||
142 | if ($city_parentid != -1) { |
||
143 | $criteria->add(new Criteria('city_parentid', $city_parentid)); |
||
144 | } |
||
145 | |||
146 | $criteria->setStart($start); |
||
147 | $criteria->setLimit($limit); |
||
148 | |||
149 | return $this->getObjects($criteria, $id_as_key); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * insert a new hotelcity in the database |
||
154 | * |
||
155 | * @param object $hotelcity reference to the {@link HotelCity} object |
||
156 | * @param bool $force |
||
157 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
||
158 | */ |
||
159 | View Code Duplication | public function insert(&$hotelcity, $force = false) |
|
160 | { |
||
161 | if (strtolower(get_class($hotelcity)) !== 'martinhotelcity') { |
||
162 | return false; |
||
163 | } |
||
164 | |||
165 | if (!$hotelcity->cleanVars()) { |
||
166 | return false; |
||
167 | } |
||
168 | |||
169 | foreach ($hotelcity->cleanVars as $k => $v) { |
||
170 | ${$k} = $v; |
||
171 | } |
||
172 | |||
173 | if ($hotelcity->isNew()) { |
||
174 | $sql = sprintf("INSERT INTO %s ( |
||
175 | city_id, |
||
176 | city_parentid, |
||
177 | city_name, |
||
178 | city_alias, |
||
179 | city_level |
||
180 | ) VALUES ( |
||
181 | NULL, |
||
182 | %u, |
||
183 | %s, |
||
184 | %s, |
||
185 | %s |
||
186 | )", $this->db->prefix('martin_hotel_city'), $city_parentid, $this->db->quoteString($city_name), $this->db->quoteString($city_alias), $this->db->quoteString($city_level)); |
||
187 | } else { |
||
188 | $sql = sprintf("UPDATE %s SET |
||
189 | city_parentid = %u, |
||
190 | city_name = %s, |
||
191 | city_alias = %s, |
||
192 | city_level = %s |
||
193 | WHERE city_id = %u", $this->db->prefix('martin_hotel_city'), $city_parentid, $this->db->quoteString($city_name), $this->db->quoteString($city_alias), $this->db->quoteString($city_level), $city_id); |
||
194 | } |
||
195 | //echo "<br />" . $sql . "<br />"; |
||
196 | if (false != $force) { |
||
0 ignored issues
–
show
|
|||
197 | $result = $this->db->queryF($sql); |
||
198 | } else { |
||
199 | $result = $this->db->query($sql); |
||
200 | } |
||
201 | if (!$result) { |
||
202 | $hotelcity->setErrors('The query returned an error. ' . $this->db->error()); |
||
203 | |||
204 | return false; |
||
205 | } |
||
206 | if ($hotelcity->isNew()) { |
||
207 | $hotelcity->assignVar('city_id', $this->db->getInsertId()); |
||
208 | } |
||
209 | |||
210 | $hotelcity->assignVar('city_id', $city_id); |
||
211 | |||
212 | return true; |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * @删除一个城市 |
||
217 | * @method:delete(city_id) |
||
218 | * @license http://www.blags.org/ |
||
219 | * @created :2010年05月21日 20时40分 |
||
220 | * @copyright 1997-2010 The Martin Group |
||
221 | * @author Martin <[email protected]> |
||
222 | * @param object $hotelcity |
||
223 | * @param bool $force |
||
224 | * @return bool|void |
||
225 | */ |
||
226 | public function delete(&$hotelcity, $force = false) |
||
227 | { |
||
228 | if (strtolower(get_class($hotelcity)) !== 'martinhotelcity') { |
||
229 | return false; |
||
230 | } |
||
231 | |||
232 | $subcats =& $this->getCityIds($hotelcity->city_id()); |
||
233 | |||
234 | $sql = "DELETE FROM " . $this->db->prefix("martin_hotel_city") . " WHERE city_id IN ( " . implode(",", $subcats) . " )"; |
||
235 | |||
236 | if (false != $force) { |
||
0 ignored issues
–
show
|
|||
237 | $result = $this->db->queryF($sql); |
||
238 | } else { |
||
239 | $result = $this->db->query($sql); |
||
240 | } |
||
241 | |||
242 | if (!$result) { |
||
243 | return false; |
||
244 | } |
||
245 | |||
246 | return true; |
||
247 | } |
||
248 | |||
249 | /** |
||
250 | * @ 得到所有子类 |
||
251 | * @license http://www.blags.org/ |
||
252 | * @created :2010年05月21日 20时40分 |
||
253 | * @copyright 1997-2010 The Martin Group |
||
254 | * @author Martin <[email protected]> |
||
255 | * @param $city_id |
||
256 | * @return array |
||
257 | */ |
||
258 | public function getCityIds($city_id) |
||
259 | { |
||
260 | if (!is_array($city_id)) { |
||
261 | $city_id = array((int)($city_id)); |
||
262 | } |
||
263 | $cities = $city_id; |
||
264 | //var_dump($cities);exit; |
||
265 | $sql = "SELECT city_id FROM " . $this->db->prefix("martin_hotel_city") . " WHERE city_parentid IN (" . implode(",", $cities) . ")"; |
||
266 | //echo $sql;exit; |
||
267 | |||
268 | $result = $this->db->query($sql); |
||
269 | while ($row = $this->db->fetchArray($result)) { |
||
270 | $cities[] = (int)$row['city_id']; |
||
271 | } |
||
272 | $cities = array_unique($cities); |
||
273 | //var_dump($cities);exit; |
||
274 | //var_dump($city_id);exit; |
||
275 | $isOver = array_diff($cities, $city_id); |
||
276 | //var_dump($isOver);exit; |
||
277 | if (empty($isOver)) { |
||
278 | return $cities; |
||
279 | } |
||
280 | |||
281 | return $this->getCityIds($cities); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * delete hotel cities matching a set of conditions |
||
286 | * |
||
287 | * @param object $criteria {@link CriteriaElement} |
||
288 | * @return bool FALSE if deletion failed |
||
289 | */ |
||
290 | View Code Duplication | public function deleteAll($criteria = null) |
|
291 | { |
||
292 | $sql = 'DELETE FROM ' . $this->db->prefix('martin_hotel_city'); |
||
293 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
294 | $sql .= ' ' . $criteria->renderWhere(); |
||
295 | } |
||
296 | if (!$result = $this->db->query($sql)) { |
||
297 | return false; |
||
298 | } |
||
299 | |||
300 | return true; |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * count hotel cities matching a condition |
||
305 | * |
||
306 | * @param object $criteria {@link CriteriaElement} to match |
||
307 | * @return int count of categories |
||
308 | */ |
||
309 | View Code Duplication | public function getCount($criteria = null) |
|
310 | { |
||
311 | $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('martin_hotel_city'); |
||
312 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
313 | $sql .= ' ' . $criteria->renderWhere(); |
||
314 | } |
||
315 | $result = $this->db->query($sql); |
||
316 | if (!$result) { |
||
317 | return 0; |
||
318 | } |
||
319 | list($count) = $this->db->fetchRow($result); |
||
320 | |||
321 | return $count; |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * @得到城市 |
||
326 | * @license http://www.blags.org/ |
||
327 | * @created :2010年05月21日 20时40分 |
||
328 | * @copyright 1997-2010 The Martin Group |
||
329 | * @author Martin <[email protected]> |
||
330 | * @param null $criteria |
||
331 | * @param bool $id_as_key |
||
332 | * @return array |
||
333 | */ |
||
334 | View Code Duplication | public function &getObjects($criteria = null, $id_as_key = false) |
|
335 | { |
||
336 | $ret = array(); |
||
337 | $limit = $start = 0; |
||
338 | $sql = 'SELECT * FROM ' . $this->db->prefix('martin_hotel_city'); |
||
339 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
||
340 | $sql .= ' ' . $criteria->renderWhere(); |
||
341 | if ($criteria->getSort() != '') { |
||
342 | $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
||
343 | } |
||
344 | $limit = $criteria->getLimit(); |
||
345 | $start = $criteria->getStart(); |
||
346 | } |
||
347 | //echo "<br />" . $sql . "<br />"; |
||
348 | $result = $this->db->query($sql, $limit, $start); |
||
349 | |||
350 | if (!$result) { |
||
351 | return $ret; |
||
352 | } |
||
353 | |||
354 | $theObjects = array(); |
||
355 | |||
356 | while ($myrow = $this->db->fetchArray($result)) { |
||
357 | $hotelcity = new MartinHotelcity(); |
||
358 | $hotelcity->assignVars($myrow); |
||
359 | $theObjects[$myrow['city_id']] =& $hotelcity; |
||
360 | //var_dump($hotelcity); |
||
361 | unset($hotelcity); |
||
362 | } |
||
363 | //var_dump($theObjects); |
||
364 | |||
365 | foreach ($theObjects as $theObject) { |
||
366 | if (!$id_as_key) { |
||
367 | $ret[] =& $theObject; |
||
368 | } else { |
||
369 | $ret[$theObject->city_id()] =& $theObject; |
||
370 | } |
||
371 | unset($theObject); |
||
372 | } |
||
373 | |||
374 | return $ret; |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * @get city tree |
||
379 | * @license http://www.blags.org/ |
||
380 | * @created :2010年05月29日 11时31分 |
||
381 | * @copyright 1997-2010 The Martin Group |
||
382 | * @author Martin <[email protected]> |
||
383 | * @param $name |
||
384 | * @param $city_id |
||
385 | * @param string $prefix |
||
386 | * @return string |
||
387 | */ |
||
388 | public function &getTree($name, $city_id, $prefix = '--') |
||
389 | { |
||
390 | $mytree = new XoopsTree($this->db->prefix("martin_hotel_city"), "city_id", "city_parentid"); |
||
391 | // Parent Category |
||
392 | ob_start(); |
||
393 | $mytree->makeMySelBox("city_name", "", $city_id, 1, $name); |
||
394 | //makeMySelBox($title,$order="",$preset_id=0, $none=0, $sel_name="", $onchange="") |
||
395 | $str = ob_get_contents(); |
||
396 | ob_end_clean(); |
||
397 | |||
398 | return $str; |
||
399 | } |
||
400 | } |
||
401 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.