~ubuntu-branches/ubuntu/hoary/moodle/hoary

« back to all changes in this revision

Viewing changes to mod/scorm/lib.php

  • Committer: Bazaar Package Importer
  • Author(s): Isaac Clerencia
  • Date: 2004-12-29 00:49:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041229004952-gliyqzpj2w3e7clx
Tags: 1.4.3-1
* Urgency high as upstream release fixes several security bugs
* New upstream release
* Write database creation errors and warn the user about it, 
closes: #285842, #285842

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?PHP  // $Id: lib.php,v 1.13.2.9 2004/12/15 19:59:28 stronk7 Exp $
 
2
 
 
3
/// Library of functions and constants for module scorm
 
4
/// (replace scorm with the name of your module and delete this line)
 
5
 
 
6
define('VALUESCOES', '0');
 
7
define('VALUEHIGHEST', '1');
 
8
define('VALUEAVERAGE', '2');
 
9
define('VALUESUM', '3');
 
10
$SCORM_GRADE_METHOD = array (VALUESCOES => get_string("gradescoes", "scorm"), 
 
11
                             VALUEHIGHEST => get_string("gradehighest", "scorm"),
 
12
                             VALUEAVERAGE => get_string("gradeaverage", "scorm"),
 
13
                             VALUESUM => get_string("gradesum", "scorm"));
 
14
                             
 
15
$SCORM_WINDOW_OPTIONS = array('resizable', 'scrollbars', 'status', 'height', 'width');
 
16
 
 
17
if (!isset($CFG->scorm_popup)) {
 
18
    set_config('scorm_popup', '');
 
19
}
 
20
if (!isset($CFG->scorm_validate)) {
 
21
    $scorm_validate = 'none';
 
22
    //I've commented this out for Moodle 1.4, as I've seen errors in 
 
23
    //SCORM packages even though the actual package worked fine. -- Martin Dougiamas
 
24
    //if (extension_loaded('domxml') && version_compare(phpversion(),'5.0.0','<')) {
 
25
    //    $scorm_validate = 'domxml';
 
26
    //}
 
27
    //if (version_compare(phpversion(),'5.0.0','>=')) {
 
28
    //    $scorm_validate = 'php5';
 
29
    //}
 
30
    set_config('scorm_validate', $scorm_validate);
 
31
}
 
32
 
 
33
foreach ($SCORM_WINDOW_OPTIONS as $popupoption) {
 
34
    $popupoption = "scorm_popup$popupoption";
 
35
    if (!isset($CFG->$popupoption)) {
 
36
        if ($popupoption == 'scorm_popupheight') {
 
37
            set_config($popupoption, 450);
 
38
        } else if ($popupoption == 'scorm_popupwidth') {
 
39
            set_config($popupoption, 620);
 
40
        } else {
 
41
            set_config($popupoption, 'checked');
 
42
        }
 
43
    }  
 
44
}
 
45
 
 
46
if (!isset($CFG->scorm_framesize)) {
 
47
    set_config('scorm_framesize', 140);
 
48
}
 
49
 
 
50
function scorm_add_instance($scorm) {
 
51
/// Given an object containing all the necessary data, 
 
52
/// (defined by the form in mod.html) this function 
 
53
/// will create a new instance and return the id number 
 
54
/// of the new instance.
 
55
 
 
56
    $scorm->timemodified = time();
 
57
 
 
58
    # May have to add extra stuff in here #
 
59
    global $SCORM_WINDOW_OPTIONS;
 
60
    
 
61
    $scorm->popup = '';
 
62
    
 
63
    $optionlist = array();
 
64
    foreach ($SCORM_WINDOW_OPTIONS as $option) {
 
65
        if (isset($scorm->$option)) {
 
66
            $optionlist[] = $option.'='.$scorm->$option;
 
67
        }
 
68
    }
 
69
    $scorm->popup = implode(',', $optionlist);
 
70
    
 
71
 
 
72
    if ($scorm->popup != '') {
 
73
        $scorm->popup .= ',location=0,menubar=0,toolbar=0';
 
74
        $scorm->auto = '0';
 
75
    }
 
76
    
 
77
    return insert_record('scorm', $scorm);
 
78
}
 
79
 
 
80
 
 
81
function scorm_update_instance($scorm) {
 
82
/// Given an object containing all the necessary data, 
 
83
/// (defined by the form in mod.html) this function 
 
84
/// will update an existing instance with new data.
 
85
    
 
86
    $scorm->timemodified = time();
 
87
    $scorm->id = $scorm->instance;
 
88
 
 
89
    # May have to add extra stuff in here #
 
90
    global $SCORM_WINDOW_OPTIONS;
 
91
    
 
92
    $scorm->popup = '';
 
93
    
 
94
    $optionlist = array();
 
95
    foreach ($SCORM_WINDOW_OPTIONS as $option) {
 
96
        if (isset($scorm->$option)) {
 
97
            $optionlist[] = $option.'='.$scorm->$option;
 
98
        }
 
99
    }
 
100
    $scorm->popup = implode(',', $optionlist);
 
101
 
 
102
    if ($scorm->popup != '') {
 
103
        $scorm->popup .= ',location=0,menubar=0,toolbar=0';
 
104
        $scorm->auto = '0';
 
105
    }
 
106
    return update_record('scorm', $scorm);
 
107
}
 
108
 
 
109
 
 
110
function scorm_delete_instance($id) {
 
111
/// Given an ID of an instance of this module, 
 
112
/// this function will permanently delete the instance 
 
113
/// and any data that depends on it.  
 
114
    
 
115
    require('../config.php');
 
116
 
 
117
    if (! $scorm = get_record('scorm', 'id', $id)) {
 
118
        return false;
 
119
    }
 
120
 
 
121
    $result = true;
 
122
 
 
123
    # Delete any dependent files #
 
124
    scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'.$scorm->datadir);
 
125
 
 
126
    # Delete any dependent records here #
 
127
    if (! delete_records('scorm_sco_users', 'scormid', $scorm->id)) {
 
128
        $result = false;
 
129
    }
 
130
    if (! delete_records('scorm_scoes', 'scorm', $scorm->id)) {
 
131
        $result = false;
 
132
    }
 
133
    if (! delete_records('scorm', 'id', $scorm->id)) {
 
134
        $result = false;
 
135
    }
 
136
    
 
137
 
 
138
    return $result;
 
139
}
 
140
 
 
141
function scorm_user_outline($course, $user, $mod, $scorm) {
 
142
/// Return a small object with summary information about what a 
 
143
/// user has done with a given particular instance of this module
 
144
/// Used for user activity reports.
 
145
/// $return->time = the time they did it
 
146
/// $return->info = a short text description
 
147
 
 
148
    return $return;
 
149
}
 
150
 
 
151
function scorm_user_complete($course, $user, $mod, $scorm) {
 
152
/// Print a detailed representation of what a  user has done with 
 
153
/// a given particular instance of this module, for user activity reports.
 
154
 
 
155
    return true;
 
156
}
 
157
 
 
158
function scorm_print_recent_activity(&$logs, $isteacher=false) {
 
159
/// Given a list of logs, assumed to be those since the last login 
 
160
/// this function prints a short list of changes related to this module
 
161
/// If isteacher is true then perhaps additional information is printed.
 
162
/// This function is called from course/lib.php: print_recent_activity()
 
163
 
 
164
    global $CFG, $COURSE_TEACHER_COLOR;
 
165
 
 
166
    $content = NULL;
 
167
 
 
168
    return $content;  // True if anything was printed, otherwise false
 
169
}
 
170
 
 
171
function scorm_cron () {
 
172
/// Function to be run periodically according to the moodle cron
 
173
/// This function searches for things that need to be done, such 
 
174
/// as sending out mail, toggling flags etc ... 
 
175
 
 
176
    global $CFG;
 
177
 
 
178
    return true;
 
179
}
 
180
 
 
181
function scorm_grades($scormid) {
 
182
/// Must return an array of grades for a given instance of this module, 
 
183
/// indexed by user.  It also returns a maximum allowed grade.
 
184
 
 
185
    global $CFG;
 
186
    
 
187
    if (!$scorm = get_record("scorm", "id", $scormid)) {
 
188
        return NULL;
 
189
    }
 
190
    
 
191
    if ($scorm->grademethod == VALUESCOES) {
 
192
        if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) {
 
193
            return NULL;
 
194
        }
 
195
    
 
196
        $return->grades = NULL;
 
197
        if ($sco_users=get_records_select('scorm_sco_users', "scormid='$scormid' GROUP BY userid")) {
 
198
            foreach ($sco_users as $sco_user) {
 
199
                $user_data=get_records_select('scorm_sco_users',"scormid='$scormid' AND userid='$sco_user->userid'");
 
200
                $scores->completed=0;
 
201
                $scores->browsed=0;
 
202
                $scores->incomplete=0;
 
203
                $scores->failed=0;
 
204
                $scores->notattempted=0;
 
205
                $result='';
 
206
                $data = current($user_data);
 
207
                foreach ($user_data as $data) {
 
208
                    if ($data->cmi_core_lesson_status=='passed')
 
209
                        $scores->completed++;
 
210
                    else
 
211
                        $scores->{scorm_remove_spaces($data->cmi_core_lesson_status)}++;
 
212
                }
 
213
                if ($scores->completed)
 
214
                    $result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/completed.gif\" alt=\"".get_string('completed','scorm')."\" title=\"".get_string('completed','scorm')."\"> $scores->completed ";
 
215
                if ($scores->incomplete)
 
216
                    $result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/incomplete.gif\" alt=\"".get_string('incomplete','scorm')."\" title=\"".get_string('incomplete','scorm')."\"> $scores->incomplete ";
 
217
                if ($scores->failed)
 
218
                    $result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/failed.gif\" alt=\"".get_string('failed','scorm')."\" title=\"".get_string('failed','scorm')."\"> $scores->failed ";
 
219
                if ($scores->browsed)
 
220
                    $result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/browsed.gif\" alt=\"".get_string('browsed','scorm')."\" title=\"".get_string('browsed','scorm')."\"> $scores->browsed ";
 
221
                if ($scores->notattempted)
 
222
                    $result.="<img src=\"$CFG->wwwroot/mod/scorm/pix/notattempted.gif\" alt=\"".get_string('notattempted','scorm')."\" title=\"".get_string('notattempted','scorm')."\"> $scores->notattempted ";
 
223
            
 
224
                $return->grades[$sco_user->userid]=$result;
 
225
            }
 
226
        
 
227
        }
 
228
    } else {
 
229
        $grades = get_records_select("scorm_sco_users", "scormid=$scormid AND cmi_core_score_raw>0","","id,userid,cmi_core_score_raw");
 
230
        //$grades = get_records_menu("scorm_sco_users", "scormid",$scormid,"","userid,cmi_core_score_raw");
 
231
        $valutations = array();
 
232
        foreach ($grades as $grade) {
 
233
            if (!isset($valutations[$grade->userid])) {
 
234
                if ($scorm->grademethod == VALUEAVERAGE) {
 
235
                    $values = array();
 
236
                    $values[$grade->userid]->grade = 0;
 
237
                    $values[$grade->userid]->values = 0;
 
238
                }
 
239
                $valutations[$grade->userid] = 0;
 
240
            }
 
241
            switch ($scorm->grademethod) {
 
242
                case VALUEHIGHEST:
 
243
                    if ($grade->cmi_core_score_raw > $valutations[$grade->userid]) {
 
244
                        $valutations[$grade->userid] = $grade->cmi_core_score_raw;
 
245
                    }
 
246
                break;
 
247
                case VALUEAVERAGE:
 
248
                    $values[$grade->userid]->grade += $grade->cmi_core_score_raw;
 
249
                    $values[$grade->userid]->values++;
 
250
                break;
 
251
                case VALUESUM:
 
252
                    $valutations[$grade->userid] += $grade->cmi_core_score_raw;
 
253
                break;
 
254
            }
 
255
        }
 
256
        if ($scorm->grademethod == VALUEAVERAGE) {
 
257
            foreach($values as $userid => $value) {
 
258
                $valutations[$userid] = $value->grade/$value->values;
 
259
            }
 
260
        }
 
261
        //print_r($grades);
 
262
        $return->grades = $valutations;
 
263
        $return->maxgrade = $scorm->maxgrade;
 
264
    }
 
265
    return $return;
 
266
}
 
267
 
 
268
 
 
269
//////////////////////////////////////////////////////////////////////////////////////
 
270
/// Any other scorm functions go here.  Each of them must have a name that 
 
271
/// starts with scorm_
 
272
 
 
273
 
 
274
function scorm_randstring($len = '8')
 
275
{
 
276
        $rstring = NULL;
 
277
        $lchar = '';
 
278
        for($i=0; $i<$len; $i++) {
 
279
                $char = chr(rand(48,122));
 
280
                while (!ereg('[a-zA-Z0-9]', $char)){
 
281
                        if($char == $lchar) continue;
 
282
                        $char = chr(rand(48,90));
 
283
                }
 
284
                $rstring .= $char;
 
285
                $lchar = $char;
 
286
        }
 
287
        return $rstring;
 
288
}
 
289
 
 
290
 
 
291
function scorm_datadir($strPath, $existingdir='', $prefix = 'SCORM')
 
292
{
 
293
    global $CFG;
 
294
 
 
295
    if (($existingdir!='') && (is_dir($strPath.$existingdir)))
 
296
        return $strPath.$existingdir;
 
297
        
 
298
    if (is_dir($strPath)) {
 
299
        do {
 
300
            $datadir='/'.$prefix.scorm_randstring();
 
301
        } while (file_exists($strPath.$datadir));
 
302
        mkdir($strPath.$datadir, $CFG->directorypermissions);
 
303
        @chmod($strPath.$datadir, $CFG->directorypermissions);  // Just in case mkdir didn't do it
 
304
        return $strPath.$datadir;
 
305
    } else {
 
306
        return false;
 
307
    }
 
308
 
309
 
 
310
if ($CFG->scorm_validate == 'domxml') {
 
311
    require_once('validatordomxml.php');
 
312
}
 
313
 
 
314
function scorm_validate($manifest)
 
315
{
 
316
    global $CFG;
 
317
    
 
318
    global $item_idref_array;
 
319
    global $idres_array;
 
320
    global $def_org_array;
 
321
    global $id_org_array;
 
322
    
 
323
    if (is_file ($manifest)) {
 
324
        if (file_exists($manifest)) {
 
325
            if ($CFG->scorm_validate == 'domxml') {
 
326
                $manifest_string = file_get_contents($manifest);
 
327
 
 
328
                /* Elimino i caratteri speciali di spaziatura e ritorno a capo dal file xml */
 
329
 
 
330
                $spec = array('\n', '\r', '\t', '\0', '\x0B');
 
331
                $content = str_replace($spec, '', $manifest_string);
 
332
 
 
333
                if ($xmldoc = domxml_open_mem($content)) {
 
334
                    $root = $xmldoc->document_element();
 
335
                    if (!testRoot($root)) {
 
336
                        return 'syntax';
 
337
                    }
 
338
                    if (testNode($root)) {      
 
339
                        // Nel corpo di questo if si controllano le corrispondenze fra gli attributi
 
340
                        // Nello Standard SCORM ad ogni attributo idRef di <item> deve corrispondere
 
341
                        // un attributo ID di <resource>
 
342
                        // Gli array degli attributi sono stati dichiarati globali in validator.php
 
343
                        // pertanto possono essere utilizzati direttamente all'interno di main.php
 
344
 
 
345
                        foreach($item_idref_array as $elem_it) {  
 
346
                            if (array_search($elem_it, $idres_array) === false) {
 
347
                                return 'mismatch';
 
348
                            }
 
349
                        }
 
350
  
 
351
                        foreach($def_org_array as $elem_def) {  
 
352
                            if (array_search($elem_it, $id_org_array) === false) {
 
353
                                return 'mismatch';
 
354
                            }
 
355
                        }
 
356
                   
 
357
                    } else {
 
358
                        return 'badmanifest';
 
359
                    }
 
360
                }
 
361
                return 'regular';
 
362
            } else {
 
363
                return 'found';
 
364
            }
 
365
        }
 
366
    } else {
 
367
        return 'nomanifest';
 
368
    }
 
369
}
 
370
 
 
371
function scorm_delete_files($directory) {
 
372
    if (is_dir($directory)) {
 
373
        $files=scorm_scandir($directory);
 
374
        //print_r($files);
 
375
        foreach($files as $file) {
 
376
            if (($file != '.') && ($file != '..')) {
 
377
                if (!is_dir($directory.'/'.$file)) {
 
378
                    //chmod($directory.'/'.$file,0777);
 
379
                    unlink($directory.'/'.$file);
 
380
                } else {
 
381
                    scorm_delete_files($directory.'/'.$file);
 
382
                }
 
383
            }
 
384
        }
 
385
        rmdir($directory);
 
386
    }
 
387
}
 
388
 
 
389
function scorm_scandir($directory) {
 
390
    if (version_compare(phpversion(),'5.0.0','>=')) {
 
391
        return scandir($directory);
 
392
    } else {
 
393
        $files = null;
 
394
        if ($dh = opendir($directory)) {
 
395
            while (($file = readdir($dh)) !== false) {
 
396
                $files[] = $file;
 
397
            }
 
398
            closedir($dh);
 
399
        }
 
400
        return $files;
 
401
    }
 
402
}
 
403
 
 
404
function scorm_startElement($parser, $name, $attrs) {
 
405
 
 
406
    global $scoes,$i,$resources,$parent,$level,$organization,$manifest,$defaultorg;
 
407
 
 
408
    if ($name == 'ITEM') {
 
409
        $i++;
 
410
        $scoes[$i]['manifest'] = $manifest;
 
411
        $scoes[$i]['organization'] = $organization;
 
412
        $scoes[$i]['identifier'] = $attrs['IDENTIFIER'];
 
413
        if (empty($attrs['IDENTIFIERREF']))
 
414
            $attrs['IDENTIFIERREF'] = '';
 
415
        $scoes[$i]['identifierref'] = $attrs['IDENTIFIERREF'];
 
416
        if (empty($attrs['ISVISIBLE']))
 
417
            $attrs['ISVISIBLE'] = '';
 
418
        $scoes[$i]['isvisible'] = $attrs['ISVISIBLE'];
 
419
        $scoes[$i]['parent'] = $parent[$level];
 
420
        $level++;
 
421
        $parent[$level] = $attrs['IDENTIFIER'];
 
422
    }
 
423
    if ($name == 'RESOURCE') {
 
424
        if (!isset($attrs['HREF'])) {
 
425
            $attrs['HREF'] = '';
 
426
        }
 
427
        $resources[$attrs['IDENTIFIER']]['href']=$attrs['HREF'];
 
428
        if (!isset($attrs['ADLCP:SCORMTYPE'])) {
 
429
            $attrs['ADLCP:SCORMTYPE'] = '';
 
430
        }
 
431
        $resources[$attrs['IDENTIFIER']]['type']=$attrs['ADLCP:SCORMTYPE'];
 
432
    }
 
433
    if ($name == 'ORGANIZATION') {
 
434
        $i++;
 
435
        $scoes[$i]['manifest'] = $manifest;
 
436
        $scoes[$i]['organization'] = '';
 
437
        $scoes[$i]['identifier'] = $attrs['IDENTIFIER'];
 
438
        $scoes[$i]['identifierref'] = '';
 
439
        $scoes[$i]['isvisible'] = '';
 
440
        $scoes[$i]['parent'] = $parent[$level];
 
441
        $level++;
 
442
        $parent[$level] = $attrs['IDENTIFIER'];
 
443
        $organization = $attrs['IDENTIFIER'];
 
444
    }
 
445
    if ($name == 'MANIFEST') {
 
446
        $manifest = $attrs['IDENTIFIER'];
 
447
    }
 
448
    if ($name == 'ORGANIZATIONS') {
 
449
        if (!isset($attrs['DEFAULT'])) {
 
450
            $attrs['DEFAULT'] = '';
 
451
        }
 
452
        $defaultorg = $attrs['DEFAULT'];
 
453
    }
 
454
}
 
455
 
 
456
function scorm_endElement($parser, $name) {
 
457
    global $scoes,$i,$level,$datacontent,$navigation;
 
458
    if ($name == 'ITEM') {
 
459
        $level--;
 
460
    }
 
461
    //if ($name == 'TITLE' && $level>0) {
 
462
    if ($name == 'TITLE') {
 
463
        $scoes[$i]['title'] = $datacontent;
 
464
    }
 
465
    if ($name == 'ADLCP:HIDERTSUI') {
 
466
        $scoes[$i][$datacontent] = 1;
 
467
    }
 
468
    if ($name == 'ADLCP:DATAFROMLMS') {
 
469
        $scoes[$i]['datafromlms'] = $datacontent;
 
470
    }
 
471
    if ($name == 'ORGANIZATION') {
 
472
        $organization = '';
 
473
        $level--;
 
474
    }
 
475
    if ($name == 'MANIFEST') {
 
476
        $manifest = '';
 
477
    }
 
478
}
 
479
 
 
480
function scorm_characterData($parser, $data) {
 
481
    global $datacontent;
 
482
    $datacontent = utf8_decode($data);
 
483
}
 
484
 
 
485
function scorm_parse($basedir,$file,$scorm_id) {
 
486
    global $scoes,$i,$resources,$parent,$level,$defaultorg;
 
487
    $datacontent = '';
 
488
    $scoes[][] = '';
 
489
    $resources[] = '';
 
490
    $organization = '';
 
491
    $defaultorg = '';
 
492
    $i = 0;
 
493
    $level = 0;
 
494
    $parent[$level] = '/';
 
495
 
 
496
    $xml_parser = xml_parser_create('UTF-8');
 
497
    // use case-folding so we are sure to find the tag in $map_array
 
498
    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
 
499
    xml_set_element_handler($xml_parser, 'scorm_startElement', 'scorm_endElement');
 
500
    xml_set_character_data_handler($xml_parser, 'scorm_characterData');
 
501
    if (!($fp = fopen($basedir.$file, 'r'))) {
 
502
       die('could not open XML input');
 
503
    }
 
504
 
 
505
    while ($data = fread($fp, 4096)) {
 
506
        if (!xml_parse($xml_parser, $data, feof($fp))) {
 
507
            die(sprintf('XML error: %s at line %d',
 
508
                    xml_error_string(xml_get_error_code($xml_parser)),
 
509
                    xml_get_current_line_number($xml_parser)));
 
510
        }
 
511
    }
 
512
    xml_parser_free($xml_parser);
 
513
    $launch = 0;
 
514
 
 
515
    $sco->scorm = $scorm_id;
 
516
    delete_records('scorm_scoes','scorm',$scorm_id);
 
517
    delete_records('scorm_sco_users','scormid',$scorm_id);
 
518
    
 
519
    if (isset($scoes[1])) {
 
520
        for ($j=1; $j<=$i; $j++) {
 
521
            $sco->identifier = $scoes[$j]['identifier'];
 
522
            $sco->parent = $scoes[$j]['parent'];
 
523
            $sco->title = $scoes[$j]['title'];
 
524
            $sco->organization = $scoes[$j]['organization'];
 
525
            if (!isset($scoes[$j]['datafromlms'])) {
 
526
                $scoes[$j]['datafromlms'] = '';
 
527
            } 
 
528
            $sco->datafromlms = $scoes[$j]['datafromlms'];
 
529
        
 
530
            if (!isset($resources[($scoes[$j]['identifierref'])]['href'])) {
 
531
                $resources[($scoes[$j]['identifierref'])]['href'] = '';
 
532
            }
 
533
            $sco->launch = $resources[($scoes[$j]['identifierref'])]['href'];
 
534
        
 
535
            if (!isset($resources[($scoes[$j]['identifierref'])]['type'])) {
 
536
                $resources[($scoes[$j]['identifierref'])]['type'] = '';
 
537
            }
 
538
            $sco->type = $resources[($scoes[$j]['identifierref'])]['type'];
 
539
        
 
540
            if (!isset($scoes[$j]['previous'])) {
 
541
                $scoes[$j]['previous'] = 0;
 
542
            }
 
543
            $sco->previous = $scoes[$j]['previous'];
 
544
        
 
545
            if (!isset($scoes[$j]['continue'])) {
 
546
                $scoes[$j]['continue'] = 0;
 
547
            }
 
548
            $sco->next = $scoes[$j]['continue'];
 
549
        
 
550
            if (scorm_remove_spaces($scoes[$j]['isvisible']) != 'false') {
 
551
                $id = insert_record('scorm_scoes',$sco);
 
552
            }
 
553
            //if (($launch==0) && (isset($sco->launch)) && ($defaultorg==$sco->organization)) {
 
554
            if (($launch==0) && ($defaultorg==$sco->identifier)) {
 
555
                $launch = $id;
 
556
            }
 
557
        }
 
558
    } else {
 
559
        foreach ($resources as $label => $resource) {
 
560
            if (!empty($resource['href'])) {
 
561
                $sco->identifier = $label;
 
562
                $sco->title = $label;
 
563
                $sco->parent = '/';
 
564
                $sco->launch = $resource['href'];
 
565
                $sco->type = $resource['type'];
 
566
                $id = insert_record('scorm_scoes',$sco);
 
567
                
 
568
                if ($launch == 0) {
 
569
                    $launch = $id;
 
570
                }
 
571
            }
 
572
        }
 
573
    }
 
574
    return $launch;
 
575
}
 
576
 
 
577
function scorm_get_scoes_records($sco_user) {
 
578
/// Gets all info required to display the table of scorm results
 
579
/// for report.php
 
580
    global $CFG;
 
581
 
 
582
    return get_records_sql("SELECT su.*, u.firstname, u.lastname, u.picture 
 
583
                            FROM {$CFG->prefix}scorm_sco_users su, 
 
584
                                 {$CFG->prefix}user u
 
585
                            WHERE su.scormid = '$sco_user->scormid'
 
586
                              AND su.userid = u.id
 
587
                              AND su.userid = '$sco_user->userid'
 
588
                              ORDER BY scoid");
 
589
}
 
590
 
 
591
function scorm_remove_spaces($sourcestr) {
 
592
// Remove blank space from a string
 
593
    $newstr='';
 
594
    for( $i=0; $i<strlen($sourcestr); $i++) {
 
595
        if ($sourcestr[$i]!=' ')
 
596
            $newstr .=$sourcestr[$i];
 
597
    }
 
598
    return $newstr;
 
599
}
 
600
 
 
601
function scorm_string_round($stringa) {
 
602
// Crop a string to $len character and set an anchor title to the full string
 
603
    $len=11;
 
604
    if ( strlen($stringa)>$len ) {
 
605
    return "<A name=\"\" title=\"$stringa\">".substr($stringa,0,$len-4).'...'.substr($stringa,strlen($stringa)-1,1).'</A>';
 
606
    } else
 
607
    return $stringa;
 
608
}
 
609
 
 
610
function scorm_external_link($link) {
 
611
// check if a link is external
 
612
    $result = false;
 
613
    $link = strtolower($link);
 
614
    if (substr($link,0,7) == 'http://')
 
615
        $result = true;
 
616
    else if (substr($link,0,8) == 'https://')
 
617
        $result = true;
 
618
    else if (substr($link,0,4) == 'www.')
 
619
        $result = true;
 
620
    /*else if (substr($link,0,7) == 'rstp://')
 
621
        $result = true;
 
622
    else if (substr($link,0,6) == 'rtp://')
 
623
        $result = true;
 
624
    else if (substr($link,0,6) == 'ftp://')
 
625
        $result = true;
 
626
    else if (substr($link,0,9) == 'gopher://')
 
627
        $result = true; */
 
628
    return $result;
 
629
}    
 
630
?>