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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
<?php
/**
* $Horde: kronolith/attendees.php,v 1.7.8.22 2008/05/25 14:53:06 jan Exp $
*
* Copyright 2004-2007 Code Fusion <http://www.codefusion.co.za/>
* Copyright 2004-2007 Stuart Binge <s.binge@codefusion.co.za>
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*/
@define('KRONOLITH_BASE', dirname(__FILE__));
require_once KRONOLITH_BASE . '/lib/base.php';
require_once KRONOLITH_BASE . '/lib/FreeBusy.php';
require_once KRONOLITH_BASE . '/lib/FBView.php';
require_once KRONOLITH_BASE . '/lib/Imple.php';
require_once 'Horde/Identity.php';
require_once 'Horde/UI/Tabs.php';
require_once 'Horde/Variables.php';
// Get the current attendees array from the session cache.
$attendees = (isset($_SESSION['kronolith']['attendees']) &&
is_array($_SESSION['kronolith']['attendees']))
? $_SESSION['kronolith']['attendees']
: array();
$editAttendee = null;
// Get the action ID and value. This specifies what action the user initiated.
$actionID = Util::getFormData('actionID');
if (Util::getFormData('clearAll')) {
$actionID = 'clear';
}
$actionValue = Util::getFormData('actionValue');
// Perform the specified action, if there is one.
switch ($actionID) {
case 'add':
require_once 'Mail/RFC822.php';
$parser = new Mail_RFC822;
// Add new attendees. Multiple attendees can be seperated on a single line
// by whitespace and/or commas.
$newAttendees = trim(Util::getFormData('newAttendees'));
if (empty($newAttendees)) {
if (Util::getFormData('addNewClose')) {
Util::closeWindowJS();
exit;
}
break;
}
require_once 'Horde/MIME.php';
foreach (MIME::rfc822Explode($newAttendees) as $newAttendee) {
// Parse the address without validation to see what we can get out of
// it. We allow email addresses (john@example.com), email address with
// user information (John Doe <john@example.com>), and plain names
// (John Doe).
$newAttendeeParsed = $parser->parseAddressList($newAttendee, '', false,
false);
// If we can't even get a mailbox out of the address, then it is
// likely unuseable. Reject it entirely.
if (is_a($newAttendeeParsed, 'PEAR_Error') ||
!isset($newAttendeeParsed[0]) ||
!isset($newAttendeeParsed[0]->mailbox)) {
$notification->push(
sprintf(_("Unable to recognize \"%s\" as an email address."),
$newAttendee),
'horde.error');
continue;
}
// Loop through any addresses we found.
foreach ($newAttendeeParsed as $newAttendeeParsedPart) {
// If there is only a mailbox part, then it is just a local name.
if (empty($newAttendeeParsedPart->host)) {
$attendees[] = array(
'attendance' => KRONOLITH_PART_REQUIRED,
'response' => KRONOLITH_RESPONSE_NONE,
'name' => $newAttendee,
);
continue;
}
// Build a full email address again and validate it.
$name = empty($newAttendeeParsedPart->personal)
? ''
: $newAttendeeParsedPart->personal;
$newAttendeeParsedPartNew = MIME::encodeAddress(
MIME::rfc822WriteAddress($newAttendeeParsedPart->mailbox,
$newAttendeeParsedPart->host, $name));
$newAttendeeParsedPartValidated = $parser->parseAddressList(
$newAttendeeParsedPartNew, '', null, true);
if (is_a($newAttendeeParsedPartValidated, 'PEAR_Error')) {
$notification->push($newAttendeeParsedPartValidated,
'horde.error');
} else {
$email = $newAttendeeParsedPart->mailbox . '@'
. $newAttendeeParsedPart->host;
// Avoid overwriting existing attendees with the default
// values.
if (!isset($attendees[$email]))
$attendees[$email] = array(
'attendance' => KRONOLITH_PART_REQUIRED,
'response' => KRONOLITH_RESPONSE_NONE,
'name' => $name,
);
}
}
}
$_SESSION['kronolith']['attendees'] = $attendees;
if (Util::getFormData('addNewClose')) {
Util::closeWindowJS();
exit;
}
break;
case 'edit':
// Edit the specified attendee.
if (isset($attendees[$actionValue])) {
if (empty($attendees[$actionValue]['name'])) {
$editAttendee = $actionValue;
} else {
require_once 'Horde/MIME.php';
$editAttendee = MIME::trimEmailAddress(
$attendees[$actionValue]['name']
. (strpos($actionValue, '@') === false
? ''
: ' <' . $actionValue . '>'));
}
unset($attendees[$actionValue]);
$_SESSION['kronolith']['attendees'] = $attendees;
}
break;
case 'remove':
// Remove the specified attendee.
if (isset($attendees[$actionValue])) {
unset($attendees[$actionValue]);
$_SESSION['kronolith']['attendees'] = $attendees;
}
break;
case 'changeatt':
// Change the attendance status of an attendee
list($partval, $partname) = explode(' ', $actionValue, 2);
if (isset($attendees[$partname])) {
$attendees[$partname]['attendance'] = $partval;
$_SESSION['kronolith']['attendees'] = $attendees;
}
break;
case 'dismiss':
// Close the attendee window.
if ($browser->hasFeature('javascript')) {
Util::closeWindowJS();
exit;
}
$url = Util::getFormData('url');
if (!empty($url)) {
$location = Horde::applicationUrl($url, true);
} else {
$url = Util::addParameter($prefs->getValue('defaultview') . '.php',
'month', Util::getFormData('month'));
$url = Util::addParameter($url, 'year', Util::getFormData('year'));
$location = Horde::applicationUrl($url, true);
}
// Make sure URL is unique.
$location = Util::addParameter($location, 'unique', md5(microtime()));
header('Location: ' . $location);
exit;
case 'clear':
// Remove all the attendees.
$attendees = array();
$_SESSION['kronolith']['attendees'] = $attendees;
break;
}
// Get the current Free/Busy view; default to the 'day' view if none specified.
$view = Util::getFormData('view', 'day');
// Pre-format our delete image/link.
$delimg = Horde::img('delete.png', _("Remove Attendee"), null,
$registry->getImageDir('horde'));
$ident = &Identity::singleton();
$identities = $ident->getAll('id');
$vars = Variables::getDefaultVariables();
$tabs = new Horde_UI_Tabs(null, $vars);
$tabs->addTab(_("Day"), 'javascript:switchView(\'day\')', 'day');
$tabs->addTab(_("Work Week"), 'javascript:switchView(\'workweek\')', 'workweek');
$tabs->addTab(_("Week"), 'javascript:switchView(\'week\')', 'week');
$tabs->addTab(_("Month"), 'javascript:switchView(\'month\')', 'month');
$attendee_view = &Kronolith_FreeBusy_View::singleton($view);
// Add the creator as a required attendee in the Free/Busy display
$cal = @unserialize($prefs->getValue('fb_cals'));
if (!is_array($cal)) {
$cal = null;
}
// If the free/busy calendars preference is empty, default to the user's
// default_share preference, and if that's empty, to their username.
if (!$cal) {
$cal = $prefs->getValue('default_share');
if (!$cal) {
$cal = Auth::getAuth();
}
$cal = array($cal);
}
$vfb = Kronolith_FreeBusy::generate($cal, null, null, true, Auth::getAuth());
if (!is_a($vfb, 'PEAR_Error')) {
$attendee_view->addRequiredMember($vfb);
} else {
$notification->push(
sprintf(_("Error retrieving your free/busy information: %s"),
$vfb->getMessage()));
}
// Add the Free/Busy information for each attendee.
foreach ($attendees as $email => $status) {
if (strpos($email, '@') !== false &&
($status['attendance'] == KRONOLITH_PART_REQUIRED ||
$status['attendance'] == KRONOLITH_PART_OPTIONAL)) {
$vfb = Kronolith_Freebusy::get($email);
if (!is_a($vfb, 'PEAR_Error')) {
$organizer = $vfb->getAttribute('ORGANIZER');
if (empty($organizer)) {
$vfb->setAttribute('ORGANIZER', 'mailto:' . $email, array(),
false);
}
if ($status['attendance'] == KRONOLITH_PART_REQUIRED) {
$attendee_view->addRequiredMember($vfb);
} else {
$attendee_view->addOptionalMember($vfb);
}
} else {
$notification->push(
sprintf(_("Error retrieving free/busy information for %s: %s"),
$email, $vfb->getMessage()));
}
}
}
$timestamp = (int)Util::getFormData('timestamp');
if (!$timestamp) {
$year = (int)Util::getFormData('year', date('Y'));
$month = (int)Util::getFormData('month', date('n'));
$day = (int)Util::getFormData('mday', date('d'));
$timestamp = empty($year)
? $_SERVER['REQUEST_TIME']
: mktime(0, 0, 0, $month, $day, $year);
}
$vfb_html = $attendee_view->render($timestamp);
// Add the ContactAutoCompleter
Imple::factory('ContactAutoCompleter', array('triggerId' => 'newAttendees'));
$title = _("Edit attendees");
require KRONOLITH_TEMPLATES . '/common-header.inc';
$notification->notify(array('status'));
require KRONOLITH_TEMPLATES . '/attendees/attendees.inc';
require $registry->get('templates', 'horde') . '/common-footer.inc';
|