XoopsModules25x /
oledrion
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* |
||
| 3 | You may not change or alter any portion of this comment or credits |
||
| 4 | of supporting developers from this source code or any supporting source code |
||
| 5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 6 | |||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * oledrion |
||
| 14 | * |
||
| 15 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 16 | * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
| 17 | * @author Hossein Azizabadi ([email protected]) |
||
| 18 | */ |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Check is admin |
||
| 22 | */ |
||
| 23 | if (!defined('OLEDRION_ADMIN')) { |
||
| 24 | exit(); |
||
| 25 | } |
||
| 26 | |||
| 27 | switch ($action) { |
||
| 28 | case 'default': |
||
| 29 | xoops_cp_header(); |
||
| 30 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||
| 31 | $adminObject->displayNavigation('index.php?op=location'); |
||
| 32 | |||
| 33 | $start = isset($_GET['start']) ? (int)$_GET['start'] : 0; |
||
| 34 | $location = array(); |
||
| 35 | $form = "<form method='post' action='$baseurl' name='frmaddlocation' id='frmaddlocation'><input type='hidden' name='op' id='op' value='location'><input type='hidden' name='action' id='action' value='add'><input type='submit' name='btngo' id='btngo' value='" |
||
| 36 | . _AM_OLEDRION_ADD_ITEM |
||
| 37 | . "'></form>"; |
||
| 38 | echo $form; |
||
| 39 | // OledrionUtility::htitle(_MI_OLEDRION_ADMENU19, 4); |
||
|
0 ignored issues
–
show
|
|||
| 40 | $location = $h_oledrion_location->getAllLocation(new Oledrion_parameters(array( |
||
| 41 | 'start' => $start, |
||
| 42 | 'limit' => $limit |
||
| 43 | ))); |
||
| 44 | $class = ''; |
||
| 45 | echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>"; |
||
| 46 | echo "<tr><th align='center'>" . _AM_OLEDRION_ID . "</th><th align='center'>" . _AM_OLEDRION_LOCATION_TITLE . "</th><th align='center'>" . _AM_OLEDRION_LOCATION_TYPE . "</th><th align='center'>" . _OLEDRION_ONLINE . "</th><th align='center'>" . _AM_OLEDRION_ACTION . '</th></tr>'; |
||
| 47 | foreach ($location as $item) { |
||
| 48 | $id = $item->getVar('location_id'); |
||
| 49 | $class = ($class === 'even') ? 'odd' : 'even'; |
||
| 50 | $actions = array(); |
||
| 51 | $actions[] = "<a href='$baseurl?op=location&action=edit&id=" . $id . "' title='" . _OLEDRION_EDIT . "'>" . $icones['edit'] . '</a>'; |
||
| 52 | $actions[] = "<a href='$baseurl?op=location&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>'; |
||
| 53 | $online = $item->getVar('location_online') == 1 ? _YES : _NO; |
||
| 54 | if ($item->getVar('location_type') === 'parent') { |
||
| 55 | $location_type = _AM_OLEDRION_LOCATION_PARENT; |
||
| 56 | } else { |
||
| 57 | $location_type = _AM_OLEDRION_LOCATION_LOCATION; |
||
| 58 | } |
||
| 59 | echo "<tr class='" . $class . "'>\n"; |
||
| 60 | echo "<td align='center'>" . $id . "</td><td align='center'>" . $item->getVar('location_title') . "</td><td align='center'>" . $location_type . "</td><td align='center'>" . $online . "</td><td align='center'>" . implode(' ', $actions) . "</td>\n"; |
||
| 61 | echo "<tr>\n"; |
||
| 62 | } |
||
| 63 | $class = ($class === 'even') ? 'odd' : 'even'; |
||
| 64 | echo "<tr class='" . $class . "'>\n"; |
||
| 65 | echo "<td colspan='5' align='center'>" . $form . "</td>\n"; |
||
| 66 | echo "</tr>\n"; |
||
| 67 | echo '</table>'; |
||
| 68 | require_once OLEDRION_ADMIN_PATH . 'admin_footer.php'; |
||
| 69 | break; |
||
| 70 | |||
| 71 | case 'add': |
||
| 72 | case 'edit': |
||
| 73 | xoops_cp_header(); |
||
| 74 | $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
||
| 75 | if ($action === 'edit') { |
||
| 76 | $title = _AM_OLEDRION_LOCATION_EDIT; |
||
| 77 | if (empty($id)) { |
||
| 78 | OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5); |
||
| 79 | } |
||
| 80 | // Item exits ? |
||
| 81 | $item = null; |
||
| 82 | $item = $h_oledrion_location->get($id); |
||
| 83 | if (!is_object($item)) { |
||
| 84 | OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
||
| 85 | } |
||
| 86 | $edit = true; |
||
| 87 | $label_submit = _AM_OLEDRION_MODIFY; |
||
| 88 | } else { |
||
| 89 | $title = _AM_OLEDRION_LOCATION_ADD; |
||
| 90 | $item = $h_oledrion_location->create(true); |
||
| 91 | $label_submit = _AM_OLEDRION_ADD; |
||
| 92 | $edit = false; |
||
| 93 | } |
||
| 94 | // Get delivery methods |
||
| 95 | $deliveres = $h_oledrion_delivery->getLocationDelivery(new Oledrion_parameters(array( |
||
| 96 | 'limit' => $limit, |
||
| 97 | 'location' => $id |
||
| 98 | ))); |
||
| 99 | if (empty($deliveres)) { |
||
| 100 | OledrionUtility::redirect(_AM_OLEDRION_LOCATION_DELIVERYADD, $baseurl, 5); |
||
| 101 | } |
||
| 102 | |||
| 103 | $sform = new XoopsThemeForm($title, 'frmaddlocation', $baseurl); |
||
| 104 | $sform->addElement(new XoopsFormHidden('op', 'location')); |
||
| 105 | $sform->addElement(new XoopsFormHidden('action', 'save')); |
||
| 106 | $sform->addElement(new XoopsFormHidden('location_id', $item->getVar('location_id'))); |
||
| 107 | $sform->addElement(new XoopsFormText(_AM_OLEDRION_LOCATION_TITLE, 'location_title', 50, 150, $item->getVar('location_title', 'e')), true); |
||
| 108 | $location_pid = $h_oledrion_location->getAllPid(new Oledrion_parameters()); |
||
| 109 | $mytree = new XoopsObjectTree($location_pid, 'location_id', 'location_pid'); |
||
| 110 | |||
| 111 | View Code Duplication | if (OledrionUtility::checkVerXoops($module, '2.5.9')) { |
|
|
0 ignored issues
–
show
The method
checkVerXoops() does not seem to exist on object<OledrionUtility>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
This code seems to be duplicated across 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. Loading history...
|
|||
| 112 | $select_pid = $mytree->makeSelectElement('location_pid', 'location_title', '--', $item->getVar('location_pid'), true, 0, '', _AM_OLEDRION_LOCATION_PID); |
||
| 113 | $form->addElement($select_pid); |
||
| 114 | } else { |
||
| 115 | $select_pid = $mytree->makeSelBox('location_pid', 'location_title', '-', $item->getVar('location_pid'), true); |
||
| 116 | $sform->addElement(new XoopsFormLabel(_AM_OLEDRION_LOCATION_PID, $select_pid), false); |
||
| 117 | } |
||
| 118 | $product_type = new XoopsFormSelect(_AM_OLEDRION_LOCATION_TYPE, 'location_type', $item->getVar('location_type')); |
||
| 119 | $product_type->addOption('location', _AM_OLEDRION_LOCATION_LOCATION); |
||
| 120 | $product_type->addOption('parent', _AM_OLEDRION_LOCATION_PARENT); |
||
| 121 | $sform->addElement($product_type, true); |
||
| 122 | $sform->addElement(new XoopsFormRadioYN(_OLEDRION_ONLINE_HLP, 'location_online', $item->getVar('location_online')), true); |
||
| 123 | |||
| 124 | $delivery_options = new XoopsFormElementTray(_AM_OLEDRION_LOCATION_DELIVERY, '<br>'); |
||
| 125 | foreach ($deliveres as $delivery) { |
||
| 126 | if (isset($delivery['ld_id']) && is_array($delivery['ld_id'])) { |
||
| 127 | $delivery_checkbox = new XoopsFormCheckBox('', $delivery['delivery_id'] . '_ld_select', $delivery['ld_id']['delivery_select']); |
||
| 128 | $delivery_checkbox->addOption(1, $delivery['delivery_title']); |
||
| 129 | $delivery_options->addElement($delivery_checkbox); |
||
| 130 | $delivery_options->addElement(new XoopsFormText(_AM_OLEDRION_LOCATION_PRICE, $delivery['delivery_id'] . '_ld_price', 16, 16, $delivery['ld_id']['ld_price'])); |
||
| 131 | $delivery_options->addElement(new XoopsFormText(_AM_OLEDRION_LOCATION_DELIVERY_TIME, $delivery['delivery_id'] . '_ld_delivery_time', 8, 8, $delivery['ld_id']['ld_delivery_time'])); |
||
| 132 | $delivery_options->addElement(new XoopsFormHidden($delivery['delivery_id'] . '_ld_id', $delivery['ld_id']['ld_id'])); |
||
| 133 | } else { |
||
| 134 | $delivery_checkbox = new XoopsFormCheckBox('', $delivery['delivery_id'] . '_ld_select', ''); |
||
| 135 | $delivery_checkbox->addOption(1, $delivery['delivery_title']); |
||
| 136 | $delivery_options->addElement($delivery_checkbox); |
||
| 137 | $delivery_options->addElement(new XoopsFormText(_AM_OLEDRION_LOCATION_PRICE, $delivery['delivery_id'] . '_ld_price', 16, 16, '')); |
||
| 138 | $delivery_options->addElement(new XoopsFormText(_AM_OLEDRION_LOCATION_DELIVERY_TIME, $delivery['delivery_id'] . '_ld_delivery_time', 8, 8, '')); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | $sform->addElement($delivery_options); |
||
| 143 | $button_tray = new XoopsFormElementTray('', ''); |
||
| 144 | $submit_btn = new XoopsFormButton('', 'post', $label_submit, 'submit'); |
||
| 145 | $button_tray->addElement($submit_btn); |
||
| 146 | $sform->addElement($button_tray); |
||
| 147 | $sform =& OledrionUtility::formMarkRequiredFields($sform); |
||
| 148 | $sform->display(); |
||
| 149 | require_once OLEDRION_ADMIN_PATH . 'admin_footer.php'; |
||
| 150 | break; |
||
| 151 | |||
| 152 | case 'save': |
||
| 153 | xoops_cp_header(); |
||
| 154 | $id = isset($_POST['location_id']) ? (int)$_POST['location_id'] : 0; |
||
| 155 | if (!empty($id)) { |
||
| 156 | $edit = true; |
||
| 157 | $item = $h_oledrion_location->get($id); |
||
| 158 | if (!is_object($item)) { |
||
| 159 | OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5); |
||
| 160 | } |
||
| 161 | $item->unsetNew(); |
||
| 162 | } else { |
||
| 163 | $item = $h_oledrion_location->create(true); |
||
| 164 | } |
||
| 165 | |||
| 166 | $post = $_POST; |
||
| 167 | $location_delivery = array(); |
||
| 168 | $deliveres = $h_oledrion_delivery->getLocationDelivery(new Oledrion_parameters(array( |
||
| 169 | 'limit' => $limit, |
||
| 170 | 'location' => $id |
||
| 171 | ))); |
||
| 172 | foreach ($deliveres as $delivery) { |
||
| 173 | if (isset($post[$delivery['delivery_id'] . '_ld_select'])) { |
||
| 174 | $location_delivery[$delivery['delivery_id']]['ld_location'] = $id; |
||
| 175 | $location_delivery[$delivery['delivery_id']]['ld_delivery'] = (int)$delivery['delivery_id']; |
||
| 176 | $location_delivery[$delivery['delivery_id']]['ld_price'] = (int)$post[$delivery['delivery_id'] . '_ld_price']; |
||
| 177 | $location_delivery[$delivery['delivery_id']]['ld_delivery_time'] = (int)$post[$delivery['delivery_id'] . '_ld_delivery_time']; |
||
| 178 | } |
||
| 179 | unset($post[$delivery['delivery_id'] . '_ld_id'], $post[$delivery['delivery_id'] . '_ld_select'], $post[$delivery['delivery_id'] . '_ld_price'], $post[$delivery['delivery_id'] . '_ld_delivery_time']); |
||
| 180 | } |
||
| 181 | |||
| 182 | $opRedirect = 'location'; |
||
| 183 | $item->setVars($post); |
||
| 184 | if ($post['location_type'] === 'parent') { |
||
| 185 | $item->setVar('location_pid', 0); |
||
| 186 | } |
||
| 187 | $res = $h_oledrion_location->insert($item); |
||
| 188 | |||
| 189 | $location_id = $item->getVar('location_id'); |
||
| 190 | // Save payments for each delivery type |
||
| 191 | if ($edit) { |
||
| 192 | // Suppression préalable |
||
| 193 | $criteria = new CriteriaCompo(); |
||
| 194 | $criteria->add(new Criteria('ld_location', $location_id, '=')); |
||
| 195 | $h_oledrion_location_delivery->deleteAll($criteria); |
||
| 196 | } |
||
| 197 | if (!empty($location_delivery)) { |
||
| 198 | foreach ($location_delivery as $ld) { |
||
| 199 | $item2 = $h_oledrion_location_delivery->create(true); |
||
| 200 | $item2->setVar('ld_location', $location_id); |
||
| 201 | $item2->setVar('ld_delivery', $ld['ld_delivery']); |
||
| 202 | $item2->setVar('ld_price', $ld['ld_price']); |
||
| 203 | $item2->setVar('ld_delivery_time', $ld['ld_delivery_time']); |
||
| 204 | $res1 = $h_oledrion_location_delivery->insert($item2); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | if ($res) { |
||
| 209 | OledrionUtility::updateCache(); |
||
| 210 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2); |
||
| 211 | } else { |
||
| 212 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5); |
||
| 213 | } |
||
| 214 | |||
| 215 | require_once OLEDRION_ADMIN_PATH . 'admin_footer.php'; |
||
| 216 | break; |
||
| 217 | |||
| 218 | View Code Duplication | case 'delete': |
|
| 219 | xoops_cp_header(); |
||
| 220 | $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; |
||
| 221 | if ($id == 0) { |
||
| 222 | OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5); |
||
| 223 | } |
||
| 224 | $location = null; |
||
| 225 | $location = $h_oledrion_location->get($id); |
||
| 226 | if (!is_object($location)) { |
||
| 227 | OledrionUtility::redirect(_AM_OLEDRION_ERROR_10, $baseurl, 5); |
||
| 228 | } |
||
| 229 | $msg = sprintf(_AM_OLEDRION_CONF_DEL_ITEM, $location->getVar('location_title')); |
||
| 230 | xoops_confirm(array('op' => 'location', 'action' => 'confdelete', 'id' => $id), 'index.php', $msg); |
||
| 231 | break; |
||
| 232 | |||
| 233 | View Code Duplication | case 'confdelete': |
|
| 234 | |||
| 235 | xoops_cp_header(); |
||
| 236 | $id = isset($_POST['id']) ? (int)$_POST['id'] : 0; |
||
| 237 | if (empty($id)) { |
||
| 238 | OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5); |
||
| 239 | } |
||
| 240 | $opRedirect = 'location'; |
||
| 241 | |||
| 242 | $item = null; |
||
| 243 | $item = $h_oledrion_location->get($id); |
||
| 244 | if (is_object($item)) { |
||
| 245 | //Delete location_delivery info |
||
| 246 | $criteria = new CriteriaCompo(); |
||
| 247 | $criteria->add(new Criteria('ld_location', $item->getVar('location_id'))); |
||
| 248 | $h_oledrion_location_delivery->deleteAll($criteria); |
||
| 249 | // Delete delivery |
||
| 250 | $res = $h_oledrion_location->delete($item); |
||
| 251 | if ($res) { |
||
| 252 | OledrionUtility::updateCache(); |
||
| 253 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2); |
||
| 254 | } else { |
||
| 255 | OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5); |
||
| 256 | } |
||
| 257 | } else { |
||
| 258 | OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5); |
||
| 259 | } |
||
| 260 | break; |
||
| 261 | } |
||
| 262 |
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.