Location: PHPKode > projects > PHPmyCDMouse > phpmycdmouse_031/adressmodify.php
<?
/*
   Copyright (C) 2003  by Uwe Thiel, Germany

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
    USA.
*/
session_start();
$Access = $_SESSION["Access"];

if (!$Access[AddCD]) header("Location: index.php");


require("./config.inc.php");
require($Header);
#require("./functioninc/catpopup.js");



if (isset($_GET["id"])) $id=$_GET["id"];

$GetAdress=new CD_DB;
$GetAdressSQL="SELECT * FROM Adresses WHERE ID='".$id."'";
$GetAdress->query($GetAdressSQL);
if ($GetAdress->num_rows()>0) $GetAdress->next_record();
if (isset($_POST["Name"])) $Name =$_POST["Name"]; else $Name=$GetAdress->f("Name");
if (isset($_POST["SurName"])) $SurName =$_POST["SurName"]; else $SurName=$GetAdress->f("SurName");
if (isset($_POST["Street"])) $Street =$_POST["Street"]; else $Street=$GetAdress->f("Street");
if (isset($_POST["HouseNr"])) $HouseNr =$_POST["HouseNr"]; else $HouseNr=$GetAdress->f("HouseNr");
if (isset($_POST["PostalCode"])) $PostalCode =$_POST["PostalCode"]; else $PostalCode=$GetAdress->f("PostalCode");
if (isset($_POST["City"])) $City =$_POST["City"]; else $City=$GetAdress->f("City");
if (isset($_POST["Room"])) $Room =$_POST["Room"]; else $Room=$GetAdress->f("Room");
if (isset($_POST["Phone1"])) $Phone1 =$_POST["Phone1"]; else $Phone1=$GetAdress->f("Phone1");
if (isset($_POST["Phone2"])) $Phone2 =$_POST["Phone2"]; else $Phone2=$GetAdress->f("Phone2");

$abbruch = $_POST["abbruch"];




clearstatcache();  # Clear the statcache of File-Functions (like is_dir or is_link and so on).



if (isset($abbruch)) { # If Cancel is clicked after AddCD, then the global Variables must be unset, because they were filled with data after AddCD
    unset($Action);
    deletevars();
                     }




$submit=$_POST["submit"];

if ($submit) {
 if ($Name!="" && $SurName!="" && $Street!="" && $HouseNr!="" && $PostalCode!="" && $City!="") {
     $submit=true;
	 }
	 else {
	 $submit=false;
     $message="<div class=\"Alert\">You must enter data in all blue fields!</div>";
    }
}
if ($submit) {
			$CheckAdresses=new CD_DB;
#			$CheckAdressesSQL="Select * FROM Adresses WHERE Name=$Name AND SurName=$SurName AND Street=$Street AND HouseNr=$HouseNr AND PostalCode=$PostalCode AND City=$City";
			$CheckAdressesSQL="Select COUNT(ID) AS ADRMATCH FROM Adresses WHERE Adresses.Name='".$Name."' AND Adresses.SurName='".$SurName."' AND Adresses.Street='".$Street."' AND Adresses.HouseNr='".$HouseNr."' AND Adresses.PostalCode='".$PostalCode."' AND Adresses.City='".$City."'";
			$CheckAdresses->query($CheckAdressesSQL);
			$CheckAdresses->next_record();
			$AdrMatch=$CheckAdresses->f("ADRMATCH");
			if ($AdrMatch==0) {
			$StoreAdress=new CD_DB;
			$StoreAdressSQL="UPDATE Adresses SET Name='$Name',SurName='$SurName',Street='$Street',HouseNr='$HouseNr',PostalCode='$PostalCode',City='$City',Phone2='$Phone2' WHERE ID=$id";
			$StoreAdress->query($StoreAdressSQL);

# now close thiswindow and refresh adress-frame to show the new added adress
			?>
			<script type="text/javascript">
			window.opener.top.mainwindow.location.reload(true);
			window.close();
			</script>

			<?
			} else
			  {
				$submit=false;
    			$message="<div class=\"Alert\">Adress already in database!</div>";
			  }


  } ####of if ($submit)




if (!$submit) {

?>
    <h1> Modify adress </h1><br>
    <? echo $message;?>
	<br>
    <form method="post" name=adressaddform action="<?=$_SERVER["PHP_SELF"]?>?id=<?=$id?>" method="post">
    <table cellpadding="2" border=1>
	<tr><td class="CDLendAdrDesc0"><font color="blue">Name:</font></td>
	<td class="CDLendAdrLine0"><input class="ReqTextField" type="text" name="Name" value="<?=$Name?>" size="25"></td><td class="CDLendAdrLine0" width=32px></td>
	<td class="CDLendAdrDesc0"><font color="blue">Surname:</font></td>
	<td class="CDLendAdrLine0"><input class="ReqTextField" type="text" name="SurName" value="<?=$SurName?>" size="25"></td></tr>
	<tr><td class="CDLendAdrDesc1">Room:</td>
	<td class="CDLendAdrLine1"><input type="text" name="Room" value="<?=$Room?>" size="25"></td>
	<td colspan="3" class="CDLendAdrLine1"></td></tr>
	<tr><td class="CDLendAdrDesc0"><font color="blue">Street:</font></td>
	<td class="CDLendAdrLine0"><input class="ReqTextField" type="text" name="Street" value="<?=$Street?>" size="25"></td><td class="CDLendAdrLine0" width=32px></td>
	<td class="CDLendAdrDesc0"><font color="blue">Nr.:</font></td>
	<td class="CDLendAdrLine0"><input class="ReqTextField" type="text" name="HouseNr" value="<?=$HouseNr?>" size="25"></td></tr>
	<tr><td class="CDLendAdrDesc1"><font color="blue">PostalCode:</font></td>
	<td class="CDLendAdrLine1"><input class="ReqTextField" type="text" name="PostalCode" value="<?=$PostalCode?>" size="25"></td><td class="CDLendAdrLine1" width=32px></td>
	<td class="CDLendAdrDesc1"><font color="blue">City:</font></td>
	<td class="CDLendAdrLine1"><input class="ReqTextField" type="text" name="City" value="<?=$City?>" size="25"></td></tr>
	<tr><td class="CDLendAdrDesc0">Phone1:</td>
	<td class="CDLendAdrLine0"><input type="text" name="Phone1" value="<?=$Phone1?>" size="25"></td><td class="CDLendAdrLine0" width=32px></td>
	<td class="CDLendAdrDesc0">Phone2:</td>
	<td class="CDLendAdrLine0"><input type="text" name="Phone2" value="<?=$Phone2?>" size="25"></td></tr>
	<tr><td class="CDLendAdrDesc0" colspan="5" align="right"><input type="submit" name="submit" value="submit"><input type=button name=Cancel value=cancel onClick="window.close()"></td></tr>
	<tr><td colspan="5" align="right"><font color="blue">* blue items are required!</font></td></tr>

	</table>
    </form>


<? } ######of if (!$submit)


require($Footer);
?>
Return current item: PHPmyCDMouse