Exemple #1
0
function ListFiles($dir)
{
    if ($dh = opendir($dir)) {
        $files = array();
        $inner_files = array();
        while ($file = readdir($dh)) {
            if ($file != "." && $file != ".." && $file[0] != '.') {
                if (is_dir($dir . "/" . $file)) {
                    $inner_files = ListFiles($dir . "/" . $file);
                    if (is_array($inner_files)) {
                        $files = array_merge($files, $inner_files);
                    }
                } else {
                    array_push($files, $dir . "/" . $file);
                }
            }
        }
        closedir($dh);
        return $files;
    }
}
Exemple #2
0
function ListFiles($gallery_link, &$content, $Folder, $SkipFileExts, $SkipObjects)
{
    $dir = opendir($Folder);
    while (false !== ($Current = readdir($dir))) {
        if ($Current != '.' && $Current != '..' && in_array($Current, $SkipObjects) === false) {
            if (is_dir($Folder . '/' . $Current)) {
                ListFiles($gallery_link, $content, $Folder . '/' . $Current, $SkipFileExts, $SkipObjects);
                // Recursivity
            } else {
                $FileExt = strtolower(substr(strrchr($Current, '.'), 1));
                if (in_array($FileExt, $SkipFileExts) === false) {
                    // Should we display this extension ?
                    $current_adress = $gallery_link . "/" . $Folder . '/' . $Current;
                }
                $content .= $current_adress . "\n";
            }
        }
    }
    closedir($dir);
    return $content;
}
Exemple #3
0
function listFiles(&$content, $Folder, $SkipFileExts, $SkipObjects)
{
    $dir = opendir($Folder);
    // Loop on all contained on the folder
    while (false !== ($Current = readdir($dir))) {
        if ($Current != '.' && $Current != '..' && in_array($Current, $SkipObjects) === false) {
            if (is_dir($Folder . '/' . $Current)) {
                ListFiles($content, $Folder . '/' . $Current, $SkipFileExts, $SkipObjects);
            } else {
                $FileExt = strtolower(substr(strrchr($Current, '.'), 1));
                // Should we display this extension ?
                if (in_array($FileExt, $SkipFileExts) === false) {
                    $current_adress = $Folder . '/' . $Current;
                    array_push($content, $current_adress);
                }
            }
        }
    }
    closedir($dir);
    return $content;
}
Exemple #4
0
        if (is_file($filename) && !in_array($filename, $exclude)) {
            $file_array[filemtime($filename)] = $filename;
        }
    }
    ksort($file_array);
    $file_array = array_reverse($file_array, true);
    return $file_array;
}
$file_array = ListFiles($settings['uploaddir'], $data['ignores']);
// Removing old files
foreach ($file_array as $file) {
    if ($settings['time_limit'] < time() - filemtime($file)) {
        unlink($file);
    }
}
$file_array = ListFiles($settings['uploaddir'], $data['ignores']);
?>
<html lang="en-GB">
	<head>
		<meta charset="utf-8">
		<title><?php 
echo $settings['title'];
?>
</title>
		<style media="screen">
			body {
				background: #111;
				margin: 0;
				color: #ddd;
				font-family: sans-serif;
			}
/**
 * Liste tous les fichier avec une extension pre-determine d'un dossier specifique
 *
 * @param string $directory Chemin relatif du DOCUMENT_ROOT du dossier qui doit etre scanné
 * @param string $extension extension des fichiers a scanné. By Default tif
 * @return array $files Tableau de tous les fichiers qui match avec @param2 si
 * dans @param1: $file[0] = /Library/Webserver/layout.sophieparis.com/.../File.tif
 * @author Nicolas Georget <*****@*****.**>
 **/
function ListFiles($directory, $extension = "tif") {
  $paths = glob($directory . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
    $files = glob($directory . "*." . $extension);
    foreach ($paths as $path) {
    $files = array_merge($files, ListFiles($path, $extension));
  }
    return $files;
}
function buildEpub()
{
    // Do stuff //
    $toc_ncx_content = "" . $_POST['toc_ncx'] . "";
    // toc_ncx	(epub 2.0)
    $nav_end_content = "" . $_POST['nav_end'] . "";
    // nav_end	(epub 3.0)
    $cover_page_content = "" . $_POST['cover_page'] . "";
    // XML Cover(epub 2.0)
    $content_opf_a = "" . $_POST['content_opf_a'] . "";
    // content_opf_a
    $content_opf_b = "" . $_POST['content_opf_b'] . "";
    $title_page = "" . $_POST['title_page'] . "";
    $toc_page = "" . $_POST['toc_page'] . "";
    $epub_html = "";
    // epub_pages
    $images_folder = "";
    // imagefolder_name
    $styles_name = "";
    $myCSSfile = 0;
    // no custom file
    $myCSSname = "";
    $manifest = "";
    $m = 0;
    function manifest_Build($type, $file, $media_type, $m)
    {
        return "\t<item id=\"" . $type . $m . "\"\thref=\"" . $file . "\"\tmedia-type=\"" . $media_type . "\"/>\r\n";
    }
    if ($_POST['epub_pages'] == "" || $_POST['epub_pages'] == "undefined") {
        echo '<span style="color:red;">ERROR: File Content Missing!</span><br/>';
        return;
    } else {
        $epub_html = json_decode($_POST['epub_pages']);
    }
    if ($_POST['cssfile_name'] == "") {
        $styles_name = 'thisissue.css';
    } else {
        $styles_name = "" . $_POST['cssfile_name'] . "";
    }
    // Allows no image folder to be included with empty set.
    $images_folder = $_POST['imagefolder_name'];
    if ($_POST['add_customCSS'] != "") {
        $myCSSfile = 1;
        $myCSSname = "" . $_POST['add_customCSS'] . "";
    }
    // Now that variables are set let's build some stuff! //
    // check if temp directory exists or not, if not create it //
    $MY_PATH = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF'];
    $MY_PATH = explode('ryuzinewriter/', $MY_PATH);
    if (is_writable($MY_PATH[0])) {
        $tmp = $MY_PATH[0] . 'tmp';
        if (!file_exists($tmp)) {
            mkdir($tmp, 0777);
        } else {
            deleteAll($tmp, true);
        }
        // If Flush was checked, get rid of all old epub files //
        if ($_POST['epub_flush'] == '1') {
            foreach (glob($MY_PATH[0] . "*.epub*") as $file) {
                unlink($file);
                // Delete only .epub files through the loop
            }
            echo '<span style="color:yellow;">WARNING: All older .epub files were permanently deleted!  To prevent this in the future uncheck the "Delete Old ePub Files" option.</span><br/>';
        }
    } else {
        echo '<script type="text/javascript">alert(\'ERROR: Dev Folder is not writable!\\nePub COULD NOT BE BUILT\\nCheck folder permissions and try again.\');</script>';
        return;
    }
    // Now populate tmp folder with standard Ryuzine Folders //
    $_css = $MY_PATH[0] . 'tmp/css';
    $_images = $MY_PATH[0] . 'tmp/images';
    echo 'Building Package file structure. . .';
    if (!file_exists($_css)) {
        mkdir($_css, 0777);
    }
    if (!file_exists($_images)) {
        mkdir($_images, 0777);
    }
    echo 'DONE<br/>';
    // Copy Core Files to Package //
    echo 'Copying Core Files to Package. . .';
    //	copy($MY_PATH[0].'ryuzinewriter/addons/epub/assets/mimetype',$MY_PATH[0].'tmp/mimetype'); // use template instead!
    recurse_copy($MY_PATH[0] . 'ryuzinewriter/addons/epub/assets/META-INF', $MY_PATH[0] . 'tmp/META-INF');
    if ($_POST['epub_fonts'] == '1') {
        recurse_copy($MY_PATH[0] . 'fonts', $MY_PATH[0] . 'tmp/fonts');
        echo 'DONE<br/>';
        // Now get the list of fonts and types for manifest //
        foreach (ListFiles('../../../fonts') as $key => $file) {
            $file = preg_replace("~../../../~", "", $file);
            if (preg_match("~\\.otf~i", $file)) {
                $media_type = 'application/x-font-otf';
                // possible 1: application/opentype
                // possible 2: application/vnd.ms-opentype
            } else {
                if (preg_match("~\\.ttf~i", $file)) {
                    $media_type = 'application/x-font-ttf';
                    // possibly:	application/truetype
                } else {
                    if (preg_match("~\\.eot~i", $file)) {
                        $media_type = 'application/x-font-eot';
                        // possibly: application/embedded-opentype
                    } else {
                        if (preg_match("~\\.svg~i", $file)) {
                            $media_type = 'image/svg+xml';
                            // possibly:   application/x-font-svg
                        } else {
                            if (preg_match("~\\.woff~i", $file)) {
                                $media_type = 'application/x-font-woff';
                                // possibly:   application/font-woff'
                                // Now check for other kinds of files in case they are there
                            } else {
                                if (preg_match("~\\.htm~i", $file) || preg_match("~\\.html~i", $file)) {
                                    $media_type = 'application/xhtml+xml';
                                } else {
                                    if (preg_match("~\\.css~i", $file)) {
                                        $media_type = 'text/css';
                                    } else {
                                        if (preg_match("~\\.txt~i", $file)) {
                                            $media_type = 'text/plain';
                                        } else {
                                            if (preg_match("~\\.rtf~i", $file)) {
                                                $media_type = 'text/richtext';
                                            } else {
                                                if (preg_match("~\\.xml~i", $file)) {
                                                    $media_type = 'text/xml';
                                                } else {
                                                    if (preg_match("~\\.zip~i", $file)) {
                                                        echo '<span style="color:yellow;">WARNING: There is a ZIP archive (' . $file . ') in your /fonts folder.  Consider removing it and run build again.</span><br/>';
                                                        $media_type = 'application/zip';
                                                    } else {
                                                        $media_type = 'unknown';
                                                        echo '<span style="color:red;">ERROR: ' . $file . ' in the fonts folder unknown media-type.  This invalidates the ePub.  Please fix it and try again!</span><br/>';
                                                        return;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $manifest = $manifest . "" . manifest_Build('font', $file, $media_type, $m) . "";
            $m++;
        }
    } else {
        if (file_exists($tmp . 'fonts')) {
            deleteAll($tmp . 'fonts', true);
        }
    }
    echo '<span style="font-weight:bold;color:limegreen;">**** BUILDING ePUB ****</span><br/>';
    ePubFiles('', 'nav.xhtml', $nav_end_content);
    ePubFiles('', 'toc.ncx', $toc_ncx_content);
    if ($cover_page_content != "") {
        ePubFiles('', 'cover.xhtml', $cover_page_content);
    }
    if ($title_page != "") {
        ePubFiles('', 'title.xhtml', $title_page);
    }
    if ($toc_page != "") {
        ePubFiles('', 'contents.xhtml', $toc_page);
    }
    $epub_html = closeTags($epub_html);
    for ($e = 0; $e < count($epub_html); $e++) {
        ePubFiles('', 'page' . $e . '.xhtml', $epub_html[$e]);
    }
    if ($images_folder != "") {
        if (!file_exists($MY_PATH[0] . 'images/' . $images_folder)) {
            echo '<span style="color:red;">ERROR: Images sub-folder does not exist!  No images are included in this ePub.</span><br/>';
        } else {
            // File exists, yay!
            echo 'DONE<br/>Copying issue-specific images subdirectory ' . $images_folder . '. . .';
            recurse_copy($MY_PATH[0] . 'images/' . $images_folder, $MY_PATH[0] . 'tmp/images/' . $images_folder);
            echo 'DONE<br/>';
            $m = 0;
            foreach (ListFiles('../../../images/' . $images_folder . '') as $key => $file) {
                $file = preg_replace("~../../../~", "", $file);
                if (preg_match("~\\.jpg~i", $file) || preg_match("~\\.jpeg~i", $file)) {
                    $media_type = 'image/jpeg';
                } else {
                    if (preg_match("~\\.png~i", $file)) {
                        $media_type = 'image/png';
                    } else {
                        if (preg_match("~\\.gif~i", $file)) {
                            $media_type = 'image/gif';
                        } else {
                            if (preg_match("~\\.svg~i", $file)) {
                                $media_type = 'image/svg+xml';
                            } else {
                                if (preg_match("~\\.htm~i", $file) || preg_match("~\\.html~i", $file)) {
                                    $media_type = 'application/xhtml+xml';
                                } else {
                                    if (preg_match("~\\.css~i", $file)) {
                                        $media_type = 'text/css';
                                    } else {
                                        if (preg_match("~\\.txt~i", $file)) {
                                            $media_type = 'text/plain';
                                        } else {
                                            if (preg_match("~\\.rtf~i", $file)) {
                                                $media_type = 'text/richtext';
                                            } else {
                                                if (preg_match("~\\.xml~i", $file)) {
                                                    $media_type = 'text/xml';
                                                } else {
                                                    $media_type = 'unknown';
                                                    echo '<span style="color:red;">ERROR: ' . $file . ' in the images folder unknown media-type.  This invalidates the ePub.  Please fix it and try again!</span><br/>';
                                                    return;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $manifest = $manifest . manifest_Build('image', $file, $media_type, $m);
                $m++;
            }
        }
    } else {
        if (file_exists($tmp . 'images')) {
            deleteAll($tmp . 'images', true);
        }
        echo '<span style="color:yellow;">WARNING: No images sub-folder set!  No images are included in this ePub.</span><br/>';
    }
    if ($styles_name != "") {
        echo 'Copying ' . $styles_name . ' to ePub Package<br/>';
        copy($MY_PATH[0] . 'css/' . $styles_name, $MY_PATH[0] . 'tmp/css/' . $styles_name);
    }
    if ($myCSSfile == '1') {
        echo 'Copying ' . $myCSSname . ' file into package /css</br/>';
        if (!copy($MY_PATH[0] . 'js/' . $myCSSname, $MY_PATH[0] . 'tmp/css/' . $myCSSname)) {
            echo 'File could not be copied (either missing, wrong name, or destination is not writable)';
        }
    }
    ePubFiles('', 'content.opf', $content_opf_a . $manifest . $content_opf_b);
    $epubname = $_POST['mytitle'];
    $epubname = preg_replace("/[^\\w\\.-]/", "-", strtolower($epubname));
    $epubname = $epubname . '_ops_' . date_timestamp_get(date_create()) . '.epub';
    createArchive($MY_PATH[0], 'tmp/', $epubname);
}
Exemple #7
0
		</tr>
	</table>
	<br />

	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<!--<tr><td colspan='2'><img src='/images/spacer.gif' width='100%' height='1' style='background-color: #BBBBBB;'></td></tr>-->
	<tr>
	  <th width="25%" class="">Name</th>
	  <th width="70%" class="">Description</th>
	  <td width="5%" class="list"></td>
	  </th>
	</tr>
	<!--<tr><td colspan='2'><img src='/images/spacer.gif' width='100%' height='1' style='background-color: #BBBBBB;'></td></tr>-->

	<?php 
foreach (ListFiles($v_conf_dir . '/sip_profiles') as $key => $file) {
    echo "<tr>\n";
    echo "\t<td class='" . $rowstyle[$c] . "' ondblclick=\"document.location='v_profile_edit.php?f=" . $file . "'\";\" valign='middle'>\n";
    echo $file;
    echo "&nbsp;\n";
    echo "\t</td>\n";
    echo "\t<td class='rowstylebg' ondblclick=\"document.location='v_profile_edit.php?f=" . $file . "\">\n";
    switch ($file) {
        case "internal.xml":
            echo "The Internal profile by default requires registration which is most often used for extensions. ";
            echo "By default the Internal profile binds to the WAN IP which is accessible to the internal network. ";
            echo "A rule can be set from PFSense -> Firewall -> Rules -> WAN to the the WAN IP for port 5060 which ";
            echo "enables phones register from outside the network.";
            echo "";
            echo "&nbsp;";
            break;
			</strong></span>
			Use this to configure your SIP profiles.
			</p></td>
		</tr>
	</table>
	<br />
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<th width="25%" class="">Name</th>
		<th width="70%" class="">Description</th>
		<td width="5%" class="list"></td>
		</th>
	</tr>

<?php 
foreach (ListFiles($_SESSION['switch']['conf']['dir'] . '/sip_profiles') as $key => $file) {
    if (substr($file, -4) == ".xml") {
        echo "<tr>\n";
        echo "\t<td class='" . $row_style[$c] . "' ondblclick=\"document.location='v_profile_edit.php?f=" . $file . "'\";\" valign='middle'>\n";
        echo $file;
        echo "&nbsp;\n";
        echo "\t</td>\n";
        echo "\t<td class='row_stylebg' ondblclick=\"document.location='v_profile_edit.php?f=" . $file . "\">\n";
        switch ($file) {
            case "internal.xml":
                echo "The Internal profile by default requires registration which is most often used for extensions. ";
                echo "By default the Internal profile binds to the WAN IP which is accessible to the internal network. ";
                echo "A rule can be set from PFSense -> Firewall -> Rules -> WAN to the the WAN IP for port 5060 which ";
                echo "enables phones register from outside the network.";
                echo "";
                echo "&nbsp;";
Exemple #9
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();
}