Shout: Convert to recording_id
authorBen Klang <ben@alkaloid.net>
Mon, 29 Mar 2010 20:46:01 +0000 (16:46 -0400)
committerBen Klang <ben@alkaloid.net>
Mon, 29 Mar 2010 20:48:40 +0000 (16:48 -0400)
shout/dialplan.php
shout/lib/Driver/Sql.php
shout/lib/Forms/MenuForm.php
shout/lib/Shout.php
shout/recordings.php
shout/templates/dialplan/edit.inc
shout/templates/recordings/list.inc

index 564ef55..1782815 100644 (file)
@@ -61,7 +61,19 @@ if ($action == 'edit') {
     try {
         $destinations = $shout->extensions->getExtensions($curaccount);
         $conferences = $shout->storage->getConferences($curaccount);
-        $soundfiles = $shout->getRecordings();
+        $recordings = $shout->storage->getRecordings($curaccount);
+        // If any of these are empty, we need to coerce them to null.
+        // Otherwise we end up with a Prototype.js $H([]) (Hash of an empty
+        // Array) which causes confusion inside the library.
+        if (empty($destinations)) {
+            $destinations = null;
+        }
+        if (empty($conferences)) {
+            $conferences = null;
+        }
+        if (empty($recordings)) {
+            $recordings = null;
+        }
     } catch (Exception $e) {
         Horde::logMessage($e, 'ERR');
         $notification->push(_("Problem getting menu information."));
index 05befc4..59c60bf 100644 (file)
@@ -103,7 +103,7 @@ class Shout_Driver_Sql extends Shout_Driver
         $this->_connect();
 
         $sql = 'SELECT accounts.code AS account, menus.name AS name, ' .
-               'menus.description AS description, menus.soundfile AS soundfile ' .
+               'menus.description AS description, recording_id ' .
                'FROM menus INNER JOIN accounts ON menus.account_id = accounts.id ' .
                'WHERE accounts.code = ?';
         $values = array($account);
@@ -126,7 +126,7 @@ class Shout_Driver_Sql extends Shout_Driver
             $menus[$menu] = array(
                 'name' => $menu,
                 'description' => $row['description'],
-                'soundfile' => $row['soundfile']
+                'recording_id' => $row['recording_id']
             );
             $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
         }
@@ -142,17 +142,17 @@ class Shout_Driver_Sql extends Shout_Driver
                 throw new Shout_Exception(_("Old menu not found.  Edit aborted."));
             } else {
                 $sql = 'UPDATE menus SET name = ?, description = ?, ' .
-                       'soundfile = ? WHERE account_id = (SELECT id FROM ' .
-                       'WHERE code = ?) AND name = ?';
+                       'recording_id = ? WHERE account_id = ' .
+                       '(SELECT id FROM accounts WHERE code = ?) AND name = ?';
                 $values = array($details['name'], $details['description'],
-                                $details['soundfile'], $account,
+                                $details['recording_id'], $account,
                                 $details['oldname']);
             }
         } else {
-            $sql = "INSERT INTO menus (account_id, name, description, soundfile) " .
+            $sql = "INSERT INTO menus (account_id, name, description, recording_id) " .
                    "VALUES ((SELECT id FROM accounts WHERE code = ?), ?, ?, ?)";
             $values = array($account, $details['name'],
-                            $details['description'], $details['soundfile']);
+                            $details['description'], $details['recording_id']);
         }
 
         $msg = 'SQL query in Shout_Driver_Sql#saveMenu(): ' . $sql;
index e962483..63a4e6b 100644 (file)
@@ -35,7 +35,7 @@ class MenuForm extends Horde_Form {
         }
         $this->addVariable(_("Menu Name"), 'name', 'text', true);
         $this->addVariable(_("Description"), 'description', 'text', false);
-        $this->addVariable(_("Sound File"), 'soundfile', 'text', true);
+        $this->addVariable(_("Recording"), 'recording_id', 'enum', true);
 
         return true;
     }
@@ -49,16 +49,14 @@ class MenuForm extends Horde_Form {
         $details = array(
             'name' => $this->_vars->get('name'),
             'description' => $this->_vars->get('description'),
-            'soundfile' => $this->_vars->get('soundfile')
+            'recording_id' => $this->_vars->get('recording_id')
         );
 
-        // FIXME: Validate soundfile
-
         if ($action == 'edit') {
             $details['oldname'] = $this->_vars->get('oldname');
         }
 
-        $shout->devices->saveMenu($account, $details);
+        $shout->devices->saveMenuInfo($account, $details);
     }
 
 }
index 9b2ee02..6d1e363 100644 (file)
@@ -27,11 +27,11 @@ class Shout
         $mask = Horde_Menu::MASK_PROBLEM | Horde_Menu::MASK_LOGIN;
         $menu = new Horde_Menu($mask);
 
-        $menu->add(Horde::applicationUrl('dialplan.php'), _("Incoming Calls"), "dialplan.png");
+        $menu->add(Horde::applicationUrl('dialplan.php'), _("Call Menus"), "dialplan.png");
+        $menu->add(Horde::applicationUrl('recordings.php'), _("Recordings"), "recordings.png");
         $menu->add(Horde::applicationUrl('extensions.php'), _("Extensions"), "extension.png");
         $menu->add(Horde::applicationUrl('devices.php'), _("Devices"), "shout.png");
         $menu->add(Horde::applicationUrl('conferences.php'), _("Conferences"), "conference.png");
-        //$menu->add(Horde::applicationUrl('recordings.php'), _("Recordings"), "recordings.png");
 
         /* Administration. */
         if (Horde_Auth::isAdmin('shout:admin')) {
index 74f9454..c7eb520 100644 (file)
 require_once dirname(__FILE__) . '/lib/Application.php';
 $shout = Horde_Registry::appInit('shout');
 
-require_once SHOUT_BASE . '/lib/Forms/MenuForm.php';
+require_once SHOUT_BASE . '/lib/Forms/RecordingForm.php';
 
 $action = Horde_Util::getFormData('action');
 $curaccount = $_SESSION['shout']['curaccount'];
-$recordings = Shout::getRecordings($curaccount);
+$recordings = $shout->storage->getRecordings($curaccount);
 
 switch($action) {
 case 'add':
     $vars = Horde_Variables::getDefaultVariables();
     $vars->set('account', $curaccount);
-    $Form = new MenuForm($vars);
+    $Form = new RecordingDetailsForm($vars);
 
     if ($Form->isSubmitted() && $Form->validate($vars, true)) {
         // Form is Valid and Submitted
         try {
             $Form->execute();
-            $notification->push(_("Menu added."),
+            $notification->push(_("Recording added."),
                                   'horde.success');
-            $menus = $shout->storage->getMenus($curaccount);
+            $recordings = $shout->storage->getRecordings($curaccount);
             $action = 'list';
         } catch (Exception $e) {
             $notification->push($e);
index 6996890..346d872 100644 (file)
@@ -11,8 +11,8 @@
                 <td class="metaStatInfo" id="menu.description"></td>
             </tr>
             <tr>
-                <td class="metaStatName">Sound File</td>
-                <td class="metaStatInfo"><span id="menu.soundfile"></span></td>
+                <td class="metaStatName">Recording</td>
+                <td class="metaStatInfo"><span id="menu.recording"></span></td>
             </tr>
         </table>
         <form id="editMenu">
                 <td class="metaStatInfo"><input id="menu_edit.description" name="description"></td>
             </tr>
             <tr>
-                <td class="metaStatName">Sound File</td>
-                <td class="metaStatInfo"><select id="menu_edit.soundfile" name="soundfile"></select></td>
+                <td class="metaStatName">Recording</td>
+                <td class="metaStatInfo"><select id="menu_edit.recording" name="recording_id"></select></td>
             </tr>
             <tr>
-                <td><div class="button" onclick="saveMenu()"><?php echo _("Save"); ?></div></td>
+                <td><div class="button" onclick="saveMenuInfo()"><?php echo _("Save"); ?></div></td>
                 <td><div class="button" onclick="$('editMenu').hide()"><?php echo _("Cancel"); ?></div></td>
             </tr>
         </table>
@@ -89,7 +89,7 @@ var menuInfo = $H();
 var menuActions = $H(<?php echo Horde_Serialize::serialize(Shout::getMenuActions(), Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
 var destinations = $H(<?php echo Horde_Serialize::serialize($destinations, Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
 var conferences = $H(<?php echo Horde_Serialize::serialize($conferences, Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
-var soundfiles = $H(<?php echo Horde_Serialize::serialize($soundfiles, Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
+var recordings = $H(<?php echo Horde_Serialize::serialize($recordings, Horde_Serialize::JSON, Horde_Nls::getCharset()); ?>);
 
 function empty(p)
 {
index f13e927..82769e8 100644 (file)
@@ -5,38 +5,30 @@
 <div id="extensionList">
     <table width="100%" cellspacing="0" class="striped">
         <tr><?php // FIXME: Change Size column to recording length ?>
-            <td class="uheader">Name</td>
-            <td class="uheader">Size</td>
-        </tr>
-        <?php
-            foreach ($recordings as $name => $info) {
-
-                $url = Horde::applicationUrl("recordings.php");
-                $url = Horde_Util::addParameter($url,
-                    array(
-                        'name' => $name,
-                    )
-                );
-                $editurl = Horde_Util::addParameter($url, 'action', 'edit');
-                $deleteurl = Horde_Util::addParameter($url, 'action', 'delete');
-        ?>
-        <tr class="item" style="vertical-align: top">
-            <td>
-                <?php echo Horde::link($editurl); echo $info['name']; ?></a>
-            </td>
-            <td>
-                <?php echo $info['size']; ?>
-            </td>
+            <td class="uheader">Recording Name</td>
+            <td class="uheader">Recording ID</td>
         </tr>
         <?php
+            $url = Horde::applicationUrl("recordings.php");
+            $deleteurl = Horde_Util::addParameter($url, 'action', 'delete');
+            foreach ($recordings as $info) {
+                ?>
+                <tr class="item" style="vertical-align: top">
+                    <td>
+                        <?php echo $info['filename']; ?>
+                    </td>
+                    <td>
+                        <?php echo $info['id']; ?>
+                    </td>
+                </tr>
+                <?php
             }
-        ?>
+            ?>
     </table>
 </div>
 <ul id="controls">
     <?php
-    $addurl = Horde::applicationUrl('recordings.php');
-    $addurl = Horde_Util::addParameter($addurl, 'action', 'add');
+    $addurl = Horde_Util::addParameter($url, 'action', 'add');
     ?>
     <li><a class="button" href="<?php echo $addurl; ?>">
         <?php echo Horde::img('recording-add.png'); ?>&nbsp;New Recording