Location: PHPKode > projects > Butterfly Organizer > module-contacts.php
<?php
/*
Butterfly Organizer
Copyright (C) 2007-2008 Butterfly Media Romania

This file is part of Butterfly Organizer.

Butterfly Organizer 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; version 3 of the License.

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
*/

include('includes/top.php');
echo '<h2>Contact Manager</h2>';

$alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for ($n=0; $n<=25; $n++) {
	echo '<a href="module-contacts.php?letter='.$alphabet[$n].'" class="bsButtonSmall">'.$alphabet[$n].'</a> ';
}

if(isset($_GET['letter'])) {
	$letter = $_GET['letter'];

	$result = mysql_query("SELECT * FROM contacts WHERE lastname LIKE '".$letter."%' ORDER BY lastname ASC",$database);
	echo '<br /><br /><h2>Contact List - Letter "'.$letter.'"</h2><br /><br />';
	while ($myrow = mysql_fetch_array($result)) {
		echo '<p class="content_container">';
		echo '<strong>'.$myrow['lastname'].' '.$myrow['firstname'].'</strong> <a href="module-contacts.php?id='.$myrow['id'].'"><img src="'.$imagesFolder.'icon-account-edit.png" alt="Edit" title="Edit" /></a> <a href="module-contacts.php?id='.$myrow['id'].'&amp;action=delete" onclick="return confirmLinkDropACC(this, \'delete &lt;'.$myrow['lastname'].' '.$myrow['firstname'].'&gt;?\')"><img src="'.$imagesFolder.'icon-account-delete.png" alt="Delete" title="Delete" /></a><br />';
		echo $myrow['address'].', '.$myrow['city'].'<br />';
		echo $myrow['phone'].', '.$myrow['email'].'<br />';
		echo $myrow['notes'];
		echo '</p>';
	}
}

if(isset($_GET['action'])) {
	$action = $_GET['action'];
	$id = $_GET['id'];

	$sql = "DELETE FROM `contacts` WHERE `contacts`.`id` = ".$id." LIMIT 1;";
	$result = mysql_query($sql);
	echo "<meta http-equiv=\"refresh\" content=\"0; url=module-contacts.php\" />";
}

if(isset($_POST['submit'])) {

	$id = $_POST['id'];
	$firstname = $_POST['firstname'];
	$lastname = $_POST['lastname'];
	$address = $_POST['address'];
	$city = $_POST['city'];
	$phone = $_POST['phone'];
	$email = $_POST['email'];
	$notes = $_POST['notes'];

	$sql = "INSERT INTO contacts (id, firstname, lastname, address, city, phone, email, notes) VALUES ('$id', '$firstname', '$lastname', '$address', '$city', '$phone', '$email', '$notes')";
	$result = mysql_query($sql);
	echo "<meta http-equiv=\"refresh\" content=\"0; url=module-contacts.php\" />";
}
else if(isset($_POST['update'])) {

	$id = $_POST['id'];
	$firstname = $_POST['firstname'];
	$lastname = $_POST['lastname'];
	$address = $_POST['address'];
	$city = $_POST['city'];
	$phone = $_POST['phone'];
	$email = $_POST['email'];
	$notes = $_POST['notes'];

	$sql = "UPDATE contacts SET id='$id',firstname='$firstname',lastname='$lastname',address='$address',city='$city',phone='$phone',email='$email',notes='$notes' WHERE id=$id";
	$result = mysql_query($sql);
	echo "<meta http-equiv=\"refresh\" content=\"0; url=module-contacts.php\" />";
}
else if(isset($_GET['id'])) {
	$id = $_GET['id'];
	$result = mysql_query("SELECT * FROM contacts WHERE id=$id",$database);
	$myrow = mysql_fetch_array($result);

	echo '<br /><br /><h2>Edit Contact - "'.$myrow['lastname'].' '.$myrow['firstname'].'"</h2><br /><br />';

	echo "<form method='post' action='module-contacts.php?id=".$myrow['id']."' id='myform'>";
	echo "<table cellspacing='1' cellpadding='2' class='mainTable'>";
	echo "<tr><td class='td_title'>First Name:</td><td class='td_content'><input type='text' name='firstname' value='".$myrow['firstname']."' /></td></tr>";
	echo "<tr><td class='td_title'>Last Name:</td><td class='td_content'><input type='text' name='lastname' value='".$myrow['lastname']."' /></td></tr>";
	echo "<tr><td class='td_title'>Address:</td><td class='td_content'><input type='text' name='address' value='".$myrow['address']."' /></td></tr>";
	echo "<tr><td class='td_title'>City:</td><td class='td_content'><input type='text' name='city' value='".$myrow['city']."' /></td></tr>";
	echo "<tr><td class='td_title'>Phone:</td><td class='td_content'><input type='text' name='phone' value='".$myrow['phone']."' /></td></tr>";
	echo "<tr><td class='td_title'>Email:</td><td class='td_content'><input type='text' name='email' value='".$myrow['email']."' /></td></tr>";
	echo "<tr><td class='td_title'>Notes:</td><td class='td_content'><textarea class='expanding' name='notes' value='".$myrow['notes']."' cols='40'></textarea></td></tr>";
	echo "<input type='hidden' name='id' value='".$myrow['id']."' />";
	echo "<tr><td class='td_title' colspan='2'><input type='submit' name='update' value='Update' /></td></tr>";
	echo "</table>";
	echo "</form>";
}
else {
	echo '<br /><br />';
	echo '<h2>Add Contact</h2>';
	echo "<form method='post' action='module-contacts.php' id='myform'>";
	echo "<table cellspacing='1' cellpadding='2' class='mainTable'>";
	echo "<tr><td class='td_title'>First Name:</td><td class='td_content'><input type='text' name='firstname' /></td></tr>";
	echo "<tr><td class='td_title'>Last Name:</td><td class='td_content'><input type='text' name='lastname' /></td></tr>";
	echo "<tr><td class='td_title'>Address:</td><td class='td_content'><input type='text' name='address' /></td></tr>";
	echo "<tr><td class='td_title'>City:</td><td class='td_content'><input type='text' name='city' /></td></tr>";
	echo "<tr><td class='td_title'>Phone:</td><td class='td_content'><input type='text' name='phone' /></td></tr>";
	echo "<tr><td class='td_title'>Email:</td><td class='td_content'><input type='text' name='email' /></td></tr>";
	echo "<tr><td class='td_title'>Notes:</td><td class='td_content'><textarea class='expanding' name='notes' cols='40'></textarea></td></tr>";
	echo "<input type='hidden' name='id' />";
	echo "<tr><td class='td_title' colspan='2'><input type='submit' name='submit' value='Add' /></td></tr>";
	echo "</table>";
	echo "</form>";
}

?>

<?php include('includes/bottom.php');?>
Return current item: Butterfly Organizer