changed git call from https to git readonly
[atutor.git] / mods / scorm_packages / scorm-1.2 / view.inc.php
1 <?php
2 /*
3  * mods/scorm_packages/scorm-1.2/view.inc.php
4  *
5  * This file is part of ATutor, see http://www.atutor.ca
6  * 
7  * Copyright (C) 2005  Matthai Kurian 
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; either version 2
12  * of the License, or (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * 
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24 function treeEl ($s) {
25         return '<img src="images/tree/tree_' . $s . '.gif" alt="">';
26 }
27
28 if (!$_GET['org_id']) {
29         header('Location: ../index.php');
30         exit;
31 }  
32
33
34 $sql = "SELECT  first_name, last_name
35         FROM    ".TABLE_PREFIX."members
36         WHERE   member_id = ".$_SESSION['member_id'];
37
38 $result = mysql_query($sql, $db);
39 $q_row  = mysql_fetch_assoc($result);
40 $student_name = $q_row['last_name'] . ', ' . $q_row['first_name'];
41
42 //if ($student_name == ', ') $msg->addWarning('packages_no_student_name');
43
44         $sql = "SELECT  package_id
45                 FROM    ".TABLE_PREFIX."scorm_1_2_org
46                 WHERE   org_id = $_GET[org_id]";
47         $result = mysql_query($sql, $db);
48         $q_row  = mysql_fetch_assoc($result);
49         $pkg    = $q_row['package_id'];
50
51         $sql = "SELECT  item_id, scormtype, idx, title, href
52                 FROM    ".TABLE_PREFIX."scorm_1_2_item
53                 WHERE   org_id = $_GET[org_id]
54                 ORDER   BY item_id
55         ";
56         $result = mysql_query($sql, $db);
57
58         $org = array();
59         $iid = array();
60         $ist = array();
61
62         $i=0;
63         while ($row = mysql_fetch_assoc($result)) {
64                 $org[$i]['id']    = $row['item_id'];
65                 $org[$i]['idx']   = $row['idx'];
66                 $org[$i]['type']  = $row['scormtype'];
67                 $org[$i]['title'] = $row['title'];
68                 $org[$i]['href']  = $row['href'];
69                 $iid[$row['item_id']] = $i;
70                 $ist[$i] = 'not attempted';
71                 $i++;
72         }
73         $c = sizeOf($org);
74
75         $sql = "SELECT  c.item_id,
76                         c.rvalue
77                 FROM    ".TABLE_PREFIX."cmi c,
78                         ".TABLE_PREFIX."scorm_1_2_item i,
79                         ".TABLE_PREFIX."scorm_1_2_org  o
80                 WHERE   o.org_id    = $_GET[org_id]
81                 AND     i.org_id    = o.org_id
82                 AND     i.item_id   = c.item_id
83                 AND     c.member_id = $_SESSION[member_id]
84                 AND     c.lvalue    = 'cmi.core.lesson_status'
85         ";
86         $result = mysql_query($sql, $db);
87         while ($row = mysql_fetch_assoc($result)) {
88                 $ist[$iid[$row['item_id']]] = $row['rvalue'];
89         }
90
91         $fil   = array();
92         $tree  = array();
93         $dtree = array();
94         $tidx  = explode ('.', $org[$c-1]['idx']);
95         $lvl   = sizeOf($tidx);
96         $llvl  = 42;
97
98         for ($l=0; $l<$lvl; $l++) array_push ($fil, treeEl ('space'));
99         array_push ($fil, treeEl('end'));
100
101         for ($i=$c-1; $i>=0; $i--) {
102                 $tidx = explode ('.', $org[$i]['idx']);
103                 $lvl = sizeOf($tidx);
104
105                 switch ($org[$i]['type']) {
106                 case 'organization':
107                         $_pages[$me]['title'] =$org[$i]['title'];
108
109                 case 'cluster':
110                         array_pop ($fil);
111                         array_pop ($fil);
112                         array_push ($fil, treeEl('disabled'));
113                         break;
114
115                 case 'sco':
116                 case 'asset':
117                         if ($org[$i]['idx'].'.1' == $org[$i+1]['idx']) {
118                                 // cluster with resource
119                                 array_pop ($fil);
120                                 array_pop ($fil);
121                                 array_push ($fil, treeEl('disabled'));
122                                 break;
123                         }
124                         
125                         array_pop ($fil);
126                         if ($lvl <  $llvl) array_push ($fil, treeEl('end'));
127                         if ($lvl == $llvl) array_push ($fil, treeEl ('split'));
128                         if ($lvl >  $llvl) {
129                                  array_push ($fil, treeEl ('vertline'));
130                                  array_push ($fil, treeEl ('end'));
131                         }
132                         break;
133                 }
134
135                 if ($org[$i]['href']) {
136                         if ($org[$i]['type'] == 'sco') {
137                                 array_push ($tree,
138                                         implode ($fil) 
139                                         . '<img id="im' . $i
140                                         . '" name="im' . $i
141                                         . '" src="' . $im
142                                         . str_replace (' ', '-', $ist[$i])
143                                         . '.png" alt="' . $ist[$i]
144                                         . '" title="' . $ist[$i] . '">'
145                                         . '<a href="javascript:void(0)" '
146                                         . 'onclick="Launch(' . $i .');'
147                                         . 'return false;">'
148                                         . $org[$i]['title'] . '</a>'
149                                 );
150                         } else {
151                                 array_push ($tree,
152                                         implode ($fil) 
153                                         . '<img id="im' . $i
154                                         . '" name="im' . $i
155                                         . '" src="' . $im
156                                         . 'asset.png" alt="">'
157                                         . '<a href="javascript:void(0)" '
158                                         . 'onclick="Launch(' . $i .');'
159                                         . 'return false;">'
160                                         . $org[$i]['title'] . '</a>'
161                                 );
162                         }
163                 } else {
164                         array_push ($tree,
165                                 implode ($fil)
166                                 . '<b>' . $org[$i]['title'] . '</b>'
167                         );
168                 }
169
170                 $llvl = $lvl;
171         }
172
173         require(AT_INCLUDE_PATH.'header.inc.php');
174         
175 ?>
176
177 <div id="rte">
178 <applet code="ATutorApiAdapterApplet" 
179 id="RTE" name="RTE" mayscript="true"
180 codebase="<?php echo AT_BASE_HREF?>mods/scorm_packages/scorm-1.2/"
181 archive="<?php echo AT_BASE_HREF?>mods/scorm_packages/scorm-1.2/java/ATutorApiAdapterApplet.jar,<?php echo AT_BASE_HREF?>mods/scorm_packages/scorm-1.2/java/PfPLMS-API-adapter-core.jar,<?php echo AT_BASE_HREF?>mods/scorm_packages/scorm-1.2/java/gnu.jar"
182 width="0" height="0" >
183 <param name="student_id"   value="<?php echo $_SESSION['member_id']?>" />
184 <param name="student_name" value="<?php echo $student_name?>" />
185 <?php   if ($prefs['show_rte_communication'] == 1) {
186                 echo '<param name="verbose" value="1" />' . "\n";
187         }
188 ?>"
189         echo ($prefs['show_rte_communication'] == 1?'true':'false');
190 </applet>
191 </div>
192
193 <script language="Javascript">
194
195 function getObj (o) {
196         if(document.getElementById) return document.getElementById(o);
197         if(document.all) return document.all[o];
198 }
199
200
201 scHREF = new Array();
202 scID   = new Array();
203 scType = new Array();
204
205 <?php
206         $c = sizeOf ($org);
207         for ($i=0; $i<=$c; $i++) {
208                 echo 'scHREF[' . $i ."] = '";
209                 if ($org[$i]['href'] != '') {
210                         echo AT_PACKAGE_URL_BASE
211                         . $_SESSION['course_id'] .'/' . $pkg .'/'
212                         . $org[$i]['href']
213                         ;
214                 }
215                 echo "';\n"
216                 . 'scID[' . $i ."] = '" . $org[$i]['id'] . "';\n"
217                 . 'scType[' . $i ."] = '" . $org[$i]['type'] . "';\n"
218                 ;
219         }
220 ?>
221
222
223 var scoidx      = 0;
224 var nextscoidx  = 0;
225 var autonext    = null;
226 var scowindow   = null;
227 var isRunning   = false;
228 var isLaunching = false;
229 var initstat    = '';
230
231 var scoWidth  = 800;
232 var scoHeight = 600;
233
234 var auto_advance = <?php
235         echo ($prefs['auto_advance'] == 1 ?'true':'false');
236 ?>;
237 var show_comm = <?php
238         echo ($prefs['show_rte_communication'] == 1?'true':'false');
239 ?>;
240
241 function LMSInitialize (s) {
242         isRunning   = true;
243         isLaunching = false;
244
245         scoidx     = nextscoidx;
246         nextscoidx = null;
247         autonext   = null;
248
249         var o = getObj ('im'+scoidx);
250         o.src = '<?php echo $im;?>busy.png';
251         o.alt   = '<?php echo _AT('scorm_sco_is_running')?>';
252         o.title = '<?php echo _AT('scorm_sco_is_running')?>';
253         rv = window.document.RTE.LMSInitialize (s);
254         initstat = window.document.RTE.ATutorGetValue (
255                 'cmi.core.lesson_status'
256         );
257         return rv;
258 }
259
260 function LMSFinish (s) {
261
262         checkResize();
263
264         var stat = window.document.RTE.ATutorGetValue ('cmi.core.lesson_status');
265         if (stat != '') {
266                 var o = getObj ('im'+scoidx);
267                 o.alt = stat;
268                 o.title = stat;
269                 if (stat == 'not attempted') stat = 'not-attempted';
270                 o.src = '<?php echo $im;?>'+stat+'.png';
271                 if (!autonext && auto_advance && !initstat.equals(stat)) {
272                         if (stat == 'completed' ||
273                             stat == 'passed'    ||
274                             stat == 'browsed') {
275                                 for (i=scoidx+1; i<scHREF.length; i++) {
276                                         if (scHREF[i].length) {
277                                                 autonext = i;
278                                                 checkResize();
279                                                 break;
280                                         }
281                                 }
282                         }
283                 }
284         }
285
286         rv = window.document.RTE.LMSFinish (s);
287         if (rv == 'true') {
288                 scowindow.close();
289                 scowindow = null;
290                 isRunning = false;
291                 scoidx    = null;
292                 if (autonext) setTimeout ('Launch (autonext)', 500);
293         }
294         return rv;
295 }
296
297 function LMSSetValue (l, r) {
298         return window.document.RTE.LMSSetValue (l, r);
299 }
300
301 function LMSGetValue (l) {
302         return window.document.RTE.LMSGetValue (l);
303 }
304
305 function LMSGetLastError () {
306         return window.document.RTE.LMSGetLastError ();
307 }
308
309 function LMSGetErrorString (s) {
310         return window.document.RTE.LMSGetErrorString (s);
311 }
312
313 function LMSGetDiagnostic (s) {
314         return window.document.RTE.LMSGetDiagnostic (s);
315 }
316
317 function LMSCommit (s) {
318         return window.document.RTE.LMSCommit (s);
319 }
320
321
322 function Launch (i) {
323         if (autonext && autonext != i) return;
324         nextscoidx = null; 
325         if (i == scoidx) return;
326
327         if (scowindow && scowindow.closed) {
328                 isLaunching = false;
329                 isRunning   = false;
330                 scowindow   = null;
331                 if (isRunning) {
332                         window.document.RTE.ATutorReset(scID[scoidx]);
333                         isRunning = false;
334                 }
335         }
336
337         if (isLaunching) return;
338
339         if (scowindow != null) {
340                if (!isRunning) return;
341                scowindow.close();
342         }
343
344         isLaunching = true;
345         if (scType[i] == 'sco') {
346                 try {
347                         window.document.RTE.ATutorPrepare(scID[i]);
348                 } catch (Exception) {
349                         alert ('Sorry, LiveConnect does not work');
350                         return;
351                 }
352                 checkResize();
353                 nextscoidx = i;
354         } else {
355                 nextscoidx = null;
356         }
357
358         isLaunching = true;
359         scowindow = window.open (
360                 scHREF[i],
361                 'ATutorSCO',
362                 'width='+scoWidth+',height='+scoHeight+','+
363                 'toolbar=no,menubar=no,status=no,scrollbars=yes'
364         );
365         if (scType[i] == 'sco') {
366                 this.API = this;
367                 if (scowindow) scowindow.API = this;
368         }
369         scowindow.focus();
370 }
371
372 function cleanup () {
373         if (scowindow) scowindow.close();
374 }
375
376 function checkResize () {
377         try {
378                 w = scowindow.innerWidth;
379                 h = scowindow.innerHeight;
380                 if (w >= 640 && h >= 480) {
381                         scoWidth  = w; 
382                         scoHeight = h;
383                 }
384         } catch (Exception) {};
385 }
386
387 this.onunload=cleanup;
388 </script>
389
390 <?php
391         $p = "\n" . '<div id="scorm_1_2_toc" style="display:block; border:thin solid #cccccc;width:95%;padding:1em;margin:auto;">' . "\n";
392         for ($i=$c-1; $i>=0; $i--) {
393                 $p .= $tree[$i] . '<br />' . "\n";
394         }
395         $p .= '</div>' . "\n";
396         echo utf8_decode($p); 
397 ?>
398
399