In this example, we have some data imported regularly from a flat file, but which breaks the flat file into two tables: a table of courses, and a table of evaluations of those courses from students. We only want to let certain people in, and those people are in another table of allowed students. So we combine the Single Sign-on with this plug-in’s match functionality.
First, there is something like this at the top to include both plugins and set up the database:
<? include('/web/includes/sso_portal.phpi'); $sso->authenticate(); include_once("/web/includes/sql.phpi"); $db = new MySQL('username', 'password', 'ratings', 'classes'); ?>
This both connects to the database and requires a log-in.
Of course, we want the style sheet for the data tables, so we also use this to include the style sheet:
<? $db->HTMLHead(); ?>
Finally, the actual code. What we want is to show the list of classes normally, but when they focus on a class, we want to show the ratings for that class.
<? //see if the account matches an entry in our authorized user table IF ($db->match('account', $authenticatedUser, 'authorized')): //display the list of courses $showFields=array('Term', 'Course_Title', 'Course_Number', 'Section', 'Team_Taught', 'Term_Letter','Instructor'); $db->displayList($showFields); //if we are focussing on a course, we want to join with the evaluation ratings table IF ($ClassID = $db->focussed()): //tell it to unfocus, or it will try to focus on this table, too $db->unFocus(); //switch to the ratings table $db->table('ratings'); //restrict to the ratings for this course $db->addRestriction(array('Class'=>$ClassID)); $db->order("Question"); //join with the question text table $db->join('questions', 'Question_Text'); //don't show a focus link for these records $db->noFocusLink(); //display the table of ratings $showFields=array('Rated_1', 'Rated_2', 'Rated_3', 'Rated_4', 'Rated_5', 'Responses', 'No_Responses'); $db->displayList($showFields); ENDIF; ELSE: echo "<p>Evaluations are available only to authorized accounts.</p>\n"; ENDIF; logoutbutton(); ?>
In order to show the ratings beneath the class we’ve focussed on, we have to switch to the ratings table, but restrict the ratings table to only show ratings for this class.
Each rating also has question text associated with it, so we join to the question text table.