move code up one directory
[atutor.git] / mods / _standard / tests / dd.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License  */
11 /* as published by the Free Software Foundation.                                */
12 /****************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
18         $content_base_href = 'get.php/';
19 } else {
20         $content_base_href = 'content/' . $_SESSION['course_id'] . '/';
21 }
22 // Verify that we may access this question
23 if (!isset($_SESSION['dd_question_ids']) || !is_array($_SESSION['dd_question_ids']) || !isset($_SESSION['dd_question_ids'][$_GET['qid']])) {
24         // Just exit as we're in an IFRAME
25         exit;
26 }
27 // Clean up tidily
28 unset($_SESSION['dd_question_ids'][$_GET['qid']]);
29 if (count($_SESSION['dd_question_ids']) == 0) {
30         unset($_SESSION['dd_question_ids']);
31 }
32 session_write_close();
33 $_GET['qid'] = intval($_GET['qid']);
34 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$_GET[qid]";
35 $result = mysql_query($sql, $db);
36 $row = mysql_fetch_assoc($result);
37
38 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
39 $_colours = array('#FF9900', '#00FF00', '#0000FF', '#F23AA3', '#9999CC', '#990026', '#0099CC', '#22C921', '#007D48', '#00248F');
40
41 $num_options = 0;
42 for ($i=0; $i < 10; $i++) {
43         if ($row['option_'. $i] != '') {
44                 $num_options++;
45         }
46 }
47 ?>
48 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
49 <html lang="<?php echo $_SESSION['lang']; ?>">
50 <head>
51         <title><?php echo SITE_NAME; ?> : <?php echo AT_print($row['question'], 'tests_questions.question'); ?></title>
52         <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $myLang->getCharacterSet(); ?>" />
53         <meta name="Generator" content="ATutor - Copyright 2007 by http://atutor.ca" />
54         <base href="<?php echo AT_BASE_HREF . $content_base_href; ?>" />
55         <script type="text/javascript" src="<?php echo AT_BASE_HREF; ?>jscripts/lib/dd_question/jquery.js"></script>
56         <script type="text/javascript" src="<?php echo AT_BASE_HREF; ?>jscripts/lib/dd_question/interface.js"></script>
57         <script type="text/javascript" src="<?php echo AT_BASE_HREF; ?>jscripts/lib/dd_question/wz_jsgraphics.js"></script>
58         <link rel="stylesheet" href="<?php echo AT_BASE_HREF; ?>themes/default/styles.css" type="text/css" />
59 <style type="text/css">
60 * {
61         margin: 0px;
62         padding: 0px;
63 }
64 body {
65         background-color: #fdfdfd;
66 }
67 option {
68         padding-right: 5px;
69 }
70 li {
71         padding: 5px;
72         border: 1px solid #ccc;
73         margin: 8px;
74 }
75 li.question {
76         width: 180px;
77         overflow: auto;
78 }
79 li.question:hover {
80         cursor: move;
81 }
82 li.answer {
83         width: 180px;
84         overflow: auto;
85         padding: 8px;
86         margin: 8px;
87 }
88 .dropactive {
89         background-color: #fc9;
90 }
91 .drophover {
92         background-color: #ffc;
93 }
94 </style>
95 </head>
96 <body>
97
98 <?php $response = explode('|', $_GET['response']); ?>
99
100 <?php for ($i=0; $i < 10; $i++): ?>
101         <?php if ($row['choice_'. $i] != ''): ?>
102                 <div id="container<?php echo $i; ?>" style="position: absolute; top: 0px; left: 0px; width: 100%"></div>
103         <?php endif; ?>
104 <?php endfor; ?>
105
106 <form method="get">
107         <ul style="position: absolute; top: 10px; left: 5px" id="q">
108                 <?php for ($i=0; $i < 10; $i++): ?>
109                         <?php if ($row['choice_'. $i] != ''): ?>
110                                 <li class="question" id="q<?php echo $i; ?>" value="<?php echo $i; ?>">
111                                         <select name="s<?php echo $i; ?>" onchange="selectLine(this.value, '<?php echo $i; ?>');" id="s<?php echo $i; ?>">
112                                                 <option value="-1">-</option>
113                                                 <?php for ($j=0; $j < $num_options; $j++): ?>
114                                                         <option value="<?php echo $j; ?>" <?php if($response[$i] == $j): ?>selected="selected"<?php endif; ?>><?php echo $_letters[$j]; ?></option>
115                                                 <?php endfor; ?>
116                                         </select>
117                                 
118                                 <?php echo AT_print($row['choice_'.$i], 'tests_questions.question'); ?></li>
119                         <?php endif; ?>
120                 <?php endfor; ?>
121         </ul>
122
123         <ol style="position: absolute; list-style-type: upper-alpha; top: 10px; left: 310px" id="a">
124                 <?php for ($i=0; $i < 10; $i++): ?>
125                         <?php if ($row['option_'. $i] != ''): ?>
126                                 <li class="answer" id="a<?php echo $i; ?>" value="<?php echo $i; ?>"><?php echo $_letters[$i]; ?>. <?php echo AT_print($row['option_'.$i], 'tests_questions.question'); ?></li>
127                         <?php endif; ?>
128                 <?php endfor; ?>
129         </ol>
130 </form>
131 <script type="text/javascript">
132 // <!--
133 if($.browser.msie) {
134         var padding = 8;
135 } else {
136         var padding = 15;
137 }
138 var jg = Array(10);
139 <?php for ($i=0; $i < 10; $i++): ?>
140         <?php if ($row['choice_'. $i] != ''): ?>
141                 jg[<?php echo $i; ?>] = new jsGraphics("container<?php echo $i; ?>");
142                 jg[<?php echo $i; ?>].setStroke(3);
143                 jg[<?php echo $i; ?>].setColor("<?php echo $_colours[$i]; ?>");
144         <?php endif; ?>
145 <?php endfor; ?>
146
147 var container_html = $("#container0").html();
148
149 $(document).ready(
150         function() {
151         
152                 $('#q>li').Draggable(
153                         {
154                                 containment: "document",
155                                 zIndex:         1000,
156                                 ghosting:       true,
157                                 opacity:        1,
158                                 revert:     true,
159                                 fx: 0 // doesn't update select menu in FF if > 0
160                         }
161                 ); // end draggable
162
163                 $('#a>li').Droppable(
164                         {
165                                 accept : 'question', 
166                                 activeclass: 'dropactive', 
167                                 hoverclass:     'drophover',
168                                 tolerance: "pointer",
169                                 ondrop: function (drag)  {
170                                         var lx = drag.offsetLeft + $("#" + drag.id).width() + padding;
171                                         var ly = drag.offsetTop  + $("#" + drag.id).height()/2 + 10;
172                                         var rx = this.offsetLeft + 310;
173                                         var ry = this.offsetTop  + $("#" + this.id).height()/2 + 10;
174
175                                         document.getElementById('s' + drag.value).selectedIndex =  this.value + 1;
176
177                                         window.top.document.getElementById("<?php echo $_GET['qid']; ?>q" + drag.value).value = this.value;
178
179                                         $("#container" + drag.value).html(container_html);
180
181                                         jg[drag.value].drawLine(lx, ly , rx, ry );
182                                         jg[drag.value].paint();
183
184                                         return true;
185                                 }
186                         }
187                 ); // end droppable
188
189         parent.iframeSetHeight(<?php echo $_GET['qid']; ?>, Math.max($("#q").height(), $("#a").height()));
190                 <?php foreach ($response as $id => $value): ?>
191                 selectLine(<?php echo $value; ?>, <?php echo $id; ?>);
192                 <?php endforeach; ?>
193         }
194 )
195
196 function selectLine(value, id) {
197         if (value == -1) {
198                 window.top.document.getElementById("<?php echo $_GET['qid']; ?>q" + id).value = "-1";
199                 $("#container" + id).html(container_html);
200
201                 return true;
202         }
203
204         var lx = document.getElementById("q" + id).offsetLeft + $("#q" + id).width() + padding;
205         var ly = document.getElementById("q" + id).offsetTop  + $("#q" + id).height()/2 + 10;
206         var rx = document.getElementById("a" + value).offsetLeft + 310;
207         var ry = document.getElementById("a" + value).offsetTop + $("#a" + value).height()/2 + 10;
208
209         window.top.document.getElementById("<?php echo $_GET['qid']; ?>q" + id).value = value;
210
211         $("#container" + id).html(container_html);
212         jg[id].drawLine(lx, ly , rx, ry );
213         jg[id].paint();
214
215         return true;
216 }
217 // -->
218 </script>
219
220 </body>