$resources[$newResource] = array(
'attendance' => Kronolith::PART_IGNORE,
'response' => Kronolith::RESPONSE_NONE,
- 'name' => $resource->name,
+ 'name' => $resource->get('name'),
);
$_SESSION['kronolith']['resources'] = $resources;
*/
public function save($resource)
{
- if ($resource->id) {
+ if ($resource->getId()) {
$query = 'UPDATE kronolith_resources SET resource_name = ?, resource_calendar = ?, resource_category = ? WHERE resource_id = ?';
- $values = array($resource->name, $resource->calendar, $resource->category, $resource->id);
+ $values = array($resource->get('name'), $resource->get('calendar'), $resource->get('category'), $resource->getId());
$result = $this->_write_db->query($query, $values);
if ($result instanceof PEAR_Error) {
throw new Horde_Exception($result->getMessage());
$query = 'INSERT INTO kronolith_resources (resource_id, resource_name, resource_calendar, resource_category)';
$cols_values = ' VALUES (?, ?, ?, ?)';
$id = $this->_db->nextId('kronolity_resources');
- $values = array($id, $resource->name, $resource->calendar, $resource->category);
+ $values = array($id, $resource->get('name'), $resource->get('calendar'), $resource->get('category'));
$result = $this->_write_db->query($query . $cols_values, $values);
if (!($result instanceof PEAR_Error)) {
return true;
*/
public function delete($resource)
{
- if (!$resource->calendar || !$resource->id) {
+ if (!$resource->get('calendar') || !$resource->getId()) {
var_dump($resource);
throw new Horde_Exception(_("Resource not valid."));
}
$query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE calendar_id = ?';
- $result = $this->_write_db->query($query, array($resource->calendar));
+ $result = $this->_write_db->query($query, array($resource->get('calendar')));
if ($result instanceof PEAR_Error) {
throw new Horde_Exception($result->getMessage());
}
$query = 'DELETE FROM kronolith_resources WHERE resource_id = ?';
- $result = $this->_write_db->query($query, array($resource->id));
+ $result = $this->_write_db->query($query, array($resource->getId()));
if ($result instanceof PEAR_Error) {
throw new Horde_Exception($result->getMessage());
}
*/
public function addResource($resource, $response)
{
- $this->_resources[$resource->id] = array(
+ $this->_resources[$resource->getId()] = array(
'attendance' => Kronolith::PART_REQUIRED,
'response' => $response,
- 'name' => $resource->name
+ 'name' => $resource->get('name')
);
}
--- /dev/null
+<?php
+/**
+ * Horde_Form for creating resource calendars.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Kronolith
+ */
+
+/** Horde_Form */
+require_once 'Horde/Form.php';
+
+/** Horde_Form_Renderer */
+require_once 'Horde/Form/Renderer.php';
+
+/**
+ * The Kronolith_CreateResourceForm class provides the form for
+ * creating a calendar.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Kronolith
+ */
+class Kronolith_CreateResourceForm extends Horde_Form {
+
+ function Kronolith_CreateResourceForm(&$vars)
+ {
+ parent::Horde_Form($vars, _("Create Resource"));
+
+ $this->addVariable(_("Name"), 'name', 'text', true);
+ $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+ $this->addVariable(_("Category"), 'category', 'text', false);
+ $this->setButtons(array(_("Create")));
+ }
+
+ function execute()
+ {
+ $new = array('name' => $this->_vars->get('name'),
+ 'category' =>$this->_vars->get('category'));
+
+ $resource = new Kronolith_Resource_Single($new);
+ return $results = Kronolith::addResource($resource);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Horde_Form for deleting calendars.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Kronolith
+ */
+
+/** Horde_Form */
+require_once 'Horde/Form.php';
+
+/** Horde_Form_Renderer */
+require_once 'Horde/Form/Renderer.php';
+
+/**
+ * The Kronolith_DeleteCalendarForm class provides the form for
+ * deleting a calendar.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Kronolith
+ */
+class Kronolith_DeleteResourceForm extends Horde_Form {
+
+ /**
+ * Calendar being deleted
+ */
+ var $_calendar;
+
+ function Kronolith_DeleteResourceForm(&$vars, &$resource)
+ {
+ $this->_resource = &$resource;
+ parent::Horde_Form($vars, sprintf(_("Delete %s"), $resource->get('name')));
+
+ $this->addHidden('', 'c', 'text', true);
+ $this->addVariable(sprintf(_("Really delete the resource \"%s\"? This cannot be undone and all data on this resource will be permanently removed."), $this->_resource->get('name')), 'desc', 'description', false);
+
+ $this->setButtons(array(_("Delete"), _("Cancel")));
+ }
+
+ function execute()
+ {
+ // If cancel was clicked, return false.
+ if ($this->_vars->get('submitbutton') == _("Cancel")) {
+ return false;
+ }
+
+ if (!($this->_resource->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE))) {
+ return PEAR::raiseError(_("Permission denied"));
+ }
+
+ // Delete the resource.
+ $result = Kronolith::getDriver('Resource')->delete($this->_resource);
+ if ($result instanceof PEAR_Error) {
+ return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $this->_resource->get('name'), $result->getMessage()));
+ }
+
+ return true;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Horde_Form for editing resource calendars.
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @package Kronolith
+ */
+
+/** Horde_Form */
+require_once 'Horde/Form.php';
+
+/** Horde_Form_Renderer */
+require_once 'Horde/Form/Renderer.php';
+
+/**
+ * The Kronolith_EditResourceForm class provides the form for
+ * editing a calendar.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @package Kronolith
+ */
+class Kronolith_EditResourceForm extends Horde_Form {
+
+ /**
+ * Calendar being edited
+ */
+ var $_resource;
+
+ function Kronolith_EditResourceForm(&$vars, &$resource)
+ {
+ $this->_resource = &$resource;
+ parent::Horde_Form($vars, sprintf(_("Edit %s"), $resource->get('name')));
+
+ $this->addHidden('', 'c', 'text', true);
+ $this->addVariable(_("Name"), 'name', 'text', true);
+ $this->addVariable(_("Description"), 'description', 'longtext', false, false, null, array(4, 60));
+ $this->addVariable(_("Category"), 'category', 'text', false);
+ $this->setButtons(array(_("Save")));
+ }
+
+ function execute()
+ {
+ $original_name = $this->_resource->get('name');
+ $new_name = $this->_vars->get('name');
+ $this->_resource->set('name', $new_name);
+ $this->_resource->set('description', $this->_vars->get('description'));
+ $this->_resource->set('category', $this->_vars->get('category'));
+ if ($original_name != $new_name) {
+ $result = Kronolith::getDriver()->rename($original_name, $new_name);
+ if (is_a($result, 'PEAR_Error')) {
+ return PEAR::raiseError(sprintf(_("Unable to rename \"%s\": %s"), $original_name, $result->getMessage()));
+ }
+ }
+
+ $result = $this->_resource->save();
+ if (is_a($result, 'PEAR_Error')) {
+ return PEAR::raiseError(sprintf(_("Unable to save resource \"%s\": %s"), $new_name, $result->getMessage()));
+ }
+
+ return $this->_resource;
+
+ }
+
+}
foreach ($event->getResources() as $id => $resource) {
if ($resource['response'] == Kronolith::RESPONSE_DECLINED) {
$r = Kronolith::getDriver('Resource')->getResource($id);
- $declined[] = $r->name;
+ $declined[] = $r->get('name');
}
}
if (count($declined)) {
$menu->add(Horde::applicationUrl('data.php'), _("_Import/Export"), 'data.png', $registry->getImageDir('horde'));
}
- /* Resources */
- $menu->add(Horde::applicationUrl('resources.php'), _("Resources"), 'resource.png');
-
return $menu;
}
{
// Create a new calendar id.
$calendar = 'resource_' . hash('md5', microtime());
- $resource->calendar = $calendar;
+ $resource->set('calendar', $calendar);
$driver = Kronolith::getDriver('Resource');
return $driver->save($resource);
<?php
/**
- * Kronolith resources
+ * Base class for Kronolith resources. Partially presents a Horde_Share_Object
+ * interface.
+ *
*
*/
abstract class Kronolith_Resource_Base
{
+ /**
+ * Instance copy of parameters
+ *
+ * name - Display name of resource.
+ * calendar - The calendar associated with this resource.
+ * category - The category of this resource...an arbitrary label used
+ * to group multiple resources for the resource_group implementation
+ * description -
+ *
+ * @var array
+ */
protected $_params = array();
+
+ /**
+ * Resource's internal id
+ *
+ * @var integer
+ */
protected $_id = '';
+ /**
+ * Const'r
+ *
+ * @param array $params
+ *
+ * @return Kronolith_Resource object
+ */
public function __construct($params = array())
{
if (!empty($params['id'])) {
$this->_id = $params['id'];
}
+ array_merge($params, array('description' => '',
+ 'category' => ''));
$this->_params = $params;
}
/**
+ * Obtain the resource's internal id.
*
- * Properties:
- * name - Display name of resource.
- * calendar - The calendar associated with this resource.
- * category - The category of this resource...an arbitrary label used
- * to group multiple resources for the resource_group implementation
- * properties - any other properties this resource may have?
- * (max capacity of room, size of TV, whatever...)
- * probably just for display, not sure how this would work
- * if we wanted to be able to search since we are implementing these generically.
- * Don't think we want a datatree-style attirbutes table for this.
+ * @return integer The id.
*/
- public function __get($property)
+ public function getId()
{
- if ($property == 'id') {
- return $this->_id;
- }
+ return $this->_id;
+ }
- $property = str_replace('resource_', '', $property);
- if (isset($this->_params[$property])) {
- return $this->_params[$property];
- } else {
- throw new Horde_Exception(sprintf(_("Invalid property, %s, requested in Kronolith_Resource"), $property));
+ /**
+ * Allow setting of the name and category properties.
+ *
+ * @param string $property The property to set
+ * @param mixed $value The value to set to
+ *
+ * @return void
+ */
+ public function set($property, $value)
+ {
+ if (in_array($property, array('name', 'category', 'calendar'))) {
+ $this->_params[$property] = $value;
}
}
/**
* @TODO: need to fine tune this
*
- *
- *
* @param $user
* @param $permission
* @param $restrict
*/
public function get($property)
{
- return $this->{$property};
+ $property = str_replace('resource_', '', $property);
+ return !empty($this->_params[$property]) ? $this->_params[$property] : false;
}
+ /**
+ * Save resource to storage.
+ */
+ public function save()
+ {
+ $d = $this->getDriver();
+ return $d->save($this);
+ }
+ /**
+ * Get a storage driver instance for the resource. For now, just instantiate
+ * it here, in future, probably inject it in the const'r.
+ *
+ * @return Kronolith_Driver_Resource
+ */
+ public function getDriver()
+ {
+ if (!$this->get('calendar')) {
+ return Kronolith::getDriver('Resource');
+ } else {
+ return Kronolith::getDriver('Resource', $this->get('calendar'));
+ }
+ }
/**
- * Should this take an event, or a time range?
+ * Determine if event is free for specified time
*
* @param $startTime
* @param $endTime
public function isFree($event)
{
/* Fetch events. */
- $busy = Kronolith::listEvents($event->start, $event->end, array($this->calendar));
+ $busy = Kronolith::listEvents($event->start, $event->end, array($this->get('calendar')));
if ($busy instanceof PEAR_Error) {
throw new Horde_Exception($busy->getMessage());
}
public function addEvent($event)
{
/* Get a driver for this resource's calendar */
- $driver = Kronolith::getDriver('Resource', $this->calendar);
+ $driver = Kronolith::getDriver('Resource', $this->get('calendar'));
/* Make sure it's not already attached. */
$uid = $event->getUID();
- $existing = $driver->getByUID($uid, array($this->calendar));
+ $existing = $driver->getByUID($uid, array($this->get('calendar')));
if (!($existing instanceof PEAR_Error)) {
/* Already attached, just update */
$existing->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
} else {
/* Create a new event */
$e = $driver->getEvent();
- $e->setCalendar($this->calendar);
+ $e->setCalendar($this->get('calendar'));
$e->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
$e->save();
}
*/
public function removeEvent($event)
{
- $driver = Kronolith::getDriver('Resource', $this->calendar);
- $re = $driver->getByUID($event->getUID(), array($this->calendar));
+ $driver = Kronolith::getDriver('Resource', $this->get('calendar'));
+ $re = $driver->getByUID($event->getUID(), array($this->get('calendar')));
// Event will only be in the calendar if it's been accepted. This error
// should never happen, but put it here as a safeguard for now.
if (!($re instanceof PEAR_Error)) {
*/
public function getFreeBusy($startstamp = null, $endstamp = null, $asObject = false)
{
- $vfb = Kronolith_Freebusy::generate($this->calendar, $startstamp, $endstamp, $asObject);
+ $vfb = Kronolith_Freebusy::generate($this->get('calendar'), $startstamp, $endstamp, $asObject);
$vfb->removeAttribute('ORGANIZER');
- $vfb->setAttribute('ORGANIZER', $this->name);
+ $vfb->setAttribute('ORGANIZER', $this->get('name'));
return $vfb;
}
+++ /dev/null
-<?php
-/**
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- */
-require_once dirname(__FILE__) . '/lib/base.php';
-
-$title = _("Edit resources");
-
-$resources = array();
-$resources = Kronolith::listResources((PERMS_DELETE));
-$display_url_base = Horde::applicationUrl('month.php', true, -1);
-
-require KRONOLITH_TEMPLATES . '/common-header.inc';
-require KRONOLITH_TEMPLATES . '/menu.inc';
-
-?>
-<!-- Break out into template -->
-<div id="page">
-
-<h1 class="header">
- <?php echo _("Resources") ?>
-</h1>
-<?php if (Horde_Auth::isAdmin()): ?>
- <form method="get" action="createresource.php">
- <?php echo Horde_Util::formInput() ?>
- <input type="submit" class="button" value="<?php echo _("Create a new Resource") ?>" />
- </form>
-<?php endif; ?>
-<table summary="<?php echo _("Resource List") ?>" cellspacing="0" id="calendar-list" class="striped sortable">
- <thead>
- <tr>
- <th class="sortdown"><?php echo _("Name") ?></th>
- <th class="calendar-list-url nosort"><?php echo _("Display URL") ?></th>
- </tr>
- </thead>
- <tbody>
-<?php foreach ($resources as $resource): ?>
- <tr>
- <td><?php echo htmlspecialchars($resource->name) ?></td>
- <td><?php $url = Horde_Util::addParameter($display_url_base, 'display_cal', $resource->calendar, false); echo Horde::link($url, _("Click or copy this URL to display this calendar"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '</a>' ?></td>
- </tr>
-<?php endforeach; ?>
-</tbody>
-</table>
-<?php
-/**
- * Show just the beginning and end of long URLs.
- */
-function shorten_url($url, $separator = '...', $first_chunk_length = 35, $last_chunk_length = 15)
-{
- $url_length = strlen($url);
- $max_length = $first_chunk_length + strlen($separator) + $last_chunk_length;
-
- if ($url_length > $max_length) {
- return substr_replace($url, $separator, $first_chunk_length, -$last_chunk_length);
- }
-
- return $url;
-}
-/* Test creating a new resource */
-//$new = array('name' => _("Another Big Meeting Room"),
-// 'category' => 'conference rooms');
-//
-//$resource = new Kronolith_Resource_Single($new);
-//$results = Kronolith::addResource($resource);
-//var_dump($results);
-?>
-</div>
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * Copyright 2009 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>
+ */
+
+@define('KRONOLITH_BASE', dirname(dirname(__FILE__)));
+require_once KRONOLITH_BASE . '/lib/base.php';
+require_once KRONOLITH_BASE . '/lib/Forms/CreateResource.php';
+
+// Exit if this isn't an authenticated, administrative user
+if (!Horde_Auth::isAdmin()) {
+ header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true));
+ exit;
+}
+
+$vars = Horde_Variables::getDefaultVariables();
+$form = new Kronolith_CreateResourceForm($vars);
+
+// Execute if the form is valid.
+if ($form->validate($vars)) {
+ $result = $form->execute();
+ if (is_a($result, 'PEAR_Error')) {
+ $notification->push($result, 'horde.error');
+ } else {
+ $notification->push(sprintf(_("The calendar \"%s\" has been created."), $vars->get('name')), 'horde.success');
+ }
+
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+}
+
+$title = $form->getTitle();
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+echo $form->renderActive($form->getRenderer(), $vars, 'create.php', 'post');
+require $registry->get('templates', 'horde') . '/common-footer.inc';
--- /dev/null
+<?php
+/**
+ * Copyright 2002-2009 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>
+ */
+
+require_once dirname(__FILE__) . '/../lib/base.php';
+require_once KRONOLITH_BASE . '/lib/Forms/DeleteResource.php';
+
+// Exit if this isn't an authenticated administrative user.
+if (!Horde_Auth::isAdmin()) {
+ header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true));
+ exit;
+}
+
+$vars = Horde_Variables::getDefaultVariables();
+$d = Kronolith::getDriver('Resource');
+$resource = $d->getResource($vars->get('c'));
+
+if ($resource instanceof PEAR_Error) {
+ $notification->push($resoruce, 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), PERMS_DELETE)) {
+ $notification->push(_("You are not allowed to delete this resource."), 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+}
+
+$form = new Kronolith_DeleteResourceForm($vars, $resource);
+
+// Execute if the form is valid (must pass with POST variables only).
+if ($form->validate(new Horde_Variables($_POST))) {
+ $result = $form->execute();
+ if ($result instanceof PEAR_Error) {
+ $notification->push($result, 'horde.error');
+ } elseif ($result) {
+ $notification->push(sprintf(_("The resource \"%s\" has been deleted."), $resource->get('name')), 'horde.success');
+ }
+
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+}
+
+$title = $form->getTitle();
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+echo $form->renderActive($form->getRenderer(), $vars, 'delete.php', 'post');
+require $registry->get('templates', 'horde') . '/common-footer.inc';
--- /dev/null
+<?php
+/**
+ * Copyright 2002-2009 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>
+ */
+
+require_once dirname(__FILE__) . '/../lib/base.php';
+require_once KRONOLITH_BASE . '/lib/Forms/EditResource.php';
+
+// Exit if this isn't an authenticated administrative user.
+if (!Horde_Auth::isAdmin()) {
+ header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php', true));
+ exit;
+}
+
+$vars = Horde_Variables::getDefaultVariables();
+$d = Kronolith::getDriver('Resource');
+$resource = $d->getResource($vars->get('c'));
+
+if ($resource instanceof PEAR_Error) {
+ $notification->push($resource, 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+} elseif (!$resource->hasPermission(Horde_Auth::getAuth(), PERMS_EDIT)) {
+ $notification->push(_("You are not allowed to change this resource."), 'horde.error');
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+}
+$form = new Kronolith_EditResourceForm($vars, $resource);
+
+// Execute if the form is valid.
+if ($form->validate($vars)) {
+ $original_name = $resource->get('name');
+ $result = $form->execute();
+ if ($result instanceof PEAR_Error) {
+ $notification->push($result, 'horde.error');
+ } else {
+ if ($result->get('name') != $original_name) {
+ $notification->push(sprintf(_("The resource \"%s\" has been renamed to \"%s\"."), $original_name, $resource->get('name')), 'horde.success');
+ } else {
+ $notification->push(sprintf(_("The resource \"%s\" has been saved."), $original_name), 'horde.success');
+ }
+ }
+
+ header('Location: ' . Horde::applicationUrl('resources/', true));
+ exit;
+}
+
+$vars->set('name', $resource->get('name'));
+$vars->set('description', $resource->get('description'));
+$vars->set('category', $resource->get('category'));
+
+$title = $form->getTitle();
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+echo $form->renderActive($form->getRenderer(), $vars, 'edit.php', 'post');
+require $registry->get('templates', 'horde') . '/common-footer.inc';
--- /dev/null
+<?php
+/**
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ */
+require_once dirname(__FILE__) . '/../lib/base.php';
+
+$title = _("Edit resources");
+
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+require KRONOLITH_TEMPLATES . '/menu.inc';
+
+// Exit if this isn't an authenticated user.
+if (!Horde_Auth::getAuth()) {
+ header('Location: ' . Horde::applicationUrl($prefs->getValue('defaultview') . '.php'));
+ exit;
+}
+$edit_url_base = Horde::applicationUrl('resources/edit.php');
+$edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('horde'));
+$resources = Kronolith::listResources();
+$display_url_base = Horde::applicationUrl('month.php', true, -1);
+$delete_url_base = Horde::applicationUrl('resources/delete.php');
+$delete_img = Horde::img('delete.png', _("Delete"), null, $registry->getImageDir('horde'));
+
+?>
+<script type="text/javascript">
+function performAction(action, rid)
+{
+ document.resourceform.actionId.value = action;
+ document.resourceform.actionValue.value = rid;
+ document.resourceform.submit();
+ return false;
+}
+</script>
+<!-- Break out into template -->
+<div id="page">
+
+<h1 class="header">
+ <?php echo _("Resources") ?>
+</h1>
+<?php if ($isAdmin = Horde_Auth::isAdmin()): ?>
+ <form method="get" action="create.php">
+ <?php echo Horde_Util::formInput() ?>
+ <input type="submit" class="button" value="<?php echo _("Create a new Resource") ?>" />
+ </form>
+<?php endif ?>
+<table summary="<?php echo _("Resource List") ?>" cellspacing="0" id="calendar-list" class="striped sortable">
+ <thead>
+ <tr>
+ <th> </th>
+ <th class="sortdown"><?php echo _("Name") ?></th>
+ <th class="calendar-list-url nosort"><?php echo _("Display URL") ?></th>
+ </tr>
+ </thead>
+ <tbody>
+<?php foreach ($resources as $resource): ?>
+ <tr>
+ <?php if ($isAdmin):?>
+ <td>
+ <?php echo Horde::link(Horde_Util::addParameter($delete_url_base, 'c', $resource->getId()), _("Delete")) . $delete_img . '</a>' ?>
+ <?php echo Horde::link(Horde_Util::addParameter($edit_url_base, 'c', $resource->getId()), _("Edit")) . $edit_img . '</a>' ?>
+ <?php else:?>
+ <td> </td>
+ <?php endif;?>
+ <td><?php echo htmlspecialchars($resource->get('name')) ?></td>
+ <td><?php $url = Horde_Util::addParameter($display_url_base, 'display_cal', $resource->get('calendar'), false); echo Horde::link($url, _("Click or copy this URL to display this calendar"), '', '_blank') . htmlspecialchars(shorten_url($url)) . '</a>' ?></td>
+ </tr>
+<?php endforeach; ?>
+</tbody>
+</table>
+
+<?php
+/**
+ * Show just the beginning and end of long URLs.
+ */
+function shorten_url($url, $separator = '...', $first_chunk_length = 35, $last_chunk_length = 15)
+{
+ $url_length = strlen($url);
+ $max_length = $first_chunk_length + strlen($separator) + $last_chunk_length;
+
+ if ($url_length > $max_length) {
+ return substr_replace($url, $separator, $first_chunk_length, -$last_chunk_length);
+ }
+
+ return $url;
+}
+/* Test creating a new resource */
+//$new = array('name' => _("Another Big Meeting Room"),
+// 'category' => 'conference rooms');
+//
+//$resource = new Kronolith_Resource_Single($new);
+//$results = Kronolith::addResource($resource);
+//var_dump($results);
+?>
+</div>
\ No newline at end of file
<select id="resourceselect" name="resourceselect">
<option value="0"><?php echo _("Select resource")?></option>
<?php foreach ($allResources as $resource):?>
- <?php printf('<option value="%s">%s</option>', $resource->id, $resource->name) ?>
+ <?php printf('<option value="%s">%s</option>', $resource->getId(), $resource->get('name')) ?>
<?php endforeach;?>
</select>
</td>
<div>
<input type="submit" class="button" name="addNew" value="<?php echo htmlspecialchars(_("Save")) ?>" />
<input type="submit" class="button" name="addNewClose" value="<?php echo htmlspecialchars(_("Save and Finish")) ?>" />
- <?php if (!empty($attendees)): ?><input type="submit" class="button" name="clearAll" value="<?php echo htmlspecialchars(_("Clear all attendees")) ?>" /><?php endif; ?>
+ <?php if (!empty($attendees)): ?><input type="submit" class="button" name="clearAll" value="<?php echo htmlspecialchars(_("Clear all")) ?>" /><?php endif; ?>
</div>
<br />
<?php endforeach; ?>
</tbody>
</table>
-
-<?php if (count($resources)): ?>
-<h1 class="smallheader">Resources</div>
-<table summary="<?php echo _("Resource Calendars") ?>" cellspacing="0" class="striped sortable">
- <thead>
- <th class="sortdown"><?php echo _("Resource Name") ?></th>
- <th class="calendar-list-url nosort"><?php echo _("Display URL") ?></th>
- <th class="calendar-list-icon nosort" colspan="<?php echo empty($conf['share']['no_sharing']) ? 3 : 2 ?>"> </th>
- </thead>
-<?php foreach ($resources as $resource): ?>
-<?php var_dump($resource);?>
- <tr>
- <td><?php echo $resource->name ?></td>
- <td><?php //echo $resource->url ?></td>
- <td><?php echo Horde::link(Horde_Util::addParameter($edit_url_base, 'c', $resource->get('calendar')), _("Edit")) . $edit_img . '</a>' ?></td>
- </tr>
-<?php endforeach; ?>
-</table>
-<?php endif; ?>
-
</div>
$driver = Kronolith::getDriver('Resource');
foreach ($GLOBALS['display_resource_calendars'] as $c) {
$rc = $driver->getResource($driver->getResourceIdByCalendar($c));
- $calendar_names[] = htmlspecialchars($rc->name);
+ $calendar_names[] = htmlspecialchars($rc->get('name'));
}
}
?>
$rd = Kronolith::getDriver('Resource');
$rc = $rd->getResource($rd->getResourceIdByCalendar($cal));
printf('<option value="%s"%s>%s</option>',
- htmlspecialchars($cal), '', $rc->name) . "\n";
+ htmlspecialchars($cal), '', $rc->get('name')) . "\n";
}
} else {
// Normal view
<?php if (Horde_Auth::getAuth()): ?>
<p>
- <a href="<?php echo Horde::applicationUrl('calendars/') ?>"><?php echo _("[Manage Calendars]") ?></a>
+ <a href="<?php echo Horde::applicationUrl('calendars/') ?>"><?php echo _("[Manage Calendars]") ?></a><br />
+ <a href="<?php echo Horde::applicationUrl('resources/')?>"><?php echo (Horde_Auth::isAdmin() ? _("[Manage Resource Calendars]") : _("[Resource Calendars]"))?></a>
</p>
<?php endif; ?>