Location: PHPKode > scripts > PHP-AGTC membership system > admin/delete_contact.php
<?php

  require '../init.php';
  require '../mysqlvars.php';
  require '../lib/db.php';
  require '../lib/form_functions.php';

  session_start('ADMIN');

  $dbConn = connectDB($dbHost, $dbUser, $dbPass, $dbDB);
  if (!$dbConn) {
	die('Database is currently down...please try again later');
  }
  
  require 'includes/secure_page.php';

  if (!isset($_GET['address_id']) && !isset($_POST['address_id'])) {
	die ('Illegal navigation');
  }
  else {
	$address_id = isset($_GET['address_id']) ? $_GET['address_id'] : $_POST['address_id'];
  }

  unset($error);
  unset($confirm);
  $found = false;

  if (isset($_POST['confirm'])) {
	$query = "DELETE FROM wsd_contacts WHERE ";
	$query .= "address_id = '" . $address_id . "'";

	if (mysql_query($query)) {
	  
	  if (mysql_affected_rows() > 0) {
		
		// delete any uploaded files for this user
		$result = mysql_query("SELECT * FROM wsd_files WHERE address_id = '$address_id'");
		if ($result) {
		  if ($frow = mysql_fetch_array($result)) {
			do {
			  $fl = $frow['file_id'] . '.' . $frow['ftype'];
			  print $fl;
			  if (file_exists($APP->upload_dir . $fl)) {
				unlink($APP->upload_dir . $fl);  
			  }
			  mysql_query("DELETE FROM wsd_files WHERE file_id = " . $frow['file_id']);
			} while ($frow = mysql_fetch_array($result));
		  }
		} 
	  } ?>
	  <SCRIPT LANGUAGE="JavaScript">
	  <!--
		 if (window.opener) {
		   if (!window.opener.closed) { 
			 window.opener.location.reload(1); 
		   }
		   window.close();
		 }
					       
	  //-->
	  </SCRIPT>
	  <?php      
	  
	  $confirm = 'Contact deleted';
	  $found = false;
	}
	else {
	  $error = mysql_error();
	}
  
  }

  else {
	$query = "SELECT first_name, last_name, email, home_phone, work_phone, mobile_phone, address, city, zip_code, country, comments, username FROM wsd_contacts WHERE ";
	$query .= "address_id = '" . $address_id . "'";
	$result = mysql_query($query, $dbConn);
	if ($result) {
	  if ($frow = mysql_fetch_array($result)) {
		$found = true;
		$first_name = $frow['first_name'];
		$last_name = $frow['last_name'];
		$email = $frow['email'];
		$home_phone = $frow['home_phone'];
		$work_phone = $frow['work_phone'];
		$mobile_phone = $frow['mobile_phone'];
		$address = $frow['address'];
		$city = $frow['city'];
		$zip_code = $frow['zip_code'];
		$country = $frow['country'];
		$comments = $frow['comments'];
		$username = $frow['username'];
	  }
	  else {
		$error = 'Contact not found';
	  }
	}
	else {
	  $error = mysql_error();
	}
  }

  include '../members/includes/header.php';
  
?>

	<tr>
	  <td>
		<table class="fg">
		  <tr>
			<td class="title">Delete Contact created by '<?php echo $username; ?>'</td>
		  </tr>
		</table>
	  </td>
	</tr>
	<tr>
	  <td>
	  <table class="nb">
		  Warning: Deleting a contact is irreversible and will remove all stored files relating to the contact

		</table>
	  </td>
	</tr>
	<tr>
	  <td>
	  <table class="nb">
		  <?php if (isset($confirm)) { echo "<tr><td class=\"bold\">$confirm</td><tr>"; } ?>

		  <?php if (isset($error)) { echo "<tr><td class=\"error\">$error</td></tr>"; } ?>

		</table>
	  </td>
	</tr>
	<tr>
	  <td>
		<?php if ($found) { ?>
		  <table class="fg">
			<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
			<tr><td class="label">&nbsp;</td><td class="field"><input type="hidden" name="address_id" value="<?php echo $address_id ?>"></td></tr>
			
			<tr>
			  <td class="label">First name:</td>
			  <td class="field"><?php echo $first_name ?></td>
			</tr>
			<tr>
			  <td class="label">Last name:</td>
			  <td class="field"><?php echo $last_name ?></td>
			</tr>
			<tr>
			  <td class="label">Email:</td>
			  <td class="field"><?php echo $email ?></td>
			</tr>
			<tr>
			  <td class="label">Home phone:</td>
			  <td class="field"><?php echo $home_phone ?></td>
			</tr>
			<tr>
			  <td class="label">Work phone:</td>
			  <td class="field"><?php echo $work_phone ?></td>
			</tr>
			<tr>
			  <td class="label">Mobile:</td>
			  <td class="field"><?php echo $mobile_phone ?></td>
			</tr>
			<tr>
			  <td class="label">Address:</td>
			  <td class="field"><?php echo $address ?></td>
			</tr>
			<tr>
			  <td class="label">City:</td>
			  <td class="field"><?php echo $city ?></td>
			</tr>
			<tr>
			  <td class="label">Zip code:</td>
			  <td class="field"><?php echo $zip_code ?></td>
			</tr>
			<tr>
			  <td class="label">Country:</td>
			  <td class="field"><?php echo $country ?></td>
			</tr>
			
			<tr>
			  <td class="label">Comments:</td>
			  <td class="field"><?php echo nl2br(wordwrap($comments, 30, "\n", 1)) ?></td>
			</tr>

			
			<tr><td class="label">&nbsp;</td><td class="field"><input type="Submit" name="confirm" value="Delete"></td></tr>
			</form>
		  </table>
		<?php } ?>
	  </td>
	</tr>
  
<?php include '../members/includes/footer.php' ?>

Return current item: PHP-AGTC membership system