Location: PHPKode > projects > PHPmyCDMouse > phpmycdmouse_031/adressdel.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/popupvar.js");
deletevars();


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


if (isset($_POST["submit"])) $submit=$_POST["submit"]; else $submit=false;
if (isset($_POST["deladress"])) $deladress=$_POST["deladress"];


if (isset($id) && $id > 0) {

## Get Adress data AND all lane data ...
	$GetAll= new CD_DB;
    $GetAllSQL="SELECT Adresses.ID as ID, Name, SurName, Street, HouseNr, PostalCode, City, Room, Phone1, Phone2, LendData.ID AS LendID, LendData.AdressID, LendData.CDID, LendData.LendDate FROM Adresses LEFT JOIN  LendData ON Adresses.ID=LendData.AdressID WHERE Adresses.ID='".$id."' ORDER BY ID, CDID";
    $GetAll->query($GetAllSQL);

	#### we needs to know, how much media (CDs/DVDs) one person has lend....
	$LendsOfAdr=new CD_DB;
	$LendsOfAdrSQL="SELECT COUNT(ID) AS MediaCount FROM LendData WHERE AdressID='".$id."'";
	$LendsOfAdr->query("$LendsOfAdrSQL");
	$LendsOfAdr->next_record();
	#####

	if ($LendsOfAdr->f("MediaCount") >0) $NrLends=$LendsOfAdr->f("MediaCount");

	if (isset($NrLends)) {
	$message="<div class=\"Alert\">WARNING! This adress contains lend data!!!</div>";
    }

	if (isset($deladress)) {
		$DeleteAdress=new CD_DB;
		$DeleteAdressSQL="DELETE FROM Adresses WHERE ID='".$id."'";
		$DeleteAdress->query($DeleteAdressSQL);
		$message="<div class=\"WarningBlue\">This Adress has been deleted</div>";
		if (isset($NrLends)) {
			$DeleteLends=new CD_DB;
			$DeleteLendsSQL="Delete FROM LendData WHERE AdressID='".$id."'";
			$DeleteLends->query($DeleteLendsSQL);
			$message="<div class=\"WarningBlue\">This Adress (including media lends) has been deleted</div>";
		}

	}

### now list the adress
?>
	<h1>Adress marked for deletion:</h1>
<?
    if ($GetAll->num_rows()>0) {
		?><br><br>

		<table cellpadding="2" ><tr><td colspan="4" align="center">
		<?
		echo("$message");
		?>
		</td></tr><tr><td>
		<?
		while ($GetAll->next_record()) {
		?>



		<table cellpadding="2" width=100% frame="3px">
		<?
			###now show the adress
			$count=0;
			if (($GetAll->f('Name') != "") || ($GetAll->f('SurName') != ""))
			 { ?>
              <tr><td class="CDLendAdrDesc<?=$count%2?>">Name: </td><td class="CDLendAdrLine<?=$count%2?>"><font color="Blue"><b><?=$GetAll->f('Name')?></b></font></td><td class="CDLendAdrDesc<?=$count%2?>">Surname: </td><td class="CDLendAdrLine<?=$count%2?>"><font color="Blue"><b><?=$GetAll->f('SurName')?></b></font></td></tr>

				<?
				$count++;
			 }

			 if ($GetAll->f('Room') != "")
			 { ?>
              <tr><td class="CDLendAdrDesc<?=$count%2?>">Room: </td><td class="CDLendAdrLine<?=$count%2?>"><b><?=$GetAll->f('Room')?></b></td><td colspan="2" class="CDLendAdrDesc<?=$count%2?>"></td></tr>
				<?
				$count++;
			 }

			 if (($GetAll->f('Street') != "") || ($GetAll->f('HouseNr') != ""))
			 { ?>
              <tr><td class="CDLendAdrDesc<?=$count%2?>">Street: </td><td class="CDLendAdrLine<?=$count%2?>"><b><?=$GetAll->f('Street')?></b></td><td class="CDLendAdrDesc<?=$count%2?>">Nr.: </td><td class="CDLendAdrLine<?=$count%2?>"><b><?=$GetAll->f('HouseNr')?></b></td></tr>
				<?
				$count++;
			 }


			 if (($GetAll->f('PostalCode') != "") || ($GetAll->f('City') != ""))
			 { ?>
              <tr><td class="CDLendAdrDesc<?=$count%2?>">Postalcode: </td><td class="CDLendAdrLine<?=$count%2?>"><b><?=$GetAll->f('PostalCode')?></b></td><td class="CDLendAdrDesc<?=$count%2?>">City: </td><td class="CDLendAdrLine<?=$count%2?>"><b><?=$GetAll->f('City')?></b></td></tr>
				<?
				$count++;
			 }


			 if (($GetAll->f('Phone1') != "") || ($GetAll->f('Phone2') != ""))
			 { ?>
              <tr><td class="CDLendAdrDesc<?=$count%2?>">Phone1: </td><td class="CDLendAdrLine<?=$count%2?>"><b><?=$GetAll->f('Phone1')?></b></td><td class="CDLendAdrDesc<?=$count%2?>">Phone2: </td><td class="CDLendAdrLine<?=$count%2?>"><b><?=$GetAll->f('Phone2')?></b></td></tr>
				<?
				$count++;
			 }
		?>

   				 <tr ><td colspan=4>
				  <table class="CDLendHdr0" width=100% cellpadding=2 >
				  <tr class="CDLendHdr0"><td colspan="5"><B>Media lent:</B></td></tr>
				  <tr class="CDLendHdr1"><td width="32px"><b>Icon</b></td><td><B>Inv.nr.</B></td><td><B>Lent since</B></td><td><B>Name</B></td><td><B>Description</B></td></tr>
			  	<?

			 if ($LendsOfAdr->f('MediaCount') > 0)
			 {


				for ($cnt=1; $cnt <= $LendsOfAdr->f('MediaCount'); $cnt++)
				{


					$GetCDName=new CD_DB; ####get Name and other Data of lent CD
					$GetCDNameSQL="SELECT CDID, CDNumber, CDLabel, Description FROM CD Where CDID=".$GetAll->f('CDID');
					$GetCDName->query("$GetCDNameSQL");
					$GetCDName->next_record();
					?><tr class="CDLine<?echo(strval($cnt%2));?>" onmouseover="this.className='MouseOverRow';" onmouseout="this.className='CDLine<?echo(strval($cnt%2));?>';" ><td width=32px><a href="browseinit.php?LookupType=Browse&<?echo("BrowseBy=CD&ID=".$GetAll->f("CDID"));?>" title="<? echo("Browse this media");?>" target=mainwindow class="BrowseList"><img width=32px,height=32px BORDER=0 src="showicon.php?type=cdicon2"></a></td><?
					?><td><center><?=$GetCDName->f("CDNumber")?></center></td><td><?=$GetAll->f("LendDate")?></td><td><?=$GetCDName->f("CDLabel")?></td><td><?=$GetCDName->f("Description")?></td></tr><?

					if (($LendsOfAdr->f('MediaCount')-$cnt)>0) {
				  		$GetAll->next_record();
					}
				}
			 ?></table>

				<?
			 }
			 else {
				?>
				<tr class="CDLine0"><td colspan="5"><div class="Warning"><b>No media lent.</b></div></td></tr>
				</table>
				<?
			 }
			 ?>
			 <tr class="CDLendAdrDesc1"><td colspan="4" align="right">
			 <?
			 if (!isset($deladress)){
			 		?>
			 		<form method="post" name=adressdelform action="<?=$_SERVER["PHP_SELF"]?>?id=<?=$id?>" method="post">

					<? if (isset($NrLends)) {
					?>
					<input type="submit" name="deladress" value="delete adress and lend data">
					<?
					}
					else {
					?>
					<input type="submit" name="deladress" value="delete adress">
					<?
					}
					?>
					<input type=button name=Cancel value=cancel onClick="window.close()">
				<?
				}
				else
				 {
				?>
				<script type="text/javascript">
				window.opener.top.mainwindow.location.reload(true);
				</script>
				<input type=button name=Close value=Close onClick="window.close()">
				<?
				 }
				 ?>
					</td></tr>
				</table>


			 <?

}

}

?></td></tr></table><?

}

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