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