<?php
# ID: 24
# Providers_edit_module ver.1.0
# last modification 16.5.2010
# Formulář pro editaci privideru
#
# 
if ($_POST['PC_SUBMIT']=="TRUE" ){
  include "build/db_connect.inc.php"  ;
   $query="UPDATE provider SET name=\"".$_POST['PC_NAME']."\",description=\"".$_POST['PC_DESCRIPTION']."\",validity=".$_POST['PC_VALIDITY']."
            WHERE idPROVIDER=".$_POST['PC_IDPROVIDER']." ";      
    $result = mysql_query($query);
    if (!$result) {
        die('Data nelze aktualizovat:' . mysql_error());
    }   
  echo "Data o poskytelovately aktualizovány. ";
  echo "<a href=\"".selfURL()."?idPROVIDER=".$_POST['PC_IDPROVIDER']."\">Pokračovat</a>";
}else{ 
?>

<script language="JavaScript">
// soubor funkcí pro kontrolu hodnot formuláře na straně klienta
  function HideIt() {
        document.getElementById('required').style.visibility= "hidden";
        document.getElementById('requiredtext').style.visibility= "hidden";
  }
 
   
  function CheckEmptyField( theField, theMessage ) {
   if( theField.value=="" ) {
      theField.focus();
      if(document.getElementById) {
        document.getElementById('required').style.visibility= "visible";
        document.getElementById('requiredtext').style.visibility= "visible";
        document.getElementById('requiredtext').innerHTML= theMessage;
        setTimeout( "HideIt()",1500);
      } else {
          alert(theMessage);
      }
      return false;
   } else {
      return true;
   }
  }
  function Validate(theForm) {
      if( !CheckEmptyField(theForm.PC_NAME,"Zadejte prosím název providera!") ) return false;
      
  // uspech
  return true;
}
     <!-- <![CDATA[
      var MaxLengthLock = false;
      function MaxLengthCount(fieldObj,fieldMaxLength)
      {
        if (!MaxLengthLock)
        {
          MaxLengthLock = true;
          if (fieldObj.value.length > fieldMaxLength)
          {
            alert("Text je delší než " + fieldMaxLength + " znaků!");
            fieldObj.value = fieldObj.value.substring(0,fieldMaxLength);
          }
          var percentage = parseInt(100 - (( fieldMaxLength - fieldObj.value.length) * 100)/fieldMaxLength);
          document.getElementById(fieldObj.id + "_PBar").style.width = parseInt((parseInt(fieldObj.offsetWidth)*percentage)/100)+"px";
          MaxLengthLock = false;
        }
      }
      //]]> -->
 

</script>

<?php
  require "build/db_connect.inc.php"  ;
  $query="SELECT idPROVIDER,name,description,validity 
          FROM provider 
          WHERE idPROVIDER=".$_GET['idPROVIDER']."";
  $result = mysql_query($query);    
  if (!$result) {
        die('Data o providerovy nelze načíst:' . mysql_error());
  }  
  list($idprovider,$name,$description,$validity)=mysql_fetch_row($result);
  
?>
<center>
 <div class="forms">
<h2>Editace providera</h2><span class="backtoform"><a href="admin_page.php?NEXTFORM=19">Zpět</a> </span>
<fieldset>
  <legend>Informace</legend>
  
  <form name="form1" action="admin_page.php" onSubmit="return Validate(this);" method="post">
      <table>
        <tr>
          <td class="tablehead">ID: </td><td class="tableculombhead"><input type="text" name="PC_IDPROVIDER" value="<?php echo $idprovider; ?>" disabled ></td>
        </tr><tr>
          <td class="tablehead">Název: </td><td class="tableculombhead"><input type="text" name="PC_NAME" value="<?php echo $name; ?>" ></td>
        </tr><tr>
          <td class="tablehead">Aktivní: </td><td class="tableculombhead"><input type="checkbox" name="PC_VALIDITY" value="1" <?php if ($validity==1){echo "checked";}?></td>
        </tr><tr>
          <td class="tablehead" colspan=2>Popis: </td>
        </tr>
        <tr>
          <td colspan=2 class="tableculombhead"><textarea name="PC_DESCRIPTION" id="PC_DESCRIPTION" accesskey="T" rows="6" cols="30" wrap="virtual"
            onpropertychange="MaxLengthCount(this,160);"
            onclick="MaxLengthCount(this,160);"
            onmousemove="MaxLengthCount(this,160);"
            onblur="MaxLengthCount(this,160);"
            onkeyup="MaxLengthCount(this,160);"
            onfocus="MaxLengthCount(this,160);"
            onchange="MaxLengthCount(this,160);"
            onafterupdate="MaxLengthCount(this,160);"><?php echo $description;?></textarea>
          <div id="PC_DESCRIPTION_PBar" style="width:0px;height:10px;border:0;font-size:8px;overflow:hidden;background-color: #3399FF;"></div></td>
        </tr><tr>
        <input name="PC_IDPROVIDER" type="hidden" value="<?php echo $idprovider; ?>" >
        <input name="PC_SUBMIT" type="hidden" value="TRUE" >
        <input type="hidden" name="NEXTFORM" value="24" >
        <td class="tablehead" colspan=2 style="text-align:center"><input type="reset" value="Storno"><input type="submit" value="Ulož"></td>
        </tr>
      </table>
  </form>
</fieldset> 

</div>
</center>
<script language="JavaScript"><!-------------
// Tuto funkci je mozno vlozit na konec hlavního dokumentu a ušetři její opakování
if(document.getElementById) {
  document.write('<img ID="required" STYLE="visibility:hidden; position:absolute; left:300; top:120" src="required.gif">');
  document.write('<p ID="requiredtext" STYLE="visibility:hidden; position:absolute; left:365; top:155" >abc</p>');
}

//-----------></script> 
<?php
}
?>