Add functionality to associate devices with an extension. Make the destinations...
authorBen Klang <ben@alkaloid.net>
Sat, 26 Dec 2009 23:51:02 +0000 (23:51 +0000)
committerBen Klang <ben@alkaloid.net>
Sat, 26 Dec 2009 23:51:02 +0000 (23:51 +0000)
git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@505 06cd67b6-e706-0410-b29e-9de616bca6e9

devices.php
lib/Driver/Ldap.php
lib/Driver/Sql.php
lib/Forms/DeviceForm.php
templates/extensions/list.inc
themes/graphics/telephone-pole.png [new file with mode: 0644]
themes/graphics/user.png [new file with mode: 0644]

index a34aa62..cac6319 100644 (file)
@@ -23,13 +23,16 @@ $title = _("Devices: ");
 
 switch ($action) {
     case 'save':
-        print_r($vars);
         $Form = new DeviceDetailsForm($vars);
-        print_r($Form);
+
         // Show the list if the save was successful, otherwise back to edit.
-        $success = ($Form->isSubmitted() && $Form->isValid());
-        if ($success) {
-            $notification->push(_("Device settings saved."));
+        if ($Form->isSubmitted() && $Form->isValid()) {
+            try {
+                $shout_devices->saveDevice($Form->getVars());
+                $notification->push(_("Device settings saved."));
+            } catch (Exception $e) {
+                $notification->push($e);
+            }
             $action = 'list';
             break;
         } else {
@@ -53,12 +56,12 @@ switch ($action) {
         $Form->open($RENDERER, $vars, Horde::applicationUrl('devices.php'), 'post');
 
         break;
-    
+
 
     case 'delete':
         $notification->push("Not supported.");
         break;
+
     case 'list':
     default:
         $action = 'list';
index 36f6d87..e268caf 100644 (file)
@@ -95,7 +95,9 @@ class Shout_Driver_Ldap extends Shout_Driver
             'AstVoicemailMailbox',
             'AstVoicemailPassword',
             'AstVoicemailOptions',
-            'AstVoicemailPager'
+            'AstVoicemailPager',
+            'telephoneNumber',
+            'AstExtension'
         );
 
         $search = ldap_search($this->_LDAP, $this->_params['basedn'], $filter, $attributes);
@@ -120,7 +122,10 @@ class Shout_Driver_Ldap extends Shout_Driver
 
             $j = 0;
             $entries[$context][$extension]['mailboxopts'] = array();
-            while ($j < @$res[$i]['astvoicemailoptions']['count']) {
+            if (empty($res[$i]['astvoicemailoptions']['count'])) {
+                $res[$i]['astvoicemailoptions']['count'] = -1;
+            }
+            while ($j < $res[$i]['astvoicemailoptions']['count']) {
                 $entries[$context][$extension]['mailboxopts'][] =
                     $res[$i]['astvoicemailoptions'][$j];
                 $j++;
@@ -132,12 +137,35 @@ class Shout_Driver_Ldap extends Shout_Driver
             $entries[$context][$extension]['name'] =
                 $res[$i]['cn'][0];
 
-            @$entries[$context][$extension]['email'] =
+            $entries[$context][$extension]['email'] =
                 $res[$i]['mail'][0];
 
-            @$entries[$context][$extension]['pageremail'] =
+            $entries[$context][$extension]['pageremail'] =
                 $res[$i]['astvoicemailpager'][0];
 
+            $j = 0;
+            $entries[$context][$extension]['numbers'] = array();
+            if (empty($res[$i]['telephonenumber']['count'])) {
+                $res[$i]['telephonenumber']['count'] = -1;
+            }
+            while ($j < $res[$i]['telephonenumber']['count']) {
+                $entries[$context][$extension]['numbers'][] =
+                    $res[$i]['telephonenumber'][$j];
+                $j++;
+            }
+
+            $j = 0;
+            $entries[$context][$extension]['devices'] = array();
+            if (empty($res[$i]['astextension']['count'])) {
+                $res[$i]['astextension']['count'] = -1;
+            }
+            while ($j < $res[$i]['astextension']['count']) {
+                $entries[$context][$extension]['devices'][] =
+                    $res[$i]['astextension'][$j];
+                $j++;
+            }
+
+
             $i++;
 
         }
index 3e34308..8eaac44 100644 (file)
@@ -110,6 +110,35 @@ class Shout_Driver_Sql extends Shout_Driver
     }
 
     /**
+     * Save a device (add or edit) to the backend.
+     *
+     * @param string $context  The context in which this device is valid
+     * @param array $info      Array of device details
+     */
+    public function saveDevice($context, $info)
+    {
+        // See getDevices() for an explanation of these conversions
+        $info['alias'] = $info['name'];
+        $info['mailbox'] = $info['mailbox'] . '@' . $context;
+
+        if ($info['devid']) {
+            // This is an edit
+            $info['name'] = $info['devid'];
+            $sql = 'UPDATE %s SET ';
+        } else {
+            // This is an add.  Generate a new unique ID and secret
+            $devid = $context . uniqid();
+            $secret = md5(uniqid(mt_rand));
+            $sql = 'INSERT INTO %s (name, accountcode, callerid, mailbox, ' .
+                   'secret, alias, canreinvite, nat, type) ' .
+                   ' VALUES (?, ?, ?, ?, ?, ?, "no", "yes", "peer")';
+
+        }
+
+
+    }
+
+    /**
      * Get a list of users valid for the contexts
      *
      * @param string $context Context on which to search
index 04a75b1..951738c 100644 (file)
@@ -14,22 +14,26 @@ class DeviceDetailsForm extends Horde_Form {
 
     function __construct(&$vars)
     {
-        parent::__construct($vars);
         global $shout_extensions;
-        $context = $vars->get('context');
+
         if ($vars->exists('devid')) {
             $formtitle = "Edit Device";
             $devid = $vars->get('devid');
+            $edit = true;
         } else {
             $formtitle = "Add Device";
+            $edit = false;
         }
 
         parent::__construct($vars, _("$formtitle - Context: $context"));
         $this->addHidden('', 'action', 'text', true);
         $vars->set('action', 'save');
-        $this->addHidden('', 'devid', 'int', true);
-        $this->addVariable(_("Device Name"), 'name', 'text', true);
-        $this->addVariable(_("Mailbox"), 'mailbox', 'int', true);
+        if ($edit) {
+            $this->addHidden('', 'devid', 'text', true);
+
+        }
+        $this->addVariable(_("Device Name"), 'name', 'text', false);
+        $this->addVariable(_("Mailbox"), 'mailbox', 'int', false);
         $this->addVariable(_("CallerID"), 'callerid', 'text', false);
 
 
index 907506f..4b00d15 100644 (file)
             </td>
             <td style="width: 35%;">
                 <?php echo Horde::link($editurl); echo $info['name']; ?></a>
+                <?php
+                foreach ($info['devices'] as $device) {
+                    echo Horde::img('shout.png');
+                }
+                foreach ($info['numbers'] as $number) {
+                    echo Horde::img('telephone-pole.png');
+                }
+                ?>
             </td>
             <td style="width: 45%">
                 <?php echo $info['email']; ?>
diff --git a/themes/graphics/telephone-pole.png b/themes/graphics/telephone-pole.png
new file mode 100644 (file)
index 0000000..7187c95
Binary files /dev/null and b/themes/graphics/telephone-pole.png differ
diff --git a/themes/graphics/user.png b/themes/graphics/user.png
new file mode 100644 (file)
index 0000000..8b2c994
Binary files /dev/null and b/themes/graphics/user.png differ