Passed
Pull Request — master (#14)
by Michael
04:13
created

admin/actions/payment.php (1 issue)

Severity
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
use Xmf\Request;
21
use XoopsModules\Oledrion;
22
23
/**
24
 * Check is admin
25
 */
26
if (!defined('OLEDRION_ADMIN')) {
27
    exit();
28
}
29
30
switch ($action) {
31
    case 'default':
32
33
        xoops_cp_header();
34
        $adminObject = \Xmf\Module\Admin::getInstance();
35
        $adminObject->displayNavigation('index.php?op=payment');
36
37
        $start   = \Xmf\Request::getInt('start', 0, 'GET');
38
        $payment = [];
39
        $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='"
40
                   . _AM_OLEDRION_ADD_ITEM
41
                   . "'></form>";
42
        echo $form;
43
        //        Oledrion\Utility::htitle(_MI_OLEDRION_ADMENU21, 4);
44
        $payment = $paymentHandler->getAllPayment(new Oledrion\Parameters([
45
                                                                              'start' => $start,
46
                                                                              'limit' => $limit,
47
                                                                          ]));
48
49
        $class = '';
50
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
51
        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>';
52
        foreach ($payment as $item) {
53
            $id           = $item->getVar('payment_id');
54
            $class        = ('even' === $class) ? 'odd' : 'even';
55
            $actions      = [];
56
            $actions[]    = "<a href='$baseurl?op=payment&action=edit&id=" . $id . "' title='" . _OLEDRION_EDIT . "'>" . $icons['edit'] . '</a>';
57
            $actions[]    = "<a href='$baseurl?op=payment&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . '>' . $icons['delete'] . '</a>';
58
            $online       = 1 == $item->getVar('payment_online') ? _YES : _NO;
59
            $payment_type = _AM_OLEDRION_PAYMENT_OFFLINE;
60
            if ('online' === $item->getVar('payment_type')) {
61
                $payment_type = _AM_OLEDRION_PAYMENT_ONLINE . '( ' . $item->getVar('payment_gateway') . ' )';
62
            }
63
            echo "<tr class='" . $class . "'>\n";
64
            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";
65
            echo "<tr>\n";
66
        }
67
        $class = ('even' === $class) ? 'odd' : 'even';
68
        echo "<tr class='" . $class . "'>\n";
69
        echo "<td colspan='5' align='center'>" . $form . "</td>\n";
70
        echo "</tr>\n";
71
        echo '</table>';
72
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
73
74
        break;
75
    case 'add':
76
77
    case 'edit':
78
79
        xoops_cp_header();
80
        if ('edit' === $action) {
81
            $title = _AM_OLEDRION_PAYMENT_EDIT;
82
            $id    = \Xmf\Request::getInt('id', 0, 'GET');
83
            if (empty($id)) {
84
                Oledrion\Utility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
85
            }
86
            // Item exits ?
87
            $item = null;
88
            $item = $paymentHandler->get($id);
89
            if (!is_object($item)) {
90
                Oledrion\Utility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
91
            }
92
            $edit         = true;
93
            $label_submit = _AM_OLEDRION_MODIFY;
94
        } else {
95
            $title        = _AM_OLEDRION_PAYMENT_ADD;
96
            $item         = $paymentHandler->create(true);
97
            $label_submit = _AM_OLEDRION_ADD;
98
            $edit         = false;
99
        }
100
        $sform = new \XoopsThemeForm($title, 'frmaddpayment', $baseurl);
101
        $sform->addElement(new \XoopsFormHidden('op', 'payment'));
102
        $sform->addElement(new \XoopsFormHidden('action', 'save'));
103
        $sform->addElement(new \XoopsFormHidden('payment_id', $item->getVar('payment_id')));
104
        $sform->addElement(new \XoopsFormText(_AM_OLEDRION_PAYMENT_TITLE, 'payment_title', 50, 150, $item->getVar('payment_title', 'e')), true);
105
        $product_type = new \XoopsFormSelect(_AM_OLEDRION_PAYMENT_TYPE, 'payment_type', $item->getVar('payment_type'));
106
        $product_type->addOption('offline', _AM_OLEDRION_PAYMENT_OFFLINE);
107
        $product_type->addOption('online', _AM_OLEDRION_PAYMENT_ONLINE);
108
        $sform->addElement($product_type, true);
109
        $payment_gateway = new \XoopsFormSelect(_AM_OLEDRION_PAYMENT_GATEWAY, 'payment_gateway', $item->getVar('payment_gateway'));
110
        $payment_gateway->addOption('offline', _AM_OLEDRION_PAYMENT_GATEWAY_OFFLINE);
111
        $payment_gateway_list = Oledrion\Gateways::getInstalledGatewaysList();
112
        foreach ($payment_gateway_list as $payment_gateway_item) {
113
            $payment_gateway->addOption($payment_gateway_item);
114
        }
115
        $sform->addElement($payment_gateway, true);
116
        if ('edit' === $action && $item->pictureExists()) {
117
            $pictureTray = new \XoopsFormElementTray(_AM_OLEDRION_CURRENT_PICTURE, '<br>');
118
            $pictureTray->addElement(new \XoopsFormLabel('', "<img src='" . $item->getPictureUrl() . "' alt='' border='0'>"));
119
            $deleteCheckbox = new \XoopsFormCheckBox('', 'delpicture');
120
            $deleteCheckbox->addOption(1, _DELETE);
121
            $pictureTray->addElement($deleteCheckbox);
122
            $sform->addElement($pictureTray);
123
            unset($pictureTray, $deleteCheckbox);
124
        }
125
        $sform->addElement(new \XoopsFormFile(_AM_OLEDRION_PICTURE, 'attachedfile', Oledrion\Utility::getModuleOption('maxuploadsize')), false);
126
127
        $editor = Oledrion\Utility::getWysiwygForm(_AM_OLEDRION_DESCRIPTION, 'payment_description', $item->getVar('payment_description', 'e'), 15, 60, 'description_hidden');
128
        if ($editor) {
0 ignored issues
show
$editor is of type XoopsFormEditor, thus it always evaluated to true.
Loading history...
129
            $sform->addElement($editor, false);
130
        }
131
        $sform->addElement(new \XoopsFormRadioYN(_OLEDRION_ONLINE_HLP, 'payment_online', $item->getVar('payment_online')), true);
132
        $buttonTray = new \XoopsFormElementTray('', '');
133
        $submit_btn = new \XoopsFormButton('', 'post', $label_submit, 'submit');
134
        $buttonTray->addElement($submit_btn);
135
        $sform->addElement($buttonTray);
136
        $sform = Oledrion\Utility::formMarkRequiredFields($sform);
137
        $sform->display();
138
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
139
140
        break;
141
    case 'save':
142
143
        xoops_cp_header();
144
        $id = \Xmf\Request::getInt('payment_id', 0, 'POST');
145
        if (!empty($id)) {
146
            $edit = true;
147
            $item = $paymentHandler->get($id);
148
            if (!is_object($item)) {
149
                Oledrion\Utility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
150
            }
151
            $item->unsetNew();
152
        } else {
153
            $item = $paymentHandler->create(true);
154
        }
155
        $opRedirect = 'payment';
156
        $item->setVars($_POST);
157
158
        if ('offline' === $_POST['payment_type']) {
159
            $item->setVar('payment_gateway', 'offline');
160
        }
161
162
        if ('online' === $_POST['payment_type'] && !in_array($_POST['payment_gateway'], Oledrion\Gateways::getInstalledGatewaysList())) {
163
            $item->setVar('payment_gateway', Oledrion\Gateways::getDefaultGateway());
164
        }
165
166
        if (\Xmf\Request::hasVar('delpicture', 'POST') && 1 == \Xmf\Request::getInt('delpicture', 0, 'POST')) {
167
            $item->deletePicture();
168
        }
169
170
        $bingo1 = Request::getString('payment_image', '', 'POST');
171
        $bingo2 = Request::getString('attachedfile', '', 'POST');
172
173
        if (Request::hasVar('attachedfile', 'POST') && '' !== Request::getString('attachedfile', '', 'POST')) {
174
            $destname = '';
175
176
            $res1 = Oledrion\Utility::uploadFile(0, OLEDRION_PICTURES_PATH);
177
            if ($res1) {
178
                if (Oledrion\Utility::getModuleOption('resize_others')) {
179
                    // Eventuellement on redimensionne l'image
180
                    Oledrion\Utility::resizePicture(OLEDRION_PICTURES_PATH . '/' . $destname, OLEDRION_PICTURES_PATH . '/' . $destname, Oledrion\Utility::getModuleOption('images_width'), Oledrion\Utility::getModuleOption('images_height'), true);
181
                }
182
                $item->setVar('payment_image', basename($destname));
183
            } else {
184
                if (false !== $res1) {
185
                    echo $res1;
186
                }
187
            }
188
        }
189
190
        $res = $paymentHandler->insert($item);
191
        if ($res) {
192
            Oledrion\Utility::updateCache();
193
            Oledrion\Utility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
194
        } else {
195
            Oledrion\Utility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
196
        }
197
198
        break;
199
    case 'delete':
200
201
        xoops_cp_header();
202
        $id = \Xmf\Request::getInt('id', 0, 'GET');
203
        if (0 == $id) {
204
            Oledrion\Utility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
205
        }
206
        $payment = null;
207
        $payment = $paymentHandler->get($id);
208
        if (!is_object($payment)) {
209
            Oledrion\Utility::redirect(_AM_OLEDRION_ERROR_10, $baseurl, 5);
210
        }
211
        $msg = sprintf(_AM_OLEDRION_CONF_DEL_ITEM, $payment->getVar('payment_title'));
212
        xoops_confirm(['op' => 'payment', 'action' => 'confdelete', 'id' => $id], 'index.php', $msg);
213
214
        break;
215
    case 'confdelete':
216
217
        xoops_cp_header();
218
        $id = \Xmf\Request::getInt('id', 0, 'POST');
219
        if (empty($id)) {
220
            Oledrion\Utility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
221
        }
222
        $opRedirect = 'payment';
223
224
        $item = null;
225
        $item = $paymentHandler->get($id);
226
        if (is_object($item)) {
227
            $res = $paymentHandler->delete($item);
228
            if ($res) {
229
                Oledrion\Utility::updateCache();
230
                Oledrion\Utility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
231
            } else {
232
                Oledrion\Utility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
233
            }
234
        } else {
235
            Oledrion\Utility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
236
        }
237
238
        break;
239
}
240