<?
/**
 * VoiceOne Settings/Extensions/Voicemail
 *
 * Frontend to provide access to the extensions system in voiceone.
 * @package voiceone
 * @subpackage  settings_extensions
 */

  include ("../../../admin/config/cfg.php");
  global $cwlang;

  //================ POST & GET =================
  $alert=getAlert();
  //delete mailbox
  if((isset($_GET["del"]))&&($_GET["del"]!="")){
    $ret=$asterisk->delVoiceMail($_GET["del"]);
    if ($ret>0) $alert="<div class=\"AlertGood\">".T_("The mailbox has been deleted")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("The mailbox hasn&acute;t been deleted")."</div>";
    goToMainPage($alert,"./");
  }
  //================ PAGE LOGIC ================
  //get mailboxes
  $ret=$asterisk->getVoiceMail(0);
  $html="";
  if(is_array($ret)){
    foreach($ret as $mailbox){
      $linkedClient=$asterisk->gelClientFromExtension($mailbox["mailbox"]);
      if(is_array($linkedClient)) $confirmBeforeSubmit="if(confirm('".T_("If you continue the mailbox will be turned off for the extension it is linked to.\\nAre you sure?")."'))"; else $confirmBeforeSubmit="";
      $html.="<tr>";
      $html.="  <td class=\"first small\"><span class=\"ext_list\"><a href=\"./edit/?id=".$mailbox["mailbox"]."\" style=\"cursor: pointer;\">".$mailbox["mailbox"]."</a></span></td>";
      $html.="  <td>".$mailbox["fullname"]."</td>";
      $html.="  <td>".$mailbox["email"]."</td>";
      if($mailbox["password"]!="") $html.="<td><img src=\"$relBasePath/public/img/ok.gif\" /></td>"; else $html.="<td>&nbsp;</td>";
      if(($mailbox["attach"]!="")&&($mailbox["attach"]!=0)) $html.="<td><img src=\"$relBasePath/public/img/ok.gif\" /></td>"; else $html.="<td>&nbsp;</td>";
      if(($mailbox["saycid"]!="")&&($mailbox["saycid"]!=0)) $html.="<td><img src=\"$relBasePath/public/img/ok.gif\" /></td>"; else $html.="<td>&nbsp;</td>";
      if(($mailbox["hidefromdir"]!="")&&($mailbox["hidefromdir"]!=0)) $html.="<td><img src=\"$relBasePath/public/img/ok.gif\" /></td>"; else $html.="<td>&nbsp;</td>";
      $html.="  <td><img style=\"cursor: pointer;\" src=\"$relBasePath/public/img/trash.gif\" onclick=\"$confirmBeforeSubmit location.href = './?del=".$mailbox["mailbox"]."';\" /></td>";
      $html.="</tr>";
    }
  }
  if($html=="") $html.="<tr><td class=\"first\" colspan=\"8\"><span style=\"font-size: 10px; font-weight: bold;\">".T_("There are no defined mailbox")."</span></td></tr>";
  //================ MAIN CONTENTS ================
  ob_start();
  ?>
    <div class="SectionHeader">
      <?=$alert?>
      <h1><?=T_("VoiceMail")?></h1>
      <h3>
        <a href="edit/" class="admin" ><?=T_("New Voicemail")?></a>
      </h3>
    </div>
    <table id="ext_table" cellpadding="0" cellspacing="0" width="100%">
  		<tr>
        <th class="first bordered"><?=T_("Mailbox")?></th>
        <th class="bordered"><?=T_("Name")?></th>
        <th class="bordered"><?=T_("Email")?></th>
        <th class="bordered"><?=T_("Password")?></th>
        <th class="bordered"><?=T_("Attach")?></th>
        <th class="bordered"><?=T_("Saycid")?></th>
        <th class="bordered"><?=T_("Hide")?></th>
        <th class="bordered">&nbsp;</th>
      </tr>
      <?=$html?>
    </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start();
  ?>
    <div class="Sidebar">
      <?$sel="voicemail";include("../sidebar.php");?>
      <h1><?=T_("Informations")?></h1>
      <p><?=T_("This page shows the voice mailbox configured on the system. A mailbox is linked to an extension or to a virtual extension if the mailbox number is equal to the extension. To create a new mailbox follow the link under the section title, otherwise click on an existing mailbox to edit it or on the basket on the right to delete it.")?></p>
    </div>
  <?
  $sidebar=ob_get_contents();
  ob_end_clean();

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

