Parcourir la source

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

Luk Vanlanduyt il y a 18 ans
Parent
commit
af999c00a4

+ 6 - 1
main/exercice/exercice_submit.php

@@ -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
@@ -402,6 +402,9 @@ if(!empty($exerciseSound))
 $number_of_hotspot_questions = 0;
 $onsubmit = '';
 $i=0;
+
+var_dump($questionList);
+
 foreach($questionList as $questionId)
 {
 	$i++;
@@ -434,6 +437,8 @@ foreach($questionList as $questionId)
 	}
 }
 
+echo ':' . $number_of_hotspot_questions;
+
 if($number_of_hotspot_questions > 0)
 {
 	$onsubmit = "onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '".get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."')\"";

+ 23 - 3
main/exercice/exercise_result.php

@@ -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
@@ -214,7 +214,21 @@ function display_free_answer($answer)
 
 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>
 				<td width="25%" valign="top">
@@ -258,13 +272,17 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 	$res = api_sql_query($sql, __FILE__, __LINE__);
 	$exeId =mysql_result($res,0,"id");
 	$exeId=$exeId+1;
+	
+	var_dump($questionList);
+	
 	foreach($questionList as $questionId)
 	{
 		// gets the student choice for this question
 		$choice=$exerciseResult[$questionId];
 		// creates a temporary Question object
 		$objQuestionTmp=new Question();
-
+		
+		echo $questionId;
 		$objQuestionTmp->read($questionId);
 
 		$questionName=$objQuestionTmp->selectTitle();
@@ -344,6 +362,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 		}
 		elseif($answerType == HOT_SPOT)
 		{
+			echo $questionId;
 			?>			
 				<tr>
 					<td width="40%">
@@ -583,6 +602,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 				}
 				elseif($answerType == HOT_SPOT)
 				{
+					echo $answerId . ':' . $answer . ':' . $studentChoice . ':' . $answerComment;
 					display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
 				}
 				else

+ 6 - 0
main/exercice/hotspot_actionscript.as.php

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

+ 10 - 3
main/exercice/hotspot_answers.as.php

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

+ 104 - 8
main/exercice/question.class.php

@@ -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
@@ -80,15 +80,15 @@ class Question
 	 */
 	function read($id)
 	{
-	
 		global $_course;
+		
 		$TBL_EXERCICES         = $_course['dbNameGlu'].'quiz';
 		$TBL_QUESTIONS         = $_course['dbNameGlu'].'quiz_question';
 		$TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question';
-
 		$sql="SELECT question,description,ponderation,position,type,picture FROM `$TBL_QUESTIONS` WHERE id='$id'";
+		
 		$result=api_sql_query($sql,__FILE__,__LINE__);
-
+		
 		// if the question has been found
 		if($object=mysql_fetch_object($result))
 		{
@@ -306,12 +306,100 @@ class Question
 			$Extension=$PictureName[sizeof($PictureName)-1];
 
 	  		$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;
 	}
+	
+	/**
+	 * 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
@@ -427,7 +515,7 @@ class Question
 	 */
 	function save($exerciseId=0)
 	{
-		global $TBL_QUESTIONS;
+		global $TBL_QUESTIONS, $_course;
 
 		$id=$this->id;
 		$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')";
 			api_sql_query($sql,__FILE__,__LINE__);
-
+			
 			$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

+ 64 - 30
main/exercice/statement_admin.inc.php

@@ -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
@@ -61,11 +61,26 @@ if($submitQuestion)
     $questionName=trim(stripslashes($_POST['questionName']));
     $questionDescription=trim(stripslashes($_POST['questionDescription']));
     $_FILES['imageUpload']['name']=strtolower($_FILES['imageUpload']['name']);
-
+    
+    $hotspotErr = false;
+    
     // 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
     elseif($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1)
@@ -139,39 +154,58 @@ if($submitQuestion)
                 else
                 {
                     $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);
-        }
-
-        $questionId=$objQuestion->selectId();
-
-        if($exerciseId)
-        {
-            // adds the question ID into the question list of the Exercise object
-            if($objExercise->addToList($questionId))
+            
+            if($hotspotErr === false)
             {
-                $objExercise->save();
-
-                $nbrQuestions++;
+            	$objQuestion->save($exerciseId);
+            }
+            else
+            {
+            	if($newQuestion)
+            		$objQuestion->removeFromList($exerciseId);
             }
         }
-
-        if($newQuestion)
-        {
-            // goes to answer administration
-            // -> answer_admin.inc.php
-            $modifyAnswers=$questionId;
-        }
-        else
+        
+        if($hotspotErr === false)
         {
-            // goes to exercise viewing
-            $editQuestion=$questionId;
+        	$questionId=$objQuestion->selectId();
+
+	        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";}
 

+ 3 - 3
main/plugin/hotspot/hotspot.js

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