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
|
<?php
/**
* Kronolith base inclusion file.
*
* $Horde: kronolith/lib/base.php,v 1.117.8.8 2006/05/03 09:58:51 jan Exp $
*
* This file brings in all of the dependencies that every Kronolith
* script will need, and sets up objects that all scripts use.
*/
/* Check for a prior definition of HORDE_BASE (perhaps by an
* auto_prepend_file definition for site customization). */
if (!defined('HORDE_BASE')) {
@define('HORDE_BASE', dirname(__FILE__) . '/../..');
}
/* Load the Horde Framework core, and set up inclusion paths. */
require_once HORDE_BASE . '/lib/core.php';
/* Registry. */
$registry = &Registry::singleton();
if (is_a(($pushed = $registry->pushApp('kronolith', !defined('AUTH_HANDLER'))), 'PEAR_Error')) {
if ($pushed->getCode() == 'permission_denied') {
Horde::authenticationFailureRedirect();
}
Horde::fatal($pushed, __FILE__, __LINE__, false);
}
$conf = &$GLOBALS['conf'];
@define('KRONOLITH_TEMPLATES', $registry->get('templates'));
/* Find the base file path of Kronolith. */
@define('KRONOLITH_BASE', dirname(__FILE__) . '/..');
/* Horde framework libraries. */
require_once 'Horde/Date.php';
require_once 'Horde/Help.php';
require_once 'Horde/History.php';
/* Notification system. */
$notification = &Notification::singleton();
$notification->attach('status');
/* Kronolith base library. */
require_once KRONOLITH_BASE . '/lib/Kronolith.php';
/* Categories. */
require_once 'Horde/Prefs/CategoryManager.php';
$GLOBALS['cManager'] = &new Prefs_CategoryManager();
/* PEAR Date_Calc. */
require_once 'Date/Calc.php';
/* Start compression, if requested. */
Horde::compressOutput();
/* Set the timezone variable, if available. */
NLS::setTimeZone();
/* Create a calendar backend object. */
$GLOBALS['kronolith'] = &Kronolith_Driver::factory();
/* Create a share instance. */
require_once 'Horde/Share.php';
$GLOBALS['kronolith_shares'] = &Horde_Share::singleton($registry->getApp());
/* Update preferences for which calendars to display. If the user
* doesn't have any selected calendars to view then fall back to an
* available calendar. */
$GLOBALS['display_calendars'] = unserialize($GLOBALS['prefs']->getValue('display_cals'));
$GLOBALS['display_remote_calendars'] = unserialize($GLOBALS['prefs']->getValue('display_remote_cals'));
if (($d_cal = Util::getFormData('display_cal')) !== null) {
if (substr($d_cal, 0, 7) == 'remote_') {
$d_cal = substr($d_cal, 7);
if (in_array($d_cal, $GLOBALS['display_remote_calendars'])) {
$key = array_search($d_cal, $GLOBALS['display_remote_calendars']);
unset($GLOBALS['display_remote_calendars'][$key]);
} else {
$GLOBALS['display_remote_calendars'][] = $d_cal;
}
} else {
if (in_array($d_cal, $GLOBALS['display_calendars'])) {
$key = array_search($d_cal, $GLOBALS['display_calendars']);
unset($GLOBALS['display_calendars'][$key]);
} else {
$GLOBALS['display_calendars'][] = $d_cal;
}
}
}
/* Make sure all shares exists now to save on checking later. */
$GLOBALS['all_calendars'] = Kronolith::listCalendars();
$calendar_keys = array_values($GLOBALS['display_calendars']);
$GLOBALS['display_calendars'] = array();
foreach ($calendar_keys as $id) {
if (isset($GLOBALS['all_calendars'][$id])) {
$GLOBALS['display_calendars'][] = $id;
}
}
/* Make sure all the remote calendars still exist. */
$_temp = $GLOBALS['display_remote_calendars'];
$_all = unserialize($GLOBALS['prefs']->getValue('remote_cals'));
$GLOBALS['display_remote_calendars'] = array();
foreach ($_all as $id) {
if (in_array($id['url'], $_temp)) {
$GLOBALS['display_remote_calendars'][] = $id['url'];
}
}
$GLOBALS['prefs']->setValue('display_remote_cals', serialize($GLOBALS['display_remote_calendars']));
if (count($GLOBALS['display_calendars']) == 0) {
$cals = Kronolith::listCalendars(true);
if (!Auth::getAuth()) {
/* All calendars for guests. */
$GLOBALS['display_calendars'] = array_keys($cals);
} else {
/* Make sure at least the default calendar is visible. */
$default_calendar = Kronolith::getDefaultCalendar(PERMS_READ);
if ($default_calendar) {
$GLOBALS['display_calendars'] = array($default_calendar);
}
/* If the user's personal calendar doesn't exist, then create it. */
if (!$GLOBALS['kronolith_shares']->exists(Auth::getAuth())) {
require_once 'Horde/Identity.php';
$identity = &Identity::singleton();
$name = $identity->getValue('fullname');
if (trim($name) == '') {
$name = Auth::removeHook(Auth::getAuth());
}
$share = &$GLOBALS['kronolith_shares']->newShare(Auth::getAuth());
$share->set('name', sprintf(_("%s's Calendar"), $name));
$GLOBALS['kronolith_shares']->addShare($share);
$GLOBALS['all_calendars'][Auth::getAuth()] = &$share;
/* Make sure the personal calendar is displayed by default. */
if (!in_array(Auth::getAuth(), $GLOBALS['display_calendars'])) {
$GLOBALS['display_calendars'][] = Auth::getAuth();
}
/* Calendar auto-sharing with the user's groups */
if ($conf['autoshare']['shareperms'] != 'none') {
$perm_value = 0;
switch ($conf['autoshare']['shareperms']) {
case 'read':
$perm_value = PERMS_READ | PERMS_SHOW;
break;
case 'edit':
$perm_value = PERMS_READ | PERMS_SHOW | PERMS_EDIT;
break;
case 'full':
$perm_value = PERMS_READ | PERMS_SHOW | PERMS_EDIT | PERMS_DELETE;
break;
}
$perm = $share->getPermission();
// Add the default perm, not added otherwise
$perm->addUserPermission(Auth::getAuth(), PERMS_ALL, false);
$groups = &Group::singleton();
$group_list = $groups->getGroupMemberships(Auth::getAuth());
if (!is_a($group_list, 'PEAR_Error')) {
foreach ($group_list as $group_id => $group_name) {
$perm->addGroupPermission($group_id, $perm_value, false);
}
}
$share->setPermission($perm);
$share->save();
$notification->push(sprintf(_("New calendar created and automatically shared with the following group(s): %s."), implode(', ', $group_list)), 'horde.success');
}
}
}
}
$GLOBALS['prefs']->setValue('display_cals', serialize($GLOBALS['display_calendars']));
|