<?
/**
 * VoiceOne Settings/Extensions/Provisioning
 *
 * 
 * @package voiceone
 * @subpackage  settings_extensions
 */
  include ("../../../../admin/config/cfg.php");
  global $cwlang;
  //================= POST & GET ==================
  $alert=getAlert();
  if((isset($_GET["del"]))&&(trim($_GET["del"])!="")){
    $ret=$asterisk->delProvFirmware($_GET["del"]);
    if($ret>0) $alert="<div class=\"AlertGood\">".T_("Firmware has been deleted")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("Firmware hasn't been deleted")."</div>";
    //go to main page
    goToMainPage($alert,"./");
  }
  //================= PAGE LOGIC ==================
  $html="";
  $id_phone_saved=0;
  $count=0;
  $ret=$asterisk->getProvFirmware(0);
  if($err=$asterisk->getError()) die("Error: $err");
  if(is_array($ret)){
    foreach($ret as $v){
      $id=$v["id"];
      $id_phone=$v["id_phone"];
      $name=$v["name"];
      $tftp=$v["tftp"];
      //html
      if($id_phone!=$id_phone_saved){
      	if($id_phone_saved!=0){
        	$html.="</table></td>\n";
      		if((++$count)%2==0) $html.="</tr><tr><td colspan=\"2\">&nbsp;</td></tr><tr>\n";
        }
        $id_phone_saved=$id_phone;
        $phone_ret=$asterisk->getPhoneType($id_phone_saved);
        if(($phone_ret!==false)&&(is_array($phone_ret))&&(is_array($phone_ret[0]))) $phone_name=$phone_ret[0]["vendor"].$phone_ret[0]["model"];
        $html.="<td valign=\"top\">\n";
        $html.="<h3 style=\"margin:0;\">".$phone_name."</h3>\n";
    		$html.="<table class=\"todolist\">\n";
      }
      if(($tftp==1)||($tftp=='1')){
        $src=$relBasePath."public/img/cog_go.png"; 
      }else{
        $src=$relBasePath."public/img/cog.gif";
      }
      $html.="<tr>";
      $html.="	<td><img src=\"".$src."\" alt=\"Firmware $id\"/> ";
      $html.="		<a href=\"edit/?id=$id\">".$name."</a> ";
      $html.="		<a href=\"$PHP_SELF?del=$id\" onclick=\"if (confirm('".sprintf(T_("Are you sure you want to remove firmware %1\$s"),$name )."')) return true; else return false;\"><img src=\"$relBasePath/public/img/trash.gif\" /></a>";
      $html.="	</td>\n";
      $html.="</tr>\n";
    }
  }
  if(trim($html)!="") $html.="</table></td>\n";
  //================ MAIN CONTENTS ================
  ob_start();
  ?>
    <?$nav="firmware";include("../navigation.php");?>
    <div class="SectionHeader">
      <?=$alert?>
      <h1><?=T_("Firmware")?></h1>
      <h3>
        <a href="edit/" class="admin" ><?=T_("Upload new Firmware")?></a> 
      </h3>
    </div>  
    <table width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <?=$html?>
      </tr>
    </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();
  
  //================ SIDEBAR ================
  ob_start(); 
  ?>
    <div class="Sidebar">
      <?$sel="provisioning";include("../../sidebar.php");?>
      <h1><?=T_("Informations")?></h1>
      <p><?=T_("This page shows the firmware versions for the phones under provisioning. To upload a new firmware follow the link under the section title, otherwise click on an existing firmware 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", "extensions");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>
