From affae3b4fbbc9bb9a4d3f7684b4123d599c16514 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Sat, 26 Dec 2009 23:51:02 +0000 Subject: [PATCH] Add functionality to associate devices with an extension. Make the destinations appear as icons in the extension view. git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@505 06cd67b6-e706-0410-b29e-9de616bca6e9 --- devices.php | 17 ++++++++++------- lib/Driver/Ldap.php | 36 ++++++++++++++++++++++++++++++++---- lib/Driver/Sql.php | 29 +++++++++++++++++++++++++++++ lib/Forms/DeviceForm.php | 14 +++++++++----- templates/extensions/list.inc | 8 ++++++++ themes/graphics/telephone-pole.png | Bin 0 -> 695 bytes themes/graphics/user.png | Bin 0 -> 797 bytes 7 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 themes/graphics/telephone-pole.png create mode 100644 themes/graphics/user.png diff --git a/devices.php b/devices.php index a34aa620a..cac6319b0 100644 --- a/devices.php +++ b/devices.php @@ -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'; diff --git a/lib/Driver/Ldap.php b/lib/Driver/Ldap.php index 36f6d87b3..e268caf7e 100644 --- a/lib/Driver/Ldap.php +++ b/lib/Driver/Ldap.php @@ -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++; } diff --git a/lib/Driver/Sql.php b/lib/Driver/Sql.php index 3e3430836..8eaac441b 100644 --- a/lib/Driver/Sql.php +++ b/lib/Driver/Sql.php @@ -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 diff --git a/lib/Forms/DeviceForm.php b/lib/Forms/DeviceForm.php index 04a75b164..951738cc7 100644 --- a/lib/Forms/DeviceForm.php +++ b/lib/Forms/DeviceForm.php @@ -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); diff --git a/templates/extensions/list.inc b/templates/extensions/list.inc index 907506f79..4b00d15aa 100644 --- a/templates/extensions/list.inc +++ b/templates/extensions/list.inc @@ -28,6 +28,14 @@ + diff --git a/themes/graphics/telephone-pole.png b/themes/graphics/telephone-pole.png new file mode 100644 index 0000000000000000000000000000000000000000..7187c95c29080ba30d32241dcb88c2380430982d GIT binary patch literal 695 zcmV;o0!aOdP)Px#24YJ`L;&yrwE!tFP*1f0000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iXi7 z7ZC!d4@z_Z001I%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