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 {
$Form->open($RENDERER, $vars, Horde::applicationUrl('devices.php'), 'post');
break;
-
+
case 'delete':
$notification->push("Not supported.");
break;
-
+
case 'list':
default:
$action = 'list';
'AstVoicemailMailbox',
'AstVoicemailPassword',
'AstVoicemailOptions',
- 'AstVoicemailPager'
+ 'AstVoicemailPager',
+ 'telephoneNumber',
+ 'AstExtension'
);
$search = ldap_search($this->_LDAP, $this->_params['basedn'], $filter, $attributes);
$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++;
$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++;
}
}
/**
+ * 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
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);
</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']; ?>