Skip to content

Commit

Permalink
Throw exception when resources are disabled, like other optional cale…
Browse files Browse the repository at this point in the history
…ndars.

Also, fix some places where we assumed they were always available.
  • Loading branch information
mrubinsk committed Jan 13, 2014
1 parent 3644f58 commit 24e9cec
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
10 changes: 7 additions & 3 deletions kronolith/attendees.php
Expand Up @@ -165,9 +165,13 @@
}

/* Get list of resources for select list, and remove those we already added */
$allResources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array(), 'name');
foreach (array_keys($resources) as $id) {
unset($allResources[$id]);
if (!empty($conf['resource']['driver'])) {
$allResources = Kronolith::getDriver('Resource')->listResources(Horde_Perms::READ, array(), 'name');
foreach (array_keys($resources) as $id) {
unset($allResources[$id]);
}
} else {
$allResources = array();
}

// Get the current Free/Busy view; default to the 'day' view if none specified.
Expand Down
30 changes: 17 additions & 13 deletions kronolith/js/kronolith.js
Expand Up @@ -5468,19 +5468,23 @@ KronolithCore = {
}

// Check that there are no conflicts.
HordeCore.doAction(
'checkResources',
{
s: this.getDate('start').toISOString(),
e: this.getDate('end').toISOString(),
i: $F('kronolithEventId'),
c: $F('kronolithEventCalendar'),
r: $F('kronolithEventResourceIds')
},
{
callback: this.validateEventCallback.curry(asnew).bind(this)
}
);
if (Kronolith.conf.has_resources && $F('kronolithEventResourceIds')) {
HordeCore.doAction(
'checkResources',
{
s: this.getDate('start').toISOString(),
e: this.getDate('end').toISOString(),
i: $F('kronolithEventId'),
c: $F('kronolithEventCalendar'),
r: $F('kronolithEventResourceIds')
},
{
callback: this.validateEventCallback.curry(asnew).bind(this)
}
);
} else {
this.validateEventCallback(asnew, {});
}
},

validateEventCallback: function(asnew, r)
Expand Down
7 changes: 4 additions & 3 deletions kronolith/lib/Ajax.php
Expand Up @@ -86,6 +86,7 @@ protected function _addBaseVars()
'app_urls' => $app_urls,
'name' => $registry->get('name'),
'has_tasks' => intval($has_tasks),
'has_resources' => intval(!empty($conf['resource']['driver'])),
'login_view' => ($prefs->getValue('defaultview') == 'workweek') ? 'week' : $prefs->getValue('defaultview'),
'default_calendar' => 'internal|' . Kronolith::getDefaultCalendar(Horde_Perms::EDIT),
'max_events' => intval($prefs->getValue('max_events')),
Expand Down Expand Up @@ -118,9 +119,9 @@ protected function _addBaseVars()
'edit' => Horde_Perms::EDIT,
'delete' => Horde_Perms::DELETE,
'delegate' => Kronolith::PERMS_DELEGATE
),
'tasks' => $has_tasks ? $registry->tasks->ajaxDefaults() : null
));
),
'tasks' => $has_tasks ? $registry->tasks->ajaxDefaults() : null
));

/* Make sure this value is not optimized out by array_filter(). */
$js_vars['conf']['week_start'] = intval($prefs->getValue('week_start_monday'));
Expand Down
4 changes: 4 additions & 0 deletions kronolith/lib/Ajax/Application/Handler.php
Expand Up @@ -1419,6 +1419,10 @@ public function toTimeslice()
*/
public function checkResources()
{
if (empty($GLOBALS['conf']['resource']['driver'])) {
return array();
}

if ($this->vars->i) {
$event = $this->_getDriver($this->vars->c)->getEvent($this->vars->i);
} else {
Expand Down
1 change: 1 addition & 0 deletions kronolith/lib/Factory/Driver.php
Expand Up @@ -71,6 +71,7 @@ public function create($driver, array $params = array())
case 'Resource_Sql':
if (!isset($GLOBALS['conf']['calendar']['driver']) ||
$GLOBALS['conf']['resource']['driver'] != 'sql') {
throw new Kronolith_Exception(_("Resources are disabled"));
return new Horde_Support_Stub();
}
$params = array_merge(Horde::getDriverConfig('resource', 'sql'), $params);
Expand Down
4 changes: 3 additions & 1 deletion kronolith/lib/Kronolith.php
Expand Up @@ -220,7 +220,9 @@ static public function listEvents(
}

// Resource calendars
if (count($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS))) {
if (count($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS) &&
!empty($GLOBALS['conf']['resource']['driver']))) {

$driver = self::getDriver('Resource');
foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_RESOURCE_CALENDARS) as $calendar) {
try {
Expand Down
2 changes: 1 addition & 1 deletion kronolith/templates/dynamic/edit.inc
Expand Up @@ -97,7 +97,7 @@
<li><a href="#" class="kronolithTabLink" id="kronolithEventLinkRecur"><?php echo _("Repeat") ?></a></li>
<li><a href="#" class="kronolithTabLink" id="kronolithEventLinkUrl"><?php echo _("URL") ?></a></li>
<li><a href="#" class="kronolithTabLink" id="kronolithEventLinkAttendees"><?php echo _("Attendees") ?></a></li>
<?php if (count(Kronolith::getDriver('Resource')->listResources())):?>
<?php if (!empty($GLOBALS['conf']['resource']['driver']) && count(Kronolith::getDriver('Resource')->listResources())):?>
<li><a href="#" class="kronolithTabLink" id="kronolithEventLinkResources"><?php echo _("Resources") ?></a></li>
<?php endif; ?>
<li><a href="#" class="kronolithTabLink" id="kronolithEventLinkTags"><?php echo _("Tags") ?></a></li>
Expand Down

0 comments on commit 24e9cec

Please sign in to comment.