1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 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:
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:
53:
54: if ($action == 'add') {
55:
56: $devid = null;
57: $password = null;
58: } else {
59: $devices = $shout->devices->getDevices($account);
60: if (!isset($devices[$devid])) {
61:
62:
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:
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: