From: Ben Klang Date: Sat, 26 Dec 2009 23:51:02 +0000 (+0000) Subject: Add functionality to associate devices with an extension. Make the destinations... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=affae3b4fbbc9bb9a4d3f7684b4123d599c16514;p=horde.git 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 --- 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 000000000..7187c95c2 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 index 000000000..8b2c9946c Binary files /dev/null and b/themes/graphics/user.png differ