<?
/**
 * VoiceOne Settings/Tool/
 *
 * Frontend to provide access to the tool system in voiceone.
 * @package voiceone
 * @subpackage  settings_tool
 */
  include ("../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  
  //================ PAGE LOGIC ================

  if (count($_POST)>0) {
    $data=$_POST["iniText"];
    $arr=split("\n",$data);
    //$entry=Array("lines"=>$arr,"filename" => $_POST["selF"]);
    $ret=$asterisk->createAstConfig($arr,$_POST["selF"]);
    if ($ret>0) {
      $alert="<div class=\"AlertGood\">".$cwlang["tool"]["alertGood"]."</div>";
      $_GET["id"]=$ret;
    } else $alert="<div class=\"AlertBad\">".$cwlang["tool"]["alertBad"]."</div>";
    //goToMainPage($alert);
  }
  
  $selF=$_GET["selF"];
  if ($selF=="") $selF="extensions.conf";

  //get the file list
  $ret=$asterisk->viewAstConfigFilename();
  foreach ($ret as $f) {
    if ($f==$selF) $class="adminCurrent admin"; else $class="admin";
    $fileMenu.= " <a href=\"?selF=$f\" class=\"$class\">$f</a> ";
  }
  $fileMenu= "<h3>$fileMenu</h3>";
  
  
  //================ MAIN CONTENTS ================
  ob_start();
  ?>
  
  <?$sel="editor";include("navigation.php");?> 
  
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=$cwlang["tool"]["title"]?></h1>
    <h3><?=$fileMenu?></h3>
  </div>

  <div id="basic_form">
  <?
  if ($selF!="") {
    $text=$asterisk->viewAstConfig($selF);
    ?>
    <form action="<?=$PHP_SELF?>?selF=<?=$selF?>" method="post">
      <textarea name='iniText' style='width: 99%; display: block; height: 350px'>
        <?=$text?>
      </textarea>
      <input type="hidden" name="selF" value="<?=$selF?>" />
      <!--<div style="text-align: right; margin-top: 1em;"><input type="submit" value="SAVE" /></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["tool"]["sidebarTitle"]?></h1>
            <?=$cwlang["tool"]["sidebarDesc"]?>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

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

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

