File: edit.php

package info (click to toggle)
kronolith2 2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,936 kB
  • ctags: 3,577
  • sloc: php: 14,001; xml: 1,494; sql: 489; makefile: 68
file content (185 lines) | stat: -rw-r--r-- 7,848 bytes parent folder | download
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
 * $Horde: kronolith/edit.php,v 1.10.2.3 2008/01/10 16:16:49 jan Exp $
 *
 * Copyright 1999-2008 The Horde Project (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 *
 * @author Chuck Hagenbuch <chuck@horde.org>
 */

function _save(&$event)
{
    $res = $event->save();
    if (is_a($res, 'PEAR_Error')) {
        $GLOBALS['notification']->push(sprintf(_("There was an error editing the event: %s"), $res->getMessage()), 'horde.error');
    } elseif (Util::getFormData('sendupdates', false)) {
        Kronolith::sendITipNotifications($event, $GLOBALS['notification'], KRONOLITH_ITIP_REQUEST);
    }
}

function _check_max()
{
    if (Kronolith::hasPermission('max_events') !== true &&
        Kronolith::hasPermission('max_events') <= Kronolith::countEvents()) {
        $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), Kronolith::hasPermission('max_events')), ENT_COMPAT, NLS::getCharset());
        if (!empty($GLOBALS['conf']['hooks']['permsdenied'])) {
            $message = Horde::callHook('_perms_hook_denied', array('kronolith:max_events'), 'horde', $message);
        }
        $GLOBALS['notification']->push($message, 'horde.error', array('content.raw'));
        return false;
    }
    return true;
}

@define('KRONOLITH_BASE', dirname(__FILE__));
require_once KRONOLITH_BASE . '/lib/base.php';

$url = Util::getFormData('url');

if ($exception = Util::getFormData('del_exception')) {
    $calendar = Util::getFormData('calendar');
    $share = &$kronolith_shares->getShare($calendar);
    if (is_a($share, 'PEAR_Error')) {
        $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error');
    } else {
        $kronolith_driver->open($calendar);
        $event = &$kronolith_driver->getEvent(Util::getFormData('eventID'));
        $result = sscanf($exception, '%04d%02d%02d', $year, $month, $day);
        if ($result == 3 && !is_a($event, 'PEAR_Error') && $event->recurs()) {
            $event->recurrence->deleteException($year, $month, $day);
            _save($event);
        }
    }
} elseif (!Util::getFormData('cancel')) {
    $source = Util::getFormData('existingcalendar');
    $targetcalendar = Util::getFormData('targetcalendar');
    if (strpos($targetcalendar, ':')) {
        list($target, $user) = explode(':', $targetcalendar, 2);
    } else {
        $target = $targetcalendar;
        $user = Auth::getAuth();
    }
    $share = &$kronolith_shares->getShare($target);

    if (is_a($share, 'PEAR_Error')) {
        $notification->push(sprintf(_("There was an error accessing the calendar: %s"), $share->getMessage()), 'horde.error');
    } else {
        $event = false;

        if (($edit_recur = Util::getFormData('edit_recur')) &&
            $edit_recur != 'all' && $edit_recur != 'copy' &&
            _check_max()) {
            /* Get event details. */
            $kronolith_driver->open($source);
            $event = &$kronolith_driver->getEvent(Util::getFormData('eventID'));
            $recur_ex = Util::getFormData('recur_ex');
            $exception = new Horde_Date($recur_ex);

            switch ($edit_recur) {
            case 'current':
                /* Add exception. */
                $event->recurrence->addException($exception->year,
                                                 $exception->month,
                                                 $exception->mday);
                $event->save();

                /* Create one-time event. */
                $kronolith_driver->open($target);
                $event = &$kronolith_driver->getEvent();
                $event->readForm();
                $event->recurrence->setRecurType(HORDE_DATE_RECUR_NONE);

                break;

            case 'future':
                /* Set recurrence end. */
                $exception->mday--;
                $exception->correct();
                if ($event->end->compareDate($exception) > 0) {
                    $result = $kronolith_driver->deleteEvent($event->getId());
                    if (is_a($result, 'PEAR_Error')) {
                        $notification->push($result, 'horde.error');
                    }
                } else {
                    $event->recurrence->setRecurEnd($exception);
                    $event->save();
                }

                /* Create new event. */
                $kronolith_driver->open($target);
                $event = &$kronolith_driver->getEvent();
                $event->readForm();

                break;
            }

            $event->setUID(null);
            _save($event);
            $event = null;
        } elseif (Util::getFormData('saveAsNew') ||
                  $edit_recur == 'copy') {
            if (_check_max()) {
                $kronolith_driver->open($target);
                $event = &$kronolith_driver->getEvent();
            }
        } else {
            $event_load_from = $source;

            if ($target != $source) {
                // Only delete the event from the source calendar if this user
                // has permissions to do so.
                $sourceShare = &$kronolith_shares->getShare($source);
                if (!is_a($share, 'PEAR_Error') &&
                    !is_a($sourceShare, 'PEAR_Error') &&
                    $sourceShare->hasPermission(Auth::getAuth(), PERMS_DELETE) &&
                    (($user == Auth::getAuth() &&
                      $share->hasPermission(Auth::getAuth(), PERMS_EDIT)) ||
                     ($user != Auth::getAuth() &&
                      $share->hasPermission(Auth::getAuth(), PERMS_DELEGATE)))) {
                    $kronolith_driver->open($source);
                    $res = $kronolith_driver->move(Util::getFormData('eventID'), $target);
                    if (is_a($res, 'PEAR_Error')) {
                        $notification->push(sprintf(_("There was an error moving the event: %s"), $res->getMessage()), 'horde.error');
                    } else {
                        $event_load_from = $target;
                    }
                }
            }

            $kronolith_driver->open($event_load_from);
            $event = &$kronolith_driver->getEvent(Util::getFormData('eventID'));
        }

        if ($event && !is_a($event, 'PEAR_Error')) {
            if (isset($sourceShare) && !is_a($sourceShare, 'PEAR_Error')
                && !$sourceShare->hasPermission(Auth::getAuth(), PERMS_DELETE)) {
                $notification->push(_("You do not have permission to move this event."), 'horde.warning');
            } elseif ($user != Auth::getAuth() &&
                      !$share->hasPermission(Auth::getAuth(), PERMS_DELEGATE, $event->getCreatorID())) {
                $notification->push(sprintf(_("You do not have permission to delegate events to %s."), Kronolith::getUserName($user)), 'horde.warning');
            } elseif ($user == Auth::getAuth() &&
                      !$share->hasPermission(Auth::getAuth(), PERMS_EDIT, $event->getCreatorID())) {
                $notification->push(_("You do not have permission to edit this event."), 'horde.warning');
            } else {
                $event->readForm();
                _save($event);
            }
        }
    }
}

if (!empty($url)) {
    $location = $url;
} else {
    $url = Util::addParameter($prefs->getValue('defaultview') . '.php',
                              array('month' => Util::getFormData('month'),
                                    'year' => Util::getFormData('year')));
    $location = Horde::applicationUrl($url, true);
}

// Make sure URL is unique.
$location = Util::addParameter($location, 'unique', md5(microtime()), false);
header('Location: ' . $location);