Location: PHPKode > projects > WebDex > popupMgr.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)) {
		closeChildLoadParent($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 = '';
	$pageHead = '';
	$pageSubMenu = '';
	$pageSubHead = '';
	$pageBodyContent = '';


/*
+----------------------------------------+
| Start data processing/preperation area |
+----------------------------------------+
*/
	######### CONTACT MGMT ###########
	
	if ($_GET[action] == 'getFullContact') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = getFullContact($_GET[contact_id]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'saveFullContactChanges') {
		// save changes from $_GET[action] == 'getFullContact'
		$result = saveFullContact($_GET);
		if (PEAR::isError($result)) {
			// always bring this window to top onLoad
			bringWindowToTop();
			$response_message = $result;
			$pageBodyContent = '<input name="Previous" type="submit" class="bodySubmitButtons" value="Try Again" onClick="history.go(-1)">';
		} else {
			header("Location: ".$GLOBALS[baseUrl].$_SERVER[PHP_SELF]."?action=getFullContact&contact_id=".$_GET[contact_id]);;
			exit;
		}
	}
	if ($_GET[action] == 'confirmDelContact') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = getDelContactForm($_GET[contact_id], $_SERVER[PHP_SELF], 'GET');
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'deleteContact') {
		if (!is_array($_GET[contact_id])) {	// for deleting a single contact
			$result = delContact($_GET[contact_id]);
		} elseif (is_array($_GET[contact_id])) {	// for deleting multiple contacts
			foreach ($_GET[contact_id] as $contact_id) {
				$result = delContact($contact_id);
			}
		}
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	if ($_GET[action] == 'dupeContact') {
		$url = $base_url.'contactMgr.php?action=addNewContactStep3&contact_id='.$_GET[contact_id];
		closeChildLoadParent($url);
		exit;
	}
	
	######### MyCONTACTS #########
	
	if ($_GET[action] == 'addContactTo') {
		// get the form that presents the choice
		$result = getAddContactToForm($_SERVER[PHP_SELF], 'GET', $_GET);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'Add To My Contacts') {
		// add $_GET[contact_id] to MyContacts, if not already there
		if (!is_array($_GET[contact_id])) {	// for adding a single contact
			$result = addToMyContacts($_GET[contact_id], $_SESSION[userid]);
		} elseif (is_array($_GET[contact_id])) {	// for adding multiple contacts
			foreach ($_GET[contact_id] as $id) {
				$result = addToMyContacts($id, $_SESSION[userid]);
			}
		}
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			if ($_GET['reload'] == 1) {
				closeWindow();
				exit;
			} else {
				closeChildReloadParent();
				exit;
			}
		}
	}
	if ($_GET[action] == 'removeMyContact') {
		// remove $_GET[contact_id] from MyContacts
		$result = rmFromMyContacts($_GET[contact_id], $_SESSION[userid]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	
	########## MY LINKS ##############
	
	if ($_GET[action] == 'removeMyLink') {
		// remove $_GET[contact_id] from MyContacts
		$result = rmFromMyLinks($_GET[link_id], $_SESSION[userid]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	if ($_GET[action] == 'editMyLink') {
		$pageHead = 'Edit MyLink';
		// remove $_GET[contact_id] from MyContacts
		$result = getMyLinkForm($_SERVER[PHP_SELF], 'Save Changes', 'GET', $_GET[link_id]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'getNewMyLinkForm') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$pageHead = 'Add New Link to MyLinks';
		// get the blank myLink form
		$result = getMyLinkForm($_SERVER[PHP_SELF], 'Create Link', 'GET');
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'saveMyLinkChanges') {
		$result = updateMyLink($_GET, $_SESSION[userid]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	if ($_GET[action] == 'addNewMyLink') {
		$result = addMyLink($_GET, $_SESSION[userid]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	
	########## USER MGMT ###########
	if ($_GET[action] == 'getNewUserForm') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = getUserForm($_SERVER[PHP_SELF], 'Create User', 'GET');
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'getUsers') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = getUsersTbl();
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'getUser') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = getUserForm($_SERVER[PHP_SELF], 'Save Changes', 'GET', $_GET[user_id]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'addNewUser') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = addUser($_GET);
		if (PEAR::isError($result)) {
			$response_message = $result;
			$result = getUserForm($_SERVER[PHP_SELF], 'Create User', 'GET');
			if (PEAR::isError($result)) {
				$response_message = $result;
			} else {
				$pageBodyContent = $result;
			}
		} else {
			$url = $_SERVER[PHP_SELF].'?action=getUsers';
			loadUrl($url);
			exit;
		}
	}
	if ($_GET[action] == 'saveUserChanges') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = updateUser($_GET);
		if (PEAR::isError($result)) {
			$response_message = $result;
			$result = getUserForm($_SERVER[PHP_SELF], 'Save Changes', 'GET', $_GET[user_id]);
			if (PEAR::isError($result)) {
				$response_message = $result;
			} else {
				$pageBodyContent = $result;
			}
		} else {
			$url = $_SERVER[PHP_SELF].'?action=getUsers';
			loadUrl($url);
			exit;
		}
	}
	if ($_GET[action] == 'delUser') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = delUser($_GET[user_id]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$url = $_SERVER[PHP_SELF].'?action=getUsers';
			loadUrl($url);
			exit;
		}
	}
	########### My Lists Mgmt ##############
	
	if ($_GET[action] == 'Add To Above List') {
		if (!is_array($_GET[contact_id])) {	// for adding a single contact
			$result = addToMyList($_SESSION[userid], $_GET['list_id'], $_GET['contact_id']);
			$msg = 'Contact Added.';
		} elseif (is_array($_GET[contact_id])) {	// for adding multiple contacts
			foreach ($_GET[contact_id] as $id) {
				$result = addToMyList($_SESSION[userid], $_GET['list_id'], $id);
			}
			$msg = 'Contacts Added.';
		}
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			if ($_GET['reload'] == 1) {
				closeChildReloadParent();
				exit;
			} else {
				closeWindow();
				exit;
			}
		}
	}
	if ($_GET[action] == 'getNewMyListForm') {
		// always bring this window to top onLoad
		bringWindowToTop();
		$result = getMyListForm($_SERVER[PHP_SELF], 'GET', 'Create New List', $_SESSION[userid]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	if ($_GET[action] == 'createNewList') {
		$result = createNewList($_GET, $_SESSION[userid]);
		if (PEAR::isError($result)) {
			$response_message = $result;
			$pageBodyContent = getMyListForm($_SERVER[PHP_SELF], 'GET', 'Create New List', $_SESSION[userid]);
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	if ($_GET[action] == 'editMyList') {
		$myList = getRows($GLOBALS[dbMyListsTbl], $_GET[list_id], '', '');
		if (PEAR::isError($myList)) {
			$response_message = $myList;
		} else {
			$pageBodyContent = getMyListForm($_SERVER[PHP_SELF], 'GET', 'Save Changes', $_SESSION[userid], $myList[0]);
		}
	}
	if ($_GET[action] == 'updateList') {
		$result = updateList($_GET[list_id], $_GET[name], $_SESSION[userid]);
		if (PEAR::isError($result)) {
			$response_message = $result;
			$myList = getRows($GLOBALS[dbMyListsTbl], $_GET[list_id], '', '');
			if (PEAR::isError($myList)) {
				$response_message = $myList;
			} else {
				$pageBodyContent = getMyListForm($_SERVER[PHP_SELF], 'GET', 'Save Changes', $_SESSION[userid], $myList[0]);
			}
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	if ($_GET[action] == 'removeMyList') {
		// throw up a confirmation dialog.
		if ($_GET['Confirm'] == 'Delete') {
			// remove $_GET[list_id] from MyLists
			$result = rmFromMyLists($_GET[list_id], $_GET[del_archives], $_SESSION[userid]);
			if (PEAR::isError($result)) {
				$response_message = $result;
			} else {
				closeChildReloadParent();
				exit;
			}
		} else {
			$result = getConfirmListDel($_GET[list_id]);
			if (PEAR::isError($result)) {
				$response_message = $result;
			} else {
				$pageBodyContent = $result;
			}
		}
	}
	
	// for removing a contact from a list
	// mainly from full contact view - provides a form that displays only lists $_GET[contact_id]
	// currently belongs to, and provides a form for removing one of those lists at a time
	if ($_GET[action] == 'getDelContactFromList') {
		$form = getDelFromListForm($_GET[contact_id], $_SERVER[PHP_SELF], 'GET', 'Remove From Above List', 'delContactFromList');
		if (PEAR::isError($form)) {
			$response_message = $form;
		} else {
			$pageBodyContent = $form;
		}
	}
	
	// for removing one or more contacts from a list
	if ($_GET[action] == 'delContactFromList') {
		// remove $_GET[contact_id] from $_GET[list_id]
		if (!is_array($_GET[contact_id])) {	// for adding a single contact
			$result = rmContactFromList($_GET[contact_id], $_GET[list_id], $_SESSION[userid]);
		} elseif (is_array($_GET[contact_id])) {	// for adding multiple contacts
			foreach ($_GET[contact_id] as $id) {
				$result = rmContactFromList($id, $_GET[list_id], $_SESSION[userid]);
			}
		}
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			closeChildReloadParent();
			exit;
		}
	}
	
	// for jumping to a list from a contact's full record
	if ($_GET[action] == 'goToList') {
		closeChildLoadParent('index.php?action=editList&list_id='.$_GET[list_id]);
		exit;
	}
	
	############ Mass Mail Actions ###############
	// 2nd step in sending a new mailing - sending the emails
	if ($_POST[action] == 'sendMailStep2') {
		// include the PEAR Classes
		require_once('Mail.php');
		require_once('Mail/mime.php');
		// set the header
		$pageHead = 'Mailing Center';
		// unescape strings if needed
		$txt_content = unescapeStr($_POST['txt_content']);
		$html_content = unescapeStr($_POST['html_content']);
		// prepare the message headers
		$hdrs = getHeaders($_POST);
		// send the message out
		$result = sendMassMail($_POST['list_id'], $hdrs, $txt_content, $html_content, $_FILES, $_POST['attachMode'], $_POST['attachId']);
		// check for errors
		if (PEAR::isError($result)) {
			$response_message = $result;
			$pageHead = 'Mass Mail Utility';
			$pageSubHead = 'Define Mailing Parameters';
			$pageBodyContent = getNewMailingForm($_SERVER[PHP_SELF], 'POST', 'Send Message', $_POST);
		} else {
			// archive the mailing if needed
			if ($_POST[archive] == 'yes') {
				$arch_result = archiveMailing($_POST['list_id'], $hdrs, $html_content, $txt_content, $_SESSION[userid], $_FILES, $_POST['attachMode'], $_POST['attachId']);
				if (PEAR::isError($arch_result)) {
					$response_message = $arch_result;
					$pageBodyContent = 'Message Sent, but unable to archive mailing attributes.';
				} else {
					// close the 'please wait' window, load messages sent window in parent
					closeChildLoadParent('mailMgr.php?action=showSendMsgDone&mailing_id='.$arch_result);
					exit;
				}
			} else {
				// delete attachment if needed
				@unlink($GLOBALS[msgTempDir].$_FILES['attachment']['name']);
				@unlink($GLOBALS[msgTempDir].$_FILES['filename']);
				// close the 'please wait' window, load messages sent window in parent
				closeChildLoadParent('mailMgr.php?action=showSendMsgDone');
				exit;
			}
		}
	}
	// when we need to display a mass mailing summary table
	if ($_GET[action] == 'getMailDetails') {
		$pageHead = 'Mailing Details';
		$results = getMassMailDetails($_GET[mailing_id]);
		if (PEAR::isError($results)) {
			$response_message = $results;
		} else {
			$pageBodyContent = $results;
		}
	}
	// when a user downloads an attachment from a previous mailing
	if ($_GET[action] == 'getMsgAttch') {	// for retrieving attachments
		$result = getMsgAttch($_GET['attach_id']);
		if (PEAR::isError($result)) {
			$response_message = $result;
		}
	}
	// for confirming the deletion of a mailing archive
	if ($_GET[action] == 'confirmDelArchive') {
		$result = getConfirmMailDelForm($_SERVER[PHP_SELF], 'Delete', 'GET', $_GET[mailing_id]);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			$pageBodyContent = $result;
		}
	}
	// for deleting a mail archive after confirmation
	if ($_GET[action] == 'delMailArchive') {
		$result = delMailArchive($_GET['mailing_id']);
		if (PEAR::isError($result)) {
			$response_message = $result;
		} else {
			// close the 'please wait' window, load messages sent window in parent
			closeChildLoadParent('mailMgr.php?action=showMsgArchive');
			exit;
		}
	}
	
/*
+--------------------------------------+
| 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[popup_template]);
	$page->getTemplate();
	if (PEAR::isError($page)) {
		echo $page->getMessage();
		exit;
	}
	$page->setPgKey('{TITLE}', $pageTitle);
	$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();
	bringWindowToTop();
?>
Return current item: WebDex