• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/modules/quiz/quizedit.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00009 
00015 function getQuizTypes() {
00016         return array('simple');
00017 }
00019 function getQuestionTypes() {
00020         return array('sso' => 'Single Select Objective', 'mso' => 'Multiselect Objective', 'subjective' => 'Subjective');
00021 }
00022 
00023 
00028 function getQuizTypeBox($quizType) {
00029         $quizTypes = getQuizTypes();
00030         $quizTypeBox = '<select name="selQuizType" id="selQuizType">';
00031         for ($i = 0; $i < count($quizTypes); ++$i) {
00032                 $quizTypeBox .= '<option value="' . addslashes($quizTypes[$i]) . '"';
00033                 if ($quizTypes[$i] == $quizType)
00034                         $quizTypeBox .= ' selected="selected"';
00035                 $quizTypeBox .= '>' . $quizTypes[$i] . '</option>';
00036         }
00037         return $quizTypeBox;
00038 }
00039 
00040 function getQuestionTypeBox($questionType) {
00041         $questionTypes = getQuestionTypes();
00042         $questionTypesBox = '<select name="selQuestionType" id="selQuestionType">';
00043         foreach ($questionTypes as $key => $text) {
00044                 $questionTypesBox .= "<option value=\"$key\"";
00045                 if ($key == $questionType)
00046                         $questionTypesBox .= ' selected="selected"';
00047                 $questionTypesBox .= ">$text</option>\n";
00048         }
00049 
00050         return $questionTypesBox . "</select>\n";
00051 }
00052 
00053 
00058 function getTableRow($tableName, $condition) {
00059         $query = "SELECT * FROM `$tableName` WHERE $condition";
00060         $result = mysql_query($query);
00061         if (!$result) {
00062                 displayerror('Database error. Could not retrieve information from the database.');
00063                 return null;
00064         }
00065         return mysql_fetch_assoc($result);
00066 }
00067 
00068 function getQuizRow($quizId) {
00069         return getTableRow('quiz_descriptions', "`page_modulecomponentid` = $quizId");
00070 }
00071 
00072 function getSectionRow($quizId, $sectionId) {
00073         return getTableRow('quiz_sections', "`page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId");
00074 }
00075 
00076 function getQuestionRow($quizId, $sectionId, $questionId) {
00077         return getTableRow('quiz_questions', "`page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `quiz_questionid` = $questionId");
00078 }
00079 
00080 
00085 function getQuizEditFormFieldMap() {
00086         return array(
00087                 array('txtTitle', 'quiz_title', 'quiz_quiztitle', 'text'),
00088                 array('txtHeaderText', 'quiz_headertext', 'quiz_headertext', 'text'),
00089                 array('txtSubmitText', 'quiz_submittext', 'quiz_submittext', 'text'),
00090                 array('selQuizType', 'quiz_quiztype', 'quiz_quiztype', 'select'),
00091                 array('txtDuration', 'quiz_testduration', 'quiz_testduration', 'text'),
00092                 array('txtQuestionCount', 'quiz_questionspertest', 'quiz_questionspertest', 'text'),
00093                 array('txtQuestionsPerPage', 'quiz_questionsperpage', 'quiz_questionsperpage', 'text'),
00094                 array('chkShowTimerPerTest', 'quiz_showquiztimer', 'quiz_showtesttimer', 'checkbox'),
00095                 array('chkShowTimerPerPage', 'quiz_showpagetimer', 'quiz_showpagetimer', 'checkbox'),
00096                 array('txtOpenTime', 'quiz_startdatetime', 'quiz_startdatetime', 'datetime'),
00097                 array('txtCloseTime', 'quiz_enddatetime', 'quiz_closedatetime', 'datetime'),
00098                 array('chkSectionRandomAccess', 'quiz_allowsectionrandomaccess', 'quiz_sectionrandomaccess', 'checkbox'),
00099                 array('chkMixSections', 'quiz_mixsections', 'quiz_mixsections', 'checkbox'),
00100         );
00101 }
00102 
00103 function getSectionEditFormFieldMap() {
00104         return array(
00105                 array('txtSectionTitle', 'quiz_sectiontitle', 'section_sectiontitle', 'text'),
00106                 array('txtSSOCount', 'quiz_sectionssocount', 'section_ssocount', 'text'),
00107                 array('txtMSOCount', 'quiz_sectionmsocount', 'section_msocount', 'text'),
00108                 array('txtSubjectiveCount', 'quiz_sectionsubjectivecount', 'section_subjectivecount', 'text'),
00109                 array('txtSessionTimeLimit', 'quiz_sectiontimelimit', 'section_timelimit', 'text'),
00110                 array('chkShuffle', 'quiz_sectionquestionshuffled', 'section_shuffle', 'checkbox'),
00111                 array('chkShowLimit', 'quiz_sectionshowlimit', 'section_showlimit', 'checkbox'),
00112         );
00113 }
00114 
00115 function getQuestionEditFormFieldMap() {
00116         return array(
00117                 array('txtQuestion', 'quiz_question', 'question_question', 'text'),
00118                 array('txtQuestionWeight', 'quiz_questionweight', 'question_weight', 'text'),
00119                 array('selQuestionType', 'quiz_questiontype', 'question_type', 'select'),
00120         );
00121 }
00122 
00123 
00128 function addItems($insertQuery, $count) {
00129         $idArray = array();
00130         for ($i = 0; $i < $count; ++$i) {
00131                 $result = mysql_query($insertQuery);
00132                 if (!$result) {
00133                         displayerror('Database Error. Could not create new item.');
00134                         return false;
00135                 }
00136                 $idArray[] = mysql_insert_id();
00137         }
00138         return $idArray;
00139 }
00140 
00141 function addSections($quizId, $count) {
00142         $sectionQuery = "INSERT INTO `quiz_sections`(`page_modulecomponentid`, `quiz_sectiontitle`, `quiz_sectionssocount`, `quiz_sectionmsocount`, `quiz_sectionsubjectivecount`, `quiz_sectiontimelimit`, `quiz_sectionquestionshuffled`, `quiz_sectionrank`) " .
00143                         "(SELECT $quizId, 'New Section', 0, 0, 0, '00:32', 0, IFNULL(MAX(`quiz_sectionrank`), 0) + 1 FROM `quiz_sections` WHERE `page_modulecomponentid` = $quizId LIMIT 1)";
00144         return addItems($sectionQuery, $count);
00145 }
00146 
00147 function addQuestions($quizId, $sectionId, $count) {
00148         $questionQuery = "INSERT INTO `quiz_questions`(`page_modulecomponentid`, `quiz_sectionid`, `quiz_question`, `quiz_questiontype`, `quiz_questionrank`, `quiz_questionweight`, `quiz_answermaxlength`, `quiz_rightanswer`) " .
00149                         "(SELECT $quizId, $sectionId, 'Your new question here?', 'subjective', IFNULL(MAX(`quiz_questionrank`), 0) + 1, 1, 1024, 'Yes, it sure is.' FROM `quiz_questions` WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId LIMIT 1)";
00150         return addItems($questionQuery, $count);
00151 }
00152 
00157 function deleteItem($tableNames, $conditions, &$affectedRows) {
00158         if (!is_array($tableNames))
00159                 $tableNames = array($tableNames);
00160 
00161         $affectedRows = array();
00162         $allOk = true;
00163         for ($i = 0; $i < count($tableNames); ++$i) {
00164                 $deleteQuery = "DELETE FROM `{$tableNames[$i]}` WHERE $conditions";
00165                 if (!mysql_query($deleteQuery)) {
00166                         displayerror("Database Error. Could not remove information from table `{$tableNames[$i]}`.");
00167                         $allOk = false;
00168                         $affectedRows[] = false;
00169                 }
00170                 else
00171                         $affectedRows[] = mysql_affected_rows();
00172         }
00173         return $allOk;
00174 }
00175 
00176 function deleteSection($quizId, $sectionId) {
00177         $tables = array('quiz_sections', 'quiz_questions', 'quiz_objectiveoptions', 'quiz_answersubmissions');
00178         $affectedRows = array();
00179         return deleteItem($tables, "`page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId", $affectedRows);
00180 }
00181 
00182 function deleteQuestion($quizId, $sectionId, $questionId) {
00183         $tableNames = array('quiz_questions', 'quiz_objectiveoptions');
00184         $affectedRows = array();
00185         return deleteItem($tableNames, "`page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `quiz_questionid` = $questionId", $affectedRows);
00186 }
00187 
00188 function deleteQuestionOptions($quizId, $sectionId, $questionId) {
00189         $tableNames = array('quiz_objectiveoptions');
00190         $affectedRows = array();
00191         return deleteItem($tableNames, "`page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `quiz_questionid` = $questionId", $affectedRows);
00192 }
00193 
00198 function moveItem($itemId, $itemRank, $tableName, $idFieldName, $rankFieldName, $conditions, $direction) {
00199         $function = $direction == 'up' ? 'DESC' : 'ASC';
00200         $operator = $direction == 'up' ? '<' : '>';
00201 
00202         $neighbourQuery = "SELECT `$idFieldName`, `$rankFieldName` FROM `$tableName` WHERE " . $conditions . ($conditions == '' ? '' : ' AND') . " `$rankFieldName` $operator $itemRank ORDER BY `$rankFieldName` $function LIMIT 1";
00203         $neighbourResult = mysql_query($neighbourQuery);
00204         if (!$neighbourResult) {
00205                 displayerror('Database Error. Could not fetch information about the given item.');
00206                 return false;
00207         }
00208 
00209         if (mysql_num_rows($neighbourResult) == 0) {
00210                 displaywarning('The item that you tried to move ' . $direction . ' is already at the ' . ($direction == 'up' ? 'top' : 'bottom') . ' of the list.');
00211                 return true;
00212         }
00213         $neighbourRow = mysql_fetch_assoc($neighbourResult);
00214         $itemId2 = $neighbourRow[$idFieldName];
00215         $itemRank2 = $neighbourRow[$rankFieldName];
00216 
00217         $updateQuery1 = "UPDATE `$tableName` SET `$rankFieldName` = $itemRank2 WHERE " . $conditions . ($conditions == '' ? '' : ' AND') . " `$idFieldName` = $itemId";
00218         $updateQuery2 = "UPDATE `$tableName` SET `$rankFieldName` = $itemRank WHERE " . $conditions . ($conditions == '' ? '' : ' AND') . " `$idFieldName` = $itemId2";
00219 
00220         if (!mysql_query($updateQuery1) || !mysql_query($updateQuery2)) {
00221                 displayerror('Database Error. Could not move the specified item.');
00222                 return false;
00223         }
00224 
00225         return true;
00226 }
00227 
00228 function moveSection($quizId, $sectionId, $direction) {
00229         $sectionRow = getSectionRow($quizId, $sectionId);
00230         if (!$sectionRow) {
00231                 displayerror('Error. Could not find the section that you were trying to move.');
00232                 return false;
00233         }
00234         return moveItem($sectionId, $sectionRow['quiz_sectionrank'], 'quiz_sections', 'quiz_sectionid', 'quiz_sectionrank', "`page_modulecomponentid` = $quizId", $direction);
00235 }
00236 
00237 function moveQuestion($quizId, $sectionId, $questionId, $direction) {
00238         $questionRow = getQuestionRow($quizId, $sectionId, $questionId);
00239         if (!$questionRow) {
00240                 displayerror('Could not find the specified question.');
00241                 return false;
00242         }
00243         return moveItem($questionId, $questionRow['quiz_questionrank'], 'quiz_questions', 'quiz_questionid', 'quiz_questionrank', "`page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId", $direction);
00244 }
00245 
00246 
00251 function getItemList($tableName, $conditions = '1') {
00252         $itemQuery = "SELECT * FROM `$tableName` WHERE $conditions";
00253         $itemResult = mysql_query($itemQuery);
00254         if (!$itemResult)
00255                 return false;
00256         $itemList = array();
00257         while ($itemList[] = mysql_fetch_assoc($itemResult));
00258         array_pop($itemList);
00259         return $itemList;
00260 }
00261 
00262 function getSectionList($quizId) {
00263         return getItemList('quiz_sections', "`page_modulecomponentid` = $quizId ORDER BY `quiz_sectionrank`");
00264 }
00265 
00271 function getQuestionTableHtml($quizId, $sectionId) {
00272         global $urlRequestRoot, $sourceFolder, $templateFolder,$cmsFolder;
00273         $editImage = "<img style=\"padding:0px\" src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/apps/accessories-text-editor.png\" alt=\"Edit\" />";
00274         $deleteImage = "$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/edit-delete.png";
00275         $moveUpImage = "<img src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/go-up.png\" alt=\"Move Section Up\" />";
00276         $moveDownImage = "<img src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/go-down.png\" alt=\"Move Section Down\" />"; 
00277 
00278         $questionQuery = "SELECT * FROM `quiz_questions` WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId ORDER BY `quiz_questionrank`";
00279         $questionResult = mysql_query($questionQuery);
00280 
00281         $questionListHtml = '<table border="1"><tr><th>Question</th><th>Type</th><th></th></tr>';
00282         $questionCount = mysql_num_rows($questionResult);
00283         $i = 0;
00284         while ($questionRow = mysql_fetch_assoc($questionResult)) {
00285                 $questionId = $questionRow['quiz_questionid'];
00286                 $rightAnswer = $questionRow['quiz_rightanswer'];
00287 
00288                 $optionsText = '';
00289                 $optionsQuery = "SELECT * FROM `quiz_objectiveoptions` WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `quiz_questionid` = $questionId ORDER BY `quiz_optionrank";
00290                 $optionsResult = mysql_query($optionsQuery);
00291                 $j = 1;
00292                 while ($optionsRow = mysql_fetch_assoc($optionsResult)) {
00293                         $style = '';
00294                         if ($j == $rightAnswer)
00295                                 $style = 'font-weight: bold;';
00296                         $optionsText .= "<p style=\"margin-left: 12px; $style\">{$optionsRow['quiz_optiontext']}</p>\n";
00297                         ++$j;
00298                 }
00299 
00300                 global $sourceFolder, $moduleFolder;
00301                 require_once($sourceFolder."/latexRender.class.php");
00302                 $render = new latexrender();
00303                 $optionsText = $render->transform($optionsText);
00304                 $questionDesc = $render->transform($questionRow['quiz_question']);
00305 
00306                 $moveUp = ($i == 0 ? '' : "<a href=\"./+edit&subaction=movequestion&direction=up&sectionid=$sectionId&questionid=$questionId\">$moveUpImage</a>");
00307                 $moveDown = ($i == $questionCount - 1 ? '' : "<a href=\"./+edit&subaction=movequestion&direction=down&sectionid=$sectionId&questionid=$questionId\">$moveDownImage</a>");
00308                 $questionListHtml .= <<<QUESTIONROW
00309                 <tr>
00310                         <td>{$questionDesc}<br />$optionsText</td><td>{$questionRow['quiz_questiontype']}</td>
00311                         <td nowrap="nowrap">
00312                                 <a href="./+edit&subaction=editquestion&sectionid=$sectionId&questionid={$questionRow['quiz_questionid']}">$editImage</a>
00313                                 <form style="display:inline;margin:0;padding:0;border:0" method="POST" action="./+edit&subaction=deletequestion">
00314                                         <input type="hidden" name="hdnSectionId" value="$sectionId" />
00315                                         <input type="hidden" name="hdnQuestionId" value="$questionId" />
00316                                         <input type="image" name="btnDelete" src="$deleteImage" title="Delete" />
00317                                 </form>
00318                                 $moveUp
00319                                 $moveDown
00320                         </td>
00321                 </tr>
00322 QUESTIONROW;
00323                 ++$i;
00324         }
00325 
00326         return $questionListHtml . '</table>';
00327 }
00328 
00333 function getQuestionOptionList($quizId, $sectionId, $questionId) {
00334         return getItemList('quiz_objectiveoptions', "`page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `quiz_questionid` = $questionId ORDER BY `quiz_optionrank`");
00335 }
00336 
00341 function getQuestionOptionListHtml($quizId, $sectionId, $questionId, $questionType, $rightAnswer, $editable = false) {
00342         $optionList = getQuestionOptionList($quizId, $sectionId, $questionId);
00343         if ($optionList === false)
00344                 return false;
00345 
00346         if ($questionType == 'mso')
00347                 $rightAnswer = explode('|', $rightAnswer);
00348         else
00349                 $rightAnswer = array($rightAnswer);
00350 
00351         $inputTypePrefix = $questionType == 'sso' ? 'opt' : 'chk';
00352         $html = '<table id="optionsTable" border="0" width="100%">';
00353         for ($i = 0; $i < count($optionList); ++$i) {
00354                 $elementName = "{$inputTypePrefix}Option";
00355                 if ($questionType == 'mso')
00356                         $elementName .= $i;
00357                 $elementId = "{$inputTypePrefix}Option$i";
00358                 $html .= '<tr><td style="width:32px"><input type="' . ($questionType == 'sso' ? 'radio' : 'checkbox') . '" id="' . $elementId . '" name="' . $elementName . '" value="' . $i . '"';
00359                 if ($editable && in_array($optionList[$i]['quiz_optionid'], $rightAnswer))
00360                         $html .= ' checked="checked"';
00361                 $html .= ' /></td><td>';
00362 
00363                 if ($editable)
00364                         $html .= '<input type="text" name="txtOptionText' . $i . '" id="txtOptionText' . $i . '" value="' . $optionList[$i]['quiz_optiontext'] . '" />';
00365                 else
00366                         $html .= $optionList[$i]['quiz_optiontext'];
00367                 $html .= "</td></tr>\n";
00368         }
00369         $html .= '</table> <input type="button" name="btnAddOption" onclick="addOption()" value="Add Option" />';
00370         return $html;
00371 }
00372 
00377 function getSubmittedQuestionOptionListHtml($questionType) {
00378         $html = '<table border="0">';
00379         $inputType = $questionType == 'sso' ? 'radio' : 'checkbox';
00380         $prefix = ($questionType == 'sso' ? 'opt' : 'chk') . 'Option';
00381         $i = 0;
00382         while (true) {
00383                 if (!isset($_POST['txtOption' . $i]))
00384                         break;
00385                 $elementName = $prefix;
00386                 $elementId = $prefix . $i;
00387                 if ($questionType == 'mso')
00388                         $elementName .= $i;
00389 
00390                 $html .= '<tr><td><input type="' . $inputType . '" name="' . $elementName . '" id="' . $elementName . '" value="' . $i . '" ';
00391                 if (($questionType == 'sso' && $_POST['optOption'] == $i) || isset($_POST[$elementName]))
00392                         $html .= 'checked="checked" ';
00393                 $html .= '/></td><td><input type="text" name="txtOption' . $i . '" id="txtOption' . $i . '" value="' . safe_html($_POST["txtOption$i"]) . '" /></td></tr>';
00394         }
00395         $html .= "</table>\n";
00396         return $html;
00397 }
00398 
00404 function setWeightMark($quizId, $weight, $positive, $negative) {
00405         $result = mysql_query("SELECT `question_weight` FROM `quiz_weightmarks` WHERE `page_modulecomponentid` = $quizId AND `question_weight` = $weight");
00406         if(mysql_fetch_assoc($result))
00407                 mysql_query("UPDATE `quiz_weightmarks` SET `question_positivemarks` = $positive, `question_negativemarks` = $negative WHERE `page_modulecomponentid` = $quizId AND `question_weight` = $weight");
00408         else
00409                 mysql_query("INSERT INTO `quiz_weightmarks`(`page_modulecomponentid`, `question_weight`, `question_positivemarks`, `question_negativemarks`) VALUES ($quizId, $weight, $positive, $negative)");
00410         return mysql_affected_rows();
00411 }
00412 
00417 function weightMarksForm($quizId) {
00418         $result = mysql_query("SELECT DISTINCT `quiz_questionweight` FROM `quiz_questions` WHERE `page_modulecomponentid` = $quizId");
00419         
00420         $ret = "<table><thead><th>Weight</th><th>Marks</th></thead>";
00421         $pmarks="";
00422         $nmarks="";
00423         while($row = mysql_fetch_assoc($result))
00424         {
00425                 $result2= mysql_query("SELECT `question_positivemarks`,`question_negativemarks` FROM `quiz_weightmarks` WHERE `page_modulecomponentid` = $quizId AND `question_weight`={$row['quiz_questionweight']}");
00426                 
00427                 if(mysql_num_rows($result2)==0)
00428                 {
00429                         $pmarks=$row['quiz_questionweight'];
00430                         $nmarks=$row['quiz_questionweight'];
00431                 }
00432                 else
00433                 {
00434                         $row2=mysql_fetch_assoc($result2);
00435                         $pmarks=$row2["question_positivemarks"];
00436                         $nmarks=$row2["question_negativemarks"];
00437                 }
00438                 $ret .= "<tr><td>{$row['quiz_questionweight']}</td><td><form method=POST action='./+edit&subaction=setweightmark'><input type=hidden name=weight value='{$row['quiz_questionweight']}'><input type=hidden name=quizId value='{$quizId}'>Positive<input type=text name='pos' value='$pmarks' size=5> Negative<input type=text name='neg' value='$nmarks' size=5> <input type=submit name=btnSetWeightMarks value='Set Marks'></form></td></tr>";
00439         }
00440         return $ret . "</table>";
00441 }
00442 
00449 function getQuizEditForm($quizId, $dataSource) {
00450         $fieldMap = getQuizEditFormFieldMap();
00451         if ($dataSource == 'POST') {
00452                 for ($i = 0; $i < count($fieldMap); ++$i) {
00453                         if ($fieldMap[$i][3] == 'chk')
00454                                 $$fieldMap[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? 'checked="checked"' : '';
00455                         else
00456                                 $$fieldMap[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? htmlentities(safe_html($_POST[$fieldMap[$i][0]])) : '';
00457                 }
00458         }
00459         elseif ($dataSource == 'db') {
00460                 $quizRow = getQuizRow($quizId);
00461                 if (!$quizRow) {
00462                         displayerror('Could not retrieve information about the specified quiz. Quiz not found.');
00463                         return '';
00464                 }
00465                 for ($i = 0; $i < count($fieldMap); ++$i) {
00466                         if ($fieldMap[$i][3] == 'checkbox')
00467                                 $$fieldMap[$i][2] = isset($quizRow[$fieldMap[$i][1]]) && $quizRow[$fieldMap[$i][1]] != 0 ? 'checked="checked"' : '';
00468                         else
00469                                 $$fieldMap[$i][2] = isset($quizRow[$fieldMap[$i][1]]) ? htmlentities($quizRow[$fieldMap[$i][1]]) : '';
00470                 }
00471         }
00472 
00473         $quizTypeBox = getQuizTypeBox($quiz_quiztype);
00474         
00475         $setWeightMarks = weightMarksForm($quizId);
00476         
00477         global $moduleFolder, $cmsFolder, $urlRequestRoot;
00478         $calpath = "$urlRequestRoot/$cmsFolder/$moduleFolder";
00479         $quizEditForm = <<<QUIZEDITFORM
00480 
00481         <link rel="stylesheet" type="text/css" media="all" href="$calpath/form/calendar/calendar.css" title="Aqua" />
00482         <script type="text/javascript" src="$calpath/form/calendar/calendar.js"></script>
00483 
00484         <form name="quizpropertiesform" action="./+edit" method="POST">
00485                 <h3>Quiz Properties</h3>
00486 
00487                 <fieldset style="padding:8px">
00488                         <legend>General Properties</legend>
00489 
00490                         <table border="0">
00491                                 <tr><td><label for="txtTitle">Quiz Title:</label></td><td><input type="text" name="txtTitle" id="txtTitle" value="$quiz_quiztitle" /></td></tr>
00492                                 <tr><td><label for="txtHeaderText">Header Text:</label></td><td><textarea rows="5" cols="30" id="txtHeaderText" name="txtHeaderText">$quiz_headertext</textarea></td></tr>
00493                                 <tr><td><label for="txtSubmitText">Submit Text:</label></td><td><textarea rows="5" cols="30" id="txtSubmitText" name="txtSubmitText">$quiz_submittext</textarea></td></tr>
00494                                 <tr><td><label for="selQuizType">Quiz Type:</label></td><td>$quizTypeBox</td></tr>
00495                                 <tr><td><label for="txtDuration">Quiz Duration (HH:MM):</label></td><td><input type="text" name="txtDuration" id="txtDuration" value="$quiz_testduration" /></td></tr>
00496                                 <tr><td><label for="txtQuestionCount">Questions Per Test:</label></td><td><input type="text" name="txtQuestionCount" id="txtQuestionCount" value="$quiz_questionspertest" /></td></tr>
00497                                 <tr><td><label for="txtQuestionsPerPage">Questions Per Page:</label></td><td><input type="text" name="txtQuestionsPerPage" id="txtQuestionsPerPage" value="$quiz_questionsperpage" /></td></tr>
00498                                 <tr><td>Show Timers:</td><td><label><input type="checkbox" name="chkShowTimerPerTest" id="chkShowTimerPerTest" value="pertest" $quiz_showtesttimer /> Per Test</label> <label><input type="checkbox" name="chkShowTimerPerPage" id="chkShowTimerPerPage" value="perpage" $quiz_showpagetimer /> Per Page</label></td></tr>
00499                                 <tr><td><label>Allow Random Access to Sections?</label></td><td><label><input type="checkbox" id="chkSectionRandomAccess" name="chkSectionRandomAccess" $quiz_sectionrandomaccess /> Yes</label></td></tr>
00500                                 <tr><td><label>Mix Sections?</label></td><td><label><input type="checkbox" name="chkMixSections" id="chkMixSections" value="mixsections" $quiz_mixsections /> Yes</label></td></tr>
00501                                 <tr><td><label for="txtOpenTime">Opening Time:</label></td><td><input type="text" name="txtOpenTime" id="txtOpenTime" value="$quiz_startdatetime" /><input name="calc" type="reset" value="  ...  " onclick="return showCalendar('txtOpenTime', '%Y-%m-%d %H:%M:%S', '24', true);" /></td></tr>
00502                                 <tr><td><label for="txtCloseTime">Closing Time:</label></td><td><input type="text" name="txtCloseTime" id="txtCloseTime" value="$quiz_closedatetime" /><input name="calc" type="reset" value="  ...  " onclick="return showCalendar('txtCloseTime', '%Y-%m-%d %H:%M:%S', '24', true);" /></td></tr>
00503                         </table>
00504                 </fieldset>
00505                 
00506                 <fieldset id="quizWeightMarks">
00507                 <legend>Weight - Marks</legend>
00508                 {$setWeightMarks}
00509                 </fieldset>
00510                 
00511                 <fieldset style="padding:8px" id="quizTypeSpecificProperties">
00512                         <legend>Quiz Type Specific Properties</legend>
00513 QUIZEDITFORM;
00514 
00515         $quizTypes = getQuizTypes();
00516         for ($i = 0; $i < count($quizTypes); ++$i) {
00517                 $quizObjectClassName = ucfirst($quizTypes[$i]) . 'Quiz';
00518                 $quizObject = new $quizObjectClassName($quizId);
00519                 $quizEditForm .= "<div id=\"{$quizTypes[$i]}QuizProperties\">" . $quizObject->getPropertiesForm($dataSource) . "</div>\n";
00520         }
00521 
00522         $quizEditForm .= <<<QUIZEDITFORM
00523                 </fieldset>
00524                 <script type="text/javascript">
00525                         function quizTypeChanged(e) {
00526                                 var selQuizType = document.getElementById('selQuizType');
00527                                 var showId = selQuizType.value + 'QuizProperties';
00528                                 var options = selQuizType.getElementsByTagName('option');
00529 
00530                                 for (var i = 0; i < options.length; ++i) {
00531                                         var curId = options[i].value + 'QuizProperties';
00532                                         document.getElementById(curId).style.display = (curId == showId ? '' : 'none');
00533                                 }
00534                         }
00535 
00536                         function validateAddQuestions(form) {
00537                                 var questionCount = form.txtQuestionCount.value;
00538                                 if (!/^\d+$/.test(questionCount)) {
00539                                         alert('Please enter the number of questions to add.');
00540                                         return false;
00541                                 }
00542                                 questionCount = parseInt(sectionCount);
00543                                 if (questionCount <= 0) {
00544                                         alert('Please enter a positive number of questions to add.');
00545                                         return false;
00546                                 }
00547                                 if (questionCount > 100)
00548                                         if (!confirm('You are about to add ' + questionCount + ' questions. Are you sure you wish to do this?'))
00549                                                 return false;
00550                                 return true;
00551                         }
00552 
00553                         function validateAddSections() {
00554                                 var sectionCount = document.getElementById('txtSectionCount').value;
00555                                 if (!/^\d+$/.test(sectionCount)) {
00556                                         alert('Please enter the number of sections to add.');
00557                                         return false;
00558                                 }
00559                                 sectionCount = parseInt(sectionCount);
00560                                 if (sectionCount <= 0) {
00561                                         alert('Please enter a positive number of sections to add.');
00562                                         return false;
00563                                 }
00564                                 if (sectionCount > 100)
00565                                         if (!confirm('You are about to add ' + sectionCount + ' sections. Are you sure you wish to do this?'))
00566                                                 return false;
00567                                 return true;
00568                         }
00569                         document.getElementById('selQuizType').onchange = quizTypeChanged;
00570                         quizTypeChanged(null);
00571                 </script>
00572                 <br />
00573                 <input type="submit" name="btnSubmit" value="Submit" />
00574         </form>
00575         <hr />
00576 
00577         <fieldset style="padding:8px">
00578                 <legend>Sections</legend>
00579 QUIZEDITFORM;
00580 
00581         global $urlRequestRoot, $sourceFolder, $templateFolder,$cmsFolder;
00582         $editImage = "<img style=\"padding:0px\" src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/apps/accessories-text-editor.png\" alt=\"Edit\" />";
00583         $deleteImage = "$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/edit-delete.png";
00584         $moveUpImage = "<img src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/go-up.png\" alt=\"Move Section Up\" />";
00585         $moveDownImage = "<img src=\"$urlRequestRoot/$cmsFolder/$templateFolder/common/icons/16x16/actions/go-down.png\" alt=\"Move Section Down\" />";
00586 
00587         $quizSections = getSectionList($quizId);
00588         $questionTypes = getQuestionTypes();
00589 
00590         $sectionCount = count($quizSections);
00591         for ($i = 0; $i < $sectionCount; ++$i) {
00592                 $moveUp = ($i == 0 ? '' : "<a href=\"./+edit&subaction=movesection&direction=up&sectionid={$quizSections[$i]['quiz_sectionid']}\" />$moveUpImage</a>");
00593                 $moveDown = ($i == $sectionCount - 1 ? '' : "<a href=\"./+edit&subaction=movesection&direction=down&sectionid={$quizSections[$i]['quiz_sectionid']}\" />$moveDownImage</a>");
00594                 $stats = array();
00595                 foreach ($questionTypes as $questionTypeName => $questionTypeTitle)
00596                         $stats[] = $quizSections[$i]['quiz_section' . $questionTypeName . 'count'] . ' ' . $questionTypeTitle . ' question(s)';
00597                 $stats = implode(', ', $stats) . ' to be chosen from this section.';
00598                 $timeLimit = $quizSections[$i]['quiz_sectiontimelimit'] == '00:00:00' ? 'No Time Limit' : $quizSections[$i]['quiz_sectiontimelimit'];
00599 
00600                 $questionTable = getQuestionTableHtml($quizId, $quizSections[$i]['quiz_sectionid']);
00601 
00602                 $quizEditForm .= <<<SECTIONTEXT
00603                         <h3>Section: {$quizSections[$i]['quiz_sectiontitle']}</h3>
00604                         Options:
00605                                 <a href="./+edit&subaction=editsection&sectionid={$quizSections[$i]['quiz_sectionid']}">$editImage</a>
00606                                 <form style="display:inline;" name="deletesectionform" method="POST" action="./+edit&subaction=deletesection" onsubmit="return confirm('You are about to delete a complete section. This will delete all questions that belong to that section. Are you sure you wish to proceed?')">
00607                                         <input type="hidden" name="hdnSectionId" value="{$quizSections[$i]['quiz_sectionid']}" />
00608                                         <input type="image" name="btnDelete" id="btnDelete" src="$deleteImage" />
00609                                 </form>
00610                                 $moveUp
00611                                 $moveDown
00612                         <p>$stats</p>
00613                         <p>Time limit: $timeLimit</p>
00614 
00615                         $questionTable
00616 
00617                         <form name="questionaddform" action="./+edit&subaction=addquestions&sectionid={$quizSections[$i]['quiz_sectionid']}" method="POST" onsubmit="return validateAddQuestions(this)">
00618                                 <p>Add <input type="text" name="txtQuestionCount" value="1" size="3" /> Questions
00619                                 <input type="submit" name="btnAddQuestions" value="Go" />
00620                         </form>
00621 
00622                         <p></p>
00623                         <hr />
00624                         <br />
00625 SECTIONTEXT;
00626         }
00627 
00628         $quizEditForm .= <<<QUIZEDITFORM
00629 
00630         <form name="sectionaddform" action="./+edit&subaction=addsections" method="POST" onsubmit="return validateAddSections()">
00631                 <p>
00632                         Add <input type="text" size="3" name="txtSectionCount" id="txtSectionCount" value="1" /> Section(s)
00633                         <input type="submit" name="btnAddSections" id="btnAddSections" value="Go" />
00634                 </p>
00635         </fieldset>
00636 QUIZEDITFORM;
00637         return $quizEditForm;
00638 }
00639 
00644 function getSectionEditForm($quizId, $sectionId, $dataSource) {
00645         $fieldMap = getSectionEditFormFieldMap();
00646 
00647         if ($dataSource == 'POST') {
00648                 for ($i = 0; $i < count($fieldMap); ++$i) {
00649                         if ($fieldMap[$i][3] == 'chk')
00650                                 $$fieldMap[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? 'checked="checked"' : '';
00651                         else
00652                                 $$fieldMap[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? htmlentities(safe_html($_POST[$fieldMap[$i][0]])) : '';
00653                 }
00654         }
00655         elseif ($dataSource == 'db') {
00656                 $sectionRow = getSectionRow($quizId, $sectionId);
00657                 if (!$sectionRow) {
00658                         displayerror('Error. Could not load information about the specified section. Section not found.');
00659                         return '';
00660                 }
00661                 for ($i = 0; $i < count($fieldMap); ++$i) {
00662                         if ($fieldMap[$i][3] == 'checkbox')
00663                                 $$fieldMap[$i][2] = isset($sectionRow[$fieldMap[$i][1]]) && $sectionRow[$fieldMap[$i][1]] != 0 ? 'checked="checked"' : '';
00664                         else
00665                                 $$fieldMap[$i][2] = isset($sectionRow[$fieldMap[$i][1]]) ? htmlentities($sectionRow[$fieldMap[$i][1]]) : '';
00666                 }
00667         }
00668 
00669         $sectionEditForm = <<<SECTIONEDITFORM
00670                 <form name="sectioneditform" action="" method="POST">
00671                         <fieldset style="padding:8px">
00672                                 <legend>Edit Section Properties</legend>
00673 
00674                                 <table border="0">
00675                                         <tr><td><label for="txtSectionTitle">Section Title:</label></td><td><input type="text" name="txtSectionTitle" id="txtSectionTitle" value="$section_sectiontitle" /></td></tr>
00676                                         <tr><td><label for="txtSSOCount">Number of Single Select Objective Questions:</label></td><td><input type="text" name="txtSSOCount" id="txtSSOCount" value="$section_ssocount" /></td></tr>
00677                                         <tr><td><label for="txtMSOCount">Number of Multi-select Objective Questions:</label></td><td><input type="text" name="txtMSOCount" id="txtMSOCount" value="$section_msocount" /></td></tr>
00678                                         <tr><td><label for="txtSubjectiveCount">Number of Subjective Questions:</label></td><td><input type="text" name="txtSubjectiveCount" id="txtSubjectiveCount" value="$section_subjectivecount" /></td></tr>
00679                                         <tr><td><label for="txtSessionTimeLimit">Time Limit:</label></td><td><input type="text" name="txtSessionTimeLimit" id="txtSessionTimeLimit" value="$section_timelimit" /></td></tr>
00680                                         <tr><td><label>Show Limit?</label></td><td><label><input type="checkbox" name="chkShowLimit" id="chkShowLimit" value="yes" $section_showlimit /> Yes</label></td></tr>
00681                                         <tr><td><label>Shuffle Questions?</label></td><td><label><input type="checkbox" name="chkShuffle" id="chkShuffle" value="yes" $section_shuffle /> Yes</label></td></tr>
00682                                 </table>
00683                         </fieldset>
00684 
00685                         <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
00686                 </form>
00687 
00688                 <p><a href="./+edit">&laquo; Back to Quiz Properties</a></p>
00689 SECTIONEDITFORM;
00690 
00691         return $sectionEditForm;
00692 }
00693 
00698 function getQuestionEditForm($quizId, $sectionId, $questionId, $dataSource) {
00699         $fieldMap = getQuestionEditFormFieldMap();
00700         $question_type = 'subjective';
00701 
00702         if ($dataSource == 'POST') {
00703                 for ($i = 0; $i < count($fieldMap); ++$i) {
00704                         if ($fieldMap[$i][3] == 'chk')
00705                                 $$fieldMap[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? 'checked="checked"' : '';
00706                         else
00707                                 $$fieldMap[$i][2] = isset($_POST[$fieldMap[$i][0]]) ? htmlentities(safe_html($_POST[$fieldMap[$i][0]])) : '';
00708                 }
00709         }
00710         elseif ($dataSource == 'db') {
00711                 $questionRow = getQuestionRow($quizId, $sectionId, $questionId);
00712                 if (!$questionRow) {
00713                         displayerror('Error. Could not load information about the specified section. Section not found.');
00714                         return '';
00715                 }
00716                 for ($i = 0; $i < count($fieldMap); ++$i) {
00717                         if ($fieldMap[$i][3] == 'checkbox')
00718                                 $$fieldMap[$i][2] = isset($questionRow[$fieldMap[$i][1]]) && $questionRow[$fieldMap[$i][1]] != 0 ? 'checked="checked"' : '';
00719                         else
00720                                 $$fieldMap[$i][2] = isset($questionRow[$fieldMap[$i][1]]) ? htmlentities($questionRow[$fieldMap[$i][1]]) : '';
00721                 }
00722         }
00723 
00724         $questionTypeBox = getQuestionTypeBox($question_type);
00725         $solutionContainer = '';
00726         if ($question_type == 'subjective') {
00727                 $solutionContainer .= '<textarea name="txtRightAnswer" id="txtRightAnswer" rows="5" cols="36">';
00728                 if ($dataSource == 'POST') {
00729                         $solutionContainer .= (isset($_POST['txtRightAnswer']) ? htmlentities(safe_html($_POST['txtRightAnswer'])) : '') . '</textarea>';
00730                 }
00731                 elseif ($dataSource == 'db') {
00732                         $solutionContainer .= (isset($questionRow['quiz_rightanswer']) ? htmlentities($questionRow['quiz_rightanswer']) : '');
00733                 }
00734                 $solutionContainer .= '</textarea>';
00735         }
00736         else {
00737                 if ($dataSource == 'POST') {
00738                         $solutionContainer .= getSubmittedQuestionOptionListHtml($question_type);
00739                 }
00740                 elseif ($dataSource == 'db') {
00741                         $solutionContainer .= getQuestionOptionListHtml($quizId, $sectionId, $questionId, $question_type, $questionRow['quiz_rightanswer'], true);
00742                 }
00743         }
00744 
00745         $questionEditForm = <<<QUESTIONEDITFORM
00746                 <fieldset><legend>Question Properties</legend>
00747                 <form name="questioneditform" method="POST" onSubmit="return validate();" action="">
00748                         <table border="0" width="100%">
00749                                 <tr><td><label for="txtQuestion">Question:</label></td><td><textarea name="txtQuestion" id="txtQuestion" rows="5" cols="36">$question_question</textarea></td></tr>
00750                                 <tr><td><label for="selQuestionType">Question Type:</label></td><td>$questionTypeBox</td></tr>
00751                                 <tr><td><label for="txtQuestionWeight">Question Weight:</label></td><td><input type="text" name="txtQuestionWeight" id="txtQuestionWeight" value="$question_weight" /></td></tr>
00752                         </table>
00753 
00754                         <p><strong>Answers</strong></p>
00755                         <p>In case of subjective questions, you can provide a hint to the solution here to help during correction.</p>
00756                         <p>In case of objective questions, please type in the options, and check the right answer(s).</p>
00757                         <div id="solutionContainer">$solutionContainer</div>
00758 
00759                         <script type="text/javascript">
00760                                 var questionType = '$question_type';
00761                                 var objectiveOptions = new Array();
00762                                 var subjectiveAnswer = '';
00763                                 function validate() {
00764                                         var elementCount = document.getElementById('optionsTable').getElementsByTagName('tr').length;
00765                                         if(elementCount > 1)
00766                                                 return true;
00767                                         alert('No answer/option specified');
00768                                         return false;
00769                                 }
00770 
00771                                 function addOption() {
00772                                         var optionsTable = document.getElementById('optionsTable');
00773                                         var elementCount = optionsTable.getElementsByTagName('tr').length;
00774                                         var elementName = (questionType == 'sso' ? 'opt' : 'chk') + 'Option';
00775                                         if (questionType == 'mso')
00776                                                 elementName += elementCount;
00777                                         var elementId = (questionType == 'sso' ? 'opt' : 'chk') + 'Option' + elementCount;
00778                                         var elementType = (questionType == 'sso' ? 'radio' : 'checkbox');
00779                                         var optionsRow = document.createElement('tr');
00780                                         var td1 = document.createElement('td');
00781                                         var td2 = document.createElement('td');
00782                                         td1.innerHTML = '<input type="' + elementType + '" id="' + elementId + '" name="' + elementName + '" value="' + elementCount + '" />';
00783                                         td2.innerHTML = '<input type="text" name="txtOptionText' + elementCount + '" id="txtOptionText' + elementCount + '" value="" />';
00784                                         optionsRow.appendChild(td1);
00785                                         optionsRow.appendChild(td2);
00786                                         var tbody = optionsTable.getElementsByTagName('tbody');
00787                                         if (tbody.length) {
00788                                                 tbody = tbody[0];
00789                                                 if (tbody.parentNode == optionsTable)
00790                                                         tbody.appendChild(optionsRow);
00791                                         }
00792                                         else
00793                                                 optionsTable.appendChild(optionsRow);
00794                                 }
00795 
00796                                 function questionTypeChanged(e) {
00797                                         var newQuestionType = document.getElementById('selQuestionType').value;
00798                                         var solutionContainer = document.getElementById('solutionContainer');
00799 
00800                                         if (questionType == 'sso' || questionType == 'mso') {
00801                                                 objectiveOptions = new Array();
00802                                                 var i = 0;
00803                                                 while (true) {
00804                                                         var option = document.getElementById('txtOptionText' + i);
00805                                                         var boxId = (questionType == 'sso' ? 'opt' : 'chk') + 'Option' + i;
00806                                                         var box = document.getElementById(boxId);
00807                                                         if (option)
00808                                                                 objectiveOptions.push(new Array(option.value, box.checked));
00809                                                         else
00810                                                                 break;
00811                                                         ++i;
00812                                                 }
00813                                         }
00814                                         else if (questionType == 'subjective') {
00815                                                 var txtRightAnswer = document.getElementById('txtRightAnswer');
00816                                                 if (txtRightAnswer)
00817                                                         subjectiveAnswer = txtRightAnswer.innerHTML;
00818                                         }
00819 
00820                                         var innerHTML = '';
00821                                         if (newQuestionType == 'sso' || newQuestionType == 'mso') {
00822                                                 innerHTML = '<table border="0" id="optionsTable">'
00823                                                 var inputType = newQuestionType == 'sso' ? 'radio' : 'checkbox';
00824                                                 var inputTypePrefix = newQuestionType == 'sso' ? 'opt' : 'chk';
00825                                                 for (var i = 0; i < objectiveOptions.length; ++i) {
00826                                                         var elementName = inputTypePrefix + 'Option';
00827                                                         var elementId = elementName + i;
00828                                                         if (newQuestionType == 'mso')
00829                                                                 elementName += i;
00830                                                         innerHTML +=
00831                                                                 '<tr><td><input type="' + inputType + '" name="' + elementName + '" id="' + elementId + '"' + (objectiveOptions[i][1] ? ' checked="checked"' : '') + ' /></td>' +
00832                                                                 '<td><input type="text" name="txtOptionText' + i + '" id="txtOptionText' + i + '" value="' + objectiveOptions[i][0] + '" /></td></tr>';
00833                                                 }
00834                                                 innerHTML += '</table>';
00835                                                 innerHTML += '<input type="button" name="btnAddOption" onclick="addOption()" value="Add Option" />'
00836                                         }
00837                                         else {
00838                                                 innerHTML += '<textarea name="txtRightAnswer" id="txtRightAnswer" rows="5" cols="36">' + subjectiveAnswer + '</textarea>';
00839                                         }
00840 
00841                                         solutionContainer.innerHTML = innerHTML;
00842 
00843                                         questionType = newQuestionType;
00844                                 }
00845 
00846                                 document.getElementById('selQuestionType').onchange = questionTypeChanged;
00847                         </script>
00848                         <input type="submit" name="btnSubmit" id="btnSubmit" value="Save Question" />
00849                 </form>
00850                 </fieldset>
00851                 <p><a href="./+edit">&laquo; Back to Quiz Properties</a></p>
00852 QUESTIONEDITFORM;
00853         return $questionEditForm;
00854 }
00855 
00856 
00861 function submitQuizEditForm($quizId) {
00862         $fieldMap = getQuizEditFormFieldMap();
00863         $updates = array();
00864 
00865         for ($i = 0; $i < count($fieldMap); ++$i) {
00866                 $update = "`{$fieldMap[$i][1]}` = ";
00867                 if ($fieldMap[$i][3] == 'checkbox') {
00868                         $update .= (isset($_POST[$fieldMap[$i][0]]) ? '1' : '0');
00869                 }
00870                 else {
00871                         if (!isset($_POST[$fieldMap[$i][0]]))
00872                                 continue;
00873                         $update .= "'" . ($_POST[$fieldMap[$i][0]]) . "'";
00874                 }
00875                 $updates[] = $update;
00876         }
00877 
00878         if (count($updates) == 0)
00879                 return true;
00880 
00881         $updateQuery = 'UPDATE `quiz_descriptions` SET ' . implode(', ', $updates) . " WHERE `page_modulecomponentid` = $quizId";
00882         if (!mysql_query($updateQuery)) {
00883                 displayerror('Database Error. Could not save quiz form. ' . $updateQuery . ' ' . mysql_error());
00884                 return false;
00885         }
00886 
00887         return true;
00888 }
00889 
00894 function submitSectionEditForm($quizId, $sectionId) {
00895         $fieldMap = getSectionEditFormFieldMap();
00896         $updates = array();
00897         for ($i = 0; $i < count($fieldMap); ++$i) {
00898                 $update = "`{$fieldMap[$i][1]}` = ";
00899                 if ($fieldMap[$i][3] == 'checkbox') {
00900                         $update .= (isset($_POST[$fieldMap[$i][0]]) ? '1' : '0');
00901                 }
00902                 else {
00903                         if (!isset($_POST[$fieldMap[$i][0]]))
00904                                 continue;
00905                         $update .= "'" . safe_html($_POST[$fieldMap[$i][0]]) . "'";
00906                 }
00907                 $updates[] = $update;
00908         }
00909 
00910         if (count($updates) == 0)
00911                 return true;
00912 
00913         $updateQuery = "UPDATE `quiz_sections` SET " . implode(', ', $updates) . " WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId";
00914 
00915         if (!mysql_query($updateQuery)) {
00916                 displayerror('Database Error. Could not save section details.');
00917                 return false;
00918         }
00919         return true;
00920 }
00921 
00927 function submitQuestionEditForm($quizId, $sectionId, $questionId) {
00928         $updates = array();
00929         if (isset($_POST['txtQuestion']))
00930                 $updates[] = "`quiz_question` = '" . escape($_POST['txtQuestion']) . "'";
00931         if (isset($_POST['selQuestionType']) && in_array($_POST['selQuestionType'], array_keys(getQuestionTypes())))
00932                 $updates[] = "`quiz_questiontype` = '" . escape($_POST['selQuestionType']) . "'";
00933         else {
00934                 displayerror('No or invalid question type specified.');
00935                 return false;
00936         }
00937 
00938         if (isset($_POST['txtQuestionWeight']) && is_numeric($_POST['txtQuestionWeight']) && $_POST['txtQuestionWeight'] > 0)
00939                 $updates[] = "`quiz_questionweight` = " . escape($_POST['txtQuestionWeight']);
00940 
00941         deleteQuestionOptions($quizId, $sectionId, $questionId);
00942 
00943         $questionType = escape($_POST['selQuestionType']);
00944         if ($questionType != 'subjective') {
00945                 $i = 0;
00946                 $rightAnswer = array();
00947                 while (true) {
00948                         if (!isset($_POST['txtOptionText' . $i]) || $_POST["txtOptionText$i"] == '')
00949                                 break;
00950                         $optionText = escape($_POST['txtOptionText' . $i]);
00951                         $insertQuery = "INSERT INTO `quiz_objectiveoptions`(`page_modulecomponentid`, `quiz_sectionid`, `quiz_questionid`, `quiz_optiontext`, `quiz_optionrank`) " .
00952                                         "SELECT $quizId, $sectionId, $questionId, '{$optionText}', IFNULL(MAX(`quiz_optionrank`), 0) + 1 FROM `quiz_objectiveoptions` WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `quiz_questionid` = $questionId LIMIT 1";
00953                         if (!mysql_query($insertQuery)) {
00954                                 displayerror('Database Error. Could not insert options.');
00955                                 return false;
00956                         }
00957                         $optionId = mysql_insert_id();
00958 
00959                         if (
00960                                 ($questionType == 'sso' && isset($_POST['optOption']) && $_POST['optOption'] == $i) ||
00961                                 ($questionType == 'mso' && isset($_POST['chkOption' . $i]))
00962                         )
00963                                 $rightAnswer[] = $optionId;
00964                         ++$i;
00965                 }
00966                 if(!isset($rightAnswer[0])) {
00967                         displayerror('No options specified for objective answer');
00968                         return false;
00969                 }
00970                 $rightAnswer = implode('|', $rightAnswer);
00971         }
00972         else {
00973                 $rightAnswer = isset($_POST['txtRightAnswer']) ? safe_html($_POST['txtRightAnswer']) : '';
00974         }
00975         $updates[] = "`quiz_rightanswer` = '{$rightAnswer}'";
00976 
00977         $updateQuery = "UPDATE `quiz_questions` SET " . implode(', ', $updates) . " WHERE `page_modulecomponentid` = $quizId AND `quiz_sectionid` = $sectionId AND `quiz_questionid` = $questionId";
00978         if (!mysql_query($updateQuery)) {
00979                 displayerror('Database Error. Could not save section details. ' . $updateQuery . ' ' . mysql_error());
00980                 return false;
00981         }
00982 
00983         return true;
00984 }

Generated on Mon Mar 14 2011 05:35:30 for Pragyan CMS by  doxygen 1.7.1