<?php
# ID: 19
# Providers_edit_filter_module ver.1.0
# last modification 16.5.2010
# Formulář pro filtraci a vyhledání privideru
#
$query="SELECT idPROVIDER,name
      FROM provider
      
      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['ID']) )
      {
        $_SESSION['UEF_TEMP'][ID]= $_POST['ID'];
      }
      if ($_SESSION['UEF_TEMP'][ID]!=''){
          $query=$query." AND idPROVIDER=\"".$_SESSION['UEF_TEMP'][ID]."\""   ;
      }
      
      if(IsSet($_POST['NAME']) )
      {
        $_SESSION['UEF_TEMP'][NAME]= $_POST['NAME'];
      }
      if ($_SESSION['UEF_TEMP'][NAME]!=''){
          $query=$query." AND name like \"".$_SESSION['UEF_TEMP'][NAME]."%\""   ;
      }
      $query.=" ORDER BY name ASC";
      ##########################################################################
      #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++;
?>
<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">
<h3>Výběr providera</h3>
<div class="userlist">
   <fieldset>
   <legend>Seznam poskytovatelů</legend>
   
    <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()."?UEF_VALIDITY=".$_SESSION['UEF_TEMP'][UEF_VALIDITY]."&PAGE=".$i."\">".($i+1)." </a>");
                      echo "</span>";   
                
            }
                  ?>
              </td>
              <input type="hidden" name="UEF_VALIDITY" id="valid" value="1" >
              <td class="tableculombhead">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"></td>
              <td class="tablehead">Id</td>
              <td class="tablehead">Název </td>
           </tr><tr>
              <td class="tablehead">Hledej:</td>
              <td class="tableculombhead"> <input type="text" name="ID" value="<?php echo($_SESSION['UEF_TEMP'][ID]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead"> <input type="text" name="NAME" value="<?php echo($_SESSION['UEF_TEMP'][NAME]);?>" OnChange="RefreshForm(this)"></td>
            
    </form>


<?php 
     
     $result = mysql_query($query);
     if (!$result) {
        die('Seznam provideru nelze načíst:' . mysql_error());
     }
    $a=1;
     #Podle radionbutonu je generovan odkaz na tarif_edit_detail
    while (list($idPROVIDER,$name) = 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=24&idPROVIDER=".$idPROVIDER."\"><img src=\"files/pictures/vyber.gif\"></a></td><td>".$idPROVIDER."</td><td>".$name."</td>";
        echo "</tr>";
    }

?>
  </table>
  </fieldset>
  </div>
</div>