Location: PHPKode > scripts > Rolodex > rolodex/admin/index.php
<?php
/*
	Rolodex
	~~~~~~~~~~
	Author	: Thomas Whitecotton
	Email	: hide@address.com
	Website	: http://www.ciamosbase.com

*/
include("admin_header.php");

$op = $sys_request['op'];

function find() {
	
	echo '	<table border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td colspan="2">
						<h4>'._MI_ROLODEX_ADMENU2.':</h4><br />
					</td>
				</tr>
				<tr>
					<td>
						<form method="POST" action="index.php?op=update">
							Search For: 
							<input type="text" name="value" size="25">
							By: 
							<select size="1" name="search">
								<option selected value="last_name">
									Last Name
								</option>
							    <option value="first_name">
									First Name
								</option>
							    <option value="address">
									Address
								</option>
							    <option value="city">
									City
								</option>
							    <option value="zip">
									Zip
								</option>
						    </select>
							<br><br>
							<input type="submit" value="Continue" class="button" name="B1">
							<input type="reset" value="Clear" class="button" name="B2">
						</form>
					</td>
				</tr>
			</table>';
}

function add() {
	
	echo '<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<tr>
				<td colspan="2">
					<h4>'._MI_ROLODEX_ADMENU1.':</h4><br />
				</td>
			</tr>			
			<tr>
				<td>
				<form method="POST" action="index.php?op=insert">
					<p style="margin-top: 0; margin-bottom: 0">
						<b>First Name</b>
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<input type="text" name="fname" size="50">
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<b>Last Name</b>
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<input type="text" name="lname" size="50">
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<b>Address</b>
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<input type="text" name="address" size="50">
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<b>City</b>
						<input type="text" name="city" size="18">
						<b> State </b>
						<select size="1" name="state">
							<option selected>AL</option>
							<OPTION>AK</OPTION>
							<OPTION>AZ</OPTION>
							<OPTION>AR</OPTION>
							<OPTION>CA</OPTION>
							<OPTION>CO</OPTION>
							<OPTION>CT</OPTION>
							<OPTION>DE</OPTION>
							<OPTION>FL</OPTION>  
							<OPTION>GA</OPTION>
							<OPTION>HI</OPTION>  
							<OPTION>ID</OPTION>
							<OPTION>IL</OPTION>  
							<OPTION>IN</OPTION>  
							<OPTION>IA</OPTION>  
							<OPTION>KS</OPTION>  
							<OPTION>KY</OPTION>  
							<OPTION>LA</OPTION>
							<OPTION>ME</OPTION>  
							<OPTION>MD</OPTION>
							<OPTION>MA</OPTION>  
							<OPTION>MI</OPTION>  
							<OPTION>MN</OPTION>  
							<OPTION>MS</OPTION>  
							<OPTION>MO</OPTION>  
							<OPTION>MT</OPTION>  
							<OPTION>NE</OPTION>  
							<OPTION>NV</OPTION>  
							<OPTION>NH</OPTION>  
							<OPTION>NJ</OPTION> 
							<OPTION>NM</OPTION>  
							<OPTION>NY</OPTION>  
							<OPTION>NC</OPTION>  
							<OPTION>ND</OPTION>  
							<OPTION>OH</OPTION>  
							<OPTION>OK</OPTION>  
							<OPTION>OR</OPTION>  
							<OPTION>PA</OPTION>  
							<OPTION>RI</OPTION>  
							<OPTION>SC</OPTION>  
							<OPTION>SD</OPTION>  
							<OPTION>TN</OPTION>  
							<OPTION>TX</OPTION>  
							<OPTION>UT</OPTION>  
							<OPTION>VT</OPTION>  
							<OPTION>VA</OPTION>  
							<OPTION>WA</OPTION>  
							<OPTION>WV</OPTION>  
							<OPTION>WI</OPTION>  
							<OPTION>WY</OPTION>
						</select>
						<b> Zip </b>
						<input type="text" name="zip" size="5">
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<b>Phone Number</b>
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<input type="text" name="phone" size="50">
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<b>Notes</b>
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<input type="text" name="notes" size="50">
					</p>
					<p style="margin-top: 0; margin-bottom: 0">
						<input type="submit" value="Insert" class="button" name="B1">
						<input type="reset" value="Clear" class="button" name="B2">
					</p>
				</form>
				</td>
			</tr>
		  </table>';
}

function update() {

	// Global variables	
	global $db, $sys_request;
	
	$value  = $sys_request['value'];
	$search = $sys_request['search'];

	echo '	<table align="left" border="0" cellspacing="0" cellpadding="10">
				<tr>
					<td>';

	// Get the search results from the database
	$sql = "SELECT * FROM ".$db->prefix("rolodex")." WHERE " . $search . "='" . $value . "'";
	$result = @$db->query($sql);
	
	while(list($id,$fname,$lname,$address,$notes,$city,$state,$zip,$phone) = @$db->fetch_row($result))	{
		$fields = $db->num_fields($result);
	
		// Keep it from saying 'No entry was found'
		$search_results = "1";

	echo '				<form method="POST" action="index.php?op=save">
							<p style="margin-top: 0; margin-bottom: 0">
								<b>ID: </b>
								<input type="text" name="id" size="3" value='.$id.'>
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<b>First Name</b>
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<input type="text" name="fname" size="50" value="'.$fname.'">
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<b>Last Name</b>
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<input type="text" name="lname" size="50" value="'.$lname.'">
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<b>Address</b>
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<input type="text" name="address" size="50" value="'.$address.'">
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<b>City </b>
								<input type="text" name="city" size="18" value="'.$city.'">
									<b> State </b>
									<select size="1" name="state">
										<option selected>AL</option>
										<OPTION>AK</OPTION>
										<OPTION>AZ</OPTION>
										<OPTION>AR</OPTION>
										<OPTION>CA</OPTION>
										<OPTION>CO</OPTION>
										<OPTION>CT</OPTION>
										<OPTION>DE</OPTION>
										<OPTION>FL</OPTION>  
										<OPTION>GA</OPTION>
										<OPTION>HI</OPTION>  
										<OPTION>ID</OPTION>
										<OPTION>IL</OPTION>  
										<OPTION>IN</OPTION>  
										<OPTION>IA</OPTION>  
										<OPTION>KS</OPTION>  
										<OPTION>KY</OPTION>  
										<OPTION>LA</OPTION>
										<OPTION>ME</OPTION>  
										<OPTION>MD</OPTION>
										<OPTION>MA</OPTION>  
										<OPTION>MI</OPTION>  
										<OPTION>MN</OPTION>  
										<OPTION>MS</OPTION>  
										<OPTION>MO</OPTION>  
										<OPTION>MT</OPTION>  
										<OPTION>NE</OPTION>  
										<OPTION>NV</OPTION>  
										<OPTION>NH</OPTION>  
										<OPTION>NJ</OPTION> 
										<OPTION>NM</OPTION>  
										<OPTION>NY</OPTION>  
										<OPTION>NC</OPTION>  
										<OPTION>ND</OPTION>  
										<OPTION>OH</OPTION>  
										<OPTION>OK</OPTION>  
										<OPTION>OR</OPTION>  
										<OPTION>PA</OPTION>  
										<OPTION>RI</OPTION>  
										<OPTION>SC</OPTION>  
										<OPTION>SD</OPTION>  
										<OPTION>TN</OPTION>  
										<OPTION>TX</OPTION>  
										<OPTION>UT</OPTION>  
										<OPTION>VT</OPTION>  
										<OPTION>VA</OPTION>  
										<OPTION>WA</OPTION>  
										<OPTION>WV</OPTION>  
										<OPTION>WI</OPTION>  
										<OPTION>WY</OPTION>
									</select>
								<b> Zip </b>
								<input type="text" name="zip" size="5" value="'.$zip.'">
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<b>Phone Number</b>
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<input type="text" name="phone" size="50" value="'.$phone.'">
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<b>Notes</b>
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<input type="text" name="notes" size="50" value="'.$notes.'">
							</p>
							<p style="margin-top: 0; margin-bottom: 0">
								<input type="submit" class="button" value="Update" />&nbsp;
								<input type="button" class="button" onclick=\'location="index.php?op=deleted&id='.$id.'"\' value="Delete" />&nbsp;
								<input type="button" class="button" onclick=\'location="index.php"\' value="Cancel" />
							</p>
						</form>';
	}

	if($search_results != "1") {
    print("No entry was found. <a href='index.php?op=edit' alt='Click to continue'>Click to continue</a>");
	}

	echo '			</td>
				</tr>
			</table>';
}

function insert() {
	
	// Global variables	
	global $db, $sys_request, $eh;

	$fname   = $sys_request['fname'];
	$lname   = $sys_request['lname'];
	$address = $sys_request['address'];
	$notes   = $sys_request['notes'];
	$city    = $sys_request['city'];
	$state   = $sys_request['state'];
	$zip     = $sys_request['zip'];
	$phone   = $sys_request['phone'];

	$sql = "insert into ".$db->prefix("rolodex")." set first_name='" . $fname . "'"
	. ", last_name='" . $lname . "'"
	. ", address='" . $address . "'"
	. ", notes='" . addslashes($notes) . "'"
	. ", city='" . $city . "'"
	. ", state='" . $state . "'"
	. ", zip='" . $zip . "'"
	. ", phone='" . $phone . "'";
	$result = $db->query($sql);

	unset($op);
    redirect_header("index.php", 1, _MD_INSERTED);
    exit();
}

function deleted() {
	
	// Global variables	
	global $db, $sys_request, $eh;

	$id   = $sys_request['id'];
	
	$sql = "DELETE FROM ".$db->prefix("rolodex")." WHERE id ='" . $id . "'";
	$result = $db->query($sql);

	unset($op);
    redirect_header("index.php", 1, _MD_DELETED);
    exit();
}

function updated() {

	// Global variables	
	global $db, $sys_request, $eh;

	$id		 = $sys_request['id'];
	$fname   = $sys_request['fname'];
	$lname   = $sys_request['lname'];
	$address = $sys_request['address'];
	$notes   = $sys_request['notes'];
	$city    = $sys_request['city'];
	$state   = $sys_request['state'];
	$zip     = $sys_request['zip'];
	$phone   = $sys_request['phone'];

	$sql = "UPDATE ".$db->prefix("rolodex")." set first_name='" . $fname . "'"
	. ", last_name='" . $lname . "'"
	. ", address='" . $address . "'"
	. ", notes='" . addslashes($notes) . "'"
	. ", city='" . $city . "'"
	. ", state='" . $state . "'"
	. ", zip='" . $zip . "'"
	. ", phone='" . $phone . "' WHERE id='" . $id . "'";
	$result = $db->query($sql);

	unset($op);
    redirect_header("index.php", 1, _MD_UPDATED);
    exit();
}

function heading() {
	sys_cp_header();
	OpenTable();

	echo "<h4 style='text-align:left;'>"._MI_ROLODEX_NAME."</h4>
	<table border='0' cellpadding='0' cellspacing='0' valign='top' width='100%'>
		<tr>
			<td>";
}

function footing() {
echo "	</td>
	</tr>
</table>";

CloseTable();
sys_cp_footer();
}

switch($op) {
		
	case "add":
		heading();
		OpenTable();
		add();
		CloseTable();
		footing();
		break;

	case "deleted":
        deleted();
        break;

	case "edit":
		heading();
		OpenTable();
		find();
		CloseTable();
		footing();
		break;

	case "insert":
		insert();
		break;
    
	case "save":
		updated();
		break;

	case "update":
		heading();
		update();
		footing();
		break;

    default:
		heading();
		OpenTable();
		add();
		CloseTable();
		OpenTable();
        find();
		CloseTable();
		footing();
		break;
}
?>
Return current item: Rolodex