Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

admin/photo.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ExtGallery Admin settings
4
 * Manage admin pages
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
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   {@link https://xoops.org/ XOOPS Project}
14
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 * @author      Zoullou (http://www.zoullou.net)
16
 * @package     ExtGallery
17
 */
18
19
require_once __DIR__ . '/admin_header.php';
20
include __DIR__ . '/../../../class/pagenav.php';
21
22
require_once __DIR__ . '/../class/pear/Image/Transform.php';
23
24
if (isset($_GET['op'])) {
25
    $op = $_GET['op'];
26
} else {
27
    $op = 'default';
28
}
29
30
if (isset($_POST['step'])) {
31
    $step = $_POST['step'];
32
} else {
33
    $step = 'default';
34
}
35
36
if (isset($_GET['start'])) {
37
    $start = $_GET['start'];
38
} else {
39
    $start = 0;
40
}
41
42
$moduleDirName = basename(dirname(__DIR__));
43
$utilityClass  = ucfirst($moduleDirName) . 'Utility';
44
switch ($op) {
45
46 View Code Duplication
    case 'add_photo':
47
        /** @var ExtgalleryPublicPhotoHandler $photoHandler */
48
        $photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
49
        $result       = $photoHandler->postPhotoTraitement('photo_file', false);
50
51
        if (2 == $result) {
52
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
53
        } elseif (4 == $result || 5 == $result) {
54
            redirect_header('photo.php', 3, _AM_EXTGALLERY_UPLOAD_ERROR . ' :<br>' . $photoHandler->photoUploader->getErrors());
55
        } elseif (0 == $result) {
56
            redirect_header('photo.php', 3, _AM_EXTGALLERY_PHOTO_UPLOADED);
57
        } elseif (1 == $result) {
58
            redirect_header('photo.php', 3, _AM_EXTGALLERY_PHOTO_PENDING);
59
        }
60
        break;
61
62
    case 'batchAdd':
63
64
        if (null === get_cfg_var('max_execution_time')) {
65
            $maxExecTime = 30;
66
        } else {
67
            $maxExecTime = get_cfg_var('max_execution_time');
68
        }
69
        $maxTime        = time() + $maxExecTime - 5;
70
        $maxTimeReached = false;
71
72
        /** @var ExtgalleryPublicCatHandler $catHandler */
73
        $catHandler = xoops_getModuleHandler('publiccat', $moduleDirName);
74
        /** @var ExtgalleryPublicPhotoHandler $photoHandler */
75
        $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
76
77
        // Test if an album is selected
78
        if (!isset($_POST['cat_id'])) {
79
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
80
        }
81
82
        // If isn't an album when stop the traitment
83
        /** @var ExtgalleryCat $cat */
84
        $cat = $catHandler->getCat($_POST['cat_id']);
85 View Code Duplication
        if (1 != $cat->getVar('nright') - $cat->getVar('nleft')) {
86
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
87
        }
88
89
        $photos = [];
90
91
        $batchRep = XOOPS_ROOT_PATH . "/modules/{$moduleDirName}/batch/";
92
        $photoRep = XOOPS_ROOT_PATH . "/uploads/{$moduleDirName}/public-photo/";
93
        $dir      = opendir($batchRep);
94 View Code Duplication
        while (false !== ($f = readdir($dir))) {
95
            if (is_file($batchRep . $f)) {
96
                if (preg_match('/.*gif/', strtolower($f)) || preg_match('/.*jpg/', strtolower($f))
97
                    || preg_match('/.*jpeg/', strtolower($f))
98
                    || preg_match('/.*png/', strtolower($f))) {
99
                    $photos[] = $f;
100
                }
101
            }
102
        }
103
104
        // Check if they are photos to add in the batch folder
105
        if (count($photos) < 1) {
106
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_IN_BATCH_DIR);
107
        }
108
109
        $nbPhotos = isset($_POST['nbPhoto']) ? $_POST['nbPhoto'] : 0;
110
        $i        = 0;
111
        foreach ($photos as $photo) {
112
113
            // Move the photo to the upload directory
114
            rename($batchRep . $photo, $photoRep . $photo);
115
116
            $photoStatus = $photoHandler->addLocalPhoto($_POST['cat_id'], $photo, $_POST['photo_desc']);
117
            ++$i;
118
            if (time() > $maxTime) {
119
                $maxTimeReached = true;
120
                break;
121
            }
122
        }
123
        // Set the category as album only if photo is approve
124
        require_once __DIR__ . '/../class/publicPerm.php';
125
        $permHandler = ExtgalleryPublicPermHandler::getInstance();
126
        if ($permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_autoapprove', $cat->getVar('cat_id'))) {
127
            $cat->setVar('cat_isalbum', 1);
128
            $catHandler->insert($cat);
129
        }
130
131
        // Make a "continue" page to display information message
132
        if ($maxTimeReached) {
133
            xoops_cp_header();
134
135
            echo '<div class="confirmMsg">';
136
137
            $photoMore = count($photos) - $i;
138
            echo '<h4>' . sprintf(_AM_EXTGALLERY_BATCH_CONTINUE_MESSAGE, $i + $nbPhotos, $photoMore) . '</h4>';
139
            echo '<form method="post" action="photo.php?op=batchAdd">';
140
            echo '<input type="hidden" name="cat_id" value="' . $_POST['cat_id'] . '">';
141
            echo '<input type="hidden" name="photo_desc" value="' . $_POST['photo_desc'] . '">';
142
            echo '<input type="hidden" name="nbPhoto" value="' . ($i + $nbPhotos) . '">';
143
            echo '<input type="submit" name="confirm_submit" value="Continue">';
144
            echo '</form>';
145
            echo '</div>';
146
147
            xoops_confirm([
148
                              'cat_id'     => $_POST['cat_id'],
149
                              'photo_desc' => $_POST['photo_desc'],
150
                              'nbPhoto'    => $nbPhotos
151
                          ], 'photo.php?op=batchAdd', _AM_EXTGALLERY_DELETE_CAT_CONFIRM);
152
153
            xoops_cp_footer();
154
        } else {
155
            /** @var XoopsNotificationHandler $notificationHandler */
156
            $notificationHandler = xoops_getHandler('notification');
157
            $extraTags           = [
158
                'X_ITEM_CAT'     => $cat->getVar('cat_name'),
159
                'X_ITEM_NBPHOTO' => $i + $nbPhotos
160
            ];
161
            if (1 == $photoStatus) {
162
                $extraTags['X_ITEM_URL'] = XOOPS_URL . "/modules/{$moduleDirName}/public-album.php?id=" . $cat->getVar('cat_id');
163
                $notificationHandler->triggerEvent('global', 0, 'new_photo', $extraTags);
164
                $notificationHandler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album', $extraTags);
165 View Code Duplication
            } else {
166
                $extraTags['X_ITEM_URL'] = XOOPS_URL . "/modules/{$moduleDirName}/admin/photo.php";
167
                $notificationHandler->triggerEvent('global', 0, 'new_photo_pending', $extraTags);
168
            }
169
170
            // Update photo count if photo needn't approve
171
            require_once __DIR__ . '/../class/publicPerm.php';
172
            $permHandler = ExtgalleryPublicPermHandler::getInstance();
173
            if ($permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_autoapprove', $cat->getVar('cat_id'))) {
174
                // Update album count
175 View Code Duplication
                if (0 == $cat->getVar('cat_nb_photo')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
                    $criteria = new CriteriaCompo();
177
                    $criteria->add(new Criteria('nleft', $cat->getVar('nleft'), '<'));
178
                    $criteria->add(new Criteria('nright', $cat->getVar('nright'), '>'));
179
                    $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria);
180
                }
181
182
                // Update photo count
183
                $criteria = new CriteriaCompo();
184
                $criteria->add(new Criteria('nleft', $cat->getVar('nleft'), '<='));
185
                $criteria->add(new Criteria('nright', $cat->getVar('nright'), '>='));
186
                $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + ' . ($i + $nbPhotos), $criteria);
187
            }
188
189
            redirect_header('photo.php', 3, sprintf(_AM_EXTGALLERY_X_PHOTO_ADDED, count($photos)));
190
        }
191
192
        break;
193
194
    case 'batchApprove':
195
        /** @var ExtgalleryPublicPhotoHandler $photoHandler */
196
        $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
197
198
        // Check if they are selected photo
199
        if (!isset($_POST['photoId'])) {
200
            redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_SELECTED);
201
        }
202
203
        if (isset($_POST['approve'])) {
204
            $catHandler = xoops_getModuleHandler('publiccat', $moduleDirName);
205
206
            // If we have only one photo we put in in an array
207
            $categories = [];
208
            foreach (array_keys($_POST['photoId']) as $photoId) {
209
                $photo = $photoHandler->get($photoId);
210
                $photo->setVar('photo_approved', 1);
211
                $photoHandler->insert($photo);
212
213
                if (!isset($categories[$photo->getVar('cat_id')])) {
214
                    $categories[$photo->getVar('cat_id')] = 0;
215
                }
216
                $categories[$photo->getVar('cat_id')]++;
217
            }
218
            /** @var XoopsNotificationHandler $notificationHandler */
219
            $notificationHandler = xoops_getHandler('notification');
220
221
            foreach ($categories as $k => $v) {
222
                $cat       = $catHandler->getCat($k);
223
                $extraTags = [
224
                    'X_ITEM_CAT'     => $cat->getVar('cat_name'),
225
                    'X_ITEM_NBPHOTO' => $v,
226
                    'X_ITEM_URL'     => XOOPS_URL . '/modules/extgallery/public-album.php?id=' . $cat->getVar('cat_id')
227
                ];
228
                $notificationHandler->triggerEvent('global', 0, 'new_photo', $extraTags);
229
                $notificationHandler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album', $extraTags);
230
231
                // Update album count
232 View Code Duplication
                if (0 == $cat->getVar('cat_nb_photo')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
233
                    $criteria = new CriteriaCompo();
234
                    $criteria->add(new Criteria('nleft', $cat->getVar('nleft'), '<'));
235
                    $criteria->add(new Criteria('nright', $cat->getVar('nright'), '>'));
236
                    $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria);
237
                }
238
239
                // Update photo count
240
                $criteria = new CriteriaCompo();
241
                $criteria->add(new Criteria('nleft', $cat->getVar('nleft'), '<='));
242
                $criteria->add(new Criteria('nright', $cat->getVar('nright'), '>='));
243
                $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + ' . $v, $criteria);
244
            }
245
246
            if (0 == $cat->getVar('cat_isalbum')) {
247
                $cat->setVar('cat_isalbum', 1);
248
                $catHandler->insert($cat);
249
            }
250
251
            redirect_header('photo.php', 3, sprintf(_AM_EXTGALLERY_X_PHOTO_APPROVED, count($_POST['photoId'])));
252
        } elseif (isset($_POST['delete'])) {
253
            foreach (array_keys($_POST['photoId']) as $photoId) {
254
                $photo = $photoHandler->get($photoId);
255
                $photoHandler->deletePhoto($photo);
256
            }
257
258
            redirect_header('photo.php', 3, sprintf(_AM_EXTGALLERY_X_PHOTO_DELETED, count($_POST['photoId'])));
259
        }
260
261
        break;
262
263
    case 'rebuildthumb':
264
        /** @var ExtgalleryPublicPhotoHandler $photoHandler */
265
        $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
266
        $photoHandler->rebuildThumbnail($_GET['cat_id']);
267
268
        redirect_header('photo.php', 3, _AM_EXTGALLERY_THUMB_REBUILDED);
269
270
        break;
271
272
    case 'modify':
273
        switch ($step) {
274
            case 'enreg':
275
                // Check if they are selected photo
276
                if (!isset($_POST['photoId'])) {
277
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_SELECTED);
278
                }
279
                /** @var ExtgalleryCatHandler $catHandler */
280
                $catHandler = xoops_getModuleHandler('publiccat', $moduleDirName);
281
                /** @var ExtgalleryPublicPhotoHandler $photoHandler */
282
                $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
283
284
                // Test if an album is selected
285
                if (!isset($_POST['cat_id'])) {
286
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
287
                }
288
289
                // If isn't an album when stop the traitment
290
                $cat = $catHandler->getCat($_POST['cat_id']);
291 View Code Duplication
                if (1 != $cat->getVar('nright') - $cat->getVar('nleft')) {
292
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NOT_AN_ALBUM);
293
                }
294
295
                $message = '';
296
297
                if (isset($_POST['modify'])) {
298
                    $toCategories = [];
299
                    foreach (array_keys($_POST['photoId']) as $photoId) {
300
                        $data = [
301
                            'cat_id'       => $_POST['catId'][$photoId],
302
                            'photo_desc'   => $_POST['photoDesc'][$photoId],
303
                            'photo_title'  => $_POST['photoTitre'][$photoId],
304
                            'photo_weight' => $_POST['photoPoids'][$photoId]
305
                        ];
306
                        $photoHandler->modifyPhoto($photoId, $data);
307
308
                        if (!isset($toCategories[$_POST['catId'][$photoId]])) {
309
                            $toCategories[$_POST['catId'][$photoId]] = 0;
310
                        }
311
                        $toCategories[$_POST['catId'][$photoId]]++;
312
                    }
313
314
                    // Get from and to categories
315
                    $categories                   = [];
316
                    $categories[$_POST['cat_id']] = $catHandler->getCat($_POST['cat_id']);
317
                    foreach (array_keys($_POST['photoId']) as $photoId) {
318
                        if ($_POST['catId'][$photoId] == $_POST['cat_id']) {
319
                            continue;
320
                        }
321
                        $categories[$_POST['catId'][$photoId]] = $catHandler->getCat($_POST['catId'][$photoId]);
322
                    }
323
324
                    // Set dest categories as album
325
                    foreach ($toCategories as $k => $v) {
326
                        if (0 == $categories[$k]->getVar('cat_isalbum')) {
327
                            $categories[$k]->setVar('cat_isalbum', 1);
328
                            $catHandler->insert($categories[$k]);
329
                        }
330
                    }
331
332
                    // Get the photo number of the from category
333
                    $nbPhotoFromCat = $catHandler->nbPhoto($categories[$_POST['cat_id']]);
334
335
                    // Update cat counter and is_album for from category
336
                    if (0 == $nbPhotoFromCat) {
337
                        $categories[$_POST['cat_id']]->setVar('cat_isalbum', 0);
338
                        $catHandler->insert($categories[$_POST['cat_id']]);
339
340
                        $criteria = new CriteriaCompo();
341
                        $criteria->add(new Criteria('nleft', $categories[$_POST['cat_id']]->getVar('nleft'), '<'));
342
                        $criteria->add(new Criteria('nright', $categories[$_POST['cat_id']]->getVar('nright'), '>'));
343
                        $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album - 1', $criteria);
344
                    }
345
346
                    // Update cat counter for to categories
347
                    foreach ($toCategories as $k => $v) {
348
                        // Skip from category
349
                        if ($k == $_POST['cat_id']) {
350
                            continue;
351
                        }
352
353
                        // If category hasn't photo before the changes
354 View Code Duplication
                        if (0 == $categories[$k]->getVar('cat_nb_photo')) {
355
                            $criteria = new CriteriaCompo();
356
                            $criteria->add(new Criteria('nleft', $categories[$k]->getVar('nleft'), '<'));
357
                            $criteria->add(new Criteria('nright', $categories[$k]->getVar('nright'), '>'));
358
                            $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria);
359
                        }
360
                    }
361
362
                    // Count the number of photo removed from from category and update photo counter for to categories
363
                    $nbPhotoMoved = 0;
364
                    foreach ($toCategories as $k => $v) {
365
                        // Skip from category
366
                        if ($k == $_POST['cat_id']) {
367
                            continue;
368
                        }
369
                        $nbPhotoMoved += $v;
370
371
                        $criteria = new CriteriaCompo();
372
                        $criteria->add(new Criteria('nleft', $categories[$k]->getVar('nleft'), '<='));
373
                        $criteria->add(new Criteria('nright', $categories[$k]->getVar('nright'), '>='));
374
                        $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + ' . $v, $criteria);
375
                    }
376
377
                    // Update the photo counter of the from gallery
378 View Code Duplication
                    if (0 != $nbPhotoMoved) {
379
                        $criteria = new CriteriaCompo();
380
                        $criteria->add(new Criteria('nleft', $categories[$_POST['cat_id']]->getVar('nleft'), '<='));
381
                        $criteria->add(new Criteria('nright', $categories[$_POST['cat_id']]->getVar('nright'), '>='));
382
                        $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo - ' . $nbPhotoMoved, $criteria);
383
                    }
384
385
                    $message = sprintf(_AM_EXTGALLERY_X_PHOTO_MODIFIED, count($_POST['photoId']));
386
                } elseif (isset($_POST['delete'])) {
387
                    foreach (array_keys($_POST['photoId']) as $photoId) {
388
                        $photo = $photoHandler->getPhoto($photoId);
389
                        $photoHandler->deletePhoto($photo);
390
                    }
391
392
                    $nbPhotoDeleted = count($_POST['photoId']);
393
                    /** @var ExtgalleryCat $cat */
394
                    $cat = $catHandler->getCat($_POST['cat_id']);
395
396
                    if ($cat->getVar('cat_nb_photo') == $nbPhotoDeleted) {
397
                        $cat->setVar('cat_isalbum', 0);
398
                        $catHandler->insert($cat);
399
400
                        $criteria = new CriteriaCompo();
401
                        $criteria->add(new Criteria('nleft', $cat->getVar('nleft'), '<'));
402
                        $criteria->add(new Criteria('nright', $cat->getVar('nright'), '>'));
403
                        $catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album - 1', $criteria);
404
                    }
405
406
                    $criteria = new CriteriaCompo();
407
                    $criteria->add(new Criteria('nleft', $cat->getVar('nleft'), '<='));
408
                    $criteria->add(new Criteria('nright', $cat->getVar('nright'), '>='));
409
                    $catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo - ' . $nbPhotoDeleted, $criteria);
410
411
                    $message = sprintf(_AM_EXTGALLERY_X_PHOTO_DELETED, count($_POST['photoId']));
412
                }
413
414
                redirect_header('photo.php', 3, $message);
415
416
                break;
417
418
            case 'default':
419
            default:
420
                xoops_cp_header();
421
                /** @var ExtgalleryPublicCatHandler $catHandler */
422
                $catHandler = xoops_getModuleHandler('publiccat', $moduleDirName);
423
                /** @var ExtgalleryPublicPhotoHandler $photoHandler */
424
                $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
425
426
                $photos  = $photoHandler->getAlbumPhotoAdminPage($_GET['cat_id'], $start);
427
                $nbPhoto = $photoHandler->getAlbumCount($_GET['cat_id']);
428
                // Check if they are selected photo
429
                if ($nbPhoto < 1) {
430
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_PHOTO_IN_THIS_ALBUM);
431
                }
432
433
                echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_APPROVE . '</legend>' . "\n";
434
                echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>' . "\n";
435
                echo _AM_EXTGALLERY_EDITDELETE_PHOTOTABLE_INFO . "\n";
436
                echo '</fieldset><br>' . "\n";
437
438
                $pageNav         = new XoopsPageNav($nbPhoto, $xoopsModuleConfig['admin_nb_photo'], $start, 'start', 'op=modify&cat_id=' . $_GET['cat_id']);
439
                $globalCatSelect = $catHandler->getLeafSelect('changeAllCat', false, $_GET['cat_id'], ' onChange="return changeAllCategory();"');
440
441
                echo '<div style="text-align:right;">' . $pageNav->renderNav() . '</div>' . "\n";
442
                echo '<form action="photo.php?op=modify" method="post">' . "\n";
443
                echo '<table class="outer" style="width:100%; text-align:center;"><tr>' . "\n";
444
                echo '<th><input type="checkbox" name="selectAllPhoto" id="selectAllPhoto" onClick="return checkAllPhoto();"></th>' . "\n";
445
                echo '<th>' . _AM_EXTGALLERY_PHOTO . '</th>' . "\n";
446
                echo '<th>' . _AM_EXTGALLERY_CATEGORY . '<br>' . $globalCatSelect . '</th>' . "\n";
447
                echo '<th>' . _AM_EXTGALLERY_WEIGHT . '</th>' . "\n";
448
                echo '<th>' . _AM_EXTGALLERY_TITLE . '<br>';
449
                echo _AM_EXTGALLERY_DESC . '</th>' . "\n";
450
                echo '</tr>' . "\n";
451
452
                $i              = 0;
453
                $cat            = [];
454
                $scriptCheckbox = '';
455
                $scriptSelect   = '';
456
                $first          = true;
457
                foreach ($photos as $photo) {
458
                    $class = (0 == (++$i % 2)) ? 'even' : 'odd';
459
                    /*if (!isset($cat[$photo->getVar('cat_id')])) {
460
                        $cat[$photo->getVar('cat_id')] = $catHandler->get($photo->getVar('cat_id'));
461
                    }*/
462
                    echo '<tr class="' . $class . '">' . "\n";
463
                    echo '<td><input type="checkbox" name="photoId[' . $photo->getVar('photo_id') . '][]" id="photoId[' . $photo->getVar('photo_id') . '][]"></td>' . "\n";
464
                    echo '<td><img src="' . XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name') . '"></td>' . "\n";
465
                    echo '<td>' . $catHandler->getLeafSelect('catId[' . $photo->getVar('photo_id') . ']', false, $_GET['cat_id']) . '</td>' . "\n";
466
                    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";
467
                    echo '<td><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";
468
                    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";
469
                    echo '</tr>' . "\n";
470
                    $scriptCheckbox .= $first ? '\'photoId[' . $photo->getVar('photo_id') . '][]\'' : ', \'photoId[' . $photo->getVar('photo_id') . '][]\'';
471
                    $scriptSelect   .= $first ? '\'catId[' . $photo->getVar('photo_id') . ']\'' : ', \'catId[' . $photo->getVar('photo_id') . ']\'';
472
                    $first          = false;
473
                }
474
                echo '<tr><td colspan="4">';
475
                echo '<input type="hidden" name="cat_id" value="' . $_GET['cat_id'] . '">';
476
                echo '<input type="hidden" name="step" value="enreg">';
477
                echo '<input type="submit" name="modify" value="' . _AM_EXTGALLERY_APPLY_CHANGE . '">&nbsp;&nbsp;<input type="submit" name="delete" value="' . _DELETE . '">';
478
                echo '</td></tr>';
479
480
                echo '</table>' . "\n";
481
                echo '</form>';
482
                echo '</fieldset><br>' . "\n";
483
484
                echo '<script type="text/javascript">' . "\n";
485
                echo 'function checkAllPhoto() {' . "\n";
486
                echo 'var optionids = new Array(' . $scriptCheckbox . ');' . "\n";
487
                echo 'xoopsCheckAllElements(optionids, \'selectAllPhoto\');' . "\n";
488
                echo '}' . "\n";
489
                echo 'function changeAllCategory() {' . "\n";
490
                echo 'var elementIds = new Array(' . $scriptSelect . ');' . "\n";
491
                echo 'var select_cbox = xoopsGetElementById(\'changeAllCat\');' . "\n";
492
                echo 'for (var i = 0; i < elementIds.length; i++) {' . "\n";
493
                echo 'var e = xoopsGetElementById(elementIds[i]);' . "\n";
494
                echo 'e.selectedIndex = select_cbox.selectedIndex;' . "\n";
495
                echo '}' . "\n";
496
                echo '}' . "\n";
497
                echo '</script>' . "\n";
498
499
                xoops_cp_footer();
500
501
                break;
502
503
        }
504
505
        break;
506
507
    /*case 'approve':
508
509
        $catHandler = xoops_getModuleHandler('publiccat', $moduleDirName);
510
        $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
511
512
        $photo = $photoHandler->getPhoto($_GET['id']);
513
        $photo->setVar('photo_approve',1);
514
        $photoHandler->insert($photo, true);
515
516
        $cat = $catHandler->getCat($photo->getVar('cat_id'));
517
518
        $notificationHandler = xoops_getHandler('notification');
519
        $extraTags = array(
520
                        'X_ITEM_CAT'=>$cat->getVar('cat_name'),
521
                        'X_ITEM_NBPHOTO'=>1,
522
                        'X_ITEM_URL'=>XOOPS_URL."/modules/extgallery/public-album.php?id=".$cat->getVar('cat_id')
523
                    );
524
        $notificationHandler->triggerEvent('global', 0, 'new_photo',$extraTags);
525
        $notificationHandler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album',$extraTags);
526
527
        //redirect_header("photo.php");
528
529
        break;*/
530
531
    /*case 'delete':
532
533
        $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
534
535
        $photo = $photoHandler->getPhoto($_GET['id']);
536
        $photoHandler->deletePhoto($photo);
537
538
        redirect_header("photo.php", 3, _AM_EXTGALLERY_PHOTO_MODIFIED);
539
540
        break;*/
541
542
    case 'default':
543
    default:
544
        require_once __DIR__ . '/../class/utility.php';
545
        /** @var ExtgalleryCatHandler $catHandler */
546
        $catHandler = xoops_getModuleHandler('publiccat', $moduleDirName);
547
        /** @var ExtgalleryPublicPhotoHandler $photoHandler */
548
        $photoHandler = xoops_getModuleHandler('publicphoto', $moduleDirName);
549
550
        xoops_cp_header();
551
552
553
554
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_ADD_PHOTO . '</legend>';
555
556
        $form = new XoopsThemeForm(_AM_EXTGALLERY_UPLOAD, 'add_photo', 'photo.php?op=add_photo', 'post', true);
557
        //$form = new XoopsThemeForm($title, 'form', $action, 'post', true);
558
        $form->setExtra('enctype="multipart/form-data"');
559
        $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_ALBUMS, $catHandler->getLeafSelect('cat_id', false, 0, '', 'public_upload')));
560
        //DNPROSSI - editors
561
        $form->addElement(new XoopsFormText(_AM_EXTGALLERY_PHOTO_TITLE, 'photo_title', '50', '150'), false);
562
        $editor = $utilityClass::getWysiwygForm(_AM_EXTGALLERY_DESC, 'photo_desc', '', 15, 60, '100%', '350px', 'hometext_hidden');
563
        $form->addElement($editor, false);
564
        $form->addElement(new XoopsFormFile(_AM_EXTGALLERY_PHOTO, 'photo_file', $xoopsModuleConfig['max_photosize']), false);
565
        if ($xoopsModuleConfig['display_extra_field']) {
566
            $form->addElement(new XoopsFormTextArea(_AM_EXTGALLERY_EXTRA_INFO, 'photo_extra'));
567
        }
568
        // For xoops tag
569 View Code Duplication
        if ((1 == $xoopsModuleConfig['usetag']) && is_dir(__DIR__ . '/../../tag')) {
570
            require_once XOOPS_ROOT_PATH . '/modules/tag/include/formtag.php';
571
            $form->addElement(new TagFormTag('tag', 60, 255, '', 0));
572
        }
573
        $form->addElement(new XoopsFormHidden('op', 'add_photo'));
574
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
575
        $form->display();
576
577
        echo '</fieldset><br>';
578
579
        $nbPhotos = 0;
580
581
        $rep = XOOPS_ROOT_PATH . "/modules/$moduleDirName/batch/";
582
        $dir = opendir($rep);
583 View Code Duplication
        while ($f = readdir($dir)) {
584
            if (is_file($rep . $f)) {
585
                if (preg_match('/.*gif/', strtolower($f)) || preg_match('/.*jpg/', strtolower($f))
586
                    || preg_match('/.*jpeg/', strtolower($f))
587
                    || preg_match('/.*png/', strtolower($f))) {
588
                    ++$nbPhotos;
589
                }
590
            }
591
        }
592
593
        // Batch upload
594
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_ADD_BATCH . '</legend>';
595
596
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
597
        echo '<b>' . _AM_EXTGALLERY_BATCH_PATH . '</b> : ' . XOOPS_ROOT_PATH . '/modules/extgallery/batch/<br><br>' . sprintf(_AM_EXTGALLERY_ADD_BATCH_INFO, $nbPhotos);
598
        echo '</fieldset><br>';
599
600
        $form = new XoopsThemeForm(_AM_EXTGALLERY_ADD_BATCH, 'batch_photo', 'photo.php?op=batchAdd', 'post', true);
601
        $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_ALBUM, $catHandler->getLeafSelect('cat_id')));
602
        $form->addElement(new XoopsFormText(_AM_EXTGALLERY_DESC, 'photo_desc', '70', '255'), false);
603
        $form->addElement(new XoopsFormHidden('step', 'enreg'));
604
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
605
        $form->display();
606
607
        echo '</fieldset><br>';
608
609
        // Rebuild thumbnail
610
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_REBUILD_THUMB . '</legend>';
611
612
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
613
        echo _AM_EXTGALLERY_REBUILD_THUMB_INFO;
614
        echo '</fieldset><br>';
615
616
        $form = new XoopsThemeForm(_AM_EXTGALLERY_REBUILD_THUMB, 'rebuild_thumb', 'photo.php', 'get', true);
617
        $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_ALBUM, $catHandler->getSelect('cat_id', 'node')));
618
        $form->addElement(new XoopsFormHidden('op', 'rebuildthumb'));
619
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
620
        $form->display();
621
622
        echo '</fieldset><br>';
623
624
        // Edit/delete photo
625
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_EDITDELETE_PHOTO . '</legend>';
626
627
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
628
        echo _AM_EXTGALLERY_EDITDELETE_PHOTO_INFO;
629
        echo '</fieldset><br>';
630
631
        $form = new XoopsThemeForm(_AM_EXTGALLERY_EDITDELETE_PHOTO, 'modify_photo', 'photo.php', 'get', true);
632
        $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_ALBUM, $catHandler->getSelect('cat_id', 'node')));
633
        $form->addElement(new XoopsFormHidden('op', 'modify'));
634
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
635
        $form->display();
636
637
        echo '</fieldset><br>';
638
639
        // Pending photo
640
        echo '<fieldset><legend style="font-weight:bold; color:#990000;">' . _AM_EXTGALLERY_PENDING_PHOTO . '</legend>';
641
        echo '<fieldset><legend style="font-weight:bold; color:#0A3760;">' . _AM_EXTGALLERY_INFORMATION . '</legend>';
642
        //echo '<img src="../assets/images/on.png" style="vertical-align:middle;">&nbsp;&nbsp;'._AM_EXTGALLERY_APPROVE_INFO.'<br>';
643
        echo '<img src="../assets/images/edit.png" style="vertical-align:middle;">&nbsp;&nbsp;' . _AM_EXTGALLERY_EDIT_INFO . '<br>';
644
        echo '<img src="../assets/images/delete.png" style="vertical-align:middle;">&nbsp;&nbsp;' . _AM_EXTGALLERY_DELETE_INFO;
645
        echo '</fieldset><br>';
646
647
        $pendingPhoto = $photoHandler->getPendingPhoto();
648
        $pageNav      = new XoopsPageNav(count($pendingPhoto), $xoopsModuleConfig['admin_nb_photo'], $start);
649
650
        echo '<div id="pending-photo" style="text-align:right;">' . $pageNav->renderNav() . '</div>';
651
        echo '<form action="photo.php?op=batchApprove" method="post">';
652
        echo '<table class="outer" style="width:100%; text-align:center;"><tr>' . "\n";
653
        echo '<th><input type="checkbox" name="selectAllPhoto" id="selectAllPhoto" onClick="return checkAllPhoto();"></th>' . "\n";
654
        echo '<th>' . _AM_EXTGALLERY_PHOTO . '</th>' . "\n";
655
        echo '<th>' . _AM_EXTGALLERY_CATEGORY . '</th>' . "\n";
656
        echo '<th>' . _AM_EXTGALLERY_TITLE . '</th>' . "\n";
657
        echo '<th>' . _AM_EXTGALLERY_DESC . '</th>' . "\n";
658
        echo '<th>' . _AM_EXTGALLERY_ACTION . '</th>' . "\n";
659
        echo '</tr>' . "\n";
660
        $i      = 0;
661
        $cat    = [];
662
        $script = '';
663
        $first  = true;
664
        foreach ($pendingPhoto as $photo) {
665
            if (++$i < $start + 1 || $i > ($start + $xoopsModuleConfig['admin_nb_photo'])) {
666
                continue;
667
            }
668
            $class = (0 == ($i % 2)) ? 'even' : 'odd';
669
            if (!isset($cat[$photo->getVar('cat_id')])) {
670
                $cat[$photo->getVar('cat_id')] = $catHandler->get($photo->getVar('cat_id'));
671
            }
672
            echo '<tr class="' . $class . '">' . "\n";
673
            echo '<td><input type="checkbox" name="photoId[' . $photo->getVar('photo_id') . ']" id="photoId[' . $photo->getVar('photo_id') . ']"></td>' . "\n";
674
            echo '<td><img src="' . XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name') . '"></td>' . "\n";
675
            echo '<td>' . $cat[$photo->getVar('cat_id')]->getVar('cat_name') . '</td>' . "\n";
676
            echo '<td>' . $photo->getVar('photo_title') . '</td>' . "\n";
677
            echo '<td>' . $photo->getVar('photo_desc') . '</td>' . "\n";
678
            echo '<td>' . "\n";
679
            //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";
680
            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";
681
            echo '<a href="photo.php?op=delete&id=' . $photo->getVar('photo_id') . '"><img src="../assets/images/delete.png" style="vertical-align:middle;"></a>' . "\n";
682
            echo '</td>' . "\n";
683
            echo '</tr>' . "\n";
684
            $script .= $first ? '\'photoId[' . $photo->getVar('photo_id') . ']\'' : ', \'photoId[' . $photo->getVar('photo_id') . ']\'';
685
            $first  = false;
686
        }
687
        echo '<tr><td colspan="5">';
688
        echo '<input type="submit" name="approve" value="' . _AM_EXTGALLERY_APPROVE . '">&nbsp;&nbsp;<input type="submit" name="delete" value="' . _DELETE . '">';
689
        echo '</td></tr>';
690
691
        echo '</table>' . "\n";
692
        echo '</form>';
693
        echo '</fieldset><br>' . "\n";
694
695
        echo '<script type="text/javascript">' . "\n";
696
        echo 'function checkAllPhoto() {' . "\n";
697
        echo 'var optionids = new Array(' . $script . ');' . "\n";
698
        echo 'xoopsCheckAllElements(optionids, \'selectAllPhoto\');' . "\n";
699
        echo '}' . "\n";
700
        echo '</script>' . "\n";
701
702
        xoops_cp_footer();
703
704
        break;
705
}
706