Location: PHPKode > projects > WebDex > contactMgr.php
<?PHP
/*
+--------------------------+
| include the needed files |
+--------------------------+
*/
	require_once('config.inc.php');
	require_once('php_inc/lib.inc.php');
	require_once('PEAR.php');
	require_once('classess/pageMaker_class.php');
/*
+------------------+
| Notes/Misc. info |
+------------------+
*/
	/*
	+-----------------------------------------------------------------------+
	| A series of variables need to be defined to output a complete page.   |
	| $pageTitle = the string to use as the html <TITLE>                    |
	| $pageHead = The page header                                           |
	| $pageSubMenu = a sub-menu/navigation system                           |
	| $pageSubHead = The page subhead                                       |
	| $response_message = Text Error/Message or $PEAR::Error                |
	| $pageBodyContent = the html to use in the body portion of the page    |
	|                                                                       |
	| A Standard footer for putting together and displaying a page is       |
	| included at the bottom of this file. Just define the variables.       |
	| Any Response Messages or Errors that are to be displayed to the user  |
	| should be set in $response_message to maintain a standard flow.       |
	+-----------------------------------------------------------------------+
	*/
	
/*
+------------------------+
| Set require user login |
+------------------------+
*/
	// Start or Resume User Session, and switch the id
	// to prevent session highjacking
	session_start();
	$sessionBackup = $_SESSION;
	$_SESSION = array();
	session_destroy();
	session_start();
	$_SESSION = $sessionBackup;
	// make sure the user is logged in before getting anything in this script
	$login = isLoggedin();
	if (PEAR::isError($login)) {
		header("Location: ".$GLOBALS[base_url]."login.php");
		exit;
	}
	
/*
+-------------------------------------------------+
| Define page content defaults.                   |
| These can be appended to or over written in the |
| data processing/preperation area below.         |
+-------------------------------------------------+
*/
	$pageTitle = 'WebDex - A Simple Contact Management System - Extended Search';
	$pageHead = '';
	$pageSubMenu = '';
	$pageSubHead = '';
	$pageBodyContent = '';


/*
+----------------------------------------+
| Start data processing/preperation area |
+----------------------------------------+
*/
	// 1st step in adding a new contact/company
	if ($_GET[action] == 'addNewContactStep1') {
		$pageHead = 'Add New Contact Step 1';
		$pageBodyContent = getAddContactStep1Form($_SERVER[PHP_SELF]);
	}
	if ($_GET[action] == 'addNewContactStep2') {
		$pageHead = 'Add New Contact Step 2';
		$pageSubHead = 'Select the existing contact you wish to base your new contact on.';
		// get all contacts that matches the query
		$query = getQuickQuery($_GET);
		$rows = selectRows($query);
		if (PEAR::isError($rows)) {
			$response_message = $rows;
			$pageBodyContent = getAddContactStep1Form($_SERVER[PHP_SELF]);
		} else {
			// build pulldown menu
			foreach ($rows as $row) {
				$opts[$row[id]] = getFullName($row[lastname], $$row[firstname]).', ('.$row[companyname].')';
			}
			$attributes = array('name'=>'contact_id',
								'selectClass'=>'bodyPulldownMenus',
								'optionClass'=>'bodyPulldownMenus');
			$contactMenu = mkPullDown($opts, $attributes);
			// put the form together
			$pageBodyContent = '<form name="addNewContact" method="GET" action="'.$_SERVER[PHP_SELF].'">
			<input name=action type=hidden value="addNewContactStep3">';
			$pageBodyContent .= $contactMenu.'<input name="Submit" type="Submit" class="bodySubmitButtons" value="Next"></form>
			<p align="center" class="bodySubHeads">-OR-</p>
        	<p align="center" class="bodyBodyTxt"><strong><a href="'.$_SERVER[PHP_SELF].'?action=addNewContactStep3">Skip the prefill, just give me the blank form.</a></strong></p>';
		}
	}
	if ($_GET[action] == 'addNewContactStep3') {
		$pageHead = 'Add New Contact Step 3';
		// get the contact record and prefill new contact form with it
		if ($_GET[contact_id] >= 1) {
			$contactRow = getRows($GLOBALS[dbContactTbl], $_GET[contact_id], '', 1);
		}
		// get the contact form, and prefill with co info
		$pageBodyContent = getContactForm($_SERVER[PHP_SELF], 'GET', 'Create Contact', $contactRow[0]);
	}
	if ($_GET[action] == 'addNewContactStep4') {
		$pageHead = 'Add New Contact Step 3';
		// insert the new contact record
		$result = addContact($_GET);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$response_message = 'Contact Created.';
			#$query = "SELECT id,firstname,lastname,address1,city,state,phone1,fax,email,website,businesstype,clientcode,companyname FROM ".$GLOBALS[dbContactTbl]." WHERE (id = \"".$result."\")";
			#$pageBodyContent = getSrchResultsTbl($query, 'extendedSearch', '');
		}
	}
	
/*
+--------------------------------------+
| End data processing/preperation area |
+--------------------------------------+
*/
	
/*
+--------------------------------------------+
| Start output/display the page              |
| Should not be any need to edit below here. |
+--------------------------------------------+
*/
	// build and output the page using pageMaker_class.php
	$page = new pageMaker();
	$page->setTemplateFile($GLOBALS[html_template]);
	$page->getTemplate();
	if (PEAR::isError($page)) {
		echo $page->getMessage();
		exit;
	}
	$page->setPgKey('{TITLE}', $pageTitle);
	$page->setPgKey('{EXTRAHTML}', getExtraHTML());
	$page->setPgKey('{LEFTNAV}', getLeftNav());
	$page->setPgKey('{TOPMENU}', getTopMenu());
	$page->setPgKey('{LOGINSTATUS}', getLoginStatus());
	$page->setPgKey('{HEADER}', $pageHead);
	$page->setPgKey('{SUBHEAD}', $pageSubHead);
	$page->setPgKey('{SUBMENU}', $pageSubMenu);
	$page->setPgKey('{RESPONSEMSG}', parseResponse($response_message));
	$page->setPgKey('{BODYCONTENT}', $pageBodyContent);
	if (PEAR::isError($page)) {
		echo $page->getMessage();
		exit;
	}
	$page->showPage();
?>
Return current item: WebDex