dokeos-exercise
[ class tree: dokeos-exercise ] [ index: dokeos-exercise ] [ all elements ]

Source for file hotspot_admin.inc.php

Documentation is available at hotspot_admin.inc.php

  1. <?php
  2. /*
  3.     DOKEOS - elearning and course management software
  4.  
  5.     For a full list of contributors, see documentation/credits.html
  6.  
  7.     This program is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU General Public License
  9.     as published by the Free Software Foundation; either version 2
  10.     of the License, or (at your option) any later version.
  11.     See "documentation/licence.html" more details.
  12.  
  13.     Contact:
  14.         Dokeos
  15.         Rue des Palais 44 Paleizenstraat
  16.         B-1030 Brussels - Belgium
  17.         Tel. +32 (2) 211 34 56
  18. */
  19.  
  20.  
  21. /**
  22. *    This script allows to manage answers. It is included from the script admin.php
  23. *    @package dokeos.exercise
  24. *     @author Toon Keppens
  25. *     @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  26. */
  27.  
  28.  
  29. // ALLOWED_TO_INCLUDE is defined in admin.php
  30. if(!defined('ALLOWED_TO_INCLUDE'))
  31. {
  32.     exit();
  33. }
  34.  
  35. $modifyAnswers $_GET['hotspotadmin'];
  36.  
  37. if(!is_object($objQuestion))
  38. {
  39.     $objQuestion Question :: read($modifyAnswers);
  40. }
  41.  
  42. $questionName=$objQuestion->selectTitle();
  43. $answerType=$objQuestion->selectType();
  44. $pictureName=$objQuestion->selectPicture();
  45.  
  46.  
  47. $debug 0// debug variable to get where we are
  48.  
  49. $okPicture=empty($pictureName)?false:true;
  50.  
  51. // if we come from the warning box "this question is used in serveral exercises"
  52. if($modifyIn)
  53. {
  54.     if($debug>0){echo '$modifyIn was set'."<br />\n";}
  55.     // if the user has chosed to modify the question only in the current exercise
  56.     if($modifyIn == 'thisExercise')
  57.     {
  58.         // duplicates the question
  59.         $questionId=$objQuestion->duplicate();
  60.  
  61.         // deletes the old question
  62.         $objQuestion->delete($exerciseId);
  63.  
  64.         // removes the old question ID from the question list of the Exercise object
  65.         $objExercise->removeFromList($modifyAnswers);
  66.  
  67.         // adds the new question ID into the question list of the Exercise object
  68.         $objExercise->addToList($questionId);
  69.  
  70.         // construction of the duplicated Question
  71.         $objQuestion Question :: read($questionId);
  72.  
  73.         // adds the exercise ID into the exercise list of the Question object
  74.         $objQuestion->addToList($exerciseId);
  75.  
  76.         // copies answers from $modifyAnswers to $questionId
  77.         $objAnswer->duplicate($questionId);
  78.  
  79.         // construction of the duplicated Answers
  80.  
  81.         $objAnswer=new Answer($questionId);
  82.     }
  83.  
  84.  
  85.     $color=unserialize($color);
  86.     $reponse=unserialize($reponse);
  87.     $comment=unserialize($comment);
  88.     $weighting=unserialize($weighting);
  89.     $hotspot_coordinates=unserialize($hotspot_coordinates);
  90.     $hotspot_type=unserialize($hotspot_type);
  91.  
  92.  
  93.     unset($buttonBack);
  94. }
  95.  
  96. // the answer form has been submitted
  97. if($submitAnswers || $buttonBack)
  98. {
  99.     if($debug>0){echo '$submitAnswers or $buttonBack was set'."<br />\n";}
  100.  
  101.     $questionWeighting=$nbrGoodAnswers=0;
  102.  
  103.     for($i=1;$i <= $nbrAnswers;$i++)
  104.     {
  105.         if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is HOT_SPOT'."<br />\n";}
  106.  
  107.         $reponse[$i]=trim($reponse[$i]);
  108.         $comment[$i]=trim($comment[$i]);
  109.         $weighting[$i]=intval($weighting[$i]);
  110.  
  111.         // checks if field is empty
  112.         if(empty($reponse[$i]&& $reponse[$i!= '0')
  113.         {
  114.             $msgErr=get_lang('HotspotGiveAnswers');
  115.  
  116.             // clears answers already recorded into the Answer object
  117.             $objAnswer->cancel();
  118.  
  119.             break;
  120.         }
  121.  
  122.         if($weighting[$i<= 0)
  123.         {
  124.             $msgErr=get_lang('HotspotWeightingError');
  125.  
  126.             // clears answers already recorded into the Answer object
  127.             $objAnswer->cancel();
  128.  
  129.             break;
  130.         }
  131.         if($hotspot_coordinates[$i== '0;0|0|0' || empty($hotspot_coordinates[$i]))
  132.         {
  133.             $msgErr=get_lang('HotspotNotDrawn');
  134.  
  135.             // clears answers already recorded into the Answer object
  136.             $objAnswer->cancel();
  137.  
  138.             break;
  139.         }
  140.  
  141.     }  // end for()
  142.  
  143.  
  144.     if(empty($msgErr))
  145.     {
  146.  
  147.         for($i=1;$i <= $nbrAnswers;$i++)
  148.         {
  149.             if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is HOT_SPOT'."<br />\n";}
  150.  
  151.             $reponse[$i]=trim($reponse[$i]);
  152.             $comment[$i]=addslashes(trim($comment[$i]));
  153.             $weighting[$i]=intval($weighting[$i]);
  154.             if($weighting[$i])
  155.             {
  156.                 $questionWeighting+=$weighting[$i];
  157.             }
  158.  
  159.             // creates answer
  160.             $objAnswer->createAnswer($reponse[$i]'',$comment[$i],$weighting[$i],$i,$hotspot_coordinates[$i],$hotspot_type[$i]);
  161.         }  // end for()
  162.         // saves the answers into the data base
  163.         $objAnswer->save();
  164.  
  165.         // sets the total weighting of the question
  166.         $objQuestion->updateWeighting($questionWeighting);
  167.         $objQuestion->save($exerciseId);
  168.  
  169.         $editQuestion=$questionId;
  170.  
  171.         unset($modifyAnswers);
  172.  
  173.         echo '<script type="text/javascript">window.location.href="admin.php"</script>';
  174.  
  175.     }
  176.     if($debug>0){echo '$modifyIn was set - end'."<br />\n";}
  177.  
  178. }
  179.  
  180. if($modifyAnswers)
  181. {
  182.  
  183.  
  184.     if($debug>0){echo str_repeat('&nbsp;',0).'$modifyAnswers is set'."<br />\n";}
  185.  
  186.     // construction of the Answer object
  187.     $objAnswer=new Answer($objQuestion -> id);
  188.  
  189.     api_session_register('objAnswer');
  190.  
  191.     if($debug>0){echo str_repeat('&nbsp;',2).'$answerType is HOT_SPOT'."<br />\n";}
  192.  
  193.     $TBL_ANSWERS Database::get_course_table(TABLE_QUIZ_ANSWER);
  194.  
  195.     if(!$nbrAnswers)
  196.     {
  197.  
  198.         $nbrAnswers=$objAnswer->selectNbrAnswers();
  199.  
  200.         $reponse=Array();
  201.         $comment=Array();
  202.         $weighting=Array();
  203.         $hotspot_coordinates=Array();
  204.         $hotspot_type=array();
  205.  
  206.  
  207.         for($i=1;$i <= $nbrAnswers;$i++)
  208.         {
  209.             $reponse[$i]=$objAnswer->selectAnswer($i);
  210.             $comment[$i]=$objAnswer->selectComment($i);
  211.             $weighting[$i]=$objAnswer->selectWeighting($i);
  212.             $hotspot_coordinates[$i]=$objAnswer->selectHotspotCoordinates($i);
  213.             $hotspot_type[$i]=$objAnswer->selectHotspotType($i);
  214.         }
  215.  
  216.  
  217.     }
  218.  
  219.     $_SESSION['tmp_answers'array();
  220.     $_SESSION['tmp_answers']['answer'$reponse;
  221.     $_SESSION['tmp_answers']['comment'$comment;
  222.     $_SESSION['tmp_answers']['weighting'$weighting;
  223.     $_SESSION['tmp_answers']['hotspot_coordinates'$hotspot_coordinates;
  224.     $_SESSION['tmp_answers']['hotspot_type'$hotspot_type;
  225.  
  226.     if($lessAnswers)
  227.     {
  228.         // At least 1 answer
  229.         if ($nbrAnswers 1{
  230.  
  231.             $nbrAnswers--;
  232.  
  233.             // Remove the last answer
  234.             $tmp array_pop($_SESSION['tmp_answers']['answer']);
  235.             $tmp array_pop($_SESSION['tmp_answers']['comment']);
  236.             $tmp array_pop($_SESSION['tmp_answers']['weighting']);
  237.             $tmp array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  238.             $tmp array_pop($_SESSION['tmp_answers']['hotspot_type']);
  239.         }
  240.         else
  241.         {
  242.             $msgErr=get_lang('MinHotspot');
  243.         }
  244.     }
  245.  
  246.     if($moreAnswers)
  247.     {
  248.         if ($nbrAnswers 12)
  249.         {
  250.             $nbrAnswers++;
  251.  
  252.             // Add a new answer
  253.             $_SESSION['tmp_answers']['answer'][]='';
  254.             $_SESSION['tmp_answers']['comment'][]='';
  255.             $_SESSION['tmp_answers']['weighting'][]='1';
  256.             $_SESSION['tmp_answers']['hotspot_coordinates'][]='0;0|0|0';
  257.             $_SESSION['tmp_answers']['hotspot_type'][]='square';
  258.         }
  259.         else
  260.         {
  261.             $msgErr=get_lang('MaxHotspot');
  262.         }
  263.  
  264.  
  265.     }
  266.  
  267.         if($debug>0){echo str_repeat('&nbsp;',2).'$usedInSeveralExercises is untrue'."<br />\n";}
  268.  
  269.  
  270.         if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is HOT_SPOT'."<br />\n";}
  271.         $hotspot_colors array(""// $i starts from 1 on next loop (ugly fix)
  272.                                 "#4271B5",
  273.                                 "#FE8E16",
  274.                                 "#3B3B3B",
  275.                                 "#BCD631",
  276.                                 "#D63173",
  277.                                 "#D7D7D7",
  278.                                 "#90AFDD",
  279.                                 "#AF8640",
  280.                                 "#4F9242",
  281.                                 "#F4EB24",
  282.                                 "#ED2024",
  283.                                 "#45C7F0",
  284.                                 "#F7BDE2");
  285. ?>
  286.  
  287. <h3>
  288.   <?php echo $langQuestion.": ".$questionName.' <img src="../img/info3.gif" title="'.strip_tags(get_lang('HotspotChoose')).'" alt="'.strip_tags(get_lang('HotspotChoose')).'" />'?>
  289. </h3>
  290. <?php
  291.     if(!empty($msgErr))
  292.     {
  293.         Display::display_normal_message($msgErr)//main API
  294.     }
  295.     
  296. ?>
  297.  
  298. <form method="post" action="<?php echo api_get_self()?>?hotspotadmin=<?php echo $modifyAnswers?>" name="frm_exercise">
  299. <table border="0" cellpadding="0" cellspacing="2" width="100%">
  300.  
  301.     <tr>
  302.         <td colspan="2" valign="bottom">
  303.             <input type="submit" name="lessAnswers" value="<?php echo get_lang('LessHotspots')?>" />
  304.             <input type="submit" name="moreAnswers" value="<?php echo get_lang('MoreHotspots')?>" />
  305.             <input type="submit" name="cancelAnswers" value="<?php echo get_lang('Cancel')?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice')))?>')) return false;" />
  306.             <input type="submit" name="submitAnswers" value="<?php echo get_lang('Ok')?>" />
  307.         </td>
  308.     </tr>
  309.     <tr>
  310.         <td valign="top" style="border:1px solid #4271b5;border-top:none;border-bottom:none;border-right:none;" >            
  311.                 <input type="hidden" name="formSent" value="1" />
  312.                 <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers?>" />
  313.                 <table class="data_table">
  314.                     <!--
  315.                     <tr>
  316.                       <td colspan="5"><?php echo get_lang('AnswerHotspot')?> :</td>
  317.                     </tr>
  318.                     -->
  319.                     <tr>
  320.                       <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  321.                       <th ><?php echo get_lang('HotspotDescription')?>*</th>
  322.                       <th ><?php echo get_lang('Comment')?></th>
  323.                       <th><?php echo get_lang('QuestionWeighting')?>*</th>
  324.                     </tr>
  325.  
  326.                     <?php
  327.                                 for($i=1;$i <= $nbrAnswers;$i++)
  328.                                 {
  329.                     ?>
  330.  
  331.                     <tr>
  332.                       <td valign="top"><div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]?>"> </div></td>
  333.                       <td valign="top" align="left"><input type="text" name="reponse[<?php echo $i?>]" value="<?php echo htmlentities($reponse[$i])?>" size="45" /></td>
  334.                       <td align="left"><textarea wrap="virtual" rows="1" cols="25" name="comment[<?php echo $i?>]" style="width: 100%"><?php echo stripslashes(htmlentities($comment[$i]))?></textarea></td>
  335.                       <td valign="top"><input type="text" name="weighting[<?php echo $i?>]" size="1" value="<?php echo (isset($weighting[$i]$weighting[$i10)?>" />
  336.                       <input type="hidden" name="hotspot_coordinates[<?php echo $i?>]" value="<?php echo (empty($hotspot_coordinates[$i]'0;0|0|0' $hotspot_coordinates[$i])?>" />
  337.                       <input type="hidden" name="hotspot_type[<?php echo $i?>]" value="<?php echo (empty($hotspot_type[$i]'square' $hotspot_type[$i])?>" /></td>
  338.                     </tr>
  339.  
  340.                     <?php
  341.                                   }
  342.                     ?>
  343.  
  344.                 </table>
  345.         </td>    
  346.     </tr>
  347.     <tr>
  348.         <td colspan="2" valign="top" style="border:1px solid #4271b5;border-top:none">
  349.             <script type="text/javascript">
  350.                 <!--
  351.                 // Version check based upon the values entered above in "Globals"
  352.                 var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  353.  
  354.  
  355.                 // Check to see if the version meets the requirements for playback
  356.                 if (hasReqestedVersion) {  // if we've detected an acceptable version
  357.                     var oeTags = '<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" width="720" height="650">'
  358.                                 + '<param name="movie" value="../plugin/hotspot/hotspot_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
  359.                                 + '<param name="test" value="OOoowww fo shooww" />'
  360.                                 + '</object>';
  361.                     document.write(oeTags);   // embed the Flash Content SWF when all tests are passed
  362.                 } else {  // flash is too old or we can't detect the plugin
  363.                     var alternateContent = 'Error<br \/>'
  364.                         + 'This content requires the Macromedia Flash Player.<br \/>'
  365.                         + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
  366.                     document.write(alternateContent);  // insert non-flash content
  367.                 }
  368.                 // -->
  369.             </script>
  370.         </td>
  371.         
  372.     </tr>
  373. </table>
  374. </form>
  375.  
  376.  
  377.  
  378. <?php
  379.  
  380.     if($debug>0){echo str_repeat('&nbsp;',0).'$modifyAnswers was set - end'."<br />\n";}
  381. }
  382. ?>

Documentation generated on Thu, 12 Jun 2008 13:39:32 -0500 by phpDocumentor 1.4.1