From: Chris S. <san...@us...> - 2005-08-29 18:41:18
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9530/scripts Modified Files: stackUser.php Added Files: stackFrontend.php Log Message: Index: stackUser.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackUser.php,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** stackUser.php 25 Aug 2005 16:06:17 -0000 1.13 --- stackUser.php 29 Aug 2005 18:41:03 -0000 1.14 *************** *** 67,70 **** --- 67,83 ---- } + /** + * Returns TRUE if the user is the guest user, FALSE otherwise + * @param $user, The user + * @return bool + */ + function stack_user_is_guest($user) { + if ('guest' == $user['username']) { + return TRUE; + } else { + return FALSE; + } + } + /** * Build the STACK admin user *************** *** 89,92 **** --- 102,118 ---- /** + * Returns TRUE if the user is the admin user, FALSE otherwise + * @param $user, The user + * @return bool + */ + function stack_user_is_admin($user) { + if ('admin' == $user['username']) { + return TRUE; + } else { + return FALSE; + } + } + + /** * Return a valid $user array, having checked usernames and passwords. * Has to cope with two special users: 'guest' and 'admin' *************** *** 136,139 **** --- 162,177 ---- } + /** + * Returns TRUE if the user is logged in, FALSE otherwise + * @param $user, The user + * @return bool + */ + function stack_is_logged_in($user) { + if ($user['loggedin']) { + return TRUE; + } else { + return FALSE; + } + } /** *************** *** 157,161 **** } $user['id'] = $userID; ! stack_user_information_validate($user,$errors); --- 195,199 ---- } $user['id'] = $userID; ! stack_user_information_validate($user,$errors); *************** *** 164,169 **** $mysqlrow = stack_db_user_update($user); } else { ! $errors['user']['password'] = '<font color="red">Password must be non-empty.</font>'; ! $error = $errors['user']['password']; $action = 'error'; } --- 202,206 ---- $mysqlrow = stack_db_user_update($user); } else { ! $errors['user']['password'] = '<font color="red">'.get_string('EmptyPassword','stack','').'</font>'; $action = 'error'; } *************** *** 204,212 **** if (array_key_exists('password1',$user)) { ! if ('' != $user['password1'] and '' !=$user['password2']) { if ( $user['password1'] == $user['password2']) { $user['password'] = $user['password1']; // HACK: should be md5($user['password1']); } else { ! $errors['user']['password'] = '<font color="red">'.get_string('MisMatchPassword','stack','').'</font>'.get_string('OldPasswordUnch','stack',''); } } --- 241,249 ---- if (array_key_exists('password1',$user)) { ! if ('' != trim($user['password1']) and '' != trim($user['password2'])) { if ( $user['password1'] == $user['password2']) { $user['password'] = $user['password1']; // HACK: should be md5($user['password1']); } else { ! $errors['user']['password'] = '<font color="red">'.get_string('MisMatchPassword','stack','').'</font> '.get_string('OldPasswordUnch','stack',''); } } *************** *** 216,221 **** $errors['user']['password'] = '<font color="red">'.get_string('QValidRequiredField','stack','').'</font>'; } - - } --- 253,256 ---- *************** *** 276,283 **** 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>'; } --- 311,318 ---- 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><td>'.nsf($err,'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><td>'.nsf($err,'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>'; } --- NEW FILE: stackFrontend.php --- <?php /** * Functions for the front end. * * @package stackFrontend * @subpackage Stack */ /** * Gets the questionbank filter if this has been set. * TO DO: This also sets $SESSION['bank_filter']. This should really * be in a separate function. Also should have a $source parameter * @return array question_bank_filter The Question Bank Filter */ function stack_questionbank_filter_get() { // Ensure all fields exist and are set. $question_bank_filter['name'] = ''; $question_bank_filter['kw'] = ''; $question_bank_filter['case_sense'] = TRUE; $question_bank_filter['show_descript'] = FALSE; $question_bank_filter['any'] = 'Any'; $question_bank_filter['order1'] = 'questionName'; $question_bank_filter['order2'] = 'questionKeywords'; $question_bank_filter['order3'] = 'questionID'; if (array_key_exists('bank_filter',$_SESSION)) { $question_bank_filter = $_SESSION['bank_filter']; } if (array_key_exists('bank_filter',$_POST)) { $question_bank_filter = $_POST['bank_filter']; if (!array_key_exists('case_sense',$question_bank_filter)) { $question_bank_filter['case_sense'] = FALSE; } if (!array_key_exists('show_descript',$question_bank_filter)) { $question_bank_filter['show_descript'] = FALSE; } } $_SESSION['bank_filter'] = $question_bank_filter; return $question_bank_filter; } /** * Gets the question instance that has been stored in $_POST * @param string $source. Must be 'database', 'new' or 'default' * @return array $questionInst Quiz question */ function stack_question_get($source) { global $stack_web_url,$user; $question = NULL; // $_POSTED data should over write any $_SESSION data, as it may have been // entered in a form. if ('default' == $source) { $question = stack_get_question_from_session(); if (array_key_exists('questionID',$_POST)) { $question = stack_get_question_from_post(); } } else if ('database' == $source) { $questionID = $_POST['questionID']; $question = stack_db_getquestion($questionID); } if ('new' == $source or NULL == $question) { //show_array($user); $question['questionID'] = '0'; $question['questionAnsKey'] = 'ans1'; $question['questionGUID'] = stack_generate_guid($stack_web_url); $question['questionFormat'] = 'text/xml; charset="utf-8"'; $question['questionPublisher'] = $stack_web_url; $question['type'] = 'question'; $question['questionUserLastEdited'] = $user['firstname']." ".$user['lastname']; if ($user['email']!='') { $question['questionUserLastEdited'].=' <'.$user['email'].'>'; } } return $question; } /** * Gets the question instance that has been stored in the session * @return array $questionInst Quiz question instance */ function stack_get_questionInst() { $questionInst = NULL; // Get any $questionInst from the current $_SESSION if (array_key_exists('questionInst',$_SESSION)) { $questionInst=$_SESSION['questionInst']; unset($_SESSION['questionInst']); } return $questionInst; } /** * Gets the question that has been stored in the session * @return array $question Quiz question */ function stack_get_question_from_session() { global $stackQuestion; $question = NULL; // Get any $question from the current $_SESSION if (array_key_exists('question',$_SESSION)) { foreach ($stackQuestion as $qfield => $val) { if (array_key_exists($qfield,$_SESSION['question'])) { if ('' != $_SESSION['question'][$qfield]) { $question[$qfield] = $_SESSION['question'][$qfield]; } } } unset($_SESSION['question']); } return $question; } /** * Gets the question instance that has been stored in $_POST * @return array $questionInst Quiz question */ function stack_get_question_from_post() { global $stackQuestion; $question = NULL; foreach($stackQuestion as $qfield => $attribs) { if (array_key_exists($qfield,$_POST) ) { if ('questionOptions' == $qfield) { $question[$qfield] = $_POST[$qfield]; } else if ('questionPotResp' == $qfield ) { $question[$qfield] = $_POST[$qfield]; } else if ( '' !=trim($_POST[$qfield]) ) { // We need this: all fields on form will be present in $_POST. $question[$qfield] = $_POST[$qfield]; } } } return $question; } /** * Gets the selected questions * @return array $quiz The questions selected */ function stack_get_selected_questions() { $quiz = NULL; if (array_key_exists('checked',$_POST)) { if (is_array($_POST['checked'])) { foreach ($_POST['checked'] as $quID => $val) { if ('ticked' == $val) { $quiz[] = $quID; } } } } return $quiz; } /** * Gets the seed variable that should be used * @return array $seed The seed variable */ function stack_get_seed() { if (array_key_exists('seed',$_POST)) { $seed=$_POST['seed']; } else { // HACK: this should involve the concept of a user! $seed = time(); } return $seed; } /** * Displays the edit metadate form * @param array $question_bank_filter The question bank filter to apply * @return void */ function stack_display_qb_edit_metadata($question_bank_filter) { global $stack_root; include("{$stack_root}/html/qselectform.php"); stack_db_listquestions('edit_metadata',$question_bank_filter); echo "<p><a href=\"javascript:SelectQs('edit_metadata');\">Edit metadata</a> "; } /** * Displays the preview of a question * @return void */ function stack_display_qb_preview($questionInst) { echo "<center><table bgcolor='#CCCCCC' width='100%' cellpadding='2'> <td align='left'> <b>Question: ".sf($questionInst,'questionName')."</b> (".sf($questionInst,'questionID'); echo ")</td><td align='right'>"; echo "<a href=\"javascript:HelpPopup('student','');\">Help</a></td></tr></table></center>"; } /** * Displays the list of quizzes for the admin to edit * @param array $quizstore The store of quizzes * @param string $PostTo The page that the info from the form should be posted to * @return void */ function stack_quiz_selectform($quiz_store, $PostTo) { global $stackQuiz,$stack_web_url; if (is_array($quiz_store)) { echo "<p>\n<form name='quiztryform' action='{$stack_web_url}quiz.php' method='POST'> <input type='hidden' name='quizid' value='-1' /> <input type='hidden' name='action' value='quiz_choose' /></form>"; echo "<p>\n<form name='quizform' action='$PostTo' method='POST'> <input type='hidden' name='quizid' value='-1' /> <input type='hidden' name='action' value='quiz_choose' />"; echo "\n<table cellpadding='2'>\n"; echo "\n<tr><th></th><th>{$stackQuiz['quizName']['descript']}</th> <th>{$stackQuiz['quizDescription']['descript']}</th><th></th></tr>"; foreach ($quiz_store as $qs => $quiz) { $qname = $quiz['quizName']; if ('' == trim($qname)) { $qname = '[empty]'; } $qID = $quiz['quizid']; echo "<tr><td>{$qID}</td><td>{$qname}</td><td>".$quiz['quizDescription']."</td>\n"; echo "<td><a href=\"javascript:takeaction('quiz_edit','$qID');\">edit</a></td>\n"; echo "<td><a href=\"javascript:quiztry('continue_quiz','$qID');\">try</a></td>\n"; echo "<td><a href=\"javascript:takeaction('quiz_report','$qID');\">results</a></td>\n"; echo "<td><a href=\"javascript:takeaction('quiz_xml','$qID');\">xml</a></td>\n"; echo "<td><a href=\"javascript:takeaction('quiz_delete','$qID');\"><font color='red'>del</font></a></td></tr>\n"; } echo "\n</table>\n\n</p></form>"; } else { echo "<p>You have no quizzes available to try.</p>"; echo "<p>\n<form name='quizform' action='$PostTo' method='POST'> <input type='hidden' name='quizid' value='-1' /> <input type='hidden' name='action' value='quiz_choose' />"; } } ?> |