<?php
# ID: 25
# Faktury_edit_filter_module ver.1.0
# last modification 17.5.2010
# Formulář pro filtraci a vyhledání trunků
#
?>
<script language="JavaScript">
 function check(theForm){
    if (document.getElementById("chck1").checked==false){
  document.getElementById('valid').disabled= false;
   }
 return true;
 }
 
 function RefreshForm(theForm){
      document.forms.form.submit();
  
  }
</script>


<?php

      include "build/db_connect.inc.php"  ;
      $query="SELECT U.jmeno,U.prijmeni,SB.name,BDF.id 
              FROM bill_date_faktura_view  BDF
              JOIN user U ON U.idUSER=BDF.idUSER
              JOIN technology T ON T.idTECHNOLOGY=BDF.idTECHNOLOGY
              JOIN sip_buddies SB ON SB.id=BDF.id
              WHERE BDF.idTECHNOLOGY=1";
              
     
                                       
      if($_POST['FF_PAYED']==1 || (IsSet($_GET['FF_PAYED']) && $_GET['FF_PAYED']==0)  )
      {
          $_SESSION['FF_TEMP'][FF_PAYED]=0;
      }else{
          $_SESSION['FF_TEMP'][FF_PAYED]= 1;
      }  
      
      if($_SESSION['FF_TEMP'][FF_PAYED]==1)
      {
         $query=$query." AND BDF.zaplaceno=0 ";
      }
      if(IsSet($_POST['FF_FIRSTNAME']) )
      {
        $_SESSION['FF_TEMP'][FF_FIRSTNAME]= $_POST['FF_FIRSTNAME'];
      }
      if ($_SESSION['FF_TEMP'][FF_FIRSTNAME]!=''){
          $query=$query." AND U.jmeno like \"".$_SESSION['FF_TEMP'][FF_FIRSTNAME]."%\""   ;
      }
      if(IsSet($_POST['FF_LASTNAME']) )
      {
        $_SESSION['FF_TEMP'][FF_LASTNAME]= $_POST['FF_LASTNAME'];
      }
      if ($_SESSION['FF_TEMP'][FF_LASTNAME]!=''){
          $query=$query." AND U.prijmeni like \"".$_SESSION['FF_TEMP'][FF_LASTNAME]."%\""   ;
      }
       if(IsSet($_POST['FF_ACCOUNT']) )
      {
        $_SESSION['FF_TEMP'][FF_ACCOUNT]= $_POST['FF_ACCOUNT'];
      }
      if ($_SESSION['FF_TEMP'][FF_ACCOUNT]!=''){
          $query=$query." AND SB.Name like \"".$_SESSION['FF_TEMP'][FF_ACCOUNT]."%\""   ;
      }
      $query.=" GROUP BY BDF.id 
      
                ORDER BY U.jmeno,U.prijmeni ";
      
      
    
##########################################################################
      #zjisteni poctu stran
        $itemperpage=15;
            $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('Could not query:' . mysql_error());
        }    
      #kod pro vypocet počtu stran
        if ($remainder!=0) $pages++; 
        
        $result = mysql_query($query);
        if (!$result) {
           die('Could not query:' . mysql_error());
        }
?>

<center>
<div class="forms">
<h3>Výběr faktur uživatele</h3>
<fieldset>
  <legend>Seznam uživatelů a jejich účtů</legend>
    <div class="userlist">
    <form name="form" action="admin_page.php" onSubmit="return check(this)" method="post">
        <table align="center">
           <tr>
              <td class="tableculombhead" colspan=2 style="text-align:left">
                  <?php
                    for ($i=0 ;$i!=$pages;$i++) {
                  if ($i==$_POST['PAGE'])
                  {
                      $styl="<span class=\"pagelistselected\">";
                  }else{
                      $styl="<span class=\"pagelist\">";
                  }
                  echo $styl;
                  unset ($styl);
                      
                      echo ("<a href=\"".selfURL()."?NEXTFORM=25&FF_PAYTYPE=".$_SESSION['FF_TEMP'][FF_PAYED]."&PAGE=".$i."\">".($i+1)." </a>");
                      echo "</span>";   
                  }
                  ?>
                
                </td>
                   <input type="hidden" name="FF_PAYED" id="valid" value="1" >
                <td class="tableculombhead" colspan=1 style="text-align:right">Jen nezaplacené <input type="checkbox" name="FF_PAYED" id="chck1" value="0" OnChange="RefreshForm(this)" <?php if ($_SESSION['FF_TEMP'][FF_PAYED]==1 ) echo "checked"; ?>></td>   
                   
           </tr><tr>
              <td class="tablehead"></td>
              <td class="tablehead">Uživatel</td>
              <td class="tablehead">Účet</td>
           </tr><tr>
              <td class="tableculombhead"></td>
              <td class="tableculombhead"><span><input size="4" type="text" name="FF_FIRSTNAME" value="<?php echo($_SESSION['FF_TEMP'][FF_FIRSTNAME]);?>" OnChange="RefreshForm(this)"> 
              <input size="4" type="text" name="FF_LASTNAME" value="<?php echo($_SESSION['FF_TEMP'][FF_LASTNAME]);?>" OnChange="RefreshForm(this)"></span></td>
              <td class="tableculombhead"><input size="8" type="text" name="FF_ACCOUNT" value="<?php  echo($_SESSION['FF_TEMP'][FF_ACCOUNT]);?>" OnChange="RefreshForm(this)"></td>
           </tr>


<?php 

         $a=1;
         while(list($jmeno,$prijmeni,$user,$id)=mysql_fetch_row($result)){
         #Stridani barev řádků tabulky
              if($a==1){$a=0; $barva="white";}else{$a=1;$barva="lightgrey"; }
              #####################################################################
              echo "<tr bgcolor=$barva>";
              echo "<td><a href=\"".selfURL()."?NEXTFORM=26&idACCOUNT=".$id."\"><img src=\"files/pictures/vyber.gif\"></a></td><td>".$jmeno." ".$prijmeni."</td><td>".$user."</td>";
              echo "</tr>";
          } 
      
?>
        </table>
        <input type="hidden" name="TREF_SUBMIT">
      </form>
    </div>
  </fieldset>
</div>