\n";
print " \n";
print " \n";
print " \n";
print " \n";
$showpersonal = 0;
if(! empty($user['firstname']) || ! empty($user['lastname']) || ! empty($user['email']) ||
$user['affiliation'] == 'Local') {
$showpersonal = 1;
print " - Personal Information");
print "
\n";
}
print " - RDP File Preferences");
print "
\n";
print " - General Preferences
\n");
print " \n";
print " \n";
print " | \n";
print " | \n";
print " \n";
if($showpersonal) {
print " \n";
}
print " \n";
print " \n";
print " \n";
print " \n";
print " | \n";
print "
\n";
print "
\n";
printUserprefJavascript();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn confirmUserPrefs($type)
///
/// \param $type - 0 for personal prefs, 1 for rdp prefs
///
/// \brief prints a page for user to confirm changes to preferences
///
////////////////////////////////////////////////////////////////////////////////
function confirmUserPrefs($type) {
global $submitErr, $user;
$data = processUserPrefsInput(1);
if($submitErr) {
userpreferences();
return;
}
if($data["audiomode"] == "none")
$audio = _("None");
else
$audio = _("Use my speakers");
if($data["mapdrives"] == 0)
$drives = _("No");
else
$drives = _("Yes");
if($data["mapprinters"] == 0)
$printers = _("No");
else
$printers = _("Yes");
if($data["mapserial"] == 0)
$serial = _("No");
else
$serial = _("Yes");
print "\n";
if($type == 0) {
print _("
Personal Information
\n");
print _("
Submit the following changes?
\n");
print "
\n";
print " \n";
print _(" Preferred Name: | \n");
print " " . $data["preferredname"] . " | \n";
print "
\n";
print "
\n";
if($user['affiliation'] == 'Local' &&
! empty($data['newpassword'])) {
print _("New password will be submitted
\n");
}
}
elseif($type == 1) {
print _("
RDP File Preferences
\n");
print _("
Submit the following changes?
\n");
print "
\n";
print " \n";
print _(" Resolution: | \n");
print " " . $data["resolution"] . " | \n";
print "
\n";
print " \n";
print _(" Color Depth: | \n");
$colordepth = array("8" => "8", "16" => "16", "24" => "24", "32" => "32");
print " " . $colordepth[$data["bpp"]] . " | \n";
print "
\n";
print " \n";
print _(" Audio: | \n");
print " $audio | \n";
print "
\n";
print " \n";
print _(" Map Local Drives: | \n");
print " $drives | \n";
print "
\n";
print " \n";
print _(" Map Local Printers: | \n");
print " $printers | \n";
print "
\n";
print " \n";
print _(" Map Local Serial Ports: | \n");
print " $serial | \n";
print "
\n";
print "
\n";
}
print "
\n";
print " \n";
print " \n";
print " \n";
print " | \n";
print " \n";
print " \n";
print " | \n";
print "
\n";
print "
\n";
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitUserPrefs()
///
/// \brief updates user prefs and prints a page informing the user of success
///
////////////////////////////////////////////////////////////////////////////////
function submitUserPrefs() {
global $user;
$data = getContinuationVar();
if($data["resolution"] == "Full Screen") {
$width = 0;
$height = 0;
}
else {
list($width, $height) = explode('x', $data["resolution"]);
if(! is_numeric($width) || ! is_numeric($height)) {
$width = 0;
$height = 0;
}
}
if(updateUserPrefs($user['id'], $data["preferredname"], $width, $height,
$data["bpp"], $data["audiomode"], $data["mapdrives"],
$data["mapprinters"], $data["mapserial"])) {
}
if($user['affiliation'] == 'Local' &&
! empty($data['newpassword'])) {
$query = "SELECT l.salt "
. "FROM localauth l, "
. "user u "
. "WHERE u.id = '{$user['id']}' AND "
. "l.userid = u.id";
$qh = doQuery($query, 101);
if(! ($row = mysql_fetch_assoc($qh)))
abort();
$passhash = sha1("{$data['newpassword']}{$row['salt']}");
$query = "UPDATE localauth "
. "SET passhash = '$passhash' "
. "WHERE userid = {$user['id']}";
doQuery($query, 101);
}
$user = getUserInfo($user["id"], 1, 1);
$_SESSION['user'] = $user;
userpreferences();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn submitGeneralPreferences()
///
/// \brief updates user general preferences and calls userpreferences
///
////////////////////////////////////////////////////////////////////////////////
function submitGeneralPreferences() {
global $user, $HTMLheader, $printedHTMLheader, $mode;
$groupview = getContinuationVar('groupview', processInputVar('groupview', ARG_STRING));
$emailnotify = processInputVar('emailnotify', ARG_NUMERIC);
if($groupview != 'affiliation' && $groupview != 'allgroups') {
$printedHTMLheader = 1;
print $HTMLheader;
userpreferences();
return;
}
if($emailnotify != 1 && $emailnotify != 2) {
$printedHTMLheader = 1;
print $HTMLheader;
userpreferences();
return;
}
if(($groupview == 'allgroups' && $user['showallgroups'] == 0) ||
($groupview == 'affiliation' && $user['showallgroups'] == 1)) {
if($groupview == 'allgroups')
$value = 1;
else
$value = 0;
$query = "UPDATE user SET showallgroups = $value WHERE id = {$user['id']}";
doQuery($query, 101);
$_SESSION['user']['showallgroups'] = $value;
$user['showallgroups'] = $value;
}
if(($user['emailnotices'] == 1 && $emailnotify == 1) ||
($user['emailnotices'] == 0 && $emailnotify == 2)) {
$newval = $emailnotify - 1;
$query = "UPDATE user SET emailnotices = $newval WHERE id = {$user['id']}";
doQuery($query, 101);
$_SESSION['user']['emailnotices'] = $newval;
$user['emailnotices'] = $newval;
}
print $HTMLheader;
$printedHTMLheader = 1;
$mode = 'submituserprefs';
# FIXME might need to clear some cache items for cached lists of groups
userpreferences();
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn processUserPrefsInput($checks)
///
/// \param $checks - (optional) 1 to perform validation, 0 not to
///
/// \return an array with the following indexes:\n
/// preferredname, resolution, bpp, audiomode, mapdrives, mapprinters,
/// mapserial, unityid
///
/// \brief validates input from the previous form; if anything was improperly
/// submitted, sets submitErr and submitErrMsg
///
////////////////////////////////////////////////////////////////////////////////
function processUserPrefsInput($checks=1) {
global $submitErr, $submitErrMsg, $user;
$return = array();
$defaultres = $user["width"] . 'x' . $user["height"];
$return["preferredname"] = processInputVar("preferredname" , ARG_STRING);
$return["resolution"] = processInputVar("resolution" , ARG_STRING, $defaultres);
$return["bpp"] = processInputVar("bpp" , ARG_NUMERIC, $user["bpp"]);
$return["audiomode"] = processInputVar("audiomode" , ARG_STRING, $user["audiomode"]);
$return["mapdrives"] = processInputVar("mapdrives" , ARG_NUMERIC, $user["mapdrives"]);
$return["mapprinters"] = processInputVar("mapprinters" , ARG_NUMERIC, $user["mapprinters"]);
$return["mapserial"] = processInputVar("mapserial" , ARG_NUMERIC, $user["mapserial"]);
if(! $checks) {
return $return;
}
if(strlen($return["preferredname"]) > 25) {
$submitErr |= PREFNAMEERR;
$submitErrMsg[PREFNAMEERR] = _("Preferred name can only be up to 25 characters");
}
if(! preg_match('/^[a-zA-Z ]*$/', $return["preferredname"])) {
$submitErr |= PREFNAMEERR;
$submitErrMsg[PREFNAMEERR] = _("Preferred name can only contain letters and spaces");
}
if($user['affiliation'] == 'Local' && array_key_exists('newpassword', $_POST)) {
$return['newpassword'] = $_POST['newpassword'];
$confirmpwd = $_POST['confirmpassword'];
$curr = $_POST['currentpassword'];
if(get_magic_quotes_gpc()) {
$return['newpassword'] = stripslashes($return['newpassword']);
$confirmpwd = stripslashes($confirmpwd);
$curr = stripslashes($curr);
}
if(! empty($return['newpassword']) && ! empty($confirmpwd) &&
! validateLocalAccount($user['unityid'], $curr)) {
$submitErr |= LOCALPASSWORDERR;
$submitErrMsg[LOCALPASSWORDERR] = _("Password incorrect");
}
elseif((empty($return['newpassword']) && ! empty($confirmpwd)) ||
(! empty($return['newpassword']) && empty($confirmpwd)) ||
($return['newpassword'] != $confirmpwd)) {
$submitErr |= LOCALPASSWORDERR;
$submitErrMsg[LOCALPASSWORDERR] = _("Passwords do not match");
}
}
return $return;
}
////////////////////////////////////////////////////////////////////////////////
///
/// \fn printUserprefJavascript()
///
/// \brief prints javascript used in user preferences page
///
////////////////////////////////////////////////////////////////////////////////
function printUserprefJavascript() {
print <<
function show(id) {
var obj = document.getElementById("personal");
if(obj)
obj.className = "hidden";
document.getElementById("rdpfile").className = "hidden";
document.getElementById("uiprefs").className = "hidden";
document.getElementById("status").className = "hidden";
if(id == 'personal' && ! obj)
id = 'rdpfile';
document.getElementById(id).className = "shown";
}
show("personal");
document.getElementById("preflinks").className = "shown";
document.getElementById("status").className = "visible";
HTMLdone;
}
?>