Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12073/scripts Modified Files: stackAuthor.php stackDatabase.php stackFrontend.php stackQuestion.php stackQuiz.php stackUser.php Added Files: stackSubject.php Log Message: **MAJOR** changes: added the Subject layer over the top, Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** stackDatabase.php 1 Sep 2005 13:50:18 -0000 1.40 --- stackDatabase.php 4 Sep 2005 19:24:57 -0000 1.41 *************** *** 10,13 **** --- 10,49 ---- /** + * Run the database update script if needed. + * + */ + function stack_db_database_update() + { + global $stack_mysql; + extract($stack_mysql); + + // If the options exists we are in business. + $query = 'SELECT options FROM stackUser'; + + if (!$connection=mysql_connect($host,$user,$pswd)) { + $msg = mysql_error(); + echo "<b>Could not connet to MYSQL on host '$host', as user '$user'. The attempt to connect generated the MYSQL Error ".mysql_errno().": ".mysql_error()."</b>"; + die(); + } + + $db = mysql_select_db($stackdb,$connection); + + if (!$db) { + echo "<b>Could not connet to the MYSQL database '$stackdb' (on host '$host', as user '$user'). The attempt to connect generated the MYSQL Error ".mysql_errno().": ".mysql_error()."</b>"; + die(); + } + + $result = mysql_query($query); + + if (0 == $result) { + return false; + } + + return true; + } + + + + /** * Serialize doesn't work properly with ';' characters in the string * *************** *** 738,741 **** --- 774,779 ---- } + + /** * Returns an array of quizID's, indicating in which quizzes a question is used. *************** *** 1329,1332 **** --- 1367,1397 ---- } + + /** + * Takes the itemSource and returns a PHP array containing the item. + * + * @param array $user The array containing the user. + * @return number $id The ID of the new user in the DB. + */ + function stack_db_user_delete($user) { + global $stackUser; + + $userID = $user['id']; + + $query = "DELETE FROM stackUser WHERE id = '$userID'"; + $result = stack_db_query($query); + + $query = "DELETE FROM user_subject WHERE userID = '$userID'"; + $result = stack_db_query($query); + + $query = "DELETE FROM quizattempts WHERE userID = '$userID'"; + $result = stack_db_query($query); + + $query = "DELETE FROM questionattempts WHERE userID = '$userID'"; + $result = stack_db_query($query); + + } + + ////////////////////////////////////////////////////// // Quiz related functions // *************** *** 1339,1343 **** * @return boolean */ ! function stack_db_confirm_quiz_exists($quizid) { $exists = FALSE; --- 1404,1408 ---- * @return boolean */ ! function stack_db_quiz_confirm_exists($quizid) { $exists = FALSE; *************** *** 1668,1704 **** } /** ! * Run the database update script if needed. * */ ! function stack_db_database_update() ! { ! global $stack_mysql; ! extract($stack_mysql); ! // If the options exists we are in business. ! $query = 'SELECT options FROM stackUser'; ! if (!$connection=mysql_connect($host,$user,$pswd)) { ! $msg = mysql_error(); ! echo "<b>Could not connet to MYSQL on host '$host', as user '$user'. The attempt to connect generated the MYSQL Error ".mysql_errno().": ".mysql_error()."</b>"; ! die(); ! } ! $db = mysql_select_db($stackdb,$connection); ! if (!$db) { ! echo "<b>Could not connet to the MYSQL database '$stackdb' (on host '$host', as user '$user'). The attempt to connect generated the MYSQL Error ".mysql_errno().": ".mysql_error()."</b>"; ! die(); ! } ! $result = mysql_query($query); ! ! if (0 == $result) { ! return false; } ! ! return true; } ?> --- 1733,2146 ---- } + + ////////////////////////////////////////////////////// + // Subject related functions // + ////////////////////////////////////////////////////// + /** ! * Confirms a subject still exists in the database. * + * @param int $subjectID The subjectID of the subject. + * @return boolean */ ! function stack_db_subject_confirm_exists($subjectID) { ! ! $exists = FALSE; ! if ('' != $subjectID ) { ! $query = 'SELECT subjectName FROM stackSubject WHERE subjectID='.$subjectID; ! $result= stack_db_query($query); ! if(0 != mysql_num_rows($result)) { ! $exists = TRUE; ! } ! } ! return $exists; ! } ! /** ! * Deletes a subject from the database. ! * ! * @param int $subjectID The subjectID of the quuiz. ! * @return void ! */ ! function stack_db_subject_delete($subjectID) { ! if ('' != $subjectID ) { ! // (0) Delete the subject itself ! $query = "DELETE FROM stackSubject WHERE subjectID = '$subjectID'"; ! $result = stack_db_query($query); ! ! // (1) Delete all quiz links attached to the subject (although the quizzes are left) ! $query = "DELETE FROM subject_quiz WHERE subjectID = '$subjectID'"; ! $result = stack_db_query($query); ! ! } ! ! } ! ! /** ! * Get details of the subject from the database. If no $subjectID is supplied, then all subjects ! * are listed instead. ! * ! * @param int $subjectID The subjectID number of the subject needed. ! * @param boolean $allqs If set to TRUE, then all quizzes are returned, including hidden ones. ! * @return array $subject_list Full information about the subjectzes. ! */ ! function stack_db_subject_get($subjectID='',$allqs=TRUE) { ! global $stackSubject; ! ! $subject_list = NULL; ! $subject_fields = array_keys($stackSubject); ! $query = ''; ! ! foreach ($subject_fields as $val) { ! $query .= ' ,'.$val; ! } ! $query = substr($query,2,strlen($query)-2); ! ! if ('' == $subjectID) { ! $query = "SELECT $query FROM stackSubject ORDER BY subjectOrder"; ! } else { ! $query = "SELECT $query FROM stackSubject WHERE subjectID = '$subjectID'"; ! } ! $result = stack_db_query($query); ! if(0 != mysql_num_rows($result)) { ! ! for ($i = 0; $i < mysql_num_rows($result); $i++) { ! $row = mysql_fetch_row($result); ! ! $subject = array(); ! foreach ($subject_fields as $qf => $qv) { ! if ('subjectOptions' == $qv) { ! $subject[$qv] = base64_unserialize(stripslashes($row[$qf])); ! } else { ! $subject[$qv] = stripslashes($row[$qf]); ! } ! } ! ! // Obtain all quizzes in the subjects. ! if ($allqs) { ! $query = "SELECT quizid, qord FROM subject_quiz WHERE subjectID = {$subject['subjectID']} ORDER BY qord"; ! } else { ! $query = "SELECT quizid, qord FROM subject_quiz WHERE subjectID = {$subject['subjectID']} AND qord >= 0 ORDER BY qord"; ! } ! $questions_result = stack_db_query($query); ! ! if(0 != mysql_num_rows($questions_result)) { ! ! for ($j = 0; $j < mysql_num_rows($questions_result); $j++) { ! $row = mysql_fetch_row($questions_result); ! $subject['quizzes'][$j]['quizid'] = $row[0]; ! $subject['quizzes'][$j]['order'] = $row[1]; ! } ! } ! ! // sortout options; ! ! $subject_list[] = $subject; ! ! } ! ! } ! ! if ('' == $subjectID) { ! return $subject_list; ! } else { ! return $subject_list[0]; ! } ! } ! ! /** ! * Update details of the subject in the database. ! * If the subjectID is blank, or the $subjectID is not in the database a new ! * subject is created. ! * ! * @param array $subject The subject. ! * @return int $subjectID The subjectID of the subject in question. ! */ ! function stack_db_subject_update($subject) { ! global $stackSubject,$stackOptions; ! ! $subject_fields = array_keys($stackSubject); ! ! //show_array($subject); ! ! $subjectID = ''; ! if (array_key_exists('subjectID',$subject)) { ! $subjectID = trim($subject['subjectID']); ! } ! ! $new_subject = FALSE; ! if ('' == $subjectID) { ! $new_subject = TRUE; ! } else if(!stack_db_subject_confirm_exists($subjectID)) { ! $new_subject = TRUE; ! } ! ! // Let SQL add the "last edit", like the question ! if (array_key_exists('subjectDateLastEdited',$subject)) { ! unset($subject['subjectDateLastEdited']); ! } ! ! // Although SubjectMode is an option and will be stored and used from there, ! // we should add it to the list of fields so we can search by it. ! $subject['subjectMode'] = $stackOptions['SubjectMode']['default']; ! if (array_key_exists('subjectOptions',$subject)) { ! if (is_array($subject['subjectOptions'])) { ! if (array_key_exists('SubjectMode',$subject['subjectOptions'])) { ! $subject['subjectMode'] = $subject['subjectOptions']['SubjectMode']; ! } ! } ! } ! ! if ($new_subject) { ! ! $qu = ''; ! $quv = ''; ! foreach ($stackSubject as $key => $fields) { ! if (array_key_exists($key,$subject)) { ! if ('' != @trim($subject[$key])) { ! $qu .= ", $key"; ! if ('subjectOptions' == $key) { ! $quv .= ", '".addslashes(base64_serialize($subject[$key]))."' "; ! } else { ! $quv .= ", '".addslashes($subject[$key])."' "; ! } ! } ! } ! } ! $qu = substr($qu,1,strlen($qu)-1); ! $quv = substr($quv,1,strlen($quv)-1); ! ! $query = "INSERT INTO stackSubject ($qu) VALUES ($quv)"; ! $result = stack_db_query($query); ! ! //show_array($query); ! ! // GET the last subjectID ! $result= stack_db_query('SELECT LAST_INSERT_ID() FROM stackSubject'); ! $row = mysql_fetch_row($result); ! $subjectID = $row[0]; ! ! } else { ! ! $qu = ''; ! foreach ($stackSubject as $key => $fields) { ! if (array_key_exists($key,$subject)) { ! if ('' != @trim($subject[$key])) { ! if ('subjectOptions' == $key) { ! $qu .= ", $key = '".addslashes(base64_serialize($subject[$key]))."' "; ! } else { ! $qu .= ", $key = '".addslashes($subject[$key])."' "; ! } ! } else if ('html' == $fields['type']) { ! // To reset the page header and footer to an empty value. ! $qu .= ", $key = NULL "; ! } ! } ! } ! $qu = substr($qu,1,strlen($qu)-1); ! ! $query = "UPDATE stackSubject SET $qu WHERE subjectID = '$subjectID'"; ! $result = stack_db_query($query); ! ! } ! ! ! return $subjectID; ! } ! ! ! /** ! * Add a quizID to a subject ! * Used in stackAuthor.php ! * ! * @param int $subjectID The subjectID number of the subject needed. ! * @param int $quizis The quizid of the quiz ! * @param int $qord The order of the question in the subject, optional ! * @return void ! */ ! function stack_db_subject_add_quiz($subjectID,$quizid,$qord='NULL') { ! ! if ($qord==='NULL') { ! $query = "INSERT INTO subject_quiz (subjectID, quizid) VALUES ('$subjectID','$quizid')"; ! } else { ! $query = "INSERT INTO subject_quiz (subjectID, quizid, qord) VALUES ('$subjectID','$questionID','$qord')"; ! } ! ! $result = stack_db_query($query); ! } ! ! /** ! * Drop a quizid from a subject ! * ! * @param int $subjectID The subjectID number of the subject needed. ! * @param int $quizid The questionID of the question! ! * @return int $result The number of table rows dropped. ! */ ! function stack_db_subject_drop_quiz($subjectID,$quizid) { ! ! if ('' != $subjectID and '' != $quizid) { ! $query = "DELETE FROM subject_quiz WHERE subjectID = '$subjectID' and quizid= '$quizid'"; ! $result = stack_db_query($query); ! } ! ! return $result; ! } ! ! /** ! * Reorder a quizid within a subject ! * ! * @param int $subjectID The subjectID number of the subject needed. ! * @param int $quizid The quizid of the quiz ! * @param int $order ! * @return int $result The number of table rows dropped. ! */ ! function stack_db_subject_reorder_quizzes($subjectID,$quizid,$order='NULL') { ! ! if ('' != $subjectID and '' != $quizid) { ! if ('NULL' === $order) { ! $query = "UPDATE subject_quiz SET qord=NULL WHERE subjectID='$subjectID' AND quizid='$quizid'"; ! } else { ! $query = "UPDATE subject_quiz SET qord='$order' WHERE subjectID='$subjectID' AND quizid='$quizid'"; ! } ! $result = stack_db_query($query); ! } ! ! return $result; ! } ! ! /** ! * Reorder a subject in the zone ! * ! * @param int $subjectID The subjectID number of the subject needed. ! * @param int $order ! * @return int $result The number of table rows dropped. ! */ ! function stack_db_subject_reorder($subjectID,$order) { ! ! if ('' === $order) { ! $query = "UPDATE stackSubject SET subjectOrder=NULL WHERE subjectID='$subjectID'"; ! } else { ! $query = "UPDATE stackSubject SET subjectOrder=$order WHERE subjectID='$subjectID'"; } ! ! $result = stack_db_query($query); ! ! return $result; ! } ! ! ! /** ! * Gets details of the quizzes in a subject from the database. ! * ! * @param int $subjectID ! * @return array $quiz_list Full information about the quizzes, without questions. ! */ ! function stack_db_subject_quiz_list_student($subjectID) { ! global $stackQuiz; ! ! $query = "SELECT quizid FROM subject_quiz WHERE subjectID = {$subjectID} AND qord >= 0 ORDER BY qord"; ! ! $result = stack_db_query($query); ! ! if(0 != mysql_num_rows($result)) { ! ! for ($i = 0; $i < mysql_num_rows($result); $i++) { ! $row = mysql_fetch_row($result); ! ! $quiz_list[] = stack_db_quiz_get($row[0],FALSE); ! ! } ! } ! ! return $quiz_list; ! } ! ! /** ! * Gets details of the subjects onto which a user is enrolled. ! * ! * @param int $userID ! * @return array $subject_store Full information about the subject, without quizzes. ! */ ! function stack_subject_user_enrolled($user) { ! ! if (0 == $user['id']) { ! $query = "SELECT subjectID FROM stackSubject WHERE subjectOrder >= 0 and subjectMode = 'all, including guests' ORDER BY subjectOrder"; ! } else { ! $query = "SELECT subjectID FROM stackSubject WHERE subjectOrder >= 0 ORDER BY subjectOrder"; ! } ! ! // Need to see which of **THESE** the student is enrolled upon. ! // A subject may have subsequently been hidden..... ! ! $result = stack_db_query($query); ! ! $subject_list = NULL; ! if(0 != mysql_num_rows($result)) { ! ! for ($i = 0; $i < mysql_num_rows($result); $i++) { ! $row = mysql_fetch_row($result); ! ! $subject_list[] = stack_db_subject_get($row[0],FALSE); ! ! } ! } ! ! return $subject_list; } + + /** + * List all the quizzes in the database for possible inclusion in a subject. + * + * @param $filter string Which questions are to be shown? + * @return void + */ + function stack_db_list_quizzes_subject($subjectID) + { // List all the questions in the database + global $_PHP_SELF; + + $query = 'SELECT quizid, quizName, quizDescription FROM stackQuiz '; + $result = stack_db_query($query); + + if(0 != mysql_num_rows($result)) { + + echo "<h2>Add quizzes to a subject</h2>\n<p>\n<form name='subjectform' action='{$_PHP_SELF}' method='POST'> + <input type='hidden' name='subjectID' value='$subjectID'>"; + echo '<table>'; + echo "<tbody>\n"; + + for ($i = 0; $i < mysql_num_rows($result); $i++) { + $row = mysql_fetch_row($result); + + $qID = $row[0]; + $name = stripslashes($row[1]); + $descript = stripslashes($row[2]); + + echo "<tr>\n"; + echo " <td><input type='checkbox' name='quizzesToAdd[$qID]' />\n"; + echo " <td>$qID</td>\n <td>$name</td>\n <td>$descript</td>\n</tr>\n"; + } + + echo "</tbody></table>\n"; + + echo '<input type="hidden" name="action" value="subject_edit" />'; + echo '<input type="submit" value="Add" /></form>'; + + + } else { + echo "<p>You currently have no quizzes in your database.</p>"; + } + + } + + + ////////////////////////////////////////////////////// + // Zone related functions // + ////////////////////////////////////////////////////// + + ?> Index: stackAuthor.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackAuthor.php,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** stackAuthor.php 1 Sep 2005 13:50:18 -0000 1.38 --- stackAuthor.php 4 Sep 2005 19:24:57 -0000 1.39 *************** *** 95,100 **** if ($remoteCaller) ! ob_start(); ! echo "<table cellpadding='4'><tr> <td> <b>".get_string('stackQuestion_questionOptions','stack')."</b> </td> --- 95,100 ---- if ($remoteCaller) ! ob_start(); ! echo "<table cellpadding='4'><tr> <td> <b>".get_string('stackQuestion_questionOptions','stack')."</b> </td> *************** *** 128,134 **** if ($remoteCaller) { ! $html = ob_get_contents(); ! ob_end_flush(); ! return $html; } } --- 128,134 ---- if ($remoteCaller) { ! $html = ob_get_contents(); ! ob_end_flush(); ! return $html; } } *************** *** 212,216 **** //For use by RQP - buffer these echo's if($remoteCaller) ! ob_start(); // hidden metadata --- 212,216 ---- //For use by RQP - buffer these echo's if($remoteCaller) ! ob_start(); // hidden metadata *************** *** 413,419 **** if ($remoteCaller) { ! $html = ob_get_contents(); ! ob_end_clean(); ! return $html; } } // end of edit_form_table --- 413,419 ---- if ($remoteCaller) { ! $html = ob_get_contents(); ! ob_end_clean(); ! return $html; } } // end of edit_form_table *************** *** 1184,1186 **** --- 1184,1564 ---- } + //****************************************************** + //** Edit subject + //****************************************************** + + /** + * Build the form to edit a STACK question. + * + * @param array $subject The STACK subject + * @param array &$errors Repository for errors + * @param string $PostTo Where to send the form + * @return void + */ + function stack_subject_edit_form($subject,&$errors,$PostTo = '') { + + //show_array($subject); + global $_PHP_SELF,$stackSubject,$stackOptions, $stack_stand_alone; + + if (empty($PostTo)) { + $PostTo=$_PHP_SELF; + } + + $t = time(); + $dts = strftime('%c',$t); // Format the string. + + //Does the subject have options set? + $subject_options = array(); + if (array_key_exists('subjectOptions',$subject)) { + if (is_array($subject['subjectOptions'])) { + $subject_options = $subject['subjectOptions']; + } + } + $optval = stack_options_formvals_set($subject_options); + + // Timestamp this edit + echo "<form name='stacksubjecteditform' action='$PostTo' method='POST'>\n"; + + // Hidden metadata, + // Why are tags one more level deep than they should be + echo "<input type='hidden' name='subject[subjectDateLastEdited]' value='$t' />\n + + <input type='hidden' name='subject[subjectGUID]' value='".sf($subject,'subjectGUID')."' />\n + <input type='hidden' name='subject[subjectUserLastEdited]' value='".sf($subject,'subjectUserLastEdited')."' />\n + <input type='hidden' name='subject[subjectPublisher]' value='".sf($subject,'subjectPublisher')."' />\n + <input type='hidden' name='subject[type]' value='".sf($subject,'type')."' />\n + <input type='hidden' name='subject[subjectFormat]' value='".sf($subject,'subjectFormat')."' />\n"; + + // Some Metadata is set at the top of the subject form. + echo "\n<table>\n"; + + $display_fields = array('subjectID','subjectName','subjectDescription','subjectKeywords'); + foreach ($display_fields as $key) { + //Check that within current field there is no type tag, otherwise skip + $err = ''; + echo "<tr><td><b>{$stackSubject[$key]['descript']}</b></td>\n"; + if ('subjectID' == $key) { + echo "<td><input type=\"hidden\" name=\"subject[$key]\" value=\"{$subject[$key]}\" alt=\"$key\" />{$subject[$key]}</td><td>".$err.'</td></tr>'; + } else { + echo "<td><input type=\"text\" name=\"subject[$key]\" size=\"35\" value=\"".nsf($subject,$key)."\" alt=\"$key\" /></td><td>".$err.'</td></tr>'; + } + } + echo "\n</table>\n"; + + // We need to add some options here also. + + $options_headings = array('',''); + $options_list = array('SubjectMode','TeacherEmail'); + + // If there is a prefix sort it out *HERE!* + $fieldname = 'subject'.'[subjectOptions]'; + stack_options_edit_form($options_headings,$options_list,$optval,$fieldname,''); + + + echo "<p><b>Quizzes attached to this subject:</b><br />(An empty order field indicates they are attached but hidden)"; + + if (array_key_exists('quizzes',$subject)) { + if (is_array($subject['quizzes'])) { + echo "\n<table>\n"; + echo "<tr><th>Drop</th><th>Order</th><th>Quiz no.</th><th>Name</th></tr>\n"; + foreach ($subject['quizzes'] as $qn => $qu) { + $qID = $qu['quizid']; + $qo = nsf($qu,'order'); + // Get the quiz with the body encoded. + $qID_exists_in_DB = stack_db_quiz_confirm_exists($qID); + if ($qID_exists_in_DB) { + $quiz = stack_db_quiz_get($qID,TRUE); + $qname = $quiz['quizName']; + $qkw = $question['quizKeywords']; + } else { + $qname = "Quiz with ID is $qID missing from DB!"; + $qkw = ''; + } + echo "<tr><td><input type=\"checkbox\" name=\"subject[quizzes][$qn][drop]\" value=\"ticked\" /></td>\n"; + echo "<td><input type=\"text\" name=\"subject[quizzes][$qn][order]\" size=\"3\" value=\"{$qo}\" /></td>\n"; + echo "<td><input type=\"hidden\" name=\"subject[quizzes][$qn][quizid]\" value=\"{$qID}\" />$qID</td>"; + echo "<td>$qname</td><td>$qkw</td> </tr>\n"; + + } + echo "\n</table></p>\n"; + } + } + + echo "<p><b><a href=\"javascript:addquiz();\">Choose quiz to add</a></b> \n"; + + echo '<input type="hidden" name="action" value="subject_edit" />'; + echo "<input type=\"submit\" value=\"Edit\" />\n"; + + + $options_headings = array('',get_string('stackOptions_edit_inmeth','stack'),'','','',get_string('stackOptions_edit_resppro','stack'),'','','','','','','','',get_string('stackOptions_edit_out','stack'),''); + $options_list = array('QuizMode','InsertStars','InformalSyntax','AllowInputTool','SyntaxHint','AnsTest','AnsTestOpt','QuVal','Penalty','Forbid','Allow','FeedBackGenericCorrect','FeedBackGenericPCorrect','FeedBackGenericIncorrect','Display','Language'); + + $fieldname = 'subject'.'[subjectOptions]'; + stack_options_edit_form($options_headings,$options_list,$optval,$fieldname,$prefix); + + // Check if subject has metadata set + // $fieldname = 'subject' + $metadata_list = array('subjectLanguage','subjectLearningContext','subjectDifficulty','subjectCompetency', + 'subjectCompetencyLevel','subjectTimeAllocated','subjectExcerciseType','subjectRights'); + stack_subject_metadata_edit_form($subject, $metadata_list); + + echo "</p>"; + + $headrows = substr_count($subject['subjectHTMLHead'],"\n") + 5; + $htmlhead = $subject['subjectHTMLHead']; + echo "<p><b>Subject page header</b><br /><textarea name='subject[subjectHTMLHead]' cols='80' rows='$headrows'>{$htmlhead}</textarea>"; + + $footrows = substr_count($subject['subjectHTMLFoot'],"\n") + 5; + $htmlfoot = $subject['subjectHTMLFoot']; + echo "<p><b>Subject page footer</b><br /><textarea name='subject[subjectHTMLFoot]' cols='80' rows='$headrows'>{$htmlfoot}</textarea>"; + + // The end of the form! + echo "<br /><input type=\"submit\" value=\"Edit\" />\n"; + echo "</form>\n"; + + + return NULL; + } + + + /** + * Process the incoming $_POST['subject'] fields. + * + * @param array $subject The STACK subject + * @param array &$errors Repository for errors + * @param string $PostTo Where to send the form + * @return void + */ + function stack_subject_edit(&$subject,&$errors) { + // (0) Establish the subjectID + if (array_key_exists('subjectID',$subject)) { + $subjectID = $subject['subjectID']; + } else { + $errors['subject']['subjectID'] = '<br />Could not find a subjectID!'; + return NULL; + } + + // (1) Validate and clean up the options. + if (array_key_exists('subjectOptions',$subject)) { + stack_options_validate($subject['subjectOptions']); + } + + if (array_key_exists('quizzes',$subject)) { + // (2) Drop any questions no longer used. + + foreach($subject['quizzes'] as $key => $qu) { + $quID = $qu['quizid']; + if (array_key_exists('drop',$qu)) { + $nodropped = stack_db_subject_drop_quiz($subject['subjectID'],$quID); + unset($subject['quizzes'][$key]); + } + } + + // (3) Re-order + $unordered_quizzes = array(); + $ordered_quizzes = array(); + + // (3.1) Split questions into hidden, and unhidden questions + foreach($subject['quizzes'] as $key => $qu) { + $ordered = FALSE; + if (array_key_exists('order',$qu)) { + if ('' != trim($qu['order'])) { + $ordered = TRUE; + } + } + if ($ordered) { + $ordered_quizzes[] = $qu; + } else { + $unordered_quizzes[] = $qu; + } + } + + if (!empty($ordered_quizzes)) { + // (3.2) Reorder those that need it. + stack_reorder($ordered_quizzes); + + // (3.3) Give these a nominal order. + foreach($ordered_quizzes as $key => $val) { + $ordered_quizzes[$key]['order'] = $key; + } + } + + // (3.4) Put them back together. + $subject['quizzes'] = array_merge($ordered_quizzes,$unordered_quizzes); + + + // (3.5) Update the database of the new orders. + foreach($subject['quizzes'] as $key => $qu) { + $ordered = FALSE; + if (array_key_exists('order',$qu)) { + if ('' != trim($qu['order'])) { + $ordered = TRUE; + } + } + if ($ordered) { + stack_db_subject_reorder_quizzes($subjectID,$qu['quizid'],$qu['order']); + } else { + stack_db_subject_reorder_quizzes($subjectID,$qu['quizid']); + } + } + + } // End of if (array_key_exists('quizzes',$subject)) .... + + // (4) Add any new questions + if (array_key_exists('quizzesToAdd',$subject)) { + + if (is_array($subject['quizzesToAdd'])) { + $to_add = $subject['quizzesToAdd']; + + foreach($to_add as $quID => $key) { + // HACK need a regular expression to confirm $quID is a number only! + + if (stack_db_quiz_confirm_exists($quID)) { + stack_db_subject_add_quiz($subjectID,$quID); + $subject['quizzes'][] = array('quizid'=>$quID); + } else { + $errors['subject']['quizzes'] .= "<br />Could not add the quiz with quizid $quID: it does not appear to exit in the database."; + } + } + } + unset($subject['questionsToAdd']); + } + + // (\infty) Update the subject information itself + stack_db_subject_update($subject); + + return NULL; + } + + /** + * Generates a portion of HTML which allows the editing of a particular subject metadata field. + * + * Checks that specified field is of type 'meta' and whether an array of values is present. If so, draw a list + * box with all the fields. As these fields contain optional data - they default to 'unspecified'. + * If an array of values is not present, we default to text box entry. + * + * @param string $name The name of the field in the form + * @param string $opt The option key + * @param mixed $optval The currently set value + * @param int $sz The size of the answer boxes + * @return void + */ + function stack_subject_edit_metadata_field($name,$opt,$optval,$default,$sz=8) { + global $stackSubject; + + $fields = $stackSubject[$opt]; + //Must be of type meta + if ('meta'==$fields['type']) { + if (is_array( $fields['values'])) { //Check that there is an array (list type) in the values tag + echo "\n<select name=\"$name\">\n"; + if (empty($optval)){echo " <option value='$default' selected>$default</option>\n";} + + foreach ($fields['values'] as $vals) { + if ($vals==$optval) {echo " <option value='$vals' selected>$vals</option>\n";} + else {echo " <option value='$vals'>$vals</option>\n";} + } + + echo " </select>\n"; + } + + else { + if (empty($optval)){echo "<input type='text' name='$name' value ='".stack_s($default)."' size = '$sz' />";} + else{echo "<input type='text' name='$name' value ='".stack_s($optval)."' size = '$sz' />";} + } + } + } + + /** + * Constructs the metadata part of the subject edit form + * + * @param string $question The current subject being edited + * @param array $metadata_list The list of subject metadata to display + * @return void + */ + function stack_subject_metadata_edit_form($subject, $metadata_list) + { + global $stackSubject; + + //Create table to put subject metadata on + echo "<table cellpadding='4'><tr> + <td> <b>".get_string('stackQuestion_questionMetadata','stack')."</b> </td> + <td> <b>".get_string('stackOptions_edit_value','stack')."</b> </td> + <td> <b>".get_string('stackOptions_edit_default','stack')."</b> </td></tr>"; + + //Iterate through each field given in $metadata_list + foreach( $metadata_list as $k => $metadata) { + $descript = stack_subject_edit_dispsubjectfield($metadata); //Display tag with help + $defval = $stackSubject[$metadata]['default']; //Retrieve the metadata's default value + $fieldname= 'subject'.'['.$metadata.']'; + + echo " <td> $descript </td>\n <td>"; + @stack_subject_edit_metadata_field($fieldname,$metadata,$subject[$metadata],$defval); //Display correct UI component for field + echo "</td>\n"; + + //$defval = $stackSubject[$metadata]['default']; //Retrieve the metadata's default value + + echo " <td> $defval </td>\n</tr>\n"; + } + + echo "\n</table>\n\n\n"; + } + + /** + * Display the name of a subjectField, in a link generating a popup window. + * + * @param string $field The field name + * @return string The link to the popup window + */ + function stack_subject_edit_dispsubjectfield($field) { + global $stackSubject; + + $fd='stackSubject_'.$field; + + $fd=get_string($fd,'stack',''); + $strout = "<a border=\"none\" href=\"javascript:HelpPopup('$field','stackSubject');\"><img align=\"middle\" border=\"0\" alt=\"$fd\" src=\"pics/help.gif\" /></a> $fd"; + return($strout); + } + + //****************************************************** + //** Edit zone + //****************************************************** + + /** + * Display a selection of subjects in the zone edit page. + * + * @param array $subject_store an array of $subject + * @return void + */ + function stack_zone_subjects_list($subject_store) { + global $stackSubject; + + echo "\n<table cellpadding='2' border='1'>\n"; + echo "\n<tr>\n"; + echo " <th>{$stackSubject['subjectOrder']['descript']}</th>\n <th>ID</th>\n"; + echo " <th>{$stackSubject['subjectName']['descript']}</th>\n"; + echo " <th>{$stackSubject['subjectMode']['descript']}</th>\n"; + echo " <th>{$stackSubject['subjectDescription']['descript']}</th>\n</tr>\n"; + + foreach ($subject_store as $key => $subject) { + $sID = $subject['subjectID']; + $so = nsf($subject,'subjectOrder'); + $sname = nsf($subject,'subjectName'); + $sdescript = nsf($subject,'subjectDescription'); + + $smode = nsf($subject,'subjectMode'); + if ('' == $smode) { + $smode = 'Default'; + } + + echo "<tr>\n"; + echo " <td><input type=\"text\" name=\"zone[subjectOrder][$key][order]\" size=\"3\" value=\"{$so}\" />\n"; + echo " <input type=\"hidden\" name=\"zone[subjectOrder][$key][subjectID]\" size=\"3\" value=\"{$sID}\" /></td>\n"; + echo " <td>$sID</td>\n <td>$sname</td>\n <td>$smode</td>\n <td>$sdescript</td> </tr>\n"; + + } + echo "\n</table></p>\n"; + + } + + ?> --- NEW FILE: stackSubject.php --- <?php /** * This file contains most functions which deal with quizzes. * * @package scripts * @subpackage Stack */ /* the stackSubject data structure */ // 'Unique quiz ID - local mySQL value' $stackSubject['subjectID']['descript'] = 'Subject ID number'; $stackSubject['subjectID']['mysql'] = 'INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY'; $stackSubject['subjectID']['type'] = 'meta'; // 'Subject name' $stackSubject['subjectName']['descript'] = 'Subject name'; $stackSubject['subjectName']['mysql'] = 'TINYTEXT'; $stackSubject['subjectName']['type'] = 'meta'; $stackSubject['subjectName']['metatag'] = 'title'; //dc:title $stackSubject['subjectName']['metatype'] = 'dublincore'; // 'Subject description' $stackSubject['subjectDescription']['descript'] = 'Description'; $stackSubject['subjectDescription']['mysql'] = 'TINYTEXT'; $stackSubject['subjectDescription']['type'] = 'meta'; $stackSubject['subjectDescription']['metatag'] = 'description'; //dc:description $stackSubject['subjectDescription']['metatype'] = 'dublincore'; // 'Subject options' $stackSubject['subjectOptions']['descript'] = 'Subject options'; $stackSubject['subjectOptions']['mysql'] = 'TEXT'; $stackSubject['subjectOptions']['type'] = 'other'; // 'Subject mode' $stackSubject['subjectMode']['descript'] = 'Mode'; $stackSubject['subjectMode']['mysql'] = 'TINYTEXT'; $stackSubject['subjectMode']['type'] = 'string'; // 'Subject mode' $stackSubject['subjectOrder']['descript'] = 'Order in Zone'; $stackSubject['subjectOrder']['mysql'] = 'INT(11)'; $stackSubject['subjectOrder']['type'] = 'int'; // Page header and footers $stackSubject['subjectHTMLHead']['descript'] = 'Subject page header'; $stackSubject['subjectHTMLHead']['mysql'] = 'TEXT'; $stackSubject['subjectHTMLHead']['type'] = 'html'; $stackSubject['subjectHTMLFoot']['descript'] = 'Subject page header'; $stackSubject['subjectHTMLFoot']['mysql'] = 'TEXT'; $stackSubject['subjectHTMLFoot']['type'] = 'html'; // Subject Metadata added - database updated // 'Globally unique subject ID'; $stackSubject['subjectGUID']['required'] = 'system'; $stackSubject['subjectGUID']['mysql'] = 'CHAR(22) UNIQUE KEY'; //GUID's are 32byte characters $stackSubject['subjectGUID']['type'] = 'meta'; $stackSubject['subjectGUID']['metatag'] = 'identifier'; $stackSubject['subjectGUID']['metatype'] = 'dublincore'; // 'Keywords'; $stackSubject['subjectKeywords']['required'] = 'optional'; $stackSubject['subjectKeywords']['mysql'] = 'TINYTEXT'; $stackSubject['subjectKeywords']['type'] = 'meta'; $stackSubject['subjectKeywords']['metatag'] = 'keyword'; //lom:keyword $stackSubject['subjectKeywords']['metatype'] = 'lom'; $stackSubject['subjectKeywords']['descript'] = 'Keywords'; //<PDK>Need for display purposes // 'Last edited by'; $stackSubject['subjectUserLastEdited']['required'] = 'system'; $stackSubject['subjectUserLastEdited']['mysql'] = 'INT UNSIGNED'; $stackSubject['subjectUserLastEdited']['type'] = 'meta'; $stackSubject['subjectUserLastEdited']['metatag'] = 'creator'; //dc:creator $stackSubject['subjectUserLastEdited']['metatype'] = 'dublincore'; // 'Last edited on'; $stackSubject['subjectDateLastEdited']['required'] = 'system'; $stackSubject['subjectDateLastEdited']['mysql'] = 'TIMESTAMP'; $stackSubject['subjectDateLastEdited']['type'] = 'meta'; $stackSubject['subjectDateLastEdited']['metatag'] = 'date'; //dc:date $stackSubject['subjectDateLastEdited']['metatype'] = 'dublincore'; //Publisher $stackSubject['subjectPublisher']['required'] = 'system'; $stackSubject['subjectPublisher']['mysql'] = 'TINYTEXT'; $stackSubject['subjectPublisher']['type'] = 'meta'; $stackSubject['subjectPublisher']['metatag'] = 'publisher'; //dc:publisher $stackSubject['subjectPublisher']['metatype'] = 'dublincore'; //Type: Hidden from user $stackSubject['type']['values']=array('subject','subject'); //Default to 'type' enumeration in XSD file $stackSubject['type']['required']='optional'; $stackSubject['type']['mysql']='TINYTEXT'; $stackSubject['type']['type']='meta'; $stackSubject['type']['metatag']='type'; //dc:type $stackSubject['type']['metatype']='dublincore'; //Format: Hidden from user, selected by script $stackSubject['subjectFormat']['values']=array('application','audio','image', 'message','model','text','video', 'multipart'); $stackSubject['subjectFormat']['required']='optional'; $stackSubject['subjectFormat']['mysql']='TINYTEXT'; $stackSubject['subjectFormat']['type']='meta'; //dc:format $stackSubject['subjectFormat']['metatag']='format'; $stackSubject['subjectFormat']['metatype']='dublincore'; //Language: Defaulted to current system language, but user definable $stackSubject['subjectLanguage']['values']=array('en','fr','nl','es','unspecified'); $stackSubject['subjectLanguage']['required']='optional'; $stackSubject['subjectLanguage']['mysql']='TINYTEXT'; $stackSubject['subjectLanguage']['type']='meta'; $stackSubject['subjectLanguage']['metatag']='language'; //dc:language $stackSubject['subjectLanguage']['metatype']='dublincore'; $stackSubject['subjectLanguage']['default']=$stack_defaultlang; //take the default language; //Rights $stackSubject['subjectRights']['required']='optional'; $stackSubject['subjectRights']['mysql']='TEXT'; $stackSubject['subjectRights']['type']='meta'; $stackSubject['subjectRights']['metatag']='rights'; //dc:rights $stackSubject['subjectRights']['metatype']='dublincore'; $stackSubject['subjectRights']['default']='http://www.gnu.org/copyleft/gpl.html'; //Learning context: Defaulted to system context, but user definable $stackSubject['subjectLearningContext']['values']=array('Primary Education','Secondary Education','Higher Education', 'University First Cycle','University Second Cycle','University Post Grade', 'Technical School First Cycle','Technical School Second Cycle','Professional Formation', 'Continuous Formation','Vocational Training','unspecified'); $stackSubject['subjectLearningContext']['required']='optional'; $stackSubject['subjectLearningContext']['mysql']='TINYTEXT'; $stackSubject['subjectLearningContext']['type']='meta'; $stackSubject['subjectLearningContext']['metatag']='context'; //lom:context $stackSubject['subjectLearningContext']['metatype']='lom'; $stackSubject['subjectLearningContext']['default']='unspecified'; //Difficulty: Default to null - up to user to specify this $stackSubject['subjectDifficulty']['values']=array('Very Easy','Easy','Medium', 'Difficult','Very Difficult','unspecified'); $stackSubject['subjectDifficulty']['required']='optional'; $stackSubject['subjectDifficulty']['mysql']='TINYTEXT'; $stackSubject['subjectDifficulty']['type']='meta'; $stackSubject['subjectDifficulty']['metatag']='difficulty'; //lom:difficulty $stackSubject['subjectDifficulty']['metatype']='lom'; $stackSubject['subjectDifficulty']['default']='unspecified'; //Competency: Default to solve - then up to user $stackSubject['subjectCompetency']['values']=array('think','argue','solve', 'represent','language','communicate', 'tools','unspecified'); $stackSubject['subjectCompetency']['required']='optional'; $stackSubject['subjectCompetency']['mysql']='TINYTEXT'; $stackSubject['subjectCompetency']['type']='meta'; $stackSubject['subjectCompetency']['metatag']='competency'; $stackSubject['subjectCompetency']['metatype']='stack'; //competency $stackSubject['subjectCompetency']['default']='unspecified'; //CompetencyLevel: Default to null - then up to user $stackSubject['subjectCompetencyLevel']['values']=array('elementary','simpleConceptual','multiStep', 'complex','unspecified'); $stackSubject['subjectCompetencyLevel']['required']='optional'; $stackSubject['subjectCompetencyLevel']['mysql']='TINYTEXT'; $stackSubject['subjectCompetencyLevel']['type']='meta'; $stackSubject['subjectCompetencyLevel']['metatag']='competencylevel'; //competencylevel $stackSubject['subjectCompetencyLevel']['metatype']='stack'; $stackSubject['subjectCompetencyLevel']['default']='unspecified'; //Time to allocate: Default to null - then up to user $stackSubject['subjectTimeAllocated']['required']='optional'; $stackSubject['subjectTimeAllocated']['mysql']='TIME'; $stackSubject['subjectTimeAllocated']['type']='meta'; $stackSubject['subjectTimeAllocated']['metatag']='typicallearningtime'; //lom:typicallearningtime $stackSubject['subjectTimeAllocated']['metatype']='lom'; $stackSubject['subjectTimeAllocated']['default']="00:00:00"; //Type of subject: Default to algebraicExpression as that is only type of subject atm, but provides extensibility $stackSubject['subjectExcerciseType']['values']=array('algebraicExpression','mcqSingleAnswer','mcqMultipleAnswer', 'fillInBlank','unspecified'); $stackSubject['subjectExcerciseType']['required']='optional'; $stackSubject['subjectExcerciseType']['mysql']='TINYTEXT'; $stackSubject['subjectExcerciseType']['type']='meta'; $stackSubject['subjectExcerciseType']['metatag']='excercisetype'; //excercisetype $stackSubject['subjectExcerciseType']['metatype']='stack'; $stackSubject['subjectExcerciseType']['default']='unspecified'; /** * Displays the student subject selection screen * @param array $userID * @return void */ function stack_subject_student_select($userID) { global $stack_root,$stackSubject;; require_once("{$stack_root}/html/subjectjava.html"); echo '<h1>'.get_string('subject_choose','stack').'</h1>'; $subject_store = stack_subject_user_enrolled($userID); if (is_array($subject_store)) { echo "<script language=\"javascript\"> function choosequiz(n) { document.forms.subjectform.subjectID.value = n; document.forms.subjectform.submit(); } </script> <p>\n<form name='subjectform' action='index.php' method='POST'> <input type='hidden' name='subjectID' value='-1'> <input type='hidden' name='action' value='choose_quiz'>"; echo "\n<table cellpadding='2'>\n"; echo "\n<tr>\n <th>{$stackSubject['subjectName']['descript']}</th>\n"; echo " <th>{$stackSubject['subjectDescription']['descript']}</th>\n</tr>\n"; foreach ($subject_store as $qs => $subject) { $sID = $subject['subjectID']; $sname = $subject['subjectName']; $sdescript = $subject['subjectDescription']; echo "<tr>\n <td><a href=\"javascript:choosequiz('$sID');\">{$sname}</a></td>\n"; echo " <td>".$sdescript."</td>\n"; echo "</tr>\n"; } echo "\n</table>\n</form>\n</p>"; } else { echo '<p>'.get_string('subject_nonetochoose','stack').'</p>'; } } //<TODO: to be implemented> /** * Validate a STACK subject * * 1. Check required fields at the subject level are there (name of subject?) * 2. Check all fields at the subject level are valid (valid format?) * * @param array &$subject The STACK subject to validate * @param array &$errors Repository for errors * @return void */ function stack_subject_validate(&$subject,&$errors) { global $stackSubject, $debug; if ('' == trim($subject['subjectName'])) { $errors['subject']['subjectName'] = get_string('QValidRequiredField','stack'); } if (is_array($subject)) { //Perform subject field level validation here if (array_key_exists('subjectOptions',$subject)) { stack_options_validate($subject['subjectOptions']); } } else { // $subject is not an array $errors['subject']=get_string('QValidquestionnotar','stack',''); } } /** * Creates a new subject with the mimimum fields. * * @param int $subjectID ID the subject is to be initialised with * @return array $subject Question with the mimimum fields */ function stack_subject_new($subjectID) { global $stack_web_url, $user; $subject['subjectID'] = $subjectID; //Automatically generated subject metadata added $subject['subjectGUID'] = stack_generate_guid($stack_web_url); $subject['subjectFormat'] = 'text/xml; charset="utf-8"'; $subject['subjectPublisher'] = $stack_web_url; $subject['type'] = 'subject'; $subject['subjectUserLastEdited'] = $user['firstname']." ".$user['lastname']; if ($user['email']!='') { $subject['questionUserLastEdited'].=' <'.$user['email'].'>'; } return $subject; } ?> Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** stackQuestion.php 30 Aug 2005 10:28:01 -0000 1.33 --- stackQuestion.php 4 Sep 2005 19:24:57 -0000 1.34 *************** *** 118,121 **** --- 118,126 ---- $stackOptions['QuizMode']['default'] = 'Practice'; + $stackOptions['SubjectMode']['type'] = 'list'; + $stackOptions['SubjectMode']['values'] = array('all, including guests','any system user','the class list only'); + $stackOptions['SubjectMode']['default'] = 'the class list only'; + + //<PDK> sqlToSchemaMapping array maps basic SQL data types used in STAKCK to their respective XML schema data types //Only place temporarily here pending a resolution! *************** *** 2169,2197 **** function stack_question_new($remoteUser='') { ! global $user, $stack_web_url; ! ! $question=''; ! ! $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'; ! ! if (empty($remoteUser)) { ! $question['questionUserLastEdited'] = $user['firstname']." ".$user['lastname']; ! ! if ($user['email']!='') { //<TODO: need to somehow retrieve the RQP user who is making new question ! $question['questionUserLastEdited'].=' <'.$user['email'].'>'; ! } ! } ! ! else ! { ! $question['questionUserLastEdited'] = $remoteUser; ! } ! ! return $question; } --- 2174,2202 ---- function stack_question_new($remoteUser='') { ! global $user, $stack_web_url; ! ! $question=''; ! ! $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'; ! ! if (empty($remoteUser)) { ! $question['questionUserLastEdited'] = $user['firstname']." ".$user['lastname']; ! ! if ($user['email']!='') { //<TODO: need to somehow retrieve the RQP user who is making new question ! $question['questionUserLastEdited'].=' <'.$user['email'].'>'; ! } ! } ! ! else ! { ! $question['questionUserLastEdited'] = $remoteUser; ! } ! ! return $question; } Index: stackQuiz.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuiz.php,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** stackQuiz.php 30 Aug 2005 13:51:55 -0000 1.10 --- stackQuiz.php 4 Sep 2005 19:24:58 -0000 1.11 *************** *** 18,24 **** $stackQuiz['quizName']['descript'] = 'Quiz name'; $stackQuiz['quizName']['mysql'] = 'TINYTEXT'; ! $stackQuiz['quizName']['type'] = 'meta'; ! $stackQuiz['quizName']['metatag'] = 'title'; //dc:title ! $stackQuiz['quizName']['metatype'] = 'dublincore'; // 'Quiz description' --- 18,24 ---- $stackQuiz['quizName']['descript'] = 'Quiz name'; $stackQuiz['quizName']['mysql'] = 'TINYTEXT'; ! $stackQuiz['quizName']['type'] = 'meta'; ! $stackQuiz['quizName']['metatag'] = 'title'; //dc:title ! $stackQuiz['quizName']['metatype'] = 'dublincore'; // 'Quiz description' *************** *** 187,191 **** require_once("{$stack_root}/html/quizjava.html"); ! echo '<h1>'.get_string('quiz_choose','stack').'</h1>'; global $stackQuiz; --- 187,191 ---- require_once("{$stack_root}/html/quizjava.html"); ! echo '<h2>'.get_string('quiz_choose','stack').'</h2>'; global $stackQuiz; *************** *** 437,440 **** --- 437,444 ---- global $stackQuiz, $debug; + if ('' == trim($quiz['quizName'])) { + $errors['quiz']['quizName'] = get_string('QValidRequiredField','stack'); + } + if (is_array($quiz)) { //Perform quiz field level validation here *************** *** 456,460 **** */ function stack_quiz_new($quizid) { ! global $stack_web_url, $user; --- 460,464 ---- */ function stack_quiz_new($quizid) { ! global $stack_web_url, $user; Index: stackFrontend.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackFrontend.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** stackFrontend.php 29 Aug 2005 18:41:03 -0000 1.1 --- stackFrontend.php 4 Sep 2005 19:24:57 -0000 1.2 *************** *** 258,260 **** --- 258,348 ---- + /** + * 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_subject_selectform($subject_store, $PostTo) { + global $stackSubject,$stack_web_url; + if (is_array($subject_store)) { + + echo "<p>\n<form name='subjectform' action='$PostTo' method='POST'> + <input type='hidden' name='subjectID' value='-1' /> + <input type='hidden' name='action' value='subject_choose' />"; + + echo "\n<table cellpadding='2'>\n"; + echo "\n<tr>\n"; + echo " <th>ID</th>\n <th>{$stackSubject['subjectOrder']['descript']}</th>\n"; + echo " <th>{$stackSubject['subjectName']['descript']}</th> + <th>{$stackSubject['subjectDescription']['descript']}</th><th></th></tr>"; + foreach ($subject_store as $qs => $subject) + { + $sname = $subject['subjectName']; + if ('' == trim($sname)) { + $sname = '[empty]'; + } + $sID = $subject['subjectID']; + $sord = $subject['subjectOrder']; + echo "<tr>\n <td>{$sID}</td>\n <td>{$sord}</td>\n"; + echo " <td>{$sname}</td><td>".$subject['subjectDescription']."</td>\n"; + echo "<td><a href=\"javascript:takeaction('subject_edit','$sID');\">edit</a></td>\n"; + //echo "<td><a href=\"javascript:takeaction('subject_xml','$sID');\">xml</a></td>\n"; + echo "<td><a href=\"javascript:takeaction('subject_delete','$sID');\"><font color='red'>del</font></a></td></tr>\n"; + } + echo "\n</table>\n\n</p></form>"; + + } else { + echo "<p>You have no subjects available to try.</p>"; + echo "<p>\n<form name='subjectform' action='$PostTo' method='POST'> + <input type='hidden' name='subjectid' value='-1' /> + <input type='hidden' name='action' value='subject_choose' />"; + } + } + + + /** + * Kills the current script if the user is not *logged in* as the *admin*. + * + * @param $user The current user + * @return void + */ + function stack_user_ensureadmin($user) { + + if (!stack_user_is_admin($user) or !stack_is_logged_in($user)) { + echo '<h1>'.get_string('FE_notadmin','stack').'</h1>'; + echo '<p>'.get_string('FE_needadmin','stack',$user['username']).'</p>'; + echo "<p>Please login <a href='index.php?action=login'>here</a></p>"; + include('html/pagefoot.php'); + die(); + } + + } + + /** + * Displays any errors + * + * @param $errors The current user + * @param $where The context of the errors - 'quiz', 'subject' etc. + * @return void + */ + function stack_errors_show($errors,$where) { + + echo '<font color="red">'.get_string('FE_errors_exist','stack','').'</font><br/>'; + if (array_key_exists($where,$errors)) { + foreach($errors[$where] as $key => $val) { + if ('quiz' == $where) { + $dispkey = 'stackQuiz_'.$key; + } else if ('subject' == $where) { + $dispkey = 'stackSubject_'.$key; + } + + $dispkey = '<font color="orange">'.get_string($dispkey,'stack').'</font>'; + echo '<br />'.get_string('FE_errors_field','stack',$dispkey); + echo '<br /><font color="red">'.$val.'</font>'; + } + } + + } + ?> Index: stackUser.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackUser.php,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** stackUser.php 29 Aug 2005 18:41:03 -0000 1.14 --- stackUser.php 4 Sep 2005 19:24:58 -0000 1.15 *************** *** 328,331 **** --- 328,333 ---- echo '<tr><td>'.get_string('USR_Institution','stack','').'</td><td><input type="text" name="user[institution]" size="35" value="'.sf($user,'institution').'" alt="Last name" /></td><td>'.nsf($err,'institution').'</td></tr>'; + // Enrolled subjects. + } |