1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: class AccountDetailsForm extends Horde_Form {
16:
17: 18: 19: 20: 21: 22:
23: function __construct(&$vars)
24: {
25: $account = $GLOBALS['session']->get('shout', 'curaccount_code');
26: $action = $vars->get('action');
27: if ($action == 'edit') {
28: $formtitle = "Edit Account";
29: $vars->set('oldaccount', $account);
30: } else {
31: $formtitle = "Add Account";
32: }
33:
34: $accountname = $GLOBALS['session']->get('shout', 'curaccount_name');
35: $title = sprintf(_("$formtitle %s"), $accountname);
36: parent::__construct($vars, $title);
37:
38: $this->addHidden('', 'action', 'text', true);
39:
40: $this->addVariable(_("Account Name"), 'name', 'text', true);
41: $this->addVariable(_("Account Code"), 'code', 'text', true);
42: $this->addVariable(_("Admin PIN"), 'adminpin', 'number', false);
43:
44: return true;
45: }
46:
47: 48: 49:
50: function execute()
51: {
52: $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
53:
54: $code = $this->_vars->get('code');
55: $name = $this->_vars->get('name');
56: $adminpin = $this->_vars->get('adminpin');
57: if (empty($adminpin)) {
58: $adminpin = rand(1000, 9999);
59: }
60:
61: $shout->storage->saveAccount($code, $name, $adminpin);
62: }
63:
64: }
65:
66: class AccountDeleteForm extends Horde_Form
67: {
68: function __construct(&$vars)
69: {
70: $extension = $vars->get('extension');
71: $account = $vars->get('account');
72:
73: $title = _("Delete Extension %s - Account: %s");
74: $account_config = $GLOBALS['session']->get('shout', 'accounts/' . $account);
75: $title = sprintf($title, $extension, $account_config['name']);
76: parent::__construct($vars, $title);
77:
78: $this->addHidden('', 'account', 'text', true);
79: $this->addHidden('', 'extension', 'int', true);
80: $this->addHidden('', 'action', 'text', true);
81: $this->setButtons(array(_("Delete"), _("Cancel")));
82: }
83:
84: function execute()
85: {
86: $shout = $GLOBALS['registry']->getApiInstance('shout', 'application');
87: $account = $this->_vars->get('account');
88: $shout->storage->deleteAccount($account);
89: }
90: }
91: