From: Ben Klang Date: Mon, 29 Mar 2010 17:16:06 +0000 (-0400) Subject: Shout: create administrative PIN feature X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a9bc57869fb254a6fe526242b581f3a50fa055cb;p=horde.git Shout: create administrative PIN feature --- diff --git a/shout/admin.php b/shout/admin.php index dde59bcab..29002bd0f 100644 --- a/shout/admin.php +++ b/shout/admin.php @@ -46,7 +46,7 @@ case 'edit': // Create a new add/edit form $account = Horde_Util::getFormData('extension'); $accounts = $shout->storage->getAccounts(); - $vars = new Horde_Variables(array('code' => $account, 'name' => $accounts[$account])); + $vars = new Horde_Variables(array('code' => $account, 'name' => $accounts[$account]['name'])); $vars->set('action', $action); // Make sure we get the right template below. diff --git a/shout/lib/Application.php b/shout/lib/Application.php index c94fb70c6..a623bf0dd 100644 --- a/shout/lib/Application.php +++ b/shout/lib/Application.php @@ -138,9 +138,9 @@ class Shout_Application extends Horde_Registry_Application self::$_perms['title']['shout:accounts'] = _("Accounts"); // Run through every contact source. - foreach ($accounts as $code => $account) { + foreach ($accounts as $code => $info) { self::$_perms['tree']['shout']['accounts'][$code] = false; - self::$_perms['title']['shout:accounts:' . $code] = $account; + self::$_perms['title']['shout:accounts:' . $code] = $info['name']; foreach( array( diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index 1166c27b8..05befc48a 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -48,7 +48,7 @@ class Shout_Driver_Sql extends Shout_Driver { $this->_connect(); - $sql = 'SELECT name, code FROM accounts'; + $sql = 'SELECT name, code, adminpin FROM accounts'; $vars = array(); $msg = 'SQL query in Shout_Driver_Sql#getAccounts(): ' . $sql; @@ -65,7 +65,7 @@ class Shout_Driver_Sql extends Shout_Driver $accounts = array(); while ($row && !($row instanceof PEAR_Error)) { - $accounts[$row['code']] = $row['name']; + $accounts[$row['code']] = $row; $row = $result->fetchRow(DB_FETCHMODE_ASSOC); } @@ -73,24 +73,23 @@ class Shout_Driver_Sql extends Shout_Driver return $accounts; } - public function saveAccount($code, $name) + public function saveAccount($code, $name, $adminpin) { $this->_connect(); - if (isset($details['oldname'])) { - if (!isset($menus[$details['oldname']])) { - throw new Shout_Exception(_("Old account not found. Edit aborted.")); - } else { - throw new Shout_Exception(_("Unsupported operation.")); - $sql = 'UPDATE accounts SET code = ?, name =? WHERE code = ?'; - } - } else { - $sql = 'INSERT INTO accounts (code, name) VALUES (?,?)'; - } - - $vars = array($code, $name); - - $msg = 'SQL query in Shout_Driver_Sql#getAccounts(): ' . $sql; + // FIXME: Enable editing of account details +// if (isset($details['oldname'])) { +// if (!isset($menus[$details['oldname']])) { +// throw new Shout_Exception(_("Old account not found. Edit aborted.")); +// } else { +// throw new Shout_Exception(_("Unsupported operation.")); +// $sql = 'UPDATE accounts SET code = ?, name = ?, adminpin = ? ' . +// 'WHERE code = ?'; +// } +// } else { + $sql = 'INSERT INTO accounts (code, name, adminpin) VALUES (?,?,?)'; + $vars = array($code, $name, $adminpin); + $msg = 'SQL query in Shout_Driver_Sql#saveAccount(): ' . $sql; Horde::logMessage($msg, 'DEBUG'); $result = $this->_db->query($sql, $vars); if ($result instanceof PEAR_Error) { diff --git a/shout/lib/Forms/AccountForm.php b/shout/lib/Forms/AccountForm.php index f2779c819..74ba7dadb 100644 --- a/shout/lib/Forms/AccountForm.php +++ b/shout/lib/Forms/AccountForm.php @@ -31,7 +31,7 @@ class AccountDetailsForm extends Horde_Form { $formtitle = "Add Account"; } - $accountname = $_SESSION['shout']['accounts'][$curaccount]; + $accountname = $_SESSION['shout']['accounts'][$curaccount]['name']; $title = sprintf(_("$formtitle %s"), $accountname); parent::__construct($vars, $title); @@ -39,6 +39,7 @@ class AccountDetailsForm extends Horde_Form { //$this->addHidden('', 'oldaccount', 'text', false); $this->addVariable(_("Account Name"), 'name', 'text', true); $this->addVariable(_("Account Code"), 'code', 'text', true); + $this->addVariable(_("Admin PIN"), 'adminpin', 'number', false); return true; } @@ -52,8 +53,12 @@ class AccountDetailsForm extends Horde_Form { $code = $this->_vars->get('code'); $name = $this->_vars->get('name'); + $adminpin = $this->_vars->get('adminpin'); + if (empty($adminpin)) { + $adminpin = rand(1000, 9999); + } - $shout->storage->saveAccount($code, $name);; + $shout->storage->saveAccount($code, $name, $adminpin); } } @@ -66,7 +71,7 @@ class AccountDeleteForm extends Horde_Form $account = $vars->get('account'); $title = _("Delete Extension %s - Account: %s"); - $title = sprintf($title, $extension, $_SESSION['shout']['accounts'][$account]); + $title = sprintf($title, $extension, $_SESSION['shout']['accounts'][$account]['name']); parent::__construct($vars, $title); $this->addHidden('', 'account', 'text', true); diff --git a/shout/lib/Forms/ConferenceForm.php b/shout/lib/Forms/ConferenceForm.php index 9e9eb2e81..46d6b61cc 100644 --- a/shout/lib/Forms/ConferenceForm.php +++ b/shout/lib/Forms/ConferenceForm.php @@ -26,7 +26,7 @@ class ConferenceDetailsForm extends Horde_Form { $curaccount = $_SESSION['shout']['curaccount']; $accountname = $vars->account; - $title = sprintf(_("$formtitle - Account: %s"), $accountname); + $title = sprintf(_("$formtitle")); parent::__construct($vars, $title); $this->addHidden('', 'action', 'text', true); @@ -76,7 +76,7 @@ class ConferenceDeleteForm extends Horde_Form $account = $vars->get('account'); $title = _("FIXME Delete Device %s - Account: %s"); - $title = sprintf($title, $devid, $_SESSION['shout']['accounts'][$account]); + $title = sprintf($title, $devid, $_SESSION['shout']['accounts'][$account]['name']); parent::__construct($vars, $title); $this->addHidden('', 'account', 'text', true); diff --git a/shout/lib/Forms/DeviceForm.php b/shout/lib/Forms/DeviceForm.php index b9d8cc6a7..7f4da6504 100644 --- a/shout/lib/Forms/DeviceForm.php +++ b/shout/lib/Forms/DeviceForm.php @@ -23,7 +23,7 @@ class DeviceDetailsForm extends Horde_Form { } $curaccount = $_SESSION['shout']['curaccount']; - $accountname = $_SESSION['shout']['accounts'][$curaccount]; + $accountname = $_SESSION['shout']['accounts'][$curaccount]['name']; $title = sprintf(_("$formtitle - Account: %s"), $accountname); parent::__construct($vars, $title); @@ -99,7 +99,7 @@ class DeviceDeleteForm extends Horde_Form $account = $vars->get('account'); $title = _("Delete Device %s - Account: %s"); - $title = sprintf($title, $devid, $_SESSION['shout']['accounts'][$account]); + $title = sprintf($title, $devid, $_SESSION['shout']['accounts'][$account]['name']); parent::__construct($vars, $title); $this->addHidden('', 'account', 'text', true); diff --git a/shout/lib/Forms/ExtensionForm.php b/shout/lib/Forms/ExtensionForm.php index 632911f60..ea110ec0d 100644 --- a/shout/lib/Forms/ExtensionForm.php +++ b/shout/lib/Forms/ExtensionForm.php @@ -21,7 +21,7 @@ class ExtensionDetailsForm extends Horde_Form { */ function __construct(&$vars) { - $account = $_SESSION['shout']['curaccount']; + $curaccount = $_SESSION['shout']['curaccount']; $action = $vars->get('action'); if ($action == 'edit') { $formtitle = "Edit User"; @@ -29,7 +29,7 @@ class ExtensionDetailsForm extends Horde_Form { $formtitle = "Add User"; } - $accountname = $_SESSION['shout']['accounts'][$curaccount]; + $accountname = $_SESSION['shout']['accounts'][$curaccount]['name']; $title = sprintf(_("$formtitle - Account: %s"), $accountname); parent::__construct($vars, $title); @@ -82,7 +82,7 @@ class ExtensionDeleteForm extends Horde_Form $account = $vars->get('account'); $title = _("Delete Extension %s - Account: %s"); - $title = sprintf($title, $extension, $_SESSION['shout']['accounts'][$account]); + $title = sprintf($title, $extension, $_SESSION['shout']['accounts'][$account]['name']); parent::__construct($vars, $title); $this->addHidden('', 'account', 'text', true); diff --git a/shout/lib/Forms/MenuForm.php b/shout/lib/Forms/MenuForm.php index ba9eb1f59..e962483c8 100644 --- a/shout/lib/Forms/MenuForm.php +++ b/shout/lib/Forms/MenuForm.php @@ -23,7 +23,7 @@ class MenuForm extends Horde_Form { } $curaccount = $_SESSION['shout']['curaccount']; - $accountname = $_SESSION['shout']['accounts'][$curaccount]; + $accountname = $_SESSION['shout']['accounts'][$curaccount]['name']; $title = sprintf(_("%s - Account: %s"), $formtitle, $accountname); parent::__construct($vars, $title); @@ -71,7 +71,7 @@ class DeviceMenuForm extends Horde_Form $account = $vars->get('account'); $title = _("Delete Menu %s - Account: %s"); - $title = sprintf($title, $menu, $_SESSION['shout']['accounts'][$account]); + $title = sprintf($title, $menu, $_SESSION['shout']['accounts'][$account]['name']); parent::__construct($vars, $title); $this->setButtons(array(_("Delete"), _("Cancel"))); diff --git a/shout/lib/Shout.php b/shout/lib/Shout.php index 55fe35199..9b2ee0294 100644 --- a/shout/lib/Shout.php +++ b/shout/lib/Shout.php @@ -207,6 +207,10 @@ class Shout 'description' => _("Restart menu"), 'args' => array() ), + 'adminlogin' => array( + 'description' => _("Login to Admin Functions"), + 'args' => array() + ), 'none' => array( 'description' => _("No action"), 'args' => array() diff --git a/shout/templates/accounts/list.inc b/shout/templates/accounts/list.inc index cde395ab2..0a9047a80 100644 --- a/shout/templates/accounts/list.inc +++ b/shout/templates/accounts/list.inc @@ -1,42 +1,41 @@
- Account: + Account:
- - - $name) { - - $url = Horde::applicationUrl("admin.php"); - $url = Horde_Util::addParameter($url, - array( - 'account' => $code, - ) - ); - $editurl = Horde_Util::addParameter($url, 'action', 'edit'); - $deleteurl = Horde_Util::addParameter($url, 'action', 'delete'); - ?> - - - + + + + + + + + + ?>
Account CodeAccount Name
- - - - Account NameAdmin PIN
+ $code))); echo $code; echo ''; ?> + + + + +