Index: /modules/branches/2.1/ivr/page.ivr.php =================================================================== --- /modules/branches/2.1/ivr/page.ivr.php (revision 1559) +++ /modules/branches/2.1/ivr/page.ivr.php (revision 1627) @@ -146,4 +146,5 @@ @@ -153,9 +154,8 @@ '._("None").""; if (isset($tresults[0])) { foreach ($tresults as $tresult) { - echo '\n"; + echo '\n"; } } @@ -166,6 +166,19 @@ + +
You must install and enable the \"Systems Recordings\" Module to edit this option")?>
+   + + + + + +
Index: /modules/branches/2.1/ivr/install.sql =================================================================== --- /modules/branches/2.1/ivr/install.sql (revision 1348) +++ /modules/branches/2.1/ivr/install.sql (revision 1627) @@ -1,2 +1,2 @@ -CREATE TABLE IF NOT EXISTS ivr ( ivr_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50), deptname VARCHAR(50), enable_directory VARCHAR(8), enable_directdial VARCHAR(8), timeout INT, announcement VARCHAR(10), dircontext VARCHAR ( 50 ) DEFAULT "default" ); +CREATE TABLE IF NOT EXISTS ivr ( ivr_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50), deptname VARCHAR(50), enable_directory VARCHAR(8), enable_directdial VARCHAR(8), timeout INT, announcement VARCHAR(255), dircontext VARCHAR ( 50 ) DEFAULT "default" ); CREATE TABLE IF NOT EXISTS ivr_dests ( ivr_id INT NOT NULL, selection VARCHAR(10), dest VARCHAR(50)); Index: /modules/branches/2.1/ivr/module.xml =================================================================== --- /modules/branches/2.1/ivr/module.xml (revision 1619) +++ /modules/branches/2.1/ivr/module.xml (revision 1627) @@ -2,5 +2,5 @@ ivr IVR - 2.1.3 + 2.2 setup Module @@ -8,6 +8,5 @@ Digital Receptionist - release/ivr-2.1.3.tgz + release/ivr-2.2.tgz http://freepbx.org/wiki/IVR - c9c49fb378e88858c884734fa9792acd Index: /modules/branches/2.1/ivr/functions.inc.php =================================================================== --- /modules/branches/2.1/ivr/functions.inc.php (revision 1483) +++ /modules/branches/2.1/ivr/functions.inc.php (revision 1627) @@ -4,27 +4,28 @@ function ivr_init() { - global $db; - - // Check to make sure that install.sql has been run - $sql = "SELECT deptname from ivr where displayname='__install_done' LIMIT 1"; - - $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); - - if (DB::IsError($results)) { - // It couldn't locate the table. This is bad. Lets try to re-create it, just - // in case the user has had the brilliant idea to delete it. - // runModuleSQL taken from page.module.php. It's inclusion here is probably - // A bad thing. It should be, I think, globally available. - runModuleSQL('ivr', 'uninstall'); - if (runModuleSQL('ivr', 'install')==false) { - echo _("There is a problem with install.sql, cannot re-create databases. Contact support\n"); - die; - } else { - $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); - } - } - if (!isset($results[0])) { - // Note: There's an invalid entry created, __invalid, after this is run, - // so as long as this has been run _once_, there will always be a result. + global $db; + + // Check to make sure that install.sql has been run + $sql = "SELECT deptname from ivr where displayname='__install_done' LIMIT 1"; + + $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); + + if (DB::IsError($results)) { + // It couldn't locate the table. This is bad. Lets try to re-create it, just + // in case the user has had the brilliant idea to delete it. + // runModuleSQL taken from page.module.php. It's inclusion here is probably + // A bad thing. It should be, I think, globally available. + runModuleSQL('ivr', 'uninstall'); + if (runModuleSQL('ivr', 'install')==false) { + echo _("There is a problem with install.sql, cannot re-create databases. Contact support\n"); + die; + } else { + $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); + } + } + + if (!isset($results[0])) { + // Note: There's an invalid entry created, __invalid, after this is run, + // so as long as this has been run _once_, there will always be a result. // Read old IVR format, part of xtns.. @@ -62,7 +63,7 @@ } } - + // Upgrade everything using IVR as a destination. Ick. - + // Are queue's using an ivr failover? // ***FIXME*** if upgrading queues away from legacy cruft. @@ -72,7 +73,7 @@ $arr=explode(',', $q['args']); sql("UPDATE extensions set args='".$ivr_newname[$arr[0]].",s,1' where context='ext-queues' and priority='6' and extension='".$q['extension']."'"); - } - } - + } + } + // Now process everything else foreach (array_keys($ivr_newname) as $old) { @@ -88,17 +89,7 @@ // Note, the __install_done line is for internal version checking - the second field // should be incremented and checked if the database ever changes. - $result = sql("INSERT INTO ivr (displayname, deptname) VALUES ('__install_done', '1')"); + $result = sql("INSERT INTO ivr (displayname, deptname) VALUES ('__install_done', '1')"); needreload(); - } - // Now, we need to check for upgrades. - // V1.0, old IVR. You shouldn't see this, but check for it anyway, and assume that it's 2.0 - // V2.0, Original Release - // V2.1, added 'directorycontext' to the schema - // - if (modules_getversion('ivr') == "1.0" || modules_getversion('ivr') == "2.0") { - // Add the col - sql('ALTER TABLE ivr ADD COLUMN dircontext VARCHAR ( 50 ) DEFAULT "default"'); - modules_setversion('ivr', '1.1'); - } + } } @@ -132,4 +123,7 @@ $id = "ivr-".$item['ivr_id']; $details = ivr_get_details($item['ivr_id']); + + $announcement = (isset($details['announcement']) ? $details['announcement'] : ''); + if (!empty($details['enable_directdial'])) $ext->addInclude($id,'ext-local'); @@ -138,21 +132,21 @@ // $ext->addInclude($item[0],'app-messagecenter'); if (!empty($details['enable_directory'])) - $ext->addInclude($id,'app-directory'); - $ext->add($id, 'h', '', new ext_hangup('')); - $ext->add($id, 's', '', new ext_setvar('LOOPCOUNT', 0)); - $ext->add($id, 's', '', new ext_setvar('__DIR-CONTEXT', $details['dircontext'])); - $ext->add($id, 's', '', new ext_answer('')); - $ext->add($id, 's', '', new ext_wait('1')); - $ext->add($id, 's', 'begin', new ext_digittimeout(3)); - $ext->add($id, 's', '', new ext_responsetimeout($details['timeout'])); - if(function_exists('recordings_get')) { - $recording = recordings_get($details['announcement']); - $ext->add($id, 's', '', new ext_background($recording['filename'])); - } - $ext->add($id, 'hang', '', new ext_playback('vm-goodbye')); - $ext->add($id, 'hang', '', new ext_hangup('')); - - $default_t=true; - // Actually add the IVR commands now. + $ext->addInclude($id,'app-directory'); + + $ext->add($id, 'h', '', new ext_hangup('')); + $ext->add($id, 's', '', new ext_setvar('LOOPCOUNT', 0)); + $ext->add($id, 's', '', new ext_setvar('__DIR-CONTEXT', $details['dircontext'])); + $ext->add($id, 's', '', new ext_answer('')); + $ext->add($id, 's', '', new ext_wait('1')); + $ext->add($id, 's', 'begin', new ext_digittimeout(3)); + $ext->add($id, 's', '', new ext_responsetimeout($details['timeout'])); + if ($announcement != '') + $ext->add($id, 's', '', new ext_background($announcement)); + $ext->add($id, 'hang', '', new ext_playback('vm-goodbye')); + $ext->add($id, 'hang', '', new ext_hangup('')); + + $default_t=true; + + // Actually add the IVR commands now. $dests = ivr_get_dests($item['ivr_id']); if (!empty($dests)) { Index: /modules/branches/2.1/ivr/install.php =================================================================== --- /modules/branches/2.1/ivr/install.php (revision 1620) +++ /modules/branches/2.1/ivr/install.php (revision 1627) @@ -3,16 +3,58 @@ global $db; -// Needed for 2.1 upgrade -$sql = "SELECT dircontext FROM ivr"; -$check = $db->getRow($sql, DB_FETCHMODE_ASSOC); -if(DB::IsError($check)) { - // add new field - $sql = 'ALTER TABLE ivr ADD COLUMN dircontext VARCHAR ( 50 ) DEFAULT "default"'; +// Now, we need to check for upgrades. +// V1.0, old IVR. You shouldn't see this, but check for it anyway, and assume that it's 2.0 +// V2.0, Original Release +// V2.1, added 'directorycontext' to the schema +// v2.2, announcement changed to support filenames instead of ID's from recordings table +// + +$ivr_modcurrentvers = modules_getversion('ivr'); + +if (version_compare($ivr_modcurrentvers, "2.1", "<")) { + // Add the col + $sql = "SELECT dircontext FROM ivr"; + $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); + if(DB::IsError($check)) { + // add new field + $sql = 'ALTER TABLE ivr ADD COLUMN dircontext VARCHAR ( 50 ) DEFAULT "default"'; + $result = $db->query($sql); + if(DB::IsError($result)) { + die($result->getDebugInfo()); + } + } +} + +if (version_compare($ivr_modcurrentvers, "2.2", "<")) { + //echo "

Start 2.2 upgrade

"; + $sql = "ALTER TABLE ivr CHANGE COLUMN announcement announcement VARCHAR ( 255 )"; $result = $db->query($sql); if(DB::IsError($result)) { die($result->getDebugInfo()); + } else { + // Change existing records + //echo "

Updating existing records

"; + $existing = sql("SELECT DISTINCT announcement FROM ivr WHERE displayname <> '__install_done' AND announcement IS NOT NULL", "getAll"); + foreach ($existing as $item) { + $recid = $item[0]; + //echo "

processing '$recid'

"; + $sql = "SELECT filename FROM recordings WHERE id = '$recid' AND displayname <> '__invalid'"; + $recordings = sql($sql, "getRow"); + if (is_array($recordings)) { + $filename = (isset($recordings[0]) ? $recordings[0] : ''); + //echo "

filename: $filename"; + if ($filename != '') { + $sql = "UPDATE ivr SET announcement = '".str_replace("'", "''", $filename)."' WHERE announcement = '$recid'"; + $upcheck = $db->query($sql); + if(DB::IsError($upcheck)) + die($upcheck->getDebugInfo()); + } + } + } } } +// bump the version number +modules_setversion('ivr', '2.2'); ?>