<?php
# ID: -14-     IdFunction v tabulce Function   
# User_callacc_detail_module ver.1.0
# last modification 28.2.2010
# Formulář pro náhled záznamu k vybranému účtu
#   
# 
# 

  include "build/db_connect.inc.php"  ;
  $query="SELECT name,callerid,context,host,type,username
          FROM sip_buddies
          WHERE id = ".$_GET['idCALLACC']."";
  $result = mysql_query($query);
  if (!$result) {
      die('Údaje o volacím účtu uživatele nelze načíst:' . mysql_error());
  }
  list($name,$callerid,$context,$host,$type,$username) = mysql_fetch_row($result); 
 
?>
<h3>Účet: <?php echo($name);?></h3><a class="zpet" href="index.php?NEXTFORM=4">Zpět</a> 
<div class="forms">

<fieldset>
<legend>Detaily účtu</legend>
  <form>
      <table>
          <tr>
            <td>Name:</td><td><?php echo($name);?></td>
          </tr><tr>
            <td>Callerid:</td><td><?php echo($callerid);?></td>
          </tr><tr>
            <td>Context</td><td><?php echo($context);?></td>
          </tr><tr>
            <td>Host:</td><td><?php echo($host);?></td>
          </tr><tr>
            <td>Type:</td><td><?php echo($type);?></td>
          </tr><tr>
            <td>Username:</td><td><?php echo($username);?></td>
          </tr>
      </table>
  </form>

</fieldset>
  

<fieldset>
  <legend>Vlastňené účty</legend>
  <div class="list">
  <table >
    
      <tr><td><b>Volaný</b></td><td><b>Datum</b></td>
      <td><b>Doba</b></td><td><b>Cena</b></td>
      <td><b>Účtováno položkou</b></td></tr>
    
<?php
  include "build/db_connect.inc.php"  ;
  $query="SELECT UA.id,CDR.dst,CDR.calldate,CDR.billsec,CR.price,TAR.Name
          FROM user U
          JOIN user_account UA ON U.idUSER=UA.idUSER AND U.validity=1
          JOIN technology T ON T.idTECHNOLOGY=UA.idTECHNOLOGY
          JOIN call_records CR ON CR.id=UA.id AND CR.idTECHNOLOGY=UA.idTECHNOLOGY AND CR.checked=1
          JOIN cdr CDR ON CDR.idCDR=CR.idCDR
          LEFT JOIN tarif TAR ON TAR.idtarif=CR.idTARIF
          WHERE U.login=\"".$_SESSION['USER']."\"
          AND UA.id=".$_GET['idCALLACC']." 
          AND UA.idTECHNOLOGY=".$_GET['idTECHNOLOGY']."
          
           
          ";
############### strankovani #########################  
   #zjisteni poctu stran
      #nastaveni radku na stranku   
      $itemperpage=10;
            $result = mysql_query($query);
      $remainder= (mysql_num_rows($result) % $itemperpage);
      $pages=(mysql_num_rows($result)-$remainder)/$itemperpage ;
      if(IsSet($_GET['PAGE']))
      {
        $query=$query." LIMIT ".($_GET['PAGE']*$itemperpage).",".$itemperpage.""   ;
        
      }
      else
      {
        $query=$query." LIMIT ".(0*$itemperpage).",".$itemperpage.""  ;
      }
      
      $result = mysql_query($query);
      if (!$result) {
          die('Údaje o účtu nelze načíst:' . mysql_error());
      } 
  #kod pro vypocet počtu stran
      if ($remainder!=0) $pages++;
     # echo "<div class=\"pagelist\">"  ;
      for ($i=0 ;$i!=$pages;$i++) {
        if ($i==$_GET['PAGE'])
        {
          echo "<span class=\"pagelistselected\">";
           echo ("<a href=\"".selfURL()."?PAGE=".$i."\">".($i+1)." </a>");
          echo "</span>"; 
        }
        else
        {
          echo "<span class=\"pagelist\">";
          echo ("<a  href=\"".selfURL()."?PAGE=".$i."\">".($i+1)." </a>");
          echo "</span>";   
        }
      }
      echo "<div class=\"userlist\">";
     
      $a=1;
###########################################  
  
  
  
  
  
  while(list($idT,$cdrdst,$calldate,$billsec,$price,$tarname)=mysql_fetch_row($result)){
    
    if($a==1){$a=0; $barva="#ffb67a";}else{$a=1;$barva="#ffdfc5"; }
      echo "<tr bgcolor=$barva>";
    echo ("<td>".$cdrdst."</td><td>".$calldate."</td><td>".$billsec."</td><td >".$price."</td><td >".$tarname."</td>");
    echo "</tr>";
  }        

?>
  </table>

  </div>
</div>