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

    $entry=Array(
      "id" => $_POST["id"],
      "name" => $_POST["name"],
      "label" => $_POST["label"],
      "description" => $_POST["description"], 
      "parameter" => $_POST["parameter"], 
      "code" => $_POST["code"]  
    ); 
    
    //save the group informations
    $ret=$asterisk->putMacro($entry);
    if ($ret>0) $alert="<div class=\"AlertGood\">L'interno è stato correttamente modificato </div>";
    else $alert="<div class=\"AlertBad\">L'interno NON è stato modificato</div>";
    goToMainPage($alert); 
  }
  //--------------------------------------------------------------------------
  
  $pageTitle="New Macro";
  $ret=$asterisk->getMacro(0);
  if ($err=$asterisk->getError()) die("Error: $err");
  if (is_array($ret)) 
  foreach($ret as $m) {
    $macroList.="<li><a href=\".?id=".$m["id"]."\">".$m["label"]."</a></li>";

    //if modify, read the group informations
    if (isset($_GET["id"]) and $m["id"]==$_GET["id"]) {
      $id=$m["id"];
      $name=$m["name"];
      $label=$m["label"];
      $description=$m["description"];
      $parameter=$m["parameter"];
      $code=$m["code"];
      
      $pageTitle="Edit macro $label";
    }  
  }

  //================ MAIN CONTENTS ================
  ob_start();
  ?>

  <?$sel="macro";include("../../navigation.php");?>
  
  <div class="SectionHeader">
    <h1><?=$pageTitle?></h1>
    <h3><a href="../" class="admin" ><?=$cwlang["exten"]["return"]?></a></h3>
  </div>

  <div id="basic_form">
    <form action="<?=$PHP_SELF?>" method="post">
      <p class="blockintro">Edit your the settings of this macro</p>
      <div class="block">
        <dl>
          <dt class="required"><?=$cwlang["exten"][""]?>Name:</dt>
          <dd><input type="textfield" id="name" name="name" value="<?=$name?>" /></dd>
          <dt class="required"><?=$cwlang["label"][""]?>Label:</dt>
          <dd><input type="textfield" id="label" name="label" value="<?=$label?>" /></dd>
          <dt class="required"><?=$cwlang["exten"][""]?>Description:</dt>
          <dd><textarea id="description" name="description" style="width: 500px"><?=$description?></textarea></dd>
          <dt class="required"><?=$cwlang["exten"][""]?>Parameter:</dt>
          <dd><textarea id="parameter" name="parameter"  style="width: 500px; height: 100px"><?=$parameter?></textarea></dd>
          <dt class="required"><?=$cwlang["exten"][""]?>Code:</dt>
          <dd><textarea id="code" name="code" style="width: 500px; height: 150px"><?=$code?></textarea></dd>
        </dl>
        <div class="help">
          <br/>
          Note: in parameters, you can specify what input variable can accept this macro.<br/> 
          Use this syntax:
            <blockquote>&lt;param name="XXX" type="YYY" label="ZZZ" description="KKK" /&gt;</blockquote>
          where<br/><strong>name</strong> is the name of parameter,  <br/>
          <strong>label</strong> is the label of parameter, <br/>
          <strong>description</strong> is the text description of parameter, <br/>
          <strong>type</strong> is one of these values: QUEUE, GROUP, EXTENSION, 
          IVR, TEXTFIELD, EMAIL_EXTENSION, OUTGOING_RULE<br/>
          Look at this example:
          
            <blockquote>&lt;param name="dest" type="IVR" label="Play this IVR" description="bla bla" /&gt;</blockquote>
        </div>
        <input type="hidden" name="id" value="<?=$id?>" />
      </div>
      <div class="action">
        <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"][""]?>Macro List</h1>
          <p><?=$cwlang["isdngrp"][""]?>Choose the macro you want to edit
            <ul>
              <?=$macroList?>
            </ul>
          </p>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

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

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

