<?
$this->load->view('cpanel/header');
?>


<script>

var xmlhttp;



function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}



function dopagination(pageNumber)
{
xmlhttp=GetXmlHttpObject();
 if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }


 document.getElementById("loading").style.display = "block";
 document.getElementById("loading").style.visibility = "visible";

var prefix=document.getElementById("prefix").value;
var idTrunk=document.getElementById("idTrunk").value;
var limit=document.getElementById("limit").value;
var routeType=document.getElementById("routeType").value;


if(prefix=="")
prefix = "NULL";

if(idTrunk=="")
idTrunk = "NULL";

if(routeType=="")
routeType = "0";


var url = "<?=site_url("gateway/dialPlanListPagination")?>";

var myRandom = parseInt(Math.random()*99999999); // cache buster


xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET", url + "/" + escape(pageNumber) + "/"  + escape(limit) + "/" + escape(prefix) + "/" + escape(idTrunk) + "/" + escape(routeType)  + "/" + myRandom, true);
xmlhttp.send(null);
}




function searchDialPlan()
{

xmlhttp=GetXmlHttpObject();
 if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }


var prefix=document.getElementById("prefix").value;
var idTrunk=document.getElementById("idTrunk").value;

var limit=document.getElementById("limit").value;
var routeType=document.getElementById("routeType").value;
var startoffset=0;

if(prefix=="")
prefix = "NULL";

if(idTrunk=="")
idTrunk = "NULL";

if(routeType=="")
routeType = "0";


 document.getElementById("loading").style.display = "block";
 document.getElementById("loading").style.visibility = "visible";

var url = "<?=site_url("gateway/dialPlanListPagination")?>";
var myRandom = parseInt(Math.random()*99999999); // cache buster


xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET", url + "/" + escape(startoffset) + "/"  + escape(limit) + "/" + escape(prefix) + "/" + escape(idTrunk) + "/" + escape(routeType)  + "/" + myRandom, true);
xmlhttp.send(null);



}




function stateChanged()
{
if (xmlhttp.readyState==4)
{
rowID = "pagination";
document.getElementById("loading").style.visibility = "hidden";
document.getElementById(rowID).innerHTML=xmlhttp.responseText;
}
}





</script>



<div id = "loading" style="position:absolute;top:200px;left:530px;width;100px;height:100px; bgcolor:#f2f2f2; border:0px solid #99BBE8;zindex:250;display:none;">
<img src="<?=base_url()?>images/indicator2.gif?>" border="0" />
</div>


<?
if($routeType == 0)
$dialPlanStr = "Common Dialplan List";
else
$dialPlanStr = "LCR Dialplan List";
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="right">

      <img src="<?=base_url()?>images/s.gif" width="600" height="1" border="0" alt="" />
      <div id="module_info">
                  <div class="quickmenu">
                      <img src="<?=base_url()?>images/qb_remove.gif" align="baseline" width="9" height="9" border="0" alt="" />
                      <?php
                      if($routeType == 0)
                      {
                      ?>
                      <a href="<?=site_url('gateway/addDialPlanForm/'.$routeType.'/0')?>">New Dial Plan</a>
                      <?php
                      }
                      else
                      {
                      ?>
                      <a href="<?=site_url('gateway/addLCRDialPlanForm/'.$routeType.'/0')?>">New Dial Plan</a>
                      <?
                      }
                      ?>
                  </div>

                  <span>&nbsp;&nbsp;&raquo;</span> <?=$dialPlanStr?>  <?=$titleErrorMessage?>   </div>


   <!-- Search Information -->

<fieldset class="search_box" id="advancedSearch" style="margin-bottom:0px;"><legend>Advanced Search</legend>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="right">Prefix :</td>
    <td align="left"><input type="text" class = "formInput" name="prefix" id="prefix" value="" style="width:100px"/></td>

    <td align="right">Turnk :</td>
    <td align="left">
    <select name="idTrunk" id="idTrunk" class = "selectFrom" style="width:100px">
    <?=$trunkList?>
    </select>
    </td>


    <td align="right">Records :</td>
    <td align="left">
  <select name="limit" id="limit" class = "selectFrom" style="width:60px" onchange="searchDialPlan();">
	<option value="<?=LIMIT_PERPAGE?>"><?=LIMIT_PERPAGE?></option>
	<option value="<?=LIMIT_PERPAGE*2?>"><?=LIMIT_PERPAGE*2?></option>
	<option value="<?=LIMIT_PERPAGE*3?>"><?=LIMIT_PERPAGE*3?></option>
	<option value="<?=LIMIT_PERPAGE*4?>"><?=LIMIT_PERPAGE*4?></option>
</select>
    </td>

<td align="left">

	<a href="#" onclick="javascript:searchDialPlan();">
	<img src="<?=base_url()?>images/apply.gif" height="22" border="0" />
	</a>

</td>

  </tr>
</table>



</fieldset>

   <!-- End Search Information -->

    </td>
  </tr>

  <tr>
    <td>

<div id = "pagination">


	<?php
	$start = $startoffset * $limit + 1;
	$end = ($startoffset +1 )* $limit ;

	if($total<$start)
	$start = $total;

	if($total<=$end)
	$end = $total;
	?>


<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBorder">
  <tr>
    <td class="mainTableTitle">

      <span>&nbsp;&nbsp;&raquo;</span> All Dial Plan Total : <?=$total?> Showing <?=$start?> to <?=$end?>

    </td>
  </tr>


 <tr>
    <td>

 <!-- Clinets List -->

 <table class="gbTable">

   <tr class="header">
     <td width="2%"><div align="left" style="padding-left:5px;">NR</div></td>
     <td width="12%"><div align="left" style="padding-left:5px;">Prefix</div></td>
     <td width="5%"><div align="left" style="padding-left:5px;">Priority</div></td>
     <td width="5%"><div align="left" style="padding-left:5px;">Share</div></td>
     <td width="13%"><div align="left" style="padding-left:5px;">Trunk</div></td>
     <td width="5%"><div align="left" style="padding-left:5px;">Tech</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">Add</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">Remove</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">FromDay</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">ToDay</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">FromHour</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">ToHour</div></td>
     <td width="4%"><div align="center" style="padding-left:0px;">Active?</div></td>
 	 <td width="3%"><div align="center" style="padding-left:0px;">Edit</div></td>
 	 <td width="3%"><div align="center" style="padding-left:0px;">Del</div></td>

   </tr>



<?
$i=1;
if(is_array($dialList))
{
foreach($dialList as $row)
{
$passid =$row->id;


if($row->status == 1)
$checkActive = "checked='checked'";
else
$checkActive = "";





?>

      <?

	  		if($i%2==0)
	  		 {

	  		 $str = "
	  		 		 <TR id = \"$passid\" class=\"row2 \"
	  		 		               onmousedown=\"rowPointer(this, 'down', 'row2', 'rowSel', 'rowMark')\"
	  		 		               onmouseover=\"rowPointer(this, 'over', 'row2', 'rowSel', 'rowMark')\"
	  		               onmouseout=\"rowPointer(this, 'out', 'row2', 'rowSel', 'rowMark')\">";


	  		 }
	  		else
	  		 {
	  			$str = "
	  					 <TR id = \"$passid\" class=\"row1 \"
	  					               onmousedown=\"rowPointer(this, 'down', 'row1', 'rowSel', 'rowMark')\"
	  					               onmouseover=\"rowPointer(this, 'over', 'row1', 'rowSel', 'rowMark')\"
	  		               onmouseout=\"rowPointer(this, 'out', 'row1', 'rowSel', 'rowMark')\">";
	  		 }



	  echo $str;

	  ?>

 <td align=center class="tableBorderAll" style="padding-left:0px;"><input name="checkActive" type="checkbox"  id="checkActive" value="1" /></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->prefix?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->priority?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->share?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->description?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->providertech?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->add_prefix?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->remove_prefix?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$this->generallib->getDay($row->from_day)?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$this->generallib->getDay($row->to_day)?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->from_hour?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;"><?=$row->to_hour?></td>
 <td align=center class="tableBorderAll" style="padding-left:0px;"><input name="checkActive" type="checkbox"  disabled="disabled" id="checkActive" value="1"  <?=$checkActive?> /></td>

 <td align=center class="tableBorderAll" style="padding-left:5px;">
   <a href="<?=site_url('gateway/editDialPlanForm/'.$row->id.'/'.$row->route_type)?>" title="Edit Dial Plan" >
   <img src="<?=base_url()?>images/contact_blue_edit.png" border="0" height="16">
   </a>
 </td>

 <td align=center  style="padding-left:5px;">
  <a href="<?=site_url('gateway/deleteDialPlan/'.$row->id.'/'.$row->route_type)?>"  onclick="return confirm('Do you really want to remove this Dial Plan')" title="Delete Dial Plan" >
  <img src="<?=base_url()?>images/remove.png" border="0" height="16">
  </a>
 </td>

   </tr>

<?
$i++;
}

}

?>


 </table>

<!-- End Clients List -->

    </td>
  </tr>

  <tr>
    <td align="center" style="padding-top:5px;">

    <input type="hidden" name="prefix" id="prefix" value="<?=$prefix?>" />
	<input type="hidden" name="idTrunk" id="idTrunk" value="<?=$idTrunk?>" />
	<input type="hidden" name="limit" id="limit" value="<?=$limit?>" />
	<input type="hidden" name="startoffset" id="startoffset" value="<?=$startoffset?>" />
	<input type="hidden" name="routeType" id="routeType" value="<?=$routeType?>" />



<?


      $p = new paginationClass;
      $p->Items($total);

      if($startoffset==0)
      $startoffset = 1;

      $p->limit($limit);
      $p->target("paginator.php");
      $p->currentPage($startoffset);
      $p->adjacents(3);
      $p->show();



?>


    </td>
  </tr>

</table>

</div>



    </td>
  </tr>

</table>


<?
$this->load->view('cpanel/left_nemu');
$this->load->view('cpanel/footer');
?>
