<?
$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 searchSucessCall()
{

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

var callStart=document.getElementById("callStart").value;
var callEnd=document.getElementById("callEnd").value;
var idTrunk=document.getElementById("idTrunk").value;
var clientName=document.getElementById("clientName").value;
var calledPrefix=document.getElementById("calledPrefix").value;

if(callStart=="")
callStart = "NULL";

if(callEnd=="")
callEnd = "NULL";

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


if(calledPrefix=="")
calledPrefix = "NULL";


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



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

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

//alert(escape(callStart) + "/" + escape(callEnd) + "/" + escape(idTrunk)  + "/" + escape(calledPrefix) + "/" + escape(clientID) + "/" + myRandom);
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET", url + "/" + escape(callStart) + "/" + escape(callEnd) + "/" + escape(idTrunk)  + "/" + escape(calledPrefix) + "/" + 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;
}
}



function exportCallSummary()
{


var callStart=document.getElementById("callStart").value;
var callEnd=document.getElementById("callEnd").value;
var idTrunk=document.getElementById("idTrunk").value;
var limit=document.getElementById("limit").value;
var calledPrefix=document.getElementById("calledPrefix").value;
var startoffset=0;

if(callStart=="")
callStart = "NULL";

if(callEnd=="")
callEnd = "NULL";

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


if(calledPrefix=="")
calledPrefix = "NULL";


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

window.location= url  + "/" + escape(startoffset) + "/"  + escape(limit) + "/" + escape(callStart) + "/" + escape(callEnd) + "/" + escape(idTrunk)  + "/" + escape(calledPrefix) + "/" + myRandom;

}





</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">

                        <div class="quickmenu" style='padding-left:10px;'>
	                        <img src="<?=base_url()?>images/qb_remove.gif" align="baseline" width="9" height="9" border="0" alt="" />
	                        <a href="#" onclick="javascript:exportCallSummary();">Export</a>
                  </div>

                  <span>&nbsp;&nbsp;&raquo;</span> Retail Call Summary <?=$titleErrorMessage?>   </div>


   <!-- Search Information -->

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

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td>
    <!-- First Part -->

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

    <td align="right">To :</td>
    <td align="left"><input type="text" class = "formInput" name="callEnd" id="callEnd" value="<?=$callEnd?>" style="width:90px"/></td>


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

    <td align="right">Client :</td>
    <td align="left"><input type="text" class = "formInput" name="clientName" id="clientName" value="" style="width:90px"/></td>



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



    <td align="right">Rec :</td>
    <td align="left">
  <select name="limit" id="limit" class = "selectFrom" style="width:60px" 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>
    <!-- End First part-->
    </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> Retail Call Summary

    </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="18%"><div align="left" style="padding-left:5px;">Date</div></td>
     <td width="20%"><div align="left" style="padding-left:5px;">Client</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Prefix</div></td>
     <td width="20%"><div align="left" style="padding-left:5px;">Gateway</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Calls</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">Duration</div></td>
     <td width="10%"><div align="left" style="padding-left:5px;">ACD</div></td>

   </tr>



<?
$i=1;
$totalNumberCall = 0;
$totalDuration  = 0;

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


$totalNumberCall = $totalNumberCall + $row->totalCall;
$totalDuration = $totalDuration + $row->callDuration;

$acd = round($row->callDuration/$row->totalCall,0);

$gatewayName = $this->generallib->getTrunkName($row->id_trunk);
//$ = $this->geberallib->getTrunkName($row->id_trunk);


?>

      <?

	  		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->callDay?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;">--</td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->tariff_prefix?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$gatewayName?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$row->totalCall?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$this->generallib->sec_to_time($row->callDuration)?></td>
 <td align=left class="tableBorderAll" style="padding-left:5px;padding-top:2px;padding-bottom:2px;"><?=$this->generallib->sec_to_time($acd)?></td>

   </tr>

<?
$i++;
}

}

?>


 </table>

<!-- End Clients List -->

    </td>
  </tr>

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

    <input type="hidden" name="callStart" id="callStart" value="<?=$callStart?>" />
    <input type="hidden" name="callEnd" id="callEnd" value="<?=$callEnd?>" />
    <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="calledPrefix" id="calledPrefix" value="<?=$calledPrefix?>" />



    </td>
  </tr>

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

<table width="50%" border="0" cellspacing="0" cellpadding="0" class="tableBorder">
  <tr>
    <td colspan="2" class="mainTableTitle"><span>&nbsp;&nbsp;&raquo;</span> Calls Summary</td>
  </tr>

 <tr>
	<td class='formLabelRigit' width="50%" style='padding-top:10px;'> Number of Calls :  </td>
	<td class='formLabelLeft' width="50%" style='padding-top:10px;'> <?=$totalNumberCall?>	</td>
</tr>

<tr>
	<td class='formLabelRigit'>  Total Call Duration :  </td>
	<td class='formLabelLeft'><?=$this->generallib->sec_to_time($totalDuration)?>	</td>
</tr>

<tr>
	<td class='formLabelRigit'>  ACD :  </td>
	<td class='formLabelLeft'>
	<?
	if($totalNumberCall == 0)
	$totalACD = 0;
	else
	$totalACD = round($totalDuration/$totalNumberCall,0);
	echo $this->generallib->sec_to_time($totalACD);
	?>

	</td>
</tr>


</table>


    </td>
  </tr>


</table>

</div>



    </td>
  </tr>

</table>


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