acctfuncs: Fix some whitespace and formatting.

Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
Loui Chang 2010-02-21 08:59:24 -05:00
parent fc607aa9f7
commit 61d0358162

View file

@ -1,7 +1,7 @@
<?php <?php
# Display the standard Account form, pass in default values if any # Display the standard Account form, pass in default values if any
#
function display_account_form($UTYPE,$A,$U="",$T="",$S="", function display_account_form($UTYPE,$A,$U="",$T="",$S="",
$E="",$P="",$C="",$R="",$L="",$I="",$N="",$UID=0) { $E="",$P="",$C="",$R="",$L="",$I="",$N="",$UID=0) {
# UTYPE: what user type the form is being displayed for # UTYPE: what user type the form is being displayed for
@ -35,21 +35,20 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
print " name='U' value='".$U."'> (".__("required").")</td>"; print " name='U' value='".$U."'> (".__("required").")</td>";
print "</tr>\n"; print "</tr>\n";
# Only TUs or Devs can promote/demote/suspend a user
if ($UTYPE == "Trusted User" || $UTYPE == "Developer") { if ($UTYPE == "Trusted User" || $UTYPE == "Developer") {
# only TUs or Devs can promote/demote/suspend a user
#
print "<tr>"; print "<tr>";
print "<td align='left'>".__("Account Type").":</td>"; print "<td align='left'>".__("Account Type").":</td>";
print "<td align='left'><select name=T>\n"; print "<td align='left'><select name=T>\n";
print "<option value='1'"; print "<option value='1'";
$T == "User" ? print " selected>" : print ">"; $T == "User" ? print " selected>" : print ">";
print __("Normal user")."\n"; print __("Normal user")."\n";
print "<option value='2'"; print "<option value='2'";
$T == "Trusted User" ? print " selected>" : print ">"; $T == "Trusted User" ? print " selected>" : print ">";
print __("Trusted user")."\n"; print __("Trusted user")."\n";
# Only developers can make another account a developer
if ($UTYPE == "Developer") { if ($UTYPE == "Developer") {
# only developers can make another account a developer
#
print "<option value='3'"; print "<option value='3'";
$T == "Developer" ? print " selected>" : print ">"; $T == "Developer" ? print " selected>" : print ">";
print __("Developer")."\n"; print __("Developer")."\n";
@ -79,7 +78,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
print "<td align='left'><input type='password' size='30' maxlength='32'"; print "<td align='left'><input type='password' size='30' maxlength='32'";
print " name='P' value='".$P."'>"; print " name='P' value='".$P."'>";
if ($A != "UpdateAccount") { if ($A != "UpdateAccount") {
print " (".__("required").")"; print " (".__("required").")";
} }
print "</td></tr>\n"; print "</td></tr>\n";
@ -88,7 +87,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
print "<td align='left'><input type='password' size='30' maxlength='32'"; print "<td align='left'><input type='password' size='30' maxlength='32'";
print " name='C' value='".$C."'>"; print " name='C' value='".$C."'>";
if ($A != "UpdateAccount") { if ($A != "UpdateAccount") {
print " (".__("required").")"; print " (".__("required").")";
} }
print "</td></tr>\n"; print "</td></tr>\n";
@ -136,7 +135,7 @@ function display_account_form($UTYPE,$A,$U="",$T="",$S="",
if ($A == "UpdateAccount") { if ($A == "UpdateAccount") {
print "<input type='submit' class='button'"; print "<input type='submit' class='button'";
print " value='".__("Update")."'> &nbsp; "; print " value='".__("Update")."'> &nbsp; ";
} else { } else {
print "<input type='submit' class='button'"; print "<input type='submit' class='button'";
print " value='".__("Create")."'> &nbsp; "; print " value='".__("Create")."'> &nbsp; ";
@ -172,20 +171,21 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
# UID: database Users.ID value # UID: database Users.ID value
# error check and process request for a new/modified account # error check and process request for a new/modified account
#
global $SUPPORTED_LANGS; global $SUPPORTED_LANGS;
if(isset($_COOKIE['AURSID'])) if(isset($_COOKIE['AURSID'])) {
$editor_user = uid_from_sid($_COOKIE['AURSID']); $editor_user = uid_from_sid($_COOKIE['AURSID']);
else }
else {
$editor_user = null; $editor_user = null;
}
$dbh = db_connect(); $dbh = db_connect();
$error = ""; $error = "";
if (empty($E) || empty($U)) { if (empty($E) || empty($U)) {
$error = __("Missing a required field."); $error = __("Missing a required field.");
} }
if ($TYPE == "new") { if ($TYPE == "new") {
# they need password fields for this type of action # they need password fields for this type of action
# #
@ -200,10 +200,10 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
if (!$error && !valid_username($U) && !user_is_privileged($editor_user)) if (!$error && !valid_username($U) && !user_is_privileged($editor_user))
$error = __("The username is invalid.") . "<ul>\n" $error = __("The username is invalid.") . "<ul>\n"
."<li>" . __("It must be between %s and %s characters long", ."<li>" . __("It must be between %s and %s characters long",
USERNAME_MIN_LEN, USERNAME_MAX_LEN ) USERNAME_MIN_LEN, USERNAME_MAX_LEN )
. "</li>" . "</li>"
. "<li>" . __("Start and end with a letter or number") . "</li>" . "<li>" . __("Start and end with a letter or number") . "</li>"
. "<li>" . __("Can contain only one period, underscore or hyphen.") . "<li>" . __("Can contain only one period, underscore or hyphen.")
. "</li>\n</ul>"; . "</li>\n</ul>";
@ -211,8 +211,7 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
$error = __("Password fields do not match."); $error = __("Password fields do not match.");
} }
if (!$error && $P != '' && !good_passwd($P)) if (!$error && $P != '' && !good_passwd($P))
$error = $error = __("Your password must be at least %s characters.",PASSWD_MIN_LEN);
__("Your password must be at least %s characters.",PASSWD_MIN_LEN);
if (!$error && !valid_email($E)) { if (!$error && !valid_email($E)) {
$error = __("The email address is invalid."); $error = __("The email address is invalid.");
@ -266,9 +265,8 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
} else { } else {
if ($TYPE == "new") { if ($TYPE == "new") {
# no errors, go ahead and create the unprivileged user # no errors, go ahead and create the unprivileged user
#
# md5hash the password
#md5hash the password
$P = md5($P); $P = md5($P);
$q = "INSERT INTO Users (AccountTypeID, Suspended, Username, Email, "; $q = "INSERT INTO Users (AccountTypeID, Suspended, Username, Email, ";
$q.= "Passwd, RealName, LangPreference, IRCNick, NewPkgNotify) "; $q.= "Passwd, RealName, LangPreference, IRCNick, NewPkgNotify) ";
@ -299,9 +297,8 @@ function process_account_form($UTYPE,$TYPE,$A,$U="",$T="",$S="",$E="",
} else { } else {
# no errors, go ahead and modify the user account # no errors, go ahead and modify the user account
#
#md5 hash the password # md5 hash the password
$q = "UPDATE Users SET "; $q = "UPDATE Users SET ";
$q.= "Username = '".mysql_real_escape_string($U)."'"; $q.= "Username = '".mysql_real_escape_string($U)."'";
if ($T) { if ($T) {
@ -545,8 +542,7 @@ function search_results_page($UTYPE,$O=0,$SB="",$U="",$T="",
# Display non-editable account info # Display non-editable account info
# #
function display_account_info($U="",$T="", function display_account_info($U="", $T="", $E="", $R="", $I="") {
$E="",$R="",$I="") {
# U: value to display for username # U: value to display for username
# T: value to display for account type # T: value to display for account type
# E: value to display for email address # E: value to display for email address
@ -565,7 +561,7 @@ function display_account_info($U="",$T="",
print " <td align='left'>".__("Username").":</td>\n"; print " <td align='left'>".__("Username").":</td>\n";
print " <td align='left'>".$U."</td>\n"; print " <td align='left'>".$U."</td>\n";
print " </tr>\n"; print " </tr>\n";
print " <tr>\n"; print " <tr>\n";
print " <td align='left'>".__("Account Type").":</td>\n"; print " <td align='left'>".__("Account Type").":</td>\n";
print " <td align='left'>"; print " <td align='left'>";
@ -573,11 +569,11 @@ function display_account_info($U="",$T="",
print __("User"); print __("User");
} elseif ($T == "Trusted User") { } elseif ($T == "Trusted User") {
print __("Trusted User"); print __("Trusted User");
} elseif ($T == "Developer") { } elseif ($T == "Developer") {
print __("Developer"); print __("Developer");
} }
print "</td>\n"; print "</td>\n";
print " <tr>\n"; print " <tr>\n";
print " <td align='left'>".__("Email Address").":</td>\n"; print " <td align='left'>".__("Email Address").":</td>\n";
print " <td align='left'><a href='mailto:".$E."'>".$E."</a></td>\n"; print " <td align='left'><a href='mailto:".$E."'>".$E."</a></td>\n";
@ -613,7 +609,6 @@ function try_login() {
if ( isset($_REQUEST['user']) || isset($_REQUEST['passwd']) ) { if ( isset($_REQUEST['user']) || isset($_REQUEST['passwd']) ) {
$userID = valid_user($_REQUEST['user']); $userID = valid_user($_REQUEST['user']);
if ( user_suspended( $userID ) ) { if ( user_suspended( $userID ) ) {
@ -641,7 +636,7 @@ function try_login() {
} }
$num_tries++; $num_tries++;
} }
if ($logged_in) { if ($logged_in) {
# set our SID cookie # set our SID cookie
@ -685,16 +680,14 @@ function try_login() {
*/ */
function valid_username( $user ) function valid_username( $user )
{ {
#Is it non-empty?
if (!empty($user)) { if (!empty($user)) {
#Is username at not too short or too long? #Is username at not too short or too long?
if ( strlen($user) >= USERNAME_MIN_LEN && if ( strlen($user) >= USERNAME_MIN_LEN &&
strlen($user) <= USERNAME_MAX_LEN ) { strlen($user) <= USERNAME_MAX_LEN ) {
$user = strtolower($user); $user = strtolower($user);
#Does username: # Does username:
# start and end with a letter or number # start and end with a letter or number
# contain only letters and numbers, # contain only letters and numbers,
# and at most has one dash, period, or underscore # and at most has one dash, period, or underscore
@ -704,7 +697,7 @@ function valid_username( $user )
} }
} }
} }
return; return;
} }
@ -721,7 +714,8 @@ function valid_user( $user )
. mysql_real_escape_string($user). "'"; . mysql_real_escape_string($user). "'";
$result = mysql_fetch_row(db_query($q, $dbh)); $result = mysql_fetch_row(db_query($q, $dbh));
#Is the username in the database?
# Is the username in the database?
if ($result[0]) { if ($result[0]) {
return $result[0]; return $result[0];
} }
@ -750,7 +744,7 @@ function valid_passwd( $userID, $passwd )
$result = mysql_fetch_row(db_query($q, $dbh)); $result = mysql_fetch_row(db_query($q, $dbh));
if ($result[0]) { if ($result[0]) {
#is it the right password? # Is it the right password?
return true; return true;
} }
} }
@ -792,8 +786,9 @@ function user_is_privileged( $id )
$dbh = db_connect(); $dbh = db_connect();
$q = "SELECT AccountTypeID FROM Users WHERE ID = '$id'"; $q = "SELECT AccountTypeID FROM Users WHERE ID = '$id'";
$result = mysql_fetch_row(db_query($q, $dbh)); $result = mysql_fetch_row(db_query($q, $dbh));
if( $result[0] > 1) if( $result[0] > 1) {
return $result[0]; return $result[0];
}
return 0; return 0;
} }
@ -802,10 +797,11 @@ function user_is_privileged( $id )
function clear_expired_sessions($dbh = null) { function clear_expired_sessions($dbh = null) {
global $LOGIN_TIMEOUT; global $LOGIN_TIMEOUT;
if (empty($dbh)) if (empty($dbh)) {
$dbh = db_connect(); $dbh = db_connect();
}
$q = "DELETE FROM Sessions WHERE LastUpdateTS < (UNIX_TIMESTAMP() - $LOGIN_TIMEOUT)"; $q = "DELETE FROM Sessions WHERE LastUpdateTS < (UNIX_TIMESTAMP() - $LOGIN_TIMEOUT)";
db_query($q, $dbh); db_query($q, $dbh);
return; return;