<?
$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 starttime=document.getElementById("starttime").value;
var stoptime=document.getElementById("stoptime").value;
var id_trunk=document.getElementById("id_trunk").value;
var id_rate=document.getElementById("id_rate").value;
var calledNumnber=document.getElementById("calledNumnber").value;
var clientName=document.getElementById("clientName").value;
var limit=document.getElementById("limit").value;


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

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


if(id_trunk=="")
id_trunk = "NULL";


if(id_rate=="")
id_rate = "NULL";


if(calledNumnber=="")
calledNumnber = "NULL";

if(clientName=="")
clientName = "NULL";

var url = "<?=site_url("call/sucessCallListPagination")?>";

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


xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET", url + "/" + escape(pageNumber) + "/"  + escape(limit) + "/" + escape(starttime) + "/" + escape(stoptime) + "/" + escape(id_trunk) + "/" + escape(id_rate) + "/" + escape(calledNumnber) + "/" + escape(clientName) + "/" + myRandom, true);
xmlhttp.send(null);
}




function searchSucessCall()
{

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



var starttime=document.getElementById("starttime").value;
var stoptime=document.getElementById("stoptime").value;
var id_trunk=document.getElementById("id_trunk").value;
var id_rate=document.getElementById("id_rate").value;
var calledNumnber=document.getElementById("calledNumnber").value;
var clientName=document.getElementById("clientName").value;
var limit=document.getElementById("limit").value;
var startoffset=0;


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

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


if(id_trunk=="")
id_trunk = "NULL";


if(id_rate=="")
id_rate = "NULL";


if(calledNumnber=="")
calledNumnber = "NULL";

if(clientName=="")
clientName = "NULL";

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

var url = "<?=site_url("call/sucessCallListPagination")?>";

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


xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET", url + "/" + escape(startoffset) + "/"  + escape(limit) + "/" + escape(starttime) + "/" + escape(stoptime) + "/" + escape(id_trunk) + "/" + escape(id_rate) + "/" + escape(calledNumnber) + "/" + escape(clientName) + "/" + 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>


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

<script type="text/javascript" src="<?=base_url()?>js/jquery.datePicker.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="<?=base_url()?>css/date.css">


		<script type="text/javascript" charset="utf-8">
		$(function()
		{
			$('.formInputDate').datePicker().val(new Date().asString()).trigger('change');
		});
		</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>



<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">
                  <span>&nbsp;&nbsp;&raquo;</span> <?=$titleMessage?>  <?=$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">From :</td>
    <td align="left"><input type="text" class = "formInputDate" name="starttime" id="starttime" value="" style="width:70px"/></td>

    <td align="right">To :</td>
    <td align="left"><input type="text" class = "formInputDate" name="stoptime" id="stoptime" value="" style="width:70px"/></td>

    <td align="right">Prefix :</td>
    <td align="left"><input type="text" class = "formInput" name="prefix" id="prefix" value="" style="width:70px"/></td>



    <td align="right">Trunk :</td>
    <td align="left">
    <select name="id_trunk" id="id_trunk" class = "selectFrom">
    <?=$trunkList?>
    </select>
    </td>

    <td align="right">Records :</td>
    <td align="left">
  <select name="limit" id="limit" class = "selectFrom" onchange="searchSucessCall();">
	<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:searchSucessCall();">
	<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">


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

      <span>&nbsp;&nbsp;&raquo;</span> Hourly ASR / ACD Call History

    </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="7%"><div align="left" style="padding-left:5px;">Client</div></td>
     <td width="6%"><div align="left" style="padding-left:5px;">R-I</div></td>
     <td width="6%"><div align="left" style="padding-left:5px;">R-II</div></td>
     <td width="6%"><div align="left" style="padding-left:5px;">R-III</div></td>
     <td width="8%"><div align="left" style="padding-left:5px;">Number</div></td>
     <td width="5%"><div align="left" style="padding-left:5px;">Prefix</div></td>
     <td width="11%"><div align="left" style="padding-left:5px;">Call Start</div></td>
     <td width="11%"><div align="left" style="padding-left:5px;">Call End</div></td>
     <td width="5%"><div align="left" style="padding-left:5px;">Duration</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Rate</div></td>
 	 <td width="7%"><div align="left" style="padding-left:5px;">Route</div></td>
 	 <td width="4%"><div align="center" style="padding-left:0px;">Cost</div></td>
 	 <td width="4%"><div align="center" style="padding-left:0px;">CostR1</div></td>
 	 <td width="4%"><div align="center" style="padding-left:0px;">CostR2</div></td>
 	 <td width="4%"><div align="center" style="padding-left:0px;">CostR3</div></td>
   </tr>



<?
$i=1;
if(is_array($callList))
{
foreach($callList as $row)
{
$passid =$i;



if($row->id_reseller==-1)
{

  $reseller3Login = "--";
  $reseller2Login = "--";
  $reseller1Login = "--";
}
else
{
  $reseller1Login = $this->generallib->getResellerLogin($row->id_reseller,1);
  $reseller2ID = $this->generallib->getIDReseller($row->id_reseller,1);
  if($reseller2ID==-1)
  {
     $reseller2Login = "--";
     $reseller3Login = "--";
  }
  else
  {
     $reseller2Login = $this->generallib->getResellerLogin($reseller2ID,2);
     $reseller3ID = $this->generallib->getIDReseller($reseller2ID,2);
     if($reseller3ID==-1)
     $reseller3Login = "--";
     else
     $reseller3Login = $this->generallib->getResellerLogin($reseller3ID,3);

  }

}


//$parent = $this->generallib->getResellerName($row->id_reseller,1);

$callDuration  = $this->generallib->sec_to_time($row->real_sessiontime);


?>

      <?

	  		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;padding-top:2px;padding-bottom:2px;"><input name="checkActive" type="checkbox"  id="checkActive" value="1" /></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->src?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$reseller1Login?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$reseller2Login?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$reseller3Login?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->dnid?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->billing_prefix?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->starttime?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->stoptime?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$callDuration?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->rateName?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->trunkName?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->client_cost?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->costr1?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->costr2?></td>
 <td align=left  style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->costr3?></td>
   </tr>

<?
$i++;
}

}

?>


 </table>

<!-- End Clients List -->

    </td>
  </tr>

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

    <input type="hidden" name="starttime" id="starttime" value="<?=$starttime?>" />
	<input type="hidden" name="stoptime" id="stoptime" value="<?=$stoptime?>" />
	<input type="hidden" name="id_trunk" id="id_trunk" value="<?=$id_trunk?>" />
	<input type="hidden" name="limit" id="limit" value="<?=$limit?>" />
	<input type="hidden" name="startoffset" id="startoffset" value="<?=$startoffset?>" />
	<input type="hidden" name="id_rate" id="id_rate" value="<?=$id_rate?>" />
	<input type="hidden" name="calledNumnber" id="calledNumnber" value="<?=$calledNumnber?>" />
	<input type="hidden" name="clientName" id="clientName" value="<?=$clientName?>" />



<?


      $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');
?>
