From: Chris S. <san...@us...> - 2005-07-08 16:36:34
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13324/scripts Modified Files: stackDatabase.php stackUser.php Log Message: Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** stackDatabase.php 4 Jul 2005 16:24:11 -0000 1.28 --- stackDatabase.php 8 Jul 2005 16:36:10 -0000 1.29 *************** *** 1147,1150 **** --- 1147,1176 ---- * Takes the itemSource and returns a PHP array containing the item. * + * @param string $username The username of the student. + * @return array $user Full information about the user themselves. + */ + function stack_db_user_get_ID($userID) { + global $stackUser; + + $user = FALSE; + $stackUserKeys = array_keys($stackUser); + + $query = "SELECT * FROM stackUser WHERE id = $userID"; + + $result = stack_db_query($query); + + if(0 != mysql_num_rows($result)) { + $row = mysql_fetch_row($result); + foreach ($row as $key => $val) { + $user[$stackUserKeys[$key]] = stripslashes($val); + } + } + + return $user; + } + + /** + * Takes the itemSource and returns a PHP array containing the item. + * * @param array $user The array containing the user. * @return number $user_id The ID of the new user in the DB. Index: stackUser.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackUser.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** stackUser.php 20 Jun 2005 15:42:55 -0000 1.9 --- stackUser.php 8 Jul 2005 16:36:11 -0000 1.10 *************** *** 107,112 **** $_SESSION['user'] = $user; } else { ! $errors['user']['password'] = '<font color="red">'.get_string('IncorrectAdminPsd','stack','').'</font>'; ! $user = stack_user_guest(); } --- 107,113 ---- $_SESSION['user'] = $user; } else { ! $errors['user'] = '<font color="red">'.get_string('IncorrectPassword','stack','').'</font>'; ! $user['loggedin'] = FALSE; ! $user['username'] = $username; } *************** *** 117,121 **** $_SESSION['user'] = $user; } else { ! $errors['user']['password'] = '<font color="red">'.get_string('IncorrectPassword','stack','').'</font>'; $user['loggedin'] = FALSE; $user['username'] = $username; --- 118,122 ---- $_SESSION['user'] = $user; } else { ! $errors['user'] = '<font color="red">'.get_string('IncorrectPassword','stack','').'</font>'; $user['loggedin'] = FALSE; $user['username'] = $username; *************** *** 124,128 **** } else { ! $errors['user']['username'] = '<font color="red">'.get_string('UnknownUserName','stack','').'</font>'; $user = stack_user_blank(); $user['loggedin'] = FALSE; --- 125,129 ---- } else { ! $errors['user'] = '<font color="red">'.get_string('UnknownUserName','stack','').'</font>'; $user = stack_user_blank(); $user['loggedin'] = FALSE; *************** *** 135,138 **** --- 136,178 ---- /** + * Update the information of a particular user. + * + * @param array $errors The array to hold any errors + * @return array $user The user's information. + */ + function stack_user_updateinfo(&$errors) { + + $user = ''; + if (array_key_exists('user',$_POST)) { + // We have an incoming form with new user information + // Get default info. + $userID = $_POST['user']['id']; + $user = stack_db_user_get_ID($userID); + + // Merge posted info with new infor + foreach ($_POST['user'] as $key => $val) { + $user[$key] = $val; + } + stack_user_information_validate($user,$errors); + + if (!nsf($errors,'user')) { + if ('' != trim($user['password'])) { + $user = stack_db_user_update($user); + } else { + $errors['user']['password'] = '<font color="red">Password must be non-empty.</font>'; + $error = $errors['user']['password']; + $action = 'error'; + } + } + + $user['id'] = $userID; + } + + return $user; + + } + + + /** * Validates the information supplied by a user * *************** *** 184,188 **** * @return void */ ! function stack_user_edit_form($user,$errors=array()) { $err = ''; --- 224,228 ---- * @return void */ ! function stack_user_edit_form($user,$errors=array(),$admin=FALSE) { $err = ''; *************** *** 195,200 **** echo '<input type="hidden" name="user[id]" value="'.sf($user,'id').'" />'; ! echo '<tr><td>'.get_string('USR_NewPassword','stack','').'</td><td><input type="password" name="user[password1]" size="15" value="" alt="Password" /></td></tr>'; ! echo '<tr><td>'.get_string('USR_ConfirmPsswd','stack','').'</td><td><input type="password" name="user[password2]" size="15" value="" alt="Confirm Password" /></td></tr>'; echo '<tr><td>'.get_string('USR_FirstName','stack','').'</td><td><input type="text" name="user[firstname]" size="25" value="'.sf($user,'firstname').'" alt="First name" /></td><td>'.nsf($err,'firstname').'</td></tr>'; echo '<tr><td>'.get_string('USR_LastName','stack','').'</td><td><input type="text" name="user[lastname]" size="25" value="'.sf($user,'lastname').'" alt="Last name" /></td><td>'.nsf($err,'lastname').'</td></tr>'; --- 235,251 ---- echo '<input type="hidden" name="user[id]" value="'.sf($user,'id').'" />'; ! if ($admin) { ! echo '<tr><td>ID</td><td>'.sf($user,'id').'</td></tr>'; ! } ! ! if ($admin) { ! $pswd = $user['password']; ! echo '<tr><td>'.get_string('USR_NewPassword','stack','').'</td><td><input type="text" name="user[password1]" size="15" value="'.$pswd.'" alt="Password" /></td></tr>'; ! echo '<tr><td>'.get_string('USR_ConfirmPsswd','stack','').'</td><td><input type="text" name="user[password2]" size="15" value="'.$pswd.'" alt="Confirm Password" /></td></tr>'; ! } else { ! echo '<tr><td>'.get_string('USR_NewPassword','stack','').'</td><td><input type="password" name="user[password1]" size="15" value="" alt="Password" /></td></tr>'; ! echo '<tr><td>'.get_string('USR_ConfirmPsswd','stack','').'</td><td><input type="password" name="user[password2]" size="15" value="" alt="Confirm Password" /></td></tr>'; ! } ! echo '<tr><td>'.get_string('USR_FirstName','stack','').'</td><td><input type="text" name="user[firstname]" size="25" value="'.sf($user,'firstname').'" alt="First name" /></td><td>'.nsf($err,'firstname').'</td></tr>'; echo '<tr><td>'.get_string('USR_LastName','stack','').'</td><td><input type="text" name="user[lastname]" size="25" value="'.sf($user,'lastname').'" alt="Last name" /></td><td>'.nsf($err,'lastname').'</td></tr>'; *************** *** 209,214 **** --- 260,311 ---- } + /** + * Build the form fragment to produce a dropdown list of current users. + * Note, this builds a whole table row. + * + * @param array $userID The user ID number of the current user. + * @param boolean $anyUser Adds an "any non-guest user" field to the list + * @return void + */ + function stack_user_select_formfrag($userID,$anyUser=TRUE){ + + $query = 'SELECT id, username, firstname, lastname FROM stackUser'; + + $stack_users = stack_db_query($query); + + if(0 != mysql_num_rows($stack_users)) { + + echo "<tr><td>User ID</td>\n"; + echo "<td><select name=\"userID\">\n"; + echo "userID"; + if ($anyUser) { + $spec_users=array('(any)','>0'); + + foreach ($spec_users as $su) { + $sup = htmlspecialchars($su); + if ($su == $userID ) { + echo " <option value=\"$sup\" selected>$sup</option>\n"; + } else { + echo " <option value=\"$sup\" >$sup</option>\n"; + } + } + } + + for ($i = 0; $i < mysql_num_rows($stack_users); $i++) + { + $row = mysql_fetch_row($stack_users); + if ($row[0] == $userID) { + echo " <option value=\"{$row[0]}\" selected>{$row[0]} {$row[1]} ({$row[2]} {$row[3]})</option>\n"; + } else { + echo " <option value=\"{$row[0]}\">{$row[0]} {$row[1]} ({$row[2]} {$row[3]})</option>\n"; + } + } + echo "</select> </td></tr>"; + + } + + } ?> |