<?
/**
 * VoiceOne Settings/Rules/incoming/edit
 *
 * Frontend to provide access to the rules system in voiceone.
 * @package voiceone
 * @subpackage  settings_rules
 */
  include ("../../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  
  //================ PAGE LOGIC ================
  if (count($_POST)>0) {

    $entry=Array(
      "id" => $_POST["id"],
      "name" => $_POST["name"],
      "description" => $_POST["description"],
      "type" => RULE_INCOMING 
    );

    //save the group informations
    $ret=$asterisk->putRule($entry);
    if ($ret>0) {
      $alert="<div class=\"AlertGood\">".$cwlang["isdngrp"][""]." ok</div>";
      $_GET["id"]=$ret;
    } else $alert="<div class=\"AlertBad\">".$cwlang["isdngrp"][""]." no</div>";
    
    goToMainPage($alert);
  }
  //--------------------------------------------------------------------------
  
  //if modify, read the group informations
  if (isset($_GET["id"])) {
    $ret=$asterisk->getRule($_REQUEST["id"]);
    if ($err=$asterisk->getError()) die("Error: $err");
    $id=$ret[0]["id"];
    $name=$ret[0]["name"];
    $description=$ret[0]["description"];

    // the name can't be changed, because of it is written all over the asterisk
    $disableName=" disabled=\"disabled\" ";
  }  
  
  //================ MAIN CONTENTS ================
  ob_start();
  ?>

  <?$sel="incoming";include("../../navigation.php");?>
  
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=$cwlang["isdngrp"][""]?>Incoming rule set</h1>
    <h3><a href="../" class="admin" ><?=$cwlang["isdngrp"]["return"]?></a></h3>
  </div>
  
  <div id="basic_form">
    <form action="<?=$PHP_SELF?>" method="post" >
      
      <p class="blockintro"><?=$cwlang["isdngrp"][""]?></p>
      <div class="block">
        <table>
          <tr>
            <td class="required"><label for="name"><?=$cwlang["isdngrp"][""]?>Name:</label></td>
            <td><input type="text" size="25" maxlength="30" id="name" name="name" value="<?=$name?>" <?=$disableName?>/></td>
          </tr>
          <tr>
            <td class="required"><label for="description"><?=$cwlang["isdngrp"][""]?>Description:</label></td>
            <td><textarea rows="10" cols="40" id="description" name="description"><?=$description?></textarea></td>
          </tr>
        </table>
      </div>

    <div class="action">
      <?if (isset($_GET["id"])) {?><input type="hidden" name="id" value="<?=$id?>" /><input type="hidden" name="name" value="<?=$name?>" /><?}?>
      <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-cancel.gif" alt="Cancel" onclick="location.href='../'; return false;"/>
      <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Save" />
    </div>
  </form>
 </div>  
  
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=$cwlang["isdngrp"][""]?>Edit the rules</h1>
          <p><?=$cwlang["isdngrp"][""]?>bla bla bla</p>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================

  $smarty->assign("section", "rules");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>

