Issues (992)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

admin/photo.php (1 issue)

Severity
1
<?php
2
3
use Xmf\Request;
4
5
/**
6
 * ExtGallery Admin settings
7
 * Manage admin pages
8
 *
9
 * You may not change or alter any portion of this comment or credits
10
 * of supporting developers from this source code or any supporting source code
11
 * which is considered copyrighted (c) material of the original comment or credit authors.
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 *
16
 * @copyright   {@link https://xoops.org/ XOOPS Project}
17
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 * @author      Zoullou (http://www.zoullou.net)
19
 * @package     ExtGallery
20
 */
21
22
use XoopsModules\Extgallery;
23
use XoopsModules\Tag\FormTag;
24
use XoopsModules\Tag\Helper;
25
26
require_once __DIR__ . '/admin_header.php';
27
require_once \dirname(__DIR__, 3) . '/class/pagenav.php';
28
29
require_once \dirname(__DIR__) . '/class/pear/Image/Transform.php';
30
31
if (\Xmf\Request::hasVar('op', 'GET')) {
32
    $op = $_GET['op'];
33
} else {
34
    $op = 'default';
35
}
36
37
if (\Xmf\Request::hasVar('step', 'POST')) {
38
    $step = $_POST['step'];
39
} else {
40
    $step = 'default';
41
}
42
43
if (\Xmf\Request::hasVar('start', 'GET')) {
44
    $start = $_GET['start'];
45
} else {
46
    $start = 0;
47
}
48
49
$moduleDirName = \basename(\dirname(__DIR__));
50
$utility       = new Extgallery\Utility();
51
/** @var Extgallery\Helper $helper */
52
$helper = Extgallery\Helper::getInstance();
53
switch ($op) {
54
    case 'add_photo':
55
56
        /** @var Extgallery\PublicPhotoHandler $photoHandler */
57
        $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
58
        $result       = $photoHandler->postPhotoTraitement('photo_file', false);
59
60
        if (2 == $result) {
61
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
62
        } elseif (4 == $result || 5 == $result) {
63
            redirect_header('photo.php', 3, _AM_EXTGALLERY_UPLOAD_ERROR . ' :<br>' . $photoHandler->photoUploader->getErrors());
64
        } elseif (0 == $result) {
65
            redirect_header('photo.php', 3, _AM_EXTGALLERY_PHOTO_UPLOADED);
66
        } elseif (1 == $result) {
67
            redirect_header('photo.php', 3, _AM_EXTGALLERY_PHOTO_PENDING);
68
        }
69
70
        break;
71
    case 'batchAdd':
72
73
        $maxExecTime    = get_cfg_var('max_execution_time') ?? 30;
74
        $maxTime        = time() + $maxExecTime - 5;
75
        $maxTimeReached = false;
76
77
        /** @var Extgallery\PublicCategoryHandler $catHandler */
78
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
79
        /** @var Extgallery\PublicPhotoHandler $photoHandler */
80
        $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
81
82
        // Test if an album is selected
83
        if (!isset($_POST['cat_id'])) {
84
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
85
        }
86
87
        // If isn't an album when stop the traitment
88
        /** @var Extgallery\Category $cat */
89
        $cat = $catHandler->getCat($_POST['cat_id']);
90
        if (1 != $cat->getVar('nright') - $cat->getVar('nleft')) {
91
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
92
        }
93
94
        $photos = [];
95
96
        $batchRep = XOOPS_ROOT_PATH . "/modules/{$moduleDirName}/batch/";
97
        $photoRep = XOOPS_ROOT_PATH . "/uploads/{$moduleDirName}/public-photo/";
98
        $dir      = opendir($batchRep);
99
        while (false !== ($f = readdir($dir))) {
100
            if (is_file($batchRep . $f)) {
101
                if (preg_match('/.*gif/', mb_strtolower($f)) || preg_match('/.*jpg/', mb_strtolower($f))
102
                    || preg_match('/.*jpeg/', mb_strtolower($f))
103
                    || preg_match('/.*png/', mb_strtolower($f))) {
104
                    $photos[] = $f;
105
                }
106
            }
107
        }
108
109
        // Check if they are photos to add in the batch folder
110
        if (count($photos) < 1) {
111
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_IN_BATCH_DIR);
112
        }
113
114
        $nbPhotos = \Xmf\Request::getInt('nbPhoto', 0, 'POST');
115
        $i        = 0;
116
        foreach ($photos as $photo) {
117
            // Move the photo to the upload directory
118
            rename($batchRep . $photo, $photoRep . $photo);
119
120
            $photoStatus = $photoHandler->addLocalPhoto($_POST['cat_id'], $photo, $_POST['photo_desc']);
121
            ++$i;
122
            if (time() > $maxTime) {
123
                $maxTimeReached = true;
124
                break;
125
            }
126
        }
127
        // Set the category as album only if photo is approve
128
        // require_once  \dirname(__DIR__) . '/class/publicPerm.php';
129
        $permHandler = Extgallery\PublicPermHandler::getInstance();
130
        if ($permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_autoapprove', $cat->getVar('cat_id'))) {
131
            $cat->setVar('cat_isalbum', 1);
132
            $catHandler->insert($cat);
133
        }
134
135
        // Make a "continue" page to display information message
136
        if ($maxTimeReached) {
137
            xoops_cp_header();
138
139
            echo '<div class="confirmMsg">';
140
141
            $photoMore = count($photos) - $i;
142
            echo '<h4>' . sprintf(_AM_EXTGALLERY_BATCH_CONTINUE_MESSAGE, $i + $nbPhotos, $photoMore) . '</h4>';
143
            echo '<form method="post" action="photo.php?op=batchAdd">';
144
            echo '<input type="hidden" name="cat_id" value="' . $_POST['cat_id'] . '">';
145
            echo '<input type="hidden" name="photo_desc" value="' . $_POST['photo_desc'] . '">';
146
            echo '<input type="hidden" name="nbPhoto" value="' . ($i + $nbPhotos) . '">';
147
            echo '<input type="submit" name="confirm_submit" value="Continue">';
148
            echo '</form>';
149
            echo '</div>';
150
151
            xoops_confirm(
152
                [
153
                    'cat_id'     => $_POST['cat_id'],
154
                    'photo_desc' => $_POST['photo_desc'],
155
                    'nbPhoto'    => $nbPhotos,
156
                ],
157
                'photo.php?op=batchAdd',
158
                _AM_EXTGALLERY_DELETE_CAT_CONFIRM
159
            );
160
161
            xoops_cp_footer();
162
        } else {
163
            /** @var \XoopsNotificationHandler $notificationHandler */
164
            $notificationHandler = xoops_getHandler('notification');
165
            $extraTags           = [
166
                'X_ITEM_CAT'     => $cat->getVar('cat_name'),
167
                'X_ITEM_NBPHOTO' => $i + $nbPhotos,
168
            ];
169
            if (1 == $photoStatus) {
170
                $extraTags['X_ITEM_URL'] = XOOPS_URL . "/modules/{$moduleDirName}/public-album.php?id=" . $cat->getVar('cat_id');
171
                $notificationHandler->triggerEvent('global', 0, 'new_photo', $extraTags);
172
                $notificationHandler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album', $extraTags);
173
            } else {
174
                $extraTags['X_ITEM_URL'] = XOOPS_URL . "/modules/{$moduleDirName}/admin/photo.php";
175
                $notificationHandler->triggerEvent('global', 0, 'new_photo_pending', $extraTags);
176
            }
177
178
            // Update photo count if photo needn't approve
179
            // require_once  \dirname(__DIR__) . '/class/publicPerm.php';
180
            $permHandler = Extgallery\PublicPermHandler::getInstance();
181
            if ($permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_autoapprove', $cat->getVar('cat_id'))) {
182
                // Update album count
183
                if (0 == $cat->getVar('cat_nb_photo')) {
184
                    $criteria = new \CriteriaCompo();
185
                    $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<'));
186
                    $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>'));
187
                    $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria);
188
                }
189
190
                // Update photo count
191
                $criteria = new \CriteriaCompo();
192
                $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<='));
193
                $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>='));
194
                $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + ' . ($i + $nbPhotos), $criteria);
195
            }
196
197
            redirect_header('photo.php', 3, sprintf(_AM_EXTGALLERY_X_PHOTO_ADDED, count($photos)));
198
        }
199
200
        break;
201
    case 'batchApprove':
202
203
        /** @var Extgallery\PublicPhotoHandler $photoHandler */
204
        $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
205
206
        // Check if they are selected photo
207
        if (!isset($_POST['photoId'])) {
208
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_SELECTED);
209
        }
210
211
        if (\Xmf\Request::hasVar('approve', 'POST')) {
212
            /** @var Extgallery\PublicCategoryHandler $catHandler */
213
            $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
214
215
            // If we have only one photo we put in in an array
216
            $categories = [];
217
            foreach (array_keys($_POST['photoId']) as $photoId) {
218
                $photo = $photoHandler->get($photoId);
219
                $photo->setVar('photo_approved', 1);
220
                $photoHandler->insert($photo);
221
222
                if (!isset($categories[$photo->getVar('cat_id')])) {
223
                    $categories[$photo->getVar('cat_id')] = 0;
224
                }
225
                $categories[$photo->getVar('cat_id')]++;
226
            }
227
            /** @var \XoopsNotificationHandler $notificationHandler */
228
            $notificationHandler = xoops_getHandler('notification');
229
230
            foreach ($categories as $k => $v) {
231
                /** @var Extgallery\PublicCategory $cat */
232
                $cat       = $catHandler->getCat($k);
233
                $extraTags = [
234
                    'X_ITEM_CAT'     => $cat->getVar('cat_name'),
235
                    'X_ITEM_NBPHOTO' => $v,
236
                    'X_ITEM_URL'     => XOOPS_URL . '/modules/extgallery/public-album.php?id=' . $cat->getVar('cat_id'),
237
                ];
238
                $notificationHandler->triggerEvent('global', 0, 'new_photo', $extraTags);
239
                $notificationHandler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album', $extraTags);
240
241
                // Update album count
242
                if (0 == $cat->getVar('cat_nb_photo')) {
243
                    $criteria = new \CriteriaCompo();
244
                    $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<'));
245
                    $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>'));
246
                    $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria);
247
                }
248
249
                // Update photo count
250
                $criteria = new \CriteriaCompo();
251
                $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<='));
252
                $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>='));
253
                $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + ' . $v, $criteria);
254
            }
255
256
            if (0 == $cat->getVar('cat_isalbum')) {
257
                $cat->setVar('cat_isalbum', 1);
258
                $catHandler->insert($cat);
259
            }
260
261
            redirect_header('photo.php', 3, sprintf(_AM_EXTGALLERY_X_PHOTO_APPROVED, count($_POST['photoId'])));
262
        } elseif (\Xmf\Request::hasVar('delete', 'POST')) {
263
            foreach (array_keys($_POST['photoId']) as $photoId) {
264
                $photo = $photoHandler->get($photoId);
265
                $photoHandler->deletePhoto($photo);
266
            }
267
268
            redirect_header('photo.php', 3, sprintf(_AM_EXTGALLERY_X_PHOTO_DELETED, count($_POST['photoId'])));
269
        }
270
271
        break;
272
    case 'rebuildthumb':
273
274
        /** @var Extgallery\PublicPhotoHandler $photoHandler */
275
        $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
276
        $photoHandler->rebuildThumbnail($_GET['cat_id']);
277
278
        redirect_header('photo.php', 3, _AM_EXTGALLERY_THUMB_REBUILDED);
279
280
        break;
281
    case 'modify':
282
283
        switch ($step) {
284
            case 'enreg':
285
                // Check if they are selected photo
286
287
                if (!isset($_POST['photoId'])) {
288
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_SELECTED);
289
                }
290
                /** @var Extgallery\CategoryHandler $catHandler */
291
                $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
292
                /** @var Extgallery\PublicPhotoHandler $photoHandler */
293
                $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
294
295
                // Test if an album is selected
296
                if (!isset($_POST['cat_id'])) {
297
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
298
                }
299
300
                // If isn't an album when stop the traitment
301
                /** @var Extgallery\PublicCategory $cat */
302
                $cat = $catHandler->getCat($_POST['cat_id']);
303
                if (1 != $cat->getVar('nright') - $cat->getVar('nleft')) {
304
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
305
                }
306
307
                $message = '';
308
309
                if (\Xmf\Request::hasVar('modify', 'POST')) {
310
                    $toCategories = [];
311
                    foreach (array_keys($_POST['photoId']) as $photoId) {
312
                        $data = [
313
                            'cat_id'       => $_POST['catId'][$photoId],
314
                            'photo_desc'   => $_POST['photoDesc'][$photoId],
315
                            'photo_title'  => $_POST['photoTitre'][$photoId],
316
                            'photo_weight' => $_POST['photoPoids'][$photoId],
317
                        ];
318
                        $photoHandler->modifyPhoto($photoId, $data);
319
320
                        if (!isset($toCategories[$_POST['catId'][$photoId]])) {
321
                            $toCategories[$_POST['catId'][$photoId]] = 0;
322
                        }
323
                        $toCategories[$_POST['catId'][$photoId]]++;
324
                    }
325
326
                    // Get from and to categories
327
                    $categories                   = [];
328
                    $categories[$_POST['cat_id']] = $catHandler->getCat($_POST['cat_id']);
329
                    foreach (array_keys($_POST['photoId']) as $photoId) {
330
                        if ($_POST['catId'][$photoId] == $_POST['cat_id']) {
331
                            continue;
332
                        }
333
                        $categories[$_POST['catId'][$photoId]] = $catHandler->getCat($_POST['catId'][$photoId]);
334
                    }
335
336
                    // Set dest categories as album
337
                    foreach ($toCategories as $k => $v) {
338
                        if (0 == $categories[$k]->getVar('cat_isalbum')) {
339
                            $categories[$k]->setVar('cat_isalbum', 1);
340
                            $catHandler->insert($categories[$k]);
341
                        }
342
                    }
343
344
                    // Get the photo number of the from category
345
                    $nbPhotoFromCat = $catHandler->nbPhoto($categories[$_POST['cat_id']]);
346
347
                    // Update cat counter and is_album for from category
348
                    if (0 == $nbPhotoFromCat) {
349
                        $categories[$_POST['cat_id']]->setVar('cat_isalbum', 0);
350
                        $catHandler->insert($categories[$_POST['cat_id']]);
351
352
                        $criteria = new \CriteriaCompo();
353
                        $criteria->add(new \Criteria('nleft', $categories[$_POST['cat_id']]->getVar('nleft'), '<'));
354
                        $criteria->add(new \Criteria('nright', $categories[$_POST['cat_id']]->getVar('nright'), '>'));
355
                        $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album - 1', $criteria);
356
                    }
357
358
                    // Update cat counter for to categories
359
                    foreach ($toCategories as $k => $v) {
360
                        // Skip from category
361
                        if ($k == $_POST['cat_id']) {
362
                            continue;
363
                        }
364
365
                        // If category hasn't photo before the changes
366
                        if (0 == $categories[$k]->getVar('cat_nb_photo')) {
367
                            $criteria = new \CriteriaCompo();
368
                            $criteria->add(new \Criteria('nleft', $categories[$k]->getVar('nleft'), '<'));
369
                            $criteria->add(new \Criteria('nright', $categories[$k]->getVar('nright'), '>'));
370
                            $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria);
371
                        }
372
                    }
373
374
                    // Count the number of photo removed from from category and update photo counter for to categories
375
                    $nbPhotoMoved = 0;
376
                    foreach ($toCategories as $k => $v) {
377
                        // Skip from category
378
                        if ($k == $_POST['cat_id']) {
379
                            continue;
380
                        }
381
                        $nbPhotoMoved += $v;
382
383
                        $criteria = new \CriteriaCompo();
384
                        $criteria->add(new \Criteria('nleft', $categories[$k]->getVar('nleft'), '<='));
385
                        $criteria->add(new \Criteria('nright', $categories[$k]->getVar('nright'), '>='));
386
                        $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + ' . $v, $criteria);
387
                    }
388
389
                    // Update the photo counter of the from gallery
390
                    if (0 != $nbPhotoMoved) {
0 ignored issues
show
The condition 0 != $nbPhotoMoved is always false.
Loading history...
391
                        $criteria = new \CriteriaCompo();
392
                        $criteria->add(new \Criteria('nleft', $categories[$_POST['cat_id']]->getVar('nleft'), '<='));
393
                        $criteria->add(new \Criteria('nright', $categories[$_POST['cat_id']]->getVar('nright'), '>='));
394
                        $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo - ' . $nbPhotoMoved, $criteria);
395
                    }
396
397
                    $message = sprintf(_AM_EXTGALLERY_X_PHOTO_MODIFIED, count($_POST['photoId']));
398
                } elseif (\Xmf\Request::hasVar('delete', 'POST')) {
399
                    foreach (array_keys($_POST['photoId']) as $photoId) {
400
                        $photo = $photoHandler->getPhoto($photoId);
401
                        $photoHandler->deletePhoto($photo);
402
                    }
403
404
                    $nbPhotoDeleted = count($_POST['photoId']);
405
                    /** @var Extgallery\Category $cat */
406
                    $cat = $catHandler->getCat($_POST['cat_id']);
407
408
                    if ($cat->getVar('cat_nb_photo') == $nbPhotoDeleted) {
409
                        $cat->setVar('cat_isalbum', 0);
410
                        $catHandler->insert($cat);
411
412
                        $criteria = new \CriteriaCompo();
413
                        $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<'));
414
                        $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>'));
415
                        $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album - 1', $criteria);
416
                    }
417
418
                    $criteria = new \CriteriaCompo();
419
                    $criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<='));
420
                    $criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>='));
421
                    $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo - ' . $nbPhotoDeleted, $criteria);
422
423
                    $message = sprintf(_AM_EXTGALLERY_X_PHOTO_DELETED, count($_POST['photoId']));
424
                }
425
426
                redirect_header('photo.php', 3, $message);
427
428
                break;
429
            case 'default':
430
431
            default:
432
433
                xoops_cp_header();
434
                /** @var Extgallery\PublicCategoryHandler $catHandler */
435
                $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
436
                /** @var Extgallery\PublicPhotoHandler $photoHandler */
437
                $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
438
439
                $photos  = $photoHandler->getAlbumPhotoAdminPage(Request::getInt('cat_id', 0, 'GET'), $start);
440
                $nbPhoto = $photoHandler->getAlbumCount(Request::getInt('cat_id', 0, 'GET'));
441
                // Check if they are selected photo
442
                if ($nbPhoto < 1) {
443
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_IN_THIS_ALBUM);
444
                }
445
446
                echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_APPROVE . '</legend>' . "\n";
447
                echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>' . "\n";
448
                echo _AM_EXTGALLERY_EDITDELETE_PHOTOTABLE_INFO . "\n";
449
                echo '</fieldset><br>' . "\n";
450
451
                $pageNav         = new \XoopsPageNav($nbPhoto, $helper->getConfig('admin_nb_photo'), $start, 'start', 'op=modify&cat_id=' . $_GET['cat_id']);
452
                $globalCatSelect = $catHandler->getLeafSelect('changeAllCat', false, $_GET['cat_id'], ' onChange="return changeAllCategory();"');
453
454
                echo '<div style="text-align:right;">' . $pageNav->renderNav() . '</div>' . "\n";
455
                echo '<form action="photo.php?op=modify" method="post">' . "\n";
456
                echo '<table class="outer" style="width:100%; text-align:center;"><tr>' . "\n";
457
                echo '<th><input type="checkbox" name="selectAllPhoto" id="selectAllPhoto" onClick="return checkAllPhoto();"></th>' . "\n";
458
                echo '<th>' . _AM_EXTGALLERY_PHOTO . '</th>' . "\n";
459
                echo '<th>' . _AM_EXTGALLERY_CATEGORY . '<br>' . $globalCatSelect . '</th>' . "\n";
460
                echo '<th>' . _AM_EXTGALLERY_WEIGHT . '</th>' . "\n";
461
                echo '<th style="text-align:left;">' . _AM_EXTGALLERY_TITLE . '<br>';
462
                echo _AM_EXTGALLERY_DESC . '</th>' . "\n";
463
                echo '</tr>' . "\n";
464
465
                $i              = 0;
466
                $cat            = [];
467
                $scriptCheckbox = '';
468
                $scriptSelect   = '';
469
                $first          = true;
470
                foreach ($photos as $photo) {
471
                    $class = (0 == (++$i % 2)) ? 'even' : 'odd';
472
                    /*if (!isset($cat[$photo->getVar('cat_id')])) {
473
                        $cat[$photo->getVar('cat_id')] = $catHandler->get($photo->getVar('cat_id'));
474
                    }*/
475
                    echo '<tr class="' . $class . '">' . "\n";
476
                    echo '<td><input type="checkbox" name="photoId[' . $photo->getVar('photo_id') . '][]" id="photoId[' . $photo->getVar('photo_id') . '][]"></td>' . "\n";
477
                    echo '<td><img src="' . XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name') . '"></td>' . "\n";
478
                    echo '<td>' . $catHandler->getLeafSelect('catId[' . $photo->getVar('photo_id') . ']', false, $_GET['cat_id']) . '</td>' . "\n";
479
                    echo '<td><input type="text" name="photoPoids[' . $photo->getVar('photo_id') . ']" id="photoPoids[' . $photo->getVar('photo_id') . ']" value="' . $photo->getVar('photo_weight') . '" size="3" maxlength="14"></td>' . "\n";
480
                    echo '<td  style="text-align:left;"><input type="text" name="photoTitre[' . $photo->getVar('photo_id') . ']" id="photoTitre[' . $photo->getVar('photo_id') . ']" value="' . $photo->getVar('photo_title', 'e') . '" size="60" maxlength="150"><br>' . "\n";
481
                    echo '<textarea name="photoDesc[' . $photo->getVar('photo_id') . ']" id="photoDesc[' . $photo->getVar('photo_id') . ']" rows="1" cols="57">' . $photo->getVar('photo_desc', 'e') . '</textarea></td>' . "\n";
482
                    echo '</tr>' . "\n";
483
                    $scriptCheckbox .= $first ? '\'photoId[' . $photo->getVar('photo_id') . '][]\'' : ', \'photoId[' . $photo->getVar('photo_id') . '][]\'';
484
                    $scriptSelect   .= $first ? '\'catId[' . $photo->getVar('photo_id') . ']\'' : ', \'catId[' . $photo->getVar('photo_id') . ']\'';
485
                    $first          = false;
486
                }
487
                echo '<tr><td colspan="4">';
488
                echo '<input type="hidden" name="cat_id" value="' . $_GET['cat_id'] . '">';
489
                echo '<input type="hidden" name="step" value="enreg">';
490
                echo '<input type="submit" name="modify" value="' . _AM_EXTGALLERY_APPLY_CHANGE . '">&nbsp;&nbsp;<input type="submit" name="delete" value="' . _DELETE . '">';
491
                echo '</td></tr>';
492
493
                echo '</table>' . "\n";
494
                echo '</form>';
495
                echo '</fieldset><br>' . "\n";
496
497
                echo '<script type="text/javascript">' . "\n";
498
                echo 'function checkAllPhoto() {' . "\n";
499
                echo 'var optionids = new Array(' . $scriptCheckbox . ');' . "\n";
500
                echo 'xoopsCheckAllElements(optionids, \'selectAllPhoto\');' . "\n";
501
                echo '}' . "\n";
502
                echo 'function changeAllCategory() {' . "\n";
503
                echo 'var elementIds = new Array(' . $scriptSelect . ');' . "\n";
504
                echo 'var select_cbox = xoopsGetElementById(\'changeAllCat\');' . "\n";
505
                echo 'for (var i = 0; i < elementIds.length; i++) {' . "\n";
506
                echo 'var e = xoopsGetElementById(elementIds[i]);' . "\n";
507
                echo 'e.selectedIndex = select_cbox.selectedIndex;' . "\n";
508
                echo '}' . "\n";
509
                echo '}' . "\n";
510
                echo '</script>' . "\n";
511
512
                xoops_cp_footer();
513
514
                break;
515
        }
516
517
        break;
518
    /*case 'approve':
519
520
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
521
        $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
522
523
        $photo = $photoHandler->getPhoto($_GET['id']);
524
        $photo->setVar('photo_approve',1);
525
        $photoHandler->insert($photo, true);
526
527
        $cat = $catHandler->getCat($photo->getVar('cat_id'));
528
529
        $notificationHandler = xoops_getHandler('notification');
530
        $extraTags = array(
531
                        'X_ITEM_CAT'=>$cat->getVar('cat_name'),
532
                        'X_ITEM_NBPHOTO'=>1,
533
                        'X_ITEM_URL'=>XOOPS_URL."/modules/extgallery/public-album.php?id=".$cat->getVar('cat_id')
534
                    );
535
        $notificationHandler->triggerEvent('global', 0, 'new_photo',$extraTags);
536
        $notificationHandler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album',$extraTags);
537
538
        //redirect_header("photo.php");
539
540
        break;*/
541
542
    /*case 'delete':
543
544
        $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
545
546
        $photo = $photoHandler->getPhoto($_GET['id']);
547
        $photoHandler->deletePhoto($photo);
548
549
        redirect_header("photo.php", 3, _AM_EXTGALLERY_PHOTO_MODIFIED);
550
551
        break;*/
552
553
    case 'default':
554
555
    default:
556
        // require_once  \dirname(__DIR__) . '/class/Utility.php';
557
558
        /** @var Extgallery\PublicCategoryHandler $catHandler */
559
        $catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory');
560
        /** @var Extgallery\PublicPhotoHandler $photoHandler */
561
        $photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
562
563
        xoops_cp_header();
564
565
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_ADD_PHOTO . '</legend>';
566
567
        $form = new \XoopsThemeForm(_AM_EXTGALLERY_UPLOAD, 'add_photo', 'photo.php?op=add_photo', 'post', true);
568
        //$form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
569
        $form->setExtra('enctype="multipart/form-data"');
570
        $form->addElement(new \XoopsFormLabel(_AM_EXTGALLERY_ALBUMS, $catHandler->getLeafSelect('cat_id', false, 0, '', 'public_upload')));
571
        //DNPROSSI - editors
572
        $form->addElement(new \XoopsFormText(_AM_EXTGALLERY_PHOTO_TITLE, 'photo_title', '50', '150'), false);
573
        $editor = $utility::getWysiwygForm(_AM_EXTGALLERY_DESC, 'photo_desc', '', 15, 60, '100%', '350px', 'hometext_hidden');
574
        $form->addElement($editor, false);
575
        $form->addElement(new \XoopsFormFile(_AM_EXTGALLERY_PHOTO, 'photo_file', $helper->getConfig('max_photosize')), false);
576
        if ($helper->getConfig('display_extra_field')) {
577
            $form->addElement(new \XoopsFormTextArea(_AM_EXTGALLERY_EXTRA_INFO, 'photo_extra'));
578
        }
579
        // For xoops tag
580
        if (class_exists(Helper::class) && 1 == $helper->getConfig('usetag')) {
581
            require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php';
582
            $form->addElement(new FormTag('tag', 60, 255, '', 0));
583
        }
584
        $form->addElement(new \XoopsFormHidden('op', 'add_photo'));
585
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
586
        $form->display();
587
588
        echo '</fieldset><br>';
589
590
        $nbPhotos = 0;
591
592
        $rep = XOOPS_ROOT_PATH . "/modules/$moduleDirName/batch/";
593
        $dir = opendir($rep);
594
        while (false !== ($f = readdir($dir))) {
595
            if (is_file($rep . $f)) {
596
                if (preg_match('/.*gif/', mb_strtolower($f)) || preg_match('/.*jpg/', mb_strtolower($f))
597
                    || preg_match('/.*jpeg/', mb_strtolower($f))
598
                    || preg_match('/.*png/', mb_strtolower($f))) {
599
                    ++$nbPhotos;
600
                }
601
            }
602
        }
603
604
        // Batch upload
605
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_ADD_BATCH . '</legend>';
606
607
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
608
        echo '<b>' . _AM_EXTGALLERY_BATCH_PATH . '</b> : ' . XOOPS_ROOT_PATH . '/modules/extgallery/batch/<br><br>' . sprintf(_AM_EXTGALLERY_ADD_BATCH_INFO, $nbPhotos);
609
        echo '</fieldset><br>';
610
611
        $form = new \XoopsThemeForm(_AM_EXTGALLERY_ADD_BATCH, 'batch_photo', 'photo.php?op=batchAdd', 'post', true);
612
        $form->addElement(new \XoopsFormLabel(_AM_EXTGALLERY_ALBUM, $catHandler->getLeafSelect('cat_id')));
613
        $form->addElement(new \XoopsFormText(_AM_EXTGALLERY_DESC, 'photo_desc', '70', '255'), false);
614
        $form->addElement(new \XoopsFormHidden('step', 'enreg'));
615
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
616
        $form->display();
617
618
        echo '</fieldset><br>';
619
620
        // Rebuild thumbnail
621
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_REBUILD_THUMB . '</legend>';
622
623
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
624
        echo _AM_EXTGALLERY_REBUILD_THUMB_INFO;
625
        echo '</fieldset><br>';
626
627
        $form = new \XoopsThemeForm(_AM_EXTGALLERY_REBUILD_THUMB, 'rebuild_thumb', 'photo.php', 'get', true);
628
        $form->addElement(new \XoopsFormLabel(_AM_EXTGALLERY_ALBUM, $catHandler->getSelect('cat_id', 'node')));
629
        $form->addElement(new \XoopsFormHidden('op', 'rebuildthumb'));
630
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
631
        $form->display();
632
633
        echo '</fieldset><br>';
634
635
        // Edit/delete photo
636
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_EDITDELETE_PHOTO . '</legend>';
637
638
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
639
        echo _AM_EXTGALLERY_EDITDELETE_PHOTO_INFO;
640
        echo '</fieldset><br>';
641
642
        $form = new \XoopsThemeForm(_AM_EXTGALLERY_EDITDELETE_PHOTO, 'modify_photo', 'photo.php', 'get', true);
643
        $form->addElement(new \XoopsFormLabel(_AM_EXTGALLERY_ALBUM, $catHandler->getSelect('cat_id', 'node')));
644
        $form->addElement(new \XoopsFormHidden('op', 'modify'));
645
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
646
        $form->display();
647
648
        echo '</fieldset><br>';
649
650
        // Pending photo
651
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_PENDING_PHOTO . '</legend>';
652
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
653
        //echo '<img src="../assets/images/on.png" style="vertical-align:middle;">&nbsp;&nbsp;'._AM_EXTGALLERY_APPROVE_INFO.'<br>';
654
        echo '<img src="../assets/images/edit.png" style="vertical-align:middle;">&nbsp;&nbsp;' . _AM_EXTGALLERY_EDIT_INFO . '<br>';
655
        echo '<img src="../assets/images/delete.png" style="vertical-align:middle;">&nbsp;&nbsp;' . _AM_EXTGALLERY_DELETE_INFO;
656
        echo '</fieldset><br>';
657
658
        $pendingPhoto = $photoHandler->getPendingPhoto();
659
        $pageNav      = new \XoopsPageNav(count($pendingPhoto), $helper->getConfig('admin_nb_photo'), $start);
660
661
        echo '<div id="pending-photo" style="text-align:right;">' . $pageNav->renderNav() . '</div>';
662
        echo '<form action="photo.php?op=batchApprove" method="post">';
663
        echo '<table class="outer" style="width:100%; text-align:center;"><tr>' . "\n";
664
        echo '<th><input type="checkbox" name="selectAllPhoto" id="selectAllPhoto" onClick="return checkAllPhoto();"></th>' . "\n";
665
        echo '<th>' . _AM_EXTGALLERY_PHOTO . '</th>' . "\n";
666
        echo '<th>' . _AM_EXTGALLERY_CATEGORY . '</th>' . "\n";
667
        echo '<th>' . _AM_EXTGALLERY_TITLE . '</th>' . "\n";
668
        echo '<th>' . _AM_EXTGALLERY_DESC . '</th>' . "\n";
669
        echo '<th>' . _AM_EXTGALLERY_ACTION . '</th>' . "\n";
670
        echo '</tr>' . "\n";
671
        $i      = 0;
672
        $cat    = [];
673
        $script = '';
674
        $first  = true;
675
        foreach ($pendingPhoto as $photo) {
676
            if (++$i < $start + 1 || $i > ($start + $helper->getConfig('admin_nb_photo'))) {
677
                continue;
678
            }
679
            $class = (0 == ($i % 2)) ? 'even' : 'odd';
680
            if (!isset($cat[$photo->getVar('cat_id')])) {
681
                $cat[$photo->getVar('cat_id')] = $catHandler->get($photo->getVar('cat_id'));
682
            }
683
            echo '<tr class="' . $class . '">' . "\n";
684
            echo '<td><input type="checkbox" name="photoId[' . $photo->getVar('photo_id') . ']" id="photoId[' . $photo->getVar('photo_id') . ']"></td>' . "\n";
685
            echo '<td><img src="' . XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name') . '"></td>' . "\n";
686
            echo '<td>' . $cat[$photo->getVar('cat_id')]->getVar('cat_name') . '</td>' . "\n";
687
            echo '<td>' . $photo->getVar('photo_title') . '</td>' . "\n";
688
            echo '<td>' . $photo->getVar('photo_desc') . '</td>' . "\n";
689
            echo '<td>' . "\n";
690
            //echo '<a href="photo.php?op=approve&id='.$photo->getVar('photo_id').'"><img src="../assets/images/on.png" style="vertical-align:middle;"></a>&nbsp;&nbsp;'."\n";
691
            echo '<a href="photo.php?op=modify&id=' . $photo->getVar('photo_id') . '"><img src="../assets/images/edit.png" style="vertical-align:middle;"></a>&nbsp;' . "\n";
692
            echo '<a href="photo.php?op=delete&id=' . $photo->getVar('photo_id') . '"><img src="../assets/images/delete.png" style="vertical-align:middle;"></a>' . "\n";
693
            echo '</td>' . "\n";
694
            echo '</tr>' . "\n";
695
            $script .= $first ? '\'photoId[' . $photo->getVar('photo_id') . ']\'' : ', \'photoId[' . $photo->getVar('photo_id') . ']\'';
696
            $first  = false;
697
        }
698
        echo '<tr><td colspan="5">';
699
        echo '<input type="submit" name="approve" value="' . _AM_EXTGALLERY_APPROVE . '">&nbsp;&nbsp;<input type="submit" name="delete" value="' . _DELETE . '">';
700
        echo '</td></tr>';
701
702
        echo '</table>' . "\n";
703
        echo '</form>';
704
        echo '</fieldset><br>' . "\n";
705
706
        echo '<script type="text/javascript">' . "\n";
707
        echo 'function checkAllPhoto() {' . "\n";
708
        echo 'var optionids = new Array(' . $script . ');' . "\n";
709
        echo 'xoopsCheckAllElements(optionids, \'selectAllPhoto\');' . "\n";
710
        echo '}' . "\n";
711
        echo '</script>' . "\n";
712
713
        xoops_cp_footer();
714
715
        break;
716
}
717