Completed
Push — master ( 9d3fbd...af269e )
by Michael
09:48
created

admin/actions/payment.php (1 issue)

Upgrade to new PHP Analysis Engine

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=payment');
32
33
        $start   = isset($_GET['start']) ? (int)$_GET['start'] : 0;
34
        $payment = array();
35
        $form    = "<form method='post' action='$baseurl' name='frmaddpayment' id='frmaddpayment'><input type='hidden' name='op' id='op' value='payment'><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_ADMENU21, 4);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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.

Loading history...
40
        $payment = $h_oledrion_payment->getAllPayment(new Oledrion_parameters(array(
41
                                                                                  'start' => $start,
42
                                                                                  'limit' => $limit
43
                                                                              )));
44
45
        $class = '';
46
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
47
        echo "<tr><th align='center'>" . _AM_OLEDRION_ID . "</th><th align='center'>" . _AM_OLEDRION_PAYMENT_TITLE . "</th><th align='center'>" . _AM_OLEDRION_PAYMENT_TYPE . "</th><th align='center'>" . _AM_OLEDRION_PAYMENT_ONLINE . "</th><th align='center'>" . _AM_OLEDRION_ACTION . '</th></tr>';
48
        foreach ($payment as $item) {
49
            $id        = $item->getVar('payment_id');
50
            $class     = ($class === 'even') ? 'odd' : 'even';
51
            $actions   = array();
52
            $actions[] = "<a href='$baseurl?op=payment&action=edit&id=" . $id . "' title='" . _OLEDRION_EDIT . "'>" . $icones['edit'] . '</a>';
53
            $actions[] = "<a href='$baseurl?op=payment&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>';
54
            $online    = $item->getVar('payment_online') == 1 ? _YES : _NO;
55
            if ($item->getVar('payment_type') === 'online') {
56
                $payment_type = _AM_OLEDRION_PAYMENT_ONLINE . '( ' . $item->getVar('payment_gateway') . ' )';
57
            } else {
58
                $payment_type = _AM_OLEDRION_PAYMENT_OFFLINE;
59
            }
60
            echo "<tr class='" . $class . "'>\n";
61
            echo "<td align='center'>" . $id . "</td><td align='center'>" . $item->getVar('payment_title') . "</td><td align='center'>" . $payment_type . "</td><td align='center'>" . $online . "</td><td align='center'>" . implode(' ', $actions) . "</td>\n";
62
            echo "<tr>\n";
63
        }
64
        $class = ($class === 'even') ? 'odd' : 'even';
65
        echo "<tr class='" . $class . "'>\n";
66
        echo "<td colspan='5' align='center'>" . $form . "</td>\n";
67
        echo "</tr>\n";
68
        echo '</table>';
69
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
70
        break;
71
72
    case 'add':
73
    case 'edit':
74
        xoops_cp_header();
75 View Code Duplication
        if ($action === 'edit') {
76
            $title = _AM_OLEDRION_PAYMENT_EDIT;
77
            $id    = isset($_GET['id']) ? (int)$_GET['id'] : 0;
78
            if (empty($id)) {
79
                OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
80
            }
81
            // Item exits ?
82
            $item = null;
83
            $item = $h_oledrion_payment->get($id);
84
            if (!is_object($item)) {
85
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
86
            }
87
            $edit         = true;
88
            $label_submit = _AM_OLEDRION_MODIFY;
89
        } else {
90
            $title        = _AM_OLEDRION_PAYMENT_ADD;
91
            $item         = $h_oledrion_payment->create(true);
92
            $label_submit = _AM_OLEDRION_ADD;
93
            $edit         = false;
94
        }
95
        $sform = new XoopsThemeForm($title, 'frmaddpayment', $baseurl);
96
        $sform->addElement(new XoopsFormHidden('op', 'payment'));
97
        $sform->addElement(new XoopsFormHidden('action', 'save'));
98
        $sform->addElement(new XoopsFormHidden('payment_id', $item->getVar('payment_id')));
99
        $sform->addElement(new XoopsFormText(_AM_OLEDRION_PAYMENT_TITLE, 'payment_title', 50, 150, $item->getVar('payment_title', 'e')), true);
100
        $product_type = new XoopsFormSelect(_AM_OLEDRION_PAYMENT_TYPE, 'payment_type', $item->getVar('payment_type'));
101
        $product_type->addOption('offline', _AM_OLEDRION_PAYMENT_OFFLINE);
102
        $product_type->addOption('online', _AM_OLEDRION_PAYMENT_ONLINE);
103
        $sform->addElement($product_type, true);
104
        $payment_gateway = new XoopsFormSelect(_AM_OLEDRION_PAYMENT_GATEWAY, 'payment_gateway', $item->getVar('payment_gateway'));
105
        $payment_gateway->addOption('offline', _AM_OLEDRION_PAYMENT_GATEWAY_OFFLINE);
106
        $payment_gateway_list = Oledrion_gateways::getInstalledGatewaysList();
107
        foreach ($payment_gateway_list as $payment_gateway_item) {
108
            $payment_gateway->addOption($payment_gateway_item);
109
        }
110
        $sform->addElement($payment_gateway, true);
111 View Code Duplication
        if ($action === 'edit' && $item->pictureExists()) {
112
            $pictureTray = new XoopsFormElementTray(_AM_OLEDRION_CURRENT_PICTURE, '<br>');
113
            $pictureTray->addElement(new XoopsFormLabel('', "<img src='" . $item->getPictureUrl() . "' alt='' border='0'>"));
114
            $deleteCheckbox = new XoopsFormCheckBox('', 'delpicture');
115
            $deleteCheckbox->addOption(1, _DELETE);
116
            $pictureTray->addElement($deleteCheckbox);
117
            $sform->addElement($pictureTray);
118
            unset($pictureTray, $deleteCheckbox);
119
        }
120
        $sform->addElement(new XoopsFormFile(_AM_OLEDRION_PICTURE, 'attachedfile', OledrionUtility::getModuleOption('maxuploadsize')), false);
121
        $editor = OledrionUtility::getWysiwygForm(_AM_OLEDRION_DESCRIPTION, 'payment_description', $item->getVar('payment_description', 'e'), 15, 60, 'description_hidden');
122
        if ($editor) {
123
            $sform->addElement($editor, false);
124
        }
125
        $sform->addElement(new XoopsFormRadioYN(_OLEDRION_ONLINE_HLP, 'payment_online', $item->getVar('payment_online')), true);
126
        $button_tray = new XoopsFormElementTray('', '');
127
        $submit_btn  = new XoopsFormButton('', 'post', $label_submit, 'submit');
128
        $button_tray->addElement($submit_btn);
129
        $sform->addElement($button_tray);
130
        $sform =& OledrionUtility::formMarkRequiredFields($sform);
131
        $sform->display();
132
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
133
        break;
134
135
    case 'save':
136
        xoops_cp_header();
137
        $id = isset($_POST['payment_id']) ? (int)$_POST['payment_id'] : 0;
138
        if (!empty($id)) {
139
            $edit = true;
140
            $item = $h_oledrion_payment->get($id);
141
            if (!is_object($item)) {
142
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
143
            }
144
            $item->unsetNew();
145
        } else {
146
            $item = $h_oledrion_payment->create(true);
147
        }
148
        $opRedirect = 'payment';
149
        $item->setVars($_POST);
150
151
        if ($_POST['payment_type'] === 'offline') {
152
            $item->setVar('payment_gateway', 'offline');
153
        }
154
155
        if ($_POST['payment_type'] === 'online'
156
            && !in_array($_POST['payment_gateway'], Oledrion_gateways::getInstalledGatewaysList())) {
157
            $item->setVar('payment_gateway', Oledrion_gateways::getDefaultGateway());
158
        }
159
160
        if (isset($_POST['delpicture']) && (int)$_POST['delpicture'] == 1) {
161
            $item->deletePicture();
162
        }
163
        $destname = '';
164
        $res1     = OledrionUtility::uploadFile(0, OLEDRION_PICTURES_PATH);
165 View Code Duplication
        if ($res1) {
166
            if (OledrionUtility::getModuleOption('resize_others')) { // Eventuellement on redimensionne l'image
167
                OledrionUtility::resizePicture(OLEDRION_PICTURES_PATH . '/' . $destname, OLEDRION_PICTURES_PATH . '/' . $destname, OledrionUtility::getModuleOption('images_width'), OledrionUtility::getModuleOption('images_height'), true);
168
            }
169
            $item->setVar('payment_image', basename($destname));
170
        } else {
171
            if ($res1 !== false) {
172
                echo $res1;
173
            }
174
        }
175
        $res = $h_oledrion_payment->insert($item);
176
        if ($res) {
177
            OledrionUtility::updateCache();
178
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
179
        } else {
180
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
181
        }
182
        break;
183
184 View Code Duplication
    case 'delete':
185
        xoops_cp_header();
186
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
187
        if ($id == 0) {
188
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
189
        }
190
        $payment = null;
191
        $payment = $h_oledrion_payment->get($id);
192
        if (!is_object($payment)) {
193
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_10, $baseurl, 5);
194
        }
195
        $msg = sprintf(_AM_OLEDRION_CONF_DEL_ITEM, $payment->getVar('payment_title'));
196
        xoops_confirm(array('op' => 'payment', 'action' => 'confdelete', 'id' => $id), 'index.php', $msg);
197
198
        break;
199
200 View Code Duplication
    case 'confdelete':
201
202
        xoops_cp_header();
203
        $id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
204
        if (empty($id)) {
205
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
206
        }
207
        $opRedirect = 'payment';
208
209
        $item = null;
210
        $item = $h_oledrion_payment->get($id);
211
        if (is_object($item)) {
212
            $res = $h_oledrion_payment->delete($item);
213
            if ($res) {
214
                OledrionUtility::updateCache();
215
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
216
            } else {
217
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
218
            }
219
        } else {
220
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
221
        }
222
        break;
223
}
224