1 | <?php |
||||
2 | |||||
3 | /* |
||||
4 | // ID: couponhandler.php 5-jul-2007 18:46:54 Demo efqconsultancy |
||||
5 | // ----------------------------------------------------------------------- // |
||||
6 | // EFQ Web // |
||||
7 | // Copyright (c) 2006 EFQ Consultancy // |
||||
8 | // <http://www.efqweb.com> // |
||||
9 | // ----------------------------------------------------------------------- // |
||||
10 | // You may distribute this software under the terms of EFQ Consultany's // |
||||
11 | // modified Artistic Licence, as specified in the accompanying // |
||||
12 | // LICENCE.txt file. // |
||||
13 | --------------------------------------------------------------------------- // |
||||
14 | */ |
||||
15 | |||||
16 | class efqCouponHandler |
||||
17 | { |
||||
18 | public $db; |
||||
19 | public $coupon = array(); |
||||
20 | public $couponid; |
||||
21 | public $descr; |
||||
22 | public $itemid; |
||||
23 | public $publish; |
||||
24 | public $expire; |
||||
25 | public $heading; |
||||
26 | public $message; |
||||
27 | public $lbr; |
||||
28 | public $_new = false; |
||||
29 | |||||
30 | public function __construct() |
||||
31 | { |
||||
32 | $this->db = XoopsDatabaseFactory::getDatabaseConnection(); |
||||
0 ignored issues
–
show
|
|||||
33 | } |
||||
34 | |||||
35 | public function create() |
||||
36 | { |
||||
37 | global $myts; |
||||
38 | $this->descr = $myts->makeTareaData4Save($_POST['description']); |
||||
39 | $this->image = $myts->makeTboxData4Save($_POST['image']); |
||||
0 ignored issues
–
show
|
|||||
40 | $this->itemid = (int)$_POST['itemid']; |
||||
41 | $this->publish = strtotime($_POST['publish']['date']) + $_POST['publish']['time']; |
||||
42 | if (isset($_POST['expire_enable']) && ($_POST['expire_enable'] == 1)) { |
||||
43 | $this->expire = strtotime($_POST['expire']['date']) + $_POST['expire']['time']; |
||||
44 | } else { |
||||
45 | $this->expire = 0; |
||||
46 | } |
||||
47 | $this->lbr = $_POST['lbr']; |
||||
48 | $this->heading = $myts->makeTboxData4Save($_POST['heading']); |
||||
49 | if (!isset($_POST['couponid'])) { |
||||
50 | $this->_new = true; |
||||
51 | $this->message = _MD_COUPONADDED; |
||||
52 | if ($this->insert()) { |
||||
53 | return true; |
||||
54 | } else { |
||||
55 | return false; |
||||
56 | } |
||||
57 | } else { |
||||
58 | $this->message = _MD_COUPONUPDATED; |
||||
59 | $this->couponid = (int)$_POST['couponid']; |
||||
60 | if ($this->update()) { |
||||
61 | return true; |
||||
62 | } else { |
||||
63 | return false; |
||||
64 | } |
||||
65 | } |
||||
66 | } |
||||
67 | |||||
68 | public function insert() |
||||
69 | { |
||||
70 | $sql = 'INSERT INTO ' . $this->db->prefix($module->getVar('dirname', 'n') . '_coupon') . ' |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
71 | (itemid, description, image, publish, expire, heading, lbr) VALUES |
||||
72 | (' . $this->itemid . ', ' . $this->db->quoteString($this->descr) . ', ' . $this->db->quoteString($this->image) . ', ' . $this->publish . ', ' . $this->expire . ', ' . $this->db->quoteString($this->heading) . ', ' . $this->lbr . ')'; |
||||
0 ignored issues
–
show
|
|||||
73 | if ($this->db->query($sql)) { |
||||
74 | $this->couponid = $this->db->getInsertId(); |
||||
75 | |||||
76 | return true; |
||||
77 | } |
||||
78 | |||||
79 | return false; |
||||
80 | } |
||||
81 | |||||
82 | public function update() |
||||
83 | { |
||||
84 | $sql = 'UPDATE ' . $this->db->prefix($module->getVar('dirname', 'n') . '_coupon') . ' SET |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
85 | description = ' . $this->db->quoteString($this->descr) . ', |
||||
86 | image = ' . $this->db->quoteString($this->image) . ', |
||||
0 ignored issues
–
show
|
|||||
87 | publish = ' . $this->publish . ', |
||||
88 | lbr = ' . $this->lbr . ', |
||||
89 | heading = ' . $this->db->quoteString($this->heading) . ", |
||||
90 | expire = $this->expire WHERE couponid = $this->couponid"; |
||||
91 | $this->db->query($sql); |
||||
92 | |||||
93 | return true; |
||||
94 | } |
||||
95 | |||||
96 | public function get($couponid = false) |
||||
97 | { |
||||
98 | if ($couponid === false) { |
||||
99 | //echo 'couponid is false'; |
||||
100 | return false; |
||||
101 | } |
||||
102 | //$couponid = (int)($couponid); |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
103 | if ($couponid > 0) { |
||||
104 | $sql = 'SELECT itemid, description, image, publish, expire, heading, lbr FROM ' . $this->db->prefix($module->getVar('dirname', 'n') . '_coupon') . ' WHERE couponid=' . $couponid; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
105 | //echo $sql; |
||||
106 | if (!$result = $this->db->query($sql)) { |
||||
107 | return false; |
||||
108 | } |
||||
109 | while (list($itemid, $descr, $image, $publish, $expire, $heading, $lbr) = $this->db->fetchRow($result)) { |
||||
110 | $this->itemid = $itemid; |
||||
111 | $this->descr = $descr; |
||||
112 | $this->image = $image; |
||||
0 ignored issues
–
show
|
|||||
113 | $this->publish = $publish; |
||||
114 | $this->expire = $expire; |
||||
115 | $this->heading = $heading; |
||||
116 | $this->lbr = $lbr; |
||||
117 | } |
||||
118 | |||||
119 | return true; |
||||
120 | } |
||||
121 | |||||
122 | return false; |
||||
123 | } |
||||
124 | |||||
125 | public function delete($couponid) |
||||
126 | { |
||||
127 | $sql = 'DELETE FROM ' . $this->db->prefix($module->getVar('dirname', 'n') . '_coupon') . ' WHERE couponid=' . (int)$couponid; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
128 | $this->db->query($sql); |
||||
129 | |||||
130 | return true; |
||||
131 | } |
||||
132 | |||||
133 | /* Returns number of coupons for a listing |
||||
134 | * |
||||
135 | * @param int $itemid listing id |
||||
136 | * |
||||
137 | * @return |
||||
138 | */ |
||||
139 | View Code Duplication | public function getCountByLink($itemid = 0) |
|||
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||||
140 | { |
||||
141 | $ret = 0; |
||||
0 ignored issues
–
show
|
|||||
142 | $now = time(); |
||||
143 | $sql = 'SELECT count(*) FROM ' . $this->db->prefix($module->getVar('dirname', 'n') . '_coupon') . ' WHERE itemid=' . $itemid . ' AND publish < ' . $now . ' AND (expire = 0 OR expire > ' . $now . ')'; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
144 | //echo $sql; |
||||
145 | if (!$result = $this->db->query($sql)) { |
||||
146 | return false; |
||||
147 | } |
||||
148 | list($ret) = $this->db->fetchRow($result); |
||||
149 | |||||
150 | return $ret; |
||||
151 | } |
||||
152 | |||||
153 | public function getByItem($itemid = 0) |
||||
154 | { |
||||
155 | if ($itemid === false) { |
||||
156 | //echo 'couponid is false'; |
||||
157 | return false; |
||||
158 | } |
||||
159 | //$couponid = (int)($couponid); |
||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||
160 | if ($itemid > 0) { |
||||
161 | $sql = 'SELECT couponid, itemid, description, image, publish, expire, heading, lbr FROM ' . $this->db->prefix($module->getVar('dirname', 'n') . '_coupon') . ' WHERE itemid=' . $itemid; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
162 | //echo $sql; |
||||
163 | if (!$result = $this->db->query($sql)) { |
||||
164 | return false; |
||||
165 | } |
||||
166 | while (list($couponid, $itemid, $descr, $image, $publish, $expire, $heading, $lbr) = $this->db->fetchRow($result)) { |
||||
167 | if ($publish == 0) { |
||||
168 | $publish = time(); |
||||
169 | } |
||||
170 | if ($expire > 0) { |
||||
171 | $expire = formatTimestamp($expire, 's'); |
||||
0 ignored issues
–
show
The function
formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
172 | } |
||||
173 | $publish = formatTimestamp($publish, 's'); |
||||
174 | $ret[] = array('couponid' => $couponid, 'itemid' => $itemid, 'descr' => $descr, 'image' => $image, 'publish' => $publish, 'expire' => $expire, 'heading' => $heading, 'lbr' => $lbr); |
||||
175 | } |
||||
176 | |||||
177 | return $ret; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
178 | } |
||||
179 | |||||
180 | return false; |
||||
181 | } |
||||
182 | } |
||||
183 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths