If response type is Kronolith_Resource::RESPONSETYPE_AUTO then use the start and end datetime
values that are now passed from the event form to determine if the resource is free.
Still need to figure out how to (efficiently) pass the datetime values to take into account
AM/PM. Probably break out the javascript from the onClick handler into it's function and
provide logic to check the am/pm fields? Is there an easier/prettier way?
$response = Kronolith::RESPONSE_ACCEPTED;
} elseif ($type == Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE) {
$response = Kronolith::RESPONSE_DECLINED;
+ } elseif ($type == Kronolith_Resource::RESPONSETYPE_AUTO) {
+ // Try to figure out the expected response
+ $date = new Horde_Date(Horde_Util::getFormData('date'));
+ $end = new Horde_Date(Horde_Util::getFormData('enddate'));
+ if ($resource->isFree(array('start' => $date, 'end' => $end))) {
+ $response = Kronolith::RESPONSE_ACCEPTED;
+ } else {
+ $response = Kronolith::RESPONSE_DECLINED;
+ }
} else {
$response = Kronolith::RESPONSE_NONE;
}
* Determine if the resource is free during the time period for the
* supplied event.
*
- * @param Kronolith_Event $event
+ * @param mixed $event Either a Kronolith_Event object or an array
+ * containing start and end times.
+ *
*
* @return boolean
*/
public function isFree($event)
{
+ if (is_array($event)) {
+ $start = $event['start'];
+ $end = $event['end'];
+ } else {
+ $start = $event->start;
+ $end = $event->end;
+ }
+
/* Fetch events. */
- $busy = Kronolith::listEvents($event->start, $event->end, array($this->get('calendar')));
+ $busy = Kronolith::listEvents($start, $end, array($this->get('calendar')));
if ($busy instanceof PEAR_Error) {
throw new Horde_Exception($busy->getMessage());
}
/* Check for conflicts, ignoring the conflict if it's for the
* same event that is passed. */
- $uid = $event->getUID();
+ if (!is_array($event)) {
+ $uid = $event->getUID();
+ } else {
+ $uid = 0;
+ }
$conflicts = 0;
foreach ($busy as $events) {
foreach ($events as $e) {
$e->hasStatus(Kronolith::STATUS_FREE)) &&
$e->getUID() !== $uid) {
- if (!($e->start->compareDateTime($event->end) >= 1 ||
- $e->end->compareDateTime($event->start) <= -1)) {
+ if (!($e->start->compareDateTime($end) >= 1 ||
+ $e->end->compareDateTime($start) <= -1)) {
$conflicts++;
}
<input type="hidden" name="actionID" value="add" />
<input type="hidden" name="actionValue" value="" />
<input type="hidden" name="view" value="<?php echo htmlspecialchars($view) ?>" />
-<input type="hidden" name="date" value="<?php echo $date->dateString() ?>" />
+<input type="hidden" name="date" value="<?php echo $date->dateString() . sprintf("%02d%02d00", $date->hour, $date->min) ?>" />
+<input type="hidden" name="enddate" value=<?php echo $end->dateString() . sprintf("%02d%02d00", $end->hour, $end->min) ?>" />
<h1 class="header"><?php echo htmlspecialchars($title) ?></h1>
<tr>
<td></td>
<td colspan="4">
- <?php echo Horde::link(Horde::applicationUrl('attendees.php'), '', 'button', '_blank', 'var date = (\'000\' + $F(\'start_year\')).slice(-4) + (\'0\' + $F(\'start_month\')).slice(-2) + (\'0\' + $F(\'start_day\')).slice(-2); this.href += (this.href.indexOf(\'?\') == -1 ? \'?\' : \'&\') + \'date=\' + date;Horde.popup({ url: this.href });return false;') . _("Edit Attendees and Resources") . '</a>' ?>
+ <?php echo Horde::link(Horde::applicationUrl('attendees.php'), '', 'button', '_blank', 'var date = (\'000\' + $F(\'start_year\')).slice(-4) + (\'0\' + $F(\'start_month\')).slice(-2) + (\'0\' + $F(\'start_day\')).slice(-2) + (\'0\' + $(\'start_hour\').value).slice(-2) + (\'0\' + $(\'start_min\').value).slice(-2) + \'00\';var enddate = (\'000\' + $F(\'end_year\')).slice(-4) + (\'0\' + $F(\'end_month\')).slice(-2) + (\'0\' + $F(\'end_day\')).slice(-2) + (\'0\' + $(\'end_hour\').value).slice(-2) + (\'0\' + $(\'end_min\').value).slice(-2) + \'00\'; this.href += (this.href.indexOf(\'?\') == -1 ? \'?\' : \'&\') + \'date=\' + date + \'&enddate=\' + enddate;Horde.popup({ url: this.href });return false;') . _("Edit Attendees and Resources") . '</a>' ?>
</td>
</tr>
</tbody>