Location: PHPKode > projects > WebDex > index.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 |
+----------------------------------------+
*/
	// for extended searches
	if ($_GET[action] == 'extendedSearch' || $_GET[action] == '') {
		// save the search options if user wants to
		if ($_GET[remember_query] == 1) {
			saveExtSrchOpts($_GET[srch]);
		}
		$pageHead = 'Extended Search';
		if ($_GET[Submit] == 'Search') {
			// build the query withopu limits
			$queryNoLimit = getExtQuery($_GET[srch], $_GET[srch][results_per_page], $_GET[srch][startingRow], 0);
			// create the search summary statement
			$summary = getSrchSummary($queryNoLimit, $_GET[srch][startingRow], $_GET[srch][results_per_page]);
			// build the query with limits
			$query = getExtQuery($_GET[srch], $_GET[srch][results_per_page], $_GET[srch][startingRow]);
			// get the results of the query
			$results = getSrchResultsTbl($query, $_GET[action], $_GET[srch], $summary);
			if (PEAR::isError($results)) {
				$response_message = $results;
				$pageBodyContent = getExtSearchForm($_SERVER[PHP_SELF], 'GET');;
			} else {
				$pageBodyContent = $results;
			}
			
		} else {
			$form = getExtSearchForm($_SERVER[PHP_SELF], 'GET');
			if (PEAR::isError($form)) {
				$response_message = $form;
			} else {
				$pageBodyContent = $form;
			}
		}
	}
	// for quick searches
	if ($_GET[action] == 'quickSearch') {
	$pageHead = 'Quick Search';
		// save options for next time
		saveQuickSrchOpts($_GET[query_string], $_GET[query_field]);
		
		// build the query withopu limits
		$queryNoLimit = getQuickQuery($_GET, $GLOBALS[qckSrchRowsPerPg], $_GET[startingRow], 0);
		// create the search summary statement
		$summary = getSrchSummary($queryNoLimit, $_GET[startingRow], $GLOBALS[qckSrchRowsPerPg]);
		
		// build the query 
		$query = getQuickQuery($_GET, $GLOBALS[qckSrchRowsPerPg], $_GET[startingRow]);
		// get the results of the query
		$results = getSrchResultsTbl($query, $_GET[action], $_GET, $summary);
		if (PEAR::isError($results)) {
			$response_message = $results;
			if ($results->getMessage() == 'No Rows Found.') {
				$pageBodyContent = '<input name="Previous" type="submit" class="bodySubmitButtons" value="<< Previous '.$limit.' Rows" onClick="history.go(-1)">';
			}
		} else {
			$pageBodyContent = $results;
		}
	}
	// for exports
	if ($_GET[action] == 'exportResults') {
	$pageHead = 'Export Result Set Options';
		if ($_GET[Submit] == 'Export') {
			// grab the full resultset with no limits
			if ($_GET[exportFrom] == 'extendedSearch') {
				$query = getExtQuery($_GET[srch], $_GET[srch][results_per_page], $_GET[srch][startingRow], 0);
			} elseif ($_GET[exportFrom] == 'quickSearch') {
				$query = getQuickQuery($_GET, $GLOBALS[qckSrchRowsPerPg], $_GET[startingRow], 0);
			} elseif ($_GET[exportFrom] == 'editList') {
				$query = getListQuery($_GET[list_id], $_SESSION[userid], 0, 0);
			} 
			// generate and output data according to user settings
			$dump = exportResults($query, $_GET);
			if (PEAR::isError($dump)) {
				$response_message = $dump;
			} else {
				if ($_GET[save_to_file] == 1) {	// decide how to send output to user
					if ($_GET['export_format'] == 'xls') {
						header("Content-type: application/vnd.ms-excel");
					} else {
						header("Content-type: application/octet-stream");
					}
					header("Content-Disposition: attachment; filename=WebDex_export.".$_GET['export_format']."");
					header("Pragma: no-cache");
					header("Expires: 0");
					echo $dump; 
					exit;
				} else {
					$pageBodyContent = '<pre>'.$dump.'</pre>';
				}
			}
		} else {
			// present the user with export options form
			$pageBodyContent = getExportForm($_SERVER[PHP_SELF], 'GET', 'Export', $_GET);
		}
	}
	// for view/editing a list
	if ($_GET[action] == 'editList') {
		$pageHead = 'List Management';
		// get all contact records that belong to this list
		$query = getListQuery($_GET[list_id], $_SESSION[userid], $_GET[startingRow]);
		if (PEAR::isError($query)) {
			$response_message = $query;
		} else {
			$form = getListMgmtForm($_SERVER[PHP_SELF], 'GET', $query, $_GET);
			if (PEAR::isError($form)) {
				$response_message = $form;
			} else {
				$pageBodyContent = $form;
			}
		}
	}
	
/*
+--------------------------------------+
| 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