From 117296c034218e907c3462861e791a570327e731 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Wed, 31 Mar 2010 17:53:12 -0400 Subject: [PATCH] Shout: Work on new-account wizard --- shout/index.php | 10 ++++---- shout/lib/Driver/Sql.php | 24 +++++++++++++++++++ shout/lib/Shout.php | 11 +++++++++ shout/templates/wizard.inc | 10 ++++++++ shout/wizard.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 shout/templates/wizard.inc create mode 100644 shout/wizard.php diff --git a/shout/index.php b/shout/index.php index f814a8302..1bf919351 100644 --- a/shout/index.php +++ b/shout/index.php @@ -10,14 +10,16 @@ */ require_once dirname(__FILE__) . '/lib/Application.php'; $shout = Horde_Registry::appInit('shout'); -$curaccount = $_SESSION['shout']['curaccount']; -if (empty($curaccount)) { + +if (empty($_SESSION['shout']['curaccount'])) { die("Permission denied."); } -$menus = $shout->storage->getMenus($curaccount); + +$curaccount = $_SESSION['shout']['curaccount']; +$menus = $shout->storage->getMenus($curaccount['code']); if (empty($menus)) { - print_r($curaccount); + header('Location: ' . Horde::applicationUrl('wizard.php', true)); } else { header('Location: ' . Horde::applicationUrl('dialplan.php', true)); exit; diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index 1a3169517..ddd7dc2cb 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -536,6 +536,30 @@ class Shout_Driver_Sql extends Shout_Driver return $recordings; } + public function getRecordingByName($account, $filename) + { + $sql = 'SELECT id, filename FROM recordings ' . + 'WHERE account_id = (SELECT id FROM accounts WHERE code = ?) ' . + 'AND filename = ?;'; + $args = array($account, $filename); + $msg = 'SQL query in Shout_Driver_Sql#getRecordingByName(): ' . $sql; + Horde::logMessage($msg, 'DEBUG'); + $result = $this->_db->query($sql, $args); + if ($result instanceof PEAR_Error) { + throw new Shout_Exception($result); + } + + $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + if ($row instanceof PEAR_Error) { + throw new Shout_Exception($row); + } + if ($row === null) { + throw new Shout_Exception('No such recording found for this account.'); + } + $result->free(); + return $row; + } + public function addRecording($account, $name) { $sql = 'INSERT INTO recordings (filename, account_id) ' . diff --git a/shout/lib/Shout.php b/shout/lib/Shout.php index fcb705cb7..9518a0019 100644 --- a/shout/lib/Shout.php +++ b/shout/lib/Shout.php @@ -13,6 +13,17 @@ */ class Shout { + /** + * @var string default menu, used for creating initial menu + */ + const MAIN_MENU = 'Main Menu'; + + /** + * + * @var string default recording, used for creating initial menu + */ + const MAIN_RECORDING = 'main_menu'; + var $applist = array(); var $_applist_curapp = ''; var $_applist_curfield = ''; diff --git a/shout/templates/wizard.inc b/shout/templates/wizard.inc new file mode 100644 index 000000000..2ee8b713b --- /dev/null +++ b/shout/templates/wizard.inc @@ -0,0 +1,10 @@ +
+

Step 1: Create your company greeting.

+ Here we record a company greeting. + Need: admin PIN, phone number + +
+ +
+ Here we create an extension. +
\ No newline at end of file diff --git a/shout/wizard.php b/shout/wizard.php new file mode 100644 index 000000000..573a2e778 --- /dev/null +++ b/shout/wizard.php @@ -0,0 +1,60 @@ + + */ +require_once dirname(__FILE__) . '/lib/Application.php'; +$shout = Horde_Registry::appInit('shout'); + +try { + // Only continue if there is no existing "Main Menu" + $curaccount = $_SESSION['shout']['curaccount']; + $menus = $shout->storage->getMenus($curaccount['code']); + + if (!empty($menus) && !empty($menus[Shout::MAIN_MENU])) { + header('Location: ' . Horde::applicationUrl('dialplan.php', true)); + exit; + } + + // Create the default recording for the main menu + try { + $recording = $shout->storage->getRecordingByName($curaccount['code'], + Shout::MAIN_RECORDING); + } catch (Shout_Exception $e) { + $shout->storage->addRecording($curaccount['code'], Shout::MAIN_RECORDING); + $recording = $shout->storage->getRecordingByName($curaccount['code'], + Shout::MAIN_RECORDING); + } + + // Create a default main menu + $details = array( + 'name' => Shout::MAIN_MENU, + 'description' => _("Main menu: what your callers will hear."), + 'recording_id' => $recording['id'] + ); + $shout->dialplan->saveMenuInfo($curaccount['code'], $details); + // Populate the default option, granting the ability to log into the admin + // section. + $shout->dialplan->saveMenuAction($curaccount['code'], Shout::MAIN_MENU, + '*', 'admin_login', array()); + + +} catch (Exception $e) { + $notification->push($e); +} + +Horde::addScriptFile('prototype.js', 'horde'); + +require SHOUT_TEMPLATES . '/common-header.inc'; +require SHOUT_TEMPLATES . '/menu.inc'; + +$notification->notify(); + +require SHOUT_TEMPLATES . '/wizard.inc'; + +require $registry->get('templates', 'horde') . '/common-footer.inc'; -- 2.11.0