<?php
# Prefix_edit_module ver.1.0
# last modification 20.5.2010
# Formulář pro stanovení předvoleb
# 
  if (IsSet($_GET['BPE_DELETE'])){
    $query="UPDATE dest_number SET validity=0 
            WHERE idNUMBER=".$_GET['idNUMBER']."
            ";
    $result = mysql_query($query);
    if (!$result) {
      die('Aktualizace dat nebyla zapsána:' . mysql_error());
    }  
  }


 if (IsSet($_POST['BPE_SUBMITED'])){
  
    include "build/db_connect.inc.php"  ;
    $query="SELECT idNUMBER 
              FROM dest_number
              WHERE number=\"".$_POST['BPE_NUMBER']."\"";
    $result = mysql_query($query);
    if (mysql_num_rows($result)==0){
    //  $trans="START TRANSACTION";
      $query="INSERT INTO dest_number (number) 
              VALUES (\"".$_POST['BPE_NUMBER']."\")";
      $result = mysql_query($query);
      if (!$result) {
        die('Aktualizace dat nebyla zapsána:' . mysql_error());
      }

    } else{ # jestli položka už existuje, tak se pouze načte
        list($idNUMBER) = mysql_fetch_row($result)  ;
        $query="UPDATE dest_number SET validity=1 WHERE idNUMBER=".$idNUMBER."";
        $result = mysql_query($query);
        if (!$result) {
            die('Aktualizace dat nebyla zapsána:' . mysql_error());
        }        
    }  
}  
?>
<center>
<div class="forms">
<h3>Editace prefixů</h3><span class="backtoform"><a href="admin_page.php?NEXTFORM=10">Zpět</a> </span>
<fieldset>
  <legend>Seznam prefixů</legend>
  <div class="userlist">
<form action="admin_page.php" method="POST">
  <table style="width:200px">
    <tr>
        <td colspan=2 class="tablehead">Nový prefix</td>
    </tr><tr>
        <td colspan=2 class="tableculombhead"><input type="text" size=2 name="BPE_NUMBER"/><input type="submit" value="Vytvoř"/></td>
    </tr><tr>
        <td colspan=2 class="tablehead">Prefix</td>
         <input type="hidden" name="NEXTFORM" value="29">
  <input type="hidden" name="BPE_SUBMITED" value="TRUE">
  </tr>

<?php
require "build/db_connect.inc.php"  ;
$query="SELECT DN.idNUMBER,number 
        FROM dest_number DN  
        WHERE DN.validity=1
        ORDER BY NUMBER ASC";        
        
        
$result = mysql_query($query);
if (!$result) {
      die('Data prefixů nelze načíst:' . mysql_error());
   }
      $a=1;
      while (list($idNUMBER,$number) = 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=29&BPE_DELETE=True&idNUMBER=".$idNUMBER."\"><img src=\"files/pictures/no1.gif\"</a></td><td>".$number."</td>";
        echo "</tr>";
        
      
      
      }
      echo "</table>";
?>
    </form>
     </div>
  </fieldset>
</div>
</center>
