[svn r10234] hotspot fixes (still does not work, but we are on the good way)

skala
Luk Vanlanduyt 19 years ago
parent e2b7983621
commit af999c00a4
  1. 7
      main/exercice/exercice_submit.php
  2. 26
      main/exercice/exercise_result.php
  3. 6
      main/exercice/hotspot_actionscript.as.php
  4. 13
      main/exercice/hotspot_answers.as.php
  5. 112
      main/exercice/question.class.php
  6. 94
      main/exercice/statement_admin.inc.php
  7. 6
      main/plugin/hotspot/hotspot.js

@ -1,4 +1,4 @@
<?php // $Id: exercice_submit.php 10204 2006-11-26 20:46:53Z pcool $ <?php // $Id: exercice_submit.php 10234 2006-11-28 13:43:34Z develop-it $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -402,6 +402,9 @@ if(!empty($exerciseSound))
$number_of_hotspot_questions = 0; $number_of_hotspot_questions = 0;
$onsubmit = ''; $onsubmit = '';
$i=0; $i=0;
var_dump($questionList);
foreach($questionList as $questionId) foreach($questionList as $questionId)
{ {
$i++; $i++;
@ -434,6 +437,8 @@ foreach($questionList as $questionId)
} }
} }
echo ':' . $number_of_hotspot_questions;
if($number_of_hotspot_questions > 0) if($number_of_hotspot_questions > 0)
{ {
$onsubmit = "onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '".get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."')\""; $onsubmit = "onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '".get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."')\"";

@ -1,4 +1,4 @@
<?php // $Id: exercise_result.php 10204 2006-11-26 20:46:53Z pcool $ <?php // $Id: exercise_result.php 10234 2006-11-28 13:43:34Z develop-it $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -214,7 +214,21 @@ function display_free_answer($answer)
function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment) function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
{ {
global $hotspot_colors; //global $hotspot_colors;
$hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
"#4271B5",
"#FE8E16",
"#3B3B3B",
"#BCD631",
"#D63173",
"#D7D7D7",
"#90AFDD",
"#AF8640",
"#4F9242",
"#F4EB24",
"#ED2024",
"#45C7F0",
"#F7BDE2");
?> ?>
<tr> <tr>
<td width="25%" valign="top"> <td width="25%" valign="top">
@ -258,13 +272,17 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
$res = api_sql_query($sql, __FILE__, __LINE__); $res = api_sql_query($sql, __FILE__, __LINE__);
$exeId =mysql_result($res,0,"id"); $exeId =mysql_result($res,0,"id");
$exeId=$exeId+1; $exeId=$exeId+1;
var_dump($questionList);
foreach($questionList as $questionId) foreach($questionList as $questionId)
{ {
// gets the student choice for this question // gets the student choice for this question
$choice=$exerciseResult[$questionId]; $choice=$exerciseResult[$questionId];
// creates a temporary Question object // creates a temporary Question object
$objQuestionTmp=new Question(); $objQuestionTmp=new Question();
echo $questionId;
$objQuestionTmp->read($questionId); $objQuestionTmp->read($questionId);
$questionName=$objQuestionTmp->selectTitle(); $questionName=$objQuestionTmp->selectTitle();
@ -344,6 +362,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
} }
elseif($answerType == HOT_SPOT) elseif($answerType == HOT_SPOT)
{ {
echo $questionId;
?> ?>
<tr> <tr>
<td width="40%"> <td width="40%">
@ -583,6 +602,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
} }
elseif($answerType == HOT_SPOT) elseif($answerType == HOT_SPOT)
{ {
echo $answerId . ':' . $answer . ':' . $studentChoice . ':' . $answerComment;
display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment); display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
} }
else else

@ -109,5 +109,11 @@
// Output // Output
echo $output."&nmbrTries=".$nmbrTries."&done=done"; echo $output."&nmbrTries=".$nmbrTries."&done=done";
/*echo '<pre>';
var_dump($explode);
echo '</pre>';*/
?> ?>

@ -42,8 +42,6 @@
$userId = $_user['user_id']; $userId = $_user['user_id'];
$questionId = $_GET['modifyAnswers']; $questionId = $_GET['modifyAnswers'];
$questionId = 7;
$objQuestion = new Question(); $objQuestion = new Question();
$objQuestion->read($questionId); $objQuestion->read($questionId);
@ -115,9 +113,18 @@
$output2 .= $coordinate."|"; $output2 .= $coordinate."|";
} }
var_dump($_SESSION['exerciseResultCoordinates']); //var_dump($_SESSION['exerciseResultCoordinates']);
// Output // Output
$output .= "&p_hotspot_answers=".substr($output2,0,-1)."&done=done"; $output .= "&p_hotspot_answers=".substr($output2,0,-1)."&done=done";
$explode = explode('&', $output);
/*echo '<pre>';
var_dump($explode);
echo '</pre>';*/
echo $output; echo $output;
?> ?>

@ -1,4 +1,4 @@
<?php // $Id: question.class.php 9665 2006-10-24 10:43:48Z elixir_inter $ <?php // $Id: question.class.php 10234 2006-11-28 13:43:34Z develop-it $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -80,15 +80,15 @@ class Question
*/ */
function read($id) function read($id)
{ {
global $_course; global $_course;
$TBL_EXERCICES = $_course['dbNameGlu'].'quiz'; $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
$TBL_QUESTIONS = $_course['dbNameGlu'].'quiz_question'; $TBL_QUESTIONS = $_course['dbNameGlu'].'quiz_question';
$TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question'; $TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question';
$sql="SELECT question,description,ponderation,position,type,picture FROM `$TBL_QUESTIONS` WHERE id='$id'"; $sql="SELECT question,description,ponderation,position,type,picture FROM `$TBL_QUESTIONS` WHERE id='$id'";
$result=api_sql_query($sql,__FILE__,__LINE__); $result=api_sql_query($sql,__FILE__,__LINE__);
// if the question has been found // if the question has been found
if($object=mysql_fetch_object($result)) if($object=mysql_fetch_object($result))
{ {
@ -306,12 +306,100 @@ class Question
$Extension=$PictureName[sizeof($PictureName)-1]; $Extension=$PictureName[sizeof($PictureName)-1];
$this->picture='quiz-'.$this->id.'.'.$Extension; $this->picture='quiz-'.$this->id.'.'.$Extension;
return move_uploaded_file($Picture,$picturePath.'/'.$this->picture); return move_uploaded_file($Picture,$picturePath.'/'.$this->picture)?true:false;
} }
return false; return false;
} }
/**
* Resizes a picture || Warning!: can only be called after uploadPicture, or if picture is already available in object.
*
* @author - Toon Keppens
* @param - string $Dimension - Resizing happens proportional according to given dimension: height|width|any
* @param - integer $Max - Maximum size
* @return - boolean - true if success, false if failed
*/
function resizePicture($Dimension, $Max)
{
global $picturePath;
// if the question has an ID
if($this->id)
{
// Get dimensions from current image.
$current_img = imagecreatefromjpeg($picturePath.'/'.$this->picture);
$current_image_size = getimagesize($picturePath.'/'.$this->picture);
$current_height = imagesy($current_img);
$current_width = imagesx($current_img);
if($current_image_size[0] < $Max && $current_image_size[1] <$Max)
return true;
elseif($current_height == "")
return false;
// Resize according to height.
if ($Dimension == "height")
{
$resize_scale = $current_height / $Max;
$new_height = $Max;
$new_width = ceil($current_width / $resize_scale);
}
// Resize according to width
if ($Dimension == "width")
{
$resize_scale = $current_width / $Max;
$new_width = $Max;
$new_height = ceil($current_height / $resize_scale);
}
// Resize according to height or width, both should not be larger than $Max after resizing.
if ($Dimension == "any")
{
if ($current_height > $current_width || $current_height == $current_width)
{
$resize_scale = $current_height / $Max;
$new_height = $Max;
$new_width = ceil($current_width / $resize_scale);
}
if ($current_height < $current_width)
{
$resize_scale = $current_width / $Max;
$new_width = $Max;
$new_height = ceil($current_height / $resize_scale);
}
}
// Create new image
$new_img = imagecreatetruecolor($new_width, $new_height);
$bgColor = imagecolorallocate($new_img, 255,255,255);
imagefill($new_img , 0,0 , $bgColor);
// Resize image
imagecopyresized($new_img, $current_img, 0, 0, 0, 0, $new_width, $new_height, $current_width, $current_height);
// Write image to file
$result = imagejpeg($new_img, $picturePath.'/'.$this->picture, 100);
// Delete temperory images, clear memory
imagedestroy($current_img);
imagedestroy($new_img);
if ($result)
{
return true;
}
else
{
return false;
}
}
}
/** /**
* deletes the picture * deletes the picture
@ -427,7 +515,7 @@ class Question
*/ */
function save($exerciseId=0) function save($exerciseId=0)
{ {
global $TBL_QUESTIONS; global $TBL_QUESTIONS, $_course;
$id=$this->id; $id=$this->id;
$question=addslashes($this->question); $question=addslashes($this->question);
@ -448,8 +536,16 @@ class Question
{ {
$sql="INSERT INTO `$TBL_QUESTIONS`(question,description,ponderation,position,type,picture) VALUES('$question','$description','$weighting','$position','$type','$picture')"; $sql="INSERT INTO `$TBL_QUESTIONS`(question,description,ponderation,position,type,picture) VALUES('$question','$description','$weighting','$position','$type','$picture')";
api_sql_query($sql,__FILE__,__LINE__); api_sql_query($sql,__FILE__,__LINE__);
$this->id=mysql_insert_id(); $this->id=mysql_insert_id();
// If hotspot, create first answer
if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
$TBL_ANSWERS = $_course['dbNameGlu'].'quiz_answer';
$sql="INSERT INTO `$TBL_ANSWERS` (`id` , `question_id` , `answer` , `correct` , `comment` , `ponderation` , `position` , `hotspot_coordinates` , `hotspot_type` ) VALUES ('1', '$this->id', '', NULL , '', NULL , '1', '0;0|0|0', 'square')";
api_sql_query($sql,__FILE__,__LINE__);
}
} }
// if the question is created in an exercise // if the question is created in an exercise

@ -1,4 +1,4 @@
<?php // $Id: statement_admin.inc.php 9972 2006-11-14 14:44:37Z pcool $ <?php // $Id: statement_admin.inc.php 10234 2006-11-28 13:43:34Z develop-it $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -61,11 +61,26 @@ if($submitQuestion)
$questionName=trim(stripslashes($_POST['questionName'])); $questionName=trim(stripslashes($_POST['questionName']));
$questionDescription=trim(stripslashes($_POST['questionDescription'])); $questionDescription=trim(stripslashes($_POST['questionDescription']));
$_FILES['imageUpload']['name']=strtolower($_FILES['imageUpload']['name']); $_FILES['imageUpload']['name']=strtolower($_FILES['imageUpload']['name']);
$hotspotErr = false;
// no name given // no name given
if(empty($questionName)) if(!$modifyQuestion && (empty($questionName) || ($answerType == HOT_SPOT && ($_FILES['imageUpload']['type'] != 'image/jpeg' && $_FILES['imageUpload']['type'] != 'image/pjpeg' && $_FILES['imageUpload']['type'] != 'image/jpg')) || ($answerType == HOT_SPOT && empty($_FILES['imageUpload']['name']))))
{ {
$msgErr=get_lang('GiveQuestion'); if(($_FILES['imageUpload']['type'] != 'image/jpeg' && $_FILES['imageUpload']['type'] != 'image/pjpeg' && $_FILES['imageUpload']['type'] != 'image/jpg') && !$modifyQuestion)
{
$msgErr = get_lang('langOnlyJPG');
$hotspotErr = true;
}
if(empty($_FILES['imageUpload']['name']) && !$modifyQuestion)
{
$msgErr=get_lang('NoImage');
$hotspotErr = true;
}
if(empty($questionName))
{
$msgErr=get_lang('GiveQuestion');
}
} }
// checks if the question is used in several exercises // checks if the question is used in several exercises
elseif($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1) elseif($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1)
@ -139,39 +154,58 @@ if($submitQuestion)
else else
{ {
$objQuestion->uploadPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']); $objQuestion->uploadPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']);
if(!$objQuestion->resizePicture("any", 350))
{
$msgErr = get_lang('langHotspotBadMetadata');
$hotspotErr = true;
$objQuestion->removePicture();
}
} }
} }
$objQuestion->save($exerciseId); if($hotspotErr === false)
}
$questionId=$objQuestion->selectId();
if($exerciseId)
{
// adds the question ID into the question list of the Exercise object
if($objExercise->addToList($questionId))
{ {
$objExercise->save(); $objQuestion->save($exerciseId);
}
$nbrQuestions++; else
{
if($newQuestion)
$objQuestion->removeFromList($exerciseId);
} }
} }
if($newQuestion) if($hotspotErr === false)
{
// goes to answer administration
// -> answer_admin.inc.php
$modifyAnswers=$questionId;
}
else
{ {
// goes to exercise viewing $questionId=$objQuestion->selectId();
$editQuestion=$questionId;
if($exerciseId)
{
// adds the question ID into the question list of the Exercise object
if($objExercise->addToList($questionId))
{
$objExercise->save();
$nbrQuestions++;
}
}
if($newQuestion)
{
// goes to answer administration
// -> answer_admin.inc.php
$modifyAnswers=$questionId;
}
else
{
// goes to exercise viewing
$editQuestion=$questionId;
}
// avoids displaying the following form in case we're editing the answer
unset($newQuestion,$modifyQuestion);
} }
// avoids displaying the following form in case we're editing the answer
unset($newQuestion,$modifyQuestion);
} }
if($debug>0){echo str_repeat('&nbsp;',2).'$submitQuestion is true - end'."<br />\n";} if($debug>0){echo str_repeat('&nbsp;',2).'$submitQuestion is true - end'."<br />\n";}

@ -10,10 +10,10 @@ function validateFlashVar(counter, lang_1, lang_2)
//alert(counter); //alert(counter);
//alert(flashVar); //alert(flashVar);
if(counter!=flashVar) if(counter == flashVar)
{ {
//alert (lang_1 + counter + lang_2); //alert (lang_1 + counter + lang_2);
alert (lang_1); alert(lang_1);
return false; return false;
} }
else else
@ -24,7 +24,7 @@ function validateFlashVar(counter, lang_1, lang_2)
function updateFlashVar() function updateFlashVar()
{ {
//alert('updateFlashVar: ' + flashVar); alert('updateFlashVar: ' + flashVar);
flashVar++; flashVar++;
} }

Loading…
Cancel
Save