<?
/**
 * VoiceOne Settings/Provider
 *
 * Frontend to provide access to the provider system in voiceone.
 * @package voiceone
 * @subpackage  settings_provider
 */
  include ("../../admin/config/cfg.php");
  global $cwlang;
  
  //================ PAGE LOGIC ================
  $alert=getAlert();

  if ($_GET["cmd"]=="del") {
    $ret=$asterisk->delProvider($_GET["id"]);
    if ($ret==1) $alert="<div class=\"AlertGood\">".$cwlang["provider"]["alertDelGood"]."</div>";
    else $alert="<div class=\"AlertBad\">".$cwlang["provider"]["alertDelBad"]."</div>";
  }
  
  $ret=$asterisk->getProvider(0,0);
  if ($err=$asterisk->getError()) die("Error: $err");
  $count=0;
  if (is_array($ret))
  foreach($ret as $v) {
    $id=$v["id"];
    $name=$v["name"];
    $tech=$v["technology"];
    $icon=getIcon($tech);
    $html.="<td>$icon <a href=\"edit/?id=$id\">$name</a>  <a href=\"$PHP_SELF?cmd=del&id=$id\" onclick=\"if (confirm('Are you sure to remove the $name provider?')) 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><?=$cwlang["provider"]["title"]?></h1>
    <h3>
      <a href="edit/?type=voip" class="admin" ><?=$cwlang["provider"][""]?>New VoIP provider</a> &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="edit/?type=telco" class="admin" ><?=$cwlang["provider"][""]?>New Telco provider</a> 
    </h3>
  </div>
  <table class="todolist">
    <tr>
      <?=$html?>
    </tr>
  </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=$cwlang["provider"]["sidebarTitle"]?></h1>
          <?=$cwlang["provider"]["sidebarText"]?>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================

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

