Example #1
0
 public static function register($driver, $hook)
 {
     $driverName = Telephony::getDriverName();
     if (!$driverName or $driverName == 'none') {
         return true;
     } elseif (!class_exists($driverName)) {
         Kohana::log('error', 'Telephony -> Unable to register the dialplan driver \'' . $driverName . '\'');
         return false;
     }
     $hookClass = $driverName . '_' . $driver . '_Driver';
     if (!class_exists($hookClass)) {
         Kohana::log('error', 'Telephony -> Unable to register the dialplan hook \'' . $driver . '\'(' . $hookClass . ')');
         return false;
     }
     if (empty(self::$dialplanSections)) {
         kohana::log('debug', 'Telephony -> EVAL ' . $driverName . '::getDialplanSections();');
         $sections = eval('return ' . $driverName . '::getDialplanSections();');
         if (is_array($sections)) {
             self::$dialplanSections = $sections;
         }
     }
     if (!in_array($hook, self::$dialplanSections)) {
         //Logger::ExceptionByCaller();
         throw new Exception('The hook ' . $hook . ' is not a recognized telephony global hook. (While trying to register callback ' . $driver . ')');
     }
     // Register event as _telephony.action with the callback array as the callback
     Event::add('_telephony.' . $hook, array($hookClass, $hook));
     Kohana::log('debug', 'Telephony -> Added hook for _telephony.' . $hook . ' to call ' . $hookClass . '::' . $hook);
     return TRUE;
 }
Example #2
0
 /**
  * When a number is saved, we need to update any contexts that the number lives in
  */
 public static function set($obj)
 {
     // Go create the number related stuff for each context it is assigned to
     if ($obj->NumberContext) {
         foreach ($obj->NumberContext as $context) {
             // Add any "global" hooks that come before the processing of any numbers (this is per context)
             dialplan::start('context_' . $context['context_id']);
             FreeSwitch_NumberContext_Driver::set($context);
             // Add any "global" hooks that come after the processing of any numbers (this is per context)
             dialplan::end('context_' . $context['context_id']);
         }
     }
 }
Example #3
0
 /**
  * When a number is saved, we need to update any contexts that the number lives in
  */
 public static function set($obj)
 {
     // Go create the number related stuff for each context it is assigned to
     if ($obj->NumberContext) {
         $assignedContexts = array();
         foreach ($obj->NumberContext as $context) {
             // Add any "global" hooks that come before the processing of any numbers (this is per context)
             dialplan::start('context_' . $context['context_id'], $context->Number);
             FreeSwitch_NumberContext_Driver::set($context);
             // Add any "global" hooks that come after the processing of any numbers (this is per context)
             dialplan::end('context_' . $context['context_id'], $context->Number);
             $assignedContexts[] = $context['context_id'];
         }
         // Changed the operation of setting the pools that cause existings
         // pool records to be used, where we used to unset (delete) them, so
         // we need to ensure we dont orphan numbers when changing contexts
         $contexts = Doctrine::getTable('Context')->findAll();
         $xml = Telephony::getDriver()->xml;
         $xp = new DOMXPath($xml);
         foreach ($contexts as $context) {
             if (!in_array($context['context_id'], $assignedContexts)) {
                 $search = sprintf('//document/section[@name="dialplan"]/context[@name="context_%s"]/extension[@name="%s"]', $context['context_id'], 'main_number_' . $obj['number_id']);
                 if ($xp->query($search)->length) {
                     kohana::log('debug', 'FreeSWITCH -> REMOVING NUMBER ' . $obj['number'] . ' (' . $obj['number_id'] . ') FROM CONTEXT ' . $context['context_id']);
                     $xml->setXmlRoot($search);
                     $xml->deleteNode();
                 }
             }
         }
         if ($obj['type'] == Number::TYPE_EXTERNAL and !empty($obj->NumberContext[0]['context_id'])) {
             kohana::log('debug', 'FreeSWITCH -> ADDING NUMBER ' . $obj['number'] . ' (' . $obj['number_id'] . ') TO NUMBER ROUTE');
             $xml = Freeswitch::setSection('number_route', $obj['number_id']);
             // Dialplans are a bit different - we don't want to keep anything that is currently in an extension, in the event it's totally changed
             $xml->deleteChildren();
             $num = str_replace(array('*', '+'), array('\\*', '\\+'), $obj['number']);
             // Check what number they dialed
             $condition = '/condition[@field="destination_number"]{@expression="^' . $num . '$"}';
             $xml->update($condition . '/action[@application="set"][@data="vm-operator-extension=' . $obj['number'] . '"]');
             $xml->update($condition . '/action[@application="set"][@data="force_transfer_context=context_' . $obj->NumberContext[0]['context_id'] . '"]');
             $xml->update($condition . '/action[@application="transfer"]{@data="' . $obj['number'] . ' XML context_' . $obj->NumberContext[0]['context_id'] . '"}');
         } else {
             kohana::log('debug', 'FreeSWITCH -> REMOVING NUMBER ' . $obj['number'] . ' (' . $obj['number_id'] . ') FROM NUMBER ROUTE');
             Freeswitch::setSection('number_route', $obj['number_id'])->deleteNode();
         }
     }
 }
Example #4
0
 public static function set($obj)
 {
     $numberInUse = FALSE;
     if ($obj->NumberContext) {
         foreach ($obj->NumberContext as $context) {
             // Add any "global" hooks that come before the processing of any numbers (this is per context)
             dialplan::start('context_' . $context['context_id']);
             $numberInUse = $numberInUse | Asterisk_NumberContext_Driver::set($context);
             // Add any "global" hooks that come after the processing of any numbers (this is per context)
             dialplan::end('context_' . $context['context_id']);
         }
     }
     if (!$numberInUse) {
         // Remove the destination itself, fully. Despite this being called create, an empty context gets deleted automagically at save time
         kohana::log('debug', 'Number id ' . $obj['number_id'] . ' is no longer in use in any context, deleteing!');
         $doc = Telephony::getDriver()->doc;
         $doc->deleteContext('extensions.conf', 'number_' . $obj['number_id']);
     }
 }
Example #5
0
 /**
  * Indicate we support FreeSWITCH with this SIP Device and provide code to save SIP device specific settings
  */
 public static function set($base)
 {
     $xml = Telephony::getDriver()->xml;
     // Reference to our XML document, context and extension. Creates the extension & context if does not already exist
     $xml = FreeSwitch::createExtension('number_' . $base['Number']['number_id'], 'main', 'context_' . $base['context_id']);
     // Does this number go anywhere?
     if ($base['Number']['class_type']) {
         kohana::log('debug', 'FreeSWITCH -> ADDING NUMBER ' . $base['Number']['number'] . ' (' . $base['Number']['number_id'] . ') TO CONTEXT ' . $base['context_id']);
         // Dialplans are a bit different - we don't want to keep anything that is currently in an extension, in the event it's totally changed
         $xml->deleteChildren();
         // Check what number they dialed
         $xml->update('/condition[@field="destination_number"]{@expression="^' . $base['Number']['number'] . '$"}');
         // Now that the extension and condition fields are created for this number, set our root to inside the condition
         $xml->setXmlRoot($xml->getXmlRoot() . '/condition[@field="destination_number"][@expression="^' . $base['Number']['number'] . '$"]');
         $dialplan = $base['Number']['dialplan'];
         // Add an extension-specific prenumber items
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the XML document for the add
         dialplan::preNumber($base['Number']);
         if (!empty($dialplan['terminate']['action'])) {
             switch ($dialplan['terminate']['action']) {
                 case 'transfer':
                     $xml->update('/action[@application="set"][@bluebox="settingEndBridge"][@data="hangup_after_bridge=true"]');
                     $xml->update('/action[@application="set"][@bluebox="settingFail"][@data="continue_on_fail=true"]');
                     break;
             }
         }
         // Add related final destination XML
         $destinationDriverName = Telephony::getDriverName() . '_' . substr($base['Number']['class_type'], 0, strlen($base['Number']['class_type']) - 6) . '_Driver';
         Kohana::log('debug', 'FreeSWITCH -> Looking for destination driver ' . $destinationDriverName);
         // Is there a driver?
         if (class_exists($destinationDriverName, TRUE)) {
             // Logging
             Kohana::log('debug', 'FreeSWITCH -> Adding information for destination ' . $base['Number']['number_id'] . ' from model "' . get_class($base['Number']) . '" to our telephony configuration...');
             // Drivers are always singletons, and are responsible for persistenting data for their own config generation via static vars
             // TODO: Change this for PHP 5.3, which doesn't require eval(). Don't change this until all the cool kids are on PHP 5.3*/
             kohana::log('debug', 'FreeSWITCH -> EVAL ' . $destinationDriverName . '::dialplan($base->Number);');
             $success = eval('return ' . $destinationDriverName . '::dialplan($base->Number);');
         }
         // Add an anti-action / failure route for this dialplan
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the XML document for the add
         dialplan::postNumber($base['Number']);
         if (!empty($dialplan['terminate']['action'])) {
             switch ($dialplan['terminate']['action']) {
                 case 'transfer':
                     if ($transfer = fs::getTransferToNumber($dialplan['terminate']['transfer'])) {
                         $xml->update('/action[@application="transfer"][@data="' . $transfer . '"]');
                     } else {
                         $xml->update('/action[@application="hangup"]');
                     }
                     break;
                 case 'continue':
                     break;
                 case 'hangup':
                 default:
                     $xml->update('/action[@application="hangup"]');
                     break;
             }
         } else {
             $xml->update('/action[@application="hangup"]');
         }
     } else {
         kohana::log('debug', 'FreeSWITCH -> REMOVING NUMBER ID ' . $base['Number']['number_id'] . ' FROM CONTEXT ' . $base['context_id']);
         $xml->deleteNode();
     }
 }
Example #6
0
 /**
  * Creates a context that you can route calls to initially. Takes care of adding the global event hooks/conditions
  * at the top of the context and then does a GoTo to the context's destinations list
  * @param integer $contextId
  */
 public function createRoutableContext($contextId)
 {
     // TODO: ADD SKIP FUNCTIONALITY HERE. Don't recreate this on the same run if we've already created this context, that's dumb.
     $this->createContext('extensions.conf', 'context_' . $contextId, NULL, array('replace' => TRUE));
     // Add global event hooks
     dialplan::start('context_' . $contextId);
     // TODO: Context gets clobbered during dialplan start/end, so let's set it again
     //self::
     $this->add('GoSub(extensions_' . $contextId . ',${EXTEN},1)');
     // Put end of dialplan stuff
     dialplan::end('context_' . $contextId);
     // TODO: Context gets clobbered again. Set it up again.
     $this->add('Hangup()');
 }
function save_hunt_group()
{
    //Hunt Group Lua Notes:
    //get the domain
    //loop through all Hunt Groups
    //get the Hunt Group information such as the name and description
    //add each Hunt Group to the dialplan
    //get the list of destinations then build the Hunt Group lua
    //get the domain
    global $db, $domain_uuid, $host, $config;
    $tmp = "";
    $tmp .= "\n";
    $tmp .= " domain_name = \"" . $domain . "\"; //by default this is the ipv4 address of FreeSWITCH used for transfer to voicemail\n";
    $tmp .= "\n";
    $tmp .= "\n";
    //prepare for hunt group .lua files to be written. delete all hunt groups that are prefixed with huntgroup_ and have a file extension of .lua
    $v_prefix = 'v_huntgroup_';
    if ($dh = opendir($_SESSION['switch']['scripts']['dir'])) {
        $files = array();
        while ($file = readdir($dh)) {
            if ($file != "." && $file != ".." && $file[0] != '.') {
                if (is_dir($dir . "/" . $file)) {
                    //this is a directory
                } else {
                    if (substr($file, 0, strlen($v_prefix)) == $v_prefix && substr($file, -4) == '.lua') {
                        if ($file != "huntgroup_originate.lua") {
                            unlink($_SESSION['switch']['scripts']['dir'] . '/' . $file);
                        }
                    }
                }
            }
        }
        closedir($dh);
    }
    //loop through all Hunt Groups
    $x = 0;
    $sql = "select * from v_hunt_groups ";
    $prep_statement = $db->prepare(check_sql($sql));
    $prep_statement->execute();
    $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
    foreach ($result as &$row) {
        //get the Hunt Group information such as the name and description
        //$row['hunt_group_uuid']
        //$row['hunt_group_extension']
        //$row['hunt_group_name']
        //$row['hunt_group_type']
        //$row['hunt_group_timeout']
        //$row['hunt_group_context']
        //$row['hunt_group_ringback']
        //$row['hunt_group_cid_name_prefix']
        //$row['hunt_group_pin']
        //$row['hunt_group_caller_announce']
        //$row['hunt_group_enabled']
        //$row['hunt_group_description']
        $domain_uuid = $row['domain_uuid'];
        $dialplan_uuid = $row['dialplan_uuid'];
        //add each hunt group to the dialplan
        if (strlen($row['hunt_group_uuid']) > 0) {
            //set default action to add
            $action = 'add';
            //check whether the dialplan entry exists in the database
            $action = 'add';
            //set default action to add
            $i = 0;
            $sql = "select count(*) as num_rows from v_dialplans ";
            $sql .= "where domain_uuid = '" . $domain_uuid . "' ";
            $sql .= "and dialplan_uuid = '" . $dialplan_uuid . "' ";
            $prep_statement_2 = $db->prepare(check_sql($sql));
            if ($prep_statement_2) {
                $prep_statement_2->execute();
                $row2 = $prep_statement_2->fetch(PDO::FETCH_ASSOC);
                if ($row2['num_rows'] > 0) {
                    //$num_rows = $row2['num_rows'];
                    $action = 'update';
                }
            }
            unset($prep_statement, $result);
            if ($action == 'add') {
                //create dialplan entry for each huntgroup
                $app_uuid = '0610f841-2e27-4c5f-7926-08ab3aad02e0';
                if ($row['hunt_group_enabled'] == "false") {
                    $dialplan_enabled = 'false';
                } else {
                    $dialplan_enabled = 'true';
                }
                if (strlen($dialplan_uuid) == 0) {
                    //create a dialplan uuid
                    $dialplan_uuid = uuid();
                    //update the hunt groups table with the database
                    $sql = "update v_hunt_groups ";
                    $sql .= "set dialplan_uuid = '" . $dialplan_uuid . "' ";
                    $sql .= "where domain_uuid = '" . $domain_uuid . "' ";
                    $sql .= "and hunt_group_uuid = '" . $row['hunt_group_uuid'] . "' ";
                    $db->query($sql);
                    unset($sql);
                }
                require_once "resources/classes/dialplan.php";
                $dialplan = new dialplan();
                $dialplan->domain_uuid = $domain_uuid;
                $dialplan->app_uuid = $app_uuid;
                $dialplan->dialplan_uuid = $dialplan_uuid;
                $dialplan->dialplan_name = $row['hunt_group_name'];
                //$dialplan->dialplan_continue = $dialplan_continue;
                $dialplan->dialplan_order = '330';
                $dialplan->dialplan_context = $_SESSION['context'];
                $dialplan->dialplan_enabled = $dialplan_enabled;
                $dialplan->dialplan_description = $row['hunt_group_description'];
                $dialplan->dialplan_add();
                unset($dialplan);
            }
            if ($action == 'update') {
                //update the huntgroup fifo
                $dialplan_name = $row['hunt_group_name'];
                $dialplan_order = '330';
                $context = $row['hunt_group_context'];
                if ($row['hunt_group_enabled'] == "false") {
                    $enabled = 'false';
                } else {
                    $enabled = 'true';
                }
                $description = $row['hunt_group_description'];
                $hunt_group_uuid = $row['hunt_group_uuid'];
                $sql = "update v_dialplans set ";
                $sql .= "dialplan_name = '{$dialplan_name}', ";
                $sql .= "dialplan_order = '{$dialplan_order}', ";
                $sql .= "dialplan_context = '{$context}', ";
                $sql .= "dialplan_enabled = '{$enabled}', ";
                $sql .= "dialplan_description = '{$description}' ";
                $sql .= "where domain_uuid = '" . $domain_uuid . "' ";
                $sql .= "and dialplan_uuid = '" . $dialplan_uuid . "' ";
                $db->query($sql);
                unset($sql);
                $sql = "delete from v_dialplan_details ";
                $sql .= "where domain_uuid = '{$domain_uuid}' ";
                $sql .= "and dialplan_uuid = '{$dialplan_uuid}' ";
                $db->query($sql);
                unset($sql);
            }
            //if action is add or update
            if ($action == 'add' || $action == 'update') {
                require_once "resources/classes/dialplan.php";
                $dialplan = new dialplan();
                $dialplan->domain_uuid = $domain_uuid;
                $dialplan->dialplan_uuid = $dialplan_uuid;
                $dialplan->dialplan_detail_tag = 'condition';
                //condition, action, antiaction
                $dialplan->dialplan_detail_type = 'destination_number';
                $dialplan->dialplan_detail_data = '^' . $row['hunt_group_extension'] . '$';
                //$dialplan->dialplan_detail_break = '';
                //$dialplan->dialplan_detail_inline = '';
                $dialplan->dialplan_detail_group = '1';
                $dialplan->dialplan_detail_order = '010';
                $dialplan->dialplan_detail_add();
                unset($dialplan);
                $dialplan = new dialplan();
                $dialplan->domain_uuid = $domain_uuid;
                $dialplan->dialplan_uuid = $dialplan_uuid;
                $dialplan->dialplan_detail_tag = 'action';
                //condition, action, antiaction
                $dialplan->dialplan_detail_type = 'lua';
                $dialplan->dialplan_detail_data = 'v_huntgroup_' . $_SESSION['domains'][$domain_uuid]['domain_name'] . '_' . $row['hunt_group_extension'] . '.lua';
                //$dialplan->dialplan_detail_break = '';
                //$dialplan->dialplan_detail_inline = '';
                $dialplan->dialplan_detail_group = '1';
                $dialplan->dialplan_detail_order = '020';
                $dialplan->dialplan_detail_add();
                unset($dialplan);
                $dialplan = new dialplan();
                $dialplan->domain_uuid = $domain_uuid;
                $dialplan->dialplan_uuid = $dialplan_uuid;
                $dialplan->dialplan_detail_tag = 'condition';
                //condition, action, antiaction
                $dialplan->dialplan_detail_type = 'destination_number';
                $dialplan->dialplan_detail_data = '^\\*' . $row['hunt_group_extension'] . '$';
                $dialplan->dialplan_detail_break = 'on-true';
                //$dialplan->dialplan_detail_inline = '';
                $dialplan->dialplan_detail_group = '2';
                $dialplan->dialplan_detail_order = '020';
                $dialplan->dialplan_detail_add();
                unset($dialplan);
                $dialplan = new dialplan();
                $dialplan->domain_uuid = $domain_uuid;
                $dialplan->dialplan_uuid = $dialplan_uuid;
                $dialplan->dialplan_detail_tag = 'action';
                //condition, action, antiaction
                $dialplan->dialplan_detail_type = 'set';
                $dialplan->dialplan_detail_data = 'fifo_music=$${hold_music}';
                //$dialplan->dialplan_detail_break = '';
                //$dialplan->dialplan_detail_inline = '';
                $dialplan->dialplan_detail_group = '2';
                $dialplan->dialplan_detail_order = '020';
                $dialplan->dialplan_detail_add();
                unset($dialplan);
                $hunt_group_timeout_type = $row['hunt_group_timeout_type'];
                $hunt_group_timeout_destination = $row['hunt_group_timeout_destination'];
                if ($hunt_group_timeout_type == "voicemail") {
                    $hunt_group_timeout_destination = '*99' . $hunt_group_timeout_destination;
                }
                $dialplan = new dialplan();
                $dialplan->domain_uuid = $domain_uuid;
                $dialplan->dialplan_uuid = $dialplan_uuid;
                $dialplan->dialplan_detail_tag = 'action';
                //condition, action, antiaction
                $dialplan->dialplan_detail_type = 'set';
                $dialplan->dialplan_detail_data = 'fifo_orbit_exten=' . $hunt_group_timeout_destination . ':' . $row['hunt_group_timeout'];
                //$dialplan->dialplan_detail_break = '';
                //$dialplan->dialplan_detail_inline = '';
                $dialplan->dialplan_detail_group = '2';
                $dialplan->dialplan_detail_order = '030';
                $dialplan->dialplan_detail_add();
                unset($dialplan);
                $dialplan = new dialplan();
                $dialplan->domain_uuid = $domain_uuid;
                $dialplan->dialplan_uuid = $dialplan_uuid;
                $dialplan->dialplan_detail_tag = 'action';
                //condition, action, antiaction
                $dialplan->dialplan_detail_type = 'fifo';
                $dialplan->dialplan_detail_data = $row['hunt_group_extension'] . '@${domain_name} in';
                //$dialplan->dialplan_detail_break = '';
                //$dialplan->dialplan_detail_inline = '';
                $dialplan->dialplan_detail_group = '2';
                $dialplan->dialplan_detail_order = '040';
                $dialplan->dialplan_detail_add();
                unset($dialplan);
            }
        }
        //end if strlen hunt_group_uuid; add the Hunt Group to the dialplan
        //get the list of destinations then build the Hunt Group Lua
        $tmp = "\n";
        $tmp .= "session:preAnswer();\n";
        $tmp .= "extension = '" . $row['hunt_group_extension'] . "';\n";
        $tmp .= "result = '';\n";
        $tmp .= "timeoutpin = 7500;\n";
        $tmp .= "sip_profile = 'internal';\n";
        $tmp .= "\n";
        $tmp .= "function extension_registered(domain_name, sip_profile, extension)\n";
        $tmp .= "\tapi = freeswitch.API();\n";
        $tmp .= "\tresult = api:execute(\"sofia_contact\", sip_profile..\"/\"..extension..\"@\"..domain_name);\n";
        $tmp .= "\tif (result == \"error/user_not_registered\") then\n";
        $tmp .= "\t\treturn false;\n";
        $tmp .= "\telse\n";
        $tmp .= "\t\treturn true;\n";
        $tmp .= "\tend\n";
        $tmp .= "end\n";
        $tmp .= "\n";
        $tmp .= "\n";
        $tmp .= "sounds_dir = session:getVariable(\"sounds_dir\");\n";
        $tmp .= "uuid = session:getVariable(\"uuid\");\n";
        $tmp .= "dialed_extension = session:getVariable(\"dialed_extension\");\n";
        $tmp .= "domain_name = session:getVariable(\"domain_name\");\n";
        $tmp .= "caller_id_name = session:getVariable(\"caller_id_name\");\n";
        $tmp .= "caller_id_number = session:getVariable(\"caller_id_number\");\n";
        $tmp .= "outbound_caller_id_name = session:getVariable(\"outbound_caller_id_name\");\n";
        $tmp .= "outbound_caller_id_number = session:getVariable(\"outbound_caller_id_number\");\n";
        $tmp .= "\n";
        $tmp .= "--set the sounds path for the language, dialect and voice\n";
        $tmp .= "\tdefault_language = session:getVariable(\"default_language\");\n";
        $tmp .= "\tdefault_dialect = session:getVariable(\"default_dialect\");\n";
        $tmp .= "\tdefault_voice = session:getVariable(\"default_voice\");\n";
        $tmp .= "\tif (not default_language) then default_language = 'en'; end\n";
        $tmp .= "\tif (not default_dialect) then default_dialect = 'us'; end\n";
        $tmp .= "\tif (not default_voice) then default_voice = 'callie'; end\n";
        $tmp .= "\n";
        //pin number requested from caller if provided
        if (strlen($row['hunt_group_pin']) > 0) {
            $tmp .= "pin = '" . $row['hunt_group_pin'] . "';\n";
            $tmp .= "digits = session:playAndGetDigits(" . strlen($row['hunt_group_pin']) . ", " . strlen($row['hunt_group_pin']) . ", 3, 3000, \"#\", sounds_dir..\"/\"..default_language..\"/\"..default_dialect..\"/\"..default_voice..\"/custom/please_enter_the_pin_number.wav\", \"\", \"\\\\d+\");\n";
            $tmp .= "\n";
            $tmp .= "\n";
            $tmp .= "if (digits == pin) then\n";
            $tmp .= "\t--continue\n";
            $tmp .= "\n";
        }
        //caller announce requested from caller if provided
        if ($row['hunt_group_caller_announce'] == "true" || $row['hunt_group_call_prompt'] == "true") {
            if ($row['hunt_group_caller_announce'] == "true") {
                $tmp .= "function originate(domain_name, session, sipuri, extension, caller_id_name, caller_id_number, caller_announce) \n";
            } else {
                $tmp .= "function originate(domain_name, session, sipuri, extension, caller_id_name, caller_id_number) \n";
            }
            $tmp .= "\t--caller_id_name = caller_id_name.replace(\" \", \"..\");\n";
            $tmp .= "\tcaller_id_name = string.gsub(caller_id_name, \" \", \"..\");\n";
            //$tmp .=	"	--session:execute(\"luarun\", \"huntgroup_originate.lua \"..domain_name..\" \"..uuid..\" \"..sipuri..\" \"..extension..\" \"..caller_id_name..\" \"..caller_id_number..\" \"..caller_announce);\n";
            $tmp .= "\tapi = freeswitch.API();\n";
            if ($row['hunt_group_caller_announce'] == "true") {
                $tmp .= "\tresult = api:execute(\"luarun\", \"huntgroup_originate.lua \"..domain_name..\" \"..uuid..\" \"..sipuri..\" \"..extension..\" \"..caller_id_name..\" \"..caller_id_number..\" \"..caller_announce);\n";
            } else {
                $tmp .= "\tresult = api:execute(\"luarun\", \"huntgroup_originate.lua \"..domain_name..\" \"..uuid..\" \"..sipuri..\" \"..extension..\" \"..caller_id_name..\" \"..caller_id_number..\"\");\n";
            }
            $tmp .= "end";
            $tmp .= "\n";
            if ($row['hunt_group_caller_announce'] == "true") {
                $tmp .= "caller_announce = \"" . $tmp_dir . "/\"..extension..\"_\"..uuid..\".wav\";\n";
                $tmp .= "session:streamFile(sounds_dir..\"/\"..default_language..\"/\"..default_dialect..\"/\"..default_voice..\"/custom/please_say_your_name_and_reason_for_calling.wav\");\n";
                $tmp .= "session:execute(\"gentones\", \"%(1000, 0, 640)\");\n";
                $tmp .= "session:execute(\"set\", \"playback_terminators=#\");\n";
                $tmp .= "session:execute(\"record\", caller_announce..\" 180 200\");\n";
            }
            $tmp .= "\n";
            $tmp .= "session:setAutoHangup(false);\n";
            $tmp .= "session:execute(\"transfer\", \"*\"..extension..\" XML " . $_SESSION["context"] . "\");\n";
            $tmp .= "\n";
        }
        //set caller id
        if (strlen($row['hunt_group_cid_name_prefix']) > 0) {
            $tmp .= "session:execute(\"set\", \"effective_caller_id_name=" . $row['hunt_group_cid_name_prefix'] . "#\"..caller_id_name);\n";
            $tmp .= "session:execute(\"set\", \"outbound_caller_id_name=" . $row['hunt_group_cid_name_prefix'] . "#\"..caller_id_name);\n";
        }
        //set ring back
        if (isset($row['hunt_group_ringback'])) {
            if ($row['hunt_group_ringback'] == "music") {
                $tmp .= "session:execute(\"set\", \"ringback=\${hold_music}\");          --set to music\n";
                $tmp .= "session:execute(\"set\", \"transfer_ringback=\${hold_music}\"); --set to music\n";
            } else {
                $tmp .= "session:execute(\"set\", \"ringback=" . $row['hunt_group_ringback'] . "\"); --set to ringtone\n";
                $tmp .= "session:execute(\"set\", \"transfer_ringback=" . $row['hunt_group_ringback'] . "\"); --set to ringtone\n";
            }
            if ($row['hunt_group_ringback'] == "ring") {
                $tmp .= "session:execute(\"set\", \"ringback=\${us-ring}\"); --set to ringtone\n";
                $tmp .= "session:execute(\"set\", \"transfer_ringback=\${us-ring}\"); --set to ringtone\n";
            }
        } else {
            $tmp .= "session:execute(\"set\", \"ringback=\${hold_music}\");          --set to ringtone\n";
            $tmp .= "session:execute(\"set\", \"transfer_ringback=\${hold_music}\"); --set to ringtone\n";
        }
        if ($row['hunt_group_timeout'] > 0) {
            //$tmp .= "session:setVariable(\"call_timeout\", \"".$row['hunt_group_timeout']."\");\n";
            $tmp .= "session:setVariable(\"continue_on_fail\", \"true\");\n";
        }
        $tmp .= "session:setVariable(\"hangup_after_bridge\", \"true\");\n";
        $tmp .= "\n";
        $tmp .= "--freeswitch.consoleLog( \"info\", \"dialed extension:\"..dialed_extension..\"\\n\" );\n";
        $tmp .= "--freeswitch.consoleLog( \"info\", \"domain: \"..domain..\"\\n\" );\n";
        $tmp .= "--freeswitch.consoleLog( \"info\", \"us_ring: \"..us_ring..\"\\n\" );\n";
        $tmp .= "--freeswitch.consoleLog( \"info\", \"domain_name: \"..domain_name..\"\\n\" );\n";
        $tmp .= "\n";
        $tmp .= "--freeswitch.consoleLog( \"info\", \"action call now don't wait for dtmf\\n\" );\n";
        if ($row['hunt_group_caller_announce'] == "true" || $row['hunt_group_call_prompt'] == "true") {
            //do nothing
        } else {
            $tmp .= "if session:ready() then\n";
            //$tmp .= "	session.answer();\n";
        }
        $tmp .= "\n";
        $i = 0;
        $sql = "select * from v_hunt_group_destinations ";
        $sql .= "where hunt_group_uuid = '" . $row['hunt_group_uuid'] . "' ";
        $sql .= "and domain_uuid = '{$domain_uuid}' ";
        //$sql .= "and destination_enabled = 'true' ";
        $sql .= "order by destination_order asc ";
        $prep_statement_2 = $db->prepare($sql);
        $prep_statement_2->execute();
        while ($ent = $prep_statement_2->fetch(PDO::FETCH_ASSOC)) {
            //$ent['hunt_group_uuid']
            //$ent['destination_data']
            //$ent['destination_type']
            //$ent['destination_profile']
            //$ent['destination_order']
            //$ent['destination_enabled']
            //$ent['destination_description']
            $destination_timeout = $ent['destination_timeout'];
            $hunt_group_cid_name_prefix = $row['hunt_group_cid_name_prefix'];
            if (strlen($hunt_group_cid_name_prefix) > 0) {
                $hunt_group_cid_name_prefix .= "#";
            }
            if (strlen($destination_timeout) == 0) {
                if (strlen($row['hunt_group_timeout']) == 0) {
                    $destination_timeout = '30';
                } else {
                    $destination_timeout = $row['hunt_group_timeout'];
                }
            }
            //set the default profile
            if (strlen($ent['destination_data']) == 0) {
                $ent['destination_data'] = "internal";
            }
            if ($ent['destination_type'] == "extension") {
                //$tmp .= "	sofia_contact_".$ent['destination_data']." = \"\${sofia_contact(".$ent['destination_profile']."/".$ent['destination_data']."@\"..domain_name..\")}\";\n";
                $tmp_sub_array["application"] = "bridge";
                $tmp_sub_array["type"] = "extension";
                $tmp_sub_array["extension"] = $ent['destination_data'];
                //$tmp_sub_array["data"] = "\"[leg_timeout=$destination_timeout]\"..sofia_contact_".$ent['destination_data'];
                $tmp_sub_array["data"] = "\"[leg_timeout={$destination_timeout},origination_caller_id_name='" . $hunt_group_cid_name_prefix . "\"..caller_id_name..\"',origination_caller_id_number=\"..caller_id_number..\"]user/" . $ent['destination_data'] . "@\"..domain_name";
                $tmp_array[$i] = $tmp_sub_array;
                unset($tmp_sub_array);
            }
            if ($ent['destination_type'] == "voicemail") {
                $tmp_sub_array["application"] = "voicemail";
                $tmp_sub_array["type"] = "voicemail";
                $tmp .= "\tsession:answer();\n";
                $tmp .= "\tsession:execute(\"transfer\", \"*99" . $ent['destination_data'] . " XML " . $_SESSION["context"] . " \");\n";
                //$tmp_sub_array["application"] = "voicemail";
                //$tmp_sub_array["data"] = "default \${domain_name} ".$ent['destination_data'];
                //$tmp_array[$i] = $tmp_sub_array;
                unset($tmp_sub_array);
            }
            if ($ent['destination_type'] == "sip uri") {
                $tmp_sub_array["application"] = "bridge";
                $tmp_sub_array["type"] = "sip uri";
                //$destination_data = "{user=foo}loopback/".$ent['destination_data']."/default/XML";
                $bridge_array = outbound_route_to_bridge($domain_uuid, $ent['destination_data']);
                $destination_data = $bridge_array[0];
                $tmp_sub_array["application"] = "bridge";
                $tmp_sub_array["data"] = "\"[leg_timeout={$destination_timeout},origination_caller_id_name='" . $hunt_group_cid_name_prefix . "\"..caller_id_name..\"',origination_caller_id_number=\"..caller_id_number..\"]" . $destination_data . "\"";
                $tmp_array[$i] = $tmp_sub_array;
                unset($tmp_sub_array);
                unset($destination_data);
            }
            $i++;
        }
        //end while
        unset($sql, $prep_statement_2);
        unset($i, $ent);
        $i = 0;
        if (count($tmp_array) > 0) {
            foreach ($tmp_array as $ent) {
                $tmpdata = $ent["data"];
                if ($ent["application"] == "voicemail") {
                    $tmpdata = "*99" . $tmpdata;
                }
                if ($i < 1) {
                    $tmp_buffer = $tmpdata;
                } else {
                    $tmp_buffer .= "..\",\".." . $tmpdata;
                }
                $i++;
            }
        }
        unset($i);
        $tmp_application = $tmp_array[0]["application"];
        if ($row['hunt_group_type'] == "simultaneous" || $row['hunt_group_type'] == "follow_me_simultaneous" || $row['hunt_group_type'] == "call_forward") {
            $tmp_switch = "simultaneous";
        }
        if ($row['hunt_group_type'] == "sequence" || $row['hunt_group_type'] == "follow_me_sequence" || $row['hunt_group_type'] == "sequentially") {
            $tmp_switch = "sequence";
        }
        switch ($tmp_switch) {
            case "simultaneous":
                if ($row['hunt_group_caller_announce'] == "true" || $row['hunt_group_call_prompt'] == "true") {
                    $i = 0;
                    if (count($tmp_array) > 0) {
                        foreach ($tmp_array as $tmp_row) {
                            $tmpdata = $tmp_row["data"];
                            if ($tmp_row["application"] == "voicemail") {
                                $tmpdata = "*99" . $tmpdata;
                            } else {
                                if ($tmp_row["type"] == "extension") {
                                    $tmp .= "if (extension_registered(domain_name, sip_profile, '" . $tmp_row["extension"] . "')) then\n";
                                    $tmp .= "\t";
                                }
                                if ($row['hunt_group_caller_announce'] == "true") {
                                    $tmp .= "result = originate (domain_name, session, " . $tmpdata . ", extension, caller_id_name, caller_id_number, caller_announce);\n";
                                } else {
                                    $tmp .= "result = originate (domain_name, session, " . $tmpdata . ", extension, caller_id_name, caller_id_number);\n";
                                }
                                if ($tmp_row["type"] == "extension") {
                                    $tmp .= "end\n";
                                }
                            }
                        }
                    }
                } else {
                    $tmp .= "\n";
                    if (strlen($tmp_buffer) > 0) {
                        $tmp .= "\tsession:execute(\"" . $tmp_application . "\", {$tmp_buffer});\n";
                    }
                }
                break;
            case "sequence":
                $tmp .= "\n";
                $i = 0;
                if (count($tmp_array) > 0) {
                    if ($row['hunt_group_caller_announce'] == "true" || $row['hunt_group_call_prompt'] == "true") {
                        $i = 0;
                        if (count($tmp_array) > 0) {
                            foreach ($tmp_array as $tmp_row) {
                                $tmpdata = $tmp_row["data"];
                                if ($tmp_row["application"] == "voicemail") {
                                    $tmpdata = "*99" . $tmpdata;
                                } else {
                                    if ($tmp_row["type"] == "extension") {
                                        $tmp .= "if (extension_registered(domain_name, sip_profile, '" . $tmp_row["extension"] . "')) then\n";
                                        $tmp .= "\t";
                                    }
                                    if ($row['hunt_group_caller_announce'] == "true") {
                                        $tmp .= "result = originate (domain_name, session, " . $tmpdata . ", extension, caller_id_name, caller_id_number, caller_announce);\n";
                                    } else {
                                        $tmp .= "result = originate (domain_name, session, " . $tmpdata . ", extension, caller_id_name, caller_id_number);\n";
                                    }
                                    if ($tmp_row["type"] == "extension") {
                                        $tmp .= "end\n";
                                    }
                                }
                            }
                        }
                    } else {
                        foreach ($tmp_array as $tmp_row) {
                            if (strlen($tmp_row["data"]) > 0) {
                                $tmp .= "\tsession:execute(\"" . $tmp_application . "\", " . $tmp_row["data"] . ");\n";
                            }
                        }
                    }
                    unset($tmp_row);
                }
                break;
        }
        unset($tmp_switch, $tmp_buffer, $tmp_array);
        //set the timeout destination
        $hunt_group_timeout_destination = $row['hunt_group_timeout_destination'];
        if ($row['hunt_group_timeout_type'] == "extension") {
            $hunt_group_timeout_type = "transfer";
        }
        if ($row['hunt_group_timeout_type'] == "voicemail") {
            $hunt_group_timeout_type = "transfer";
            $hunt_group_timeout_destination = "*99" . $hunt_group_timeout_destination . " XML " . $_SESSION["context"];
        }
        if ($row['hunt_group_timeout_type'] == "sip uri") {
            $hunt_group_timeout_type = "bridge";
        }
        $tmp .= "\n";
        if ($row['hunt_group_caller_announce'] == "true" || $row['hunt_group_call_prompt'] == "true") {
            //do nothing
        } else {
            $tmp .= "\t--timeout\n";
            if ($row['hunt_group_type'] != 'dnd') {
                $tmp .= "\toriginate_disposition = session:getVariable(\"originate_disposition\");\n";
                $tmp .= "\tif originate_disposition ~= \"SUCCESS\" then\n";
            }
            if ($row['hunt_group_timeout_type'] == "voicemail") {
                $tmp .= "\t\t\tsession:answer();\n";
            }
            $tmp .= "\t\t\tsession:execute(\"" . $hunt_group_timeout_type . "\", \"" . $hunt_group_timeout_destination . "\");\n";
            if ($row['hunt_group_type'] != 'dnd') {
                $tmp .= "\tend\n";
            }
        }
        if ($row['hunt_group_caller_announce'] == "true" || $row['hunt_group_call_prompt'] == "true") {
            //do nothing
        } else {
            $tmp .= "end --end if session:ready\n";
        }
        $tmp .= "\n";
        //pin number requested from caller if provided
        if (strlen($row['hunt_group_pin']) > 0) {
            $tmp .= "else \n";
            $tmp .= "\tsession:streamFile(sounds_dir..\"/\"..default_language..\"/\"..default_dialect..\"/\"..default_voice..\"/custom/your_pin_number_is_incorect_goodbye.wav\");\n";
            $tmp .= "\tsession:hangup();\n";
            $tmp .= "end\n";
            $tmp .= "\n";
        }
        //unset variables
        $tmp .= "\n";
        $tmp .= "--clear variables\n";
        $tmp .= "dialed_extension = \"\";\n";
        $tmp .= "new_extension = \"\";\n";
        $tmp .= "domain_name = \"\";\n";
        $tmp .= "\n";
        //remove invalid characters from the file names
        $huntgroup_extension = $row['hunt_group_extension'];
        $huntgroup_extension = str_replace(" ", "_", $huntgroup_extension);
        $huntgroup_extension = preg_replace("/[\\*\\:\\/\\<\\>\\|\\'\"\\?]/", "", $huntgroup_extension);
        //write the hungroup lua script
        if (strlen($row['hunt_group_extension']) > 0) {
            if ($row['hunt_group_enabled'] != "false") {
                $hunt_group_filename = "v_huntgroup_" . $_SESSION['domains'][$domain_uuid]['domain_name'] . "_" . $huntgroup_extension . ".lua";
                //echo "location".$_SESSION['switch']['scripts']['dir']."/".$hunt_group_filename;
                $fout = fopen($_SESSION['switch']['scripts']['dir'] . "/" . $hunt_group_filename, "w");
                fwrite($fout, $tmp);
                unset($hunt_group_filename);
                fclose($fout);
            }
        }
    }
    //end while
    //save the dialplan xml files
    save_dialplan_xml();
}
Example #8
0
 protected function copy_conf()
 {
     $this->write_progress("\tCopying Config");
     //make a backup of the config
     if (file_exists($this->global_settings->switch_conf_dir())) {
         $this->backup_dir($this->global_settings->switch_conf_dir(), 'fusionpbx_switch_config');
         recursive_delete($this->global_settings->switch_conf_dir());
     }
     //make sure the conf directory exists
     if (!is_dir($this->global_settings->switch_conf_dir())) {
         if (!mkdir($this->global_settings->switch_conf_dir(), 0774, true)) {
             throw new Exception("Failed to create the switch conf directory '" . $this->global_settings->switch_conf_dir() . "'. ");
         }
     }
     //copy resources/templates/conf to the freeswitch conf dir
     if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')) {
         $src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
     } else {
         $src_dir = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/resources/templates/conf";
     }
     $dst_dir = $this->global_settings->switch_conf_dir();
     if (is_readable($dst_dir)) {
         recursive_copy($src_dir, $dst_dir);
         unset($src_dir, $dst_dir);
     }
     $fax_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'fax'));
     if (!is_readable($fax_dir)) {
         mkdir($fax_dir, 0777, true);
     }
     $voicemail_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_storage_dir(), 'voicemail'));
     if (!is_readable($voicemail_dir)) {
         mkdir($voicemail_dir, 0777, true);
     }
     //create the dialplan/default.xml for single tenant or dialplan/domain.xml
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/dialplan")) {
         $dialplan = new dialplan();
         $dialplan->domain_uuid = $this->domain_uuid;
         $dialplan->domain = $this->domain_name;
         $dialplan->switch_dialplan_dir = join(DIRECTORY_SEPARATOR, array($this->global_settings->switch_conf_dir(), "/dialplan"));
         $dialplan->restore_advanced_xml();
         if ($this->_debug) {
             print_r($dialplan->result, $message);
             $this->write_debug($message);
         }
     }
     //write the xml_cdr.conf.xml file
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/xml_cdr")) {
         xml_cdr_conf_xml();
     }
     //write the switch.conf.xml file
     if (file_exists($this->global_settings->switch_conf_dir())) {
         switch_conf_xml();
     }
 }
Example #9
0
 unset($dialplan);
 //<action application="set" data="ringback=${us-ring}"/>
 //$dialplan = new dialplan;
 //$dialplan->domain_uuid = $domain_uuid;
 //$dialplan->dialplan_uuid = $dialplan_uuid;
 //$dialplan->dialplan_detail_tag = 'action'; //condition, action, antiaction
 //$dialplan->dialplan_detail_type = 'set';
 //$dialplan->dialplan_detail_data = 'ringback=${us-ring}';
 //$dialplan->dialplan_detail_break = '';
 //$dialplan->dialplan_detail_inline = '';
 //$dialplan->dialplan_detail_group = '2';
 //$dialplan->dialplan_detail_order = '020';
 //$dialplan->dialplan_detail_add();
 //unset($dialplan);
 //<action application="lua" data="call_flow.lua"/>
 $dialplan = new dialplan();
 $dialplan->domain_uuid = $domain_uuid;
 $dialplan->dialplan_uuid = $dialplan_uuid;
 $dialplan->dialplan_detail_tag = 'action';
 //condition, action, antiaction
 $dialplan->dialplan_detail_type = 'lua';
 //$dialplan->dialplan_detail_data = $call_flow_extension . ' LUA call_flow.lua';
 $dialplan->dialplan_detail_data = 'call_flow.lua';
 //$dialplan->dialplan_detail_break = '';
 //$dialplan->dialplan_detail_inline = '';
 $dialplan->dialplan_detail_group = '2';
 $dialplan->dialplan_detail_order = '030';
 $dialplan->dialplan_detail_add();
 unset($dialplan);
 //save the xml
 save_dialplan_xml();
Example #10
0
 /**
  * Indicate we support Asterisk with this SIP Device and provide code to save SIP device specific settings
  */
 public static function set($base)
 {
     kohana::log('debug', 'Asterisk -> Create a context dialplan for id ' . $base['context_id']);
     $doc = Telephony::getDriver()->doc;
     // Create the context we're going to start routing at. This just does pre-call setup routines
     // In Asterisk land this ensures a [context_X] exists and has, at minimum, a NoOp() at the top
     // and a GoSub to our actual list of available numbers
     $doc->createRoutableContext($base['context_id']);
     // THE ABOVE TWO LINES SHOULD RESULT IN:
     // [context_1]
     // exten => _X,NoOp()        ; added by dialplanStart
     // exten => _X,n,network-stuff
     // exten => _X,n,conditioning-stuff
     // exten => _X,n,blah
     // exten => _X,n,Gosub(destinations_1) ; added by diaplanEnd
     // exten => _X,n,FinishUpCallHooks   ; diaplanEnd hooks
     // exten => _X,n,Hangup()
     //
     // [context_1_destinations]
     //
     // THAT'S IT. It will delete and recreate the context_1 section but not destinations_1. This LOGIC belongs elsewhere, NOT HERE.
     // Does this number go anywhere?
     if ($base['Number']['class_type']) {
         $dialplan = $base['Number']['dialplan'];
         // Create the exten => 3000,Goto(number_X)  or whatever in the [destinations] list so we can actually reach this guy via the current context
         // This also sets some internal variable that tracks our current number and context (for use by the next few items) and
         // also creates a dummy [number_X] section
         // NOTE: This also sets a pointer in memory for the preNumber, actual dialplan and postNumber routines to use
         // too add their "stuff" to this dialplan entry
         //$doc->createDestination($base['context_id'], $base['Number']['number_id'], $base['Number']['number']);
         $doc->createDialplanExtension($base['context_id'], $base['Number']['number_id'], $base['Number']['number']);
         // Make sure the extensions list for this context exists
         $doc->createContext('extensions.conf', 'extensions_' . $base['context_id'], $base['Number']['number']);
         // Delete any existing references to this particular extension number in the extensions list
         $doc->deleteDialplanExtension($base['context_id'], $base['Number']['number']);
         // Add a NoOp at the top of all numbers
         $doc->add('NoOp', 1, array('replace' => TRUE));
         // Add an extension-specific prenumber items
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the number_X section
         dialplan::preNumber($base['Number']);
         // Replace nay matching extension definitions
         $doc->add('GoSub(number_' . $base['Number']['number_id'] . ',${EXTEN},1)', NULL, array('replace' => TRUE));
         // Add a failure route for this dialplan
         // Note that unlike other dialplan adds, this one assumes you're already in the right spot in the dialplan
         dialplan::postNumber($base['Number']);
         if (!empty($dialplan['terminate']['action'])) {
             switch ($dialplan['terminate']['action']) {
                 case 'transfer':
                     if ($transfer = astrsk::getTransferToNumber($dialplan['terminate']['transfer'])) {
                         $doc->add('Goto(' . $transfer . ')');
                     } else {
                         $doc->add('Hangup');
                     }
                     break;
                 case 'continue':
                     $doc->add('Return');
                     break;
                 case 'hangup':
                 default:
                     $doc->add('Hangup');
                     break;
             }
         } else {
             $doc->add('Hangup');
         }
         $doc->createContext('extensions.conf', 'number_' . $base['Number']['number_id'], NULL, array('replace' => TRUE));
         // Add related final destination XML
         $destinationDriverName = Telephony::getDriverName() . '_' . substr($base['Number']['class_type'], 0, strlen($base['Number']['class_type']) - 6) . '_Driver';
         Kohana::log('debug', 'Asterisk -> Looking for destination driver ' . $destinationDriverName);
         // Is there a driver?
         if (class_exists($destinationDriverName, TRUE)) {
             // Logging
             Kohana::log('debug', 'Asterisk -> Adding information for destination ' . $base['Number']['number_id'] . ' from model "' . get_class($base['Number']) . '" to our telephony configuration...');
             // Drivers are always singletons, and are responsible for persistenting data for their own config generation via static vars
             // TODO: Change this for PHP 5.3, which doesn't require eval(). Don't change this until all the cool kids are on PHP 5.3*/
             kohana::log('debug', 'Asterisk -> EVAL ' . $destinationDriverName . '::dialplan($base->Number);');
             // Drivers are always singletons, and are responsible for persistenting data for their own config generation via static vars
             // TODO: Change this for PHP 5.3, which doesn't require eval(). Don't change this until all the cool kids are on PHP 5.3*/
             $success = eval('return ' . $destinationDriverName . '::dialplan($base->Number);');
         }
         $doc->add('Return');
         return TRUE;
     } else {
         kohana::log('debug', 'Asterisk -> REMOVING NUMBER ID ' . $base['Number']['number_id'] . ' FROM CONTEXT ' . $base['context_id']);
         // Number doesn't go anywhere - delete it altogether.
         $doc->deleteDialplanExtension($base['context_id'], $base['Number']['number']);
     }
     return FALSE;
 }
Example #11
0
 function save_call_center_xml()
 {
     global $db, $domain_uuid;
     if (strlen($_SESSION['switch']['call_center']['dir']) > 0) {
         //include the classes
         include "app/dialplan/resources/classes/dialplan.php";
         $sql = "select * from v_call_center_queues ";
         $prep_statement = $db->prepare(check_sql($sql));
         $prep_statement->execute();
         $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
         $result_count = count($result);
         unset($prep_statement, $sql);
         if ($result_count > 0) {
             foreach ($result as $row) {
                 //set the variables
                 $call_center_queue_uuid = $row["call_center_queue_uuid"];
                 $domain_uuid = $row["domain_uuid"];
                 $dialplan_uuid = $row["dialplan_uuid"];
                 $queue_name = check_str($row["queue_name"]);
                 $queue_extension = $row["queue_extension"];
                 $queue_strategy = $row["queue_strategy"];
                 $queue_moh_sound = $row["queue_moh_sound"];
                 $queue_record_template = $row["queue_record_template"];
                 $queue_time_base_score = $row["queue_time_base_score"];
                 $queue_max_wait_time = $row["queue_max_wait_time"];
                 $queue_max_wait_time_with_no_agent = $row["queue_max_wait_time_with_no_agent"];
                 $queue_tier_rules_apply = $row["queue_tier_rules_apply"];
                 $queue_tier_rule_wait_second = $row["queue_tier_rule_wait_second"];
                 $queue_tier_rule_wait_multiply_level = $row["queue_tier_rule_wait_multiply_level"];
                 $queue_tier_rule_no_agent_no_wait = $row["queue_tier_rule_no_agent_no_wait"];
                 $queue_timeout_action = $row["queue_timeout_action"];
                 $queue_discard_abandoned_after = $row["queue_discard_abandoned_after"];
                 $queue_abandoned_resume_allowed = $row["queue_abandoned_resume_allowed"];
                 $queue_cid_prefix = $row["queue_cid_prefix"];
                 $queue_announce_sound = $row["queue_announce_sound"];
                 $queue_announce_frequency = $row["queue_announce_frequency"];
                 $queue_description = check_str($row["queue_description"]);
                 //replace space with an underscore
                 $queue_name = str_replace(" ", "_", $queue_name);
                 //add each Queue to the dialplan
                 if (strlen($row['call_center_queue_uuid']) > 0) {
                     $action = 'add';
                     //set default action to add
                     $i = 0;
                     //determine the action add or update
                     if (strlen($dialplan_uuid) > 0) {
                         $sql = "select * from v_dialplans ";
                         $sql .= "where dialplan_uuid = '" . $dialplan_uuid . "' ";
                         $prep_statement_2 = $db->prepare($sql);
                         $prep_statement_2->execute();
                         while ($row2 = $prep_statement_2->fetch(PDO::FETCH_ASSOC)) {
                             $action = 'update';
                         }
                         unset($sql, $prep_statement_2);
                     }
                     if ($action == 'add') {
                         //create queue entry in the dialplan
                         $dialplan_name = $queue_name;
                         $dialplan_order = '210';
                         $dialplan_context = $_SESSION['context'];
                         $dialplan_enabled = 'true';
                         $dialplan_description = $queue_description;
                         $app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
                         $dialplan_uuid = uuid();
                         dialplan_add($domain_uuid, $dialplan_uuid, $dialplan_name, $dialplan_order, $dialplan_context, $dialplan_enabled, $dialplan_description, $app_uuid);
                         //add the dialplan_uuid to the call center table
                         $sql = "update v_call_center_queues set ";
                         $sql .= "dialplan_uuid = '{$dialplan_uuid}' ";
                         $sql .= "where domain_uuid = '{$domain_uuid}' ";
                         $sql .= "and call_center_queue_uuid = '" . $row['call_center_queue_uuid'] . "' ";
                         $db->exec(check_sql($sql));
                         unset($sql);
                     }
                     if ($action == 'update') {
                         //add the dialplan_uuid to the call center table
                         $sql = "update v_dialplans set ";
                         $sql .= "dialplan_name = '" . $queue_name . "', ";
                         $sql .= "dialplan_description = '" . $queue_description . "' ";
                         $sql .= "where domain_uuid = '" . $domain_uuid . "' ";
                         $sql .= "and dialplan_uuid = '" . $dialplan_uuid . "' ";
                         $db->exec(check_sql($sql));
                         unset($sql);
                         //add the dialplan_uuid to the call center table
                         $sql = "delete from v_dialplan_details ";
                         $sql .= "where domain_uuid = '{$domain_uuid}' ";
                         $sql .= "and dialplan_uuid = '{$dialplan_uuid}' ";
                         $db->exec(check_sql($sql));
                         unset($sql);
                     }
                     //group 1
                     $dialplan = new dialplan();
                     $dialplan->domain_uuid = $domain_uuid;
                     $dialplan->dialplan_uuid = $dialplan_uuid;
                     $dialplan->dialplan_detail_tag = 'condition';
                     //condition, action, antiaction
                     $dialplan->dialplan_detail_type = '${caller_id_name}';
                     $dialplan->dialplan_detail_data = '^([^#]+#)(.*)$';
                     $dialplan->dialplan_detail_break = 'never';
                     $dialplan->dialplan_detail_inline = '';
                     $dialplan->dialplan_detail_group = '1';
                     $dialplan->dialplan_detail_order = '010';
                     $dialplan->dialplan_detail_add();
                     unset($dialplan);
                     $dialplan = new dialplan();
                     $dialplan->domain_uuid = $domain_uuid;
                     $dialplan->dialplan_uuid = $dialplan_uuid;
                     $dialplan->dialplan_detail_tag = 'action';
                     //condition, action, antiaction
                     $dialplan->dialplan_detail_type = 'set';
                     $dialplan->dialplan_detail_data = 'caller_id_name=$2';
                     $dialplan->dialplan_detail_break = '';
                     $dialplan->dialplan_detail_inline = '';
                     $dialplan->dialplan_detail_group = '1';
                     $dialplan->dialplan_detail_order = '020';
                     $dialplan->dialplan_detail_add();
                     unset($dialplan);
                     //group 2
                     $dialplan = new dialplan();
                     $dialplan->domain_uuid = $domain_uuid;
                     $dialplan->dialplan_uuid = $dialplan_uuid;
                     $dialplan->dialplan_detail_tag = 'condition';
                     //condition, action, antiaction
                     $dialplan->dialplan_detail_type = 'destination_number';
                     $dialplan->dialplan_detail_data = '^' . $row['queue_extension'] . '$';
                     $dialplan->dialplan_detail_break = '';
                     $dialplan->dialplan_detail_inline = '';
                     $dialplan->dialplan_detail_group = '2';
                     $dialplan->dialplan_detail_order = '010';
                     $dialplan->dialplan_detail_add();
                     unset($dialplan);
                     $dialplan = new dialplan();
                     $dialplan->domain_uuid = $domain_uuid;
                     $dialplan->dialplan_uuid = $dialplan_uuid;
                     $dialplan->dialplan_detail_tag = 'action';
                     //condition, action, antiaction
                     $dialplan->dialplan_detail_type = 'answer';
                     $dialplan->dialplan_detail_data = '';
                     $dialplan->dialplan_detail_break = '';
                     $dialplan->dialplan_detail_inline = '';
                     $dialplan->dialplan_detail_group = '2';
                     $dialplan->dialplan_detail_order = '020';
                     $dialplan->dialplan_detail_add();
                     unset($dialplan);
                     $dialplan = new dialplan();
                     $dialplan->domain_uuid = $domain_uuid;
                     $dialplan->dialplan_uuid = $dialplan_uuid;
                     $dialplan->dialplan_detail_tag = 'action';
                     //condition, action, antiaction
                     $dialplan->dialplan_detail_type = 'set';
                     $dialplan->dialplan_detail_data = 'hangup_after_bridge=true';
                     $dialplan->dialplan_detail_break = '';
                     $dialplan->dialplan_detail_inline = '';
                     $dialplan->dialplan_detail_group = '2';
                     $dialplan->dialplan_detail_order = '030';
                     $dialplan->dialplan_detail_add();
                     unset($dialplan);
                     if (strlen($queue_cid_prefix) > 0) {
                         $dialplan = new dialplan();
                         $dialplan->domain_uuid = $domain_uuid;
                         $dialplan->dialplan_uuid = $dialplan_uuid;
                         $dialplan->dialplan_detail_tag = 'action';
                         //condition, action, antiaction
                         $dialplan->dialplan_detail_type = 'set';
                         $dialplan->dialplan_detail_data = "effective_caller_id_name=" . $queue_cid_prefix . "-\${caller_id_name}";
                         $dialplan->dialplan_detail_break = '';
                         $dialplan->dialplan_detail_inline = '';
                         $dialplan->dialplan_detail_group = '2';
                         $dialplan->dialplan_detail_order = '040';
                         $dialplan->dialplan_detail_add();
                         unset($dialplan);
                     }
                     $dialplan = new dialplan();
                     $dialplan->domain_uuid = $domain_uuid;
                     $dialplan->dialplan_uuid = $dialplan_uuid;
                     $dialplan->dialplan_detail_tag = 'action';
                     //condition, action, antiaction
                     $dialplan->dialplan_detail_type = 'callcenter';
                     $dialplan->dialplan_detail_data = $queue_name . "@" . $_SESSION['domains'][$domain_uuid]['domain_name'];
                     $dialplan->dialplan_detail_break = '';
                     $dialplan->dialplan_detail_inline = '';
                     $dialplan->dialplan_detail_group = '2';
                     $dialplan->dialplan_detail_order = '050';
                     $dialplan->dialplan_detail_add();
                     unset($dialplan);
                     if (strlen($queue_timeout_action) > 0) {
                         $action_array = explode(":", $queue_timeout_action);
                         $dialplan = new dialplan();
                         $dialplan->domain_uuid = $domain_uuid;
                         $dialplan->dialplan_uuid = $dialplan_uuid;
                         $dialplan->dialplan_detail_tag = 'action';
                         //condition, action, antiaction
                         $dialplan->dialplan_detail_type = $action_array[0];
                         $dialplan->dialplan_detail_data = substr($queue_timeout_action, strlen($action_array[0]) + 1, strlen($queue_timeout_action));
                         $dialplan->dialplan_detail_break = '';
                         $dialplan->dialplan_detail_inline = '';
                         $dialplan->dialplan_detail_group = '2';
                         $dialplan->dialplan_detail_order = '060';
                         $dialplan->dialplan_detail_add();
                         unset($dialplan);
                     }
                     $dialplan = new dialplan();
                     $dialplan->domain_uuid = $domain_uuid;
                     $dialplan->dialplan_uuid = $dialplan_uuid;
                     $dialplan->dialplan_detail_tag = 'action';
                     //condition, action, antiaction
                     $dialplan->dialplan_detail_type = 'hangup';
                     $dialplan->dialplan_detail_data = '';
                     $dialplan->dialplan_detail_break = '';
                     $dialplan->dialplan_detail_inline = '';
                     $dialplan->dialplan_detail_group = '2';
                     $dialplan->dialplan_detail_order = '070';
                     $dialplan->dialplan_detail_add();
                     unset($dialplan);
                     //synchronize the xml config
                     save_dialplan_xml();
                     //unset variables
                     unset($action);
                 }
                 //end if strlen call_center_queue_uuid; add the call center queue to the dialplan
             }
             //prepare Queue XML string
             $v_queues = '';
             $sql = "select * from v_call_center_queues ";
             $prep_statement = $db->prepare(check_sql($sql));
             $prep_statement->execute();
             $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
             $x = 0;
             foreach ($result as &$row) {
                 $queue_name = $row["queue_name"];
                 $queue_extension = $row["queue_extension"];
                 $queue_strategy = $row["queue_strategy"];
                 $queue_moh_sound = $row["queue_moh_sound"];
                 $queue_record_template = $row["queue_record_template"];
                 $queue_time_base_score = $row["queue_time_base_score"];
                 $queue_max_wait_time = $row["queue_max_wait_time"];
                 $queue_max_wait_time_with_no_agent = $row["queue_max_wait_time_with_no_agent"];
                 $queue_tier_rules_apply = $row["queue_tier_rules_apply"];
                 $queue_tier_rule_wait_second = $row["queue_tier_rule_wait_second"];
                 $queue_tier_rule_wait_multiply_level = $row["queue_tier_rule_wait_multiply_level"];
                 $queue_tier_rule_no_agent_no_wait = $row["queue_tier_rule_no_agent_no_wait"];
                 $queue_discard_abandoned_after = $row["queue_discard_abandoned_after"];
                 $queue_abandoned_resume_allowed = $row["queue_abandoned_resume_allowed"];
                 $queue_announce_sound = $row["queue_announce_sound"];
                 $queue_announce_frequency = $row["queue_announce_frequency"];
                 $queue_description = $row["queue_description"];
                 if ($x > 0) {
                     $v_queues .= "\n";
                     $v_queues .= "\t\t";
                 }
                 $v_queues .= "<queue name=\"{$queue_name}@" . $_SESSION['domains'][$row["domain_uuid"]]['domain_name'] . "\">\n";
                 $v_queues .= "\t\t\t<param name=\"strategy\" value=\"{$queue_strategy}\"/>\n";
                 if (strlen($queue_moh_sound) == 0) {
                     $v_queues .= "\t\t\t<param name=\"moh-sound\" value=\"local_stream://default\"/>\n";
                 } else {
                     if (substr($queue_moh_sound, 0, 15) == 'local_stream://') {
                         $v_queues .= "\t\t\t<param name=\"moh-sound\" value=\"" . $queue_moh_sound . "\"/>\n";
                     } elseif (substr($queue_moh_sound, 0, 2) == '${' && substr($queue_moh_sound, -5) == 'ring}') {
                         $v_queues .= "\t\t\t<param name=\"moh-sound\" value=\"tone_stream://" . $queue_moh_sound . ";loops=-1\"/>\n";
                     } else {
                         $v_queues .= "\t\t\t<param name=\"moh-sound\" value=\"" . $queue_moh_sound . "\"/>\n";
                     }
                 }
                 if (strlen($queue_record_template) > 0) {
                     $v_queues .= "\t\t\t<param name=\"record-template\" value=\"{$queue_record_template}\"/>\n";
                 }
                 $v_queues .= "\t\t\t<param name=\"time-base-score\" value=\"{$queue_time_base_score}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"max-wait-time\" value=\"{$queue_max_wait_time}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"max-wait-time-with-no-agent\" value=\"{$queue_max_wait_time_with_no_agent}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"max-wait-time-with-no-agent-time-reached\" value=\"{$queue_max_wait_time_with_no_agent_time_reached}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"tier-rules-apply\" value=\"{$queue_tier_rules_apply}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"tier-rule-wait-second\" value=\"{$queue_tier_rule_wait_second}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"tier-rule-wait-multiply-level\" value=\"{$queue_tier_rule_wait_multiply_level}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"tier-rule-no-agent-no-wait\" value=\"{$queue_tier_rule_no_agent_no_wait}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"discard-abandoned-after\" value=\"{$queue_discard_abandoned_after}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"abandoned-resume-allowed\" value=\"{$queue_abandoned_resume_allowed}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"announce-sound\" value=\"{$queue_announce_sound}\"/>\n";
                 $v_queues .= "\t\t\t<param name=\"announce-frequency\" value=\"{$queue_announce_frequency}\"/>\n";
                 $v_queues .= "\t\t</queue>";
                 $x++;
             }
             unset($prep_statement);
             //prepare Agent XML string
             $v_agents = '';
             $sql = "select * from v_call_center_agents ";
             $prep_statement = $db->prepare(check_sql($sql));
             $prep_statement->execute();
             $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
             $x = 0;
             foreach ($result as &$row) {
                 //get the values from the db and set as php variables
                 $agent_name = $row["agent_name"];
                 $agent_type = $row["agent_type"];
                 $agent_call_timeout = $row["agent_call_timeout"];
                 $agent_contact = $row["agent_contact"];
                 $agent_status = $row["agent_status"];
                 $agent_no_answer_delay_time = $row["agent_no_answer_delay_time"];
                 $agent_max_no_answer = $row["agent_max_no_answer"];
                 $agent_wrap_up_time = $row["agent_wrap_up_time"];
                 $agent_reject_delay_time = $row["agent_reject_delay_time"];
                 $agent_busy_delay_time = $row["agent_busy_delay_time"];
                 if ($x > 0) {
                     $v_agents .= "\n";
                     $v_agents .= "\t\t";
                 }
                 //get and then set the complete agent_contact with the call_timeout and when necessary confirm
                 //$tmp_confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1";
                 //if you change this variable also change app/call_center/call_center_agent_edit.php
                 $tmp_confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1,group_confirm_read_timeout=2000,leg_timeout=" . $agent_call_timeout;
                 if (strstr($agent_contact, '}') === FALSE) {
                     //not found
                     if (stristr($agent_contact, 'sofia/gateway') === FALSE) {
                         //add the call_timeout
                         $tmp_agent_contact = "{call_timeout=" . $agent_call_timeout . "}" . $agent_contact;
                     } else {
                         //add the call_timeout and confirm
                         $tmp_agent_contact = $tmp_first . ',call_timeout=' . $agent_call_timeout . $tmp_last;
                         $tmp_agent_contact = "{" . $tmp_confirm . ",call_timeout=" . $agent_call_timeout . "}" . $agent_contact;
                     }
                 } else {
                     //found
                     if (stristr($agent_contact, 'sofia/gateway') === FALSE) {
                         //not found
                         if (stristr($agent_contact, 'call_timeout') === FALSE) {
                             //add the call_timeout
                             $tmp_pos = strrpos($agent_contact, "}");
                             $tmp_first = substr($agent_contact, 0, $tmp_pos);
                             $tmp_last = substr($agent_contact, $tmp_pos);
                             $tmp_agent_contact = $tmp_first . ',call_timeout=' . $agent_call_timeout . $tmp_last;
                         } else {
                             //the string has the call timeout
                             $tmp_agent_contact = $agent_contact;
                         }
                     } else {
                         //found
                         $tmp_pos = strrpos($agent_contact, "}");
                         $tmp_first = substr($agent_contact, 0, $tmp_pos);
                         $tmp_last = substr($agent_contact, $tmp_pos);
                         if (stristr($agent_contact, 'call_timeout') === FALSE) {
                             //add the call_timeout and confirm
                             $tmp_agent_contact = $tmp_first . ',' . $tmp_confirm . ',call_timeout=' . $agent_call_timeout . $tmp_last;
                         } else {
                             //add confirm
                             $tmp_agent_contact = $tmp_first . ',' . $tmp_confirm . $tmp_last;
                         }
                     }
                 }
                 $v_agents .= "<agent ";
                 $v_agents .= "name=\"{$agent_name}@" . $_SESSION['domains'][$row["domain_uuid"]]['domain_name'] . "\" ";
                 $v_agents .= "type=\"{$agent_type}\" ";
                 $v_agents .= "contact=\"{$tmp_agent_contact}\" ";
                 $v_agents .= "status=\"{$agent_status}\" ";
                 $v_agents .= "no-answer-delay-time=\"{$agent_no_answer_delay_time}\" ";
                 $v_agents .= "max-no-answer=\"{$agent_max_no_answer}\" ";
                 $v_agents .= "wrap-up-time=\"{$agent_wrap_up_time}\" ";
                 $v_agents .= "reject-delay-time=\"{$agent_reject_delay_time}\" ";
                 $v_agents .= "busy-delay-time=\"{$agent_busy_delay_time}\" ";
                 $v_agents .= "/>";
                 $x++;
             }
             unset($prep_statement);
             //prepare Tier XML string
             $v_tiers = '';
             $sql = "select * from v_call_center_tiers ";
             $prep_statement = $db->prepare(check_sql($sql));
             $prep_statement->execute();
             $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
             $x = 0;
             foreach ($result as &$row) {
                 $agent_name = $row["agent_name"];
                 $queue_name = $row["queue_name"];
                 $tier_level = $row["tier_level"];
                 $tier_position = $row["tier_position"];
                 if ($x > 0) {
                     $v_tiers .= "\n";
                     $v_tiers .= "\t\t";
                 }
                 $v_tiers .= "<tier agent=\"{$agent_name}@" . $_SESSION['domains'][$row["domain_uuid"]]['domain_name'] . "\" queue=\"{$queue_name}@" . $_SESSION['domains'][$row["domain_uuid"]]['domain_name'] . "\" level=\"{$tier_level}\" position=\"{$tier_position}\"/>";
                 $x++;
             }
             //set the path
             if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')) {
                 $path = "/usr/share/examples/fusionpbx/resources/templates/conf";
             } else {
                 $path = $_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/resources/templates/conf";
             }
             //get the contents of the template
             $file_contents = file_get_contents($path . "/autoload_configs/callcenter.conf.xml");
             //add the Call Center Queues, Agents and Tiers to the XML config
             $file_contents = str_replace("{v_queues}", $v_queues, $file_contents);
             unset($v_queues);
             $file_contents = str_replace("{v_agents}", $v_agents, $file_contents);
             unset($v_agents);
             $file_contents = str_replace("{v_tiers}", $v_tiers, $file_contents);
             unset($v_tiers);
             //write the XML config file
             $fout = fopen($_SESSION['switch']['conf']['dir'] . "/autoload_configs/callcenter.conf.xml", "w");
             fwrite($fout, $file_contents);
             fclose($fout);
             //save the dialplan xml files
             save_dialplan_xml();
             //apply settings
             $_SESSION["reload_xml"] = true;
         }
     }
 }
Example #12
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
dialplan::register('CallRecord', 'conditioning');
dialplan::register('CallRecord', 'preanswer');
dialplan::register('CallRecord', 'prenumber');
plugins::register('devicemanager/create', 'view', array('CallRecord_Plugin', 'update'));
plugins::register('devicemanager/edit', 'view', array('CallRecord_Plugin', 'update'));
plugins::register('devicemanager', 'save', array('CallRecord_Plugin', 'save'));
plugins::register('xmlcdr/details', 'view', array('CallRecord_Plugin', 'recordings'));
Example #13
0
 public function dialplan()
 {
     //create the database object
     $database = new database();
     if ($this->db) {
         $database->db = $this->db;
     }
     //check to see if the dialplan entry exists
     $dialplan = new dialplan();
     $dialplan->domain_uuid = $_SESSION["domain_uuid"];
     $dialplan->dialplan_uuid = $this->dialplan_uuid;
     $dialplan_exists = $dialplan->dialplan_exists();
     //if the dialplan entry does not exist then add it
     if (!$dialplan_exists) {
         $database = new database();
         $database->table = "v_dialplans";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_name'] = $this->ivr_menu_name;
         $database->fields['dialplan_order'] = '333';
         $database->fields['dialplan_context'] = $_SESSION['context'];
         $database->fields['dialplan_enabled'] = $this->ivr_menu_enabled;
         $database->fields['dialplan_description'] = $this->ivr_menu_description;
         $database->fields['app_uuid'] = $this->app_uuid;
         $database->add();
     }
     //if the dialplan entry exists then update it
     if ($dialplan_exists && strlen($this->ivr_menu_extension) > 0) {
         //update the dialplan
         $database = new database();
         $database->table = "v_dialplans";
         $database->fields['dialplan_name'] = $this->ivr_menu_name;
         $database->fields['dialplan_order'] = '333';
         $database->fields['dialplan_context'] = $_SESSION['context'];
         $database->fields['dialplan_enabled'] = $this->ivr_menu_enabled;
         $database->fields['dialplan_description'] = $this->ivr_menu_description;
         $database->fields['app_uuid'] = $this->app_uuid;
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->where[0]['name'] = 'domain_uuid';
         $database->where[0]['value'] = $this->domain_uuid;
         $database->where[0]['operator'] = '=';
         $database->where[1]['name'] = 'dialplan_uuid';
         $database->where[1]['value'] = $this->dialplan_uuid;
         $database->where[1]['operator'] = '=';
         $database->update();
         //delete the old dialplan details to prepare for new details
         $database = new database();
         $database->table = "v_dialplan_details";
         $database->where[0]['name'] = 'domain_uuid';
         $database->where[0]['value'] = $this->domain_uuid;
         $database->where[0]['operator'] = '=';
         $database->where[1]['name'] = 'dialplan_uuid';
         $database->where[1]['value'] = $this->dialplan_uuid;
         $database->where[1]['operator'] = '=';
         $database->delete();
     }
     //add the dialplan details
     $detail_data = '^' . $this->ivr_menu_extension . '$';
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'condition';
     //condition, action, antiaction
     $database->fields['dialplan_detail_type'] = 'destination_number';
     $database->fields['dialplan_detail_data'] = $detail_data;
     $database->fields['dialplan_detail_order'] = '005';
     $database->add();
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'action';
     //condition, action, antiaction
     $database->fields['dialplan_detail_type'] = 'answer';
     $database->fields['dialplan_detail_data'] = '';
     $database->fields['dialplan_detail_order'] = '010';
     $database->add();
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'action';
     //condition, action, antiaction
     $database->fields['dialplan_detail_type'] = 'sleep';
     $database->fields['dialplan_detail_data'] = '1000';
     $database->fields['dialplan_detail_order'] = '015';
     $database->add();
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'action';
     //condition, action, antiaction
     $database->fields['dialplan_detail_type'] = 'set';
     $database->fields['dialplan_detail_data'] = 'hangup_after_bridge=true';
     $database->fields['dialplan_detail_order'] = '020';
     $database->add();
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'action';
     //condition, action, antiaction
     $database->fields['dialplan_detail_type'] = 'set';
     if ($this->ivr_menu_ringback == "music" || $this->ivr_menu_ringback == "") {
         $database->fields['dialplan_detail_data'] = 'ringback=${hold_music}';
     } else {
         $database->fields['dialplan_detail_data'] = 'ringback=' . $this->ivr_menu_ringback;
     }
     $database->fields['dialplan_detail_order'] = '025';
     $database->add();
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'action';
     //condition, action, antiaction
     $database->fields['dialplan_detail_type'] = 'set';
     if ($this->ivr_menu_ringback == "music" || $this->ivr_menu_ringback == "") {
         $database->fields['dialplan_detail_data'] = 'transfer_ringback=${hold_music}';
     } else {
         $database->fields['dialplan_detail_data'] = 'transfer_ringback=' . $this->ivr_menu_ringback;
     }
     $database->fields['dialplan_detail_order'] = '030';
     $database->add();
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'action';
     //condition, action, antiaction
     $database->fields['dialplan_detail_type'] = 'set';
     $database->fields['dialplan_detail_data'] = 'ivr_menu_uuid=' . $this->ivr_menu_uuid;
     $database->fields['dialplan_detail_order'] = '035';
     $database->add();
     $database->table = "v_dialplan_details";
     $database->fields['domain_uuid'] = $this->domain_uuid;
     $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
     $database->fields['dialplan_detail_uuid'] = uuid();
     $database->fields['dialplan_detail_tag'] = 'action';
     //condition, action, antiaction
     if ($_SESSION['ivr menu']['application']['text'] == "lua") {
         $database->fields['dialplan_detail_type'] = 'lua';
         $database->fields['dialplan_detail_data'] = 'ivr_menu.lua';
     } else {
         $database->fields['dialplan_detail_type'] = 'ivr';
         $database->fields['dialplan_detail_data'] = $this->ivr_menu_uuid;
     }
     $database->fields['dialplan_detail_order'] = '040';
     $database->add();
     if (strlen($this->ivr_menu_exit_app) > 0) {
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = $this->ivr_menu_exit_app;
         $database->fields['dialplan_detail_data'] = $this->ivr_menu_exit_data;
         $database->fields['dialplan_detail_order'] = '045';
         $database->add();
     }
     //delete the dialplan context from memcache
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     if ($fp) {
         $switch_cmd .= "memcache delete dialplan:" . $_SESSION["context"] . "@" . $_SESSION['domain_name'];
         $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
     }
 }
Example #14
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
dialplan::register('NumberCleanup', 'conditioning');
plugins::register('contextmanager/create', 'view', array('NumberCleanup_Plugin', 'update'));
plugins::register('contextmanager/edit', 'view', array('NumberCleanup_Plugin', 'update'));
plugins::register('contextmanager', 'save', array('NumberCleanup_Plugin', 'save'));
plugins::register('accountmanager', 'delete', array('NumberCleanup_Plugin', 'buildAccountRelationships'));
 $sql .= "hunt_group_ringback = '{$hunt_group_ringback}', ";
 $sql .= "hunt_group_cid_name_prefix = '{$hunt_group_cid_name_prefix}', ";
 $sql .= "hunt_group_pin = '{$hunt_group_pin}', ";
 $sql .= "hunt_group_caller_announce = '{$hunt_group_caller_announce}', ";
 if (if_group("admin") || if_group("superadmin")) {
     $sql .= "hunt_group_user_list = '{$hunt_group_user_list}', ";
 }
 $sql .= "hunt_group_enabled = '{$hunt_group_enabled}', ";
 $sql .= "hunt_group_description = '{$hunt_group_description}' ";
 $sql .= "where domain_uuid = '" . $_SESSION['domain_uuid'] . "' ";
 $sql .= "and hunt_group_uuid = '{$hunt_group_uuid}'";
 $db->exec(check_sql($sql));
 unset($sql);
 //update the dialplan entry
 require_once "resources/classes/dialplan.php";
 $dialplan = new dialplan();
 $dialplan->domain_uuid = $_SESSION['domain_uuid'];
 $dialplan->app_uuid = $app_uuid;
 $dialplan->dialplan_uuid = $dialplan_uuid;
 $dialplan->dialplan_name = $hunt_group_name;
 //$dialplan->dialplan_continue = $dialplan_continue;
 //$dialplan->dialplan_order = '330';
 $dialplan->dialplan_context = $_SESSION['context'];
 $dialplan->dialplan_enabled = $hunt_group_enabled;
 $dialplan->dialplan_description = $hunt_group_description;
 $dialplan->dialplan_update();
 unset($dialplan);
 //update the condition
 $sql = "update v_dialplan_details set ";
 $sql .= "dialplan_detail_data = '^" . $hunt_group_extension . "\$' ";
 $sql .= "where domain_uuid = '" . $_SESSION['domain_uuid'] . "' ";
Example #16
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
dialplan::register('FeatureCode', 'postroute');
Event::add('numbermanager.collectNumberTargets', array('FeatureCodeManager', 'provideNumberTargets'));
Event::add('bluebox.account.initialize', array('FeatureCodeManager', 'initializeFeatureCode'));
} else {
    //show the header
    require_once "resources/header.php";
    //send the call broadcast
    if (strlen($broadcast_phone_numbers) > 0) {
        $broadcast_phone_number_array = explode("\n", $broadcast_phone_numbers);
        $count = 1;
        $sched_seconds = '3';
        foreach ($broadcast_phone_number_array as $tmp_value) {
            //set the variables
            $tmp_value = str_replace(";", "|", $tmp_value);
            $tmp_value_array = explode("|", $tmp_value);
            //remove the number formatting
            $phone_1 = preg_replace('{\\D}', '', $tmp_value_array[0]);
            //get the dialplan variables and bridge statement
            $dialplan = new dialplan();
            $dialplan->domain_uuid = $_SESSION['domain_uuid'];
            $dialplan->outbound_routes($phone_1);
            $dialplan_variables = $dialplan->variables;
            $bridge_array[0] = $dialplan->bridges;
            //echo "var: ".$variables."\n";
            //echo "bridges: ".$bridges."\n";
            //prepare the string
            $channel_variables = $dialplan_variables . "ignore_early_media=true";
            $channel_variables .= ",origination_number={$phone_1}";
            $channel_variables .= ",origination_caller_id_name='{$broadcast_caller_id_name}'";
            $channel_variables .= ",origination_caller_id_number={$broadcast_caller_id_number}";
            $channel_variables .= ",domain_uuid=" . $_SESSION['domain_uuid'];
            $channel_variables .= ",domain=" . $_SESSION['domain_name'];
            $channel_variables .= ",domain_name=" . $_SESSION['domain_name'];
            $channel_variables .= ",accountcode='{$broadcast_accountcode}'";
Example #18
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
dialplan::register('SipEncryption', 'conditioning');
plugins::register('sipinterface/add', 'view', array('SipEncrption_Plugin', 'update'));
plugins::register('sipinterface/edit', 'view', array('SipEncryption_Plugin', 'update'));
plugins::register('sipinterface', 'save', array('SipEncryption_Plugin', 'save'));
Example #19
0
             mkdir($switch_recordings_dir . '', 0777, true);
         }
     }
     //copy the files and directories from resources/install
     require_once "resources/classes/install.php";
     $install = new install();
     $install->domain_uuid = $_SESSION["domain_uuid"];
     $install->domain = $domain_name;
     $install->switch_conf_dir = $switch_conf_dir;
     $install->switch_scripts_dir = $switch_scripts_dir;
     //	$install->switch_sounds_dir = $switch_sounds_dir;
     $install->copy_conf();
     $install->copy();
     //create the dialplan/default.xml for single tenant or dialplan/domain.xml
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/dialplan")) {
         $dialplan = new dialplan();
         $dialplan->domain_uuid = $_SESSION["domain_uuid"];
         $dialplan->domain = $domain_name;
         $dialplan->switch_dialplan_dir = $switch_dialplan_dir;
         $dialplan->restore_advanced_xml();
         //print_r($dialplan->result);
     }
     //write the xml_cdr.conf.xml file
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/app/xml_cdr")) {
         xml_cdr_conf_xml();
     }
     //write the switch.conf.xml file
     if (file_exists($switch_conf_dir)) {
         switch_conf_xml();
     }
 }
Example #20
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
dialplan::register('Voicemail', 'prenumber');
dialplan::register('Voicemail', 'postnumber');
Event::add('numbermanager.collectNumberOptions', array('Voicemails', 'provideNumberOptions'));
Event::add('numbermanager.collectNumberTargets', array('Voicemails', 'provideNumberTargets'));
Event::add('numbermanager.collectNumberTerminators', array('Voicemails', 'provideNumberTerminator'));
plugins::register('devicemanager/create', 'view', array('Voicemail_Plugin', 'update'));
plugins::register('devicemanager/edit', 'view', array('Voicemail_Plugin', 'update'));
plugins::register('devicemanager', 'save', array('Voicemail_Plugin', 'save'));
Event::add('bluebox.create.extension', array('Voicemails', 'createExtension'));
Example #21
0
File: fax.php Project: swk/bluebox
<?php

defined('SYSPATH') or die('No direct access allowed.');
plugins::register('numbermanager/create', 'view', array('Fax_Plugin', 'update'));
plugins::register('numbermanager/edit', 'view', array('Fax_Plugin', 'update'));
plugins::register('numbermanager', 'save', array('Fax_Plugin', 'save'));
Event::add('numbermanager.collectNumberTargets', array('Fax_Plugin', 'provideNumberTargets'));
dialplan::register('FaxProfile', 'network');
dialplan::register('FaxProfile', 'conditioning');
dialplan::register('FaxProfile', 'preroute');
dialplan::register('FaxProfile', 'postroute');
dialplan::register('FaxProfile', 'preanswer');
dialplan::register('FaxProfile', 'postanswer');
dialplan::register('FaxProfile', 'prenumber');
dialplan::register('FaxProfile', 'main');
dialplan::register('FaxProfile', 'postnumber');
dialplan::register('FaxProfile', 'catchall');
dialplan::register('FaxProfile', 'postexecute');
Example #22
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
plugins::register('devicemanager/create', 'view', array('CallIntercept_Plugin', 'update'));
plugins::register('devicemanager/edit', 'view', array('CallIntercept_Plugin', 'update'));
plugins::register('devicemanager', 'save', array('CallIntercept_Plugin', 'save'));
dialplan::register('CallIntercept', 'prenumber');
Example #23
0
    }
}
//get the $apps array from the installed apps from the core and mod directories
$xml_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/resources/switch/conf/dialplan/*.xml");
foreach ($xml_list as &$xml_file) {
    //get and parse the xml
    $xml_string = file_get_contents($xml_file);
    //get the order number prefix from the file name
    $name_array = explode('_', basename($xml_file));
    if (is_numeric($name_array[0])) {
        $dialplan_order = $name_array[0];
    } else {
        $dialplan_order = 0;
    }
    //dialplan class
    $dialplan = new dialplan();
    $dialplan->domain_uuid = $domain_uuid;
    $dialplan->dialplan_order = $dialplan_order;
    $dialplan->default_context = $domain_name;
    if ($display_type == "text") {
        $dialplan->display_type = 'text';
    }
    $dialplan->xml = $xml_string;
    $dialplan->import();
}
//add the global dialplan to inbound routes
/*
if ($domains_processed == 1) {
	$sql = "select count(*) as num_rows from v_dialplans ";
	$sql .= "where dialplan_uuid = 'd4e06654-e394-444a-b3af-4c3d54aebbec' ";
	$prep_statement = $db->prepare(check_sql($sql));
Example #24
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
dialplan::register('CallerId', 'conditioning');
dialplan::register('CallerId', 'prenumber');
plugins::register('devicemanager/create', 'view', array('CallerId_Plugin', 'update'));
plugins::register('devicemanager/edit', 'view', array('CallerId_Plugin', 'update'));
plugins::register('devicemanager', 'save', array('CallerId_Plugin', 'save'));
plugins::register('externalxfer/create', 'view', array('CallerId_Plugin', 'update_ext'));
plugins::register('externalxfer/edit', 'view', array('CallerId_Plugin', 'update_ext'));
plugins::register('externalxfer', 'save', array('CallerId_Plugin', 'save'));
Event::add('bluebox.create.extension', array('CidLib', 'createExtension'));
Example #25
0
 public function update()
 {
     //udate the ivr menu
     if (strlen($this->ivr_menu_option_action) == 0) {
         //get the dialplan uuid
         $database = new database();
         if ($this->db) {
             $database->db = $this->db;
         }
         $database->table = "v_ivr_menus";
         $database->where[0]['name'] = 'domain_uuid';
         $database->where[0]['value'] = $this->domain_uuid;
         $database->where[0]['operator'] = '=';
         $database->where[1]['name'] = 'ivr_menu_uuid';
         $database->where[1]['value'] = $this->ivr_menu_uuid;
         $database->where[1]['operator'] = '=';
         $result = $database->find();
         foreach ($result as $row) {
             $this->dialplan_uuid = $row['dialplan_uuid'];
         }
         //if the extension number is empty and the dialplan exists then delete the dialplan
         if (strlen($this->ivr_menu_extension) == 0) {
             if (strlen($this->dialplan_uuid) > 0) {
                 //delete dialplan entry
                 $database = new database();
                 $database->table = "v_dialplan_details";
                 $database->where[0]['name'] = 'domain_uuid';
                 $database->where[0]['value'] = $this->domain_uuid;
                 $database->where[0]['operator'] = '=';
                 $database->where[1]['name'] = 'dialplan_uuid';
                 $database->where[1]['value'] = $this->dialplan_uuid;
                 $database->where[1]['operator'] = '=';
                 $database->delete();
                 //delete the child dialplan information
                 $database = new database();
                 $database->table = "v_dialplans";
                 $database->where[0]['name'] = 'domain_uuid';
                 $database->where[0]['value'] = $this->domain_uuid;
                 $database->where[0]['operator'] = '=';
                 $database->where[1]['name'] = 'dialplan_uuid';
                 $database->where[1]['value'] = $this->dialplan_uuid;
                 $database->where[1]['operator'] = '=';
                 $database->delete();
                 //update the table to remove the dialplan_uuid
                 $this->dialplan_uuid = '';
             }
         }
         //update the ivr menu
         if (strlen($this->dialplan_uuid) == 0) {
             $this->dialplan_uuid = uuid();
         }
         $database = new database();
         $database->table = "v_ivr_menus";
         $database->fields['ivr_menu_uuid'] = $this->ivr_menu_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['ivr_menu_name'] = $this->ivr_menu_name;
         $database->fields['ivr_menu_extension'] = $this->ivr_menu_extension;
         $database->fields['ivr_menu_greet_long'] = $this->ivr_menu_greet_long;
         $database->fields['ivr_menu_greet_short'] = $this->ivr_menu_greet_short;
         $database->fields['ivr_menu_invalid_sound'] = $this->ivr_menu_invalid_sound;
         $database->fields['ivr_menu_exit_sound'] = $this->ivr_menu_exit_sound;
         $database->fields['ivr_menu_confirm_macro'] = $this->ivr_menu_confirm_macro;
         $database->fields['ivr_menu_confirm_key'] = $this->ivr_menu_confirm_key;
         $database->fields['ivr_menu_tts_engine'] = $this->ivr_menu_tts_engine;
         $database->fields['ivr_menu_tts_voice'] = $this->ivr_menu_tts_voice;
         $database->fields['ivr_menu_confirm_attempts'] = $this->ivr_menu_confirm_attempts;
         $database->fields['ivr_menu_timeout'] = $this->ivr_menu_timeout;
         $database->fields['ivr_menu_exit_app'] = $this->ivr_menu_exit_app;
         $database->fields['ivr_menu_exit_data'] = $this->ivr_menu_exit_data;
         $database->fields['ivr_menu_inter_digit_timeout'] = $this->ivr_menu_inter_digit_timeout;
         $database->fields['ivr_menu_max_failures'] = $this->ivr_menu_max_failures;
         $database->fields['ivr_menu_max_timeouts'] = $this->ivr_menu_max_timeouts;
         $database->fields['ivr_menu_max_timeouts'] = $this->ivr_menu_max_timeouts;
         $database->fields['ivr_menu_digit_len'] = $this->ivr_menu_digit_len;
         $database->fields['ivr_menu_digit_len'] = $this->ivr_menu_digit_len;
         $database->fields['ivr_menu_direct_dial'] = $this->ivr_menu_direct_dial;
         $database->fields['ivr_menu_ringback'] = $this->ivr_menu_ringback;
         $database->fields['ivr_menu_cid_prefix'] = $this->ivr_menu_cid_prefix;
         $database->fields['ivr_menu_enabled'] = $this->ivr_menu_enabled;
         $database->fields['ivr_menu_description'] = $this->ivr_menu_description;
         $database->where[0]['name'] = 'domain_uuid';
         $database->where[0]['value'] = $this->domain_uuid;
         $database->where[0]['operator'] = '=';
         $database->where[1]['name'] = 'ivr_menu_uuid';
         $database->where[1]['value'] = $this->ivr_menu_uuid;
         $database->where[1]['operator'] = '=';
         $database->update();
         //check to see if the dialplan entry exists
         $dialplan = new dialplan();
         $dialplan->domain_uuid = $_SESSION["domain_uuid"];
         $dialplan->dialplan_uuid = $this->dialplan_uuid;
         $dialplan_exists = $dialplan->dialplan_exists();
         //if the dialplan entry does not exist then add it
         if (!$dialplan_exists) {
             $database = new database();
             $database->table = "v_dialplans";
             $database->fields['dialplan_name'] = $this->ivr_menu_name;
             $database->fields['dialplan_order'] = '333';
             $database->fields['dialplan_context'] = $_SESSION['context'];
             $database->fields['dialplan_enabled'] = $this->ivr_menu_enabled;
             $database->fields['dialplan_description'] = $this->ivr_menu_description;
             $database->fields['app_uuid'] = $this->app_uuid;
             $database->fields['domain_uuid'] = $this->domain_uuid;
             $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
             $database->add();
         }
         //if the dialplan entry exists then update it
         if ($dialplan_exists && strlen($this->ivr_menu_extension) > 0) {
             //update the dialplan
             $database = new database();
             $database->table = "v_dialplans";
             $database->fields['dialplan_name'] = $this->ivr_menu_name;
             $database->fields['dialplan_order'] = '333';
             $database->fields['dialplan_context'] = $_SESSION['context'];
             $database->fields['dialplan_enabled'] = $this->ivr_menu_enabled;
             $database->fields['dialplan_description'] = $this->ivr_menu_description;
             $database->fields['app_uuid'] = $this->app_uuid;
             $database->fields['domain_uuid'] = $this->domain_uuid;
             $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
             $database->where[0]['name'] = 'domain_uuid';
             $database->where[0]['value'] = $this->domain_uuid;
             $database->where[0]['operator'] = '=';
             $database->where[1]['name'] = 'dialplan_uuid';
             $database->where[1]['value'] = $this->dialplan_uuid;
             $database->where[1]['operator'] = '=';
             $database->update();
             //delete the old dialplan details to prepare for new details
             $database = new database();
             $database->table = "v_dialplan_details";
             $database->where[0]['name'] = 'domain_uuid';
             $database->where[0]['value'] = $this->domain_uuid;
             $database->where[0]['operator'] = '=';
             $database->where[1]['name'] = 'dialplan_uuid';
             $database->where[1]['value'] = $this->dialplan_uuid;
             $database->where[1]['operator'] = '=';
             $database->delete();
         }
         //add the dialplan details
         $detail_data = '^' . $this->ivr_menu_extension . '$';
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'condition';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'destination_number';
         $database->fields['dialplan_detail_data'] = $detail_data;
         $database->fields['dialplan_detail_order'] = '005';
         $database->add();
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'answer';
         $database->fields['dialplan_detail_data'] = '';
         $database->fields['dialplan_detail_order'] = '010';
         $database->add();
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'sleep';
         $database->fields['dialplan_detail_data'] = '1000';
         $database->fields['dialplan_detail_order'] = '015';
         $database->add();
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'set';
         $database->fields['dialplan_detail_data'] = 'hangup_after_bridge=true';
         $database->fields['dialplan_detail_order'] = '020';
         $database->add();
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'set';
         if ($this->ivr_menu_ringback == "music" || $this->ivr_menu_ringback == "") {
             $database->fields['dialplan_detail_data'] = 'ringback=${hold_music}';
         } else {
             $database->fields['dialplan_detail_data'] = 'ringback=' . $this->ivr_menu_ringback;
         }
         $database->fields['dialplan_detail_order'] = '025';
         $database->add();
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'set';
         if ($this->ivr_menu_ringback == "music" || $this->ivr_menu_ringback == "") {
             $database->fields['dialplan_detail_data'] = 'transfer_ringback=${hold_music}';
         } else {
             $database->fields['dialplan_detail_data'] = 'transfer_ringback=' . $this->ivr_menu_ringback;
         }
         $database->fields['dialplan_detail_order'] = '030';
         $database->add();
         /*
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'ivr';
         if (count($_SESSION["domains"]) > 1) {
         	$database->fields['dialplan_detail_data'] = $_SESSION['domain_name'].'-'.$this->ivr_menu_name;
         }
         else {
         	$database->fields['dialplan_detail_data'] = $this->ivr_menu_name;
         }
         $database->fields['dialplan_detail_order'] = '035';
         $database->add();
         */
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'set';
         $database->fields['dialplan_detail_data'] = 'ivr_menu_uuid=' . $this->ivr_menu_uuid;
         $database->fields['dialplan_detail_order'] = '035';
         $database->add();
         $database->table = "v_dialplan_details";
         $database->fields['domain_uuid'] = $this->domain_uuid;
         $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
         $database->fields['dialplan_detail_uuid'] = uuid();
         $database->fields['dialplan_detail_tag'] = 'action';
         //condition, action, antiaction
         $database->fields['dialplan_detail_type'] = 'lua';
         $database->fields['dialplan_detail_data'] = 'ivr_menu.lua';
         $database->fields['dialplan_detail_order'] = '040';
         $database->add();
         if (strlen($this->ivr_menu_exit_app) > 0) {
             $database->table = "v_dialplan_details";
             $database->fields['domain_uuid'] = $this->domain_uuid;
             $database->fields['dialplan_uuid'] = $this->dialplan_uuid;
             $database->fields['dialplan_detail_uuid'] = uuid();
             $database->fields['dialplan_detail_tag'] = 'action';
             //condition, action, antiaction
             $database->fields['dialplan_detail_type'] = $this->ivr_menu_exit_app;
             $database->fields['dialplan_detail_data'] = $this->ivr_menu_exit_data;
             $database->fields['dialplan_detail_order'] = '045';
             $database->add();
         }
     }
     //update the ivr menu option
     if (strlen($this->ivr_menu_option_action) > 0) {
         $database = new database();
         $database->table = "v_ivr_menu_options";
         $database->fields['ivr_menu_option_digits'] = $this->ivr_menu_option_digits;
         $database->fields['ivr_menu_option_action'] = $this->ivr_menu_option_action;
         $database->fields['ivr_menu_option_param'] = $this->ivr_menu_option_param;
         $database->fields['ivr_menu_option_order'] = $this->ivr_menu_option_order;
         $database->fields['ivr_menu_option_description'] = $this->ivr_menu_option_description;
         $database->where[0]['name'] = 'domain_uuid';
         $database->where[0]['value'] = $this->domain_uuid;
         $database->where[0]['operator'] = '=';
         $database->where[1]['name'] = 'ivr_menu_uuid';
         $database->where[1]['value'] = $this->ivr_menu_uuid;
         $database->where[1]['operator'] = '=';
         $database->where[2]['name'] = 'ivr_menu_option_uuid';
         $database->where[2]['value'] = $this->ivr_menu_option_uuid;
         $database->where[2]['operator'] = '=';
         $database->update();
     }
 }
Example #26
0
File: xmpp.php Project: swk/bluebox
<?php

defined('SYSPATH') or die('No direct access allowed');
dialplan::register('Xmpp', 'preanswer');