<?
/**
 * VoiceOne Settings/Offices
 *
 * Frontend to provide access to the offices system in voiceone.
 * @package voiceone
 * @subpackage  settings_offices
 */
  include ("../../../admin/config/cfg.php");
  global $cwlang;

  $alert=getAlert();
  //================ POST & GET ================
  //delete office
  if ($_GET["cmd"]=="del") {
    $ret=$asterisk->delOffice($_GET["id"]);
    if ($ret==1) $alert="<div class=\"AlertGood\">".T_("Office has been deleted successfully")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("Office has NOT been deleted")."</div>";
    goToMainPage($alert,"./");
  }

  //================ PAGE LOGIC ================
  //get Offices
  $ret=$asterisk->getOffice(0);
  if ($err=$asterisk->getError()) die("Error: $err");
  $count=0;
  if (is_array($ret))
  foreach($ret as $v) {
    $id=$v["id"];
    $name=$v["name"];
    $label=$v["label"];
    $techtag="IAX2";
    $icon=getIcon(IAX2);
    $html.="<td>$icon <a href=\"edit/?id=$id\">$label</a> ($techtag/$name)  <a href=\"$PHP_SELF?cmd=del&id=$id\" onclick=\"if (confirm('".sprintf(T_("Are you sure to remove the office %s ?"),$name )."')) 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();
  ?>
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=T_("Offices")?></h1>
    <h3>
      <a href="edit/" class="admin" ><?=T_("New Office")?></a>
    </h3>
  </div>
  <table class="todolist">
    <tr>
      <?=$html?>
    </tr>
  </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start();
  ?>
    <div class="Sidebar">
      <?$sel="offices";include("../sidebar.php");?>
      <h1><?=T_("Informations")?></h1>
      <p><?=T_("This page shows the offices configured on the system. To create a new office follow the link under the section title, otherwise click on an existing office to edit it or on the basket on the right of the name to delete it.")?></p> 
    </div>
  <?
  $sidebar=ob_get_contents();
  ob_end_clean();

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

