<?
$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 starttime=document.getElementById("starttime").value;
	var stoptime=document.getElementById("stoptime").value;
	var rate_id=document.getElementById("rate_id").value;
	var rType=document.getElementById("rType").value;
	var limit=document.getElementById("limit").value;


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

	if(starttime=="")
	starttime = "NULL";

	if(stoptime=="")
	stoptime = "NULL";

	if(rate_id=="")
	rate_id = "NULL";

	if(rType=="")
	rType = 1;


var url = "<?=site_url("rate/featureTariffPlanPagi")?>";

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


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



function searchRate()
{

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

	var prefix=document.getElementById("prefix").value;
	var starttime=document.getElementById("starttime").value;
	var stoptime=document.getElementById("stoptime").value;
	var rate_id=document.getElementById("rate_id").value;
	var rType=document.getElementById("rType").value;
	var limit=document.getElementById("limit").value;
	var startoffset=0;


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

	if(starttime=="")
	starttime = "NULL";

	if(stoptime=="")
	stoptime = "NULL";

	if(rate_id=="")
	rate_id = "NULL";

	if(rType=="")
	rType = 1;



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

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


xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET", url + "/" + escape(startoffset) + "/"  + escape(limit) + "/" + escape(prefix) + "/" + escape(starttime) + "/" + escape(stoptime) + "/" + escape(rate_id) + "/" + escape(rType) + "/" + myRandom, true);
xmlhttp.send(null);



}


function exportRate()
{


	var prefix=document.getElementById("prefix").value;
	var starttime=document.getElementById("starttime").value;
	var stoptime=document.getElementById("stoptime").value;
	var rate_id=document.getElementById("rate_id").value;
	var rType=document.getElementById("rType").value;
	var limit=document.getElementById("limit").value;
	var startoffset=0;


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

	if(starttime=="")
	starttime = "NULL";

	if(stoptime=="")
	stoptime = "NULL";

	if(rate_id=="")
	rate_id = "NULL";

	if(rType=="")
	rType = 1;


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

window.location= url + "/" + escape(startoffset) + "/"  + escape(limit) + "/" + escape(prefix) + "/" + escape(starttime) + "/" + escape(stoptime) + "/" + escape(rate_id) + "/" + escape(rType) + "/" + myRandom;


}




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


$(document).ready(function() {
    $('#selecctall').click(function(event) {  //on click
        if(this.checked) { // check select status
            $('.checkActiveAll').each(function() { //loop through each checkbox
                this.checked = true;  //select all checkboxes with class "checkbox1"
            });
        }else{
            $('.checkActiveAll').each(function() { //loop through each checkbox
                this.checked = false; //deselect all checkboxes with class "checkbox1"
            });
        }
    });

});

function deleteALL(){
        $('#loading').show();
        var query = $('#theForm').serialize();
        var url = "<?=site_url('rate/deleteRatePlanAll')?>"
        $.post(url, query, function (response) {
         //alert (response);
         window.location= response;
        });
    }

</script>


<link rel="stylesheet" type="text/css" href="<?=base_url()?>date/jquery.datetimepicker.css"/>
<div id = "loading" style="position:absolute;top:200px;left:500px;width;100px;height:100px; bgcolor:#f2f2f2; border:0px solid #99BBE8;zindex:250;display:none;">
<img src="<?=base_url()?>images/indicator2.gif?>" border="0" />
</div>


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

                  <div class="quickmenu" style='padding-left:10px;'>
                      <a href="#" onclick="javascript:exportRate();"><i class="fa fa-files-o"></i><b>Export</b></a>
                  </div>

                  <div class="quickmenu" style='padding-left:10px;'>
                      <a href="<?=site_url('rate/planImportForm')?>"><i class="fa fa-files-o"></i><b>Import</b></a>
                  </div>

                     <div class="quickmenu" style='padding-left:10px;'>
                      <a href="#" onclick="javascript:deleteALL();"><i class="fa fa-trash-o"></i><b>Delete Selected</b></a>
                  	</div>


                  <div class="quickmenu">
                      <a href="<?=site_url('rate/addNewPlan')?>"><i class="fa fa-plus-square"></i><b>New Plan</b></a>
                  </div>

                  <i class="fa fa-camera-retro"></i> Feature Tariff Plan  </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">Start Time :</td>
    <td align="left">
    	<input type="text" class = "formInputDate" id="starttime" value="<?=$starttime?>" style="width:118px"/>
    </td>

    <td align="right">End Time :</td>
    <td align="left">
    	<input type="text" class = "formInputDate" id="stoptime" value="<?=$stoptime?>" style="width:118px"/>
    </td>

	<td align="right">Tariff :</td>
	<td align="left">
	<select name="rate_id" id="rate_id" class = "selectFrom" style="width:130px">
	<?=$rateList?>
	</select>
	</td>

	<td align="right">Status :</td>
	<td align="left">
		<select name="rType" id="rType" class="selectFrom" style="width:120px;">
		<option value="1">Update</option>
		<option value="2">New Code</option>
		<option value="3">Delete</option>
		</select>
	</td>


	<td align="left">
	<a href="#" onclick="javascript:searchRate();">
	<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
	echo $titleErrorMessage;
	$start = $startoffset * $limit + 1;
	$end = ($startoffset +1 )* $limit ;

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

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

<form name="theForm" id="theForm">
<input type="hidden" name="idRate" id="idRate" value="<?=$idRate?>" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBorder">
  <tr>
    <td class="mainTableTitle">
  		<i class="fa fa-caret-square-o-down"></i> Feature Tariff Plan List Total : <?=$total?> Showing <?=$start?> to <?=$end?>
    </td>
  </tr>


 <tr>
    <td>

 <!-- Clinets List -->

 <table class="gbTable">

   <tr class="header">
     <td width="2%"><div align="center" style="padding-left:0px;"><input name="selecctall" id = "selecctall" type="checkbox" /></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Prefix</div></td>
     <td width="20%"><div align="left" style="padding-left:5px;">Description</div></td>
     <td width="9%"><div align="left" style="padding-left:5px;">Voice Rate</div></td>
     <td width="6%"><div align="left" style="padding-left:5px;">Pulse</div></td>
     <td width="25%"><div align="left" style="padding-left:5px;">Tariff Name</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Type</div></td>
     <td width="13%"><div align="left" style="padding-left:5px;">Action Date</div></td>
     <td width="5%" colspan="2"><div align="center" style="padding-left:0px;">Action</div></td>
   </tr>

<?
$i=1;
if(is_array($planList))
{
	foreach($planList as $row)
	{
		$passid =$row->id;
		$voiceRate = number_format($row->voice_rate, 4, '.', '');
		$rateName = $this->generallib->getTariffName($row->id_rate);
		if($row->code_type == 1)
		$codeAction = "Update";
		elseif($row->code_type == 2)
		$codeAction = "Insert New Code";
		else
		$codeAction = "Delete Code";




		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 class="gbTableTDCenter"><input name="check[]" type="checkbox"  id="checkActiveAll_<?=$row->id?>" class="checkActiveAll" value="<?=$row->id?>" /></td>
	 <td class="gbTableTD"><?=$row->prefix?></td>
	 <td class="gbTableTD"><?=$row->description?></td>
	 <td class="gbTableTD"><?=$voiceRate?></td>
	 <td class="gbTableTD"><?=$row->pulse?></td>
	 <td class="gbTableTD"><?=$rateName?></td>
	 <td class="gbTableTD"><?=$codeAction?></td>
	 <td class="gbTableTD"><?=$row->effective_date?></td>
	 <td class="gbTableTDCenter" colspan="2">
	   <a href="<?=site_url('rate/editRatePlanForm/'.$row->id)?>" title="Edit Tariff" >
	   <i class="fa fa-edit"></i>
	   </a>
	  <a href="<?=site_url('rate/deleteRatePlan/'.$row->id)?>"  onclick="return confirm('Do you really want to remove this Plan')" title="Delete" >
	  <i class="fa fa-trash-o"></i>
	  </a>
 </td>
</tr>

<?

	$i++;
	}
}
else
{
?>

 <tr>
    <td colspan="15" align="center" style = "padding:100px;">


        <b>No Records Found</b>

    </td>
  </tr>

<?
}
?>
</table>

    </td>
  </tr>

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

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



<?


      $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>
</form>

</div>


<script type="text/javascript" src="<?=base_url()?>date/jquery.datetimepicker.js"></script>
<script type="text/javascript">

$('#starttime').datetimepicker({
        hours12: false,
        format: 'Y-m-d H:i',
        step: 60,
        opened: false,
        validateOnBlur: false,
        closeOnDateSelect: false,
        closeOnTimeSelect: false
});

$('#stoptime').datetimepicker({
        hours12: false,
        format: 'Y-m-d H:i',
        allowTimes:['00:59', '01:59', '02:59','03:59', '04:59', '05:59','06:59', '07:59', '08:59','09:59', '10:59', '11:59','12:59', '13:59', '14:59','15:59', '16:59', '17:59','18:59', '19:59', '20:59','21:59', '22:59', '23:59'],
        opened: false,
        validateOnBlur: false,
        closeOnDateSelect: false,
        closeOnTimeSelect: false
});
</script>


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