示例#1
1
 function switch_dingaling_status($fp, $profile_username, $result_type = 'xml')
 {
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     $cmd = 'api dingaling status';
     $response = trim(event_socket_request($fp, $cmd));
     $response = explode("\n", $response);
     $x = 0;
     foreach ($response as $row) {
         if ($x > 1) {
             $dingaling = explode("|", $row);
             if ($profile_username == trim($dingaling[0])) {
                 return trim($dingaling[1]);
             }
         }
         $x++;
     }
 }
示例#2
0
 function switch_gateway_status($gateway_uuid, $result_type = 'xml')
 {
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     $cmd = 'api sofia xmlstatus gateway ' . $gateway_uuid;
     $response = trim(event_socket_request($fp, $cmd));
     if ($response == "Invalid Gateway!") {
         $cmd = 'api sofia xmlstatus gateway ' . strtoupper($gateway_uuid);
         $response = trim(event_socket_request($fp, $cmd));
     }
     return $response;
 }
 public function user_status()
 {
     //set the global variable
     global $db;
     //update the status
     if ($this->enabled == "true") {
         //update the call center status
         $user_status = "Logged Out";
         $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
         if ($fp) {
             $switch_cmd .= "callcenter_config agent set status " . $_SESSION['username'] . "@" . $this->domain_name . " '" . $user_status . "'";
             $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
         }
         //update the database user_status
         $user_status = "Do Not Disturb";
         $sql = "update v_users set ";
         $sql .= "user_status = '{$user_status}' ";
         $sql .= "where domain_uuid = '" . $this->domain_uuid . "' ";
         $sql .= "and username = '******'username'] . "' ";
         $prep_statement = $db->prepare(check_sql($sql));
         $prep_statement->execute();
     }
 }
示例#4
0
function switch_module_is_running($fp, $mod)
{
    if (!$fp) {
        //if the handle does not exist create it
        $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
        //if the handle still does not exist show an error message
        if (!$fp) {
            $msg = "<div align='center'>Connection to Event Socket failed.<br /></div>";
        }
    }
    if ($fp) {
        //send the api command to check if the module exists
        $switchcmd = "module_exists {$mod}";
        $switch_result = event_socket_request($fp, 'api ' . $switchcmd);
        unset($switchcmd);
        if (trim($switch_result) == "true") {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
示例#5
0
 public function message_download()
 {
     //check the message waiting status
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     if ($fp) {
         $switch_cmd .= "luarun app.lua voicemail mwi " . $this->voicemail_id . "@" . $_SESSION['domain_name'];
         $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
     }
     //change the message status
     $this->message_saved();
     //clear the cache
     session_cache_limiter('public');
     //set source folder path
     $path = $_SESSION['switch']['voicemail']['dir'] . '/default/' . $_SESSION['domain_name'] . '/' . $this->voicemail_id;
     //prepare base64 content from db, if enabled
     if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
         $sql = "select message_base64 from ";
         $sql .= "v_voicemail_messages as m, ";
         $sql .= "v_voicemails as v ";
         $sql .= "where ";
         $sql .= "m.voicemail_uuid = v.voicemail_uuid ";
         $sql .= "and v.voicemail_id = '" . $this->voicemail_id . "' ";
         $sql .= "and m.voicemail_uuid = '" . $this->voicemail_uuid . "' ";
         $sql .= "and m.domain_uuid = '" . $this->domain_uuid . "' ";
         $sql .= "and m.voicemail_message_uuid = '" . $this->voicemail_message_uuid . "' ";
         $prep_statement = $this->db->prepare(check_sql($sql));
         $prep_statement->execute();
         $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
         if (count($result) > 0) {
             foreach ($result as &$row) {
                 if ($row['message_base64'] != '') {
                     $message_decoded = base64_decode($row['message_base64']);
                     file_put_contents($path . '/msg_' . $this->voicemail_message_uuid . '.ext', $message_decoded);
                     $finfo = finfo_open(FILEINFO_MIME_TYPE);
                     //determine mime type (requires PHP >= 5.3.0, must be manually enabled on Windows)
                     $file_mime = finfo_file($finfo, $path . '/msg_' . $this->voicemail_message_uuid . '.ext');
                     finfo_close($finfo);
                     switch ($file_mime) {
                         case 'audio/x-wav':
                         case 'audio/wav':
                             $file_ext = 'wav';
                             break;
                         case 'audio/mpeg':
                         case 'audio/mp3':
                             $file_ext = 'mp3';
                             break;
                     }
                     rename($path . '/msg_' . $this->voicemail_message_uuid . '.ext', $path . '/msg_' . $this->voicemail_message_uuid . '.' . $file_ext);
                 }
                 break;
             }
         }
         unset($sql, $prep_statement, $result, $message_decoded);
     }
     //prepare and stream the file
     if (file_exists($path . '/msg_' . $this->voicemail_message_uuid . '.wav')) {
         $file_path = $path . '/msg_' . $this->voicemail_message_uuid . '.wav';
     }
     if (file_exists($path . '/msg_' . $this->voicemail_message_uuid . '.mp3')) {
         $file_path = $path . '/msg_' . $this->voicemail_message_uuid . '.mp3';
     }
     if ($file_path != '') {
         $fd = fopen($file_path, "rb");
         if ($_GET['t'] == "bin") {
             header("Content-Type: application/force-download");
             header("Content-Type: application/octet-stream");
             header("Content-Type: application/download");
             header("Content-Description: File Transfer");
             $file_ext = substr($file_path, -3);
             if ($file_ext == "wav") {
                 header('Content-Disposition: attachment; filename="msg_' . $this->voicemail_message_uuid . '.wav"');
             }
             if ($file_ext == "mp3") {
                 header('Content-Disposition: attachment; filename="msg_' . $this->voicemail_message_uuid . '.mp3"');
             }
         } else {
             $file_ext = substr($file_path, -3);
             if ($file_ext == "wav") {
                 header("Content-Type: audio/wav");
             }
             if ($file_ext == "mp3") {
                 header("Content-Type: audio/mpeg");
             }
         }
         header("Cache-Control: no-cache, must-revalidate");
         // HTTP/1.1
         header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
         // date in the past
         header("Content-Length: " . filesize($file_path));
         ob_end_clean();
         fpassthru($fd);
     }
     //if base64, remove temp file
     if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
         @unlink($path . '/msg_' . $this->voicemail_message_uuid . '.' . $file_ext);
     }
 }
 public function reload()
 {
     //if the handle does not exist create it
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     //if the handle still does not exist show an error message
     if (!$fp) {
         $msg = "<div align='center'>" . $text['message-event-socket'] . "<br /></div>";
     }
     //send the api command to check if the module exists
     if ($fp) {
         $cmd = "reload mod_local_stream";
         $switch_result = event_socket_request($fp, 'api ' . $cmd);
         unset($cmd);
     }
 }
示例#7
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);
     }
 }
示例#8
0
        $sql = "";
        $sql .= "select * from v_settings ";
        $sql .= "where v_id = '{$v_id}' ";
        $prepstatement = $db->prepare(check_sql($sql));
        $prepstatement->execute();
        $result = $prepstatement->fetchAll();
        foreach ($result as &$row) {
            //$v_id = $row["v_id"];
            $event_socket_ip_address = $row["event_socket_ip_address"];
            $event_socket_port = $row["event_socket_port"];
            $event_socket_password = $row["event_socket_password"];
            break;
            //limit to 1 row
        }
        echo "<b>switch command:</b>\n";
        echo "<pre>\n";
        $fp = event_socket_create($event_socket_ip_address, $event_socket_port, $event_socket_password);
        $switch_result = event_socket_request($fp, 'api ' . $switchcmd);
        //$switch_result = eval($switchcmd);
        echo htmlentities($switch_result);
        echo "</pre>\n";
    }
    echo "\t\t</td>\n";
    echo "\t</tr>";
}
echo "\t</td>";
echo "\t</tr>";
echo "</table>";
echo "</div>";
echo "</form>";
require_once "includes/footer.php";
示例#9
0
function get_call_activity()
{
    global $db;
    global $ext_user_status;
    //get the extensions and their user status
    $sql = "select ";
    $sql .= "e.extension, ";
    $sql .= "e.number_alias, ";
    $sql .= "e.effective_caller_id_name, ";
    $sql .= "e.effective_caller_id_number, ";
    $sql .= "e.call_group, ";
    $sql .= "e.description, ";
    $sql .= "u.user_uuid, ";
    $sql .= "u.user_status ";
    $sql .= "from ";
    $sql .= "v_extensions as e ";
    $sql .= "left outer join v_extension_users as eu on ( eu.extension_uuid = e.extension_uuid and eu.domain_uuid = '" . $_SESSION['domain_uuid'] . "' ) ";
    $sql .= "left outer join v_users as u on ( u.user_uuid = eu.user_uuid and u.domain_uuid = '" . $_SESSION['domain_uuid'] . "' ) ";
    $sql .= "where ";
    $sql .= "e.domain_uuid = '" . $_SESSION['domain_uuid'] . "' ";
    $sql .= "order by ";
    $sql .= "e.extension asc ";
    $prep_statement = $db->prepare($sql);
    $prep_statement->execute();
    $extensions = $prep_statement->fetchAll(PDO::FETCH_NAMED);
    unset($prep_statement, $sql);
    //store extension status by user uuid
    foreach ($extensions as &$row) {
        if ($row['user_uuid'] != '') {
            $ext_user_status[$row['user_uuid']] = $row['user_status'];
            unset($row['user_status']);
        }
    }
    //send the command
    $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
    if ($fp) {
        $switch_cmd = 'show channels as json';
        $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
        $json_array = json_decode($switch_result, true);
    }
    //build the response
    $x = 0;
    foreach ($extensions as &$row) {
        $user = $row['extension'];
        if (strlen($row['number_alias']) > 0) {
            $user = $row['number_alias'];
        }
        //add the extension details
        $array[$x] = $row;
        //set the call detail defaults
        $array[$x]["uuid"] = null;
        $array[$x]["direction"] = null;
        $array[$x]["created"] = null;
        $array[$x]["created_epoch"] = null;
        $array[$x]["name"] = null;
        $array[$x]["state"] = null;
        $array[$x]["cid_name"] = null;
        $array[$x]["cid_num"] = null;
        $array[$x]["ip_addr"] = null;
        $array[$x]["dest"] = null;
        $array[$x]["application"] = null;
        $array[$x]["application_data"] = null;
        $array[$x]["dialplan"] = null;
        $array[$x]["context"] = null;
        $array[$x]["read_codec"] = null;
        $array[$x]["read_rate"] = null;
        $array[$x]["read_bit_rate"] = null;
        $array[$x]["write_codec"] = null;
        $array[$x]["write_rate"] = null;
        $array[$x]["write_bit_rate"] = null;
        $array[$x]["secure"] = null;
        $array[$x]["hostname"] = null;
        $array[$x]["presence_id"] = null;
        $array[$x]["presence_data"] = null;
        $array[$x]["callstate"] = null;
        $array[$x]["callee_name"] = null;
        $array[$x]["callee_num"] = null;
        $array[$x]["callee_direction"] = null;
        $array[$x]["call_uuid"] = null;
        $array[$x]["sent_callee_name"] = null;
        $array[$x]["sent_callee_num"] = null;
        $array[$x]["destination"] = null;
        //add the active call details
        $found = false;
        foreach ($json_array['rows'] as &$field) {
            $presence_id = $field['presence_id'];
            $presence = explode("@", $presence_id);
            $presence_id = $presence[0];
            $presence_domain = $presence[1];
            if ($user == $presence_id) {
                if ($presence_domain == $_SESSION['domain_name']) {
                    $found = true;
                    break;
                }
            }
        }
        //normalize the array
        if ($found) {
            $array[$x]["uuid"] = $field['uuid'];
            $array[$x]["direction"] = $field['direction'];
            $array[$x]["created"] = $field['created'];
            $array[$x]["created_epoch"] = $field['created_epoch'];
            $array[$x]["name"] = $field['name'];
            $array[$x]["state"] = $field['state'];
            $array[$x]["cid_name"] = $field['cid_name'];
            $array[$x]["cid_num"] = $field['cid_num'];
            $array[$x]["ip_addr"] = $field['ip_addr'];
            $array[$x]["dest"] = $field['dest'];
            $array[$x]["application"] = $field['application'];
            $array[$x]["application_data"] = $field['application_data'];
            $array[$x]["dialplan"] = $field['dialplan'];
            $array[$x]["context"] = $field['context'];
            $array[$x]["read_codec"] = $field['read_codec'];
            $array[$x]["read_rate"] = $field['read_rate'];
            $array[$x]["read_bit_rate"] = $field['read_bit_rate'];
            $array[$x]["write_codec"] = $field['write_codec'];
            $array[$x]["write_rate"] = $field['write_rate'];
            $array[$x]["write_bit_rate"] = $field['write_bit_rate'];
            $array[$x]["secure"] = $field['secure'];
            $array[$x]["hostname"] = $field['hostname'];
            $array[$x]["presence_id"] = $field['presence_id'];
            $array[$x]["presence_data"] = $field['presence_data'];
            $array[$x]["callstate"] = $field['callstate'];
            $array[$x]["callee_name"] = $field['callee_name'];
            $array[$x]["callee_num"] = $field['callee_num'];
            $array[$x]["callee_direction"] = $field['callee_direction'];
            $array[$x]["call_uuid"] = $field['call_uuid'];
            $array[$x]["sent_callee_name"] = $field['sent_callee_name'];
            $array[$x]["sent_callee_num"] = $field['sent_callee_num'];
            $array[$x]["destination"] = $user;
            //calculate and set the call length
            $call_length_seconds = time() - $array[$x]["created_epoch"];
            $call_length_hour = floor($call_length_seconds / 3600);
            $call_length_min = floor($call_length_seconds / 60 - $call_length_hour * 60);
            $call_length_sec = $call_length_seconds - ($call_length_hour * 3600 + $call_length_min * 60);
            $call_length_min = sprintf("%02d", $call_length_min);
            $call_length_sec = sprintf("%02d", $call_length_sec);
            $call_length = $call_length_hour . ':' . $call_length_min . ':' . $call_length_sec;
            $array[$x]['call_length'] = $call_length;
            //send the command
            if ($field['state'] != '') {
                if ($fp) {
                    $switch_cmd = 'uuid_dump ' . $field['uuid'] . ' json';
                    $dump_result = event_socket_request($fp, 'api ' . $switch_cmd);
                    $dump_array = json_decode($dump_result, true);
                    foreach ($dump_array as $dump_var_name => $dump_var_value) {
                        $array[$x][$dump_var_name] = trim($dump_var_value);
                    }
                }
            }
        }
        //increment the row
        $x++;
    }
    //reindex array using extension instead of auto-incremented value
    $result = array();
    foreach ($array as $index => $subarray) {
        $extension = $subarray['extension'];
        foreach ($subarray as $field => $value) {
            $result[$extension][$field] = $array[$index][$field];
            unset($array[$index][$field]);
        }
        unset($array[$subarray['extension']]['extension']);
        unset($array[$index]);
    }
    //return array
    return $result;
}
示例#10
0
 public function set()
 {
     //set the global variable
     global $db;
     //determine whether to update the dial string
     $sql = "select * from v_extensions ";
     $sql .= "where domain_uuid = '" . $this->domain_uuid . "' ";
     $sql .= "and extension_uuid = '" . $this->extension_uuid . "' ";
     $prep_statement = $db->prepare(check_sql($sql));
     $prep_statement->execute();
     $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
     if (count($result) > 0) {
         foreach ($result as &$row) {
             $this->extension = $row["extension"];
             $this->accountcode = $row["accountcode"];
             $this->outbound_caller_id_name = $row["outbound_caller_id_name"];
             $this->outbound_caller_id_number = $row["outbound_caller_id_number"];
         }
     }
     unset($prep_statement);
     //set the dial string
     if ($this->forward_all_enabled == "true") {
         $dial_string = "{presence_id=" . $this->forward_all_destination . "@" . $_SESSION['domain_name'];
         $dial_string .= ",instant_ringback=true";
         $dial_string .= ",domain_uuid=" . $_SESSION['domain_uuid'];
         $dial_string .= ",sip_invite_domain=" . $_SESSION['domain_name'];
         $dial_string .= ",domain_name=" . $_SESSION['domain_name'];
         $dial_string .= ",domain=" . $_SESSION['domain_name'];
         $dial_string .= ",extension_uuid=" . $this->extension_uuid;
         if (strlen($this->accountcode) > 0) {
             $dial_string .= ",sip_h_X-accountcode=" . $this->accountcode;
             $dial_string .= ",accountcode=" . $this->accountcode;
         }
         if (strlen($this->forward_caller_id_uuid) > 0) {
             $sql_caller = "select destination_number, destination_description from v_destinations where domain_uuid = '{$this->domain_uuid}' and destination_type = 'inbound' and destination_uuid = '{$this->forward_caller_id_uuid}'";
             $prep_statement_caller = $db->prepare($sql_caller);
             if ($prep_statement_caller) {
                 $prep_statement_caller->execute();
                 $row_caller = $prep_statement_caller->fetch(PDO::FETCH_ASSOC);
                 if (strlen($row_caller['destination_description']) > 0) {
                     $dial_string_caller_id_name = $row_caller['destination_description'];
                     $dial_string .= ",origination_caller_id_name={$dial_string_caller_id_name}";
                 }
                 if (strlen($row_caller['destination_number']) > 0) {
                     $dial_string_caller_id_number = $row_caller['destination_number'];
                     $dial_string .= ",origination_caller_id_number={$dial_string_caller_id_number}";
                     $dial_string .= ",outbound_caller_id_number={$dial_string_caller_id_number}";
                 }
             }
         } else {
             if ($_SESSION['cdr']['call_forward_fix']['boolean'] == "true") {
                 $dial_string .= ",outbound_caller_id_name=" . $this->outbound_caller_id_name;
                 $dial_string .= ",outbound_caller_id_number=" . $this->outbound_caller_id_number;
                 $dial_string .= ",origination_caller_id_name=" . $this->outbound_caller_id_name;
                 $dial_string .= ",origination_caller_id_number=" . $this->outbound_caller_id_number;
             }
         }
         $dial_string .= "}";
         if (extension_exists($this->forward_all_destination)) {
             $dial_string .= "user/" . $this->forward_all_destination . "@" . $_SESSION['domain_name'];
         } else {
             if ($_SESSION['domain']['bridge']['text'] == "outbound" || $_SESSION['domain']['bridge']['text'] == "bridge") {
                 $bridge = outbound_route_to_bridge($_SESSION['domain_uuid'], $this->forward_all_destination);
                 $dial_string .= $bridge[0];
             } elseif ($_SESSION['domain']['bridge']['text'] == "lcr") {
                 $dial_string .= "lcr/" . $_SESSION['lcr']['profile']['text'] . "/" . $_SESSION['domain_name'] . "/" . $this->forward_all_destination;
             } elseif ($_SESSION['domain']['bridge']['text'] === "loopback") {
                 $dial_string .= "loopback/" . $this->forward_all_destination;
             } else {
                 $dial_string .= "loopback/" . $this->forward_all_destination;
             }
         }
         $this->dial_string = $dial_string;
     } else {
         $this->dial_string = '';
     }
     //update the extension
     $sql = "update v_extensions set ";
     if (strlen($this->forward_all_destination) == 0 || $this->forward_all_enabled == "false") {
         if (strlen($this->forward_all_destination) == 0) {
             $sql .= "forward_all_destination = null, ";
         }
         $sql .= "dial_string = null, ";
         $sql .= "forward_all_enabled = 'false' ";
     } else {
         $sql .= "forward_all_destination = '{$this->forward_all_destination}', ";
         $sql .= "dial_string = '" . $this->dial_string . "', ";
         $sql .= "forward_all_enabled = 'true' ";
     }
     $sql .= "where domain_uuid = '{$this->domain_uuid}' ";
     $sql .= "and extension_uuid = '{$this->extension_uuid}' ";
     if ($this->debug) {
         echo $sql;
     }
     $db->exec(check_sql($sql));
     unset($sql);
     //delete extension 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 directory:" . $this->extension . "@" . $this->domain_name;
         $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
     }
 }
示例#11
0
 public function active($name)
 {
     if (!$this->fp) {
         $this->fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     }
     if ($this->fp) {
         $cmd = "api module_exists " . $name;
         $response = trim(event_socket_request($this->fp, $cmd));
         if ($response == "true") {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
示例#12
0
function event_socket_request_cmd($cmd)
{
    global $db, $domain_uuid, $host;
    if (file_exists($_SERVER['DOCUMENT_ROOT'] . PROJECT_PATH . "/app/settings/app_config.php")) {
        $sql = "select * from v_settings ";
        $prep_statement = $db->prepare(check_sql($sql));
        $prep_statement->execute();
        $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
        foreach ($result as &$row) {
            $event_socket_ip_address = $row["event_socket_ip_address"];
            $event_socket_port = $row["event_socket_port"];
            $event_socket_password = $row["event_socket_password"];
            break;
            //limit to 1 row
        }
        unset($prep_statement);
    }
    $fp = event_socket_create($event_socket_ip_address, $event_socket_port, $event_socket_password);
    $response = event_socket_request($fp, $cmd);
    fclose($fp);
}
示例#13
0
 /**
  * Delete the entire cache
  */
 public function flush()
 {
     //send a custom event
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     if ($fp) {
         $event = "sendevent CUSTOM\n";
         $event .= "Event-Name: MEMCACHE\n";
         $event .= "Event-Subclass: flush\n";
         $event .= "API-Command: memcache\n";
         $event .= "API-Command-Argument: flush\n";
         echo event_socket_request($fp, $event);
     }
     //run the memcache
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     if ($fp) {
         $command = "memcache flush";
         return event_socket_request($fp, 'api ' . $command);
     } else {
         return false;
     }
 }
示例#14
0
function switch_module_exists($mod)
{
    global $db, $v_id;
    $sql = "";
    $sql .= "select * from v_settings ";
    $sql .= "where v_id = '{$v_id}' ";
    $prepstatement = $db->prepare(check_sql($sql));
    $prepstatement->execute();
    $result = $prepstatement->fetchAll();
    foreach ($result as &$row) {
        $event_socket_ip_address = $row["event_socket_ip_address"];
        $event_socket_port = $row["event_socket_port"];
        $event_socket_password = $row["event_socket_password"];
        break;
        //limit to 1 row
    }
    $switchcmd = "module_exists {$mod}";
    $fp = event_socket_create($event_socket_ip_address, $event_socket_port, $event_socket_password);
    $switch_result = event_socket_request($fp, 'api ' . $switchcmd);
    //$switch_result = eval($switchcmd);
    if (trim($switch_result) == "true") {
        //echo "yes";
        return true;
    } else {
        //echo "no";
        return false;
    }
    unset($switchcmd);
}
示例#15
0
 function delete()
 {
     //create the database object
     $database = new database();
     if ($this->db) {
         $database->db = $this->db;
     }
     //start the transaction
     //$count = $database->db->exec("BEGIN;");
     //delete the ivr menu option
     if (strlen($this->ivr_menu_option_uuid) > 0) {
         $database->table = "v_ivr_menu_options";
         $database->where[0]['name'] = 'domain_uuid';
         $database->where[0]['value'] = $this->domain_uuid;
         $database->where[0]['operator'] = '=';
         $database->where[1]['name'] = 'ivr_menu_option_uuid';
         $database->where[1]['value'] = $this->ivr_menu_option_uuid;
         $database->where[1]['operator'] = '=';
         $database->delete();
         unset($this->ivr_menu_option_uuid);
     }
     //delete the ivr menu
     if (strlen($this->ivr_menu_option_uuid) == 0) {
         //select the dialplan entries
         $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'];
             //delete the child dialplan information
             $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 dialplan information
             $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();
         }
         //delete child data
         $database->table = "v_ivr_menu_options";
         $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->delete();
         //delete parent data
         $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'] = '=';
         $database->delete();
         //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"];
             $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
         }
         //commit the transaction
         //$count = $database->db->exec("COMMIT;");
     }
 }
示例#16
0
 /**
  * Delete the entire cache
  */
 public function flush()
 {
     // connect to event socket
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     if ($fp === false) {
         return false;
     }
     //send a custom event
     $event = "sendevent CUSTOM\n";
     $event .= "Event-Name: MEMCACHE\n";
     $event .= "Event-Subclass: flush\n";
     $event .= "API-Command: memcache\n";
     $event .= "API-Command-Argument: flush\n";
     event_socket_request($fp, $event);
     //run the memcache
     $command = "memcache flush";
     $result = event_socket_request($fp, 'api ' . $command);
     //close event socket
     fclose($fp);
     // return result
     return $result;
 }
示例#17
0
function event_socket_mkdir($dir)
{
    //connect to fs
    $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
    if (!$fp) {
        return false;
    }
    //send the mkdir command to freeswitch
    if ($fp) {
        //build and send the mkdir command to freeswitch
        $switch_cmd = "lua mkdir.lua '{$dir}'";
        $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
        fclose($fp);
        //check result
        if (trim($switch_result) == "-ERR no reply") {
            return true;
        }
    }
    //can not create directory
    return false;
}
示例#18
0
 public function message_waiting()
 {
     //send the message waiting status
     $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
     if ($fp) {
         $switch_cmd .= "luarun app.lua voicemail mwi " . $this->voicemail_id . "@" . $_SESSION['domain_name'];
         $switch_result = event_socket_request($fp, 'api ' . $switch_cmd);
     }
 }
示例#19
0
            case 'shell':
                if (permission_exists('exec_command')) {
                    $result = htmlentities(shell_exec($cmd));
                }
                break;
            case 'php':
                if (permission_exists('exec_php')) {
                    ob_start();
                    eval($cmd);
                    $result = ob_get_contents();
                    ob_end_clean();
                }
                break;
            case 'switch':
                if (permission_exists('exec_switch')) {
                    $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
                    if ($fp) {
                        $result = htmlentities(event_socket_request($fp, 'api ' . $cmd));
                    }
                }
                break;
        }
        if ($result != '') {
            echo "<span id='response'>";
            echo "<b>" . $text['label-response'] . "</b>\n";
            echo "<br /><br />\n";
            echo $handler == 'switch' ? "<textarea style='width: 100%; height: 450px; font-family: monospace; padding: 15px;' wrap='off'>" . $result . "</textarea>\n" : "<pre>" . $result . "</pre>";
            echo "</span>";
        }
    }
}
示例#20
0
function sync_package_v_auto_attendant()
{
    global $db, $v_id, $host;
    $v_settings_array = v_settings();
    foreach ($v_settings_array as $name => $value) {
        ${$name} = $value;
    }
    $db->beginTransaction();
    //prepare for auto attendant .js files to be written. delete all auto attendants that are prefixed with autoattendant_ and have a file extension of .js
    $v_prefix = 'autoattendant_';
    if ($dh = opendir($v_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, -3) == '.js') {
                        //echo "file: $file<br />\n";
                        //echo "extension: ".substr($file,-3)."<br />";
                        unlink($v_scripts_dir . '/' . $file);
                    }
                }
            }
        }
        closedir($dh);
    }
    //loop through all auto attendants
    $sql = "";
    $sql .= "select * from v_auto_attendant ";
    $sql .= "where v_id = '{$v_id}' ";
    $prepstatement = $db->prepare(check_sql($sql));
    $prepstatement->execute();
    $result = $prepstatement->fetchAll();
    foreach ($result as &$row) {
        //add the auto attendant to the dialplan
        if (strlen($row['auto_attendant_id']) > 0) {
            $action = 'add';
            //set default action to add
            $sql = "";
            $sql .= "select * from v_dialplan_includes ";
            $sql .= "where v_id = '{$v_id}' ";
            $sql .= "and opt1name = 'auto_attendant_id' ";
            $sql .= "and opt1value = '" . $row['auto_attendant_id'] . "' ";
            $prepstatement2 = $db->prepare($sql);
            $prepstatement2->execute();
            while ($row2 = $prepstatement2->fetch()) {
                $action = 'update';
                $dialplan_include_id = $row2['dialplan_include_id'];
                break;
                //limit to 1 row
            }
            unset($sql, $prepstatement2);
        }
        if ($action == 'add') {
            //create auto attendant extension in the dialplan
            $extensionname = $row['aaextension'];
            $dialplanorder = '9001';
            $context = $row['aacontext'];
            $enabled = 'true';
            $descr = 'auto attendant';
            $opt1name = 'auto_attendant_id';
            $opt1value = $row['auto_attendant_id'];
            $dialplan_include_id = v_dialplan_includes_add($v_id, $extensionname, $dialplanorder, $context, $enabled, $descr, $opt1name, $opt1value);
            $tag = 'condition';
            //condition, action, antiaction
            $fieldtype = 'destination_number';
            $fielddata = '^' . $row['aaextension'] . '$';
            $fieldorder = '000';
            v_dialplan_includes_details_add($v_id, $dialplan_include_id, $tag, $fieldorder, $fieldtype, $fielddata);
            $tag = 'action';
            //condition, action, antiaction
            $fieldtype = 'javascript';
            $fielddata = 'autoattendant_' . $row['aaextension'] . '.js';
            $fieldorder = '001';
            v_dialplan_includes_details_add($v_id, $dialplan_include_id, $tag, $fieldorder, $fieldtype, $fielddata);
        }
        if ($action == 'update') {
            $extensionname = $row['aaextension'];
            $dialplanorder = '9001';
            $context = $row['aacontext'];
            $enabled = 'true';
            $descr = 'auto attendant';
            $auto_attendant_id = $row['auto_attendant_id'];
            //update the main dialplan entry
            $sql = "";
            $sql = "update v_dialplan_includes set ";
            $sql .= "extensionname = '{$extensionname}', ";
            $sql .= "dialplanorder = '{$dialplanorder}', ";
            $sql .= "context = '{$context}', ";
            $sql .= "enabled = '{$enabled}', ";
            $sql .= "descr = '{$descr}' ";
            $sql .= "where v_id = '{$v_id}' ";
            $sql .= "and opt1name = 'auto_attendant_id' ";
            $sql .= "and opt1value = '{$auto_attendant_id}' ";
            //echo "sql: ".$sql."<br />";
            //exit;
            $db->query($sql);
            unset($sql);
            //update the condition
            $sql = "";
            $sql = "update v_dialplan_includes_details set ";
            $sql .= "fielddata = '^" . $row['aaextension'] . "\$' ";
            $sql .= "where v_id = '{$v_id}' ";
            $sql .= "and tag = 'condition' ";
            $sql .= "and fieldtype = 'destination_number' ";
            $sql .= "and dialplan_include_id = '{$dialplan_include_id}' ";
            //echo $sql."<br />";
            $db->query($sql);
            unset($sql);
            //update the action
            $sql = "";
            $sql = "update v_dialplan_includes_details set ";
            $sql .= "fielddata = 'autoattendant_" . $row['aaextension'] . ".js' ";
            $sql .= "where v_id = '{$v_id}' ";
            $sql .= "and tag = 'action' ";
            $sql .= "and fieldtype = 'javascript' ";
            $sql .= "and dialplan_include_id = '{$dialplan_include_id}' ";
            //echo $sql."<br />";
            $db->query($sql);
            unset($sql);
            unset($ent);
            unset($extensionname);
            unset($dialplanorder);
            unset($context);
            unset($enabled);
            unset($descr);
            unset($opt1name);
            unset($opt1value);
        }
        sync_package_v_dialplan_includes();
        unset($dialplanincludeid);
        // Build the auto attendant javascript
        $recording_action_filename = get_recording_filename($row['recordingidaction']);
        $recording_antiaction_filename = get_recording_filename($row['recordingidantiaction']);
        $sql = "";
        $sql .= "select * from v_settings ";
        $sql .= "where v_id = '{$v_id}' ";
        $prepstatement2 = $db->prepare($sql);
        $prepstatement2->execute();
        while ($row2 = $prepstatement2->fetch()) {
            $event_socket_ip_address = $row2["event_socket_ip_address"];
            $event_socket_port = $row2["event_socket_port"];
            $event_socket_password = $row2["event_socket_password"];
        }
        unset($prepstatement2);
        if (pkg_is_service_running('freeswitch')) {
            $fp = event_socket_create($event_socket_ip_address, $event_socket_port, $event_socket_password);
            $cmd = "api global_getvar domain";
            $domain = trim(event_socket_request($fp, $cmd));
        }
        $tmp = "";
        //make sure the variable starts with no value
        $tmp .= "\n";
        $tmp .= " var condition = true;\n";
        $tmp .= "\n";
        $tmp .= " var domain = \"" . $domain . "\"; //by default this is the ipv4 address of FreeSWITCH used for transfer to voicemail\n";
        $tmp .= " var digitmaxlength = 0;\n";
        $tmp .= " var objdate = new Date();\n";
        $tmp .= "\n";
        $tmp .= " var adjusthours = 0; //Adjust Server time that is set to GMT 7 hours\n";
        $tmp .= " var adjustoperator = \"-\"; //+ or -\n";
        $tmp .= "\n";
        $tmp .= " if (adjustoperator == \"-\") {\n";
        $tmp .= "   var objdate2 = new Date(objdate.getFullYear(),objdate.getMonth(),objdate.getDate(),(objdate.getHours() - adjusthours),objdate.getMinutes(),objdate.getSeconds());\n";
        $tmp .= " }\n";
        $tmp .= " if (adjustoperator == \"+\") {\n";
        $tmp .= "   var objdate2 = new Date(objdate.getFullYear(),objdate.getMonth(),objdate.getDate(),(objdate.getHours() + adjusthours),objdate.getMinutes(),objdate.getSeconds());\n";
        $tmp .= " }\n";
        $tmp .= "\n";
        $tmp .= " var Hours = objdate2.getHours();\n";
        $tmp .= " var Mins = objdate2.getMinutes();\n";
        $tmp .= " var Seconds = objdate2.getSeconds();\n";
        $tmp .= " var Month = objdate2.getMonth() + 1;\n";
        $tmp .= " var Date = objdate2.getDate();\n";
        $tmp .= " var Year = objdate2.getYear()\n";
        $tmp .= " var Day = objdate2.getDay()+1;\n";
        $tmp .= " var exit = false;\n";
        $tmp .= "\n";
        $tmp .= " dialed_extension = session.getVariable(\"dialed_extension\");\n";
        $tmp .= " domain_name = session.getVariable(\"domain_name\");\n";
        $tmp .= " domain = session.getVariable(\"domain\");\n";
        $tmp .= " us_ring = session.getVariable(\"us-ring\");\n";
        $tmp .= " caller_id_name = session.getVariable(\"caller_id_name\");\n";
        $tmp .= " caller_id_number = session.getVariable(\"caller_id_number\");\n";
        $tmp .= " effective_caller_id_name = session.getVariable(\"effective_caller_id_name\");\n";
        $tmp .= " effective_caller_id_number = session.getVariable(\"effective_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";
        //set caller id prefix
        if (strlen($row['aacidnameprefix']) > 0) {
            $tmp .= "session.execute(\"set\", \"caller_id_name=" . $row['aacidnameprefix'] . "\"+caller_id_name);\n";
            $tmp .= "session.execute(\"set\", \"effective_caller_id_name=" . $row['aacidnameprefix'] . "\"+effective_caller_id_name);\n";
            $tmp .= "session.execute(\"set\", \"outbound_caller_id_name=" . $row['aacidnameprefix'] . "\"+outbound_caller_id_name);\n";
        }
        $tmp .= "\n";
        $tmp .= "session.execute(\"set\", \"ignore_early_media=true\");\n";
        $tmp .= " session.execute(\"set\", \"hangup_after_bridge=true\");\n";
        $tmp .= " session.execute(\"set\", \"continue_on_fail=true\");\n";
        if (strlen($row['aacalltimeout']) == 0) {
            $tmp .= " session.execute(\"set\", \"call_timeout=30\");\n";
            //aacalltimeout
            $tmp .= " session.execute(\"export\", \"call_timeout=30\");\n";
            //aacalltimeout
        } else {
            $tmp .= " session.execute(\"set\", \"call_timeout=" . $row['aacalltimeout'] . "\");\n";
            //aacalltimeout
            $tmp .= " session.execute(\"export\", \"call_timeout=" . $row['aacalltimeout'] . "\");\n";
            //aacalltimeout
        }
        if (isset($row['aaringback'])) {
            if ($row['aaringback'] == "ring") {
                $tmp .= " session.execute(\"set\", \"ringback=\"+us_ring);          //set to ringtone\n";
                $tmp .= " session.execute(\"set\", \"transfer_ringback=\"+us_ring); //set to ringtone\n";
            }
            if ($row['aaringback'] == "music") {
                $tmp .= " session.execute(\"set\", \"ringback=\${hold_music}\");          //set to ringtone\n";
                $tmp .= " session.execute(\"set\", \"transfer_ringback=\${hold_music}\"); //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";
        }
        $tmp .= "\n";
        $tmp .= "//console_log( \"info\", \"Auto Attendant Server Time is: \"+Hours+\":\"+Mins+\" \\n\" );\n";
        $tmp .= "\n";
        $tmp .= " function get_sofia_contact(extension,domain_name, profile){\n";
        $tmp .= "\tif (profile == \"auto\") {\n";
        $i = 0;
        foreach (ListFiles($v_conf_dir . '/sip_profiles') as $key => $sip_profile_file) {
            $sip_profile_name = str_replace(".xml", "", $sip_profile_file);
            if ($i == 0) {
                $tmp .= "\t\t\tprofile = \"" . $sip_profile_name . "\";\n";
                $tmp .= "\t\t\tsession.execute(\"set\", \"sofia_contact_\"+extension+\"=\${sofia_contact(\"+profile+\"/\"+extension+\"@\"+domain_name+\")}\");\n";
                $tmp .= "\t\t\tsofia_contact = session.getVariable(\"sofia_contact_\"+extension);\n";
            } else {
                $tmp .= "\n";
                $tmp .= "\t\t\tif (sofia_contact == \"error/user_not_registered\") {\n";
                $tmp .= "\t\t\t\tprofile = \"" . $sip_profile_name . "\";\n";
                $tmp .= "\t\t\t\tsession.execute(\"set\", \"sofia_contact_\"+extension+\"=\${sofia_contact(\"+profile+\"/\"+extension+\"@\"+domain_name+\")}\");\n";
                $tmp .= "\t\t\t\tsofia_contact = session.getVariable(\"sofia_contact_\"+extension);\n";
                $tmp .= "\t\t\t}\n";
            }
            $i++;
        }
        unset($i);
        $tmp .= "\t}\n";
        $tmp .= "\telse {\n";
        $tmp .= "\t\tsession.execute(\"set\", \"sofia_contact_\"+extension+\"=\${sofia_contact(\"+profile+\"/\"+extension+\"@\"+domain_name+\")}\");\n";
        $tmp .= "\t\tsofia_contact = session.getVariable(\"sofia_contact_\"+extension);\n";
        $tmp .= "\t}\n";
        $tmp .= "\tconsole_log( \"info\", \"sofia_contact \"+profile+\": \"+sofia_contact+\".\\n\" );\n";
        $tmp .= "\treturn sofia_contact;\n";
        $tmp .= " }\n";
        $tmp .= "\n";
        $tmp .= " function mycb( session, type, obj, arg ) {\n";
        $tmp .= "    try {\n";
        $tmp .= "        if ( type == \"dtmf\" ) {\n";
        $tmp .= "          console_log( \"info\", \"digit: \"+obj.digit+\"\\n\" );\n";
        $tmp .= "          if ( obj.digit == \"#\" ) {\n";
        $tmp .= "            //console_log( \"info\", \"detected pound sign.\\n\" );\n";
        $tmp .= "            exit = true;\n";
        $tmp .= "            return( false );\n";
        $tmp .= "          }\n";
        $tmp .= "\n";
        $tmp .= "          dtmf.digits += obj.digit;\n";
        $tmp .= "\n";
        $tmp .= "          if ( dtmf.digits.length >= digitmaxlength ) {\n";
        $tmp .= "            exit = true;\n";
        $tmp .= "            return( false );\n";
        $tmp .= "          }\n";
        $tmp .= "        }\n";
        $tmp .= "    } catch (e) {\n";
        $tmp .= "        console_log( \"err\", e+\"\\n\" );\n";
        $tmp .= "    }\n";
        $tmp .= "    return( true );\n";
        $tmp .= " } //end function mycb\n";
        $tmp .= "\n";
        //condition
        $tmp .= $row['aaconditionjs'];
        $tmp .= "\n";
        $tmp .= "\n";
        //$tmp .= " //condition = true; //debugging\n";
        $actiondirect = false;
        $actiondefault = false;
        $actioncount = 0;
        $sql = "";
        $sql .= "select * from v_auto_attendant_options ";
        $sql .= "where v_id = '{$v_id}' ";
        $sql .= "and auto_attendant_id = '" . $row['auto_attendant_id'] . "' ";
        //echo $sql;
        $prepstatement2 = $db->prepare($sql);
        $prepstatement2->execute();
        while ($row2 = $prepstatement2->fetch()) {
            //$auto_attendant_id = $row2["auto_attendant_id"];
            //$optionaction = $row2["optionaction"];
            //$optionnumber = $row2["optionnumber"];
            //$optiontype = $row2["optiontype"];
            //$optionprofile = $row2["optionprofile"];
            //$optiondata = $row2["optiondata"];
            //$optiondescr = $row2["optiondescr"];
            if ($row2['optionaction'] == "action") {
                $actioncount++;
                if (strtolower($row2['optionnumber']) == "n") {
                    //direct the call now don't wait for dtmf
                    //echo "now found\n";
                    $actiondirect = true;
                    $actiondirecttype = $row2['optiontype'];
                    $actiondirectprofile = $row2['optionprofile'];
                    $actiondirectdest = $row2['optiondata'];
                    $actiondirectdesc = $row2['optiondesc'];
                }
                if (strtolower($row2['optionnumber']) == "d") {
                    //default option used when dtmf doesn't match any other option
                    //echo "default found\n";
                    $actiondefault = true;
                    $actiondefaulttype = $row2['optiontype'];
                    $actiondefaultprofile = $row2['optionprofile'];
                    $actiondefaultdest = $row2['optiondata'];
                    $actiondefaultdesc = $row2['optiondesc'];
                    $actiondefaultrecording = $row2['optionrecording'];
                }
            }
        }
        //end while
        unset($prepstatement2);
        //$tmp .= "action count: ".$actioncount."<br />\n";
        if ($actioncount > 0) {
            if ($actiondirect) {
                $tmp .= " if (condition) {\n";
                $tmp .= "    //direct\n";
                $tmp .= "    //console_log( \"info\", \"action direct\\n\" );\n";
                //play the option recording if it exists
                if (strlen($row2['optionrecording']) > 0) {
                    $option_recording_filename = get_recording_filename($row2['optionrecording']);
                    $tmp .= "    session.streamFile( \"" . $v_recordings_dir . "/" . $option_recording_filename . "\" );\n";
                }
                $tmp .= "    session.execute(\"" . $actiondirecttype . "\", \"" . $actiondirectdest . "\"); //" . $actiondirectdesc . "\n";
                //if ($actiondirecttype == "extension") {
                //	$tmp .= "    sofia_contact_".$actiondirectdest." = get_sofia_contact(\"".$actiondirectdest."\",domain_name, \"".$actiondirectprofile."\");\n";
                //	$tmp .= "    session.execute(\"bridge\", sofia_contact_".$actiondirectdest."); //".$actiondirectdest."\n";
                //	if ($actiondirectprofile == "auto") {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$actiondirectdest."\");\n";
                //	}
                //	else {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$actiondirectdest."\");\n";
                //	}
                //}
                //if ($actiondirecttype == "voicemail") {
                //	if ($actiondirectprofile == "auto") {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$actiondirectdest."\");\n";
                //	}
                //	else {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$actiondirectdest."\");\n";
                //	}
                //}
                //if ($actiondirecttype == "sip uri") {
                //	$tmp .= "    session.execute(\"bridge\", \"".$actiondirectdest."\"); //".$actiondirectdest."\n";
                //}
                $tmp .= "}\n";
            } else {
                $tmp .= " if (condition) {\n";
                $tmp .= "    //action\n";
                $tmp .= "\n";
                $tmp .= "     //console_log( \"info\", \"action call now don't wait for dtmf\\n\" );\n";
                $tmp .= "      var dtmf = new Object( );\n";
                $tmp .= "     dtmf.digits = \"\";\n";
                $tmp .= "     if ( session.ready( ) ) {\n";
                $tmp .= "         session.answer( );\n";
                $tmp .= "\n";
                $tmp .= "         digitmaxlength = 1;\n";
                $tmp .= "         while (session.ready() && ! exit ) {\n";
                $tmp .= "           session.streamFile( \"" . $v_recordings_dir . "/" . $recording_action_filename . "\", mycb, \"dtmf " . $row['aatimeout'] . "\" );\n";
                $tmp .= "           if (session.ready()) {\n";
                $tmp .= "           \tif (dtmf.digits.length == 0) {\n";
                $tmp .= "           \t\tdtmf.digits +=  session.getDigits(1, \"#\", " . $row['aatimeout'] * 1000 . "); // " . $row['aatimeout'] . " seconds\n";
                $tmp .= "           \t\tif (dtmf.digits.length == 0) {\n";
                //$tmp .= "           			console_log( "info", "time out option: " + dtmf.digits + "\n" );\n";
                //find the timeout auto attendant options with the correct action
                $sql = "";
                $sql .= "select * from v_auto_attendant_options ";
                $sql .= "where auto_attendant_id = '" . $row['auto_attendant_id'] . "' ";
                $sql .= "and v_id = '{$v_id}' ";
                $prepstatement2 = $db->prepare($sql);
                $prepstatement2->execute();
                while ($row2 = $prepstatement2->fetch()) {
                    //$auto_attendant_id = $row2["auto_attendant_id"];
                    //$optionaction = $row2["optionaction"];
                    //$optionnumber = $row2["optionnumber"];
                    //$optiontype = $row2["optiontype"];
                    //$optiondata = $row2["optiondata"];
                    //$optionprofile = $row2["optionprofile"];
                    //$optiondescr = $row2["optiondescr"];
                    if ($row2['optionaction'] == "action") {
                        if (strtolower($row2['optionnumber']) == "t") {
                            //play the option recording if it exists
                            if (strlen($row2['optionrecording']) > 0) {
                                $option_recording_filename = get_recording_filename($row2['optionrecording']);
                                $tmp .= "                 \tsession.streamFile( \"" . $v_recordings_dir . "/" . $option_recording_filename . "\" );\n";
                            }
                            $tmp .= "                 \tsession.execute(\"" . $row2['optiontype'] . "\", \"" . $row2['optiondata'] . "\"); //" . $row2['optiondescr'] . "\n";
                            //if ($row2['optiontype'] == "extension") {
                            //	$tmp .= "                 	sofia_contact_".$row2['optiondata']." = get_sofia_contact(\"".$row2['optiondata']."\",domain_name, \"".$row2['optionprofile']."\");\n";
                            //	$tmp .= "                 	session.execute(\"bridge\", sofia_contact_".$row2['optiondata']."); //".$row2['optiondescr']."\n";
                            //	if ($row2['optionprofile'] == "auto") {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\");\n";
                            //	}
                            //	else {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\");\n";
                            //	}
                            //}
                            //if ($row2['optiontype'] == "voicemail") {
                            //	if ($row2['optionprofile'] == "auto") {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                            //	}
                            //	else {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                            //	}
                            //}
                            //if ($row2['optiontype'] == "sip uri") {
                            //	$tmp .= "                 	session.execute(\"bridge\", \"".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                            //}
                        }
                    }
                    //end anti-action
                }
                //end while
                unset($prepstatement2);
                $tmp .= "           \t\t}\n";
                $tmp .= "           \t\telse {\n";
                $tmp .= "           \t\t\tbreak; //dtmf found end the while loop\n";
                $tmp .= "           \t\t}\n";
                $tmp .= "           \t}\n";
                $tmp .= "           }\n";
                $tmp .= "         }\n";
                $tmp .= "\n";
                $tmp .= "         //pickup the remaining digits\n";
                //$tmp .= "         //http://wiki.freeswitch.org/wiki/Session_getDigits\n";
                //$tmp .= "         //getDigits(length, terminators, timeout, digit_timeout, abs_timeout)\n";
                //$tmp .= "       //dtmf.digits +=  session.getDigits(2, \"#\", 3000); //allow up to 3 digits\n";
                $tmp .= "         dtmf.digits +=  session.getDigits(4, \"#\", 3000); //allow up to 5 digits\n";
                $tmp .= "\n";
                $tmp .= "\n";
                //$tmp .= "         console_log( \"info\", \"Auto Attendant Digit Pressed: \" + dtmf.digits + \"\\n\" );\n";
                //action
                $tmpaction = "";
                $tmp .= "         if ( dtmf.digits.length > \"0\" ) {\n\n";
                $x = 0;
                $sql = "";
                $sql .= "select * from v_auto_attendant_options ";
                $sql .= "where auto_attendant_id = '" . $row['auto_attendant_id'] . "' ";
                $sql .= "and v_id = '{$v_id}' ";
                $prepstatement2 = $db->prepare($sql);
                $prepstatement2->execute();
                while ($row2 = $prepstatement2->fetch()) {
                    //$auto_attendant_id = $row2["auto_attendant_id"];
                    //$optionaction = $row2["optionaction"];
                    //$optionnumber = $row2["optionnumber"];
                    //$optiontype = $row2["optiontype"];
                    //$optiondata = $row2["optiondata"];
                    //$optionprofile = $row2["optionprofile"];
                    //$optiondescr = $row2["optiondescr"];
                    $tmpactiondefault = "";
                    if ($row2['optionaction'] == "action") {
                        //$tmpaction .= "\n";
                        switch ($row2['optionnumber']) {
                            //case "t":
                            //		break;
                            //case "d":
                            //		break;
                            default:
                                //$tmpaction .= "             //console_log( \"info\", \"Auto Attendant Detected 1 digit \\n\" );\n";
                                if ($x == 0) {
                                    $tmpaction .= "             if ( dtmf.digits == \"" . $row2['optionnumber'] . "\" ) { //" . $row2['optiondescr'] . "\n";
                                } else {
                                    $tmpaction .= "             else if ( dtmf.digits == \"" . $row2['optionnumber'] . "\" ) { //" . $row2['optiondescr'] . "\n";
                                }
                                //play the option recording if it was provided
                                if (strlen($row2['optionrecording']) > 0) {
                                    $option_recording_filename = get_recording_filename($row2['optionrecording']);
                                    $tmpaction .= "                 session.streamFile( \"" . $v_recordings_dir . "/" . $option_recording_filename . "\" );\n";
                                }
                                $tmpaction .= "                 session.execute(\"" . $row2['optiontype'] . "\", \"" . $row2['optiondata'] . "\"); //" . $row2['optiondescr'] . "\n";
                                //if ($row2['optiontype'] == "extension") {
                                //	$tmpaction .= "                 sofia_contact_".$row2['optiondata']." = get_sofia_contact(\"".$row2['optiondata']."\",domain_name, \"".$row2['optionprofile']."\");\n";
                                //	$tmpaction .= "                 session.execute(\"bridge\", sofia_contact_".$row2['optiondata']."); //".$row2['optiondescr']."\n";
                                //	if ($row2['optionprofile'] == "auto") {
                                //		$tmpaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\");\n";
                                //	}
                                //	else {
                                //		$tmpaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                                //	}
                                //}
                                //if ($row2['optiontype'] == "voicemail") {
                                //	if ($row2['optionprofile'] == "auto") {
                                //		$tmpaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                                //	}
                                //	else {
                                //		$tmpaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                                //	}
                                //}
                                //if ($row2['optiontype'] == "sip uri") {
                                //	$tmpaction .= "                 session.execute(\"bridge\", \"".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                                //}
                                $tmpaction .= "             }\n";
                        }
                        $x++;
                    }
                    //end auto_attendant_id
                }
                //end while
                unset($prepstatement2);
                $tmp .= $tmpaction;
                if ($row['aadirectdial'] == "true") {
                    $tmp .= "             else {\n";
                    $tmp .= "\t                  session.execute(\"transfer\", dtmf.digits+\" XML default\");\n";
                    //$tmp .= $tmpactiondefault;
                    $tmp .= "             }\n";
                } else {
                    if ($actiondefault) {
                        $tmp .= "             else {\n";
                        $tmp .= "\t                  //console_log( \"info\", \"default option when there is no matching dtmf found\\n\" );\n";
                        //play the option recording if it exists
                        if (strlen($actiondefaultrecording) > 0) {
                            $option_recording_filename = get_recording_filename($actiondefaultrecording);
                            $tmp .= "\t                  session.streamFile( \"" . $v_recordings_dir . "/" . $option_recording_filename . "\" );\n";
                        }
                        $tmp .= "\t                  session.execute(\"" . $actiondefaulttype . "\", \"" . $actiondefaultdest . "\"); //" . $actiondefaultdesc . "\n";
                        //if ($actiondefaulttype == "extension") {
                        //	$tmp .= "	                  sofia_contact_".$actiondefaultdest." = get_sofia_contact(\"".$actiondefaultdest."\",domain_name, \"".$actiondefaultprofile."\");\n";
                        //	$tmp .= "	                  session.execute(\"bridge\", sofia_contact_".$actiondefaultdest."); //".$actiondefaultdest."\n";
                        //	if ($actiondirectprofile == "auto") {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$actiondefaultdest."\");\n";
                        //	}
                        //	else {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$actiondefaultdest."\");\n";
                        //	}
                        //}
                        //if ($actiondefaulttype == "voicemail") {
                        //	if ($actiondirectprofile == "auto") {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$actiondefaultdest."\");\n";
                        //	}
                        //	else {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$actiondefaultdest."\");\n";
                        //	}
                        //}
                        //if ($actiondefaulttype == "sip uri") {
                        //	$tmp .= "	                  session.execute(\"bridge\", \"".$actiondefaultdest."\"); //".$actiondefaultdest."\n";
                        //}
                        $tmp .= "             }\n";
                    }
                }
                $tmp .= "\n";
                unset($tmpaction);
                $tmp .= "          } \n";
                //$tmp .= "          else if ( dtmf.digits.length == \"4\" ) {\n";
                //$tmp .= "	                  //Transfer to the extension the caller\n";
                //$tmp .= "	                  session.execute(\"transfer\", dtmf.digits+\" XML default\");\n";
                //$tmp .= "          } else {\n";
                //$tmp .= $tmpactiondefault;
                //$tmp .= "          }\n";
                $tmp .= "\n";
                $tmp .= "     } //end if session.ready\n";
                $tmp .= "\n";
                $tmp .= " }\n";
                //end if condition
            }
            //if ($actiondirect)
        }
        //actioncount
        $antiactiondirect = false;
        $antiactiondefault = false;
        $antiactioncount = 0;
        $sql = "";
        $sql .= "select * from v_auto_attendant_options ";
        $sql .= "where auto_attendant_id = '" . $row['auto_attendant_id'] . "' ";
        $sql .= "and v_id = '{$v_id}' ";
        $prepstatement2 = $db->prepare($sql);
        $prepstatement2->execute();
        while ($row2 = $prepstatement2->fetch()) {
            //$auto_attendant_id = $row2["auto_attendant_id"];
            //$optionaction = $row2["optionaction"];
            //$optionnumber = $row2["optionnumber"];
            //$optiontype = $row2["optiontype"];
            //$optionprofile = $row2["optionprofile"];
            //$optiondata = $row2["optiondata"];
            //$optiondescr = $row2["optiondescr"];
            if ($row2['optionaction'] == "anti-action") {
                $antiactioncount++;
                if (strtolower($row2['optionnumber']) == "n") {
                    //direct the call now don't wait for dtmf
                    $antiactiondirect = true;
                    $antiactiondirecttype = $row2['optiontype'];
                    $antiactiondirectdest = $row2['optiondata'];
                    $antiactiondirectdesc = $row2['optiondesc'];
                    $antiactiondirectprofile = $row2['optionprofile'];
                }
                if (strtolower($row2['optionnumber']) == "d") {
                    //default option used when an dtmf doesn't match any option
                    $antiactiondefault = true;
                    $antiactiondefaulttype = $row2['optiontype'];
                    $antiactiondefaultdest = $row2['optiondata'];
                    $antiactiondefaultdesc = $row2['optiondesc'];
                    $antiactiondefaultrecording = $row2['optionrecording'];
                    $antiactiondefaultprofile = $row2['optionprofile'];
                }
            }
        }
        //end while
        unset($prepstatement2);
        //$tmp .= "anti-action count: ".$antiactioncount."<br />\n";
        if ($antiactioncount > 0) {
            if ($antiactiondirect) {
                $tmp .= " else {\n";
                $tmp .= "     //console_log( \"info\", \"anti-action call now don't wait for dtmf\\n\" );\n";
                $tmp .= "     session.execute(\"" . $antiactiondirecttype . "\", \"" . $antiactiondirectdest . "\"); //" . $antiactiondefaultdesc . "\n";
                //if ($antiactiondirecttype == "extension") {
                //	$tmp .= "    sofia_contact_".$antiactiondirectdest." = get_sofia_contact(\"".$antiactiondirectdest."\",domain_name, \"".$antiactiondirectprofile."\");\n";
                //	$tmp .= "    session.execute(\"bridge\", sofia_contact_".$antiactiondirectdest."); //".$antiactiondirectdest."\n";
                //	if ($antiactiondirectprofile == "auto") {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$antiactiondirectdest."\");\n";
                //	}
                //	else {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$antiactiondirectdest."\");\n";
                //	}
                //}
                //if ($antiactiondirecttype == "voicemail") {
                //	if ($antiactiondirectprofile == "auto") {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$antiactiondirectdest."\");\n";
                //	}
                //	else {
                //		$tmp .= "    session.execute(\"voicemail\", \"default \${domain} ".$antiactiondirectdest."\");\n";
                //	}
                //}
                //if ($antiactiondirecttype == "sip uri") {
                //	$tmp .= "    session.execute(\"bridge\", \"".$antiactiondirectdest."\"); //".$antiactiondirectdest."\n";
                //}
                $tmp .= "}\n";
            } else {
                $tmp .= " else {\n";
                $tmp .= "     //anti-action\n";
                $tmp .= "     //console_log( \"info\", \"anti-action options\\n\" );\n";
                $tmp .= "\n";
                $tmp .= "     var dtmf = new Object( );\n";
                $tmp .= "     dtmf.digits = \"\";\n";
                $tmp .= "     if ( session.ready( ) ) {\n";
                $tmp .= "         session.answer( );\n";
                $tmp .= "\n";
                $tmp .= "         digitmaxlength = 1;\n";
                $tmp .= "         while (session.ready() && ! exit ) {\n";
                $tmp .= "           session.streamFile( \"" . $v_recordings_dir . "/" . $recording_antiaction_filename . "\", mycb, \"dtmf " . $row['aatimeout'] . "\" );\n";
                $tmp .= "           if (session.ready()) {\n";
                $tmp .= "           \tif (dtmf.digits.length == 0) {\n";
                $tmp .= "           \t\tdtmf.digits +=  session.getDigits(1, \"#\", " . $row['aatimeout'] * 1000 . "); // " . $row['aatimeout'] . " seconds\n";
                $tmp .= "           \t\tif (dtmf.digits.length == 0) {\n";
                //$tmp .= "           			console_log( "info", "time out option: " + dtmf.digits + "\n" );\n";
                //find the timeout auto attendant options with the correct action
                $sql = "";
                $sql .= "select * from v_auto_attendant_options ";
                $sql .= "where auto_attendant_id = '" . $row['auto_attendant_id'] . "' ";
                $sql .= "and v_id = '{$v_id}' ";
                $prepstatement2 = $db->prepare($sql);
                $prepstatement2->execute();
                while ($row2 = $prepstatement2->fetch()) {
                    $auto_attendant_id = $row2["auto_attendant_id"];
                    $optionaction = $row2["optionaction"];
                    $optionnumber = $row2["optionnumber"];
                    $optiontype = $row2["optiontype"];
                    $optionprofile = $row2["optionprofile"];
                    $optiondata = $row2["optiondata"];
                    $optiondescr = $row2["optiondescr"];
                    if ($row2['optionaction'] == "anti-action") {
                        if (strtolower($row2['optionnumber']) == "t") {
                            //play the option recording if it exists
                            if (strlen($row2['optionrecording']) > 0) {
                                $option_recording_filename = get_recording_filename($row2['optionrecording']);
                                $tmp .= "                 \tsession.streamFile( \"" . $v_recordings_dir . "/" . $option_recording_filename . "\" );\n";
                            }
                            $tmp .= "                 \tsession.execute(\"" . $row2['optiontype'] . "\", \"" . $row2['optiondata'] . "\"); //" . $row2['optiondescr'] . "\n";
                            //if ($row2['optiontype'] == "extension") {
                            //	$tmp .= "                 	sofia_contact_".$row2['optiondata']." = get_sofia_contact(\"".$row2['optiondata']."\",domain_name, \"".$row2['optionprofile']."\");\n";
                            //	$tmp .= "                 	session.execute(\"bridge\", sofia_contact_".$row2['optiondata']."); //".$row2['optiondescr']."\n";
                            //	if ($row2['optionprofile'] == "auto") {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\");\n";
                            //	}
                            //	else {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\");\n";
                            //	}
                            //}
                            //if ($row2['optiontype'] == "voicemail") {
                            //	if ($row2['optionprofile'] == "auto") {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                            //	}
                            //	else {
                            //		$tmp .= "                 	session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                            //	}
                            //}
                            //if ($row2['optiontype'] == "sip uri") {
                            //	$tmp .= "                 	session.execute(\"bridge\", \"".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                            //}
                        }
                    }
                    //end anti-action
                }
                //end while
                unset($prepstatement2);
                $tmp .= "           \t\t}\n";
                $tmp .= "           \t\telse {\n";
                $tmp .= "           \t\t\tbreak; //dtmf found end the while loop\n";
                $tmp .= "           \t\t}\n";
                $tmp .= "           \t}\n";
                $tmp .= "           }\n";
                $tmp .= "         }\n";
                $tmp .= "\n";
                $tmp .= "         //pickup the remaining digits\n";
                $tmp .= "         //http://wiki.freeswitch.org/wiki/Session_getDigits\n";
                $tmp .= "         //getDigits(length, terminators, timeout, digit_timeout, abs_timeout)\n";
                $tmp .= "         dtmf.digits +=  session.getDigits(4, \"#\", 3000);\n";
                $tmp .= "\n";
                $tmp .= "         console_log( \"info\", \"Auto Attendant Digit Pressed: \" + dtmf.digits + \"\\n\" );\n";
                $tmp .= "\n";
                $tmpantiaction = "";
                $tmp .= "         if ( dtmf.digits.length > \"0\" ) {\n\n";
                $x = 0;
                $sql = "";
                $sql .= "select * from v_auto_attendant_options ";
                $sql .= "where auto_attendant_id = '" . $row['auto_attendant_id'] . "' ";
                $sql .= "and v_id = '{$v_id}' ";
                $prepstatement2 = $db->prepare($sql);
                $prepstatement2->execute();
                while ($row2 = $prepstatement2->fetch()) {
                    $auto_attendant_id = $row2["auto_attendant_id"];
                    $optionaction = $row2["optionaction"];
                    $optionnumber = $row2["optionnumber"];
                    $optiontype = $row2["optiontype"];
                    $optionprofile = $row2["optionprofile"];
                    $optiondata = $row2["optiondata"];
                    $optiondescr = $row2["optiondescr"];
                    //find the correct auto attendant options with the correct action
                    if ($row2['optionaction'] == "anti-action") {
                        switch ($row2['optionnumber']) {
                            //case "t":
                            //		//break;
                            //case "d":
                            //		//break;
                            default:
                                //$tmpantiaction .= "             //console_log( \"info\", \"Auto Attendant Detected 1 digit \\n\" );\n";
                                if ($x == 0) {
                                    $tmpantiaction .= "             if ( dtmf.digits == \"" . $row2['optionnumber'] . "\" ) { //" . $row2['optiondescr'] . "\n";
                                } else {
                                    $tmpantiaction .= "             else if ( dtmf.digits == \"" . $row2['optionnumber'] . "\" ) { //" . $row2['optiondescr'] . "\n";
                                }
                                //play the option recording if it was provided
                                if (strlen($row2['optionrecording']) > 0) {
                                    $option_recording_filename = get_recording_filename($row2['optionrecording']);
                                    $tmpantiaction .= "             session.streamFile( \"" . $v_recordings_dir . "/" . $option_recording_filename . "\" );\n\n";
                                }
                                $tmpantiaction .= "                 session.execute(\"" . $row2['optiontype'] . "\", \"" . $row2['optiondata'] . "\"); //" . $row2['optiondescr'] . "\n";
                                //if ($row2['optiontype'] == "extension") {
                                //	$tmpantiaction .= "                 sofia_contact_".$row2['optiondata']." = get_sofia_contact(\"".$row2['optiondata']."\",domain_name, \"".$row2['optionprofile']."\");\n";
                                //	$tmpantiaction .= "                 session.execute(\"bridge\", sofia_contact_".$row2['optiondata']."); //".$row2['optiondescr']."\n";
                                //	if ($row2['optionprofile'] == "auto") {
                                //		$tmpantiaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\");\n";
                                //	}
                                //	else {
                                //		$tmpantiaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\");\n";
                                //	}
                                //}
                                //if ($row2['optiontype'] == "voicemail") {
                                //	if ($row2['optionprofile'] == "auto") {
                                //		$tmpantiaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                                //	}
                                //	else {
                                //		$tmpantiaction .= "                 session.execute(\"voicemail\", \"default \${domain} ".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                                //	}
                                //}
                                //if ($row2['optiontype'] == "sip uri") {
                                //	$tmpantiaction .= "                 session.execute(\"bridge\", \"".$row2['optiondata']."\"); //".$row2['optiondescr']."\n";
                                //}
                                $tmpantiaction .= "             }\n";
                        }
                        //end switch
                        $x++;
                    }
                    //end anti-action
                }
                //end while
                unset($prepstatement2);
                $tmp .= $tmpantiaction;
                if ($row['aadirectdial'] == "true") {
                    $tmp .= "             else {\n";
                    $tmp .= "\t                  session.execute(\"transfer\", dtmf.digits+\" XML default\");\n";
                    //$tmp .= $tmpantiactiondefault;
                    $tmp .= "             }\n";
                } else {
                    if ($antiactiondefault) {
                        $tmp .= "             else {\n";
                        $tmp .= "\t                  //console_log( \"info\", \"default option used when dtmf doesn't match any other option\\n\" );\n";
                        //play the option recording if it exists
                        if (strlen($antiactiondefaultrecording) > 0) {
                            $option_recording_filename = get_recording_filename($antiactiondefaultrecording);
                            $tmp .= "\t                  session.streamFile( \"" . $v_recordings_dir . "/" . $option_recording_filename . "\" );\n";
                        }
                        $tmp .= "\t                  session.execute(\"" . $antiactiondefaulttype . "\", \"" . $antiactiondefaultdest . "\"); //" . $antiactiondefaultdesc . "\n";
                        //if ($antiactiondefaulttype == "extension") {
                        //	$tmp .= "	                  sofia_contact_".$antiactiondefaultdest." = get_sofia_contact(\"".$antiactiondefaultdest."\",domain_name, \"".$actiondirectprofile."\");\n";
                        //	$tmp .= "	                  session.execute(\"bridge\", sofia_contact_".$antiactiondefaultdest."); //".$antiactiondefaultdest."\n";
                        //	if ($actiondirectprofile == "auto") {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$antiactiondefaultdest."\");\n";
                        //	}
                        //	else {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$antiactiondefaultdest."\");\n";
                        //	}
                        //}
                        //if ($antiactiondefaulttype == "voicemail") {
                        //	if ($actiondirectprofile == "auto") {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$antiactiondefaultdest."\");\n";
                        //	}
                        //	else {
                        //		$tmp .= "	                  session.execute(\"voicemail\", \"default \${domain} ".$antiactiondefaultdest."\");\n";
                        //	}
                        //}
                        //if ($antiactiondefaulttype == "sip uri") {
                        //	$tmp .= "	                  session.execute(\"bridge\", \"".$antiactiondefaultdest."\"); //".$antiactiondefaultdest."\n";
                        //}
                        $tmp .= "             }\n";
                    }
                }
                $tmp .= "\n";
                unset($tmpantiaction);
                $tmp .= "          } \n";
                //$tmp .= "          else if ( dtmf.digits.length == \"3\" ) {\n";
                //$tmp .= "                //Transfer to the extension the caller chose\n";
                //$tmp .= "                session.execute(\"transfer\", dtmf.digits+\" XML default\"); \n";
                //$tmp .= "          }\n";
                //$tmp .= "          else {\n";
                //$tmp .= $tmpantiactiondefault;
                //$tmp .= "          }\n";
                $tmp .= "\n";
                $tmp .= "     } //end if session.ready\n";
                $tmp .= "\n";
                $tmp .= " } //end if condition";
            }
            //if ($antiactiondirect)
        }
        //antiactioncount
        unset($tmpactiondefault);
        unset($tmpantiactiondefault);
        if (strlen($row['aaextension']) > 0) {
            $aafilename = "autoattendant_" . $row['aaextension'] . ".js";
            $fout = fopen($v_scripts_dir . "/" . $aafilename, "w");
            fwrite($fout, $tmp);
            unset($aafilename);
            fclose($fout);
        }
    }
    //end while
    $db->commit();
}