<?php
/* $Id$ */
/*

  freeswitch_ivr_edit.php
  Copyright (C) 2008 Mark J Crane
  All rights reserved.

  FreeSWITCH (TM)
  http://www.freeswitch.org/
	
	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:
	
	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.
	
	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.
	
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/

require("guiconfig.inc");
require("/usr/local/pkg/freeswitch.inc");


$a_ivr          = &$config['installedpackages']['freeswitchivr']['config'];
$a_ivr_options 	= &$config['installedpackages']['freeswitchivroptions']['config'];


$id = $_GET['id'];
if (isset($_POST['id'])) {
	$id = $_POST['id'];
}
$parentid = $id;

//set default $ivrconditionjs
  $ivrconditionjs = "function isholiday( Month, Date ) {\n";
  $ivrconditionjs .= "    var Holiday = 0; //default false\n";
  $ivrconditionjs .= "    if (Month == \"12\" && Date == \"25\") {\n";
  $ivrconditionjs .= "      Holiday = 1; //true\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    if (Month == \"7\" && Date == \"4\") {\n";
  $ivrconditionjs .= "      Holiday = 1; //true\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    if (Month == \"1\" && Date == \"1\") {\n";
  $ivrconditionjs .= "      Holiday = 1; //true\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    if (Holiday == 1) {\n";
  $ivrconditionjs .= "      return true;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    else {\n";
  $ivrconditionjs .= "      return false;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "function isweekday( Day ) {\n";
  $ivrconditionjs .= "    if (Day > 1 && Day < 7) {\n";
  $ivrconditionjs .= "        return true;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    else {\n";
  $ivrconditionjs .= "        return false;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "function isweekend( Day ) {\n";
  $ivrconditionjs .= "    if (Day > 1 && Day < 7) {\n";
  $ivrconditionjs .= "        return false;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    else {\n";
  $ivrconditionjs .= "        return true;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "function isofficehours( Hours ) {\n";
  $ivrconditionjs .= "    if (Hours >= 9 && Hours < 17) {\n";
  $ivrconditionjs .= "        return true;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    else {\n";
  $ivrconditionjs .= "        return false;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "function isafterhours( Hours ) {\n";
  $ivrconditionjs .= "    if (Hours >= 9 && Hours < 17) {\n";
  $ivrconditionjs .= "        return false;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "    else {\n";
  $ivrconditionjs .= "        return true;\n";
  $ivrconditionjs .= "    }\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "//set default\n";
  $ivrconditionjs .= "condition = true;\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "//Holiday?\n";
  $ivrconditionjs .= "if (isholiday( Month, Date )) {\n";
  $ivrconditionjs .= "    console_log( \"info\", \"holiday\\n\" );\n";
  $ivrconditionjs .= "    condition = false;\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "//Weekend?\n";
  $ivrconditionjs .= "if (isweekend( Day )) {\n";
  $ivrconditionjs .= "    console_log( \"info\", \"weekend\\n\" );\n";
  $ivrconditionjs .= "    condition = false;\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";
  $ivrconditionjs .= "// After Hours?\n";
  $ivrconditionjs .= "if (isafterhours( Hours )) {\n";
  $ivrconditionjs .= "    console_log( \"info\", \"after hours\\n\" );\n";
  $ivrconditionjs .= "    condition = false;\n";
  $ivrconditionjs .= "}\n";
  $ivrconditionjs .= "\n";


if (isset($id) && $a_ivr[$id]) {
	$pconfig['ivrid'] = $a_ivr[$id]['ivrid'];
	$ivrid = $a_ivr[$id]['ivrid'];
	$pconfig['ivrextension'] = $a_ivr[$id]['ivrextension'];
	$pconfig['ivrname'] = $a_ivr[$id]['ivrname'];
	$pconfig['recordingidaction'] = $a_ivr[$id]['recordingidaction'];
	$pconfig['recordingidantiaction'] = $a_ivr[$id]['recordingidantiaction'];
	$pconfig['ivrtimeout'] = $a_ivr[$id]['ivrtimeout'];
	$pconfig['ivrcalltimeout'] = $a_ivr[$id]['ivrcalltimeout'];
	$pconfig['ivrcontext'] = $a_ivr[$id]['ivrcontext'];
	$pconfig['ivrdirectdial'] = $a_ivr[$id]['ivrdirectdial'];
	$pconfig['ivrringback'] = $a_ivr[$id]['ivrringback'];
	$pconfig['ivrcidnameprefix'] = $a_ivr[$id]['ivrcidnameprefix'];	
	$pconfig['ivrconditionjs'] = ($a_ivr[$id]['ivrconditionjs']);
	$pconfig['ivrdescr'] = $a_ivr[$id]['ivrdescr'];
}

if ($_POST) {

	unset($input_errors);
	$pconfig = $_POST;

	
	if ($_GET['act'] == "del") {
    if ($_GET['type'] == 'options') {
        if ($a_ivroptions[$_GET['optionid']]) {
            unset($a_ivr_options[$_GET['optionid']]);
            write_config();
            sync_package_freeswitch_ivr();
            header("Location: freeswitch_ivr_edit.php?id=".$_GET['id']);
            exit;
        }
    }
  }


	if (!$input_errors) {
  	
		$ivrent = array();
		if (strlen($_POST['ivrid']) > 0) {
			$ivrent['ivrid'] = $_POST['ivrid'];
		}
		else {
      		$ivrent['ivrid'] = guid();
    	}
		$ivrent['ivrextension'] = $_POST['ivrextension'];
		$ivrent['ivrname'] = $_POST['ivrname'];
		$ivrent['recordingidaction'] = $_POST['recordingidaction'];
		$ivrent['recordingidantiaction'] = $_POST['recordingidantiaction'];
		$ivrent['ivrtimeout'] = $_POST['ivrtimeout'];
		$ivrent['ivrcalltimeout'] = $_POST['ivrcalltimeout'];
		$ivrent['ivrcontext'] = $_POST['ivrcontext'];
		$ivrent['ivrdirectdial'] = $_POST['ivrdirectdial'];
		$ivrent['ivrringback'] = $_POST['ivrringback'];
		$ivrent['ivrcidnameprefix'] = $_POST['ivrcidnameprefix'];
		$ivrent['ivrconditionjs'] = base64_encode($_POST['ivrconditionjs']);
		$ivrent['ivrdescr'] = $_POST['ivrdescr'];

		if (isset($id) && $a_ivr[$id]) {
		  	//update
      		$a_ivr[$id] = $ivrent;
		}
		else {
		  	//add
			$a_ivr[] = $ivrent;
		}
		
		//touch($d_hostsdirty_path);		
		write_config();
		sync_package_freeswitch_ivr();
		
		header("Location: freeswitch_ivr.php");
		exit;
	}
}

include("head.inc");

?>
<script language="Javascript">
function sf() { document.forms[0].savetopath.focus(); }
</script>
<script language="Javascript" type="text/javascript" src="/edit_area/edit_area_full.js"></script>
<script language="Javascript" type="text/javascript">
	// initialisation
	editAreaLoader.init({
		id: "ivrconditionjs"	// id of the textarea to transform		
		,start_highlight: true
		,allow_toggle: false
		,language: "en"
		,syntax: "js"	
		,toolbar: "search, go_to_line,|, fullscreen, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help"
		,syntax_selection_allow: "css,html,js,php,xml,c,cpp,sql"
		,show_line_colors: true
	});	
</script>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">

<?php include("fbegin.inc"); ?>
<p class="pgtitle">FreeSWITCH: IVR: Edit</p>
<?php if ($input_errors) print_input_errors($input_errors); ?>


<div id="mainlevel">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td class="tabnavtbl">
<?php

display_top_tabs(build_menu());
 	
?>
</td></tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
   <tr>
     <td class="tabcont" >

      	<table width="100%" border="0" cellpadding="6" cellspacing="0">
          <tr>
            <td><p><span class="vexpl"><span class="red"><strong>General Settings:<br>
                </strong></span>
                Interactive voice response general settings.
                </span></p></td>
          </tr>
        </table>
        <br />
    		
        <form action="freeswitch_ivr_edit.php" method="post" name="iform" id="iform">
            <table width="100%" border="0" cellpadding="6" cellspacing="0">
            <tr>
              <td width="22%" valign="top" class="vncellreq">Extension</td>
              <td width="78%" class="vtable">
                <input name="ivrextension" type="text" class="formfld" id="ivrextension" size="40" value="<?=htmlspecialchars($pconfig['ivrextension']);?>">
                <br> <span class="vexpl">e.g. <em>5002</em></span></td>
            </tr>
            <tr>
              <td width="22%" valign="top" class="vncellreq">IVR Name</td>
              <td width="78%" class="vtable">
                <input name="ivrname" type="text" class="formfld" id="ivrname" size="40" value="<?=htmlspecialchars($pconfig['ivrname']);?>">
              </td>
            </tr>
            <tr>
              <td width="22%" valign="top" class="vncellreq">Recording Action</td>
              <td width="78%" class="vtable">
                <?php
                $a_recordings = &$config['installedpackages']['freeswitchrecordings']['config'];
                echo "              <select name='recordingidaction' class='formfld'>\n";
                echo "                <option></option>\n";
                if (count($a_recordings) > 0) {
                  foreach ($a_recordings as $ent) {
                      if (htmlspecialchars($pconfig['recordingidaction']) == $ent['recordingid']) {
                          echo "              <option value='".$ent['recordingid']."' selected='yes'>".$ent['recordingname']."</option>\n";
                      }
                      else {
                          echo "              <option value='".$ent['recordingid']."'>".$ent['recordingname']."</option>\n";
                      }
                  }
                }
                echo "              </select>\n";
                ?>
              </td>
            </tr>
            <tr>
              <td width="22%" valign="top" class="vncellreq">Recording Anti-Action</td>
              <td width="78%" class="vtable">
                <?php
                //$a_recordings = &$config['installedpackages']['freeswitchrecordings']['config'];
                echo "              <select name='recordingidantiaction' class='formfld'>\n";
                echo "                <option></option>\n";
                if (count($a_recordings) > 0) {
                  foreach ($a_recordings as $ent) {
                      if (htmlspecialchars($pconfig['recordingidantiaction']) == $ent['recordingid']) {
                          echo "              <option value='".$ent['recordingid']."' selected='yes'>".$ent['recordingname']."</option>\n";
                      }
                      else {
                          echo "              <option value='".$ent['recordingid']."'>".$ent['recordingname']."</option>\n";
                      }
                  }
                }
                echo "              </select>\n";
                ?>
              </td>
            </tr>
            <?php
            if (strlen($pconfig['ivrtimeout']) == 0) {
                $pconfig['ivrtimeout'] = 10; //set a default timeout
            }
            ?>
            <tr>
              <td width="22%" valign="top" class="vncellreq">IVR Timeout</td>
              <td width="78%" class="vtable">
                <input name="ivrtimeout" type="text" class="formfld" id="ivrtimeout" size="40" value="<?=htmlspecialchars($pconfig['ivrtimeout']);?>">
                <br>
				<span class="vexpl">After the recording concludes the
                timeout sets the time in seconds to continue to wait for DTMF.
                If the DTMF is <br />not detected during that time the 't'
                timeout option is executed.
				</span>
              </td>
            </tr>
            <tr>
              <td width="22%" valign="top" class="vncellreq">Call Timeout</td>
              <td width="78%" class="vtable">
                <input name="ivrcalltimeout" type="text" class="formfld" id="ivrcalltimeout" size="40" value="<?=htmlspecialchars($pconfig['ivrcalltimeout']);?>">
                <br>
				<span class="vexpl">
				Call timeout is the time in seconds to ring the destination. After this time is exceeded calls 
				to extensions will be sent to voicemail. default: 30 seconds
				</span>
              </td>
            </tr>
            <tr>
              <td width="22%" valign="top" class="vncellreq">Context</td>
              <td width="78%" class="vtable">
                <input name="ivrcontext" type="text" class="formfld" id="ivrextension" size="40" value="<?=htmlspecialchars($pconfig['ivrcontext']);?>">
                <br> <span class="vexpl">e.g. <em>default</em></span></td>
            </tr>
            <tr>
              <td width="22%" valign="top" class="vncellreq">Direct Dial</td>
              <td width="78%" class="vtable">
                <?php
                echo "                <select name='ivrdirectdial' class='formfld'>\n";
                echo "                <option></option>\n";
				if (strlen($pconfig['ivrdirectdial']) == 0) { //set default
					echo "                <option value='true'>enable</option>\n";
                    echo "                <option selected='yes' value='false'>disabled</option>\n";					
                }
                else {
					if (htmlspecialchars($pconfig['ivrdirectdial']) == "true") {
						echo "                <option selected='yes' value='true'>enabled</option>\n";
					}
					else {
						echo "                <option value='true'>enable</option>\n";
					}
					if (htmlspecialchars($pconfig['ivrdirectdial']) == "false") {
						echo "                <option selected='yes' value='false'>disabled</option>\n";
					}
					else {
						echo "                <option value='false'>disable</option>\n";
					}
                }

                echo "                </select>\n";
                ?>
				<br><span class="vexpl">Allows callers to dial directly to extensions and feature codes that are up to 5 digits in length.</span>
              </td>
            </tr>			
            <tr>
              <td width="22%" valign="top" class="vncellreq">Ring Back</td>
              <td width="78%" class="vtable">
                <?php
                echo "                <select name='ivrringback' class='formfld'>\n";
                echo "                <option></option>\n";
                if (htmlspecialchars($pconfig['ivrringback']) == "ring") {
                    echo "                <option selected='yes'>ring</option>\n";
                }
                else {
                    echo "                <option>ring</option>\n";
                }
                if (htmlspecialchars($pconfig['ivrringback']) == "music") {
                    echo "                <option selected='yes'>music</option>\n";
                }
                else {
                    echo "                <option>music</option>\n";
                }
                echo "                </select>\n";
                ?>
				<br>
				<span class="vexpl">
				Defines what the caller will hear while destination is being called. The choices are music 
				(music on hold) ring (ring tone.) default: music 
				</span>
              </td>
            </tr>
			
            <tr>
              <td width="22%" valign="top" class="vncellreq">CID Prefix</td>
              <td width="78%" class="vtable">
                <input name="ivrcidnameprefix" type="text" class="formfld" id="ivrcidnameprefix" size="40" value="<?=htmlspecialchars($pconfig['ivrcidnameprefix']);?>">
                <br> <span class="vexpl">Set a prefix on the caller ID name. (optional)</span></td>
            </tr>
			
            <tr>
              <td width="22%" valign="top" class="vncellreq">Description</td>
              <td width="78%" class="vtable">
                <input name="ivrdescr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['ivrdescr']);?>">
                <br>
				<span class="vexpl">
					You may enter a description here for your reference (not parsed).
				</span>
			  </td>
            </tr>

            <tr>
              <td width="22%" valign="top" class="vncellreq">Javascript Condition</td>
              <td width="78%" class="vtable">
              <?php
              if (strlen(htmlspecialchars(base64_decode($pconfig['ivrconditionjs']))) == 0) {
                echo "<textarea name=\"ivrconditionjs\" id=\"ivrconditionjs\" cols=\"75\" rows=\"10\" wrap=\"off\">".$ivrconditionjs."</textarea>\n";
              }
              else {
                echo "<textarea name=\"ivrconditionjs\" id=\"ivrconditionjs\" cols=\"75\" rows=\"10\" wrap=\"off\">".htmlspecialchars(base64_decode($pconfig['ivrconditionjs']))."</textarea>\n";
              }
              ?>
                <br> <span class="vexpl">A simple valid condition is:
                condition=true; To re-populate the default simply empty the
                textarea and click on save. The following javascript variables
                have been defined: Hours, Mins, Seconds, Month, Date, Year,
                and Day.</span></td>
            </tr>


            <tr>
              <td width="22%" valign="top">&nbsp;</td>
              <td width="78%">
                <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
                  <input name="ivrid" type="hidden" value="<?=htmlspecialchars($pconfig['ivrid']);?>">
                <?php if (isset($id) && $a_ivr[$id]): ?>
                  <input name="id" type="hidden" value="<?=$id;?>">
                <?php endif; ?>
              </td>
            </tr>
            </table>
        </form>

      <br>
      <br>

      <form action="freeswitch_ivr_edit.php" method="post" name="iform2" id="iform2">
      <?php


      //echo "<pre>";
      //print_r ($a_ivr);
      //echo "</pre>";

      //if ($savemsg) print_info_box($savemsg);
      //if (file_exists($d_hostsdirty_path)): echo"<p>";
      //print_info_box_np("The FreeSWITCH recordings have been changed.<br>You must apply the changes in order for them to take effect.");
      //echo"<br />";
      //endif;

      ?>

    <table width="100%" border="0" cellpadding="6" cellspacing="0">
      <tr>
        <td><p><span class="vexpl"><span class="red"><strong><br>
            </strong></span>
            Options are the choices that are available to the caller when they
            are calling the auto attendant. If the caller presses 2 then the call
            is directed to the corresponding destination.
            </span></p></td>
      </tr>
    </table>


  	<table width="100%" border="0" cellpadding="6" cellspacing="0">
      <tr>
        <td><p><span class="vexpl"><span class="red"><strong>Action<br />
            </strong></span>
            The options that are executed when the <b>condition matches.</b>
            </span></p></td>
      </tr>
    </table>
    <br />

    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="30" class="listhdrr">Option</td>
      <td width="30" class="listhdrr">Type</td>
	  <td width="30" class="listhdrr">Profile</td>
      <td width="150" class="listhdrr">Destination</td>
      <td width="30%" class="listhdr">Description</td>
      <td width="40" class="list">
        <table border="0" cellspacing="0" cellpadding="1">
          <tr>
            <td width="17"></td>
            <td valign="middle">
			<?php if (strlen($ivrid) > 1) { ?>
				<a href="freeswitch_ivr_options_edit.php?parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>&a=action"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a>
			<?php } ?>
			</td>
          </tr>
        </table>
      </td>
		</tr>

		<?php
      $i = 0;
      if (count($a_ivr_options) > 0) {
        foreach ($a_ivr_options as $ent) {
          if ($ent['optionaction'] == "action" && $ivrid == $ent['ivrid']) {
    ?>
            <tr>
              <td class="listlr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>'">
                <?=$ent['optionnumber']?>
              </td>
              <td class="listr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <?=$ent['optiontype'];?>&nbsp;
              </td>
              <td class="listr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <?=$ent['optionprofile'];?>&nbsp;
              </td>			  
              <td class="listr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <?=$ent['optiondest'];?>&nbsp;
              </td>
              <td class="listbg" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$id;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <font color="#FFFFFF"><?=htmlspecialchars($ent['optiondescr']);?>&nbsp;
              </td>
              <td valign="middle" nowrap class="list">
                <table border="0" cellspacing="0" cellpadding="1">
                  <tr>
                    <td valign="middle"><a href="freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
                    <td><a href="freeswitch_ivr_options.php?type=ivroptions&act=del&id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>" onclick="return confirm('Do you really want to delete this recording?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
                  </tr>
               </table>
              </td>
            </tr>
		<?php
		      }
          $i++;
        }
      }
    ?>
    <tr>
      <td class="list" colspan="5"></td>
      <td class="list">
        <table border="0" cellspacing="0" cellpadding="1">
          <tr>
            <td width="17"></td>
            <td valign="middle">
			<?php if (strlen($ivrid) > 1) { ?>
				<a href="freeswitch_ivr_options_edit.php?parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>&a=action"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a>
			<?php } ?>
			</td>
          </tr>
        </table>
		  </td>
     </tr>


     <tr>
       <td class="list" colspan="5"></td>
       <td class="list"></td>
     </tr>
     </table>

      </form>



      <form action="freeswitch_ivr_edit.php" method="post" name="iform2" id="iform2">
      <?php


      //echo "<pre>";
      //print_r ($a_ivr);
      //echo "</pre>";

      //if ($savemsg) print_info_box($savemsg);
      //if (file_exists($d_hostsdirty_path)): echo"<p>";
      //print_info_box_np("The FreeSWITCH recordings have been changed.<br>You must apply the changes in order for them to take effect.");
      //echo"<br />";
      //endif;

      ?>
  	<table width="100%" border="0" cellpadding="6" cellspacing="0">
      <tr>
        <td><p><span class="vexpl"><span class="red"><strong>Anti-Action<br />
            </strong></span>
              The options that are executed when the <b>condition does NOT match.</b>
            </span></p></td>
      </tr>
    </table>
    <br />

    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="30" class="listhdrr">Option</td>
      <td width="30" class="listhdrr">Type</td>
	  <td width="30" class="listhdrr">Profile</td>
      <td width="150" class="listhdrr">Destination</td>
      <td width="30%" class="listhdr">Description</td>
      <td width="40" class="list">
        <table border="0" cellspacing="0" cellpadding="1">
          <tr>
            <td width="17"></td>
            <td valign="middle">
			<?php if (strlen($ivrid) > 1) { ?>
				<a href="freeswitch_ivr_options_edit.php?parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>&a=antiaction"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a>
			<?php } ?>
			</td>
          </tr>
        </table>
      </td>
		</tr>

	<?php
      $i = 0;
      if (count($a_ivr_options) > 0) {
        foreach ($a_ivr_options as $ent) {
          if ($ent['optionaction'] == "anti-action" && $ivrid == $ent['ivrid']) {
    ?>
            <tr>
              <td class="listlr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>'">
                <?=$ent['optionnumber']?>
              </td>
              <td class="listr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <?=$ent['optiontype'];?>&nbsp;
              </td>
              <td class="listr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <?=$ent['optionprofile'];?>&nbsp;
              </td>			  
              <td class="listr" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <?=$ent['optiondest'];?>&nbsp;
              </td>
              <td class="listbg" ondblclick="document.location='freeswitch_ivr_options_edit.php?id=<?=$id;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>';">
                <font color="#FFFFFF"><?=htmlspecialchars($ent['optiondescr']);?>&nbsp;
              </td>
              <td valign="middle" nowrap class="list">
                <table border="0" cellspacing="0" cellpadding="1">
                  <tr>
                    <td valign="middle"><a href="freeswitch_ivr_options_edit.php?id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
                    <td><a href="freeswitch_ivr_options.php?type=ivroptions&act=del&id=<?=$i;?>&parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>" onclick="return confirm('Do you really want to delete this recording?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
                  </tr>
               </table>
              </td>
            </tr>
		<?php
		      }
          $i++;
        }
      }
    ?>
    <tr>
      <td class="list" colspan="5"></td>
      <td class="list">
        <table border="0" cellspacing="0" cellpadding="1">
          <tr>
            <td width="17"></td>
            <td valign="middle">
			<?php if (strlen($ivrid) > 1) { ?>
				<a href="freeswitch_ivr_options_edit.php?parentid=<?=$parentid;?>&ivrid=<?=$ivrid;?>&a=antiaction"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a>
			<? } ?>
			</td>
          </tr>
        </table>
		  </td>
     </tr>


     <tr>
       <td class="list" colspan="5"></td>
       <td class="list"></td>
     </tr>
     </table>

      </form>

      <br>
      <br>

     </td>
   </tr>
</table>

</div>

<?php include("fend.inc"); ?>
</body>
</html>