Example #1
0
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
// The Digital Receptionist code is a rat's nest.  If you are planning on making significant modifications, just re-write from scratch.
// OK! You're the boss. --Rob
// Re-written from the ground up by Rob Thomas <*****@*****.**> 23rd March, 2006.
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
$dircontext = isset($_SESSION["AMP_user"]->_deptname) ? $_SESSION["AMP_user"]->_deptname : '';
$nbroptions = isset($_REQUEST['nbroptions']) ? $_REQUEST['nbroptions'] : '3';
$tabindex = 0;
if (empty($dircontext)) {
    $dircontext = 'default';
}
switch ($action) {
    case "add":
        $id = ivr_get_ivr_id('Unnamed');
        // Set the defaults
        $def['timeout'] = 5;
        $def['ena_directdial'] = '';
        $def['ena_directory'] = '';
        ivr_sidebar($id);
        ivr_show_edit($id, 3, $def);
        break;
    case "edit":
        ivr_sidebar($id);
        ivr_show_edit($id, $nbroptions, $_POST);
        break;
    case "edited":
        if (isset($_REQUEST['delete'])) {
            sql("DELETE from ivr where ivr_id='{$id}'");
            sql("DELETE FROM ivr_dests where ivr_id='{$id}'");
Example #2
0
function ivr_init()
{
    global $db;
    global $amp_conf;
    // 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.
        localrunModuleSQL('ivr', 'uninstall');
        if (localrunModuleSQL('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..
        // In old IVR format, we had different dept as part of the context name, but since this is run once at install time, we need to read
        // all of them. Hopefully a wildcard will be adequate, changing it to that.
        //
        if ($amp_conf["AMPDBENGINE"] == "sqlite3") {
            $sql = "SELECT context,descr FROM extensions WHERE extension = 's' AND application LIKE 'DigitTimeout' AND context LIKE '%aa\\_%' ESCAPE '\\' ORDER BY context,priority";
        } else {
            $sql = "SELECT context,descr FROM extensions WHERE extension = 's' AND application LIKE 'DigitTimeout' AND context LIKE '%aa_%' ORDER BY context,priority";
        }
        $unique_aas = $db->getAll($sql);
        if (isset($unique_aas)) {
            foreach ($unique_aas as $aa) {
                // This gets all the menu options
                $id = ivr_get_ivr_id($aa[1]);
                // Save the old name, with a link to the new name, for upgrading
                $ivr_newname[$aa[0]] = "ivr-{$id}";
                // Get the old config
                $sql = "SELECT extension,args from extensions where application='Goto' and context='{$aa[0]}'";
                $cmds = $db->getAll($sql, DB_FETCHMODE_ASSOC);
                if (isset($cmds)) {
                    // There were some actions, so loop through them
                    foreach ($cmds as $cmd) {
                        $arr = explode(',', $cmd['args']);
                        // s == old stuff. We don't care.
                        if ($arr[0] != 's') {
                            ivr_add_command($id, $cmd['extension'], $cmd['args'], 0);
                        }
                    }
                }
            }
            // Now. Upgrade all the links inside the old IVR's
            if (isset($ivr_newname)) {
                // Some IVR's were upgraded
                $sql = "SELECT * FROM ivr_dests WHERE dest LIKE '%aa_%'";
                $dests = $db->getAll($sql, DB_FETCHMODE_ASSOC);
                if (isset($dests)) {
                    foreach ($dests as $dest) {
                        $arr = explode(',', $dest['dest']);
                        sql("UPDATE ivr_dests set dest='" . $ivr_newname[$arr[0]] . ",s,1' where ivr_id='" . $dest['ivr_id'] . "' and selection='" . $dest['selection'] . "'");
                    }
                }
            }
            // Upgrade everything using IVR as a destination. Ick.
            // Are queue's using an ivr failover?
            // ***FIXME*** if upgrading queues away from legacy cruft.
            $queues = $db->getAll("select extensions,args from extensions where args LIKE '%aa_%' and context='ext-queues' and priority='6'");
            if (is_array($queues)) {
                foreach ($queues as $q) {
                    $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 - if there's anything to process.
            if (isset($ivr_newname) && is_array($ivr_newname)) {
                foreach (array_keys($ivr_newname) as $old) {
                    // Timeconditions
                    sql("UPDATE timeconditions set truegoto='" . $ivr_newname[$arr[0]] . ",s,1' where truegoto='{$old},s,1'");
                    sql("UPDATE timeconditions set falsegoto='" . $ivr_newname[$arr[0]] . ",s,1' where falsegoto='{$old},s,1'");
                    // Inbound Routes
                    sql("UPDATE incoming set destination='" . $ivr_newname[$arr[0]] . ",s,1' where destination='{$old},s,1'");
                    // Ring Groups
                    sql("UPDATE ringgroups set postdest='" . $ivr_newname[$arr[0]] . ",s,1' where postdest='{$old},s,1'");
                }
            }
        }
        // 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')");
        needreload();
    }
}