<?
/**
 * VoiceOne Settings/Tech/group_default
 *
 * Frontend to provide access to the tech system in voiceone.
 * @package voiceone
 * @subpackage  settings_tech
 */
  include ("../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
 	sajax_init();
  
  if(!_isModuleLoaded('mISDN')) goToMainPage('',"../");
  //================ PAGE LOGIC ================

  if (count($_POST)>0) {

    //get technology
    $tech=$_POST["technology"];

    //add options to the entry
    foreach ($_POST as $k=>$v) {
      if (substr($k,0,7)=="status_") {
        $k=substr($k,7);
        if ($v=="1") {
          $o["key"]=$k; 
          $o["value"]=$_POST["option_".$k];
          $options[]=$o;
        }
      }
    }
    
    $ret=$asterisk->putOption(MISDN,$options,SECTION_DEFAULT);
    
    if ($ret>0 and $ret2=="") $alert="<div class=\"AlertGood\">".$cwlang["sip"]["alertGood"]."</div>";
    else $alert="<div class=\"AlertBad\">".$cwlang["sip"]["alertGood"]."</div>";
  }
  

  //get the configuration option
  $optionArr=$asterisk->getConfOption(0,"MISDN",0);
  //$optionArr=$asterisk->getConfOption(0,"MISDN",SECTION_DEFAULT);    
  
  //extract the options
  if (is_array($optionArr))
  foreach ($optionArr as $k=>$v) {
    if ($v["commented"]==0 and $v["default_section"]==1) {
      if ($v["value"]=="") $selOptionArr[$v["id"]]=$v["default"];
      else $selOptionArr[$v["id"]]=$v["value"];
    }
    //$optionArr[$k]["advanced_option"]="0";
  } 
  //create the HTML options
  $html=getOption($optionArr,$selOptionArr,false,RULE_INCOMING);
  
  //================ MAIN CONTENTS ================
  ob_start();
  ?>
  <? $sel="groups_default"; include ("navigation.php");?>
  
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=$cwlang["sip"][""]?>ISDN Default Group Option</h1>
  </div>

  <div id="basic_form">
    <form action="<?=$PHP_SELF?>" method="post">
      <div class="block">
        <table>
          <?=$html?>
        </table>
      </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">
          <?$sel="isdn";include("../sidebar.php");?>
          <h1><?=$cwlang["sip"]["sidebarTitle"]?></h1>
          <?=$cwlang["sip"]["sidebarDesc"]?>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================
 	sajax_handle_client_request();

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

