Passed
Pull Request — master (#81)
by Michael
02:53
created

admin/audios.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
 
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * Module: Yogurt
17
 *
18
 * @category        Module
19
 * @package         yogurt
20
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
21
 * @copyright       {@link https://xoops.org/ XOOPS Project}
22
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 */
24
25
use Xmf\Module\Helper\Permission;
26
use Xmf\Request;
27
28
require __DIR__ . '/admin_header.php';
29
xoops_cp_header();
30
//It recovered the value of argument op in URL$
31
$op    = Request::getString('op', 'list');
32
$order = Request::getString('order', 'desc');
33
$sort  = Request::getString('sort', '');
34
35
$adminObject->displayNavigation(basename(__FILE__));
36
$permHelper = new Permission();
37
$uploadDir  = XOOPS_UPLOAD_PATH . '/yogurt/audio/';
38
$uploadUrl  = XOOPS_UPLOAD_URL . '/yogurt/audio/';
39
40
switch ($op) {
41
    case 'new':
42
        $adminObject->addItemButton(AM_YOGURT_AUDIO_LIST, 'audios.php', 'list');
43
        $adminObject->displayButton('left');
44
45
        $audioObject = $audioHandler->create();
46
        $form        = $audioObject->getForm();
47
        $form->display();
48
        break;
49
50
    case 'save':
51
        if (!$GLOBALS['xoopsSecurity']->check()) {
52
            redirect_header('audios.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
53
        }
54
        if (0 !== Request::getInt('audio_id', 0)) {
55
            $audioObject = $audioHandler->get(Request::getInt('audio_id', 0));
56
        } else {
57
            $audioObject = $audioHandler->create();
58
        }
59
60
        // Form save fields
61
        $audioObject->setVar('uid_owner', Request::getVar('uid_owner', ''));
62
        $audioObject->setVar('title', Request::getVar('title', ''));
63
        $audioObject->setVar('author', Request::getVar('author', ''));
64
        $audioObject->setVar('description', Request::getText('description', ''));
65
        //        $audioObject->setVar('filename', Request::getVar('filename', ''));
66
        require_once XOOPS_ROOT_PATH . '/class/uploader.php';
67
        $uploadDir = XOOPS_UPLOAD_PATH . '/yogurt/audio/';
68
        $uploader  = new \XoopsMediaUploader(
69
            $uploadDir, $helper->getConfig('mimetypes'), $helper->getConfig('maxsize'), null, null
70
        );
71
        if ($uploader->fetchMedia(Request::getString('xoops_upload_file')[0], '', 'POST')) {
0 ignored issues
show
'' of type string is incompatible with the type integer expected by parameter $index of XoopsMediaUploader::fetchMedia(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
        if ($uploader->fetchMedia(Request::getString('xoops_upload_file')[0], /** @scrutinizer ignore-type */ '', 'POST')) {
Loading history...
72
            //            $uploader->setPrefix('url_');
73
            $uploader->setPrefix('aud_' . $uid . '_');
74
            $uploader->fetchMedia(Request::getString('xoops_upload_file')[0], '', 'POST');
75
            if (!$uploader->upload()) {
76
                $errors = $uploader->getErrors();
77
                redirect_header('javascript:history.go(-1)', 3, $errors);
78
            } else {
79
                $audioObject->setVar("filename", $uploader->getSavedFileName());
80
            }
81
        }
82
83
        $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_created', '', 'POST'));
84
        $audioObject->setVar('date_created', $dateTimeObj->getTimestamp());
85
        $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('date_updated', '', 'POST'));
86
        $audioObject->setVar('date_updated', $dateTimeObj->getTimestamp());
87
88
        //insert object
89
        if ($audioHandler->insert($audioObject)) {
90
            redirect_header('audios.php?op=list', 2, AM_YOGURT_FORMOK);
91
        }
92
93
        echo $audioObject->getHtmlErrors();
94
        $form = $audioObject->getForm();
95
        $form->display();
96
        break;
97
98
    case 'edit':
99
        $adminObject->addItemButton(AM_YOGURT_ADD_AUDIO, 'audios.php?op=new', 'add');
100
        $adminObject->addItemButton(AM_YOGURT_AUDIO_LIST, 'audios.php', 'list');
101
        $adminObject->displayButton('left');
102
        $audioObject = $audioHandler->get(Request::getString('audio_id', ''));
103
        $form        = $audioObject->getForm();
104
        $form->display();
105
        break;
106
107
    case 'delete':
108
        $audioObject = $audioHandler->get(Request::getString('audio_id', ''));
109
        if (1 === Request::getInt('ok', 0)) {
110
            if (!$GLOBALS['xoopsSecurity']->check()) {
111
                redirect_header('audios.php', 3, implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
112
            }
113
            if ($audioHandler->delete($audioObject)) {
114
                redirect_header('audios.php', 3, AM_YOGURT_FORMDELOK);
115
            } else {
116
                echo $audioObject->getHtmlErrors();
117
            }
118
        } else {
119
            xoops_confirm(
120
                [
121
                    'ok'       => 1,
122
                    'audio_id' => Request::getString('audio_id', ''),
123
                    'op'       => 'delete',
124
                ],
125
                Request::getUrl('REQUEST_URI', '', 'SERVER'),
126
                sprintf(
127
                    AM_YOGURT_FORMSUREDEL,
128
                    $audioObject->getVar('title')
129
                )
130
            );
131
        }
132
        break;
133
134
    case 'clone':
135
136
        $id_field = Request::getString('audio_id', '');
137
138
        if ($utility::cloneRecord('yogurt_audios', 'audio_id', $id_field)) {
139
            redirect_header('audios.php', 3, AM_YOGURT_CLONED_OK);
140
        } else {
141
            redirect_header('audios.php', 3, AM_YOGURT_CLONED_FAILED);
142
        }
143
144
        break;
145
    case 'list':
146
    default:
147
        $adminObject->addItemButton(AM_YOGURT_ADD_AUDIO, 'audios.php?op=new', 'add');
148
        $adminObject->displayButton('left');
149
        $start                = Request::getInt('start', 0);
150
        $audioPaginationLimit = $helper->getConfig('userpager');
151
152
        $criteria = new CriteriaCompo();
153
        $criteria->setSort('audio_id ASC, title');
154
        $criteria->setOrder('ASC');
155
        $criteria->setLimit($audioPaginationLimit);
156
        $criteria->setStart($start);
157
        $audioTempRows  = $audioHandler->getCount();
158
        $audioTempArray = $audioHandler->getAll($criteria);
159
        /*
160
        //
161
        //
162
                            <th class='center width5'>".AM_YOGURT_FORM_ACTION."</th>
163
        //                    </tr>";
164
        //            $class = "odd";
165
        */
166
167
        // Display Page Navigation
168
        if ($audioTempRows > $audioPaginationLimit) {
169
            xoops_load('XoopsPageNav');
170
171
            $pagenav = new XoopsPageNav(
172
                $audioTempRows, $audioPaginationLimit, $start, 'start', 'op=list' . '&sort=' . $sort . '&order=' . $order . ''
173
            );
174
            $GLOBALS['xoopsTpl']->assign('pagenav', null === $pagenav ? $pagenav->renderNav() : '');
175
        }
176
177
        $GLOBALS['xoopsTpl']->assign('audioRows', $audioTempRows);
178
        $audioArray = [];
179
180
        //    $fields = explode('|', audio_id:int:11::NOT NULL::primary:audio_id|title:varchar:256::NOT NULL:::title|author:varchar:256::NOT NULL:::author|filename:varchar:256::NOT NULL:::filename|uid_owner:int:11::NOT NULL:::uid_owner|date_created:date:0::NOT NULL:::date_created|date_updated:timestamp:CURRENT_TIMESTAMP::NOT NULL:::date_updated);
181
        //    $fieldsCount    = count($fields);
182
183
        $criteria = new CriteriaCompo();
184
185
        //$criteria->setOrder('DESC');
186
        $criteria->setSort($sort);
187
        $criteria->setOrder($order);
188
        $criteria->setLimit($audioPaginationLimit);
189
        $criteria->setStart($start);
190
191
        $audioCount     = $audioHandler->getCount($criteria);
192
        $audioTempArray = $audioHandler->getAll($criteria);
193
194
        //    for ($i = 0; $i < $fieldsCount; ++$i) {
195
        if ($audioCount > 0) {
196
            foreach (array_keys($audioTempArray) as $i) {
197
                //        $field = explode(':', $fields[$i]);
198
199
                $GLOBALS['xoopsTpl']->assign(
200
                    'selectoraudio_id',
201
                    AM_YOGURT_AUDIO_AUDIO_ID
202
                );
203
                $audioArray['audio_id'] = $audioTempArray[$i]->getVar('audio_id');
204
205
                $GLOBALS['xoopsTpl']->assign('selectoruid_owner', AM_YOGURT_AUDIO_UID_OWNER);
206
                $audioArray['uid_owner'] = strip_tags(
207
                    XoopsUser::getUnameFromId($audioTempArray[$i]->getVar('uid_owner'))
208
                );
209
210
                $GLOBALS['xoopsTpl']->assign('selectorauthor', AM_YOGURT_AUDIO_AUTHOR);
211
                $audioArray['author'] = $audioTempArray[$i]->getVar('author');
212
213
                $GLOBALS['xoopsTpl']->assign('selectortitle', AM_YOGURT_AUDIO_TITLE);
214
                $audioArray['title'] = $audioTempArray[$i]->getVar('title');
215
216
                $GLOBALS['xoopsTpl']->assign('selectordescription', AM_YOGURT_AUDIO_DESCRIPTION);
217
                $audioArray['description'] = $audioTempArray[$i]->getVar('description');
218
219
                $GLOBALS['xoopsTpl']->assign('selectorfilename', AM_YOGURT_AUDIO_URL);
220
                $audioArray['filename'] = $audioTempArray[$i]->getVar('filename');
221
222
                $GLOBALS['xoopsTpl']->assign('selectordate_created', AM_YOGURT_AUDIO_DATE_CREATED);
223
                $audioArray['date_created'] = formatTimestamp($audioTempArray[$i]->getVar('date_created'), 's');
224
225
                $GLOBALS['xoopsTpl']->assign('selectordate_updated', AM_YOGURT_AUDIO_DATE_UPDATED);
226
                $audioArray['date_updated'] = formatTimestamp($audioTempArray[$i]->getVar('date_updated'), 's');
227
228
                $audioArray['edit_delete'] = "<a href='audios.php?op=edit&audio_id=" . $i . "'><img src=" . $pathIcon16 . "/edit.png alt='" . _EDIT . "' title='" . _EDIT . "'></a>
229
               <a href='audios.php?op=delete&audio_id=" . $i . "'><img src=" . $pathIcon16 . "/delete.png alt='" . _DELETE . "' title='" . _DELETE . "'></a>
230
               <a href='audios.php?op=clone&audio_id=" . $i . "'><img src=" . $pathIcon16 . "/editcopy.png alt='" . _CLONE . "' title='" . _CLONE . "'></a>";
231
232
                $GLOBALS['xoopsTpl']->append_by_ref('audiosArrays', $audioArray);
233
                unset($audioArray);
234
            }
235
            unset($audioTempArray);
236
            // Display Navigation
237
            if ($audioCount > $audioPaginationLimit) {
238
                xoops_load('XoopsPageNav');
239
                $pagenav = new XoopsPageNav(
240
                    $audioCount, $audioPaginationLimit, $start, 'start', 'op=list' . '&sort=' . $sort . '&order=' . $order . ''
241
                );
242
                $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
243
            }
244
245
            //                     echo "<td class='center width5'>
246
247
            //                    <a href='audios.php?op=edit&audio_id=".$i."'><img src=".$pathIcon16."/edit.png alt='"._EDIT."' title='"._EDIT."'></a>
248
            //                    <a href='audios.php?op=delete&audio_id=".$i."'><img src=".$pathIcon16."/delete.png alt='"._DELETE."' title='"._DELETE."'></a>
249
            //                    </td>";
250
251
            //                echo "</tr>";
252
253
            //            }
254
255
            //            echo "</table><br><br>";
256
257
            //        } else {
258
259
            //            echo "<table width='100%' cellspacing='1' class='outer'>
260
261
            //                    <tr>
262
263
            //                     <th class='center width5'>".AM_YOGURT_FORM_ACTION."XXX</th>
264
            //                    </tr><tr><td class='errorMsg' colspan='8'>There are noXXX audio</td></tr>";
265
            //            echo "</table><br><br>";
266
267
            //-------------------------------------------
268
269
            echo $GLOBALS['xoopsTpl']->fetch(
270
                XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['xoopsModule']->getVar(
271
                    'dirname'
272
                ) . '/templates/admin/yogurt_admin_audios.tpl'
273
            );
274
        }
275
276
        break;
277
}
278
require __DIR__ . '/admin_footer.php';
279