<?
  include ("../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
 	sajax_init();
  
  if(!_isModuleLoaded('zap')) 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(ZAP,$options,0);
    //$ret=$asterisk->putOption(ZAP,$options,SECTION_DEFAULT);
		
    if ($ret>0 and $ret2=="") $alert="<div class=\"AlertGood\">".$cwlang["zapataOpt"]["alertModGood"]."</div>";
    else $alert="<div class=\"AlertBad\">".$cwlang["zapataOpt"]["alertModBad"]."</div>";
  }
  

  // get the configuration option

  $optionArr=$asterisk->getConfOption(0,"ZAP",0);
  //$optionArr=$asterisk->getConfOption(0,"ZAP",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["zapatagrp"][""]?>Zapata 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="zapata";include("../sidebar.php");?>
          <h1><?=$cwlang["zapatagrp"]["sidebarTitle"]?></h1>
          <?=$cwlang["zapatagrp"]["sidebarDesc"]?>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

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

  $smarty->assign("section", "zapata");
  $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');
?>

