<?
/**
 * VoiceOne Settings/Tool/macro
 *
 * 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 ================
  $alert=getAlert();

  if ($_GET["cmd"]=="del") {
    $ret=$asterisk->delMacro($_GET["id"]);
    if ($ret==1) $alert="<div class=\"AlertGood\">".T_("The macro has been deleted successfully")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("The macro has NOT been deleted successfully")."</div>";
  }
  
  //--------------------------------------------------------------------------
  $count=0; 
  $ret=$asterisk->getMacro(0);
  if ($err=$asterisk->getError()) die("Error: $err");
  if (is_array($ret)) 
  foreach($ret as $m) {
    $id=$m["id"];
    $label=$m["label"];
    if($m['in_use']==1) $lock="<img width=\"12\" src=\"$relBasePath/public/img/lock.gif\" alt=\"Locked\" />"; else $lock="";
    $macroList.="<li><a href=\"./edit/?id=$id\">$label</a> $lock </li>";
    $html.="<td><a href=\"./edit/?id=$id\">$label</a> $lock <a href=\"$PHP_SELF?cmd=del&id=$id\" onclick=\"if (confirm('".sprintf(T_("Are you sure to remove the macro: %s ?"),$label )."')) return true; else return false;\"><img src=\"$relBasePath/public/img/trash.gif\" /></a></td>\n";
    if ((++$count)%2==0) $html.="</tr><tr>\n";
  }
  
  $title=T_("Available macros");
  //================ MAIN CONTENTS ================
  ob_start();
  ?>

  <?$sel="macro";include("../navigation.php");?>
  
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=$title?></h1>
    <h3><a href="./edit/index.php" class="admin"><?=T_("Add a new macro")?></a></h3>
  </div>

  <table class="todolist">
    <tr>
      <?=$html?>
    </tr>
  </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=T_("Informations")?></h1>
          <p><?=T_("This page shows the macros configured on the system. To create a new macro follow the link under the section title, otherwise click on an existing extension to edit it or on the basket on the right of the name to delete it. Macros included in incoming rules or applications are locked and cannot be deleted.")?></p>  
          <!--h1><?=T_("Macro List")?></h1>
          <p><?=T_("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');
?>

