<?php
# User_edit_filter_module ver.1.0
# last modification 11.2.2010
# Formulář pro výběr uživatele nebo množiny uživatelů na základě filtrovaných 
# hodnot
# 
?>
<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>
<center>
<div class="forms">
<script language="JavaScript">
write.document.form.submit();
</script>

    <h3>Výběr uživatele</h3>
<fieldset>
  <legend>Seznam uživatelů</legend>
<?php
//if (IsSet($_GET['UEF_SUBMITED']))
 // { 
      
 
      $query="SELECT idUSER,jmeno,prijmeni,login,email
      FROM user
      
      WHERE ";
      
      if($_POST['UEF_VALIDITY']==1 || (IsSet($_GET['UEF_VALIDITY']) && $_GET['UEF_VALIDITY']==0)  )
      {
          $_SESSION['UEF_TEMP'][UEF_VALIDITY]=0;
      }else{
          $_SESSION['UEF_TEMP'][UEF_VALIDITY]= 1;
      }
      
      if($_SESSION['UEF_TEMP'][UEF_VALIDITY]==1)
      {
         $query=$query."validity=1";
      }else{
         $query=$query."1=1";
      }
      
      
      
      
      if(IsSet($_POST['UEF_ID']) )
      {
        $_SESSION['UEF_TEMP'][UEF_ID]= $_POST['UEF_ID'];
      }
      if ($_SESSION['UEF_TEMP'][UEF_ID]!=''){
          $query=$query." AND idUSER=\"".$_SESSION['UEF_TEMP'][UEF_ID]."\""   ;
      }
       
      if(IsSet($_POST['UEF_FIRSTNAME']) )
      {
        $_SESSION['UEF_TEMP'][UEF_FIRSTNAME]= $_POST['UEF_FIRSTNAME'];
      }
      if ($_SESSION['UEF_TEMP'][UEF_FIRSTNAME]!=''){
          $query=$query." AND jmeno like \"".$_SESSION['UEF_TEMP'][UEF_FIRSTNAME]."%\""   ;
      }
      if(IsSet($_POST['UEF_LASTNAME']) )
      {
        $_SESSION['UEF_TEMP'][UEF_LASTNAME]= $_POST['UEF_LASTNAME'];
      }
      if ($_SESSION['UEF_TEMP'][UEF_LASTNAME]!=''){
          $query=$query." AND prijmeni like \"".$_SESSION['UEF_TEMP'][UEF_LASTNAME]."%\""   ;
      }
      if(IsSet($_POST['UEF_LOGIN']) )
      {
        $_SESSION['UEF_TEMP'][UEF_LOGIN]= $_POST['UEF_LOGIN'];
      }
      if ($_SESSION['UEF_TEMP'][UEF_LOGIN]!=''){
          $query=$query." AND login like \"".$_SESSION['UEF_TEMP'][UEF_LOGIN]."%\""   ;
      }
      if(IsSet($_POST['UEF_EMAIL']) )
      {
        $_SESSION['UEF_TEMP'][UEF_EMAIL]= $_POST['UEF_EMAIL'];
      }
      if ($_SESSION['UEF_TEMP'][UEF_EMAIL]!=''){
          $query=$query." AND email like \"".$_SESSION['UEF_EMAIL'][UEF_EMAIL]."%\""   ;
      }
      
      
      
      
      
      
      
      
      ##########################################################################
      #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++;
    ?>
    <div class="userlist">
      <table align="center">
          <form name="form" action="admin_page.php" onSubmit="return check(this)" method="post">
                <td class="tableculombhead" colspan=5 style="text-align:left">
                  <?php
                    for ($o=0 ;$o<$pages;$o++) {
                  if ($o==$_GET['PAGE'])
                  {
                      echo "<span id=\"pagelistselected\">";
                  }else{
                      echo "<span id=\"pagelist\">";
                  }
                  
                 
                    
                      echo ("<a href=\"".selfURL()."?UEF_VALIDITY=".$_SESSION['UEF_TEMP'][UEF_VALIDITY]."&PAGE=".$o."\">".($o+1)." </a>");
                      echo "</span>";   
                
            }
                  ?>
                
                </td>
                <input type="hidden" name="UEF_VALIDITY" id="valid" value="1" >
               <td class="tableculombhead" colspan=1 style="text-align:right">Aktivní <input type="checkbox" name="UEF_VALIDITY" id="chck1" value="0" OnChange="RefreshForm(this)" <?php if ($_SESSION['UEF_TEMP'][UEF_VALIDITY]==1 ) echo "checked"; ?>></td>
          </tr><tr>   
              <td class="tablehead">Operace</td>
              <td class="tablehead">ID</td>
              <td class="tablehead">Jméno</td>
              <td class="tablehead">Příjmení</td>
              <td class="tablehead">Login</td>
              <td class="tablehead">Email</td>
          </tr><tr>
              <td class="tableculombhead"></td>
              <td class="tableculombhead"><input size="1" type="text" name="UEF_ID" value="<?php echo($_SESSION['UEF_TEMP'][UEF_ID]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead"><input size="8" type="text" name="UEF_FIRSTNAME" value="<?php echo($_SESSION['UEF_TEMP'][UEF_FIRSTNAME]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead"><input size="8" type="text" name="UEF_LASTNAME" value="<?php echo($_SESSION['UEF_TEMP'][UEF_LASTNAME]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead"><input size="8" type="text" name="UEF_LOGIN" value="<?php echo($_SESSION['UEF_TEMP'][UEF_LOGIN]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead"><input size="8" type="text" name="UEF_EMAIL" value="<?php echo($_SESSION['UEF_TEMP'][UEF_EMAIL]);?>" OnChange="RefreshForm(this)"></td>
                  <input type="hidden" name="UEF_SUBMITED" value="TRUE">
                  <input type="hidden" name="NEXTFORM" value="7" >
                  
          </tr>
          </form>
      <?php
      $a=1;
      while (list($idUSER,$jmeno,$prijmeni,$login,$email) = 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=8&idUSER=".$idUSER."\"><img src=\"files/pictures/vyber.gif\"></a></td><td>".$idUSER."</td><td>".$jmeno."</td><td>".$prijmeni."</td><td>".$login."</td><td>".$email."</td>";
        echo "</tr>";
      }
?>
    </table>
    </div>
</fieldset>
</div>
</center>