<?
/**
 * VoiceOne Settings/Tool/application
 *
 * Frontend to provide access to the tech system in voiceone.
 * @package voiceone
 * @subpackage  settings_tool
 */
  include ("../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  $alert=getAlert();
  
  //================ POST & GET ================
  if ($_GET["cmd"]=="del") {
    $ret=$asterisk->delApplication($_GET["id"]);
    if ($ret==1) $alert="<div class=\"AlertGood\">".T_("The Application has been deleted")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("The Application hasn't been deleted")."</div>";
    goToMainPage($alert);
  }
  
  //================ PAGE LOGIC ================
  $count=0; 
  $ret=$asterisk->getApplication(0);
  if ($err=$asterisk->getError()) die("Error: $err");
  if (is_array($ret)) 
  foreach($ret as $a) {
    $id=$a["id"];
    $label=$a["label"];
    $extension=$a["extension"];
    $appList.="<tr><td class=\"postit\"><a href=\"./edit/?id=$id\">$extension</a></td><td><a href=\"./edit/?id=$id\">$label</a></td></tr>";
    $html.="<td><a href=\"./edit/?id=$id\">$label</a>  <a href=\"$PHP_SELF?cmd=del&id=$id\" onclick=\"if (confirm('".sprintf(T_("Are you sure to delete the application: %1\$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";
  }
  
  //================ MAIN CONTENTS ================
  ob_start();
  ?>

  <?$sel="application";include("../navigation.php");?>
  
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=T_("Available Application")?></h1>
    <h3><a href="./edit/index.php" class="admin"><?=T_("Add a new Application")?></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 applications configured on the system. To create a new application follow the link under the section title, otherwise click on an existing application to edit it or on the basket on the right of the name to delete it.")?></p>  
          <h1><?=T_("Application List")?></h1>
          <p><?=T_("Choose the application you want to edit")?>
            <table class="small">
              <?=$appList?>
            </table>
          </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');
?>

