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