Initial adding of resource to an event from the attendees page.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 10 Sep 2009 14:28:57 +0000 (10:28 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:53 +0000 (16:53 -0400)
kronolith/attendees.php
kronolith/templates/attendees/attendees.inc

index 5ab189b..50f3d8c 100644 (file)
@@ -21,7 +21,7 @@ $resources = (isset($_SESSION['kronolith']['resources']) &&
               is_array($_SESSION['kronolith']['resources']))
     ? $_SESSION['kronolith']['resources']
     : array();
-$editResource = null;
+$allResources = Kronolith::listResources();
 
 // Get the action ID and value. This specifies what action the user initiated.
 $actionID = Horde_Util::getFormData('actionID');
@@ -33,76 +33,86 @@ $actionValue = Horde_Util::getFormData('actionValue');
 // Perform the specified action, if there is one.
 switch ($actionID) {
 case 'add':
-    $parser = new Mail_RFC822;
-    // Add new attendees. Multiple attendees can be seperated on a single line
-    // by whitespace and/or commas.
+    // Add new attendees and/or resources. Multiple attendees can be seperated
+    // on a single line by whitespace and/or commas. Resources are added one
+    // at a time (at least for now).
     $newAttendees = trim(Horde_Util::getFormData('newAttendees'));
-    if (empty($newAttendees)) {
-        if (Horde_Util::getFormData('addNewClose')) {
-            Horde_Util::closeWindowJS();
-            exit;
-        }
-        break;
-    }
+    $newResource = trim(Horde_Util::getFormData('resourceselect'));
 
-    foreach (Horde_Mime_Address::explode($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;
-        }
+    if (!empty($newAttendees)) {
+        $parser = new Mail_RFC822;
+        foreach (Horde_Mime_Address::explode($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);
 
-        // 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,
-                );
+            // 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;
             }
 
-            // Build a full email address again and validate it.
-            $name = empty($newAttendeeParsedPart->personal)
-                ? ''
-                : $newAttendeeParsedPart->personal;
-
-            try {
-                $newAttendeeParsedPartNew = Horde_Mime::encodeAddress(Horde_Mime_Address::writeAddress($newAttendeeParsedPart->mailbox, $newAttendeeParsedPart->host, $name));
-                $newAttendeeParsedPartValidated = $parser->parseAddressList($newAttendeeParsedPartNew, '', null, true);
-
-                $email = $newAttendeeParsedPart->mailbox . '@'
-                    . $newAttendeeParsedPart->host;
-                // Avoid overwriting existing attendees with the default
-                // values.
-                if (!isset($attendees[$email]))
-                    $attendees[$email] = array(
+            // 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'       => $name,
+                        'name'       => $newAttendee,
                     );
-            } catch (Horde_Mime_Exception $e) {
-                $notification->push($e, 'horde.error');
+                    continue;
+                }
+
+                // Build a full email address again and validate it.
+                $name = empty($newAttendeeParsedPart->personal)
+                    ? ''
+                    : $newAttendeeParsedPart->personal;
+
+                try {
+                    $newAttendeeParsedPartNew = Horde_Mime::encodeAddress(Horde_Mime_Address::writeAddress($newAttendeeParsedPart->mailbox, $newAttendeeParsedPart->host, $name));
+                    $newAttendeeParsedPartValidated = $parser->parseAddressList($newAttendeeParsedPartNew, '', null, true);
+
+                    $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,
+                        );
+                } catch (Horde_Mime_Exception $e) {
+                    $notification->push($e, 'horde.error');
+                }
             }
         }
+
+        $_SESSION['kronolith']['attendees'] = $attendees;
     }
 
-    $_SESSION['kronolith']['attendees'] = $attendees;
+    // Any new resources?
+    if (!empty($newResource)) {
+        $resource = Kronolith::getDriver('Resource')->getResource($newResource);
+
+        $resources[$newResource] = array(
+            'attendance' => Kronolith::PART_IGNORE,
+            'response'   => Kronolith::RESPONSE_NONE,
+            'name'       => $resource->name,
+        );
+
+        $_SESSION['kronolith']['resources'] = $resources;
+    }
 
     if (Horde_Util::getFormData('addNewClose')) {
         Horde_Util::closeWindowJS();
@@ -135,6 +145,14 @@ case 'remove':
     }
     break;
 
+case 'removeResource':
+    // Remove the specified resource
+    if (isset($resources[$actionValue])) {
+        unset($resources[$actionValue]);
+        $_SESSION['kronolith']['resources'] = $resources;
+    }
+    break;
+
 case 'changeatt':
     // Change the attendance status of an attendee
     list($partval, $partname) = explode(' ', $actionValue, 2);
index d347bd8..2daac5d 100644 (file)
@@ -89,7 +89,7 @@ function switchDateView(view, date)
  <tr><td colspan="4"><em><?php echo _("No attendees") ?></em></td></tr>
 <?php else: foreach ($resources as $id => $resource): ?>
  <tr>
-  <td class="nowrap"><?php echo Horde::img('delete.png', '', null, $registry->getImageDir('horde')) . ' ' . Horde::img('edit.png', '', null, $registry->getImageDir('horde')) . ' ' ?></td>
+  <td class="nowrap"><?php echo Horde::link('#', sprintf(_("Remove %s"), $resource['name']), '', '', "performAction('removeResource', " . $id . "); return false;") . Horde::img('delete.png', '', null, $registry->getImageDir('horde')) ?></a></td>
   <td><?php echo htmlspecialchars($resource['name']) ?></td>
   <td colspan="2">
     <?php switch ($resource['response']) {
@@ -99,6 +99,8 @@ function switchDateView(view, date)
         case Kronolith::RESPONSE_DECLINED:
             echo _("Declined");
             break;
+        default:
+            echo _("Pending");
     } ?>
   </td>
  </tr>
@@ -121,9 +123,19 @@ function switchDateView(view, date)
   </td>
 <?php if ($registry->hasMethod('contacts/search')): ?>
   <td align="center"><?php echo Horde::link('#', '', 'widget', null, 'window.open(\'' . Horde::applicationUrl('contacts.php') . '\', \'contacts\', \'toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=550,height=270,left=100,top=100\'); return false;') . Horde::img('addressbook_browse.png') . '<br />' . _("Address Book") . '</a>' ?></td>
-  <td width="100%"><?php echo _("resources link") ?></td>
 <?php endif; ?>
  </tr>
+ <tr>
+  <td class="rightAlign"><strong><?php echo _("Add resource")?></strong></td>
+  <td width="100%">
+    <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 endforeach;?>
+    </select>
+  </td>
+ </tr>
 </table>
 
 <br />