<?
/**
 * VoiceOne Settings/System/Editor
 *
 * Frontend to provide access to the .conf editor in voiceone.
 * @package voiceone
 * @subpackage  settings_system_editor
 */
  include ("../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  
  //================ PAGE LOGIC ================

  if (count($_POST)>0) {
    $data=$_POST["iniText"];
    $arr=explode("\n",$data);
    $ret=$asterisk->createAstConfig($arr,$_POST["selF"]);
    if ($ret>0) {
      $alert="<div class=\"AlertGood\">".T_("The file has been saved")."</div>";
      $_GET["id"]=$ret;
    } else $alert="<div class=\"AlertBad\">".T_("The file hasn't been saved")."</div>";
  }
  
  $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><?=T_("Configuration file editor")?></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' wrap="off" 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><?=T_("High RISK!")?></h1>
            <p><?=T_("It is very dangerous the changes on this files. A bad use of this tool can damage the pbx.")?></p>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

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

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