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