From: <ope...@li...> - 2002-06-28 02:11:46
|
Update of /cvsroot/openposs/Server In directory usw-pr-cvs1:/tmp/cvs-serv6407 Modified Files: index.php Log Message: Made major style changes. Changed from cookie based to session based. Adhered to PHP global variables Index: index.php =================================================================== RCS file: /cvsroot/openposs/Server/index.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** index.php 27 Jun 2002 01:12:39 -0000 1.6 --- index.php 28 Jun 2002 02:11:44 -0000 1.7 *************** *** 1,204 **** ! <?php ! ! /****************************************************************************** ! * * ! * File Name: index.php * ! * * ! * Created : Apr, 21 2001 * ! * * ! * Purpose : Provide the initial point of contact to the openPOS server. * ! * * ! *----------------------------------------------------------------------------* ! * Change Log * ! *----------------------------------------------------------------------------* ! * Date | Description * ! * -------------+------------------------------------------------------------ * ! * Apr 6, 2002 | Moved the database code into database.php * ! * -------------+------------------------------------------------------------ * ! * Apr 6, 2002 | Initial Coding. * ! ******************************************************************************/ ! ! /****************************************************************************** ! * System Includes * ! ******************************************************************************/ ! include_once("database.php"); ! ! /****************************************************************************** ! * Function: DisplayMainMenu() * ! * -------------------------------------------------------------------------- * ! * This function will display the main menu when the user is accessing the * ! * system via a web browser. * ! * * ! * Returned Values * ! * HTML Page text to return to the client. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function DisplayMainMenu() { ! GLOBAL $UserName; ! $Output = Theme_Open_Page(_OPENPOSMAINTITLE); ! $Output .= Theme_Open_Table("99%"); ! $Output .= Theme_Open_Row(); ! $Output .= Theme_Open_Data_Cell("Right", "15%"); ! if (isset($UserName)) { ! $Output .= $UserName." Logged In<br>"; ! } else { ! $Output .= "Not Logged In<br>"; ! } ! $Output .= "<br><br><B>" . _OPENPOSNAVTITLE . "</B><br>"; ! if ( strcmp($SystemConfig['modUserLogin'], "On")) { ! if (isset($UserName)) { ! $Output .= Theme_Add_Link("/Server/?action=logout", "Logout") . "<br>"; ! } else { ! $Output .= Theme_Add_Link("/Server/?action=login", "Login") . "<br>"; ! } ! } ! $Output .= Theme_Add_Link("/Server/?action=admin", _OPENPOSADMINTITLE ); ! $Output .= Theme_Close_Data_Cell().Theme_Open_Data_Cell(); ! $Output .= Theme_Close_Data_Cell(); ! $Output .= Theme_Close_Row(); ! $Output .= Theme_Close_Table(); ! $Output .= Theme_Close_Page(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: DisplayAdminMenu() * ! * -------------------------------------------------------------------------- * ! * This function will display the administration menu when the user is * ! * accessing the system via a web browser. * ! * * ! * Returned Values * ! * HTML Page text to return to the client. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function DisplayAdminMenu() { ! $Output = Theme_Open_Page(_OPENPOSADMINTITLE); ! $Output .= Theme_Close_Page(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: DisplayError() * ! * -------------------------------------------------------------------------- * ! * This function will display the error messages to the user. * ! * * ! * Returned Values * ! * HTML Page text to return to the client. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function DisplayError() { ! $Output = Theme_Open_Page( _OPENPOSERRORTITLE ); ! $Output .= "<DIV ALIGN=\"CENTER\"><H3>ERROR: Incorrect Parameters sent to the server. Please contact your support section.</H3></DIV>"; ! $Output .= Theme_Close_Page(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: ProcessLoginRequest() * ! * -------------------------------------------------------------------------- * ! * This function will validate user, and then set cookie if user is valid. * ! * * ! * Returned Values * ! * None. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function ProcessLoginRequest() { ! GLOBAL $Action, $UserName, $Password; ! // Validate the password against the database, and if all is well ! // we will create a cookie, and return to the main menu. ! if (Validate_Password($UserName, $Password) == 1) { ! setcookie("openPOSAuthTok", $UserName, time()+3600); ! } ! header("HTTP/1.0 303 See Other"); ! header("Location: /Server/"); ! return; ! } ! ! /****************************************************************************** ! * Function: ProcessLogoutRequest() * ! * -------------------------------------------------------------------------- * ! * This function will destroy the users session, logging them out * ! * * ! * Returned Values * ! * None. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function ProcessLogoutRequest() ! { ! GLOBAL $Action, $UserName; ! if (isset($UserName)) { ! setcookie("openPOSAuthTok", $UserName, time()-3600); ! header("HTTP/1.0 303 See Other"); ! header("Location: /Server/"); ! unset($UserName); ! } ! return; ! } ! ! /*End Functions ! *******************************************************************************/ ! ! global $HTMLOutput, $OutputLang, $Action, $OutputTheme, $SystemConfig; ! global $UserName, $Password; ! if (!DBInit()) { ! die("Unable to connect to the database."); ! } ! $OutputLang=$HTTP_GET_VARS["lang"]; ! $Action=$HTTP_GET_VARS["action"]; ! $OutputTheme=$HTTP_GET_VARS["theme"]; ! if (!isset($Action)) { ! $Action="none"; ! } ! if (!isset($OutputLang)) { ! $OutputLang="eng"; ! } ! if (!isset($OutputTheme)) { ! $OutputTheme="Default"; ! } ! if (isset($openPOSAuthTok)) { ! $UserName = $openPOSAuthTok; ! } ! include_once ("theme/$OutputTheme/theme.php"); ! include_once ("language/$OutputLang/global.php"); ! switch ($Action) { ! case "login": ! $HTMLOutput = Theme_Login_Screen(); ! break; ! case "submitlogin": ! $UserName=$HTTP_GET_VARS["username"]; ! $Password=$HTTP_GET_VARS["password"]; ! ProcessLoginRequest(); ! break; ! case "logout": ! ProcessLogoutRequest(); ! break; ! case "none": ! $HTMLOutput = DisplayMainMenu(); ! break; ! case "admin": ! $HTMLOutput = DisplayAdminMenu(); ! break; ! default: ! $HTMLOutput = DisplayError(); ! break; ! } ! ! if (!DBClose()) { ! die("Unable to disconnect from the database."); ! } ! ! if (isset($HTMLOutput)) { ! echo $HTMLOutput; ! } ! ! ?> --- 1,294 ---- ! <?php ! ! /****************************************************************************** ! * * ! * File Name: index.php * ! * * ! * Created : Apr, 21 2001 * ! * * ! * Purpose : Provide the initial point of contact to the openPOS server. * ! * * ! *----------------------------------------------------------------------------* ! * Change Log * ! *----------------------------------------------------------------------------* ! * Date | Description * ! * -------------+------------------------------------------------------------ * ! * Apr 6, 2002 | Moved the database code into database.php * ! * -------------+------------------------------------------------------------ * ! * Apr 6, 2002 | Initial Coding. * ! ******************************************************************************/ ! ! /****************************************************************************** ! * Begin Session * ! ******************************************************************************/ ! session_start(); ! ! if(isset($HTTP_GET_VARS["action"])) ! { ! $HTTP_SESSION_VARS["action"] = $HTTP_GET_VARS["action"]; ! } ! ! /****************************************************************************** ! * System Includes * ! ******************************************************************************/ ! include_once("database.php"); ! include_once("./vars.inc"); ! ! /****************************************************************************** ! * Function: DisplayMainMenu() * ! * -------------------------------------------------------------------------- * ! * This function will display the main menu when the user is accessing the * ! * system via a web browser. * ! * * ! * Returned Values * ! * HTML Page text to return to the client. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function DisplayMainMenu() { ! GLOBAL $HTTP_SESSION_VARS,$CONFIG_VARS; ! ! ! $Output = Theme_Menu_Open($CONFIG_VARS["MenuWidth"],_OPENPOSNAVTITLE); ! ! if (isset($HTTP_SESSION_VARS["openPOSAuthTok"])) ! { ! $Output .= $HTTP_SESSION_VARS["openPOSAuthTok"]." Logged In<p>"; ! } ! else ! { ! $Output .= "Not Logged In<p>"; ! } ! ! $menuArray = GetMenuEntries(); ! ! $Output .= "\n"; ! ! foreach($menuArray as $tmp) ! { ! $Output .= "<a class=\"menu\" href=\"/module/$tmp/module.php\">$tmp</a><br>\n"; ! } ! ! if($HTTP_SESSION_VARS["openPOSAuthRights"] == "SuperUser") ! { ! $Output .= Theme_Add_Menu_Link("./?action=admin", _OPENPOSADMINTITLE) . "<BR>"; ! } ! ! if ( strcmp($SystemConfig['modUserLogin'], "On")) ! { ! if (isset($HTTP_SESSION_VARS["openPOSAuthTok"])) ! { ! $Output .= Theme_Add_Menu_Link("./?action=logout", "Logout") . "<br>"; ! } ! else ! { ! $Output .= Theme_Add_Menu_Link("./?action=login", "Login") . "<br>"; ! } ! } ! $Output .= "\n<BR>"; ! $Output .= Theme_Menu_Close(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: GetMenuEntries() * ! * -------------------------------------------------------------------------- * ! * This function will access the db, and get all activem, showable menu * ! * menu entries. * ! * * ! * Returned Values * ! * $menuEntries of type Array * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function GetMenuEntries() ! { ! $query = "SELECT * FROM modules WHERE status='A' AND menu='Y'"; ! $result = DB_Query($query); ! $menuEntires = DB_Fetch_Data_Array($result); ! return $menuEntires; ! } ! ! /****************************************************************************** ! * Function: DisplayAdminMenu() * ! * -------------------------------------------------------------------------- * ! * This function will display the administration menu when the user is * ! * accessing the system via a web browser. * ! * * ! * Returned Values * ! * HTML Page text to return to the client. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function DisplayAdminMenu() { ! $Output = Theme_Open_Page(_OPENPOSADMINTITLE); ! $Output .= Theme_Close_Page(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: DisplayError() * ! * -------------------------------------------------------------------------- * ! * This function will display the error messages to the user. * ! * * ! * Returned Values * ! * HTML Page text to return to the client. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function DisplayError() ! { ! $Output = Theme_Open_Page( _OPENPOSERRORTITLE ); ! $Output .= "<DIV ALIGN=\"CENTER\"><H3>ERROR: Incorrect Parameters sent to the server. Please contact your support section.</H3></DIV>"; ! $Output .= Theme_Close_Page(); ! return $Output; ! } ! ! /****************************************************************************** ! * Function: ProcessLoginRequest() * ! * -------------------------------------------------------------------------- * ! * This function will validate user, and then set cookie if user is valid. * ! * * ! * Returned Values * ! * None. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function ProcessLoginRequest($UserName,$Password) { ! GLOBAL $HTTP_SESSION_VARS; ! $rights = Validate_Password($UserName, $Password); ! //echo "$rights"; ! if ($rights != FALSE) ! { ! $HTTP_SESSION_VARS["openPOSAuthTok"] = $UserName; ! //session_register("openPOSAuthTok"); ! ! //echo "<BR>$UserName = ".$HTTP_SESSION_VARS["openPOSAuthTok"]."<BR>"; ! ! $HTTP_SESSION_VARS["openPOSAuthRights"] = $rights; ! //session_register("openPOSAuthRights"); ! ! $HTTP_SESSION_VARS["action"] = "none"; ! //session_register("action"); ! ! $HTTP_SESSION_VARS["OutputLang"] = NULL; ! //session_register("OutputLang"); ! ! $HTTP_SESSION_VARS["OutputTheme"] = "Default"; ! //session_register("OutputTheme"); ! ! } ! else ! { ! //Not a valid login. figure out a way to pass an error message ! } ! ! header("HTTP/1.0 303 See Other"); ! header("Location: ./"); ! return; ! } ! ! /****************************************************************************** ! * Function: ProcessLogoutRequest() * ! * -------------------------------------------------------------------------- * ! * This function will destroy the users session, logging them out * ! * * ! * Returned Values * ! * None. * ! * * ! * Input Values * ! * None. * ! ******************************************************************************/ ! function ProcessLogoutRequest() ! { ! GLOBAL $Action, $UserName; ! if (isset($UserName)) ! { ! session_unset(); ! session_destroy(); ! header("HTTP/1.0 303 See Other"); ! header("Location: ./"); ! ! } ! return; ! } ! ! /*End Functions ! *******************************************************************************/ ! ! global $HTMLOutput, $OutputLang, $Action, $OutputTheme, $SystemConfig; ! global $UserName, $Password; ! if (!DBInit()) { ! die("Unable to connect to the database."); ! } ! /* ! $OutputLang=$HTTP_SESSION_VARS["lang"]; ! $Action=$HTTP_SESSION_VARS["action"]; ! $OutputTheme=$HTTP_SESSION_VARS["theme"]; ! */ ! ! if (!isset($HTTP_SESSION_VARS["action"])) { ! $HTTP_SESSION_VARS["action"] = "none"; ! } ! if (!isset($HTTP_SESSION_VARS["OutputLang"])) { ! $HTTP_SESSION_VARS["OutputLang"] = "eng"; ! } ! if (!isset($HTTP_SESSION_VARS["OutputTheme"])) { ! $HTTP_SESSION_VARS["OutputTheme"] = "Default"; ! } ! //echo $HTTP_SESSION_VARS["openPOSAuthTok"]."<BR>"; ! if (isset($HTTP_SESSION_VARS["openPOSAuthTok"])) { ! $UserName = $HTTP_SESSION_VARS["openPOSAuthTok"]; ! } ! //echo $HTTP_SESSION_VARS["openPOSAuthTok"]."<BR>"; ! ! $themeFile = "theme/".$HTTP_SESSION_VARS["OutputTheme"]."/theme.php"; ! include_once ($themeFile); ! $langFile = "language/".$HTTP_SESSION_VARS["OutputLang"]."/global.php"; ! include_once ($langFile); ! ! ! switch ($HTTP_SESSION_VARS["action"]) ! { ! case "login": ! $HTTP_SESSION_VARS["action"] = "submitlogin"; ! $HTMLOutput = Theme_Login_Screen(); ! break; ! case "submitlogin": ! $UserName=$HTTP_GET_VARS["username"]; ! $Password=$HTTP_GET_VARS["password"]; ! $HTTP_SESSION_VARS["action"] = "none"; ! ProcessLoginRequest($UserName,$Password); ! break; ! case "logout": ! ProcessLogoutRequest(); ! $HTTP_SESSION_VARS["action"] = NULL; ! break; ! case "none": ! $HTMLOutput = Theme_Open_Page(_OPENPOSMAINTITLE); ! $HTMLOutput .= DisplayMainMenu(); ! $HTMLOutput .= Theme_Close_Page(); ! ! break; ! case "admin": ! $HTMLOutput = DisplayAdminMenu(); ! break; ! default: ! $HTMLOutput = DisplayError(); ! break; ! } ! ! if (!DBClose()) { ! die("Unable to disconnect from the database."); ! } ! ! if (isset($HTMLOutput)) { ! echo $HTMLOutput; ! } ! ! ?> |