File: edit_dates.php

package info (click to toggle)
php-horde-ansel 3.0.9%2Bdebian0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,860 kB
  • sloc: php: 15,757; xml: 1,979; makefile: 28; sh: 3
file content (102 lines) | stat: -rw-r--r-- 3,781 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
 * Copyright 2008-2017 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Michael J. Rubinsky <mrubinsk@horde.org>
 */

require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('ansel');

$images = Horde_Util::getFormData('image', array());
$actionID = Horde_Util::getFormData('actionID');
$gallery_id = Horde_Util::getFormData('gallery');
$page = Horde_Util::getFormData('page', 0);

/* If we have a single gallery, check perms now */
if (!empty($gallery_id)) {
    $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($gallery_id);
    if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
        $notification->push(_("You are not allowed to edit these photos."), 'horde.error');
        echo Horde::wrapInlineScript(array(
            'window.opener.location.href = window.opener.location.href;',
            'window.close();'
        ));
        exit;
    }
}

/* Make sure we have at least one image */
if (!count($images)) {
    echo $notification->push(_("You must select at least on photo to edit."), 'horde.error');
    echo Horde::wrapInlineScript(array(
        'window.opener.location.href = window.opener.location.href;',
        'window.close();'
    ));
    exit;
}

/* Set up the form */
$vars = Horde_Variables::getDefaultVariables();
$form = new Ansel_Form_ImageDate($vars, _("Edit Dates"));
/* Are we doing the edit now? */
if ($actionID == 'edit_dates') {
    $count = 0;
    foreach (array_keys($images) as $image_id) {
        try {
            $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
            if (empty($gallery_id)) {
                // Images might be from different galleries
                $gallery = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
                if (!$gallery->hasPermission($registry->getAuth(), Horde_Perms::EDIT)) {
                    continue;
                }
            }
            $newDate = new Horde_Date($vars->get('image_originalDate'));
            $image->originalDate = (int)$newDate->timestamp();
            $image->save();
            ++$count;
        } catch (Ansel_Exception $e) {
           $notification->push(sprintf(_("There was an error editing the dates: %s"), $e->getMessage()), 'horde.error');
            echo Horde::wrapInlineScript(array(
                'window.opener.location.href = window.opener.location.href;',
                'window.close();'
            ));
           exit;
        }
    }

    $notification->push(sprintf(_("Successfully modified the date on %d photos."), $count), 'horde.success');
    echo Horde::wrapInlineScript(array(
        'window.opener.location.href = window.opener.location.href;',
        'window.close();'
    ));
    exit;
}

$keys = array_keys($images);
$html = '';
foreach ($keys as $key) {
    $html .= '<img src="' . Ansel::getImageUrl($key, 'mini', false) . '" style="margin:2px;" alt="[thumbnail]" />';
}
$image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage(array_pop($keys));
/* Display the form */
$vars->set('image', $images);
$vars->set('gallery', $gallery_id);
$vars->set('page', $page);
$vars->set('actionID', 'edit_dates');
$vars->set('image_list', $html);
$vars->set('image_originalDate', $image->originalDate);
$renderer = new Horde_Form_Renderer();
$count = count($images);

$page_output->topbar = $page_output->sidebar = false;

$page_output->header();
$form->renderActive($renderer, $vars, null, 'post');
// Needed to ensure the body element is large enough to hold the pop up calendar
echo '<br /><br /><br />';
$page_output->footer();