Shout: Work on new-account wizard
authorBen Klang <ben@alkaloid.net>
Wed, 31 Mar 2010 21:53:12 +0000 (17:53 -0400)
committerBen Klang <ben@alkaloid.net>
Wed, 31 Mar 2010 22:26:04 +0000 (18:26 -0400)
shout/index.php
shout/lib/Driver/Sql.php
shout/lib/Shout.php
shout/templates/wizard.inc [new file with mode: 0644]
shout/wizard.php [new file with mode: 0644]

index f814a83..1bf9193 100644 (file)
  */
 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;
index 1a31695..ddd7dc2 100644 (file)
@@ -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) ' .
index fcb705c..9518a00 100644 (file)
  */
 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 (file)
index 0000000..2ee8b71
--- /dev/null
@@ -0,0 +1,10 @@
+<div id="step1" class="step">
+    <h2>Step 1: Create your company greeting.</h2>
+    Here we record a company greeting.
+    Need: admin PIN, phone number
+    <?php print_r($curaccount); ?>
+</div>
+
+<div id="step2" class="step">
+    Here we create an extension.
+</div>
\ No newline at end of file
diff --git a/shout/wizard.php b/shout/wizard.php
new file mode 100644 (file)
index 0000000..573a2e7
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Copyright 2010 Alkaloid Networks LLC (http://projects.alkaloid.net)
+ *
+ * See the enclosed file COPYING for license information (BSD). If you
+ * did not receive this file, see
+ * http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * @author  Ben Klang <ben@alkaloid.net>
+ */
+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';