<?
/**
 * VoiceOne Settings/System/Location
 *
 * Frontend to provide access to the locations  
 * @package voiceone
 * @subpackage  settings_system_location
 */
  include ("../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  //=================== GET ====================
  $alert=getAlert();
  if ($_GET["cmd"]=="del") {
    $ret=$asterisk->delLocation($_GET["id"]);
    if ($ret==1) $alert="<div class=\"AlertGood\">".T_("The Location has been deleted")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("The Location hasn't been deleted")."</div>";
    goToMainPage($alert,"./");
  }
  //================ PAGE LOGIC ================
  $ret=$asterisk->getLocation(0);
  if ($err=$asterisk->getError()) die("Error: $err");
  $count=0;
  if(is_array($ret)){
    foreach($ret as $v){
      $id=$v["id"];
      $name=$v["name"];
      $prefix=$v["int_prefix"].$v["country_code"];
      $default=$v["default"];
      $isErasable=$asterisk->isLocationErasable($id);
      //build html
      $html.="<td><img src=\"$relBasePath/public/img/world.gif\" /> [$prefix] <a href=\"edit/?id=$id\">$name</a>";
      if($default==1){
        $html.=" (default)";
      }
      if($isErasable==0){
        $html.=" <img src=\"$relBasePath/public/img/lock.gif\" alt=\"".T_("Not erasable")."\" />";
      }else{ 
        $html.=" <a href=\"$PHP_SELF?cmd=del&id=$id\" onclick=\"if (confirm('".sprintf(T_("Are you sure you want to delete location %1\$s"),$name )."')) return true; else return false;\"><img src=\"$relBasePath/public/img/trash.gif\" /></a>";
      }
      $html.="</td>\n";
      if((++$count)%2==0) $html.="</tr><tr>\n";
    }
  }
  //================ MAIN CONTENTS ================
  ob_start();
  ?>
  <?$sel="location";include("../navigation.php");?>
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=T_("Location")?></h1>
    <h3>
      <a href="edit/" class="admin" ><?=T_("New location")?></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 locations configured on the system. To create a new location follow the link under the section title, otherwise click on an existing location to edit it or on the basket on the right of the name to delete it. It's not possible to delete defaul location.")?></p>  
    </div>         
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();
  //================ SETTINGS ================
  $smarty->assign("section", "system");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>

