Completed
Push — master ( 7bb5bf...9a4e50 )
by Richard
28:24 queued 22s
created

htdocs/modules/system/admin/images/main.php (1 issue)

Labels
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
 * @copyright    XOOPS Project http://xoops.org/
14
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team, Kazumi Ono (AKA onokazu)
18
 */
19
/* @var XoopsUser $xoopsUser */
20
/* @var XoopsModule $xoopsModule */
21
22
use Xmf\Request;
23
24
// Check users rights
25
if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) {
26
    exit(_NOPERM);
27
}
28
29
//  Check is active
30
if (!xoops_getModuleOption('active_images', 'system')) {
31
    redirect_header('admin.php', 2, _AM_SYSTEM_NOTACTIVE);
32
}
33
34
// Get Action type
35
$op = Request::getString('op', 'list');
36
37
$image_id = Request::getInt('image_id', 0);
38
$imgcat_id = Request::getInt('imgcat_id', 0);
39
40
/* @var  XoopsGroupPermHandler $gperm_handler */
41
$gperm_handler = xoops_getHandler('groupperm');
42
$groups        = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
43
44
// check READ right by category before continue
45
if (isset($imgcat_id) && $op === 'listimg') {
46
    $imgcat_read  = $gperm_handler->checkRight('imgcat_read', $imgcat_id, $groups, $xoopsModule->mid());
47
    $imgcat_write = $gperm_handler->checkRight('imgcat_write', $imgcat_id, $groups, $xoopsModule->mid());
48
    if (!$imgcat_read && !$imgcat_write) {
49
        redirect_header('admin.php?fct=images', 1);
50
    }
51
}
52
53
// check WRITE right by category before continue
54
if (isset($imgcat_id) && ($op === 'addfile' || $op === 'editcat' || $op === 'updatecat' || $op === 'delcatok' || $op === 'delcat')) {
55
    $imgcat_write = $gperm_handler->checkRight('imgcat_write', $imgcat_id, $groups, $xoopsModule->mid());
56
    if (!$imgcat_write) {
57
        redirect_header('admin.php?fct=images', 1);
58
    }
59
}
60
61
// Only website administator can delete categories or images
62
63
if (!$xoopsUser->isAdmin($xoopsModule->mid()) && ($op === 'delfile' || $op === 'delfileok' || $op === 'delcatok' || $op === 'delcat')) {
64
    redirect_header('admin.php?fct=images', 1);
65
}
66
67
switch ($op) {
68
69
    case 'list':
70
        // Define main template
71
        $GLOBALS['xoopsOption']['template_main'] = 'system_images.tpl';
72
        // Call Header
73
        xoops_cp_header();
74
        // Define Stylesheet
75
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
76
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
77
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/lightbox.css');
78
        // Define scripts
79
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
80
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
81
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
82
        $xoTheme->addScript('modules/system/js/admin.js');
83
        // Define Breadcrumb and tips
84
        $xoBreadCrumb->addLink(_AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath'));
85
        $xoBreadCrumb->addHelp(system_adminVersion('images', 'help'));
86
        $xoBreadCrumb->addTips(_AM_SYSTEM_IMAGES_TIPS);
87
        $xoBreadCrumb->render();
88
89
        $imgcat_handler = xoops_getHandler('imagecategory');
90
        $imagecategorys = $imgcat_handler->getObjects();
91
92
        $catcount      = count($imagecategorys);
93
        /* @var  XoopsImageHandler $image_handler */
94
        $image_handler = xoops_getHandler('image');
95
96
        foreach (array_keys($imagecategorys) as $i) {
97
            $imgcat_read  = $gperm_handler->checkRight('imgcat_read', $imagecategorys[$i]->getVar('imgcat_id'), $groups, $xoopsModule->mid());
98
            $imgcat_write = $gperm_handler->checkRight('imgcat_write', $imagecategorys[$i]->getVar('imgcat_id'), $groups, $xoopsModule->mid());
99
            if ($imgcat_read || $imgcat_write) {
100
                $count = $image_handler->getCount(new Criteria('imgcat_id', $imagecategorys[$i]->getVar('imgcat_id')));
101
102
                $cat_images['id']        = $imagecategorys[$i]->getVar('imgcat_id');
103
                $cat_images['name']      = $imagecategorys[$i]->getVar('imgcat_name');
104
                $cat_images['count']     = $count;
105
                $cat_images['size']      = $count;
106
                $cat_images['maxsize']   = $imagecategorys[$i]->getVar('imgcat_maxsize');
107
                $cat_images['maxwidth']  = $imagecategorys[$i]->getVar('imgcat_maxwidth');
108
                $cat_images['maxheight'] = $imagecategorys[$i]->getVar('imgcat_maxheight');
109
                $cat_images['display']   = $imagecategorys[$i]->getVar('imgcat_display');
110
                $cat_images['weight']    = $imagecategorys[$i]->getVar('imgcat_weight');
111
                $cat_images['type']      = $imagecategorys[$i]->getVar('imgcat_type');
112
                $cat_images['store']     = $imagecategorys[$i]->getVar('imgcat_storetype');
113
114
                $xoopsTpl->append_by_ref('cat_img', $cat_images);
115
                unset($cat_images);
116
            }
117
        }
118
        // Image Form
119
        if (!empty($catcount)) {
120
            $form = new XoopsThemeForm(_ADDIMAGE, 'image_form', 'admin.php', 'post', true);
121
            $form->setExtra('enctype="multipart/form-data"');
122
            $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255), true);
123
            $select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id');
124
            $select->addOptionArray($imgcat_handler->getList($groups, 'imgcat_write'));
125
            $form->addElement($select, true);
126
            $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', 5000000));
127
            $form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, 0));
128
            $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', 1, _YES, _NO));
129
            $form->addElement(new XoopsFormHidden('op', 'addfile'));
130
            $form->addElement(new XoopsFormHidden('fct', 'images'));
131
            $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit'));
132
            $form->assign($xoopsTpl);
133
        }
134
        // Category Form
135
        if ($xoopsUser->isAdmin($xoopsModule->mid())) {
136
            $form = new XoopsThemeForm(_AM_SYSTEM_IMAGES_ADDCAT, 'imagecat_form', 'admin.php', 'post', true);
137
            $form->addElement(new XoopsFormText(_AM_SYSTEM_IMAGES_IMGCATNAME, 'imgcat_name', 50, 255), true);
138
            $form->addElement(new XoopsFormSelectGroup(_AM_SYSTEM_IMAGES_IMGCATRGRP, 'readgroup', true, XOOPS_GROUP_ADMIN, 5, true));
139
            $form->addElement(new XoopsFormSelectGroup(_AM_SYSTEM_IMAGES_IMGCATWGRP, 'writegroup', true, XOOPS_GROUP_ADMIN, 5, true));
140
            $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, 1000000));
141
            $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, 800));
142
            $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, 600));
143
            $form->addElement(new XoopsFormText(_AM_SYSTEM_IMAGES_IMGCATWEIGHT, 'imgcat_weight', 3, 4, 0));
144
            $form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_IMAGES_IMGCATDISPLAY, 'imgcat_display', 1, _YES, _NO));
145
146
            $storetype = new XoopsFormRadio(_MD_IMGCATSTRTYPE . '<br><span style="color:#ff0000;">' . _MD_STRTYOPENG . '</span>', 'imgcat_storetype', 'file');
147
            $storetype->addOptionArray(array('file' => _MD_ASFILE, 'db' => _MD_INDB));
148
            $form->addElement($storetype);
149
150
            //$form->addElement(new XoopsFormHidden('imgcat_storetype', 'file'));
151
            $form->addElement(new XoopsFormHidden('op', 'addcat'));
152
            $form->addElement(new XoopsFormHidden('fct', 'images'));
153
            $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
154
            $form->assign($xoopsTpl);
155
        }
156
        // Call Footer
157
        xoops_cp_footer();
158
        break;
159
160
    case 'display_cat':
161
        // Get Image Category handler
162
        $imgcat_handler = xoops_getHandler('imagecategory');
163
        // Get category id
164
		$imgcat_id = Request::getInt('imgcat_id', 0);
165
        if ($imgcat_id > 0) {
166
            $imgcat = $imgcat_handler->get($imgcat_id);
167
            $old    = $imgcat->getVar('imgcat_display');
168
            $imgcat->setVar('imgcat_display', !$old);
169
            if (!$imgcat_handler->insert($imgcat)) {
170
                $error = true;
171
            }
172
        }
173
        break;
174
175
    case 'listimg':
176
        // Get category id
177
		$imgcat_id = Request::getInt('imgcat_id', 0);
178
        if ($imgcat_id <= 0) {
179
            redirect_header('admin.php?fct=images', 1);
180
        }
181
        // Get rights
182
        $imgcat_write = $gperm_handler->checkRight('imgcat_write', $imgcat_id, $groups, $xoopsModule->mid());
183
        // Get category handler
184
        $imgcat_handler = xoops_getHandler('imagecategory');
185
186
        $imagecategory = $imgcat_handler->get($imgcat_id);
187
        if (!is_object($imagecategory)) {
188
            redirect_header('admin.php?fct=images', 1);
189
        }
190
        // Get image handler
191
        $image_handler = xoops_getHandler('image');
192
        // Define main template
193
        $GLOBALS['xoopsOption']['template_main'] = 'system_images.tpl';
194
        // Call header
195
        xoops_cp_header();
196
        // Define Stylesheet
197
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
198
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
199
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/lightbox.css');
200
        // Define scripts
201
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
202
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
203
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
204
        $xoTheme->addScript('modules/system/js/admin.js');
205
206
        // Define Breadcrumb and tips
207
        $xoBreadCrumb->addLink(_AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath'));
208
        $xoBreadCrumb->addLink($imagecategory->getVar('imgcat_name'));
209
        $xoBreadCrumb->addHelp(system_adminVersion('images', 'help') . '#cat');
210
        $xoBreadCrumb->addTips(_AM_SYSTEM_IMAGES_TIPS);
211
        $xoBreadCrumb->render();
212
213
        $criteria = new CriteriaCompo(new Criteria('imgcat_id', $imgcat_id));
214
        $criteria->setSort('image_weight ASC, image_id');
215
        $criteria->setOrder('DESC');
216
        $imgcount = $image_handler->getCount($criteria);
217
        $start    = isset($_GET['start']) ? (int)$_GET['start'] : 0;
218
        $criteria->setStart($start);
219
        $criteria->setLimit(xoops_getModuleOption('images_pager', 'system'));
220
        $images = $image_handler->getObjects($criteria, true, false);
221
222
        if ($imagecategory->getVar('imgcat_storetype') === 'db') {
223
            $xoopsTpl->assign('db_store', 1);
224
        }
225
226
        foreach ($images as $listImage) {
227
            $xoopsTpl->append('images', $listImage->toArray());
228
        }
229
        if ($imgcount > 0) {
230
            if ($imgcount > xoops_getModuleOption('images_pager', 'system')) {
231
                //include_once XOOPS_ROOT_PATH.'/class/pagenav.php';
232
                $nav = new XoopsPageNav($imgcount, xoops_getModuleOption('images_pager', 'system'), $start, 'start', 'fct=images&amp;op=listimg&amp;imgcat_id=' . $imgcat_id);
233
                $xoopsTpl->assign('nav_menu', $nav->renderNav(4));
234
            }
235
        }
236
237
        if (file_exists(XOOPS_ROOT_PATH . '/modules/system/language/' . $GLOBALS['xoopsConfig']['language'] . '/images/lightbox-btn-close.gif')) {
238
            $xoopsTpl->assign('xoops_language', $GLOBALS['xoopsConfig']['language']);
239
        } else {
240
            $xoopsTpl->assign('xoops_language', 'english');
241
        }
242
        $xoopsTpl->assign('listimg', true);
243
        $xoopsTpl->assign('imgcat_id', $imgcat_id);
244
245
        // Image Form
246
        $form = new XoopsThemeForm(_ADDIMAGE, 'image_form', 'admin.php', 'post', true);
247
        $form->setExtra('enctype="multipart/form-data"');
248
        $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255), true);
249
        $select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id', $imgcat_id);
250
        $select->addOptionArray($imgcat_handler->getList($groups, 'imgcat_write'));
251
        $form->addElement($select, true);
252
        $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', 5000000));
253
        $form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, 0));
254
        $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', 1, _YES, _NO));
255
        $form->addElement(new XoopsFormHidden('op', 'addfile'));
256
        $form->addElement(new XoopsFormHidden('fct', 'images'));
257
        $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit'));
258
        $form->assign($xoopsTpl);
259
260
        // Call Footer
261
        xoops_cp_footer();
262
        break;
263
264
    case 'display_img':
265
        // Get image handler
266
        $image_handler = xoops_getHandler('image');
267
        // Get image id
268
		$image_id = Request::getInt('image_id', 0);
269
        if ($image_id > 0) {
270
            $img = $image_handler->get($image_id);
271
            $old = $img->getVar('image_display');
272
            $img->setVar('image_display', !$old);
273
            if (!$image_handler->insert($img)) {
274
                $error = true;
275
            }
276
        }
277
        break;
278
279
    case 'editimg':
280
        // Define main template
281
        $GLOBALS['xoopsOption']['template_main'] = 'system_images.tpl';
282
        // Call Header
283
        xoops_cp_header();
284
        // Define Stylesheet
285
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
286
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
287
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/lightbox.css');
288
        // Define scripts
289
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
290
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
291
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
292
        $xoTheme->addScript('modules/system/js/admin.js');
293
        // Get image handler
294
        $image_handler  = xoops_getHandler('image');
295
        $imgcat_handler = xoops_getHandler('imagecategory');
296
        // Get image id
297
		$image_id = Request::getInt('image_id', 0);
298
299
        if ($image_id > 0) {
300
            $image     = $image_handler->get($image_id);
301
            $image_cat = $imgcat_handler->get($image->getVar('imgcat_id'));
302
            // Define Breadcrumb and tips
303
            $xoBreadCrumb->addLink(_AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath'));
304
            $xoBreadCrumb->addLink($image_cat->getVar('imgcat_name'), system_adminVersion('images', 'adminpath') . '&amp;op=listimg&amp;imgcat_id=' . $image->getVar('imgcat_id'));
305
            $xoBreadCrumb->addLink(_AM_SYSTEM_IMAGES_EDITIMG);
306
            $xoBreadCrumb->render();
307
            $msg = '<div class="txtcenter"><img class="tooltip" src="' . XOOPS_URL . '/image.php?id=' . $image->getVar('image_id') . '&amp;width=120&amp;height=120" alt="' . $image->getVar('image_nicename') . '" title="' . $image->getVar('image_nicename') . '" style="max-width:120px; max-height:120px;"/></div>';
308
309
            $xoopsTpl->assign('edit_thumbs', $msg);
310
311
            $form = new XoopsThemeForm(_AM_SYSTEM_IMAGES_EDITIMG, 'edit_form', 'admin.php', 'post', true);
312
            $form->setExtra('enctype="multipart/form-data"');
313
            $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255, $image->getVar('image_nicename')), true);
314
            $select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id', $image->getVar('imgcat_id'));
315
            $select->addOptionArray($imgcat_handler->getList($groups, 'imgcat_write', $image->getVar('imgcat_write')));
316
            $form->addElement($select, true);
317
            //$form->addElement(new XoopsFormFile( _IMAGEFILE, 'image_file', 5000000) );
318
            $form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, $image->getVar('image_weight')));
319
            $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', $image->getVar('image_display'), _YES, _NO));
320
            $form->addElement(new XoopsFormHidden('image_id', $image_id));
321
            $form->addElement(new XoopsFormHidden('op', 'save'));
322
            $form->addElement(new XoopsFormHidden('fct', 'images'));
323
            //$form->addElement(new XoopsFormButton( '', 'img_button', _SUBMIT, 'submit' ) );
324
            $form->addElement(new XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
325
            $form->assign($xoopsTpl);
326
        } else {
327
            redirect_header('admin.php?fct=images', 1, _AM_SYSTEM_DBERROR);
328
        }
329
        // Call Footer
330
        xoops_cp_footer();
331
        break;
332
333
    case 'delfile':
334
        // Get image handler
335
        $image_handler  = xoops_getHandler('image');
336
        $imgcat_handler = xoops_getHandler('imagecategory');
337
        // Call Header
338
        xoops_cp_header();
339
        // Define Stylesheet
340
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
341
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
342
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/lightbox.css');
343
        // Define scripts
344
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
345
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
346
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
347
        $xoTheme->addScript('modules/system/js/admin.js');
348
        // Get image id
349
		$image_id = Request::getInt('image_id', 0);
350
        if ($image_id > 0) {
351
            $image     = $image_handler->get($image_id);
352
            $image_cat = $imgcat_handler->get($image->getVar('imgcat_id'));
353
            if ($image_cat->getVar('imgcat_storetype') === 'db') {
354
                $msg = '<div style="width: 180px;margin:0 auto;"><img class="thumb" src="' . XOOPS_URL . '/image.php?id=' . $image->getVar('image_id') . '&width=120&height=120" alt="" title="" style="max-width:120px; max-height:120px;"/></div>';
355
            } else {
356
                $msg = '<div style="width: 180px;margin:0 auto;"><img class="thumb" src="' . XOOPS_URL . '/image.php?id=' . $image->getVar('image_id') . '&width=120&height=120" alt="" title="" style="max-width:120px; max-height:120px;"/></div>';
357
            }
358
            $msg .= '<div class="spacer">' . $image->getVar('image_nicename') . '</div>';
359
            $msg .= '<div class="spacer">' . _AM_SYSTEM_IMAGES_RUDELIMG . '</div>';
360
            xoops_confirm(array('op' => 'delfileok', 'image_id' => $image_id, 'fct' => 'images'), 'admin.php', $msg, _DELETE);
361
        } else {
362
            redirect_header('admin.php?fct=images', 1, _AM_SYSTEM_DBERROR);
363
        }
364
        // Call Footer
365
        xoops_cp_footer();
366
        break;
367
368
    case 'delfileok':
369
        if (!$GLOBALS['xoopsSecurity']->check()) {
370
            redirect_header('admin.php?fct=images', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
371
        }
372
        // Get image id
373
        $image_id = Request::getInt('image_id', 0);
374
        if ($image_id <= 0) {
375
            redirect_header('admin.php?fct=images', 1);
376
        }
377
        $image_handler = xoops_getHandler('image');
378
        $image         = $image_handler->get($image_id);
379
        if (!is_object($image)) {
380
            redirect_header('admin.php?fct=images', 1);
381
        }
382
        if (!$image_handler->delete($image)) {
383
            xoops_cp_header();
384
            xoops_error(sprintf(_AM_SYSTEM_IMAGES_FAILDEL, $image->getVar('image_id')));
385
            xoops_cp_footer();
386
            exit();
387
        }
388
        @unlink(XOOPS_UPLOAD_PATH . '/' . $image->getVar('image_name'));
389
        redirect_header('admin.php?fct=images&op=listimg&imgcat_id=' . $image->getVar('imgcat_id'), 2, _AM_SYSTEM_DBUPDATED);
390
        break;
391
392
    case 'save':
393
        if (!$GLOBALS['xoopsSecurity']->check()) {
394
            redirect_header('admin.php?fct=images', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
395
        }
396
        // Get image handler
397
        $image_handler = xoops_getHandler('image');
398
        // Call Header
399
        xoops_cp_header();
400
        // Define Stylesheet
401
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
402
        // Get image id
403
        $image_id = Request::getInt('image_id', 0);
404
        if ($image_id > 0) {
405
            $image = $image_handler->get($image_id);
406
			$image->setVar('image_nicename', Request::getString('image_nicename', ''));
407
			$image->setVar('image_weight', Request::getInt('image_weight', 0));
408
			$image->setVar('image_display', Request::getInt('image_display', 1));
409
			$image->setVar('imgcat_id', Request::getInt('imgcat_id', 0));
410
            if (!$image_handler->insert($image)) {
411
				xoops_cp_header();
412
                echo sprintf(_AM_SYSTEM_IMAGES_FAILSAVE, $image->getVar('image_nicename'));
413
                xoops_cp_footer();
414
                exit;
415
            }
416
            redirect_header('admin.php?fct=images&op=listimg&imgcat_id=' . $image->getVar('imgcat_id'), 2, _AM_SYSTEM_DBUPDATED);
417
        }
418
419
        // Call Footer
420
        xoops_cp_footer();
421
        break;
422
423
    case 'addfile':
424
        if (!$GLOBALS['xoopsSecurity']->check()) {
425
            redirect_header('admin.php?fct=images', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
426
        }
427
        $imgcat_handler = xoops_getHandler('imagecategory');
428
        $imagecategory  = $imgcat_handler->get((int)$imgcat_id);
429
        if (!is_object($imagecategory)) {
430
            redirect_header('admin.php?fct=images', 1);
431
        }
432
        xoops_load('xoopsmediauploader');
433
        $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH . '/images', array(
434
            'image/gif',
435
            'image/jpeg',
436
            'image/pjpeg',
437
            'image/x-png',
438
            'image/png',
439
            'image/bmp'), $imagecategory->getVar('imgcat_maxsize'), $imagecategory->getVar('imgcat_maxwidth'), $imagecategory->getVar('imgcat_maxheight'));
440
        $uploader->setPrefix('img');
441
        $err    = array();
442
        $ucount = count($_POST['xoops_upload_file']);
443
        for ($i = 0; $i < $ucount; ++$i) {
444
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {
445
                if (!$uploader->upload()) {
446
                    $err[] =& $uploader->getErrors();
447
                } else {
448
                    $image_handler = xoops_getHandler('image');
449
                    $image         = $image_handler->create();
450
                    $image->setVar('image_name', 'images/' . $uploader->getSavedFileName());
451
                    $image->setVar('image_nicename', Request::getString('image_nicename', ''));
452
                    $image->setVar('image_mimetype', $uploader->getMediaType());
453
                    $image->setVar('image_created', time());
454
                    $image->setVar('image_display', Request::getInt('image_display', 1));
455
                    $image->setVar('image_weight', Request::getInt('image_weight', 0));
456
                    $image->setVar('imgcat_id', $imgcat_id);
457
                    if ($imagecategory->getVar('imgcat_storetype') === 'db') {
458
                        $fp      = @fopen($uploader->getSavedDestination(), 'rb');
459
                        $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
460
                        @fclose($fp);
461
                        $image->setVar('image_body', $fbinary, true);
462
                        @unlink($uploader->getSavedDestination());
463
                    }
464
                    if (!$image_handler->insert($image)) {
465
                        $err[] = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename'));
466
                    }
467
                }
468
            } else {
469
                $err[] = sprintf(_FAILFETCHIMG, $i);
470
                $err   = array_merge($err, $uploader->getErrors(false));
471
            }
472
        }
473
        if (count($err) > 0) {
474
            xoops_cp_header();
475
            xoops_error($err);
476
            xoops_cp_footer();
477
            exit();
478
        }
479
        redirect_header('admin.php?fct=images&op=listimg&imgcat_id=' . $image->getVar('imgcat_id'), 2, _AM_SYSTEM_DBUPDATED);
480
        break;
481
482
    case 'addcat':
483
        if (!$GLOBALS['xoopsSecurity']->check()) {
484
            redirect_header('admin.php?fct=images', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
485
        }
486
        $imgcat_handler = xoops_getHandler('imagecategory');
487
        $imagecategory  = $imgcat_handler->create();
488
        $imagecategory->setVar('imgcat_name', Request::getString('imgcat_name', ''));
489
        $imagecategory->setVar('imgcat_maxsize', Request::getInt('imgcat_maxsize', 1000000));
490
		$imagecategory->setVar('imgcat_maxwidth', Request::getInt('imgcat_maxwidth', 800));
491
		$imagecategory->setVar('imgcat_maxheight', Request::getInt('imgcat_maxheight', 600));
492
		$imagecategory->setVar('imgcat_display', Request::getInt('imgcat_display', 1));
493
		$imagecategory->setVar('imgcat_weight', Request::getInt('imgcat_weight', 0));
494
		$imagecategory->setVar('imgcat_storetype', Request::getString('imgcat_storetype', 'file'));
495
        $imagecategory->setVar('imgcat_type', 'C');
496
        if (!$imgcat_handler->insert($imagecategory)) {
497
            xoops_cp_header();
498
            echo 'Failed save category ' . $imagecategory->getVar('imgcat_name') . ' into the database';
499
            xoops_cp_footer();
500
            exit();
501
        }
502
        $newid                     = $imagecategory->getVar('imgcat_id');
503
        /* @var  XoopsGroupPermHandler $imagecategoryperm_handler */
504
        $imagecategoryperm_handler = xoops_getHandler('groupperm');
505
        if (!isset($readgroup)) {
506
            $readgroup = array();
507
        }
508
        if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
509
            $readgroup[] = XOOPS_GROUP_ADMIN;
510
        }
511
        foreach ($readgroup as $rgroup) {
512
            $imagecategoryperm = $imagecategoryperm_handler->create();
513
            $imagecategoryperm->setVar('gperm_groupid', $rgroup);
514
            $imagecategoryperm->setVar('gperm_itemid', $newid);
515
            $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
516
            $imagecategoryperm->setVar('gperm_modid', 1);
517
            $imagecategoryperm_handler->insert($imagecategoryperm);
518
            unset($imagecategoryperm);
519
        }
520
        if (!isset($writegroup)) {
521
            $writegroup = array();
522
        }
523
        if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
524
            $writegroup[] = XOOPS_GROUP_ADMIN;
525
        }
526
        foreach ($writegroup as $wgroup) {
527
            $imagecategoryperm = $imagecategoryperm_handler->create();
528
            $imagecategoryperm->setVar('gperm_groupid', $wgroup);
529
            $imagecategoryperm->setVar('gperm_itemid', $newid);
530
            $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
531
            $imagecategoryperm->setVar('gperm_modid', 1);
532
            $imagecategoryperm_handler->insert($imagecategoryperm);
533
            unset($imagecategoryperm);
534
        }
535
536
        redirect_header('admin.php?fct=images', 2, _AM_SYSTEM_DBUPDATED);
537
        break;
538
539
    case 'editcat':
540
        if ($imgcat_id <= 0) {
541
            redirect_header('admin.php?fct=images', 1);
542
        }
543
        $imgcat_handler = xoops_getHandler('imagecategory');
544
        $imagecategory  = $imgcat_handler->get($imgcat_id);
545
        if (!is_object($imagecategory)) {
546
            redirect_header('admin.php?fct=images', 1);
547
        }
548
549
        $imagecategoryperm_handler = xoops_getHandler('groupperm');
550
        $form                      = new XoopsThemeForm(_AM_SYSTEM_IMAGES_EDITIMG, 'imagecat_form', 'admin.php', 'post', true);
551
        $form->addElement(new XoopsFormText(_AM_SYSTEM_IMAGES_IMGCATNAME, 'imgcat_name', 50, 255, $imagecategory->getVar('imgcat_name')), true);
552
        $form->addElement(new XoopsFormSelectGroup(_AM_SYSTEM_IMAGES_IMGCATRGRP, 'readgroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_read', $imgcat_id), 5, true));
553
        $form->addElement(new XoopsFormSelectGroup(_AM_SYSTEM_IMAGES_IMGCATWGRP, 'writegroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_write', $imgcat_id), 5, true));
554
        $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, $imagecategory->getVar('imgcat_maxsize')));
555
        $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, $imagecategory->getVar('imgcat_maxwidth')));
556
        $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, $imagecategory->getVar('imgcat_maxheight')));
557
        $form->addElement(new XoopsFormText(_AM_SYSTEM_IMAGES_IMGCATWEIGHT, 'imgcat_weight', 3, 4, $imagecategory->getVar('imgcat_weight')));
558
        $form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_IMAGES_IMGCATDISPLAY, 'imgcat_display', $imagecategory->getVar('imgcat_display'), _YES, _NO));
559
        $storetype = array('db' => _AM_SYSTEM_IMAGES_INDB, 'file' => _AM_SYSTEM_IMAGES_ASFILE);
560
        $form->addElement(new XoopsFormLabel(_AM_SYSTEM_IMAGES_IMGCATSTRTYPE, $storetype[$imagecategory->getVar('imgcat_storetype')]));
561
        $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id));
562
        $form->addElement(new XoopsFormHidden('op', 'updatecat'));
563
        $form->addElement(new XoopsFormHidden('fct', 'images'));
564
        //$form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
565
        $form->addElement(new XoopsFormButtonTray('imgcat_button', _SUBMIT, 'submit', '', false));
566
        // Define main template
567
        $GLOBALS['xoopsOption']['template_main'] = 'system_header.tpl';
568
        // Call Header
569
        xoops_cp_header();
570
        // Define Stylesheet
571
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
572
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
573
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/lightbox.css');
574
        // Define scripts
575
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
576
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
577
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
578
        $xoTheme->addScript('modules/system/js/admin.js');
579
        // Define Breadcrumb and tips
580
        $xoBreadCrumb->addLink(_AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath'));
581
        $xoBreadCrumb->addLink($imagecategory->getVar('imgcat_name'), '');
582
        $xoBreadCrumb->render();
583
        echo '<br>';
584
        $form->display();
585
        // Call Footer
586
        xoops_cp_footer();
587
        exit();
588
589
    case 'updatecat':
590
        if (!$GLOBALS['xoopsSecurity']->check() || $imgcat_id <= 0) {
591
            redirect_header('admin.php?fct=images', 1, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
592
        }
593
        $imgcat_handler = xoops_getHandler('imagecategory');
594
        $imagecategory  = $imgcat_handler->get($imgcat_id);
595
        if (!is_object($imagecategory)) {
596
            redirect_header('admin.php?fct=images', 1);
597
        }
598
		$imagecategory->setVar('imgcat_name', Request::getString('imgcat_name', ''));
599
        $imagecategory->setVar('imgcat_maxsize', Request::getInt('imgcat_maxsize', 1000000));
600
		$imagecategory->setVar('imgcat_maxwidth', Request::getInt('imgcat_maxwidth', 800));
601
		$imagecategory->setVar('imgcat_maxheight', Request::getInt('imgcat_maxheight', 600));
602
		$imagecategory->setVar('imgcat_display', Request::getInt('imgcat_display', 1));
603
		$imagecategory->setVar('imgcat_weight', Request::getInt('imgcat_weight', 0));
604
        if (!$imgcat_handler->insert($imagecategory)) {
605
			xoops_cp_header();
606
            echo 'Failed save category ' . $imagecategory->getVar('imgcat_name') . ' into the database';
607
            xoops_cp_footer();
608
            exit();
609
        }
610
        $imagecategoryperm_handler = xoops_getHandler('groupperm');
611
        $criteria                  = new CriteriaCompo(new Criteria('gperm_itemid', $imgcat_id));
612
        $criteria->add(new Criteria('gperm_modid', 1));
613
        $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'imgcat_write'));
614
        $criteria2->add(new Criteria('gperm_name', 'imgcat_read'), 'OR');
615
        $criteria->add($criteria2);
616
        $imagecategoryperm_handler->deleteAll($criteria);
617
        $readgroup = Request::getArray('readgroup', array());
618
        if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
619
            $readgroup[] = XOOPS_GROUP_ADMIN;
620
        }
621
        foreach ($readgroup as $rgroup) {
622
            $imagecategoryperm = $imagecategoryperm_handler->create();
623
            $imagecategoryperm->setVar('gperm_groupid', $rgroup);
624
            $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
625
            $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
626
            $imagecategoryperm->setVar('gperm_modid', 1);
627
            $imagecategoryperm_handler->insert($imagecategoryperm);
628
            unset($imagecategoryperm);
629
        }
630
        $writegroup = Request::getArray('writegroup', array());
631
        if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
632
            $writegroup[] = XOOPS_GROUP_ADMIN;
633
        }
634
        foreach ($writegroup as $wgroup) {
635
            $imagecategoryperm = $imagecategoryperm_handler->create();
636
            $imagecategoryperm->setVar('gperm_groupid', $wgroup);
637
            $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
638
            $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
639
            $imagecategoryperm->setVar('gperm_modid', 1);
640
            $imagecategoryperm_handler->insert($imagecategoryperm);
641
            unset($imagecategoryperm);
642
        }
643
        redirect_header('admin.php?fct=images', 2, _AM_SYSTEM_DBUPDATED);
644
        break;
645
646
    case 'delcat':
647
        // Call Header
648
        xoops_cp_header();
649
        // Display message
650
        xoops_confirm(array('op' => 'delcatok', 'imgcat_id' => $imgcat_id, 'fct' => 'images'), 'admin.php', _AM_SYSTEM_IMAGES_RUDELIMGCAT);
651
        // Call Footer
652
        xoops_cp_footer();
653
        break;
654
655
    case 'delcatok':
656
        if (!$GLOBALS['xoopsSecurity']->check()) {
657
            redirect_header('admin.php?fct=images', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
658
        }
659
        $imgcat_id = (int)$imgcat_id;
660
        if ($imgcat_id <= 0) {
661
            redirect_header('admin.php?fct=images', 1);
662
        }
663
        $imgcat_handler = xoops_getHandler('imagecategory');
664
        $imagecategory  = $imgcat_handler->get($imgcat_id);
665
        if (!is_object($imagecategory)) {
666
            redirect_header('admin.php?fct=images', 1);
667
        }
668
        if ($imagecategory->getVar('imgcat_type') !== 'C') {
669
            xoops_cp_header();
670
            xoops_error(_MD_SCATDELNG);
0 ignored issues
show
The constant _MD_SCATDELNG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
671
            xoops_cp_footer();
672
            exit();
673
        }
674
        /* @var  XoopsImageHandler $image_handler */
675
        $image_handler = xoops_getHandler('image');
676
        $images        = $image_handler->getObjects(new Criteria('imgcat_id', $imgcat_id), true, false);
677
        $errors        = array();
678
        foreach (array_keys($images) as $i) {
679
            if (!$image_handler->delete($images[$i])) {
680
                $errors[] = sprintf(_AM_SYSTEM_IMAGES_FAILDEL, $i);
681
            } else {
682
                if (file_exists(XOOPS_UPLOAD_PATH . '/' . $images[$i]->getVar('image_name')) && !unlink(XOOPS_UPLOAD_PATH . '/' . $images[$i]->getVar('image_name'))) {
683
                    $errors[] = sprintf(_AM_SYSTEM_IMAGES_FAILUNLINK, $i);
684
                }
685
            }
686
        }
687
        if (!$imgcat_handler->delete($imagecategory)) {
688
            $errors[] = sprintf(_AM_SYSTEM_IMAGES_FAILDELCAT, $imagecategory->getVar('imgcat_name'));
689
        }
690
        if (count($errors) > 0) {
691
            xoops_cp_header();
692
            xoops_error($errors);
693
            xoops_cp_footer();
694
            exit();
695
        }
696
        redirect_header('admin.php?fct=images', 2, _AM_SYSTEM_DBUPDATED);
697
        break;
698
699
    case 'multiupload':
700
        // Get category id
701
		$imgcat_id = Request::getInt('imgcat_id', 0);
702
        if ($imgcat_id <= 0) {
703
            redirect_header('admin.php?fct=images', 1);
704
        }
705
        // Get rights
706
        $imgcat_write = $gperm_handler->checkRight('imgcat_write', $imgcat_id, $groups, $xoopsModule->mid());
707
        // Get category handler
708
        $imgcat_handler = xoops_getHandler('imagecategory');
709
710
        $imagecategory = $imgcat_handler->get($imgcat_id);
711
        if (!is_object($imagecategory)) {
712
            redirect_header('admin.php?fct=images', 1);
713
        }
714
        // Get image handler
715
        //$image_handler = xoops_getHandler('image');
716
        // Define main template
717
        $GLOBALS['xoopsOption']['template_main'] = 'system_images.tpl';
718
        // Call header
719
        xoops_cp_header();
720
        // Define Stylesheet
721
        $xoTheme->addStylesheet(XOOPS_URL . '/media/fine-uploader/fine-uploader-new.css');
722
        $xoTheme->addStylesheet(XOOPS_URL . '/media/fine-uploader/ManuallyTriggerUploads.css');
723
        $xoTheme->addStylesheet(XOOPS_URL . '/media/font-awesome/css/font-awesome.min.css');
724
        $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css');
725
        // Define scripts
726
        $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
727
        $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
728
        $xoTheme->addScript('modules/system/js/admin.js');
729
        $xoTheme->addScript('media/fine-uploader/fine-uploader.js');
730
        // Define Breadcrumb and tips
731
        $xoBreadCrumb->addLink(_AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath'));
732
        $xoBreadCrumb->addLink($imagecategory->getVar('imgcat_name'), system_adminVersion('images', 'adminpath') . '&amp;op=listimg&amp;imgcat_id=' . $imgcat_id);
733
        $xoBreadCrumb->addLink(_AM_SYSTEM_IMAGES_MULTIUPLOAD);
734
        $xoBreadCrumb->render();
735
736
        $xoopsTpl->assign('multiupload', true);
737
        $xoopsTpl->assign('imgcat_maxsize', $imagecategory->getVar('imgcat_maxsize'));
738
        $xoopsTpl->assign('imgcat_maxwidth', $imagecategory->getVar('imgcat_maxwidth'));
739
        $xoopsTpl->assign('imgcat_maxheight', $imagecategory->getVar('imgcat_maxheight'));
740
        $xoopsTpl->assign('imgcat_name', $imagecategory->getVar('imgcat_name'));
741
        $payload = array(
742
            'aud' => 'ajaxfineupload.php',
743
            'cat' => $imgcat_id,
744
            'uid' => $xoopsUser instanceof \XoopsUser ? $xoopsUser->id() : 0,
745
            'handler' => 'fineimuploadhandler',
746
            'moddir' => 'system',
747
        );
748
        $jwt = \Xmf\Jwt\TokenFactory::build('fineuploader', $payload, 60*30); // token good for 30 minutes
749
        $xoopsTpl->assign('jwt', $jwt);
750
        $fineup_debug = 'false';
751
        if (($xoopsUser instanceof \XoopsUser ? $xoopsUser->isAdmin() : false)
752
            && isset($_REQUEST['FINEUPLOADER_DEBUG']))
753
        {
754
            $fineup_debug = 'true';
755
        }
756
        $xoopsTpl->assign('fineup_debug', $fineup_debug);
757
        // Call footer
758
        xoops_cp_footer();
759
}
760