appdb/. preferences.php

WineHQ wineowner at wine.codeweavers.com
Fri Jul 7 13:18:09 CDT 2006


ChangeSet ID:	26343
CVSROOT:	/opt/cvs-commit
Module name:	appdb
Changes by:	wineowner at winehq.org	2006/07/07 13:18:09

Modified files:
	.              : preferences.php 

Log message:
	Chris Morgan <cmorgan at alum.wpi.edu>
	Stop using global variables.  Reorder functions so we don't have functions in the middle of
	executing code.  Rename a couple of variables to match our current naming convention

Patch: http://cvs.winehq.org/patch.py?id=26343

Old revision  New revision  Changes     Path
 1.31          1.32          +46 -49     appdb/preferences.php

Index: appdb/preferences.php
diff -u -p appdb/preferences.php:1.31 appdb/preferences.php:1.32
--- appdb/preferences.php:1.31	7 Jul 2006 18:18: 9 -0000
+++ appdb/preferences.php	7 Jul 2006 18:18: 9 -0000
@@ -25,48 +25,8 @@
 include("path.php");
 include(BASE."include/incl.php");
 
-$aClean = array(); //array of filtered user input
-
-$aClean['iUserId'] = makeSafe($_REQUEST['iUserId']);
-$aClean['iLimit'] = makeSafe($_REQUEST['iLimit']);
-$aClean['sOrderBy'] = makeSafe($_REQUEST['sOrderBy']);
-$aClean['sUserPassword'] = makeSafe($_REQUEST['sUserPassword']);
-$aClean['sUserPassword2'] = makeSafe($_REQUEST['sUserPassword2']);
-$aClean['sUserEmail'] = makeSafe($_REQUEST['sUserEmail']);
-$aClean['sUserRealname'] = makeSafe($_REQUEST['sUserRealname']);
-$aClean['sWineRelease'] = makeSafe($_REQUEST['sWineRelease']);
-$aClean['sHasAdmin'] = makeSafe($_POST['sHasAdmin']); 
-
-/* filter all of the preferences */
-while(list($key, $value) = each($_REQUEST))
+function build_prefs_list($oUser)
 {
-    if(ereg("^pref_(.+)$", $key, $arr))
-        $aClean[$key] = makeSafe($value);
-}
-
-
-
-
-if(!$_SESSION['current']->isLoggedIn())
-    util_show_error_page_and_exit("You must be logged in to edit preferences");
-
-// we come from the administration to edit an user
-if($_SESSION['current']->hasPriv("admin") && 
-   is_numeric($aClean['iUserId']) &&
-   is_numeric($aClean['iLimit']) &&
-   in_array($aClean['sOrderBy'],array("email","realname","created"))
-) 
-{
-    $oUser = new User($aClean['iUserId']);
-} else
-{
-    $oUser = &$_SESSION['current'];
-}
-
-
-function build_prefs_list()
-{
-    global $oUser;
     $hResult = query_parameters("SELECT * FROM prefs_list ORDER BY id");
     while($hResult && $r = mysql_fetch_object($hResult))
     {
@@ -93,10 +53,8 @@ function build_prefs_list()
     }
 }
 
-function show_user_fields()
+function show_user_fields($oUser)
 {
-    global $oUser;
-
     $sUserRealname = $oUser->sRealname;
     $sUserEmail = $oUser->sEmail;
     $sWineRelease = $oUser->sWineRelease;
@@ -112,15 +70,54 @@ function show_user_fields()
     echo "</td></tr>";
 }
 
+
+$aClean = array(); //array of filtered user input
+
+$aClean['iUserId'] = makeSafe($_REQUEST['iUserId']);
+$aClean['iLimit'] = makeSafe($_REQUEST['iLimit']);
+$aClean['sOrderBy'] = makeSafe($_REQUEST['sOrderBy']);
+$aClean['sUserPassword'] = makeSafe($_REQUEST['sUserPassword']);
+$aClean['sUserPassword2'] = makeSafe($_REQUEST['sUserPassword2']);
+$aClean['sUserEmail'] = makeSafe($_REQUEST['sUserEmail']);
+$aClean['sUserRealname'] = makeSafe($_REQUEST['sUserRealname']);
+$aClean['sWineRelease'] = makeSafe($_REQUEST['sWineRelease']);
+$aClean['sHasAdmin'] = makeSafe($_POST['sHasAdmin']); 
+
+/* filter all of the preferences */
+while(list($sKey, $sValue) = each($_REQUEST))
+{
+    if(ereg("^pref_(.+)$", $sKey, $arr))
+        $aClean[$sKey] = makeSafe($sValue);
+}
+
+
+
+
+if(!$_SESSION['current']->isLoggedIn())
+    util_show_error_page_and_exit("You must be logged in to edit preferences");
+
+// we come from the administration to edit an user
+if($_SESSION['current']->hasPriv("admin") && 
+   is_numeric($aClean['iUserId']) &&
+   is_numeric($aClean['iLimit']) &&
+   in_array($aClean['sOrderBy'],array("email","realname","created"))
+) 
+{
+    $oUser = new User($aClean['iUserId']);
+} else
+{
+    $oUser = &$_SESSION['current'];
+}
+
 if($_POST)
 {   
-    while(list($key, $value) = each($aClean))
+    while(list($sKey, $sValue) = each($aClean))
     {
         /* if a parameter lacks 'pref_' at its head it isn't a */
         /* preference so skip over processing it */
-        if(!ereg("^pref_(.+)$", $key, $arr))
+        if(!ereg("^pref_(.+)$", $sKey, $arr))
             continue;
-        $oUser->setPref($arr[1], $value);
+        $oUser->setPref($arr[1], $sValue);
     }
     
     /* make sure the user enters the same password twice */
@@ -180,10 +177,10 @@ if($oUser->iUserId == $aClean['iUserId']
 echo html_frame_start("Preferences for ".$oUser->sRealname, "80%");
 echo html_table_begin("width='100%' border=0 align=left cellspacing=0 class='box-body'");
 
-show_user_fields();
+show_user_fields($oUser);
 
 // if we don't manage another user
-if($oUser->iUserId != $aClean['iUserId']) build_prefs_list();
+if($oUser->iUserId != $aClean['iUserId']) build_prefs_list($oUser);
 
 echo html_table_end();
 echo html_frame_end();



More information about the wine-cvs mailing list