<?php
# ID: 10
# Tarif_edit_filter_module ver.1.0
# last modification 24.2.2010
# Formulář vyhledání/listování v tarifech
 if (IsSet($_SESSION['ted_buffer'])){unset ($_SESSION['ted_buffer']);}
if (IsSet($_SESSION['ted_dest_buffer'])){unset ($_SESSION['ted_dest_buffer']);}
 if (IsSet($_SESSION['ted_trunk'])){unset ($_SESSION['ted_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
 // if (IsSet($_GET['TEF_SUBMITED']))
 // { 
####### Načítání skupiny tarifů nebo položek ###################################
    if (IsSet($_POST['TEF_CHECK']) && $_POST['TEF_CHECK']=="Item"){
        $query="SELECT T.idTARIF,T.Name,UC.cost
                FROM tarif T
                JOIN union_cost UC ON UC.idCENAJEDNOTKY=T.idCENAJEDNOTKY AND UC.validity=1
                WHERE ";
    }else{
        $query="SELECT idTARIFMIX,Name,start_date
                FROM tarif_mix T
                WHERE ";
    }
    if($_POST['TEF_VALIDITY']==1 || (IsSet($_GET['TEF_VALIDITY']) && $_GET['TEF_VALIDITY']==0)  )
      {
          $_SESSION['TEF_TEMP'][TEF_VALIDITY]=0;
      }else{
          $_SESSION['TEF_TEMP'][TEF_VALIDITY]= 1;
      }
      
      if($_SESSION['TEF_TEMP'][TEF_VALIDITY]==1)
      {
         $query=$query."T.validity=1";
      }else{
         $query=$query."1=1";
      }
    
#*******************************************************************************
      if(IsSet($_POST['TEF_CHECK']) )
      {
        $_SESSION['TEF_TEMP'][TEF_CHECK]= $_POST['TEF_CHECK'];
      }
      
     
     
     if(IsSet($_POST['TEF_ID']) )
      {
        $_SESSION['TEF_TEMP'][TEF_ID]= $_POST['TEF_ID'];
      }
      if ($_SESSION['TEF_TEMP'][TEF_ID]!=''){
          if(IsSet($_POST['TEF_CHECK']) && $_POST['TEF_CHECK']=="Item"){
              $query=$query." AND idTARIF=\"".$_SESSION['TEF_TEMP'][TEF_ID]."\""   ;
          }else{
              $query=$query." AND idTARIFMIX=\"".$_SESSION['TEF_TEMP'][TEF_ID]."\""   ;
          }
      }
    if(IsSet($_POST['TEF_NAME']) )
      {
        $_SESSION['TEF_TEMP'][TEF_NAME]= $_POST['TEF_NAME'];
      }
      if ($_SESSION['TEF_TEMP'][TEF_NAME]!=''){
          $query=$query." AND Name like \"".$_SESSION['TEF_TEMP'][TEF_NAME]."%\""   ;
      }
      
      
      
       
      #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++;
     # echo "<div class=\"pagelist\">"  ;
      
      ?>
<center>
  <div class="forms">
  <h3>Tarify a tarifní skupiny</h3>
  <fieldset>
    <legend>Seznam tarifních skupin a tarifů</legend>
    
    
       <div class="userlist">
          <table align="left" >
             <form name="form" action="admin_page.php" onSubmit="return check(this)" method="post">
                <tr>
                  <td class="tablehead" colspan=2 style="width:20px">Zobrazení</td><td class="tableculombhead" colspan=2>
                      Tarifní skupiny<input type="radio" name="TEF_CHECK" value="Group" OnChange="RefreshForm(this)" <?php if ($_POST['TEF_CHECK']!="Item" ) echo "checked"; ?>  >
                      Tarifní položky<input type="radio" name="TEF_CHECK" value="Item" OnChange="RefreshForm(this)"   <?php if ($_POST['TEF_CHECK']=="Item") echo "checked"; ?>>
                  </td>
                </tr><tr>  
                <td class="tableculombhead" colspan=3 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()."?TEF_VALIDITY=".$_SESSION['TEF_TEMP'][TEF_VALIDITY]."&PAGE=".$i."\">".($i+1)." </a>");
                      echo "</span>";   
                
            }     
                  ?>
                
                </td>
                <input type="hidden" name="TEF_VALIDITY" id="valid" value="1" >
               <td class="tableculombhead" colspan=2 style="text-align:right">Aktivní <input type="checkbox" name="TEF_VALIDITY" id="chck1" value="0" OnChange="RefreshForm(this)" <?php if ($_SESSION['TEF_TEMP'][TEF_VALIDITY]==1 ) echo "checked"; ?>></td>
            </tr><tr> 
        <?php
             if (IsSet($_POST['TEF_CHECK']) && $_POST['TEF_CHECK']=="Item"){
        ?> 
              <td class="tablehead" style="width:20px"></td>
              <td class="tablehead" style="width:20px">ID</td>
              <td class="tablehead" style="width:20px">Název</td>
              <td class="tablehead">Cena jednotky</td>
          </tr><tr>
              <td class="tableculombhead" style="width:20px"></td>
              <td class="tableculombhead" style="width:20px"><input size="1" type="text" name="TEF_ID" value="<?php echo($_SESSION['TEF_TEMP'][TEF_ID]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead" style="width:20px"><input size="8" type="text" name="TEF_NAME" value="<?php echo($_SESSION['TEF_TEMP'][TEF_NAME]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead"></td>
        <?php
         }else{
        ?>      
              <td class="tablehead" style="width:20px"></td>
              <td class="tablehead" style="width:20px">ID</td>
              <td class="tablehead" style="width:20px">Název</td>
              <td class="tablehead">Platnost od</td>
          </tr><tr>
              <td class="tableculombhead" style="width:20px"></td>
              <td class="tableculombhead" style="width:20px"><input size="1" type="text" name="TEF_ID" value="<?php echo($_SESSION['TEF_TEMP'][TEF_ID]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead" style="width:20px"><input size="8" type="text" name="TEF_NAME" value="<?php echo($_SESSION['TEF_TEMP'][TEF_NAME]);?>" OnChange="RefreshForm(this)"></td>
              <td class="tableculombhead"></td>
         <?php
        }
         ?> 
          
                  <input type="hidden" name="TEF_SUBMITED" value="TRUE">
                  <input type="hidden" name="NEXTFORM" value="10" >
                  
          </tr>
          </form>
      
      
      
      <?php
      
      
      $a=1;
      
      #Podle radionbutonu je generovan odkaz na tarif_edit_detail
      if ($_POST['TEF_CHECK']=="Item"){
          
          while (list($idTARIF,$name,$cost) = 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 style=\"width:20px\"><a href=\"".selfURL()."?NEXTFORM=11&idTARIF=".$idTARIF."\"><img src=\"files/pictures/vyber.gif\"></a></td><td style=\"width:20px\">".$idTARIF."</td><td style=\"width:20px\">".$name."</td><td>".$cost."</td>";
              echo "</tr>";
          }
      #nebo generovan odkaz na tarif_group_edit_detail    
      }else{
      
          
          while (list($idTARIFMIX,$name,$startdate) = 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 style=\"width:20px\"><a href=\"".selfURL()."?NEXTFORM=16&idTARIFMIX=".$idTARIFMIX."\"><img src=\"files/pictures/vyber.gif\"></a></td><td style=\"width:20px\">".$idTARIFMIX."</td><td style=\"width:20px\">".$name."</td><td>".$startdate."</td>";
              echo "</tr>";
          }
      }
      
      
      
  
  //}

?>

    </table>
    </div>
</fieldset>
</div>
</center>