Conditions | 15 |
Paths | 3458 |
Total Lines | 203 |
Code Lines | 140 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
129 | function modifyAd($lid): void |
||
130 | { |
||
131 | global $xoopsDB, $xoopsModule, $xoopsConfig, $myts, $desctext; |
||
132 | |||
133 | $helper = Helper::getInstance(); |
||
|
|||
134 | $mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||
135 | $helper = Helper::getInstance(); |
||
136 | $contactselect = ''; |
||
137 | // require_once __DIR__ . '/admin_header.php'; |
||
138 | xoops_cp_header(); |
||
139 | // loadModuleAdminMenu(0, ""); |
||
140 | $id_price = ''; |
||
141 | $nom_price = ''; |
||
142 | $lid = (int)$lid; |
||
143 | |||
144 | echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODANN . '</legend>'; |
||
145 | |||
146 | $sql = 'SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typecondition, date_created, email, submitter, town, country, contactby, premium, valid, photo FROM ' . $xoopsDB->prefix('adslight_listing') . " WHERE lid={$lid}"; |
||
147 | $result = $xoopsDB->query($sql); |
||
148 | if (!$xoopsDB->isResultSet($result)) { |
||
149 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
150 | } |
||
151 | while ([$lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typecondition, $date_created, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo] = $xoopsDB->fetchRow( |
||
152 | $result |
||
153 | )) { |
||
154 | $title = \htmlspecialchars($title, ENT_QUOTES | ENT_HTML5); |
||
155 | $status = \htmlspecialchars($status, ENT_QUOTES | ENT_HTML5); |
||
156 | $expire = \htmlspecialchars($expire, ENT_QUOTES | ENT_HTML5); |
||
157 | $type = \htmlspecialchars($type, ENT_QUOTES | ENT_HTML5); |
||
158 | $desctext = $myts->displayTarea($desctext, 1, 1, 1); |
||
159 | $tel = \htmlspecialchars($tel, ENT_QUOTES | ENT_HTML5); |
||
160 | // $price = number_format($price, 2, ',', ' '); |
||
161 | |||
162 | xoops_load('XoopsLocal'); |
||
163 | $tempXoopsLocal = new \XoopsLocal(); |
||
164 | // For US currency with 2 numbers after the decimal comment out if you don't want 2 numbers after decimal |
||
165 | $priceFormatted = $tempXoopsLocal->number_format($price); |
||
166 | // For other countries uncomment the below line and comment out the above line |
||
167 | // $priceFormatted = $tempXoopsLocal->number_format($price); |
||
168 | |||
169 | $typeprice = \htmlspecialchars($typeprice, ENT_QUOTES | ENT_HTML5); |
||
170 | $typecondition = \htmlspecialchars($typecondition, ENT_QUOTES | ENT_HTML5); |
||
171 | $submitter = \htmlspecialchars($submitter, ENT_QUOTES | ENT_HTML5); |
||
172 | $town = \htmlspecialchars($town, ENT_QUOTES | ENT_HTML5); |
||
173 | $country = \htmlspecialchars($country, ENT_QUOTES | ENT_HTML5); |
||
174 | $contactby = \htmlspecialchars($contactby, ENT_QUOTES | ENT_HTML5); |
||
175 | $premium = \htmlspecialchars($premium, ENT_QUOTES | ENT_HTML5); |
||
176 | |||
177 | $date2 = formatTimestamp($date_created, 's'); |
||
178 | |||
179 | echo '<form action="modify_ads.php" method=post>'; |
||
180 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
181 | echo "<table class='bnone'><tr class='head' border='1'> |
||
182 | <td>" . _AM_ADSLIGHT_NUMANN . " </td><td>{$lid} " . _AM_ADSLIGHT_ADDED_ON . " {$date2}</td> |
||
183 | </tr><tr class='head' border='1'> |
||
184 | <td>" . _AM_ADSLIGHT_SENDBY . " </td><td>{$submitter}</td> |
||
185 | </tr><tr class='head' border='1'> |
||
186 | <td>" . _AM_ADSLIGHT_EMAIL . " </td><td><input type=\"text\" name=\"email\" size=\"40\" value=\"{$email}\"></td> |
||
187 | </tr><tr class='head' border='1'> |
||
188 | <td>" . _AM_ADSLIGHT_TEL . " </td><td><input type=\"text\" name=\"tel\" size=\"50\" value=\"{$tel}\"></td> |
||
189 | </tr><tr class='head' border='1'> |
||
190 | <td>" . _AM_ADSLIGHT_TOWN . " </td><td><input type=\"text\" name=\"town\" size=\"40\" value=\"{$town}\"></td> |
||
191 | </tr><tr class='head' border='1'> |
||
192 | <td>" . _AM_ADSLIGHT_COUNTRY . " </td><td><input type=\"text\" name=\"country\" size=\"40\" value=\"{$country}\"></td> |
||
193 | </tr></tr><tr class='head' border='1'>"; |
||
194 | |||
195 | $contactSel1 = $contactSel2 = $contactSel3 = $contactSel4 = ''; |
||
196 | $selected = 'contactSel' . (int)$contactby; |
||
197 | ${$selected} = ' selected'; |
||
198 | |||
199 | echo " <td class='head'>" |
||
200 | . _AM_ADSLIGHT_CONTACTBY |
||
201 | . " </td><td class='head'><select name=\"contactby\">\n" |
||
202 | // . " <option value=\"{$contactby}\">{$contactselect[$contactby]}</option>\n" |
||
203 | . " <option value=\"1\"{$contactSel1}>" |
||
204 | . _AM_ADSLIGHT_CONTACT_BY_EMAIL |
||
205 | . "</option>\n" |
||
206 | . " <option value=\"2\"{$contactSel2}>" |
||
207 | . _AM_ADSLIGHT_CONTACT_BY_PM |
||
208 | . "</option>\n" |
||
209 | . " <option value=\"3\"{$contactSel3}>" |
||
210 | . _AM_ADSLIGHT_CONTACT_BY_BOTH |
||
211 | . "</option>\n" |
||
212 | . " <option value=\"4\"{$contactSel4}>" |
||
213 | . _AM_ADSLIGHT_CONTACT_BY_PHONE |
||
214 | . "</option></select>\n" |
||
215 | . " </td>\n" |
||
216 | . '</tr>'; |
||
217 | |||
218 | echo "<tr><td class='head'>" . _AM_ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\""; |
||
219 | if (0 === (int)$status) { |
||
220 | echo 'checked'; |
||
221 | } |
||
222 | echo '>' . _AM_ADSLIGHT_ACTIVE . ' <input type="radio" name="status" value="1"'; |
||
223 | if (1 === (int)$status) { |
||
224 | echo 'checked'; |
||
225 | } |
||
226 | echo '>' . _AM_ADSLIGHT_INACTIVE . ' <input type="radio" name="status" value="2"'; |
||
227 | if (2 === (int)$status) { |
||
228 | echo 'checked'; |
||
229 | } |
||
230 | echo '>' . _AM_ADSLIGHT_SOLD . '</td></tr>'; |
||
231 | |||
232 | echo "<tr class='head' border='1'> |
||
233 | <td>" . _AM_ADSLIGHT_TITLE2 . " </td><td><input type=\"text\" name=\"title\" size=\"40\" value=\"{$title}\"></td> |
||
234 | </tr><tr class='head' border='1'> |
||
235 | <td>" . _AM_ADSLIGHT_PREMIUM . " </td><td><input type=\"text\" name=\"premium\" size=\"3\" value=\"{$premium}\"></td> |
||
236 | </tr><tr class='head' border='1'> |
||
237 | <td>" . _AM_ADSLIGHT_EXPIRE . " </td><td><input type=\"text\" name=\"expire\" size=\"40\" value=\"{$expire}\"></td> |
||
238 | </tr>"; |
||
239 | ////// Type d'annonce |
||
240 | echo "<tr class='head' border='1'> |
||
241 | <td>" . _AM_ADSLIGHT_TYPE . ' </td><td><select name="type">'; |
||
242 | $sql = 'SELECT nom_type, id_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type'; |
||
243 | $result5 = $xoopsDB->query($sql); |
||
244 | if (!$xoopsDB->isResultSet($result5)) { |
||
245 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
246 | } |
||
247 | while ([$nom_type, $id_type] = $xoopsDB->fetchRow($result5)) { |
||
248 | $sel = ''; |
||
249 | if ($id_type === $type) { |
||
250 | $sel = 'selected'; |
||
251 | } |
||
252 | echo "<option value=\"{$id_type}\"{$sel}>{$nom_type}</option>"; |
||
253 | } |
||
254 | echo '</select></td></tr>'; |
||
255 | |||
256 | ////// Condition |
||
257 | echo "<tr class='head' border='1'> |
||
258 | <td>" . _AM_ADSLIGHT_TYPE_CONDITION . ' </td><td><select name="typecondition">'; |
||
259 | $sql = 'SELECT nom_condition, id_condition FROM ' . $xoopsDB->prefix('adslight_condition') . ' ORDER BY nom_condition'; |
||
260 | $result6 = $xoopsDB->query($sql); |
||
261 | if (!$xoopsDB->isResultSet($result6)) { |
||
262 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
263 | } |
||
264 | while ([$nom_condition, $id_condition] = $xoopsDB->fetchRow($result6)) { |
||
265 | $sel = ''; |
||
266 | if ($id_condition === $typecondition) { |
||
267 | $sel = 'selected'; |
||
268 | } |
||
269 | echo "<option value=\"{$id_condition}\"{$sel}>{$nom_condition}</option>"; |
||
270 | } |
||
271 | echo '</select></td></tr>'; |
||
272 | |||
273 | /////// Price |
||
274 | echo "<tr class='head' border='1'><td>" . _AM_ADSLIGHT_PRICE2 . " </td><td><input type=\"text\" name=\"price\" size=\"20\" value=\"{$price}\"> " . $helper->getConfig('adslight_currency_symbol'); |
||
275 | |||
276 | //////// Price type |
||
277 | $sql = 'SELECT nom_price, id_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY nom_price'; |
||
278 | $resultx = $xoopsDB->query($sql); |
||
279 | if (!$xoopsDB->isResultSet($resultx)) { |
||
280 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
281 | } |
||
282 | |||
283 | echo " <select name=\"typeprice\"><option value=\"{$id_price}\">{$nom_price}</option>"; |
||
284 | while ([$nom_price, $id_price] = $xoopsDB->fetchRow($resultx)) { |
||
285 | $sel = ''; |
||
286 | if ($id_price === $typeprice) { |
||
287 | $sel = 'selected'; |
||
288 | } |
||
289 | echo "<option value=\"{$id_price}\"{$sel}>{$nom_price}</option>"; |
||
290 | } |
||
291 | echo '</select></td>'; |
||
292 | |||
293 | /////// Category |
||
294 | |||
295 | echo "<tr class='head' border='1'> |
||
296 | <td>" . _AM_ADSLIGHT_CAT2 . ' </td><td>'; |
||
297 | $mytree->makeMySelBox('title', 'title', $cid); |
||
298 | echo "</td> |
||
299 | </tr><tr class='head' border='1'> |
||
300 | <td>" . _AM_ADSLIGHT_DESC . ' </td><td>'; |
||
301 | // $options = ['desctext', $desctext, '100%', '200px', 'small']; |
||
302 | $options = []; |
||
303 | $options['name'] = 'desctext'; |
||
304 | $options['value'] = $desctext; |
||
305 | $options['cols'] = '100%'; |
||
306 | $options['width'] = '100%'; |
||
307 | $options['height'] = '400px'; |
||
308 | $options['rows'] = 10; |
||
309 | |||
310 | $wysiwyg_text_area = Utility::getEditor($helper, $options); |
||
311 | echo $wysiwyg_text_area->render(); |
||
312 | |||
313 | echo '</td></tr>'; |
||
314 | |||
315 | echo "<tr class='head' border='1'> |
||
316 | <td>" . _AM_ADSLIGHT_PHOTO1 . " </td><td><input type=\"text\" name=\"photo\" size=\"50\" value=\"{$photo}\"></td> |
||
317 | </tr><tr>"; |
||
318 | $time = time(); |
||
319 | echo "</tr><tr class='head' border='1'> |
||
320 | <td> </td><td><select name=\"op\"> |
||
321 | <option value=\"modifyAds\"> " . _AM_ADSLIGHT_MODIF . ' |
||
322 | <option value="ListingDel"> ' . _AM_ADSLIGHT_DEL . ' |
||
323 | </select><input type="submit" value="' . _AM_ADSLIGHT_GO . '"></td> |
||
324 | </tr></table>'; |
||
325 | echo '<input type="hidden" name="valid" value="Yes">'; |
||
326 | echo "<input type=\"hidden\" name=\"lid\" value=\"{$lid}\">"; |
||
327 | echo "<input type=\"hidden\" name=\"date_created\" value=\"{$time}\">"; |
||
328 | echo "<input type=\"hidden\" name=\"submitter\" value=\"{$submitter}\"> |
||
329 | </form><br>"; |
||
330 | echo '</fieldset><br>'; |
||
331 | xoops_cp_footer(); |
||
332 | } |
||
503 |