From: Chris S. <san...@us...> - 2005-11-24 18:47:55
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27885/scripts Modified Files: stackDatabase.php stackFrontend.php stackSubject.php Log Message: Add the concept of class list Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** stackDatabase.php 19 Nov 2005 15:33:54 -0000 1.55 --- stackDatabase.php 24 Nov 2005 18:47:47 -0000 1.56 *************** *** 2145,2181 **** } - /** - * 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; - } - /** --- 2145,2148 ---- *************** *** 2225,2228 **** --- 2192,2311 ---- ////////////////////////////////////////////////////// + // User-Subject related functions // + ////////////////////////////////////////////////////// + + /** + * Adds a user to a subject + * + * @param int $userID + * @param int $subjectID + * @return void + */ + function stack_db_subject_user_add($userID,$subjectID) { + $query = "INSERT INTO user_subject (userID, subjectID) VALUES ($userID,$subjectID)"; + $result = stack_db_query($query); + } + + /** + * Adds a user to a subject + * + * @param int $userID + * @param int $subjectID + * @return void + */ + function stack_db_subject_user_drop($userID,$subjectID) { + $query = "DELETE FROM user_subject WHERE userID = '$userID' AND subjectID='$subjectID'"; + $result = stack_db_query($query); + } + + /** + * Return an array of $userID's who are enrolled on a subject + * + * @param int $userID + * @param int $subjectID + * @return void + */ + function stack_db_subject_classlist($subjectID) { + + $query = "SELECT userID FROM user_subject WHERE subjectID=$subjectID"; + + $result = stack_db_query($query); + + $enrolled=FALSE; + if(0 != mysql_num_rows($result)) { + for ($i = 0; $i < mysql_num_rows($result); $i++) { + $row = mysql_fetch_row($result); + $enrolled[]=$row[0]; + } + } + + return $enrolled; + } + + + /** + * Gets details of the subjects onto which any user can take. + * + * @param int $userID + * @return array $subject_store Full information about the subject, without quizzes. + */ + function stack_db_subject_user_enrolled($userID) { + + if (0 == $userID) { + $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 AND (subjectMode = 'any system user' OR subjectMode = 'all, including guests') 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; + } + + /** + * Gets details of the subjects onto which registered users have access. + * + * @param int $userID + * @return array $subject_store Full information about the subject, without quizzes. + */ + function stack_db_subject_user_enrolled_strict($userID) { + + $subject_list = NULL; + + if (0 != $userID) { + $query = "SELECT stackSubject.subjectID FROM stackSubject,user_subject WHERE user_subject.subjectID=stackSubject.subjectID AND user_subject.userID = {$userID} AND stackSubject.subjectOrder >= 0 and stackSubject.subjectMode = 'the class list only' ORDER BY stackSubject.subjectOrder"; + + $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_list[] = stack_db_subject_get($row[0],FALSE); + } + } + } + + return $subject_list; + } + + + + ////////////////////////////////////////////////////// // Zone related functions // ////////////////////////////////////////////////////// Index: stackSubject.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackSubject.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** stackSubject.php 11 Oct 2005 09:57:44 -0000 1.3 --- stackSubject.php 24 Nov 2005 18:47:47 -0000 1.4 *************** *** 179,183 **** /** * Displays the student subject selection screen ! * @param array $userID * @return void */ --- 179,183 ---- /** * Displays the student subject selection screen ! * @param array $user * @return void */ *************** *** 187,194 **** 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) { --- 187,190 ---- *************** *** 201,204 **** --- 197,209 ---- <input type='hidden' name='action' value='choose_quiz'>"; + $subject_store_all = stack_db_subject_user_enrolled($userID); + $subject_store_enr = stack_db_subject_user_enrolled_strict($userID); + + $no_subjects = TRUE; + if (is_array($subject_store_enr)) { + $no_subjects = FALSE; + $subject_store = $subject_store_enr; + + echo '<h2>'.get_string('FE_subject_closed','stack','').'</h2>'; echo "\n<table cellpadding='2'>\n"; echo "\n<tr>\n <th>".get_string('stackSubject_subjectName','stack','')."</th>\n"; *************** *** 213,220 **** echo "</tr>\n"; } ! echo "\n</table>\n</form>\n</p>"; ! } else { echo '<p>'.get_string('subject_nonetochoose','stack').'</p>'; } } --- 218,248 ---- echo "</tr>\n"; } ! echo "\n</table>\n"; ! } ! ! if (is_array($subject_store_all)) { ! $no_subjects = FALSE; ! $subject_store = $subject_store_all; ! ! echo '<h2>'.get_string('FE_subject_open','stack','').'</h2>'; ! echo "\n<table cellpadding='2'>\n"; ! echo "\n<tr>\n <th>".get_string('stackSubject_subjectName','stack','')."</th>\n"; ! echo " <th>".get_string('stackSubject_subjectDescription','stack','')."</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"; ! } ! ! if ($no_subjects){ echo '<p>'.get_string('subject_nonetochoose','stack').'</p>'; } + echo "</form>\n</p>"; } Index: stackFrontend.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackFrontend.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** stackFrontend.php 20 Oct 2005 12:53:36 -0000 1.9 --- stackFrontend.php 24 Nov 2005 18:47:47 -0000 1.10 *************** *** 283,288 **** --- 283,291 ---- echo " <th>".get_string('stackSubject_subjectName','stack','')."</th> <th>".get_string('stackSubject_subjectDescription','stack','')."</th><th></th></tr>"; + + $trcol = FALSE; foreach ($subject_store as $qs => $subject) { + $trcol = !$trcol; $sname = $subject['subjectName']; if ('' == trim($sname)) { *************** *** 291,297 **** $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"; --- 294,302 ---- $sID = $subject['subjectID']; $sord = $subject['subjectOrder']; ! if ($trcol) { echo "\n<tr bgcolor='#DDDDDD'>\n"; } else { echo "\n<tr bgcolor='#DDDDFF'>\n"; } ! echo "<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:userenrole('$sID');\">".get_string('menu_Enrole','stack','')."</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"; |