Overview

Packages

  • None
  • Shout

Classes

  • AccountDeleteForm
  • ConferenceDeleteForm
  • DeviceDeleteForm
  • DeviceMenuForm
  • ExtensionDeleteForm
  • NumberDeleteForm
  • Shout_Application
  • Shout_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Copyright 2005-2010 Alkaloid Networks LLC (http://projects.alkaloid.net)
  4:  *
  5:  * See the enclosed file LICENSE for license information (BSD). If you
  6:  * did not receive this file, see
  7:  * http://www.opensource.org/licenses/bsd-license.php.
  8:  *
  9:  * @package Shout
 10:  */
 11: 
 12: class DeviceDetailsForm extends Horde_Form {
 13: 
 14:     function __construct(&$vars)
 15:     {
 16:         if ($vars->exists('devid')) {
 17:             $formtitle = "Edit Device";
 18:             $devid = $vars->get('devid');
 19:             $edit = true;
 20:         } else {
 21:             $formtitle = "Add Device";
 22:             $edit = false;
 23:         }
 24: 
 25:         $accountname = $GLOBALS['session']->get('shout', 'curaccount_name');
 26:         $title = sprintf(_("$formtitle - Account: %s"), $accountname);
 27:         parent::__construct($vars, $title);
 28: 
 29:         $this->addHidden('', 'action', 'text', true);
 30:         if ($edit) {
 31:             $this->addHidden('', 'devid', 'text', true);
 32: 
 33:         }
 34:         $this->addVariable(_("Device Name"), 'name', 'text', true);
 35:         $this->addVariable(_("Mailbox"), 'mailbox', 'int', false);
 36:         $this->addVariable(_("CallerID"), 'callerid', 'text', false);
 37:         $this->addVariable(_("Reset authentication token?"), 'genauthtok',
 38:                            'boolean', false, false);//,
 39:                           // _("If checked, the system will generate new device ID and password.  The associated device will need to be reconfigured with the new information."));
 40: 
 41:         return true;
 42:     }
 43: 
 44:     public function execute()
 45:     {
 46:         $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
 47: 
 48:         $action = $this->_vars->get('action');
 49:         $account = $this->_vars->get('account');
 50:         $devid = $this->_vars->get('devid');
 51: 
 52:         // For safety, we force the device ID and password rather than rely
 53:         // on the form to pass them around.
 54:         if ($action == 'add') {
 55:             // The device ID should be empty so it can be generated.
 56:             $devid = null;
 57:             $password = null;
 58:         } else { // $action must be 'edit'
 59:             $devices = $shout->devices->getDevices($account);
 60:             if (!isset($devices[$devid])) {
 61:                 // The device requested doesn't already exist.  This can't
 62:                 // be a valid edit.
 63:                 throw new Shout_Exception(_("That device does not exist."),
 64:                                             'horde.error');
 65:             } else {
 66:                 $password = $devices[$devid]['password'];
 67:             }
 68:         }
 69: 
 70:         $callerid = $this->_vars->get('callerid');
 71:         $name = $this->_vars->get('name');
 72:         $mailbox = $this->_vars->get('mailbox');
 73: 
 74:         // Default the caller id to something sane.
 75:         if (empty($callerid)) {
 76:             $callerid = sprintf('"%s" <%s>', $name, $mailbox);
 77:         }
 78: 
 79:         $details = array(
 80:             'devid' => $devid,
 81:             'name' => $this->_vars->get('name'),
 82:             'mailbox' => $mailbox,
 83:             'callerid' => $callerid,
 84:             'genauthtok' => $this->_vars->get('genauthtok'),
 85:             'password' => $password,
 86:         );
 87: 
 88:         $shout->devices->saveDevice($account, $devid, $details);
 89:     }
 90: 
 91: }
 92: 
 93: class DeviceDeleteForm extends Horde_Form
 94: {
 95:     function __construct(&$vars)
 96:     {
 97:         $devid = $vars->get('devid');
 98:         $account = $vars->get('account');
 99: 
100:         $title = _("Delete Device %s - Account: %s");
101:         $account_config = $GLOBALS['session']->get('shout', 'accounts/' . $account);
102:         $title = sprintf($title, $devid, $account_config['name']);
103:         parent::__construct($vars, $title);
104: 
105:         $this->addHidden('', 'account', 'text', true);
106:         $this->addHidden('', 'devid', 'text', true);
107:         $this->addHidden('', 'action', 'text', true);
108:         $this->setButtons(array(_("Delete"), _("Cancel")));
109:     }
110: 
111:     function execute()
112:     {
113:         $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
114:         $account = $this->_vars->get('account');
115:         $devid = $this->_vars->get('devid');
116:         $shout->devices->deleteDevice($account, $devid);
117:     }
118: }
119: 
API documentation generated by ApiGen