@@ -36,16 +36,16 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class CourseRestorer |
38 | 38 | { |
39 | - /** |
|
40 | - * The course-object |
|
41 | - */ |
|
39 | + /** |
|
40 | + * The course-object |
|
41 | + */ |
|
42 | 42 | public $course; |
43 | 43 | public $destination_course_info; |
44 | 44 | |
45 | - /** |
|
46 | - * What to do with files with same name (FILE_SKIP, FILE_RENAME or |
|
47 | - * FILE_OVERWRITE) |
|
48 | - */ |
|
45 | + /** |
|
46 | + * What to do with files with same name (FILE_SKIP, FILE_RENAME or |
|
47 | + * FILE_OVERWRITE) |
|
48 | + */ |
|
49 | 49 | public $file_option; |
50 | 50 | public $set_tools_invisible_by_default; |
51 | 51 | public $skip_content; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | 'events', |
58 | 58 | 'forum_category', |
59 | 59 | 'forums', |
60 | - // 'forum_topics', |
|
60 | + // 'forum_topics', |
|
61 | 61 | 'glossary', |
62 | 62 | 'quizzes', |
63 | 63 | 'test_category', |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | $this->tool_copy_settings = $array; |
127 | 127 | } |
128 | 128 | |
129 | - /** |
|
130 | - * Restore a course. |
|
129 | + /** |
|
130 | + * Restore a course. |
|
131 | 131 | * |
132 | - * @param string $destination_course_code code of the Chamilo-course in |
|
133 | - * @param int $session_id |
|
134 | - * @param bool $update_course_settings Course settings are going to be restore? |
|
132 | + * @param string $destination_course_code code of the Chamilo-course in |
|
133 | + * @param int $session_id |
|
134 | + * @param bool $update_course_settings Course settings are going to be restore? |
|
135 | 135 | * @param bool $respect_base_content |
136 | 136 | * @return false|null |
137 | - */ |
|
137 | + */ |
|
138 | 138 | public function restore( |
139 | 139 | $destination_course_code = '', |
140 | 140 | $session_id = 0, |
@@ -277,17 +277,17 @@ discard block |
||
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
280 | - /** |
|
281 | - * Restore only harmless course settings: |
|
280 | + /** |
|
281 | + * Restore only harmless course settings: |
|
282 | 282 | * course_language, visibility, department_name,department_url, |
283 | 283 | * subscribe, unsubscribe ,category_code |
284 | - * |
|
285 | - * @param string $destination_course_code |
|
286 | - */ |
|
284 | + * |
|
285 | + * @param string $destination_course_code |
|
286 | + */ |
|
287 | 287 | public function restore_course_settings($destination_course_code) |
288 | 288 | { |
289 | - $origin_course_info = api_get_course_info($destination_course_code); |
|
290 | - $course_info = $this->course->info; |
|
289 | + $origin_course_info = api_get_course_info($destination_course_code); |
|
290 | + $course_info = $this->course->info; |
|
291 | 291 | $params['course_language'] = $course_info['language']; |
292 | 292 | $params['visibility'] = $course_info['visibility']; |
293 | 293 | $params['department_name'] = $course_info['department_name']; |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | $params['category_code'] = $course_info['categoryCode']; |
297 | 297 | $params['subscribe'] = $course_info['subscribe_allowed']; |
298 | 298 | $params['unsubscribe'] = $course_info['unsubscribe']; |
299 | - CourseManager::update_attributes($origin_course_info['real_id'], $params); |
|
300 | - } |
|
299 | + CourseManager::update_attributes($origin_course_info['real_id'], $params); |
|
300 | + } |
|
301 | 301 | |
302 | 302 | /** |
303 | 303 | * Restore documents |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | $course_info = api_get_course_info($destination_course_code); |
312 | 312 | |
313 | 313 | if ($this->course->has_resources(RESOURCE_DOCUMENT)) { |
314 | - $table = Database :: get_course_table(TABLE_DOCUMENT); |
|
315 | - $resources = $this->course->resources; |
|
314 | + $table = Database :: get_course_table(TABLE_DOCUMENT); |
|
315 | + $resources = $this->course->resources; |
|
316 | 316 | $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; |
317 | 317 | |
318 | - foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { |
|
318 | + foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { |
|
319 | 319 | |
320 | 320 | if (empty($document->item_properties[0]['id_session'])) { |
321 | 321 | $my_session_id = 0; |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | } |
386 | 386 | } |
387 | 387 | } |
388 | - } elseif ($document->file_type == DOCUMENT) { |
|
388 | + } elseif ($document->file_type == DOCUMENT) { |
|
389 | 389 | //Checking if folder exists in the database otherwise we created it |
390 | 390 | $dir_to_create = dirname($document->path); |
391 | 391 | |
@@ -441,19 +441,19 @@ discard block |
||
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | - if (file_exists($path.$document->path)) { |
|
445 | - switch ($this->file_option) { |
|
446 | - case FILE_OVERWRITE: |
|
444 | + if (file_exists($path.$document->path)) { |
|
445 | + switch ($this->file_option) { |
|
446 | + case FILE_OVERWRITE: |
|
447 | 447 | $origin_path = $this->course->backup_path.'/'.$document->path; |
448 | 448 | |
449 | - if (file_exists($origin_path)) { |
|
450 | - copy($origin_path, $path.$document->path); |
|
449 | + if (file_exists($origin_path)) { |
|
450 | + copy($origin_path, $path.$document->path); |
|
451 | 451 | $sql = "SELECT id FROM $table |
452 | 452 | WHERE |
453 | 453 | c_id = ".$this->destination_course_id." AND |
454 | 454 | path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'"; |
455 | 455 | |
456 | - $res = Database::query($sql); |
|
456 | + $res = Database::query($sql); |
|
457 | 457 | $count = Database::num_rows($res); |
458 | 458 | |
459 | 459 | if ($count == 0) { |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | 'session_id' => $my_session_id, |
468 | 468 | ]; |
469 | 469 | |
470 | - $document_id = Database::insert($table, $params); |
|
470 | + $document_id = Database::insert($table, $params); |
|
471 | 471 | |
472 | 472 | if ($document_id) { |
473 | 473 | $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; |
@@ -575,83 +575,83 @@ discard block |
||
575 | 575 | ], |
576 | 576 | ] |
577 | 577 | ); |
578 | - } |
|
578 | + } |
|
579 | 579 | |
580 | - break; |
|
581 | - case FILE_SKIP: |
|
582 | - $sql = "SELECT id FROM $table |
|
580 | + break; |
|
581 | + case FILE_SKIP: |
|
582 | + $sql = "SELECT id FROM $table |
|
583 | 583 | WHERE |
584 | 584 | c_id = ".$this->destination_course_id." AND |
585 | 585 | path='/".self::DBUTF8escapestring(substr($document->path, 9))."'"; |
586 | - $res = Database::query($sql); |
|
587 | - $obj = Database::fetch_object($res); |
|
588 | - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; |
|
589 | - break; |
|
590 | - case FILE_RENAME: |
|
591 | - $i = 1; |
|
592 | - $ext = explode('.', basename($document->path)); |
|
593 | - if (count($ext) > 1) { |
|
594 | - $ext = array_pop($ext); |
|
595 | - $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
596 | - $ext = '.'.$ext; |
|
597 | - } else { |
|
598 | - $ext = ''; |
|
599 | - $file_name_no_ext = $document->path; |
|
600 | - } |
|
601 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
602 | - $file_exists = file_exists($path.$new_file_name); |
|
603 | - while ($file_exists) { |
|
604 | - $i ++; |
|
605 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
606 | - $file_exists = file_exists($path.$new_file_name); |
|
607 | - } |
|
608 | - |
|
609 | - if (!empty($session_id)) { |
|
610 | - |
|
611 | - $document_path = explode('/',$document->path,3); |
|
612 | - $course_path = $path; |
|
613 | - $orig_base_folder = $document_path[1]; |
|
614 | - $orig_base_path = $course_path.$document_path[0].'/'.$document_path[1]; |
|
615 | - |
|
616 | - if (is_dir($orig_base_path)) { |
|
617 | - |
|
618 | - $new_base_foldername = $orig_base_folder; |
|
619 | - $new_base_path = $orig_base_path; |
|
620 | - |
|
621 | - if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { |
|
622 | - unset($_SESSION['new_base_foldername']); |
|
623 | - unset($_SESSION['orig_base_foldername']); |
|
624 | - unset($_SESSION['new_base_path']); |
|
625 | - } |
|
626 | - |
|
627 | - $folder_exists = file_exists($new_base_path); |
|
628 | - if ($folder_exists) { |
|
629 | - $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session |
|
630 | - $x = ''; |
|
631 | - while ($folder_exists) { |
|
632 | - $x = $x + 1; |
|
633 | - $new_base_foldername = $document_path[1].'_'.$x; |
|
634 | - $new_base_path = $orig_base_path.'_'.$x; |
|
586 | + $res = Database::query($sql); |
|
587 | + $obj = Database::fetch_object($res); |
|
588 | + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; |
|
589 | + break; |
|
590 | + case FILE_RENAME: |
|
591 | + $i = 1; |
|
592 | + $ext = explode('.', basename($document->path)); |
|
593 | + if (count($ext) > 1) { |
|
594 | + $ext = array_pop($ext); |
|
595 | + $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
596 | + $ext = '.'.$ext; |
|
597 | + } else { |
|
598 | + $ext = ''; |
|
599 | + $file_name_no_ext = $document->path; |
|
600 | + } |
|
601 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
602 | + $file_exists = file_exists($path.$new_file_name); |
|
603 | + while ($file_exists) { |
|
604 | + $i ++; |
|
605 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
606 | + $file_exists = file_exists($path.$new_file_name); |
|
607 | + } |
|
608 | + |
|
609 | + if (!empty($session_id)) { |
|
610 | + |
|
611 | + $document_path = explode('/',$document->path,3); |
|
612 | + $course_path = $path; |
|
613 | + $orig_base_folder = $document_path[1]; |
|
614 | + $orig_base_path = $course_path.$document_path[0].'/'.$document_path[1]; |
|
615 | + |
|
616 | + if (is_dir($orig_base_path)) { |
|
617 | + |
|
618 | + $new_base_foldername = $orig_base_folder; |
|
619 | + $new_base_path = $orig_base_path; |
|
620 | + |
|
621 | + if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { |
|
622 | + unset($_SESSION['new_base_foldername']); |
|
623 | + unset($_SESSION['orig_base_foldername']); |
|
624 | + unset($_SESSION['new_base_path']); |
|
625 | + } |
|
626 | + |
|
627 | + $folder_exists = file_exists($new_base_path); |
|
628 | + if ($folder_exists) { |
|
629 | + $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session |
|
630 | + $x = ''; |
|
631 | + while ($folder_exists) { |
|
632 | + $x = $x + 1; |
|
633 | + $new_base_foldername = $document_path[1].'_'.$x; |
|
634 | + $new_base_path = $orig_base_path.'_'.$x; |
|
635 | 635 | if ($_SESSION['new_base_foldername'] == $new_base_foldername) { |
636 | 636 | break; |
637 | 637 | } |
638 | - $folder_exists = file_exists($new_base_path); |
|
639 | - } |
|
640 | - $_SESSION['new_base_foldername'] = $new_base_foldername; |
|
641 | - $_SESSION['new_base_path'] = $new_base_path; |
|
642 | - } |
|
643 | - |
|
644 | - if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { |
|
645 | - $new_base_foldername = $_SESSION['new_base_foldername']; |
|
646 | - $new_base_path = $_SESSION['new_base_path']; |
|
647 | - } |
|
648 | - |
|
649 | - $dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" |
|
650 | - $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" |
|
651 | - $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" |
|
652 | - $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; |
|
653 | - |
|
654 | - copy_folder_course_session( |
|
638 | + $folder_exists = file_exists($new_base_path); |
|
639 | + } |
|
640 | + $_SESSION['new_base_foldername'] = $new_base_foldername; |
|
641 | + $_SESSION['new_base_path'] = $new_base_path; |
|
642 | + } |
|
643 | + |
|
644 | + if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { |
|
645 | + $new_base_foldername = $_SESSION['new_base_foldername']; |
|
646 | + $new_base_path = $_SESSION['new_base_path']; |
|
647 | + } |
|
648 | + |
|
649 | + $dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" |
|
650 | + $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" |
|
651 | + $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" |
|
652 | + $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; |
|
653 | + |
|
654 | + copy_folder_course_session( |
|
655 | 655 | $basedir_dest_path, |
656 | 656 | $base_path_document, |
657 | 657 | $session_id, |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | 'session_id' => $my_session_id, |
694 | 694 | ]; |
695 | 695 | |
696 | - $document_id = Database::insert($table, $params); |
|
696 | + $document_id = Database::insert($table, $params); |
|
697 | 697 | |
698 | 698 | if ($document_id) { |
699 | 699 | $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; |
@@ -722,10 +722,10 @@ discard block |
||
722 | 722 | null, |
723 | 723 | $my_session_id |
724 | 724 | ); |
725 | - } else { |
|
726 | - if (file_exists($path.$document->path)) { |
|
725 | + } else { |
|
726 | + if (file_exists($path.$document->path)) { |
|
727 | 727 | copy($path.$document->path, $path.$new_file_name); |
728 | - } |
|
728 | + } |
|
729 | 729 | //Replace old course code with the new destination code see BT#1985 |
730 | 730 | if (file_exists($path.$new_file_name)) { |
731 | 731 | $file_info = pathinfo($path.$new_file_name); |
@@ -784,10 +784,10 @@ discard block |
||
784 | 784 | $my_session_id |
785 | 785 | ); |
786 | 786 | } |
787 | - } |
|
788 | - } else { |
|
787 | + } |
|
788 | + } else { |
|
789 | 789 | |
790 | - copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name); |
|
790 | + copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name); |
|
791 | 791 | |
792 | 792 | //Replace old course code with the new destination code see BT#1985 |
793 | 793 | if (file_exists($path.$new_file_name)) { |
@@ -847,20 +847,20 @@ discard block |
||
847 | 847 | null, |
848 | 848 | $my_session_id |
849 | 849 | ); |
850 | - } |
|
851 | - break; |
|
852 | - |
|
853 | - } // end switch |
|
854 | - } else { |
|
855 | - // end if file exists |
|
856 | - //make sure the source file actually exists |
|
857 | - if (is_file($this->course->backup_path.'/'.$document->path) && |
|
850 | + } |
|
851 | + break; |
|
852 | + |
|
853 | + } // end switch |
|
854 | + } else { |
|
855 | + // end if file exists |
|
856 | + //make sure the source file actually exists |
|
857 | + if (is_file($this->course->backup_path.'/'.$document->path) && |
|
858 | 858 | is_readable($this->course->backup_path.'/'.$document->path) && |
859 | 859 | is_dir(dirname($path.$document->path)) && |
860 | 860 | is_writeable(dirname($path.$document->path)) |
861 | 861 | ) { |
862 | - //echo 'Copying'; |
|
863 | - copy($this->course->backup_path.'/'.$document->path, $path.$document->path); |
|
862 | + //echo 'Copying'; |
|
863 | + copy($this->course->backup_path.'/'.$document->path, $path.$document->path); |
|
864 | 864 | |
865 | 865 | //Replace old course code with the new destination code see BT#1985 |
866 | 866 | if (file_exists($path.$document->path)) { |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | Database::query($sql); |
899 | 899 | } |
900 | 900 | |
901 | - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; |
|
901 | + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; |
|
902 | 902 | |
903 | 903 | $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : ''; |
904 | 904 | $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id(); |
@@ -920,79 +920,79 @@ discard block |
||
920 | 920 | null, |
921 | 921 | $my_session_id |
922 | 922 | ); |
923 | - } else { |
|
924 | - if (is_file($this->course->backup_path.'/'.$document->path) && |
|
923 | + } else { |
|
924 | + if (is_file($this->course->backup_path.'/'.$document->path) && |
|
925 | 925 | is_readable($this->course->backup_path.'/'.$document->path) |
926 | 926 | ) { |
927 | - error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found'); |
|
928 | - } |
|
929 | - if (!is_dir(dirname($path.$document->path))) { |
|
930 | - error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found'); |
|
931 | - } |
|
932 | - if (!is_writeable(dirname($path.$document->path))) { |
|
933 | - error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable'); |
|
934 | - } |
|
935 | - } |
|
936 | - } // end file doesn't exist |
|
937 | - } |
|
938 | - } // end for each |
|
939 | - |
|
940 | - // Delete sessions for the copy the new folder in session |
|
941 | - unset($_SESSION['new_base_foldername']); |
|
942 | - unset($_SESSION['orig_base_foldername']); |
|
943 | - unset($_SESSION['new_base_path']); |
|
944 | - } |
|
945 | - } |
|
946 | - |
|
947 | - /** |
|
948 | - * Restore scorm documents |
|
949 | - * TODO @TODO check that the restore function with renaming doesn't break the scorm structure! |
|
927 | + error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found'); |
|
928 | + } |
|
929 | + if (!is_dir(dirname($path.$document->path))) { |
|
930 | + error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found'); |
|
931 | + } |
|
932 | + if (!is_writeable(dirname($path.$document->path))) { |
|
933 | + error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable'); |
|
934 | + } |
|
935 | + } |
|
936 | + } // end file doesn't exist |
|
937 | + } |
|
938 | + } // end for each |
|
939 | + |
|
940 | + // Delete sessions for the copy the new folder in session |
|
941 | + unset($_SESSION['new_base_foldername']); |
|
942 | + unset($_SESSION['orig_base_foldername']); |
|
943 | + unset($_SESSION['new_base_path']); |
|
944 | + } |
|
945 | + } |
|
946 | + |
|
947 | + /** |
|
948 | + * Restore scorm documents |
|
949 | + * TODO @TODO check that the restore function with renaming doesn't break the scorm structure! |
|
950 | 950 | * see #7029 |
951 | - */ |
|
952 | - public function restore_scorm_documents() |
|
951 | + */ |
|
952 | + public function restore_scorm_documents() |
|
953 | 953 | { |
954 | - $perm = api_get_permissions_for_new_directories(); |
|
954 | + $perm = api_get_permissions_for_new_directories(); |
|
955 | 955 | |
956 | - if ($this->course->has_resources(RESOURCE_SCORM)) { |
|
957 | - $resources = $this->course->resources; |
|
956 | + if ($this->course->has_resources(RESOURCE_SCORM)) { |
|
957 | + $resources = $this->course->resources; |
|
958 | 958 | |
959 | - foreach ($resources[RESOURCE_SCORM] as $document) { |
|
960 | - $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; |
|
959 | + foreach ($resources[RESOURCE_SCORM] as $document) { |
|
960 | + $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; |
|
961 | 961 | |
962 | - @mkdir(dirname($path.$document->path), $perm, true); |
|
962 | + @mkdir(dirname($path.$document->path), $perm, true); |
|
963 | 963 | |
964 | - if (file_exists($path.$document->path)) { |
|
965 | - switch ($this->file_option) { |
|
966 | - case FILE_OVERWRITE: |
|
967 | - rmdirr($path.$document->path); |
|
964 | + if (file_exists($path.$document->path)) { |
|
965 | + switch ($this->file_option) { |
|
966 | + case FILE_OVERWRITE: |
|
967 | + rmdirr($path.$document->path); |
|
968 | 968 | copyDirTo( |
969 | 969 | $this->course->backup_path . '/' . $document->path, |
970 | 970 | $path . dirname($document->path), |
971 | 971 | false |
972 | 972 | ); |
973 | - break; |
|
974 | - case FILE_SKIP: |
|
975 | - break; |
|
973 | + break; |
|
974 | + case FILE_SKIP: |
|
975 | + break; |
|
976 | 976 | case FILE_RENAME: |
977 | - $i = 1; |
|
978 | - $ext = explode('.', basename($document->path)); |
|
979 | - if (count($ext) > 1) { |
|
980 | - $ext = array_pop($ext); |
|
981 | - $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
982 | - $ext = '.'.$ext; |
|
983 | - } else { |
|
984 | - $ext = ''; |
|
985 | - $file_name_no_ext = $document->path; |
|
986 | - } |
|
987 | - |
|
988 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
989 | - $file_exists = file_exists($path.$new_file_name); |
|
990 | - |
|
991 | - while ($file_exists) { |
|
992 | - $i ++; |
|
993 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
994 | - $file_exists = file_exists($path.$new_file_name); |
|
995 | - } |
|
977 | + $i = 1; |
|
978 | + $ext = explode('.', basename($document->path)); |
|
979 | + if (count($ext) > 1) { |
|
980 | + $ext = array_pop($ext); |
|
981 | + $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
982 | + $ext = '.'.$ext; |
|
983 | + } else { |
|
984 | + $ext = ''; |
|
985 | + $file_name_no_ext = $document->path; |
|
986 | + } |
|
987 | + |
|
988 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
989 | + $file_exists = file_exists($path.$new_file_name); |
|
990 | + |
|
991 | + while ($file_exists) { |
|
992 | + $i ++; |
|
993 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
994 | + $file_exists = file_exists($path.$new_file_name); |
|
995 | + } |
|
996 | 996 | |
997 | 997 | rename( |
998 | 998 | $this->course->backup_path . '/' . $document->path, |
@@ -1008,30 +1008,30 @@ discard block |
||
1008 | 1008 | $this->course->backup_path . '/' . $document->path |
1009 | 1009 | ); |
1010 | 1010 | |
1011 | - break; |
|
1012 | - } // end switch |
|
1013 | - } else { |
|
1011 | + break; |
|
1012 | + } // end switch |
|
1013 | + } else { |
|
1014 | 1014 | // end if file exists |
1015 | 1015 | copyDirTo( |
1016 | 1016 | $this->course->backup_path . '/' . $document->path, |
1017 | 1017 | $path . dirname($document->path), |
1018 | 1018 | false |
1019 | 1019 | ); |
1020 | - } |
|
1021 | - } // end for each |
|
1022 | - } |
|
1023 | - } |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Restore forums |
|
1027 | - */ |
|
1028 | - public function restore_forums($sessionId = 0) |
|
1020 | + } |
|
1021 | + } // end for each |
|
1022 | + } |
|
1023 | + } |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Restore forums |
|
1027 | + */ |
|
1028 | + public function restore_forums($sessionId = 0) |
|
1029 | 1029 | { |
1030 | - if ($this->course->has_resources(RESOURCE_FORUM)) { |
|
1030 | + if ($this->course->has_resources(RESOURCE_FORUM)) { |
|
1031 | 1031 | $sessionId = intval($sessionId); |
1032 | - $table_forum = Database::get_course_table(TABLE_FORUM); |
|
1033 | - $resources = $this->course->resources; |
|
1034 | - foreach ($resources[RESOURCE_FORUM] as $id => $forum) { |
|
1032 | + $table_forum = Database::get_course_table(TABLE_FORUM); |
|
1033 | + $resources = $this->course->resources; |
|
1034 | + foreach ($resources[RESOURCE_FORUM] as $id => $forum) { |
|
1035 | 1035 | $params = (array)$forum->obj; |
1036 | 1036 | $cat_id = ''; |
1037 | 1037 | if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) && |
@@ -1077,33 +1077,33 @@ discard block |
||
1077 | 1077 | Database::query($sql); |
1078 | 1078 | } |
1079 | 1079 | |
1080 | - $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id; |
|
1081 | - |
|
1082 | - $forum_topics = 0; |
|
1083 | - if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) { |
|
1084 | - foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) { |
|
1085 | - if ($topic->obj->forum_id == $id) { |
|
1086 | - $this->restore_topic($topic_id, $new_id, $sessionId); |
|
1087 | - $forum_topics ++; |
|
1088 | - } |
|
1089 | - } |
|
1090 | - } |
|
1091 | - if ($forum_topics > 0) { |
|
1092 | - $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics." |
|
1080 | + $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id; |
|
1081 | + |
|
1082 | + $forum_topics = 0; |
|
1083 | + if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) { |
|
1084 | + foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) { |
|
1085 | + if ($topic->obj->forum_id == $id) { |
|
1086 | + $this->restore_topic($topic_id, $new_id, $sessionId); |
|
1087 | + $forum_topics ++; |
|
1088 | + } |
|
1089 | + } |
|
1090 | + } |
|
1091 | + if ($forum_topics > 0) { |
|
1092 | + $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics." |
|
1093 | 1093 | WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id; |
1094 | - Database::query($sql); |
|
1095 | - } |
|
1096 | - } |
|
1097 | - } |
|
1098 | - } |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Restore forum-categories |
|
1102 | - */ |
|
1094 | + Database::query($sql); |
|
1095 | + } |
|
1096 | + } |
|
1097 | + } |
|
1098 | + } |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Restore forum-categories |
|
1102 | + */ |
|
1103 | 1103 | public function restore_forum_category($my_id = null, $sessionId = 0) |
1104 | 1104 | { |
1105 | - $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY); |
|
1106 | - $resources = $this->course->resources; |
|
1105 | + $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY); |
|
1106 | + $resources = $this->course->resources; |
|
1107 | 1107 | if (!empty($resources[RESOURCE_FORUMCATEGORY])) { |
1108 | 1108 | foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) { |
1109 | 1109 | if (!empty($my_id)) { |
@@ -1150,16 +1150,16 @@ discard block |
||
1150 | 1150 | } |
1151 | 1151 | } |
1152 | 1152 | } |
1153 | - } |
|
1153 | + } |
|
1154 | 1154 | |
1155 | - /** |
|
1156 | - * Restore a forum-topic |
|
1157 | - * @param false|string $forum_id |
|
1158 | - */ |
|
1155 | + /** |
|
1156 | + * Restore a forum-topic |
|
1157 | + * @param false|string $forum_id |
|
1158 | + */ |
|
1159 | 1159 | public function restore_topic($thread_id, $forum_id, $sessionId = 0) |
1160 | 1160 | { |
1161 | - $table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
1162 | - $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]; |
|
1161 | + $table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
1162 | + $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]; |
|
1163 | 1163 | |
1164 | 1164 | $params = (array)$topic->obj; |
1165 | 1165 | $params = self::DBUTF8_array($params); |
@@ -1195,28 +1195,28 @@ discard block |
||
1195 | 1195 | $sessionId |
1196 | 1196 | ); |
1197 | 1197 | |
1198 | - $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id; |
|
1198 | + $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id; |
|
1199 | 1199 | |
1200 | - $topic_replies = -1; |
|
1200 | + $topic_replies = -1; |
|
1201 | 1201 | |
1202 | - foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) { |
|
1203 | - if ($post->obj->thread_id == $thread_id) { |
|
1204 | - $topic_replies++; |
|
1205 | - $this->restore_post($post_id, $new_id, $forum_id, $sessionId); |
|
1206 | - } |
|
1207 | - } |
|
1208 | - return $new_id; |
|
1209 | - } |
|
1202 | + foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) { |
|
1203 | + if ($post->obj->thread_id == $thread_id) { |
|
1204 | + $topic_replies++; |
|
1205 | + $this->restore_post($post_id, $new_id, $forum_id, $sessionId); |
|
1206 | + } |
|
1207 | + } |
|
1208 | + return $new_id; |
|
1209 | + } |
|
1210 | 1210 | |
1211 | - /** |
|
1212 | - * Restore a forum-post |
|
1213 | - * @TODO Restore tree-structure of posts. For example: attachments to posts. |
|
1214 | - * @param false|string $topic_id |
|
1215 | - */ |
|
1211 | + /** |
|
1212 | + * Restore a forum-post |
|
1213 | + * @TODO Restore tree-structure of posts. For example: attachments to posts. |
|
1214 | + * @param false|string $topic_id |
|
1215 | + */ |
|
1216 | 1216 | public function restore_post($id, $topic_id, $forum_id, $sessionId = 0) |
1217 | 1217 | { |
1218 | - $table_post = Database :: get_course_table(TABLE_FORUM_POST); |
|
1219 | - $post = $this->course->resources[RESOURCE_FORUMPOST][$id]; |
|
1218 | + $table_post = Database :: get_course_table(TABLE_FORUM_POST); |
|
1219 | + $post = $this->course->resources[RESOURCE_FORUMPOST][$id]; |
|
1220 | 1220 | $params = (array) $post->obj; |
1221 | 1221 | $params['c_id'] = $this->destination_course_id; |
1222 | 1222 | $params['forum_id'] = $forum_id; |
@@ -1251,37 +1251,37 @@ discard block |
||
1251 | 1251 | null, |
1252 | 1252 | $sessionId |
1253 | 1253 | ); |
1254 | - $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id; |
|
1254 | + $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id; |
|
1255 | 1255 | |
1256 | - return $new_id; |
|
1257 | - } |
|
1256 | + return $new_id; |
|
1257 | + } |
|
1258 | 1258 | |
1259 | - /** |
|
1260 | - * Restore links |
|
1261 | - */ |
|
1259 | + /** |
|
1260 | + * Restore links |
|
1261 | + */ |
|
1262 | 1262 | public function restore_links($session_id = 0) |
1263 | 1263 | { |
1264 | - if ($this->course->has_resources(RESOURCE_LINK)) { |
|
1265 | - $link_table = Database :: get_course_table(TABLE_LINK); |
|
1266 | - $resources = $this->course->resources; |
|
1264 | + if ($this->course->has_resources(RESOURCE_LINK)) { |
|
1265 | + $link_table = Database :: get_course_table(TABLE_LINK); |
|
1266 | + $resources = $this->course->resources; |
|
1267 | 1267 | |
1268 | - foreach ($resources[RESOURCE_LINK] as $id => $link) { |
|
1268 | + foreach ($resources[RESOURCE_LINK] as $id => $link) { |
|
1269 | 1269 | $cat_id = $this->restore_link_category( |
1270 | 1270 | $link->category_id, |
1271 | 1271 | $session_id |
1272 | 1272 | ); |
1273 | - $sql = "SELECT MAX(display_order) |
|
1273 | + $sql = "SELECT MAX(display_order) |
|
1274 | 1274 | FROM $link_table |
1275 | 1275 | WHERE |
1276 | 1276 | c_id = ".$this->destination_course_id." AND |
1277 | 1277 | category_id='" . intval($cat_id). "'"; |
1278 | - $result = Database::query($sql); |
|
1279 | - list($max_order) = Database::fetch_array($result); |
|
1278 | + $result = Database::query($sql); |
|
1279 | + list($max_order) = Database::fetch_array($result); |
|
1280 | 1280 | |
1281 | 1281 | $params = []; |
1282 | - if (!empty($session_id)) { |
|
1282 | + if (!empty($session_id)) { |
|
1283 | 1283 | $params['session_id'] = $session_id; |
1284 | - } |
|
1284 | + } |
|
1285 | 1285 | |
1286 | 1286 | $params['c_id'] = $this->destination_course_id; |
1287 | 1287 | $params['url'] = self::DBUTF8($link->url); |
@@ -1310,9 +1310,9 @@ discard block |
||
1310 | 1310 | } |
1311 | 1311 | $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id; |
1312 | 1312 | } |
1313 | - } |
|
1314 | - } |
|
1315 | - } |
|
1313 | + } |
|
1314 | + } |
|
1315 | + } |
|
1316 | 1316 | |
1317 | 1317 | /** |
1318 | 1318 | * Restore a link-category |
@@ -1356,21 +1356,21 @@ discard block |
||
1356 | 1356 | return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id; |
1357 | 1357 | } |
1358 | 1358 | |
1359 | - /** |
|
1360 | - * Restore tool intro |
|
1361 | - */ |
|
1359 | + /** |
|
1360 | + * Restore tool intro |
|
1361 | + */ |
|
1362 | 1362 | public function restore_tool_intro($sessionId = 0) |
1363 | 1363 | { |
1364 | - if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) { |
|
1364 | + if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) { |
|
1365 | 1365 | $sessionId = intval($sessionId); |
1366 | - $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO); |
|
1367 | - $resources = $this->course->resources; |
|
1368 | - foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) { |
|
1369 | - $sql = "DELETE FROM ".$tool_intro_table." |
|
1366 | + $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO); |
|
1367 | + $resources = $this->course->resources; |
|
1368 | + foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) { |
|
1369 | + $sql = "DELETE FROM ".$tool_intro_table." |
|
1370 | 1370 | WHERE |
1371 | 1371 | c_id = ".$this->destination_course_id." AND |
1372 | 1372 | id='".self::DBUTF8escapestring($tool_intro->id)."'"; |
1373 | - Database::query($sql); |
|
1373 | + Database::query($sql); |
|
1374 | 1374 | |
1375 | 1375 | $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
1376 | 1376 | $tool_intro->intro_text, |
@@ -1398,21 +1398,21 @@ discard block |
||
1398 | 1398 | |
1399 | 1399 | $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id; |
1400 | 1400 | } |
1401 | - } |
|
1402 | - } |
|
1403 | - } |
|
1401 | + } |
|
1402 | + } |
|
1403 | + } |
|
1404 | 1404 | |
1405 | - /** |
|
1406 | - * Restore events |
|
1407 | - */ |
|
1405 | + /** |
|
1406 | + * Restore events |
|
1407 | + */ |
|
1408 | 1408 | public function restore_events($sessionId = 0) |
1409 | 1409 | { |
1410 | - if ($this->course->has_resources(RESOURCE_EVENT)) { |
|
1410 | + if ($this->course->has_resources(RESOURCE_EVENT)) { |
|
1411 | 1411 | $sessionId = intval($sessionId); |
1412 | - $table = Database :: get_course_table(TABLE_AGENDA); |
|
1413 | - $resources = $this->course->resources; |
|
1414 | - foreach ($resources[RESOURCE_EVENT] as $id => $event) { |
|
1415 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1412 | + $table = Database :: get_course_table(TABLE_AGENDA); |
|
1413 | + $resources = $this->course->resources; |
|
1414 | + foreach ($resources[RESOURCE_EVENT] as $id => $event) { |
|
1415 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1416 | 1416 | $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
1417 | 1417 | $event->content, |
1418 | 1418 | $this->course->code, |
@@ -1430,7 +1430,7 @@ discard block |
||
1430 | 1430 | 'end_date' => $event->end_date, |
1431 | 1431 | 'session_id' => $sessionId, |
1432 | 1432 | ]; |
1433 | - $new_event_id = Database::insert($table, $params); |
|
1433 | + $new_event_id = Database::insert($table, $params); |
|
1434 | 1434 | |
1435 | 1435 | if ($new_event_id) { |
1436 | 1436 | $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id"; |
@@ -1443,30 +1443,30 @@ discard block |
||
1443 | 1443 | $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; |
1444 | 1444 | } |
1445 | 1445 | |
1446 | - // Copy event attachment |
|
1446 | + // Copy event attachment |
|
1447 | 1447 | |
1448 | - $origin_path = $this->course->backup_path.'/upload/calendar/'; |
|
1449 | - $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
1448 | + $origin_path = $this->course->backup_path.'/upload/calendar/'; |
|
1449 | + $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
1450 | 1450 | |
1451 | - if (!empty($this->course->orig)) { |
|
1451 | + if (!empty($this->course->orig)) { |
|
1452 | 1452 | |
1453 | - $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1454 | - $sql = 'SELECT path, comment, size, filename |
|
1453 | + $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1454 | + $sql = 'SELECT path, comment, size, filename |
|
1455 | 1455 | FROM '.$table_attachment.' |
1456 | 1456 | WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id; |
1457 | - $attachment_event = Database::query($sql); |
|
1458 | - $attachment_event = Database::fetch_object($attachment_event); |
|
1457 | + $attachment_event = Database::query($sql); |
|
1458 | + $attachment_event = Database::fetch_object($attachment_event); |
|
1459 | 1459 | |
1460 | - if (file_exists($origin_path.$attachment_event->path) && |
|
1460 | + if (file_exists($origin_path.$attachment_event->path) && |
|
1461 | 1461 | !is_dir($origin_path.$attachment_event->path) |
1462 | 1462 | ) { |
1463 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1464 | - $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename); |
|
1465 | - //$copy_result = true; |
|
1466 | - if ($copy_result) { |
|
1467 | - $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1463 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1464 | + $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename); |
|
1465 | + //$copy_result = true; |
|
1466 | + if ($copy_result) { |
|
1467 | + $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1468 | 1468 | |
1469 | - $params = [ |
|
1469 | + $params = [ |
|
1470 | 1470 | 'c_id' => $this->destination_course_id, |
1471 | 1471 | 'path' => self::DBUTF8($new_filename), |
1472 | 1472 | 'comment' => self::DBUTF8($attachment_event->comment), |
@@ -1480,17 +1480,17 @@ discard block |
||
1480 | 1480 | Database::query($sql); |
1481 | 1481 | } |
1482 | 1482 | } |
1483 | - } |
|
1484 | - } else { |
|
1485 | - // get the info of the file |
|
1486 | - if (!empty($event->attachment_path) && |
|
1483 | + } |
|
1484 | + } else { |
|
1485 | + // get the info of the file |
|
1486 | + if (!empty($event->attachment_path) && |
|
1487 | 1487 | is_file($origin_path.$event->attachment_path) && |
1488 | 1488 | is_readable($origin_path.$event->attachment_path) |
1489 | 1489 | ) { |
1490 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1491 | - $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename); |
|
1492 | - if ($copy_result) { |
|
1493 | - $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1490 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1491 | + $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename); |
|
1492 | + if ($copy_result) { |
|
1493 | + $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
1494 | 1494 | |
1495 | 1495 | $params = [ |
1496 | 1496 | 'c_id' => $this->destination_course_id, |
@@ -1506,29 +1506,29 @@ discard block |
||
1506 | 1506 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id"; |
1507 | 1507 | Database::query($sql); |
1508 | 1508 | } |
1509 | - } |
|
1510 | - } |
|
1511 | - } |
|
1512 | - } |
|
1513 | - } |
|
1514 | - } |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * Restore course-description |
|
1518 | - */ |
|
1509 | + } |
|
1510 | + } |
|
1511 | + } |
|
1512 | + } |
|
1513 | + } |
|
1514 | + } |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * Restore course-description |
|
1518 | + */ |
|
1519 | 1519 | public function restore_course_descriptions($session_id = 0) |
1520 | 1520 | { |
1521 | - if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) { |
|
1522 | - $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); |
|
1523 | - $resources = $this->course->resources; |
|
1524 | - foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) { |
|
1521 | + if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) { |
|
1522 | + $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); |
|
1523 | + $resources = $this->course->resources; |
|
1524 | + foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) { |
|
1525 | 1525 | $courseDescription = (array) $cd; |
1526 | 1526 | |
1527 | 1527 | $content = isset($courseDescription['content']) ? $courseDescription['content'] : ''; |
1528 | 1528 | $descriptionType = isset($courseDescription['description_type']) ? $courseDescription['description_type'] : ''; |
1529 | 1529 | $title = isset($courseDescription['title']) ? $courseDescription['title'] : ''; |
1530 | 1530 | |
1531 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1531 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1532 | 1532 | $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
1533 | 1533 | $content, |
1534 | 1534 | $this->course->code, |
@@ -1556,22 +1556,22 @@ discard block |
||
1556 | 1556 | } |
1557 | 1557 | $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id; |
1558 | 1558 | } |
1559 | - } |
|
1560 | - } |
|
1561 | - } |
|
1559 | + } |
|
1560 | + } |
|
1561 | + } |
|
1562 | 1562 | |
1563 | - /** |
|
1564 | - * Restore announcements |
|
1565 | - */ |
|
1563 | + /** |
|
1564 | + * Restore announcements |
|
1565 | + */ |
|
1566 | 1566 | public function restore_announcements($sessionId = 0) |
1567 | 1567 | { |
1568 | - if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { |
|
1568 | + if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { |
|
1569 | 1569 | $sessionId = intval($sessionId); |
1570 | - $table = Database :: get_course_table(TABLE_ANNOUNCEMENT); |
|
1571 | - $resources = $this->course->resources; |
|
1572 | - foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) { |
|
1570 | + $table = Database :: get_course_table(TABLE_ANNOUNCEMENT); |
|
1571 | + $resources = $this->course->resources; |
|
1572 | + foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) { |
|
1573 | 1573 | |
1574 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1574 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1575 | 1575 | $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
1576 | 1576 | $announcement->content, |
1577 | 1577 | $this->course->code, |
@@ -1590,7 +1590,7 @@ discard block |
||
1590 | 1590 | 'session_id' => $sessionId, |
1591 | 1591 | ]; |
1592 | 1592 | |
1593 | - $new_announcement_id = Database::insert($table, $params); |
|
1593 | + $new_announcement_id = Database::insert($table, $params); |
|
1594 | 1594 | |
1595 | 1595 | if ($new_announcement_id) { |
1596 | 1596 | $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id"; |
@@ -1602,32 +1602,32 @@ discard block |
||
1602 | 1602 | $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id; |
1603 | 1603 | } |
1604 | 1604 | |
1605 | - $origin_path = $this->course->backup_path.'/upload/announcements/'; |
|
1606 | - $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/'; |
|
1605 | + $origin_path = $this->course->backup_path.'/upload/announcements/'; |
|
1606 | + $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/'; |
|
1607 | 1607 | |
1608 | - // Copy announcement attachment file |
|
1609 | - if (!empty($this->course->orig)) { |
|
1608 | + // Copy announcement attachment file |
|
1609 | + if (!empty($this->course->orig)) { |
|
1610 | 1610 | |
1611 | - $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1612 | - $sql = 'SELECT path, comment, size, filename |
|
1611 | + $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1612 | + $sql = 'SELECT path, comment, size, filename |
|
1613 | 1613 | FROM '.$table_attachment.' |
1614 | 1614 | WHERE |
1615 | 1615 | c_id = '.$this->destination_course_id.' AND |
1616 | 1616 | announcement_id = '.$id; |
1617 | - $attachment_event = Database::query($sql); |
|
1618 | - $attachment_event = Database::fetch_object($attachment_event); |
|
1617 | + $attachment_event = Database::query($sql); |
|
1618 | + $attachment_event = Database::fetch_object($attachment_event); |
|
1619 | 1619 | |
1620 | - if (file_exists($origin_path.$attachment_event->path) && |
|
1620 | + if (file_exists($origin_path.$attachment_event->path) && |
|
1621 | 1621 | !is_dir($origin_path.$attachment_event->path) |
1622 | 1622 | ) { |
1623 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1623 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1624 | 1624 | $copy_result = copy( |
1625 | 1625 | $origin_path.$attachment_event->path, |
1626 | 1626 | $destination_path.$new_filename |
1627 | 1627 | ); |
1628 | 1628 | |
1629 | - if ($copy_result) { |
|
1630 | - $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1629 | + if ($copy_result) { |
|
1630 | + $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1631 | 1631 | |
1632 | 1632 | $params = [ |
1633 | 1633 | 'c_id' => $this->destination_course_id, |
@@ -1644,20 +1644,20 @@ discard block |
||
1644 | 1644 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId"; |
1645 | 1645 | Database::query($sql); |
1646 | 1646 | } |
1647 | - } |
|
1648 | - } |
|
1649 | - } else { |
|
1650 | - // get the info of the file |
|
1651 | - if (!empty($announcement->attachment_path) && |
|
1647 | + } |
|
1648 | + } |
|
1649 | + } else { |
|
1650 | + // get the info of the file |
|
1651 | + if (!empty($announcement->attachment_path) && |
|
1652 | 1652 | is_file($origin_path.$announcement->attachment_path) && |
1653 | 1653 | is_readable($origin_path.$announcement->attachment_path) |
1654 | 1654 | ) { |
1655 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1656 | - $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename); |
|
1655 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
1656 | + $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename); |
|
1657 | 1657 | |
1658 | - if ($copy_result) { |
|
1659 | - $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1660 | - /*$sql = "INSERT INTO ".$table_attachment." SET |
|
1658 | + if ($copy_result) { |
|
1659 | + $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
1660 | + /*$sql = "INSERT INTO ".$table_attachment." SET |
|
1661 | 1661 | c_id = ".$this->destination_course_id." , |
1662 | 1662 | path = '".self::DBUTF8escapestring($new_filename)."', |
1663 | 1663 | comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."', |
@@ -1680,12 +1680,12 @@ discard block |
||
1680 | 1680 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId"; |
1681 | 1681 | Database::query($sql); |
1682 | 1682 | } |
1683 | - } |
|
1684 | - } |
|
1685 | - } |
|
1686 | - } |
|
1687 | - } |
|
1688 | - } |
|
1683 | + } |
|
1684 | + } |
|
1685 | + } |
|
1686 | + } |
|
1687 | + } |
|
1688 | + } |
|
1689 | 1689 | |
1690 | 1690 | /** |
1691 | 1691 | * Restore Quiz |
@@ -1696,13 +1696,13 @@ discard block |
||
1696 | 1696 | $session_id = 0, |
1697 | 1697 | $respect_base_content = false |
1698 | 1698 | ) { |
1699 | - if ($this->course->has_resources(RESOURCE_QUIZ)) { |
|
1700 | - $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); |
|
1701 | - $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
1702 | - $table_doc = Database :: get_course_table(TABLE_DOCUMENT); |
|
1703 | - $resources = $this->course->resources; |
|
1699 | + if ($this->course->has_resources(RESOURCE_QUIZ)) { |
|
1700 | + $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); |
|
1701 | + $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
1702 | + $table_doc = Database :: get_course_table(TABLE_DOCUMENT); |
|
1703 | + $resources = $this->course->resources; |
|
1704 | 1704 | |
1705 | - foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) { |
|
1705 | + foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) { |
|
1706 | 1706 | |
1707 | 1707 | if (isset($quiz->obj)) { |
1708 | 1708 | //For new imports |
@@ -1712,7 +1712,7 @@ discard block |
||
1712 | 1712 | $quiz->obj = $quiz; |
1713 | 1713 | } |
1714 | 1714 | |
1715 | - $doc = ''; |
|
1715 | + $doc = ''; |
|
1716 | 1716 | if (!empty($quiz->sound)) { |
1717 | 1717 | if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) && |
1718 | 1718 | $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) { |
@@ -1720,14 +1720,14 @@ discard block |
||
1720 | 1720 | WHERE |
1721 | 1721 | c_id = " . $this->destination_course_id . " AND |
1722 | 1722 | id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id; |
1723 | - $doc = Database::query($sql); |
|
1724 | - $doc = Database::fetch_object($doc); |
|
1725 | - $doc = str_replace('/audio/', '', $doc->path); |
|
1726 | - } |
|
1727 | - } |
|
1728 | - |
|
1729 | - if ($id != -1) { |
|
1730 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1723 | + $doc = Database::query($sql); |
|
1724 | + $doc = Database::fetch_object($doc); |
|
1725 | + $doc = str_replace('/audio/', '', $doc->path); |
|
1726 | + } |
|
1727 | + } |
|
1728 | + |
|
1729 | + if ($id != -1) { |
|
1730 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1731 | 1731 | $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
1732 | 1732 | $quiz->description, |
1733 | 1733 | $this->course->code, |
@@ -1736,13 +1736,13 @@ discard block |
||
1736 | 1736 | $this->course->info['path'] |
1737 | 1737 | ); |
1738 | 1738 | |
1739 | - global $_custom; |
|
1740 | - if (isset($_custom['exercises_clean_dates_when_restoring']) && |
|
1739 | + global $_custom; |
|
1740 | + if (isset($_custom['exercises_clean_dates_when_restoring']) && |
|
1741 | 1741 | $_custom['exercises_clean_dates_when_restoring'] |
1742 | 1742 | ) { |
1743 | - $quiz->start_time = null; |
|
1744 | - $quiz->end_time = null; |
|
1745 | - } |
|
1743 | + $quiz->start_time = null; |
|
1744 | + $quiz->end_time = null; |
|
1745 | + } |
|
1746 | 1746 | |
1747 | 1747 | $params = array( |
1748 | 1748 | 'c_id' => $this->destination_course_id, |
@@ -1774,10 +1774,10 @@ discard block |
||
1774 | 1774 | } |
1775 | 1775 | $params['session_id'] = $my_session_id; |
1776 | 1776 | } else { |
1777 | - if (!empty($session_id)) { |
|
1778 | - $session_id = intval($session_id); |
|
1777 | + if (!empty($session_id)) { |
|
1778 | + $session_id = intval($session_id); |
|
1779 | 1779 | $params['session_id'] = $session_id; |
1780 | - } |
|
1780 | + } |
|
1781 | 1781 | } |
1782 | 1782 | $new_id = Database::insert($table_qui, $params); |
1783 | 1783 | |
@@ -1786,15 +1786,15 @@ discard block |
||
1786 | 1786 | Database::query($sql); |
1787 | 1787 | } |
1788 | 1788 | |
1789 | - } else { |
|
1790 | - // $id = -1 identifies the fictionary test for collecting |
|
1791 | - // orphan questions. We do not store it in the database. |
|
1792 | - $new_id = -1; |
|
1793 | - } |
|
1789 | + } else { |
|
1790 | + // $id = -1 identifies the fictionary test for collecting |
|
1791 | + // orphan questions. We do not store it in the database. |
|
1792 | + $new_id = -1; |
|
1793 | + } |
|
1794 | 1794 | |
1795 | - $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id; |
|
1795 | + $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id; |
|
1796 | 1796 | |
1797 | - $order = 0; |
|
1797 | + $order = 0; |
|
1798 | 1798 | if (!empty($quiz->question_ids)) { |
1799 | 1799 | foreach ($quiz->question_ids as $index => $question_id) { |
1800 | 1800 | $qid = $this->restore_quiz_question($question_id); |
@@ -1807,30 +1807,30 @@ discard block |
||
1807 | 1807 | Database::query($sql); |
1808 | 1808 | } |
1809 | 1809 | } |
1810 | - } |
|
1811 | - } |
|
1812 | - } |
|
1810 | + } |
|
1811 | + } |
|
1812 | + } |
|
1813 | 1813 | |
1814 | - /** |
|
1815 | - * Restore quiz-questions |
|
1814 | + /** |
|
1815 | + * Restore quiz-questions |
|
1816 | 1816 | * @params int question id |
1817 | - */ |
|
1817 | + */ |
|
1818 | 1818 | public function restore_quiz_question($id) |
1819 | 1819 | { |
1820 | - $resources = $this->course->resources; |
|
1820 | + $resources = $this->course->resources; |
|
1821 | 1821 | $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null; |
1822 | 1822 | |
1823 | - $new_id = 0; |
|
1823 | + $new_id = 0; |
|
1824 | 1824 | |
1825 | - if (is_object($question)) { |
|
1826 | - if ($question->is_restored()) { |
|
1827 | - return $question->destination_id; |
|
1828 | - } |
|
1829 | - $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
1830 | - $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
1825 | + if (is_object($question)) { |
|
1826 | + if ($question->is_restored()) { |
|
1827 | + return $question->destination_id; |
|
1828 | + } |
|
1829 | + $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
1830 | + $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
1831 | 1831 | $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); |
1832 | 1832 | |
1833 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1833 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1834 | 1834 | $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
1835 | 1835 | $question->description, |
1836 | 1836 | $this->course->code, |
@@ -1851,7 +1851,7 @@ discard block |
||
1851 | 1851 | 'extra' => self::DBUTF8($question->extra), |
1852 | 1852 | ]; |
1853 | 1853 | |
1854 | - $new_id = Database::insert($table_que, $params); |
|
1854 | + $new_id = Database::insert($table_que, $params); |
|
1855 | 1855 | |
1856 | 1856 | if ($new_id) { |
1857 | 1857 | |
@@ -1892,7 +1892,7 @@ discard block |
||
1892 | 1892 | |
1893 | 1893 | foreach ($temp as $index => $answer) { |
1894 | 1894 | //id = '".$index."', |
1895 | - $params = [ |
|
1895 | + $params = [ |
|
1896 | 1896 | 'c_id' => $this->destination_course_id, |
1897 | 1897 | 'question_id' => $new_id, |
1898 | 1898 | 'answer' => self::DBUTF8($answer['answer']), |
@@ -1909,12 +1909,12 @@ discard block |
||
1909 | 1909 | $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId"; |
1910 | 1910 | Database::query($sql); |
1911 | 1911 | } |
1912 | - } |
|
1913 | - } else { |
|
1912 | + } |
|
1913 | + } else { |
|
1914 | 1914 | $correct_answers = array(); |
1915 | - foreach ($question->answers as $index => $answer) { |
|
1915 | + foreach ($question->answers as $index => $answer) { |
|
1916 | 1916 | |
1917 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1917 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
1918 | 1918 | $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
1919 | 1919 | $answer['answer'], |
1920 | 1920 | $this->course->code, |
@@ -1953,8 +1953,8 @@ discard block |
||
1953 | 1953 | } |
1954 | 1954 | |
1955 | 1955 | $correct_answers[$answerId] = $answer['correct']; |
1956 | - } |
|
1957 | - } |
|
1956 | + } |
|
1957 | + } |
|
1958 | 1958 | |
1959 | 1959 | //Current course id |
1960 | 1960 | $course_id = api_get_course_int_id(); |
@@ -2051,12 +2051,12 @@ discard block |
||
2051 | 2051 | } |
2052 | 2052 | } |
2053 | 2053 | } |
2054 | - $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id; |
|
2055 | - } |
|
2056 | - return $new_id; |
|
2057 | - } |
|
2054 | + $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id; |
|
2055 | + } |
|
2056 | + return $new_id; |
|
2057 | + } |
|
2058 | 2058 | |
2059 | - /** |
|
2059 | + /** |
|
2060 | 2060 | * @todo : add session id when used for session |
2061 | 2061 | */ |
2062 | 2062 | public function restore_test_category($session_id, $respect_base_content, $destination_course_code) |
@@ -2136,21 +2136,21 @@ discard block |
||
2136 | 2136 | $sessionId = intval($sessionId); |
2137 | 2137 | |
2138 | 2138 | if ($this->course->has_resources(RESOURCE_SURVEY)) { |
2139 | - $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
2140 | - $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
2141 | - $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
2142 | - $resources = $this->course->resources; |
|
2143 | - foreach ($resources[RESOURCE_SURVEY] as $id => $survey) { |
|
2139 | + $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
2140 | + $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
2141 | + $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
2142 | + $resources = $this->course->resources; |
|
2143 | + foreach ($resources[RESOURCE_SURVEY] as $id => $survey) { |
|
2144 | 2144 | |
2145 | - $sql = 'SELECT survey_id FROM '.$table_sur.' |
|
2145 | + $sql = 'SELECT survey_id FROM '.$table_sur.' |
|
2146 | 2146 | WHERE |
2147 | 2147 | c_id = '.$this->destination_course_id.' AND |
2148 | 2148 | code = "'.self::DBUTF8escapestring($survey->code).'" AND |
2149 | 2149 | lang = "'.self::DBUTF8escapestring($survey->lang).'" '; |
2150 | 2150 | |
2151 | - $result_check = Database::query($sql); |
|
2151 | + $result_check = Database::query($sql); |
|
2152 | 2152 | |
2153 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2153 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2154 | 2154 | $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
2155 | 2155 | $survey->title, |
2156 | 2156 | $this->course->code, |
@@ -2204,20 +2204,20 @@ discard block |
||
2204 | 2204 | 'session_id' => $sessionId, |
2205 | 2205 | ]; |
2206 | 2206 | |
2207 | - //An existing survey exists with the same code and the same language |
|
2208 | - if (Database::num_rows($result_check) == 1) { |
|
2209 | - switch ($this->file_option) { |
|
2210 | - case FILE_SKIP: |
|
2211 | - //Do nothing |
|
2212 | - break; |
|
2213 | - case FILE_RENAME: |
|
2214 | - $survey_code = $survey->code.'_'; |
|
2215 | - $i=1; |
|
2216 | - $temp_survey_code = $survey_code.$i; |
|
2217 | - while (!$this->is_survey_code_available($temp_survey_code)) { |
|
2218 | - $temp_survey_code = $survey_code.++$i; |
|
2219 | - } |
|
2220 | - $survey_code = $temp_survey_code; |
|
2207 | + //An existing survey exists with the same code and the same language |
|
2208 | + if (Database::num_rows($result_check) == 1) { |
|
2209 | + switch ($this->file_option) { |
|
2210 | + case FILE_SKIP: |
|
2211 | + //Do nothing |
|
2212 | + break; |
|
2213 | + case FILE_RENAME: |
|
2214 | + $survey_code = $survey->code.'_'; |
|
2215 | + $i=1; |
|
2216 | + $temp_survey_code = $survey_code.$i; |
|
2217 | + while (!$this->is_survey_code_available($temp_survey_code)) { |
|
2218 | + $temp_survey_code = $survey_code.++$i; |
|
2219 | + } |
|
2220 | + $survey_code = $temp_survey_code; |
|
2221 | 2221 | |
2222 | 2222 | $params['code'] = $survey_code; |
2223 | 2223 | $new_id = Database::insert($table_sur, $params); |
@@ -2236,25 +2236,25 @@ discard block |
||
2236 | 2236 | Database::query($sql); |
2237 | 2237 | } |
2238 | 2238 | } |
2239 | - break; |
|
2240 | - case FILE_OVERWRITE: |
|
2241 | - // Delete the existing survey with the same code and language and import the one of the source course |
|
2242 | - // getting the information of the survey (used for when the survey is shared) |
|
2239 | + break; |
|
2240 | + case FILE_OVERWRITE: |
|
2241 | + // Delete the existing survey with the same code and language and import the one of the source course |
|
2242 | + // getting the information of the survey (used for when the survey is shared) |
|
2243 | 2243 | |
2244 | - $sql = "SELECT * FROM $table_sur |
|
2244 | + $sql = "SELECT * FROM $table_sur |
|
2245 | 2245 | WHERE |
2246 | 2246 | c_id = ".$this->destination_course_id." AND |
2247 | 2247 | survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'"; |
2248 | - $result = Database::query($sql); |
|
2249 | - $survey_data = Database::fetch_array($result,'ASSOC'); |
|
2248 | + $result = Database::query($sql); |
|
2249 | + $survey_data = Database::fetch_array($result,'ASSOC'); |
|
2250 | 2250 | |
2251 | - // if the survey is shared => also delete the shared content |
|
2252 | - if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) { |
|
2251 | + // if the survey is shared => also delete the shared content |
|
2252 | + if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) { |
|
2253 | 2253 | SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id); |
2254 | - } |
|
2255 | - SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id); |
|
2254 | + } |
|
2255 | + SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id); |
|
2256 | 2256 | |
2257 | - // Insert the new source survey |
|
2257 | + // Insert the new source survey |
|
2258 | 2258 | $new_id = Database::insert($table_sur, $params); |
2259 | 2259 | |
2260 | 2260 | if ($new_id) { |
@@ -2275,11 +2275,11 @@ discard block |
||
2275 | 2275 | Database::query($sql); |
2276 | 2276 | } |
2277 | 2277 | } |
2278 | - break; |
|
2279 | - default: |
|
2280 | - break; |
|
2281 | - } |
|
2282 | - } else { |
|
2278 | + break; |
|
2279 | + default: |
|
2280 | + break; |
|
2281 | + } |
|
2282 | + } else { |
|
2283 | 2283 | // No existing survey with the same language and the same code, we just copy the survey |
2284 | 2284 | $new_id = Database::insert($table_sur, $params); |
2285 | 2285 | |
@@ -2301,45 +2301,45 @@ discard block |
||
2301 | 2301 | Database::query($sql); |
2302 | 2302 | } |
2303 | 2303 | } |
2304 | - } |
|
2305 | - } |
|
2306 | - } |
|
2307 | - } |
|
2308 | - |
|
2309 | - /** |
|
2310 | - * Check availability of a survey code |
|
2311 | - * @param string $survey_code |
|
2312 | - */ |
|
2304 | + } |
|
2305 | + } |
|
2306 | + } |
|
2307 | + } |
|
2308 | + |
|
2309 | + /** |
|
2310 | + * Check availability of a survey code |
|
2311 | + * @param string $survey_code |
|
2312 | + */ |
|
2313 | 2313 | public function is_survey_code_available($survey_code) |
2314 | 2314 | { |
2315 | - $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
2316 | - $sql = "SELECT * FROM $table_sur |
|
2315 | + $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
2316 | + $sql = "SELECT * FROM $table_sur |
|
2317 | 2317 | WHERE |
2318 | 2318 | c_id = ".$this->destination_course_id." AND |
2319 | 2319 | code='".self::DBUTF8escapestring($survey_code)."'"; |
2320 | - $result = Database::query($sql); |
|
2321 | - if (Database::num_rows($result) > 0) return false; else return true; |
|
2322 | - } |
|
2323 | - |
|
2324 | - /** |
|
2325 | - * Restore survey-questions |
|
2326 | - * @param string $survey_id |
|
2327 | - */ |
|
2320 | + $result = Database::query($sql); |
|
2321 | + if (Database::num_rows($result) > 0) return false; else return true; |
|
2322 | + } |
|
2323 | + |
|
2324 | + /** |
|
2325 | + * Restore survey-questions |
|
2326 | + * @param string $survey_id |
|
2327 | + */ |
|
2328 | 2328 | public function restore_survey_question($id, $survey_id) |
2329 | 2329 | { |
2330 | - $resources = $this->course->resources; |
|
2331 | - $question = $resources[RESOURCE_SURVEYQUESTION][$id]; |
|
2330 | + $resources = $this->course->resources; |
|
2331 | + $question = $resources[RESOURCE_SURVEYQUESTION][$id]; |
|
2332 | 2332 | |
2333 | - $new_id=0; |
|
2333 | + $new_id=0; |
|
2334 | 2334 | |
2335 | - if (is_object($question)) { |
|
2336 | - if ($question->is_restored()) { |
|
2337 | - return $question->destination_id; |
|
2338 | - } |
|
2339 | - $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
2340 | - $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
2335 | + if (is_object($question)) { |
|
2336 | + if ($question->is_restored()) { |
|
2337 | + return $question->destination_id; |
|
2338 | + } |
|
2339 | + $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
2340 | + $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
2341 | 2341 | |
2342 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2342 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2343 | 2343 | $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
2344 | 2344 | $question->survey_question, |
2345 | 2345 | $this->course->code, |
@@ -2393,10 +2393,10 @@ discard block |
||
2393 | 2393 | } |
2394 | 2394 | $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id; |
2395 | 2395 | } |
2396 | - } |
|
2396 | + } |
|
2397 | 2397 | |
2398 | - return $new_id; |
|
2399 | - } |
|
2398 | + return $new_id; |
|
2399 | + } |
|
2400 | 2400 | |
2401 | 2401 | /** |
2402 | 2402 | * Restoring learning paths |
@@ -2407,20 +2407,20 @@ discard block |
||
2407 | 2407 | { |
2408 | 2408 | $session_id = intval($session_id); |
2409 | 2409 | |
2410 | - if ($this->course->has_resources(RESOURCE_LEARNPATH)) { |
|
2410 | + if ($this->course->has_resources(RESOURCE_LEARNPATH)) { |
|
2411 | 2411 | $table_main = Database::get_course_table(TABLE_LP_MAIN); |
2412 | 2412 | $table_item = Database::get_course_table(TABLE_LP_ITEM); |
2413 | 2413 | $table_tool = Database::get_course_table(TABLE_TOOL_LIST); |
2414 | 2414 | |
2415 | - $resources = $this->course->resources; |
|
2415 | + $resources = $this->course->resources; |
|
2416 | 2416 | |
2417 | - $origin_path = $this->course->backup_path.'/upload/learning_path/images/'; |
|
2418 | - $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/'; |
|
2417 | + $origin_path = $this->course->backup_path.'/upload/learning_path/images/'; |
|
2418 | + $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/'; |
|
2419 | 2419 | |
2420 | - foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) { |
|
2420 | + foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) { |
|
2421 | 2421 | |
2422 | - $condition_session = ""; |
|
2423 | - if (!empty($session_id)) { |
|
2422 | + $condition_session = ""; |
|
2423 | + if (!empty($session_id)) { |
|
2424 | 2424 | if ($respect_base_content) { |
2425 | 2425 | $my_session_id = $lp->session_id; |
2426 | 2426 | if (!empty($lp->session_id)) { |
@@ -2431,21 +2431,21 @@ discard block |
||
2431 | 2431 | $session_id = intval($session_id); |
2432 | 2432 | $condition_session = $session_id; |
2433 | 2433 | } |
2434 | - } |
|
2435 | - |
|
2436 | - // Adding the author's image |
|
2437 | - if (!empty($lp->preview_image)) { |
|
2438 | - $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image)); |
|
2439 | - if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) { |
|
2440 | - $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename); |
|
2441 | - //$copy_result = true; |
|
2442 | - if ($copy_result) { |
|
2443 | - $lp->preview_image = $new_filename; |
|
2444 | - } else { |
|
2445 | - $lp->preview_image =''; |
|
2446 | - } |
|
2447 | - } |
|
2448 | - } |
|
2434 | + } |
|
2435 | + |
|
2436 | + // Adding the author's image |
|
2437 | + if (!empty($lp->preview_image)) { |
|
2438 | + $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image)); |
|
2439 | + if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) { |
|
2440 | + $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename); |
|
2441 | + //$copy_result = true; |
|
2442 | + if ($copy_result) { |
|
2443 | + $lp->preview_image = $new_filename; |
|
2444 | + } else { |
|
2445 | + $lp->preview_image =''; |
|
2446 | + } |
|
2447 | + } |
|
2448 | + } |
|
2449 | 2449 | |
2450 | 2450 | if ($this->add_text_in_items) { |
2451 | 2451 | $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix'); |
@@ -2492,7 +2492,7 @@ discard block |
||
2492 | 2492 | $params['session_id'] = $condition_session; |
2493 | 2493 | } |
2494 | 2494 | |
2495 | - $new_lp_id = Database::insert($table_main, $params); |
|
2495 | + $new_lp_id = Database::insert($table_main, $params); |
|
2496 | 2496 | |
2497 | 2497 | if ($new_lp_id) { |
2498 | 2498 | |
@@ -2553,13 +2553,13 @@ discard block |
||
2553 | 2553 | $old_refs = array(); |
2554 | 2554 | $prerequisite_ids = array(); |
2555 | 2555 | |
2556 | - foreach ($lp->get_items() as $index => $item) { |
|
2557 | - // we set the ref code here and then we update in a for loop |
|
2558 | - $ref = $item['ref']; |
|
2556 | + foreach ($lp->get_items() as $index => $item) { |
|
2557 | + // we set the ref code here and then we update in a for loop |
|
2558 | + $ref = $item['ref']; |
|
2559 | 2559 | |
2560 | - // Dealing with path the same way as ref as some data has |
|
2560 | + // Dealing with path the same way as ref as some data has |
|
2561 | 2561 | // been put into path when it's a local resource |
2562 | - // Only fix the path for no scos |
|
2562 | + // Only fix the path for no scos |
|
2563 | 2563 | if ($item['item_type'] == 'sco') { |
2564 | 2564 | $path = $item['path']; |
2565 | 2565 | } else { |
@@ -2588,128 +2588,128 @@ discard block |
||
2588 | 2588 | 'launch_data' => self::DBUTF8($item['launch_data']), |
2589 | 2589 | ]; |
2590 | 2590 | |
2591 | - $new_item_id = Database::insert($table_item, $params); |
|
2591 | + $new_item_id = Database::insert($table_item, $params); |
|
2592 | 2592 | |
2593 | 2593 | $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id"; |
2594 | 2594 | Database::query($sql); |
2595 | 2595 | |
2596 | - //save a link between old and new item IDs |
|
2597 | - $new_item_ids[$item['id']] = $new_item_id; |
|
2598 | - //save a reference of items that need a parent_item_id refresh |
|
2599 | - $parent_item_ids[$new_item_id] = $item['parent_item_id']; |
|
2600 | - //save a reference of items that need a previous_item_id refresh |
|
2601 | - $previous_item_ids[$new_item_id] = $item['previous_item_id']; |
|
2602 | - //save a reference of items that need a next_item_id refresh |
|
2603 | - $next_item_ids[$new_item_id] = $item['next_item_id']; |
|
2604 | - |
|
2605 | - if (!empty($item['prerequisite'])) { |
|
2606 | - if ($lp->lp_type =='2') { |
|
2607 | - // if is an sco |
|
2608 | - $old_prerequisite[$new_item_id]= $item['prerequisite']; |
|
2609 | - } else { |
|
2610 | - $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']]; |
|
2611 | - } |
|
2612 | - } |
|
2613 | - |
|
2614 | - if (!empty($ref)) { |
|
2615 | - if ($lp->lp_type =='2') { |
|
2616 | - // if is an sco |
|
2617 | - $old_refs[$new_item_id]= $ref; |
|
2618 | - } else { |
|
2596 | + //save a link between old and new item IDs |
|
2597 | + $new_item_ids[$item['id']] = $new_item_id; |
|
2598 | + //save a reference of items that need a parent_item_id refresh |
|
2599 | + $parent_item_ids[$new_item_id] = $item['parent_item_id']; |
|
2600 | + //save a reference of items that need a previous_item_id refresh |
|
2601 | + $previous_item_ids[$new_item_id] = $item['previous_item_id']; |
|
2602 | + //save a reference of items that need a next_item_id refresh |
|
2603 | + $next_item_ids[$new_item_id] = $item['next_item_id']; |
|
2604 | + |
|
2605 | + if (!empty($item['prerequisite'])) { |
|
2606 | + if ($lp->lp_type =='2') { |
|
2607 | + // if is an sco |
|
2608 | + $old_prerequisite[$new_item_id]= $item['prerequisite']; |
|
2609 | + } else { |
|
2610 | + $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']]; |
|
2611 | + } |
|
2612 | + } |
|
2613 | + |
|
2614 | + if (!empty($ref)) { |
|
2615 | + if ($lp->lp_type =='2') { |
|
2616 | + // if is an sco |
|
2617 | + $old_refs[$new_item_id]= $ref; |
|
2618 | + } else { |
|
2619 | 2619 | $old_refs[$new_item_id]= $new_item_ids[$ref]; |
2620 | - } |
|
2621 | - } |
|
2620 | + } |
|
2621 | + } |
|
2622 | 2622 | |
2623 | - $prerequisite_ids[$new_item_id] = $item['prerequisite']; |
|
2624 | - } |
|
2623 | + $prerequisite_ids[$new_item_id] = $item['prerequisite']; |
|
2624 | + } |
|
2625 | 2625 | |
2626 | - // Updating prerequisites |
|
2627 | - foreach ($old_prerequisite as $key=>$my_old_prerequisite) { |
|
2628 | - if($my_old_prerequisite != ''){ |
|
2629 | - $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."' |
|
2626 | + // Updating prerequisites |
|
2627 | + foreach ($old_prerequisite as $key=>$my_old_prerequisite) { |
|
2628 | + if($my_old_prerequisite != ''){ |
|
2629 | + $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."' |
|
2630 | 2630 | WHERE c_id = ".$this->destination_course_id." AND id = '".$key."' "; |
2631 | - Database::query($sql); |
|
2632 | - } |
|
2633 | - } |
|
2634 | - |
|
2635 | - // Updating refs |
|
2636 | - foreach ($old_refs as $key=>$my_old_ref) { |
|
2637 | - if ($my_old_ref != '') { |
|
2638 | - $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."' |
|
2631 | + Database::query($sql); |
|
2632 | + } |
|
2633 | + } |
|
2634 | + |
|
2635 | + // Updating refs |
|
2636 | + foreach ($old_refs as $key=>$my_old_ref) { |
|
2637 | + if ($my_old_ref != '') { |
|
2638 | + $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."' |
|
2639 | 2639 | WHERE c_id = ".$this->destination_course_id." AND id = '".$key."' "; |
2640 | - Database::query($sql); |
|
2641 | - } |
|
2642 | - } |
|
2643 | - |
|
2644 | - foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) { |
|
2645 | - $parent_new_id = 0; |
|
2646 | - if($parent_item_old_id != 0){ |
|
2647 | - $parent_new_id = $new_item_ids[$parent_item_old_id]; |
|
2648 | - } |
|
2649 | - $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."' |
|
2640 | + Database::query($sql); |
|
2641 | + } |
|
2642 | + } |
|
2643 | + |
|
2644 | + foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) { |
|
2645 | + $parent_new_id = 0; |
|
2646 | + if($parent_item_old_id != 0){ |
|
2647 | + $parent_new_id = $new_item_ids[$parent_item_old_id]; |
|
2648 | + } |
|
2649 | + $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."' |
|
2650 | 2650 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
2651 | - Database::query($sql); |
|
2652 | - } |
|
2653 | - foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) { |
|
2654 | - $previous_new_id = 0; |
|
2655 | - if($previous_item_old_id != 0){ |
|
2656 | - $previous_new_id = $new_item_ids[$previous_item_old_id]; |
|
2657 | - } |
|
2658 | - $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."' |
|
2651 | + Database::query($sql); |
|
2652 | + } |
|
2653 | + foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) { |
|
2654 | + $previous_new_id = 0; |
|
2655 | + if($previous_item_old_id != 0){ |
|
2656 | + $previous_new_id = $new_item_ids[$previous_item_old_id]; |
|
2657 | + } |
|
2658 | + $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."' |
|
2659 | 2659 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
2660 | - Database::query($sql); |
|
2661 | - } |
|
2662 | - |
|
2663 | - foreach ($next_item_ids as $new_item_id => $next_item_old_id) { |
|
2664 | - $next_new_id = 0; |
|
2665 | - if($next_item_old_id != 0){ |
|
2666 | - $next_new_id = $new_item_ids[$next_item_old_id]; |
|
2667 | - } |
|
2668 | - $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."' |
|
2660 | + Database::query($sql); |
|
2661 | + } |
|
2662 | + |
|
2663 | + foreach ($next_item_ids as $new_item_id => $next_item_old_id) { |
|
2664 | + $next_new_id = 0; |
|
2665 | + if($next_item_old_id != 0){ |
|
2666 | + $next_new_id = $new_item_ids[$next_item_old_id]; |
|
2667 | + } |
|
2668 | + $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."' |
|
2669 | 2669 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
2670 | - Database::query($sql); |
|
2671 | - } |
|
2672 | - |
|
2673 | - foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) { |
|
2674 | - $prerequisite_new_id = 0; |
|
2675 | - if($prerequisite_old_id != 0){ |
|
2676 | - $prerequisite_new_id = $new_item_ids[$prerequisite_old_id]; |
|
2677 | - } |
|
2678 | - $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."' |
|
2670 | + Database::query($sql); |
|
2671 | + } |
|
2672 | + |
|
2673 | + foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) { |
|
2674 | + $prerequisite_new_id = 0; |
|
2675 | + if($prerequisite_old_id != 0){ |
|
2676 | + $prerequisite_new_id = $new_item_ids[$prerequisite_old_id]; |
|
2677 | + } |
|
2678 | + $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."' |
|
2679 | 2679 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
2680 | - Database::query($sql); |
|
2681 | - } |
|
2682 | - $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id; |
|
2683 | - } |
|
2684 | - } |
|
2685 | - } |
|
2686 | - |
|
2687 | - /** |
|
2688 | - * Restore works |
|
2680 | + Database::query($sql); |
|
2681 | + } |
|
2682 | + $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id; |
|
2683 | + } |
|
2684 | + } |
|
2685 | + } |
|
2686 | + |
|
2687 | + /** |
|
2688 | + * Restore works |
|
2689 | 2689 | * @deprecated use restore_works |
2690 | 2690 | * |
2691 | - */ |
|
2692 | - public function restore_student_publication($sessionId = 0) |
|
2691 | + */ |
|
2692 | + public function restore_student_publication($sessionId = 0) |
|
2693 | 2693 | { |
2694 | 2694 | $sessionId = intval($sessionId); |
2695 | - $work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); |
|
2696 | - $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
2697 | - $item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
2695 | + $work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); |
|
2696 | + $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
2697 | + $item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
2698 | 2698 | |
2699 | - // Query in student publication |
|
2700 | - $sql = 'SELECT * FROM '.$work_table.' |
|
2699 | + // Query in student publication |
|
2700 | + $sql = 'SELECT * FROM '.$work_table.' |
|
2701 | 2701 | WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) '; |
2702 | 2702 | |
2703 | - $result = Database::query($sql); |
|
2704 | - $folders = Database::store_result($result, 'ASSOC'); |
|
2703 | + $result = Database::query($sql); |
|
2704 | + $folders = Database::store_result($result, 'ASSOC'); |
|
2705 | 2705 | |
2706 | - foreach ($folders as $folder) { |
|
2707 | - $old_id = $folder['id']; |
|
2706 | + foreach ($folders as $folder) { |
|
2707 | + $old_id = $folder['id']; |
|
2708 | 2708 | unset($folder['id']); |
2709 | - $folder['c_id'] = $this->destination_course_id; |
|
2709 | + $folder['c_id'] = $this->destination_course_id; |
|
2710 | 2710 | $folder['parent_id'] = 0; |
2711 | 2711 | $folder['session_id'] = $sessionId; |
2712 | - $new_id = Database::insert($work_table, $folder); |
|
2712 | + $new_id = Database::insert($work_table, $folder); |
|
2713 | 2713 | |
2714 | 2714 | if ($new_id) { |
2715 | 2715 | //query in item property |
@@ -2768,23 +2768,23 @@ discard block |
||
2768 | 2768 | } |
2769 | 2769 | } |
2770 | 2770 | } |
2771 | - } |
|
2771 | + } |
|
2772 | 2772 | |
2773 | - $destination = '../../courses/'.$this->course->destination_path.'/work/'; |
|
2774 | - $origin = '../../courses/'.$this->course->info['path'].'/work/'; |
|
2775 | - self::allow_create_all_directory($origin,$destination,false); |
|
2776 | - } |
|
2773 | + $destination = '../../courses/'.$this->course->destination_path.'/work/'; |
|
2774 | + $origin = '../../courses/'.$this->course->info['path'].'/work/'; |
|
2775 | + self::allow_create_all_directory($origin,$destination,false); |
|
2776 | + } |
|
2777 | 2777 | |
2778 | 2778 | /** |
2779 | - * copy all directory and sub directory |
|
2780 | - * @param string The path origin |
|
2781 | - * @param string The path destination |
|
2782 | - * @param boolean Option Overwrite |
|
2783 | - * @param string $source |
|
2784 | - * @param string $dest |
|
2785 | - * @return void() |
|
2786 | - * @deprecated |
|
2787 | - */ |
|
2779 | + * copy all directory and sub directory |
|
2780 | + * @param string The path origin |
|
2781 | + * @param string The path destination |
|
2782 | + * @param boolean Option Overwrite |
|
2783 | + * @param string $source |
|
2784 | + * @param string $dest |
|
2785 | + * @return void() |
|
2786 | + * @deprecated |
|
2787 | + */ |
|
2788 | 2788 | public function allow_create_all_directory($source, $dest, $overwrite = false) |
2789 | 2789 | { |
2790 | 2790 | if (!is_dir($dest)) { |
@@ -2795,14 +2795,14 @@ discard block |
||
2795 | 2795 | if ($file != '.' && $file != '..') { |
2796 | 2796 | $path = $source . '/' . $file; |
2797 | 2797 | if (is_file($path)) { |
2798 | - /* if (!is_file($dest . '/' . $file) || $overwrite) |
|
2798 | + /* if (!is_file($dest . '/' . $file) || $overwrite) |
|
2799 | 2799 | if (!@copy($path, $dest . '/' . $file)) { |
2800 | 2800 | echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>'; |
2801 | 2801 | }*/ |
2802 | 2802 | } elseif(is_dir($path)) { |
2803 | 2803 | if (!is_dir($dest . '/' . $file)) |
2804 | 2804 | mkdir($dest . '/' . $file); |
2805 | - self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite); |
|
2805 | + self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite); |
|
2806 | 2806 | } |
2807 | 2807 | } |
2808 | 2808 | } |
@@ -2810,12 +2810,12 @@ discard block |
||
2810 | 2810 | } |
2811 | 2811 | } |
2812 | 2812 | |
2813 | - /** |
|
2814 | - * Gets the new ID of one specific tool item from the tool name and the old ID |
|
2815 | - * @param string Tool name |
|
2816 | - * @param integer Old ID |
|
2817 | - * @return integer New ID |
|
2818 | - */ |
|
2813 | + /** |
|
2814 | + * Gets the new ID of one specific tool item from the tool name and the old ID |
|
2815 | + * @param string Tool name |
|
2816 | + * @param integer Old ID |
|
2817 | + * @return integer New ID |
|
2818 | + */ |
|
2819 | 2819 | public function get_new_id($tool, $ref) |
2820 | 2820 | { |
2821 | 2821 | // Check if the value exist in the current array. |
@@ -2837,25 +2837,25 @@ discard block |
||
2837 | 2837 | } |
2838 | 2838 | |
2839 | 2839 | return ''; |
2840 | - } |
|
2840 | + } |
|
2841 | 2841 | |
2842 | - /** |
|
2843 | - * Restore glossary |
|
2844 | - */ |
|
2842 | + /** |
|
2843 | + * Restore glossary |
|
2844 | + */ |
|
2845 | 2845 | public function restore_glossary($session_id = 0) |
2846 | 2846 | { |
2847 | - if ($this->course->has_resources(RESOURCE_GLOSSARY)) { |
|
2848 | - $table_glossary = Database :: get_course_table(TABLE_GLOSSARY); |
|
2849 | - $resources = $this->course->resources; |
|
2850 | - foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) { |
|
2847 | + if ($this->course->has_resources(RESOURCE_GLOSSARY)) { |
|
2848 | + $table_glossary = Database :: get_course_table(TABLE_GLOSSARY); |
|
2849 | + $resources = $this->course->resources; |
|
2850 | + foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) { |
|
2851 | 2851 | |
2852 | 2852 | $params = []; |
2853 | - if (!empty($session_id)) { |
|
2854 | - $session_id = intval($session_id); |
|
2853 | + if (!empty($session_id)) { |
|
2854 | + $session_id = intval($session_id); |
|
2855 | 2855 | $params['session_id'] = $session_id; |
2856 | - } |
|
2856 | + } |
|
2857 | 2857 | |
2858 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2858 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2859 | 2859 | $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
2860 | 2860 | $glossary->description, |
2861 | 2861 | $this->course->code, |
@@ -2889,27 +2889,27 @@ discard block |
||
2889 | 2889 | |
2890 | 2890 | $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id; |
2891 | 2891 | } |
2892 | - } |
|
2893 | - } |
|
2894 | - } |
|
2892 | + } |
|
2893 | + } |
|
2894 | + } |
|
2895 | 2895 | |
2896 | 2896 | /** |
2897 | 2897 | * @param int $session_id |
2898 | 2898 | */ |
2899 | 2899 | public function restore_wiki($session_id = 0) |
2900 | 2900 | { |
2901 | - if ($this->course->has_resources(RESOURCE_WIKI)) { |
|
2902 | - // wiki table of the target course |
|
2903 | - $table_wiki = Database :: get_course_table(TABLE_WIKI); |
|
2904 | - $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF); |
|
2901 | + if ($this->course->has_resources(RESOURCE_WIKI)) { |
|
2902 | + // wiki table of the target course |
|
2903 | + $table_wiki = Database :: get_course_table(TABLE_WIKI); |
|
2904 | + $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF); |
|
2905 | 2905 | |
2906 | - // storing all the resources that have to be copied in an array |
|
2907 | - $resources = $this->course->resources; |
|
2906 | + // storing all the resources that have to be copied in an array |
|
2907 | + $resources = $this->course->resources; |
|
2908 | 2908 | |
2909 | - foreach ($resources[RESOURCE_WIKI] as $id => $wiki) { |
|
2910 | - // the sql statement to insert the groups from the old course to the new course |
|
2909 | + foreach ($resources[RESOURCE_WIKI] as $id => $wiki) { |
|
2910 | + // the sql statement to insert the groups from the old course to the new course |
|
2911 | 2911 | |
2912 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2912 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2913 | 2913 | $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
2914 | 2914 | $wiki->content, |
2915 | 2915 | $this->course->code, |
@@ -2932,7 +2932,7 @@ discard block |
||
2932 | 2932 | 'session_id' => !empty($session_id) ? intval($session_id) : 0, |
2933 | 2933 | ]; |
2934 | 2934 | |
2935 | - $new_id = Database::insert($table_wiki, $params); |
|
2935 | + $new_id = Database::insert($table_wiki, $params); |
|
2936 | 2936 | |
2937 | 2937 | if ($new_id) { |
2938 | 2938 | |
@@ -2963,9 +2963,9 @@ discard block |
||
2963 | 2963 | |
2964 | 2964 | Database::insert($table_wiki_conf, $params); |
2965 | 2965 | } |
2966 | - } |
|
2967 | - } |
|
2968 | - } |
|
2966 | + } |
|
2967 | + } |
|
2968 | + } |
|
2969 | 2969 | |
2970 | 2970 | /** |
2971 | 2971 | * Restore Thematics |
@@ -2973,15 +2973,15 @@ discard block |
||
2973 | 2973 | */ |
2974 | 2974 | public function restore_thematic($session_id = 0) |
2975 | 2975 | { |
2976 | - if ($this->course->has_resources(RESOURCE_THEMATIC)) { |
|
2976 | + if ($this->course->has_resources(RESOURCE_THEMATIC)) { |
|
2977 | 2977 | $table_thematic = Database:: get_course_table(TABLE_THEMATIC); |
2978 | 2978 | $table_thematic_advance = Database:: get_course_table(TABLE_THEMATIC_ADVANCE); |
2979 | 2979 | $table_thematic_plan = Database:: get_course_table(TABLE_THEMATIC_PLAN); |
2980 | 2980 | |
2981 | - $resources = $this->course->resources; |
|
2982 | - foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) { |
|
2981 | + $resources = $this->course->resources; |
|
2982 | + foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) { |
|
2983 | 2983 | |
2984 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2984 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
2985 | 2985 | $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
2986 | 2986 | $thematic->params['content'], |
2987 | 2987 | $this->course->code, |
@@ -2989,13 +2989,13 @@ discard block |
||
2989 | 2989 | $this->course->backup_path, |
2990 | 2990 | $this->course->info['path'] |
2991 | 2991 | ); |
2992 | - $thematic->params['c_id'] = $this->destination_course_id; |
|
2993 | - unset($thematic->params['id']); |
|
2992 | + $thematic->params['c_id'] = $this->destination_course_id; |
|
2993 | + unset($thematic->params['id']); |
|
2994 | 2994 | unset($thematic->params['iid']); |
2995 | 2995 | |
2996 | - $last_id = Database::insert($table_thematic, $thematic->params, false); |
|
2996 | + $last_id = Database::insert($table_thematic, $thematic->params, false); |
|
2997 | 2997 | |
2998 | - if ($last_id) { |
|
2998 | + if ($last_id) { |
|
2999 | 2999 | |
3000 | 3000 | $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id"; |
3001 | 3001 | Database::query($sql); |
@@ -3008,19 +3008,19 @@ discard block |
||
3008 | 3008 | api_get_user_id() |
3009 | 3009 | ); |
3010 | 3010 | |
3011 | - foreach ($thematic->thematic_advance_list as $thematic_advance) { |
|
3012 | - unset($thematic_advance['id']); |
|
3011 | + foreach ($thematic->thematic_advance_list as $thematic_advance) { |
|
3012 | + unset($thematic_advance['id']); |
|
3013 | 3013 | unset($thematic_advance['iid']); |
3014 | - $thematic_advance['attendance_id'] = 0; |
|
3015 | - $thematic_advance['thematic_id'] = $last_id; |
|
3016 | - $thematic_advance['c_id'] = $this->destination_course_id; |
|
3014 | + $thematic_advance['attendance_id'] = 0; |
|
3015 | + $thematic_advance['thematic_id'] = $last_id; |
|
3016 | + $thematic_advance['c_id'] = $this->destination_course_id; |
|
3017 | 3017 | $my_id = Database::insert( |
3018 | 3018 | $table_thematic_advance, |
3019 | 3019 | $thematic_advance, |
3020 | 3020 | false |
3021 | 3021 | ); |
3022 | 3022 | |
3023 | - if ($my_id) { |
|
3023 | + if ($my_id) { |
|
3024 | 3024 | |
3025 | 3025 | $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id"; |
3026 | 3026 | Database::query($sql); |
@@ -3032,17 +3032,17 @@ discard block |
||
3032 | 3032 | "ThematicAdvanceAdded", |
3033 | 3033 | api_get_user_id() |
3034 | 3034 | ); |
3035 | - } |
|
3036 | - } |
|
3035 | + } |
|
3036 | + } |
|
3037 | 3037 | |
3038 | - foreach($thematic->thematic_plan_list as $thematic_plan) { |
|
3039 | - unset($thematic_plan['id']); |
|
3038 | + foreach($thematic->thematic_plan_list as $thematic_plan) { |
|
3039 | + unset($thematic_plan['id']); |
|
3040 | 3040 | unset($thematic_plan['iid']); |
3041 | - $thematic_plan['thematic_id'] = $last_id; |
|
3042 | - $thematic_plan['c_id'] = $this->destination_course_id; |
|
3043 | - $my_id = Database::insert($table_thematic_plan, $thematic_plan, false); |
|
3041 | + $thematic_plan['thematic_id'] = $last_id; |
|
3042 | + $thematic_plan['c_id'] = $this->destination_course_id; |
|
3043 | + $my_id = Database::insert($table_thematic_plan, $thematic_plan, false); |
|
3044 | 3044 | |
3045 | - if ($my_id) { |
|
3045 | + if ($my_id) { |
|
3046 | 3046 | |
3047 | 3047 | $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id"; |
3048 | 3048 | Database::query($sql); |
@@ -3054,12 +3054,12 @@ discard block |
||
3054 | 3054 | "ThematicPlanAdded", |
3055 | 3055 | api_get_user_id() |
3056 | 3056 | ); |
3057 | - } |
|
3058 | - } |
|
3059 | - } |
|
3060 | - } |
|
3061 | - } |
|
3062 | - } |
|
3057 | + } |
|
3058 | + } |
|
3059 | + } |
|
3060 | + } |
|
3061 | + } |
|
3062 | + } |
|
3063 | 3063 | |
3064 | 3064 | /** |
3065 | 3065 | * Restore Attendance |
@@ -3067,14 +3067,14 @@ discard block |
||
3067 | 3067 | */ |
3068 | 3068 | public function restore_attendance($session_id = 0) |
3069 | 3069 | { |
3070 | - if ($this->course->has_resources(RESOURCE_ATTENDANCE)) { |
|
3071 | - $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
3072 | - $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
3070 | + if ($this->course->has_resources(RESOURCE_ATTENDANCE)) { |
|
3071 | + $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
3072 | + $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
3073 | 3073 | |
3074 | - $resources = $this->course->resources; |
|
3075 | - foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) { |
|
3074 | + $resources = $this->course->resources; |
|
3075 | + foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) { |
|
3076 | 3076 | |
3077 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
3077 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
3078 | 3078 | $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
3079 | 3079 | $obj->params['description'], |
3080 | 3080 | $this->course->code, |
@@ -3086,11 +3086,11 @@ discard block |
||
3086 | 3086 | unset($obj->params['id']); |
3087 | 3087 | unset($obj->params['iid']); |
3088 | 3088 | |
3089 | - $obj->params['c_id'] = $this->destination_course_id; |
|
3089 | + $obj->params['c_id'] = $this->destination_course_id; |
|
3090 | 3090 | |
3091 | - $last_id = Database::insert($table_attendance, $obj->params); |
|
3091 | + $last_id = Database::insert($table_attendance, $obj->params); |
|
3092 | 3092 | |
3093 | - if (is_numeric($last_id)) { |
|
3093 | + if (is_numeric($last_id)) { |
|
3094 | 3094 | |
3095 | 3095 | $sql = "UPDATE $table_attendance SET id = iid WHERE iid = $last_id"; |
3096 | 3096 | Database::query($sql); |
@@ -3104,11 +3104,11 @@ discard block |
||
3104 | 3104 | ); |
3105 | 3105 | |
3106 | 3106 | foreach ($obj->attendance_calendar as $attendance_calendar) { |
3107 | - unset($attendance_calendar['id']); |
|
3107 | + unset($attendance_calendar['id']); |
|
3108 | 3108 | unset($attendance_calendar['iid']); |
3109 | 3109 | |
3110 | - $attendance_calendar['attendance_id'] = $last_id; |
|
3111 | - $attendance_calendar['c_id'] = $this->destination_course_id; |
|
3110 | + $attendance_calendar['attendance_id'] = $last_id; |
|
3111 | + $attendance_calendar['c_id'] = $this->destination_course_id; |
|
3112 | 3112 | $attendanceCalendarId = Database::insert( |
3113 | 3113 | $table_attendance_calendar, |
3114 | 3114 | $attendance_calendar |
@@ -3116,11 +3116,11 @@ discard block |
||
3116 | 3116 | |
3117 | 3117 | $sql = "UPDATE $table_attendance_calendar SET id = iid WHERE iid = $attendanceCalendarId"; |
3118 | 3118 | Database::query($sql); |
3119 | - } |
|
3120 | - } |
|
3121 | - } |
|
3122 | - } |
|
3123 | - } |
|
3119 | + } |
|
3120 | + } |
|
3121 | + } |
|
3122 | + } |
|
3123 | + } |
|
3124 | 3124 | |
3125 | 3125 | /** |
3126 | 3126 | * Restore Works |
@@ -3262,11 +3262,11 @@ discard block |
||
3262 | 3262 | */ |
3263 | 3263 | public function DBUTF8($str) |
3264 | 3264 | { |
3265 | - if (UTF8_CONVERT) { |
|
3265 | + if (UTF8_CONVERT) { |
|
3266 | 3266 | $str = utf8_encode($str); |
3267 | 3267 | } |
3268 | - return $str; |
|
3269 | - } |
|
3268 | + return $str; |
|
3269 | + } |
|
3270 | 3270 | |
3271 | 3271 | /** |
3272 | 3272 | * @param string $str |
@@ -3277,8 +3277,8 @@ discard block |
||
3277 | 3277 | if (UTF8_CONVERT) { |
3278 | 3278 | $str = utf8_encode($str); |
3279 | 3279 | } |
3280 | - return Database::escape_string($str); |
|
3281 | - } |
|
3280 | + return Database::escape_string($str); |
|
3281 | + } |
|
3282 | 3282 | |
3283 | 3283 | /** |
3284 | 3284 | * @param array $array |
@@ -728,43 +728,43 @@ discard block |
||
728 | 728 | } |
729 | 729 | |
730 | 730 | /** |
731 | - * Return an array of student state answers for fill the blank questions |
|
732 | - * for each students that answered the question |
|
733 | - * -2 : didn't answer |
|
734 | - * -1 : student answer is wrong |
|
735 | - * 0 : student answer is correct |
|
736 | - * >0 : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0) |
|
737 | - * |
|
738 | - * @param integer $testId |
|
739 | - * @param integer $questionId |
|
740 | - * @param $studentsIdList |
|
741 | - * @param string $startDate |
|
742 | - * @param string $endDate |
|
743 | - * @param bool $useLastAnswerredAttempt |
|
744 | - * @return array |
|
745 | - * ( |
|
746 | - * [student_id] => Array |
|
747 | - * ( |
|
748 | - * [first fill the blank for question] => -1 |
|
749 | - * [second fill the blank for question] => 2 |
|
750 | - * [third fill the blank for question] => -1 |
|
751 | - * ) |
|
752 | - * ) |
|
753 | - */ |
|
731 | + * Return an array of student state answers for fill the blank questions |
|
732 | + * for each students that answered the question |
|
733 | + * -2 : didn't answer |
|
734 | + * -1 : student answer is wrong |
|
735 | + * 0 : student answer is correct |
|
736 | + * >0 : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0) |
|
737 | + * |
|
738 | + * @param integer $testId |
|
739 | + * @param integer $questionId |
|
740 | + * @param $studentsIdList |
|
741 | + * @param string $startDate |
|
742 | + * @param string $endDate |
|
743 | + * @param bool $useLastAnswerredAttempt |
|
744 | + * @return array |
|
745 | + * ( |
|
746 | + * [student_id] => Array |
|
747 | + * ( |
|
748 | + * [first fill the blank for question] => -1 |
|
749 | + * [second fill the blank for question] => 2 |
|
750 | + * [third fill the blank for question] => -1 |
|
751 | + * ) |
|
752 | + * ) |
|
753 | + */ |
|
754 | 754 | public static function getFillTheBlankTabResult($testId, $questionId, $studentsIdList, $startDate, $endDate, $useLastAnswerredAttempt = true) { |
755 | 755 | |
756 | - $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
757 | - $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
|
758 | - $courseId = api_get_course_int_id(); |
|
756 | + $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
757 | + $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
|
758 | + $courseId = api_get_course_int_id(); |
|
759 | 759 | |
760 | - require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php'; |
|
760 | + require_once api_get_path(SYS_PATH).'main/exercice/fill_blanks.class.php'; |
|
761 | 761 | |
762 | - // request to have all the answers of student for this question |
|
763 | - // student may have doing it several time |
|
764 | - // student may have not answered the bracket id, in this case, is result of the answer is empty |
|
762 | + // request to have all the answers of student for this question |
|
763 | + // student may have doing it several time |
|
764 | + // student may have not answered the bracket id, in this case, is result of the answer is empty |
|
765 | 765 | |
766 | - // we got the less recent attempt first |
|
767 | - $sql = ' |
|
766 | + // we got the less recent attempt first |
|
767 | + $sql = ' |
|
768 | 768 | SELECT * FROM '.$tblTrackEAttempt.' tea |
769 | 769 | |
770 | 770 | LEFT JOIN '.$tblTrackEExercise.' tee |
@@ -780,49 +780,49 @@ discard block |
||
780 | 780 | ORDER BY user_id, tea.exe_id; |
781 | 781 | '; |
782 | 782 | |
783 | - $res = Database::query($sql); |
|
784 | - $tabUserResult = array(); |
|
785 | - $bracketNumber = 0; |
|
786 | - // foreach attempts for all students starting with his older attempt |
|
787 | - while ($data = Database::fetch_array($res)) { |
|
788 | - $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true); |
|
783 | + $res = Database::query($sql); |
|
784 | + $tabUserResult = array(); |
|
785 | + $bracketNumber = 0; |
|
786 | + // foreach attempts for all students starting with his older attempt |
|
787 | + while ($data = Database::fetch_array($res)) { |
|
788 | + $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true); |
|
789 | 789 | |
790 | - // for each bracket to find in this question |
|
791 | - foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) { |
|
790 | + // for each bracket to find in this question |
|
791 | + foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) { |
|
792 | 792 | |
793 | - if ($tabAnswer['studentanswer'][$bracketNumber] != '') { |
|
794 | - // student has answered this bracket, cool |
|
795 | - switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) { |
|
796 | - case self::FILL_THE_BLANK_MENU : |
|
793 | + if ($tabAnswer['studentanswer'][$bracketNumber] != '') { |
|
794 | + // student has answered this bracket, cool |
|
795 | + switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) { |
|
796 | + case self::FILL_THE_BLANK_MENU : |
|
797 | 797 | // get the indice of the choosen answer in the menu |
798 | 798 | // we know that the right answer is the first entry of the menu, ie 0 |
799 | 799 | // (remember, menu entries are shuffled when taking the test) |
800 | 800 | $tabUserResult[$data['user_id']][$bracketNumber] = FillBlanks::getFillTheBlankMenuAnswerNum($tabAnswer['tabwords'][$bracketNumber], $tabAnswer['studentanswer'][$bracketNumber]); |
801 | - break; |
|
802 | - default : |
|
801 | + break; |
|
802 | + default : |
|
803 | 803 | if (FillBlanks::isGoodStudentAnswer($tabAnswer['studentanswer'][$bracketNumber], $tabAnswer['tabwords'][$bracketNumber])) { |
804 | - $tabUserResult[$data['user_id']][$bracketNumber] = 0; // right answer |
|
805 | - } else { |
|
806 | - $tabUserResult[$data['user_id']][$bracketNumber] = -1; // wrong answer |
|
807 | - } |
|
808 | - } |
|
809 | - } else { |
|
810 | - // student didn't answer this bracket |
|
811 | - if ($useLastAnswerredAttempt) { |
|
812 | - // if we take into account the last answered attempt |
|
813 | - if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) { |
|
814 | - $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
815 | - } |
|
816 | - } else { |
|
817 | - // we take the last attempt, even if the student answer the question before |
|
818 | - $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
819 | - } |
|
820 | - } |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - } |
|
825 | - return $tabUserResult; |
|
804 | + $tabUserResult[$data['user_id']][$bracketNumber] = 0; // right answer |
|
805 | + } else { |
|
806 | + $tabUserResult[$data['user_id']][$bracketNumber] = -1; // wrong answer |
|
807 | + } |
|
808 | + } |
|
809 | + } else { |
|
810 | + // student didn't answer this bracket |
|
811 | + if ($useLastAnswerredAttempt) { |
|
812 | + // if we take into account the last answered attempt |
|
813 | + if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) { |
|
814 | + $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
815 | + } |
|
816 | + } else { |
|
817 | + // we take the last attempt, even if the student answer the question before |
|
818 | + $tabUserResult[$data['user_id']][$bracketNumber] = -2; // not answered |
|
819 | + } |
|
820 | + } |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + } |
|
825 | + return $tabUserResult; |
|
826 | 826 | } |
827 | 827 | |
828 | 828 |
@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | public $name; |
14 | 14 | public $description; |
15 | 15 | |
16 | - /** |
|
17 | - * Constructor of the class Category |
|
18 | - * If you give an in_id and no in_name, you get info concerning the category of id=in_id |
|
19 | - * otherwise, you've got an category objet avec your in_id, in_name, in_descr |
|
20 | - * |
|
16 | + /** |
|
17 | + * Constructor of the class Category |
|
18 | + * If you give an in_id and no in_name, you get info concerning the category of id=in_id |
|
19 | + * otherwise, you've got an category objet avec your in_id, in_name, in_descr |
|
20 | + * |
|
21 | 21 | * @param int $id |
22 | 22 | * @param string $name |
23 | 23 | * @param string $description |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - /** |
|
64 | + /** |
|
65 | 65 | * add TestCategory in the database if name doesn't already exists |
66 | - */ |
|
66 | + */ |
|
67 | 67 | public function addCategoryInBDD() |
68 | 68 | { |
69 | 69 | $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | |
109 | 109 | return false; |
110 | 110 | } |
111 | - } |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
113 | + /** |
|
114 | 114 | * Removes the category from the database |
115 | 115 | * if there were question in this category, the link between question and category is removed |
116 | - */ |
|
116 | + */ |
|
117 | 117 | public function removeCategory() |
118 | 118 | { |
119 | 119 | $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | |
144 | 144 | return true; |
145 | 145 | } |
146 | - } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
148 | + /** |
|
149 | 149 | * Modify category name or description of category with id=in_id |
150 | - */ |
|
150 | + */ |
|
151 | 151 | public function modifyCategory() |
152 | 152 | { |
153 | 153 | $table = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
@@ -175,40 +175,40 @@ discard block |
||
175 | 175 | |
176 | 176 | return true; |
177 | 177 | } |
178 | - } |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
180 | + /** |
|
181 | 181 | * Gets the number of question of category id=in_id |
182 | - */ |
|
182 | + */ |
|
183 | 183 | public function getCategoryQuestionsNumber() |
184 | 184 | { |
185 | - $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
186 | - $in_id = intval($this->id); |
|
187 | - $sql = "SELECT count(*) AS nb |
|
185 | + $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
186 | + $in_id = intval($this->id); |
|
187 | + $sql = "SELECT count(*) AS nb |
|
188 | 188 | FROM $table |
189 | 189 | WHERE category_id=$in_id AND c_id=".api_get_course_int_id(); |
190 | - $res = Database::query($sql); |
|
191 | - $row = Database::fetch_array($res); |
|
190 | + $res = Database::query($sql); |
|
191 | + $row = Database::fetch_array($res); |
|
192 | 192 | |
193 | - return $row['nb']; |
|
194 | - } |
|
193 | + return $row['nb']; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @param string $in_color |
198 | 198 | */ |
199 | 199 | public function display($in_color="#E0EBF5") |
200 | 200 | { |
201 | - echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>"; |
|
202 | - print_r($this); |
|
203 | - echo "</textarea>"; |
|
204 | - } |
|
201 | + echo "<textarea style='background-color:$in_color; width:60%; height:100px;'>"; |
|
202 | + print_r($this); |
|
203 | + echo "</textarea>"; |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
206 | + /** |
|
207 | 207 | * Return an array of all Category objects in the database |
208 | - * If in_field=="" Return an array of all category objects in the database |
|
209 | - * Otherwise, return an array of all in_field value |
|
210 | - * in the database (in_field = id or name or description) |
|
211 | - */ |
|
208 | + * If in_field=="" Return an array of all category objects in the database |
|
209 | + * Otherwise, return an array of all in_field value |
|
210 | + * in the database (in_field = id or name or description) |
|
211 | + */ |
|
212 | 212 | public static function getCategoryListInfo($in_field = "", $courseId = "") |
213 | 213 | { |
214 | 214 | if (empty($courseId) || $courseId=="") { |
@@ -239,8 +239,8 @@ discard block |
||
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | - return $tabres; |
|
243 | - } |
|
242 | + return $tabres; |
|
243 | + } |
|
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Return the TestCategory id for question with question_id = $questionId |
@@ -251,210 +251,210 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return int |
253 | 253 | */ |
254 | - public static function getCategoryForQuestion($questionId, $courseId ="") |
|
254 | + public static function getCategoryForQuestion($questionId, $courseId ="") |
|
255 | 255 | { |
256 | - $result = 0; |
|
256 | + $result = 0; |
|
257 | 257 | if (empty($courseId) || $courseId == "") { |
258 | 258 | $courseId = api_get_course_int_id(); |
259 | 259 | } |
260 | - $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
260 | + $table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
261 | 261 | $questionId = intval($questionId); |
262 | - $sql = "SELECT category_id |
|
262 | + $sql = "SELECT category_id |
|
263 | 263 | FROM $table |
264 | 264 | WHERE question_id = $questionId AND c_id = $courseId"; |
265 | - $res = Database::query($sql); |
|
266 | - if (Database::num_rows($res) > 0) { |
|
265 | + $res = Database::query($sql); |
|
266 | + if (Database::num_rows($res) > 0) { |
|
267 | 267 | $data = Database::fetch_array($res); |
268 | - $result = $data['category_id']; |
|
269 | - } |
|
268 | + $result = $data['category_id']; |
|
269 | + } |
|
270 | 270 | |
271 | - return $result; |
|
272 | - } |
|
271 | + return $result; |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * true if question id has a category |
|
276 | - */ |
|
277 | - public static function isQuestionHasCategory($questionId) |
|
274 | + /** |
|
275 | + * true if question id has a category |
|
276 | + */ |
|
277 | + public static function isQuestionHasCategory($questionId) |
|
278 | 278 | { |
279 | - if (TestCategory::getCategoryForQuestion($questionId) > 0) { |
|
280 | - return true; |
|
281 | - } |
|
282 | - return false; |
|
283 | - } |
|
279 | + if (TestCategory::getCategoryForQuestion($questionId) > 0) { |
|
280 | + return true; |
|
281 | + } |
|
282 | + return false; |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
285 | + /** |
|
286 | 286 | Return the category name for question with question_id = $questionId |
287 | 287 | In this version, a question has only 1 category. |
288 | 288 | Return the category id, "" if none |
289 | - */ |
|
289 | + */ |
|
290 | 290 | public static function getCategoryNameForQuestion( |
291 | 291 | $questionId, |
292 | 292 | $courseId = "" |
293 | 293 | ) { |
294 | - if (empty($courseId) || $courseId=="") { |
|
295 | - $courseId = api_get_course_int_id(); |
|
296 | - } |
|
297 | - $catid = TestCategory::getCategoryForQuestion($questionId, $courseId); |
|
298 | - $result = ""; // result |
|
299 | - $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
|
300 | - $catid = intval($catid); |
|
301 | - $sql = "SELECT title FROM $table |
|
294 | + if (empty($courseId) || $courseId=="") { |
|
295 | + $courseId = api_get_course_int_id(); |
|
296 | + } |
|
297 | + $catid = TestCategory::getCategoryForQuestion($questionId, $courseId); |
|
298 | + $result = ""; // result |
|
299 | + $table = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
|
300 | + $catid = intval($catid); |
|
301 | + $sql = "SELECT title FROM $table |
|
302 | 302 | WHERE id = $catid AND c_id = $courseId"; |
303 | - $res = Database::query($sql); |
|
304 | - $data = Database::fetch_array($res); |
|
305 | - if (Database::num_rows($res) > 0) { |
|
306 | - $result = $data['title']; |
|
307 | - } |
|
308 | - |
|
309 | - return $result; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Return the list of differents categories ID for a test in the current course |
|
314 | - * input : test_id |
|
315 | - * return : array of category id (integer) |
|
316 | - * hubert.borderiou 07-04-2011 |
|
317 | - * @param int $exerciseId |
|
318 | - */ |
|
319 | - public static function getListOfCategoriesIDForTest($exerciseId) |
|
303 | + $res = Database::query($sql); |
|
304 | + $data = Database::fetch_array($res); |
|
305 | + if (Database::num_rows($res) > 0) { |
|
306 | + $result = $data['title']; |
|
307 | + } |
|
308 | + |
|
309 | + return $result; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Return the list of differents categories ID for a test in the current course |
|
314 | + * input : test_id |
|
315 | + * return : array of category id (integer) |
|
316 | + * hubert.borderiou 07-04-2011 |
|
317 | + * @param int $exerciseId |
|
318 | + */ |
|
319 | + public static function getListOfCategoriesIDForTest($exerciseId) |
|
320 | 320 | { |
321 | - // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
322 | - $exercise = new Exercise(); |
|
323 | - $exercise->read($exerciseId, false); |
|
324 | - $categoriesInExercise = $exercise->getQuestionWithCategories(); |
|
325 | - // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
326 | - $categories = array(); |
|
321 | + // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
322 | + $exercise = new Exercise(); |
|
323 | + $exercise->read($exerciseId, false); |
|
324 | + $categoriesInExercise = $exercise->getQuestionWithCategories(); |
|
325 | + // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
326 | + $categories = array(); |
|
327 | 327 | if (!empty($categoriesInExercise)) { |
328 | - foreach ($categoriesInExercise as $category) { |
|
329 | - //$category['id'] = $category['iid']; |
|
330 | - $categories[$category['id']] = $category; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - return $categories; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * @param Exercise $exercise_obj |
|
339 | - * @return array |
|
340 | - */ |
|
341 | - public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj) |
|
342 | - { |
|
343 | - // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
344 | - $categories_in_exercise = array(); |
|
345 | - // $question_list = $exercise_obj->getQuestionList(); |
|
346 | - $question_list = $exercise_obj->getQuestionOrderedListByName(); |
|
347 | - |
|
348 | - // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
349 | - foreach ($question_list as $questionInfo) { |
|
350 | - $question_id = $questionInfo['question_id']; |
|
351 | - $category_list = self::getCategoryForQuestion($question_id); |
|
352 | - if (is_numeric($category_list)) { |
|
353 | - $category_list = array($category_list); |
|
354 | - } |
|
355 | - |
|
356 | - if (!empty($category_list)) { |
|
357 | - $categories_in_exercise = array_merge($categories_in_exercise, $category_list); |
|
358 | - } |
|
359 | - } |
|
360 | - if (!empty($categories_in_exercise)) { |
|
361 | - $categories_in_exercise = array_unique(array_filter($categories_in_exercise)); |
|
362 | - } |
|
363 | - return $categories_in_exercise; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Return the list of differents categories NAME for a test |
|
368 | - * @param int exercise id |
|
369 | - * @param bool |
|
370 | - * @return integer of string |
|
371 | - * |
|
328 | + foreach ($categoriesInExercise as $category) { |
|
329 | + //$category['id'] = $category['iid']; |
|
330 | + $categories[$category['id']] = $category; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + return $categories; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * @param Exercise $exercise_obj |
|
339 | + * @return array |
|
340 | + */ |
|
341 | + public static function getListOfCategoriesIDForTestObject(Exercise $exercise_obj) |
|
342 | + { |
|
343 | + // parcourir les questions d'un test, recup les categories uniques dans un tableau |
|
344 | + $categories_in_exercise = array(); |
|
345 | + // $question_list = $exercise_obj->getQuestionList(); |
|
346 | + $question_list = $exercise_obj->getQuestionOrderedListByName(); |
|
347 | + |
|
348 | + // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ??? |
|
349 | + foreach ($question_list as $questionInfo) { |
|
350 | + $question_id = $questionInfo['question_id']; |
|
351 | + $category_list = self::getCategoryForQuestion($question_id); |
|
352 | + if (is_numeric($category_list)) { |
|
353 | + $category_list = array($category_list); |
|
354 | + } |
|
355 | + |
|
356 | + if (!empty($category_list)) { |
|
357 | + $categories_in_exercise = array_merge($categories_in_exercise, $category_list); |
|
358 | + } |
|
359 | + } |
|
360 | + if (!empty($categories_in_exercise)) { |
|
361 | + $categories_in_exercise = array_unique(array_filter($categories_in_exercise)); |
|
362 | + } |
|
363 | + return $categories_in_exercise; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Return the list of differents categories NAME for a test |
|
368 | + * @param int exercise id |
|
369 | + * @param bool |
|
370 | + * @return integer of string |
|
371 | + * |
|
372 | 372 | * @author function rewrote by jmontoya |
373 | - */ |
|
374 | - public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true) |
|
373 | + */ |
|
374 | + public static function getListOfCategoriesNameForTest($exercise_id, $grouped_by_category = true) |
|
375 | 375 | { |
376 | - $result = array(); |
|
377 | - $categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category); |
|
376 | + $result = array(); |
|
377 | + $categories = self::getListOfCategoriesIDForTest($exercise_id, $grouped_by_category); |
|
378 | 378 | |
379 | - foreach ($categories as $catInfo) { |
|
380 | - $categoryId = $catInfo['id']; |
|
381 | - if (!empty($categoryId)) { |
|
382 | - $result[$categoryId] = array( |
|
379 | + foreach ($categories as $catInfo) { |
|
380 | + $categoryId = $catInfo['id']; |
|
381 | + if (!empty($categoryId)) { |
|
382 | + $result[$categoryId] = array( |
|
383 | 383 | 'title' => $catInfo['title'], |
384 | 384 | //'parent_id' => $catInfo['parent_id'], |
385 | - 'parent_id' => '', |
|
385 | + 'parent_id' => '', |
|
386 | 386 | 'c_id' => $catInfo['c_id'] |
387 | 387 | ); |
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - return $result; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * @param Exercise $exercise_obj |
|
396 | - * @return array |
|
397 | - */ |
|
398 | - public static function getListOfCategoriesForTest(Exercise $exercise_obj) |
|
399 | - { |
|
400 | - $result = array(); |
|
401 | - $categories = self::getListOfCategoriesIDForTestObject($exercise_obj); |
|
402 | - foreach ($categories as $cat_id) { |
|
403 | - $cat = new TestCategory($cat_id); |
|
404 | - $cat = (array)$cat; |
|
405 | - $cat['iid'] = $cat['id']; |
|
406 | - $cat['title'] = $cat['name']; |
|
407 | - $result[$cat['id']] = $cat; |
|
408 | - } |
|
409 | - return $result; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * return the number of differents categories for a test |
|
414 | - * input : test_id |
|
415 | - * return : integer |
|
416 | - * hubert.borderiou 07-04-2011 |
|
417 | - */ |
|
418 | - public static function getNumberOfCategoriesForTest($id) |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + return $result; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * @param Exercise $exercise_obj |
|
396 | + * @return array |
|
397 | + */ |
|
398 | + public static function getListOfCategoriesForTest(Exercise $exercise_obj) |
|
399 | + { |
|
400 | + $result = array(); |
|
401 | + $categories = self::getListOfCategoriesIDForTestObject($exercise_obj); |
|
402 | + foreach ($categories as $cat_id) { |
|
403 | + $cat = new TestCategory($cat_id); |
|
404 | + $cat = (array)$cat; |
|
405 | + $cat['iid'] = $cat['id']; |
|
406 | + $cat['title'] = $cat['name']; |
|
407 | + $result[$cat['id']] = $cat; |
|
408 | + } |
|
409 | + return $result; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * return the number of differents categories for a test |
|
414 | + * input : test_id |
|
415 | + * return : integer |
|
416 | + * hubert.borderiou 07-04-2011 |
|
417 | + */ |
|
418 | + public static function getNumberOfCategoriesForTest($id) |
|
419 | 419 | { |
420 | - return count(TestCategory::getListOfCategoriesIDForTest($id)); |
|
421 | - } |
|
420 | + return count(TestCategory::getListOfCategoriesIDForTest($id)); |
|
421 | + } |
|
422 | 422 | |
423 | - /** |
|
424 | - * return the number of question of a category id in a test |
|
425 | - * @param int $exerciseId |
|
423 | + /** |
|
424 | + * return the number of question of a category id in a test |
|
425 | + * @param int $exerciseId |
|
426 | 426 | * @param int $categoryId |
427 | 427 | * |
428 | - * @return integer |
|
428 | + * @return integer |
|
429 | 429 | * |
430 | - * @author hubert.borderiou 07-04-2011 |
|
431 | - */ |
|
432 | - public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId) |
|
430 | + * @author hubert.borderiou 07-04-2011 |
|
431 | + */ |
|
432 | + public static function getNumberOfQuestionsInCategoryForTest($exerciseId, $categoryId) |
|
433 | 433 | { |
434 | - $nbCatResult = 0; |
|
435 | - $quiz = new Exercise(); |
|
436 | - $quiz->read($exerciseId); |
|
437 | - $tabQuestionList = $quiz->selectQuestionList(); |
|
438 | - // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ? |
|
439 | - for ($i=1; $i <= count($tabQuestionList); $i++) { |
|
440 | - if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) { |
|
441 | - $nbCatResult++; |
|
442 | - } |
|
443 | - } |
|
444 | - |
|
445 | - return $nbCatResult; |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * return the number of question for a test using random by category |
|
450 | - * input : test_id, number of random question (min 1) |
|
451 | - * hubert.borderiou 07-04-2011 |
|
452 | - * question without categories are not counted |
|
453 | - */ |
|
454 | - public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom) |
|
434 | + $nbCatResult = 0; |
|
435 | + $quiz = new Exercise(); |
|
436 | + $quiz->read($exerciseId); |
|
437 | + $tabQuestionList = $quiz->selectQuestionList(); |
|
438 | + // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ? ? ? |
|
439 | + for ($i=1; $i <= count($tabQuestionList); $i++) { |
|
440 | + if (TestCategory::getCategoryForQuestion($tabQuestionList[$i]) == $categoryId) { |
|
441 | + $nbCatResult++; |
|
442 | + } |
|
443 | + } |
|
444 | + |
|
445 | + return $nbCatResult; |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * return the number of question for a test using random by category |
|
450 | + * input : test_id, number of random question (min 1) |
|
451 | + * hubert.borderiou 07-04-2011 |
|
452 | + * question without categories are not counted |
|
453 | + */ |
|
454 | + public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbrandom) |
|
455 | 455 | { |
456 | - $nbquestionresult = 0; |
|
457 | - $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
456 | + $nbquestionresult = 0; |
|
457 | + $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
458 | 458 | |
459 | 459 | foreach ($tabcatid as $category) { |
460 | 460 | if (empty($category['id'])) { |
@@ -470,30 +470,30 @@ discard block |
||
470 | 470 | } |
471 | 471 | } |
472 | 472 | |
473 | - return $nbquestionresult; |
|
474 | - } |
|
473 | + return $nbquestionresult; |
|
474 | + } |
|
475 | 475 | |
476 | - /** |
|
477 | - * Return an array (id=>name) |
|
478 | - * tabresult[0] = get_lang('NoCategory'); |
|
476 | + /** |
|
477 | + * Return an array (id=>name) |
|
478 | + * tabresult[0] = get_lang('NoCategory'); |
|
479 | 479 | * |
480 | 480 | * @param int $courseId |
481 | 481 | * |
482 | 482 | * @return array |
483 | - * |
|
484 | - */ |
|
483 | + * |
|
484 | + */ |
|
485 | 485 | public static function getCategoriesIdAndName($courseId = "") |
486 | 486 | { |
487 | - if (empty($courseId)) { |
|
488 | - $courseId = api_get_course_int_id(); |
|
489 | - } |
|
490 | - $tabcatobject = TestCategory::getCategoryListInfo("", $courseId); |
|
491 | - $tabresult = array("0"=>get_lang('NoCategorySelected')); |
|
492 | - for ($i=0; $i < count($tabcatobject); $i++) { |
|
493 | - $tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name; |
|
494 | - } |
|
495 | - return $tabresult; |
|
496 | - } |
|
487 | + if (empty($courseId)) { |
|
488 | + $courseId = api_get_course_int_id(); |
|
489 | + } |
|
490 | + $tabcatobject = TestCategory::getCategoryListInfo("", $courseId); |
|
491 | + $tabresult = array("0"=>get_lang('NoCategorySelected')); |
|
492 | + for ($i=0; $i < count($tabcatobject); $i++) { |
|
493 | + $tabresult[$tabcatobject[$i]->id] = $tabcatobject[$i]->name; |
|
494 | + } |
|
495 | + return $tabresult; |
|
496 | + } |
|
497 | 497 | |
498 | 498 | /** |
499 | 499 | * Returns an array of question ids for each category |
@@ -502,10 +502,10 @@ discard block |
||
502 | 502 | * @param int exercise |
503 | 503 | * @param array $check_in_question_list |
504 | 504 | * @param array $categoriesAddedInExercise |
505 | - * |
|
506 | - * @param int $exerciseId |
|
507 | - * @return array |
|
508 | - */ |
|
505 | + * |
|
506 | + * @param int $exerciseId |
|
507 | + * @return array |
|
508 | + */ |
|
509 | 509 | static function getQuestionsByCat( |
510 | 510 | $exerciseId, |
511 | 511 | $check_in_question_list = array(), |
@@ -583,28 +583,28 @@ discard block |
||
583 | 583 | } |
584 | 584 | |
585 | 585 | return $categories; |
586 | - } |
|
586 | + } |
|
587 | 587 | |
588 | - /** |
|
589 | - * return a tab of $in_number random elements of $in_tab |
|
590 | - */ |
|
588 | + /** |
|
589 | + * return a tab of $in_number random elements of $in_tab |
|
590 | + */ |
|
591 | 591 | public static function getNElementsFromArray($in_tab, $in_number) |
592 | 592 | { |
593 | - $tabres = $in_tab; |
|
594 | - shuffle($tabres); |
|
595 | - if ($in_number < count($tabres)) { |
|
596 | - $tabres = array_slice($tabres, 0, $in_number); |
|
597 | - } |
|
598 | - return $tabres; |
|
599 | - } |
|
600 | - |
|
601 | - /** |
|
602 | - * display the category |
|
603 | - */ |
|
604 | - public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1) |
|
593 | + $tabres = $in_tab; |
|
594 | + shuffle($tabres); |
|
595 | + if ($in_number < count($tabres)) { |
|
596 | + $tabres = array_slice($tabres, 0, $in_number); |
|
597 | + } |
|
598 | + return $tabres; |
|
599 | + } |
|
600 | + |
|
601 | + /** |
|
602 | + * display the category |
|
603 | + */ |
|
604 | + public static function displayCategoryAndTitle($questionId, $in_display_category_name = 1) |
|
605 | 605 | { |
606 | 606 | echo self::returnCategoryAndTitle($questionId, $in_display_category_name); |
607 | - } |
|
607 | + } |
|
608 | 608 | |
609 | 609 | /** |
610 | 610 | * @param int $questionId |
@@ -620,90 +620,90 @@ discard block |
||
620 | 620 | $in_display_category_name = $objExercise->display_category_name; |
621 | 621 | } |
622 | 622 | $content = null; |
623 | - if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) { |
|
623 | + if (TestCategory::getCategoryNameForQuestion($questionId) != "" && ($in_display_category_name == 1 || !$is_student)) { |
|
624 | 624 | $content .= '<div class="page-header">'; |
625 | 625 | $content .= '<h4>'.get_lang('Category').": ".TestCategory::getCategoryNameForQuestion($questionId).'</h4>'; |
626 | 626 | $content .= "</div>"; |
627 | - } |
|
627 | + } |
|
628 | 628 | return $content; |
629 | - } |
|
629 | + } |
|
630 | 630 | |
631 | 631 | /** |
632 | - * Display signs [+] and/or (>0) after question title if question has options |
|
633 | - * scoreAlwaysPositive and/or uncheckedMayScore |
|
634 | - */ |
|
632 | + * Display signs [+] and/or (>0) after question title if question has options |
|
633 | + * scoreAlwaysPositive and/or uncheckedMayScore |
|
634 | + */ |
|
635 | 635 | public function displayQuestionOption($in_objQuestion) |
636 | 636 | { |
637 | - if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) { |
|
638 | - echo "<span style='font-size:75%'> (>0)</span>"; |
|
639 | - } |
|
640 | - if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) { |
|
641 | - echo "<span style='font-size:75%'> [+]</span>"; |
|
642 | - } |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * sortTabByBracketLabel ($tabCategoryQuestions) |
|
647 | - * key of $tabCategoryQuestions are the category id (0 for not in a category) |
|
648 | - * value is the array of question id of this category |
|
649 | - * Sort question by Category |
|
650 | - */ |
|
637 | + if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->scoreAlwaysPositive) { |
|
638 | + echo "<span style='font-size:75%'> (>0)</span>"; |
|
639 | + } |
|
640 | + if ($in_objQuestion->type == MULTIPLE_ANSWER && $in_objQuestion->uncheckedMayScore) { |
|
641 | + echo "<span style='font-size:75%'> [+]</span>"; |
|
642 | + } |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * sortTabByBracketLabel ($tabCategoryQuestions) |
|
647 | + * key of $tabCategoryQuestions are the category id (0 for not in a category) |
|
648 | + * value is the array of question id of this category |
|
649 | + * Sort question by Category |
|
650 | + */ |
|
651 | 651 | public static function sortTabByBracketLabel($in_tab) |
652 | 652 | { |
653 | - $tabResult = array(); |
|
654 | - $tabCatName = array(); // tab of category name |
|
655 | - while (list($cat_id, $tabquestion) = each($in_tab)) { |
|
656 | - $catTitle = new TestCategory($cat_id); |
|
657 | - $tabCatName[$cat_id] = $catTitle->name; |
|
658 | - } |
|
659 | - reset($in_tab); |
|
660 | - // sort table by value, keeping keys as they are |
|
661 | - asort($tabCatName); |
|
662 | - // keys of $tabCatName are keys order for $in_tab |
|
663 | - while (list($key, $val) = each($tabCatName)) { |
|
664 | - $tabResult[$key] = $in_tab[$key]; |
|
665 | - } |
|
666 | - return $tabResult; |
|
667 | - } |
|
653 | + $tabResult = array(); |
|
654 | + $tabCatName = array(); // tab of category name |
|
655 | + while (list($cat_id, $tabquestion) = each($in_tab)) { |
|
656 | + $catTitle = new TestCategory($cat_id); |
|
657 | + $tabCatName[$cat_id] = $catTitle->name; |
|
658 | + } |
|
659 | + reset($in_tab); |
|
660 | + // sort table by value, keeping keys as they are |
|
661 | + asort($tabCatName); |
|
662 | + // keys of $tabCatName are keys order for $in_tab |
|
663 | + while (list($key, $val) = each($tabCatName)) { |
|
664 | + $tabResult[$key] = $in_tab[$key]; |
|
665 | + } |
|
666 | + return $tabResult; |
|
667 | + } |
|
668 | 668 | |
669 | 669 | /** |
670 | - * return total score for test exe_id for all question in the category $in_cat_id for user |
|
671 | - * If no question for this category, return "" |
|
672 | - */ |
|
673 | - public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id) |
|
674 | - { |
|
675 | - $tbl_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
676 | - $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
677 | - $in_cat_id = intval($in_cat_id); |
|
678 | - $in_exe_id = intval($in_exe_id); |
|
679 | - $in_user_id = intval($in_user_id); |
|
680 | - |
|
681 | - $query = "SELECT DISTINCT |
|
670 | + * return total score for test exe_id for all question in the category $in_cat_id for user |
|
671 | + * If no question for this category, return "" |
|
672 | + */ |
|
673 | + public static function getCatScoreForExeidForUserid($in_cat_id, $in_exe_id, $in_user_id) |
|
674 | + { |
|
675 | + $tbl_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
|
676 | + $tbl_question_rel_category = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); |
|
677 | + $in_cat_id = intval($in_cat_id); |
|
678 | + $in_exe_id = intval($in_exe_id); |
|
679 | + $in_user_id = intval($in_user_id); |
|
680 | + |
|
681 | + $query = "SELECT DISTINCT |
|
682 | 682 | marks, exe_id, user_id, ta.question_id, category_id |
683 | 683 | FROM $tbl_track_attempt ta , $tbl_question_rel_category qrc |
684 | 684 | WHERE |
685 | 685 | ta.question_id=qrc.question_id AND |
686 | 686 | qrc.category_id=$in_cat_id AND |
687 | 687 | exe_id=$in_exe_id AND user_id=$in_user_id"; |
688 | - $res = Database::query($query); |
|
689 | - $totalcatscore = ""; |
|
690 | - while ($data = Database::fetch_array($res)) { |
|
691 | - $totalcatscore += $data['marks']; |
|
692 | - } |
|
693 | - return $totalcatscore; |
|
694 | - } |
|
695 | - |
|
696 | - /** |
|
688 | + $res = Database::query($query); |
|
689 | + $totalcatscore = ""; |
|
690 | + while ($data = Database::fetch_array($res)) { |
|
691 | + $totalcatscore += $data['marks']; |
|
692 | + } |
|
693 | + return $totalcatscore; |
|
694 | + } |
|
695 | + |
|
696 | + /** |
|
697 | 697 | * return the number max of question in a category |
698 | 698 | * count the number of questions in all categories, and return the max |
699 | 699 | * @param int $exerciseId |
700 | 700 | * @author - hubert borderiou |
701 | - */ |
|
701 | + */ |
|
702 | 702 | public static function getNumberMaxQuestionByCat($exerciseId) |
703 | 703 | { |
704 | 704 | $res_num_max = 0; |
705 | 705 | // foreach question |
706 | - $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
706 | + $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); |
|
707 | 707 | |
708 | 708 | foreach ($tabcatid as $category) { |
709 | 709 | if (empty($category['id'])) { |
@@ -775,34 +775,34 @@ discard block |
||
775 | 775 | } |
776 | 776 | |
777 | 777 | /** |
778 | - * @return array |
|
779 | - */ |
|
780 | - function get_all_categories() |
|
781 | - { |
|
782 | - $table = Database::get_course_table(TABLE_QUIZ_CATEGORY); |
|
783 | - $sql = "SELECT * FROM $table ORDER BY title ASC"; |
|
784 | - $res = Database::query($sql); |
|
785 | - while ($row = Database::fetch_array($res,'ASSOC')) { |
|
786 | - $array[] = $row; |
|
787 | - } |
|
788 | - return $array; |
|
789 | - } |
|
790 | - |
|
791 | - /** |
|
792 | - * @param Exercise $exercise |
|
793 | - * @param int $course_id |
|
794 | - * @param string $order |
|
795 | - * @param bool $shuffle |
|
796 | - * @param bool $excludeCategoryWithNoQuestions |
|
797 | - * @return array|bool |
|
798 | - */ |
|
799 | - public function getCategoryExerciseTree( |
|
800 | - $exercise, |
|
801 | - $course_id, |
|
802 | - $order = null, |
|
803 | - $shuffle = false, |
|
804 | - $excludeCategoryWithNoQuestions = true |
|
805 | - ) { |
|
778 | + * @return array |
|
779 | + */ |
|
780 | + function get_all_categories() |
|
781 | + { |
|
782 | + $table = Database::get_course_table(TABLE_QUIZ_CATEGORY); |
|
783 | + $sql = "SELECT * FROM $table ORDER BY title ASC"; |
|
784 | + $res = Database::query($sql); |
|
785 | + while ($row = Database::fetch_array($res,'ASSOC')) { |
|
786 | + $array[] = $row; |
|
787 | + } |
|
788 | + return $array; |
|
789 | + } |
|
790 | + |
|
791 | + /** |
|
792 | + * @param Exercise $exercise |
|
793 | + * @param int $course_id |
|
794 | + * @param string $order |
|
795 | + * @param bool $shuffle |
|
796 | + * @param bool $excludeCategoryWithNoQuestions |
|
797 | + * @return array|bool |
|
798 | + */ |
|
799 | + public function getCategoryExerciseTree( |
|
800 | + $exercise, |
|
801 | + $course_id, |
|
802 | + $order = null, |
|
803 | + $shuffle = false, |
|
804 | + $excludeCategoryWithNoQuestions = true |
|
805 | + ) { |
|
806 | 806 | if (empty($exercise)) { |
807 | 807 | return array(); |
808 | 808 | } |
@@ -812,165 +812,165 @@ discard block |
||
812 | 812 | } |
813 | 813 | |
814 | 814 | $course_id = intval($course_id); |
815 | - $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); |
|
815 | + $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); |
|
816 | 816 | $categoryTable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); |
817 | - $sql = "SELECT * FROM $table qc |
|
817 | + $sql = "SELECT * FROM $table qc |
|
818 | 818 | LEFT JOIN $categoryTable c |
819 | 819 | ON (qc.c_id = c.c_id AND c.id = qc.category_id) |
820 | 820 | WHERE qc.c_id = $course_id AND exercise_id = {$exercise->id} "; |
821 | 821 | |
822 | - if (!empty($order)) { |
|
823 | - $sql .= "ORDER BY $order"; |
|
824 | - } |
|
825 | - |
|
826 | - $categories = array(); |
|
827 | - |
|
828 | - $result = Database::query($sql); |
|
829 | - if (Database::num_rows($result)) { |
|
830 | - while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
831 | - if ($excludeCategoryWithNoQuestions) { |
|
832 | - if ($row['count_questions'] == 0) { |
|
833 | - continue; |
|
834 | - } |
|
835 | - } |
|
836 | - if (empty($row['title']) && empty($row['category_id'])) { |
|
837 | - $row['title'] = get_lang('NoCategory'); |
|
838 | - } |
|
822 | + if (!empty($order)) { |
|
823 | + $sql .= "ORDER BY $order"; |
|
824 | + } |
|
825 | + |
|
826 | + $categories = array(); |
|
827 | + |
|
828 | + $result = Database::query($sql); |
|
829 | + if (Database::num_rows($result)) { |
|
830 | + while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
831 | + if ($excludeCategoryWithNoQuestions) { |
|
832 | + if ($row['count_questions'] == 0) { |
|
833 | + continue; |
|
834 | + } |
|
835 | + } |
|
836 | + if (empty($row['title']) && empty($row['category_id'])) { |
|
837 | + $row['title'] = get_lang('NoCategory'); |
|
838 | + } |
|
839 | 839 | $categories[$row['category_id']] = $row; |
840 | - } |
|
841 | - } |
|
842 | - |
|
843 | - if ($shuffle) { |
|
844 | - shuffle_assoc($categories); |
|
845 | - } |
|
846 | - |
|
847 | - return $categories; |
|
848 | - } |
|
849 | - |
|
850 | - public function getForm(& $form, $action = 'new') |
|
851 | - { |
|
852 | - switch($action) { |
|
853 | - case 'new': |
|
854 | - $header = get_lang('AddACategory'); |
|
855 | - $submit = get_lang('AddTestCategory'); |
|
856 | - break; |
|
857 | - case 'edit': |
|
858 | - $header = get_lang('EditCategory'); |
|
859 | - $submit = get_lang('ModifyCategory'); |
|
860 | - break; |
|
861 | - } |
|
862 | - |
|
863 | - // settting the form elements |
|
864 | - $form->addElement('header', $header); |
|
865 | - $form->addElement('hidden', 'category_id'); |
|
866 | - $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); |
|
867 | - $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); |
|
868 | - $category_parent_list = array(); |
|
869 | - |
|
870 | - $options = array( |
|
871 | - '1' => get_lang('Visible'), |
|
872 | - '0' => get_lang('Hidden') |
|
873 | - ); |
|
874 | - $form->addElement('select', 'visibility', get_lang('Visibility'), $options); |
|
875 | - $script = null; |
|
876 | - if (!empty($this->parent_id)) { |
|
877 | - $parent_cat = new TestCategory($this->parent_id); |
|
878 | - $category_parent_list = array($parent_cat->id => $parent_cat->name); |
|
879 | - $script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>'; |
|
880 | - } |
|
881 | - $form->addElement('html', $script); |
|
882 | - |
|
883 | - $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id')); |
|
884 | - $form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"'); |
|
885 | - |
|
886 | - // setting the defaults |
|
887 | - $defaults = array(); |
|
888 | - $defaults["category_id"] = $this->id; |
|
889 | - $defaults["category_name"] = $this->name; |
|
890 | - $defaults["category_description"] = $this->description; |
|
891 | - $defaults["parent_id"] = $this->parent_id; |
|
892 | - $defaults["visibility"] = $this->visibility; |
|
893 | - $form->setDefaults($defaults); |
|
894 | - |
|
895 | - // setting the rules |
|
896 | - $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); |
|
897 | - } |
|
898 | - |
|
899 | - /** |
|
900 | - * Returns the category form. |
|
901 | - * @param Exercise $exercise_obj |
|
902 | - * @return string |
|
903 | - */ |
|
904 | - public function returnCategoryForm(Exercise $exercise_obj) |
|
905 | - { |
|
906 | - $categories = $this->getListOfCategoriesForTest($exercise_obj); |
|
907 | - |
|
908 | - $saved_categories = $exercise_obj->get_categories_in_exercise(); |
|
909 | - $return = null; |
|
910 | - |
|
911 | - if (!empty($categories)) { |
|
912 | - $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory(); |
|
913 | - $exercise_obj->setCategoriesGrouping(true); |
|
914 | - $real_question_count = count($exercise_obj->getQuestionList()); |
|
915 | - |
|
916 | - $warning = null; |
|
917 | - if ($nbQuestionsTotal != $real_question_count) { |
|
918 | - $warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning'); |
|
919 | - } |
|
920 | - |
|
921 | - $return .= $warning; |
|
922 | - $return .= '<table class="data_table">'; |
|
923 | - $return .= '<tr>'; |
|
924 | - $return .= '<th height="24">' . get_lang('Categories') . '</th>'; |
|
925 | - $return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>'; |
|
926 | - |
|
927 | - $emptyCategory = array( |
|
928 | - 'id' => '0', |
|
929 | - 'name' => get_lang('NoCategory'), |
|
930 | - 'description' => '', |
|
931 | - 'iid' => '0', |
|
932 | - 'title' => get_lang('NoCategory') |
|
933 | - ); |
|
934 | - |
|
935 | - $categories[] = $emptyCategory; |
|
936 | - |
|
937 | - foreach ($categories as $category) { |
|
938 | - $cat_id = $category['iid']; |
|
939 | - $return .= '<tr>'; |
|
940 | - $return .= '<td>'; |
|
941 | - //$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : ''); |
|
942 | - $return .= Display::div($category['name']); |
|
943 | - $return .= '</td>'; |
|
944 | - $return .= '<td>'; |
|
945 | - $value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1; |
|
946 | - $return .= '<input name="category['.$cat_id.']" value="' .$value.'" />'; |
|
947 | - $return .= '</td>'; |
|
948 | - $return .= '</tr>'; |
|
949 | - } |
|
950 | - |
|
951 | - $return .= '</table>'; |
|
952 | - $return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected'); |
|
953 | - return $return; |
|
954 | - } |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * Sorts an array |
|
959 | - * @param $array |
|
960 | - * @return mixed |
|
961 | - */ |
|
962 | - public function sort_tree_array($array) |
|
963 | - { |
|
964 | - foreach ($array as $key => $row) { |
|
965 | - $parent[$key] = $row['parent_id']; |
|
966 | - } |
|
967 | - if (count($array) > 0) { |
|
968 | - array_multisort($parent, SORT_ASC, $array); |
|
969 | - } |
|
970 | - return $array; |
|
971 | - } |
|
972 | - |
|
973 | - /** |
|
840 | + } |
|
841 | + } |
|
842 | + |
|
843 | + if ($shuffle) { |
|
844 | + shuffle_assoc($categories); |
|
845 | + } |
|
846 | + |
|
847 | + return $categories; |
|
848 | + } |
|
849 | + |
|
850 | + public function getForm(& $form, $action = 'new') |
|
851 | + { |
|
852 | + switch($action) { |
|
853 | + case 'new': |
|
854 | + $header = get_lang('AddACategory'); |
|
855 | + $submit = get_lang('AddTestCategory'); |
|
856 | + break; |
|
857 | + case 'edit': |
|
858 | + $header = get_lang('EditCategory'); |
|
859 | + $submit = get_lang('ModifyCategory'); |
|
860 | + break; |
|
861 | + } |
|
862 | + |
|
863 | + // settting the form elements |
|
864 | + $form->addElement('header', $header); |
|
865 | + $form->addElement('hidden', 'category_id'); |
|
866 | + $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); |
|
867 | + $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); |
|
868 | + $category_parent_list = array(); |
|
869 | + |
|
870 | + $options = array( |
|
871 | + '1' => get_lang('Visible'), |
|
872 | + '0' => get_lang('Hidden') |
|
873 | + ); |
|
874 | + $form->addElement('select', 'visibility', get_lang('Visibility'), $options); |
|
875 | + $script = null; |
|
876 | + if (!empty($this->parent_id)) { |
|
877 | + $parent_cat = new TestCategory($this->parent_id); |
|
878 | + $category_parent_list = array($parent_cat->id => $parent_cat->name); |
|
879 | + $script .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</script>'; |
|
880 | + } |
|
881 | + $form->addElement('html', $script); |
|
882 | + |
|
883 | + $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id')); |
|
884 | + $form->addElement('style_submit_button', 'SubmitNote', $submit, 'class="add"'); |
|
885 | + |
|
886 | + // setting the defaults |
|
887 | + $defaults = array(); |
|
888 | + $defaults["category_id"] = $this->id; |
|
889 | + $defaults["category_name"] = $this->name; |
|
890 | + $defaults["category_description"] = $this->description; |
|
891 | + $defaults["parent_id"] = $this->parent_id; |
|
892 | + $defaults["visibility"] = $this->visibility; |
|
893 | + $form->setDefaults($defaults); |
|
894 | + |
|
895 | + // setting the rules |
|
896 | + $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); |
|
897 | + } |
|
898 | + |
|
899 | + /** |
|
900 | + * Returns the category form. |
|
901 | + * @param Exercise $exercise_obj |
|
902 | + * @return string |
|
903 | + */ |
|
904 | + public function returnCategoryForm(Exercise $exercise_obj) |
|
905 | + { |
|
906 | + $categories = $this->getListOfCategoriesForTest($exercise_obj); |
|
907 | + |
|
908 | + $saved_categories = $exercise_obj->get_categories_in_exercise(); |
|
909 | + $return = null; |
|
910 | + |
|
911 | + if (!empty($categories)) { |
|
912 | + $nbQuestionsTotal = $exercise_obj->getNumberQuestionExerciseCategory(); |
|
913 | + $exercise_obj->setCategoriesGrouping(true); |
|
914 | + $real_question_count = count($exercise_obj->getQuestionList()); |
|
915 | + |
|
916 | + $warning = null; |
|
917 | + if ($nbQuestionsTotal != $real_question_count) { |
|
918 | + $warning = Display::return_message(get_lang('CheckThatYouHaveEnoughQuestionsInYourCategories'), 'warning'); |
|
919 | + } |
|
920 | + |
|
921 | + $return .= $warning; |
|
922 | + $return .= '<table class="data_table">'; |
|
923 | + $return .= '<tr>'; |
|
924 | + $return .= '<th height="24">' . get_lang('Categories') . '</th>'; |
|
925 | + $return .= '<th width="70" height="24">' . get_lang('Number') . '</th></tr>'; |
|
926 | + |
|
927 | + $emptyCategory = array( |
|
928 | + 'id' => '0', |
|
929 | + 'name' => get_lang('NoCategory'), |
|
930 | + 'description' => '', |
|
931 | + 'iid' => '0', |
|
932 | + 'title' => get_lang('NoCategory') |
|
933 | + ); |
|
934 | + |
|
935 | + $categories[] = $emptyCategory; |
|
936 | + |
|
937 | + foreach ($categories as $category) { |
|
938 | + $cat_id = $category['iid']; |
|
939 | + $return .= '<tr>'; |
|
940 | + $return .= '<td>'; |
|
941 | + //$return .= Display::div(isset($category['parent_path']) ? $category['parent_path'] : ''); |
|
942 | + $return .= Display::div($category['name']); |
|
943 | + $return .= '</td>'; |
|
944 | + $return .= '<td>'; |
|
945 | + $value = isset($saved_categories) && isset($saved_categories[$cat_id]) ? $saved_categories[$cat_id]['count_questions'] : -1; |
|
946 | + $return .= '<input name="category['.$cat_id.']" value="' .$value.'" />'; |
|
947 | + $return .= '</td>'; |
|
948 | + $return .= '</tr>'; |
|
949 | + } |
|
950 | + |
|
951 | + $return .= '</table>'; |
|
952 | + $return .= get_lang('ZeroMeansNoQuestionWillBeSelectedMinusOneMeansThatAllQuestionsWillBeSelected'); |
|
953 | + return $return; |
|
954 | + } |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * Sorts an array |
|
959 | + * @param $array |
|
960 | + * @return mixed |
|
961 | + */ |
|
962 | + public function sort_tree_array($array) |
|
963 | + { |
|
964 | + foreach ($array as $key => $row) { |
|
965 | + $parent[$key] = $row['parent_id']; |
|
966 | + } |
|
967 | + if (count($array) > 0) { |
|
968 | + array_multisort($parent, SORT_ASC, $array); |
|
969 | + } |
|
970 | + return $array; |
|
971 | + } |
|
972 | + |
|
973 | + /** |
|
974 | 974 | * Return true if a category already exists with the same name |
975 | 975 | * @param string $in_name |
976 | 976 | * |
@@ -1016,8 +1016,8 @@ discard block |
||
1016 | 1016 | * @param int $categoryId |
1017 | 1017 | * @param int $questionId |
1018 | 1018 | * @param int $courseId |
1019 | - * |
|
1020 | - * @return string|false |
|
1019 | + * |
|
1020 | + * @return string|false |
|
1021 | 1021 | */ |
1022 | 1022 | public static function add_category_for_question_id($categoryId, $questionId, $courseId) |
1023 | 1023 | { |
@@ -1025,18 +1025,18 @@ discard block |
||
1025 | 1025 | // if question doesn't have a category |
1026 | 1026 | // @todo change for 1.10 when a question can have several categories |
1027 | 1027 | if (TestCategory::getCategoryForQuestion($questionId, $courseId) == 0 && |
1028 | - $questionId > 0 && |
|
1029 | - $courseId > 0 |
|
1028 | + $questionId > 0 && |
|
1029 | + $courseId > 0 |
|
1030 | 1030 | ) { |
1031 | 1031 | $sql = "INSERT INTO $table (c_id, question_id, category_id) |
1032 | 1032 | VALUES (".intval($courseId).", ".intval($questionId).", ".intval($categoryId).")"; |
1033 | 1033 | Database::query($sql); |
1034 | - $id = Database::insert_id(); |
|
1034 | + $id = Database::insert_id(); |
|
1035 | 1035 | |
1036 | - return $id; |
|
1036 | + return $id; |
|
1037 | 1037 | } |
1038 | 1038 | |
1039 | - return false; |
|
1039 | + return false; |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
@@ -77,20 +77,20 @@ discard block |
||
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - /** |
|
81 | - * private function creating a new work object |
|
82 | - * |
|
83 | - * @param int $uploader_id |
|
84 | - * @param string $title |
|
85 | - * @param string $description |
|
86 | - * @param string $author |
|
87 | - * @param string $filename |
|
88 | - * @param int $filesize |
|
89 | - * |
|
90 | - * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
91 | - * As a consequence this parameter can be removed |
|
92 | - */ |
|
93 | - public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
80 | + /** |
|
81 | + * private function creating a new work object |
|
82 | + * |
|
83 | + * @param int $uploader_id |
|
84 | + * @param string $title |
|
85 | + * @param string $description |
|
86 | + * @param string $author |
|
87 | + * @param string $filename |
|
88 | + * @param int $filesize |
|
89 | + * |
|
90 | + * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
91 | + * As a consequence this parameter can be removed |
|
92 | + */ |
|
93 | + public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
94 | 94 | { |
95 | 95 | $dropbox_cnf = getDropboxConf(); |
96 | 96 | |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | // Check if object exists already. If it does, the old object is used |
109 | 109 | // with updated information (authors, description, upload_date) |
110 | 110 | $this->isOldWork = false; |
111 | - $sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']." |
|
111 | + $sql = "SELECT id, upload_date FROM ".$dropbox_cnf['tbl_file']." |
|
112 | 112 | WHERE c_id = $course_id AND filename = '".Database::escape_string($this->filename)."'"; |
113 | 113 | $result = Database::query($sql); |
114 | - $res = Database::fetch_array($result); |
|
115 | - if ($res) { |
|
116 | - $this->isOldWork = true; |
|
117 | - } |
|
118 | - // Insert or update the dropbox_file table and set the id property |
|
119 | - if ($this->isOldWork) { |
|
120 | - $this->id = $res['id']; |
|
121 | - $this->upload_date = $res['upload_date']; |
|
114 | + $res = Database::fetch_array($result); |
|
115 | + if ($res) { |
|
116 | + $this->isOldWork = true; |
|
117 | + } |
|
118 | + // Insert or update the dropbox_file table and set the id property |
|
119 | + if ($this->isOldWork) { |
|
120 | + $this->id = $res['id']; |
|
121 | + $this->upload_date = $res['upload_date']; |
|
122 | 122 | |
123 | 123 | $params = [ |
124 | 124 | 'filesize' => $this->filesize, |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | ['c_id = ? AND id = ?' => [$course_id, $this->id]] |
136 | 136 | ); |
137 | 137 | |
138 | - } else { |
|
139 | - $this->upload_date = $this->last_upload_date; |
|
140 | - $params = [ |
|
138 | + } else { |
|
139 | + $this->upload_date = $this->last_upload_date; |
|
140 | + $params = [ |
|
141 | 141 | 'c_id' => $course_id, |
142 | 142 | 'uploader_id' => $this->uploader_id, |
143 | 143 | 'filename' => $this->filename, |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | 'last_upload_date' => $this->last_upload_date, |
150 | 150 | 'session_id' => api_get_session_id(), |
151 | 151 | 'cat_id' => 0 |
152 | - ]; |
|
152 | + ]; |
|
153 | 153 | |
154 | - $this->id = Database::insert($dropbox_cnf['tbl_file'], $params); |
|
155 | - if ($this->id) { |
|
156 | - $sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}"; |
|
157 | - Database::query($sql); |
|
158 | - } |
|
159 | - } |
|
154 | + $this->id = Database::insert($dropbox_cnf['tbl_file'], $params); |
|
155 | + if ($this->id) { |
|
156 | + $sql = "UPDATE ".$dropbox_cnf['tbl_file']." SET id = iid WHERE iid = {$this->id}"; |
|
157 | + Database::query($sql); |
|
158 | + } |
|
159 | + } |
|
160 | 160 | |
161 | 161 | $sql = "SELECT count(file_id) as count |
162 | 162 | FROM ".$dropbox_cnf['tbl_person']." |
@@ -170,16 +170,16 @@ discard block |
||
170 | 170 | VALUES ($course_id, ".intval($this->id)." , ".intval($this->uploader_id).")"; |
171 | 171 | Database::query($sql); |
172 | 172 | } |
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * private function creating existing object by retreiving info from db |
|
177 | - * |
|
178 | - * @param int $id |
|
179 | - */ |
|
180 | - public function _createExistingWork($id) |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * private function creating existing object by retreiving info from db |
|
177 | + * |
|
178 | + * @param int $id |
|
179 | + */ |
|
180 | + public function _createExistingWork($id) |
|
181 | 181 | { |
182 | - $course_id = api_get_course_int_id(); |
|
182 | + $course_id = api_get_course_int_id(); |
|
183 | 183 | $dropbox_cnf = getDropboxConf(); |
184 | 184 | |
185 | 185 | $action = isset($_GET['action']) ? $_GET['action'] : null; |
@@ -229,52 +229,52 @@ discard block |
||
229 | 229 | } |
230 | 230 | $this->feedback2= $feedback2; |
231 | 231 | } |
232 | - } |
|
232 | + } |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | class Dropbox_SentWork extends Dropbox_Work |
236 | 236 | { |
237 | - public $recipients; //array of ['id']['name'] arrays |
|
238 | - |
|
239 | - /** |
|
240 | - * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
241 | - * depending on the number of parameters |
|
242 | - * |
|
243 | - * @param unknown_type $arg1 |
|
244 | - * @param unknown_type $arg2 |
|
245 | - * @param unknown_type $arg3 |
|
246 | - * @param unknown_type $arg4 |
|
247 | - * @param unknown_type $arg5 |
|
248 | - * @param unknown_type $arg6 |
|
249 | - * @param unknown_type $arg7 |
|
250 | - * @return Dropbox_SentWork |
|
251 | - */ |
|
252 | - public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
237 | + public $recipients; //array of ['id']['name'] arrays |
|
238 | + |
|
239 | + /** |
|
240 | + * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
241 | + * depending on the number of parameters |
|
242 | + * |
|
243 | + * @param unknown_type $arg1 |
|
244 | + * @param unknown_type $arg2 |
|
245 | + * @param unknown_type $arg3 |
|
246 | + * @param unknown_type $arg4 |
|
247 | + * @param unknown_type $arg5 |
|
248 | + * @param unknown_type $arg6 |
|
249 | + * @param unknown_type $arg7 |
|
250 | + * @return Dropbox_SentWork |
|
251 | + */ |
|
252 | + public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
253 | 253 | { |
254 | - if (func_num_args() > 1) { |
|
255 | - $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
256 | - } else { |
|
257 | - $this->_createExistingSentWork($arg1); |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * private function creating a new SentWork object |
|
263 | - * |
|
264 | - * @param int $uploader_id |
|
265 | - * @param string $title |
|
266 | - * @param string $description |
|
267 | - * @param string $author |
|
268 | - * @param string $filename |
|
269 | - * @param int $filesize |
|
270 | - * @param array $recipient_ids |
|
271 | - */ |
|
272 | - public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
254 | + if (func_num_args() > 1) { |
|
255 | + $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
256 | + } else { |
|
257 | + $this->_createExistingSentWork($arg1); |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * private function creating a new SentWork object |
|
263 | + * |
|
264 | + * @param int $uploader_id |
|
265 | + * @param string $title |
|
266 | + * @param string $description |
|
267 | + * @param string $author |
|
268 | + * @param string $filename |
|
269 | + * @param int $filesize |
|
270 | + * @param array $recipient_ids |
|
271 | + */ |
|
272 | + public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
273 | 273 | { |
274 | 274 | $dropbox_cnf = getDropboxConf(); |
275 | 275 | $_course = api_get_course_info(); |
276 | 276 | |
277 | - // Call constructor of Dropbox_Work object |
|
277 | + // Call constructor of Dropbox_Work object |
|
278 | 278 | parent::__construct( |
279 | 279 | $uploader_id, |
280 | 280 | $title, |
@@ -284,31 +284,31 @@ discard block |
||
284 | 284 | $filesize |
285 | 285 | ); |
286 | 286 | |
287 | - $course_id = api_get_course_int_id(); |
|
288 | - |
|
289 | - // Do sanity checks on recipient_ids array & property fillin |
|
290 | - // The sanity check for ex-coursemembers is already done in base constructor |
|
291 | - settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type |
|
287 | + $course_id = api_get_course_int_id(); |
|
292 | 288 | |
293 | - $justSubmit = false; |
|
294 | - if ( is_int($recipient_ids)) { |
|
295 | - $justSubmit = true; |
|
296 | - $recipient_ids = array($recipient_ids + $this->id); |
|
297 | - } elseif ( count($recipient_ids) == 0) { |
|
298 | - $justSubmit = true; |
|
299 | - $recipient_ids = array($uploader_id); |
|
300 | - } |
|
289 | + // Do sanity checks on recipient_ids array & property fillin |
|
290 | + // The sanity check for ex-coursemembers is already done in base constructor |
|
291 | + settype($uploader_id, 'integer') or die(get_lang('GeneralError').' (code 208)'); // Set $uploader_id to correct type |
|
292 | + |
|
293 | + $justSubmit = false; |
|
294 | + if ( is_int($recipient_ids)) { |
|
295 | + $justSubmit = true; |
|
296 | + $recipient_ids = array($recipient_ids + $this->id); |
|
297 | + } elseif ( count($recipient_ids) == 0) { |
|
298 | + $justSubmit = true; |
|
299 | + $recipient_ids = array($uploader_id); |
|
300 | + } |
|
301 | 301 | |
302 | - if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
303 | - die(get_lang('GeneralError').' (code 209)'); |
|
304 | - } |
|
302 | + if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
303 | + die(get_lang('GeneralError').' (code 209)'); |
|
304 | + } |
|
305 | 305 | |
306 | - foreach ($recipient_ids as $rec) { |
|
307 | - if (empty($rec)) die(get_lang('GeneralError').' (code 210)'); |
|
308 | - //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course |
|
309 | - //this check is done when validating submitted data |
|
310 | - $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec)); |
|
311 | - } |
|
306 | + foreach ($recipient_ids as $rec) { |
|
307 | + if (empty($rec)) die(get_lang('GeneralError').' (code 210)'); |
|
308 | + //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course |
|
309 | + //this check is done when validating submitted data |
|
310 | + $this->recipients[] = array('id' => $rec, 'name' => getUserNameFromId($rec)); |
|
311 | + } |
|
312 | 312 | |
313 | 313 | $table_post = $dropbox_cnf['tbl_post']; |
314 | 314 | $table_person = $dropbox_cnf['tbl_person']; |
@@ -317,13 +317,13 @@ discard block |
||
317 | 317 | $user = api_get_user_id(); |
318 | 318 | $now = api_get_utc_datetime(); |
319 | 319 | |
320 | - // Insert data in dropbox_post and dropbox_person table for each recipient |
|
321 | - foreach ($this->recipients as $rec) { |
|
320 | + // Insert data in dropbox_post and dropbox_person table for each recipient |
|
321 | + foreach ($this->recipients as $rec) { |
|
322 | 322 | $file_id = (int)$this->id; |
323 | 323 | $user_id = (int)$rec['id']; |
324 | - $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id) |
|
324 | + $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id) |
|
325 | 325 | VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)"; |
326 | - Database::query($sql); |
|
326 | + Database::query($sql); |
|
327 | 327 | // If work already exists no error is generated |
328 | 328 | |
329 | 329 | /** |
@@ -340,13 +340,13 @@ discard block |
||
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | - // Update item_property table for each recipient |
|
344 | - if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
345 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
346 | - } |
|
347 | - if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) { |
|
348 | - $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
349 | - } |
|
343 | + // Update item_property table for each recipient |
|
344 | + if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
345 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
346 | + } |
|
347 | + if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) { |
|
348 | + $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
349 | + } |
|
350 | 350 | api_item_property_update( |
351 | 351 | $_course, |
352 | 352 | TOOL_DROPBOX, |
@@ -356,92 +356,92 @@ discard block |
||
356 | 356 | null, |
357 | 357 | $recipid |
358 | 358 | ); |
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * private function creating existing object by retreiving info from db |
|
364 | - * |
|
365 | - * @param unknown_type $id |
|
366 | - */ |
|
367 | - public function _createExistingSentWork($id) |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * private function creating existing object by retreiving info from db |
|
364 | + * |
|
365 | + * @param unknown_type $id |
|
366 | + */ |
|
367 | + public function _createExistingSentWork($id) |
|
368 | 368 | { |
369 | 369 | $dropbox_cnf = getDropboxConf(); |
370 | 370 | $id = intval($id); |
371 | 371 | |
372 | - $course_id = api_get_course_int_id(); |
|
372 | + $course_id = api_get_course_int_id(); |
|
373 | 373 | |
374 | - // Call constructor of Dropbox_Work object |
|
375 | - parent::__construct($id); |
|
374 | + // Call constructor of Dropbox_Work object |
|
375 | + parent::__construct($id); |
|
376 | 376 | |
377 | - // Fill in recipients array |
|
378 | - $this->recipients = array(); |
|
379 | - $sql = "SELECT dest_user_id, feedback_date, feedback |
|
377 | + // Fill in recipients array |
|
378 | + $this->recipients = array(); |
|
379 | + $sql = "SELECT dest_user_id, feedback_date, feedback |
|
380 | 380 | FROM ".$dropbox_cnf['tbl_post']." |
381 | 381 | WHERE c_id = $course_id AND file_id = ".intval($id).""; |
382 | 382 | $result = Database::query($sql); |
383 | - while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
384 | - |
|
385 | - // Check for deleted users |
|
386 | - $dest_user_id = $res['dest_user_id']; |
|
387 | - $user_info = api_get_user_info($dest_user_id); |
|
388 | - //$this->category = $res['cat_id']; |
|
389 | - if (!$user_info) { |
|
390 | - $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
391 | - } else { |
|
392 | - $this->recipients[] = array( |
|
383 | + while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
384 | + |
|
385 | + // Check for deleted users |
|
386 | + $dest_user_id = $res['dest_user_id']; |
|
387 | + $user_info = api_get_user_info($dest_user_id); |
|
388 | + //$this->category = $res['cat_id']; |
|
389 | + if (!$user_info) { |
|
390 | + $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
391 | + } else { |
|
392 | + $this->recipients[] = array( |
|
393 | 393 | 'id' => $dest_user_id, |
394 | 394 | 'name' => $user_info['complete_name'], |
395 | 395 | 'user_id' => $dest_user_id, |
396 | - 'feedback_date' => $res['feedback_date'], |
|
396 | + 'feedback_date' => $res['feedback_date'], |
|
397 | 397 | 'feedback' => $res['feedback'] |
398 | 398 | ); |
399 | - } |
|
400 | - } |
|
401 | - } |
|
399 | + } |
|
400 | + } |
|
401 | + } |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | class Dropbox_Person |
405 | 405 | { |
406 | - // The receivedWork and the sentWork arrays are sorted. |
|
407 | - public $receivedWork; // an array of Dropbox_Work objects |
|
408 | - public $sentWork; // an array of Dropbox_SentWork objects |
|
409 | - |
|
410 | - public $userId = 0; |
|
411 | - public $isCourseAdmin = false; |
|
412 | - public $isCourseTutor = false; |
|
413 | - public $_orderBy = ''; // private property that determines by which field |
|
414 | - |
|
415 | - /** |
|
416 | - * Constructor for recreating the Dropbox_Person object |
|
417 | - * |
|
418 | - * @param int $userId |
|
419 | - * @param bool $isCourseAdmin |
|
420 | - * @param bool $isCourseTutor |
|
421 | - * @return Dropbox_Person |
|
422 | - */ |
|
423 | - public function __construct($userId, $isCourseAdmin, $isCourseTutor) |
|
406 | + // The receivedWork and the sentWork arrays are sorted. |
|
407 | + public $receivedWork; // an array of Dropbox_Work objects |
|
408 | + public $sentWork; // an array of Dropbox_SentWork objects |
|
409 | + |
|
410 | + public $userId = 0; |
|
411 | + public $isCourseAdmin = false; |
|
412 | + public $isCourseTutor = false; |
|
413 | + public $_orderBy = ''; // private property that determines by which field |
|
414 | + |
|
415 | + /** |
|
416 | + * Constructor for recreating the Dropbox_Person object |
|
417 | + * |
|
418 | + * @param int $userId |
|
419 | + * @param bool $isCourseAdmin |
|
420 | + * @param bool $isCourseTutor |
|
421 | + * @return Dropbox_Person |
|
422 | + */ |
|
423 | + public function __construct($userId, $isCourseAdmin, $isCourseTutor) |
|
424 | 424 | { |
425 | - $course_id = api_get_course_int_id(); |
|
425 | + $course_id = api_get_course_int_id(); |
|
426 | 426 | |
427 | - // Fill in properties |
|
427 | + // Fill in properties |
|
428 | 428 | $this->userId = $userId; |
429 | 429 | $this->isCourseAdmin = $isCourseAdmin; |
430 | 430 | $this->isCourseTutor = $isCourseTutor; |
431 | 431 | $this->receivedWork = array(); |
432 | 432 | $this->sentWork = array(); |
433 | 433 | |
434 | - // Note: perhaps include an ex coursemember check to delete old files |
|
434 | + // Note: perhaps include an ex coursemember check to delete old files |
|
435 | 435 | |
436 | - $session_id = api_get_session_id(); |
|
437 | - $condition_session = api_get_session_condition($session_id); |
|
436 | + $session_id = api_get_session_id(); |
|
437 | + $condition_session = api_get_session_condition($session_id); |
|
438 | 438 | |
439 | - $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
440 | - $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
441 | - $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
439 | + $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
440 | + $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
441 | + $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
442 | 442 | |
443 | 443 | // Find all entries where this person is the recipient |
444 | - $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
444 | + $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
445 | 445 | FROM $post_tbl r |
446 | 446 | INNER JOIN $person_tbl p |
447 | 447 | ON (r.file_id = p.file_id AND r.c_id = $course_id AND p.c_id = $course_id ) |
@@ -450,12 +450,12 @@ discard block |
||
450 | 450 | r.dest_user_id = ".intval($this->userId)." $condition_session "; |
451 | 451 | |
452 | 452 | $result = Database::query($sql); |
453 | - while ($res = Database::fetch_array($result)) { |
|
454 | - $temp = new Dropbox_Work($res['file_id']); |
|
455 | - $temp->category = $res['cat_id']; |
|
456 | - $this->receivedWork[] = $temp; |
|
457 | - } |
|
458 | - // Find all entries where this person is the sender/uploader |
|
453 | + while ($res = Database::fetch_array($result)) { |
|
454 | + $temp = new Dropbox_Work($res['file_id']); |
|
455 | + $temp->category = $res['cat_id']; |
|
456 | + $this->receivedWork[] = $temp; |
|
457 | + } |
|
458 | + // Find all entries where this person is the sender/uploader |
|
459 | 459 | $sql = "SELECT DISTINCT f.id |
460 | 460 | FROM $file_tbl f |
461 | 461 | INNER JOIN $person_tbl p |
@@ -466,261 +466,261 @@ discard block |
||
466 | 466 | $condition_session |
467 | 467 | "; |
468 | 468 | $result = Database::query($sql); |
469 | - while ($res = Database::fetch_array($result)) { |
|
470 | - $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * This private method is used by the usort function in the |
|
476 | - * orderSentWork and orderReceivedWork methods. |
|
477 | - * It compares 2 work-objects by 1 of the properties of that object, dictated by the |
|
478 | - * private property _orderBy |
|
479 | - * |
|
480 | - * @param unknown_type $a |
|
481 | - * @param unknown_type $b |
|
482 | - * @return -1, 0 or 1 dependent of the result of the comparison. |
|
483 | - */ |
|
484 | - function _cmpWork($a, $b) |
|
469 | + while ($res = Database::fetch_array($result)) { |
|
470 | + $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * This private method is used by the usort function in the |
|
476 | + * orderSentWork and orderReceivedWork methods. |
|
477 | + * It compares 2 work-objects by 1 of the properties of that object, dictated by the |
|
478 | + * private property _orderBy |
|
479 | + * |
|
480 | + * @param unknown_type $a |
|
481 | + * @param unknown_type $b |
|
482 | + * @return -1, 0 or 1 dependent of the result of the comparison. |
|
483 | + */ |
|
484 | + function _cmpWork($a, $b) |
|
485 | 485 | { |
486 | - $sort = $this->_orderBy; |
|
487 | - $aval = $a->$sort; |
|
488 | - $bval = $b->$sort; |
|
489 | - if ($sort == 'recipients') { |
|
490 | - // The recipients property is an array so we do the comparison based |
|
491 | - // on the first item of the recipients array |
|
492 | - $aval = $aval[0]['name']; |
|
493 | - $bval = $bval[0]['name']; |
|
494 | - } |
|
495 | - if ($sort == 'filesize') { // Filesize is not a string, so we use other comparison technique |
|
496 | - return $aval < $bval ? -1 : 1; |
|
497 | - } elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly" |
|
498 | - return api_strnatcmp($aval, $bval); |
|
499 | - } else { |
|
500 | - return api_strcasecmp($aval, $bval); |
|
501 | - } |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * A method that sorts the objects in the sentWork array, dependent on the $sort parameter. |
|
506 | - * $sort can be lastDate, firstDate, title, size, ... |
|
507 | - * |
|
508 | - * @param unknown_type $sort |
|
509 | - */ |
|
510 | - function orderSentWork($sort) |
|
486 | + $sort = $this->_orderBy; |
|
487 | + $aval = $a->$sort; |
|
488 | + $bval = $b->$sort; |
|
489 | + if ($sort == 'recipients') { |
|
490 | + // The recipients property is an array so we do the comparison based |
|
491 | + // on the first item of the recipients array |
|
492 | + $aval = $aval[0]['name']; |
|
493 | + $bval = $bval[0]['name']; |
|
494 | + } |
|
495 | + if ($sort == 'filesize') { // Filesize is not a string, so we use other comparison technique |
|
496 | + return $aval < $bval ? -1 : 1; |
|
497 | + } elseif ($sort == 'title') { // Natural order for sorting titles is more "human-friendly" |
|
498 | + return api_strnatcmp($aval, $bval); |
|
499 | + } else { |
|
500 | + return api_strcasecmp($aval, $bval); |
|
501 | + } |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * A method that sorts the objects in the sentWork array, dependent on the $sort parameter. |
|
506 | + * $sort can be lastDate, firstDate, title, size, ... |
|
507 | + * |
|
508 | + * @param unknown_type $sort |
|
509 | + */ |
|
510 | + function orderSentWork($sort) |
|
511 | 511 | { |
512 | - switch($sort) { |
|
513 | - case 'lastDate': |
|
514 | - $this->_orderBy = 'last_upload_date'; |
|
515 | - break; |
|
516 | - case 'firstDate': |
|
517 | - $this->_orderBy = 'upload_date'; |
|
518 | - break; |
|
519 | - case 'title': |
|
520 | - $this->_orderBy = 'title'; |
|
521 | - break; |
|
522 | - case 'size': |
|
523 | - $this->_orderBy = 'filesize'; |
|
524 | - break; |
|
525 | - case 'author': |
|
526 | - $this->_orderBy = 'author'; |
|
527 | - break; |
|
528 | - case 'recipient': |
|
529 | - $this->_orderBy = 'recipients'; |
|
530 | - break; |
|
531 | - default: |
|
532 | - $this->_orderBy = 'last_upload_date'; |
|
533 | - } |
|
534 | - |
|
535 | - usort($this->sentWork, array($this, '_cmpWork')); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * method that sorts the objects in the receivedWork array, dependent on the $sort parameter. |
|
540 | - * $sort can be lastDate, firstDate, title, size, ... |
|
541 | - * @param unknown_type $sort |
|
542 | - */ |
|
543 | - function orderReceivedWork($sort) |
|
512 | + switch($sort) { |
|
513 | + case 'lastDate': |
|
514 | + $this->_orderBy = 'last_upload_date'; |
|
515 | + break; |
|
516 | + case 'firstDate': |
|
517 | + $this->_orderBy = 'upload_date'; |
|
518 | + break; |
|
519 | + case 'title': |
|
520 | + $this->_orderBy = 'title'; |
|
521 | + break; |
|
522 | + case 'size': |
|
523 | + $this->_orderBy = 'filesize'; |
|
524 | + break; |
|
525 | + case 'author': |
|
526 | + $this->_orderBy = 'author'; |
|
527 | + break; |
|
528 | + case 'recipient': |
|
529 | + $this->_orderBy = 'recipients'; |
|
530 | + break; |
|
531 | + default: |
|
532 | + $this->_orderBy = 'last_upload_date'; |
|
533 | + } |
|
534 | + |
|
535 | + usort($this->sentWork, array($this, '_cmpWork')); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * method that sorts the objects in the receivedWork array, dependent on the $sort parameter. |
|
540 | + * $sort can be lastDate, firstDate, title, size, ... |
|
541 | + * @param unknown_type $sort |
|
542 | + */ |
|
543 | + function orderReceivedWork($sort) |
|
544 | 544 | { |
545 | - switch($sort) { |
|
546 | - case 'lastDate': |
|
547 | - $this->_orderBy = 'last_upload_date'; |
|
548 | - break; |
|
549 | - case 'firstDate': |
|
550 | - $this->_orderBy = 'upload_date'; |
|
551 | - break; |
|
552 | - case 'title': |
|
553 | - $this->_orderBy = 'title'; |
|
554 | - break; |
|
555 | - case 'size': |
|
556 | - $this->_orderBy = 'filesize'; |
|
557 | - break; |
|
558 | - case 'author': |
|
559 | - $this->_orderBy = 'author'; |
|
560 | - break; |
|
561 | - case 'sender': |
|
562 | - $this->_orderBy = 'uploaderName'; |
|
563 | - break; |
|
564 | - default: |
|
565 | - $this->_orderBy = 'last_upload_date'; |
|
566 | - } |
|
567 | - |
|
568 | - usort($this->receivedWork, array($this, '_cmpWork')); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Deletes all the received work of this person |
|
573 | - */ |
|
574 | - function deleteAllReceivedWork() |
|
545 | + switch($sort) { |
|
546 | + case 'lastDate': |
|
547 | + $this->_orderBy = 'last_upload_date'; |
|
548 | + break; |
|
549 | + case 'firstDate': |
|
550 | + $this->_orderBy = 'upload_date'; |
|
551 | + break; |
|
552 | + case 'title': |
|
553 | + $this->_orderBy = 'title'; |
|
554 | + break; |
|
555 | + case 'size': |
|
556 | + $this->_orderBy = 'filesize'; |
|
557 | + break; |
|
558 | + case 'author': |
|
559 | + $this->_orderBy = 'author'; |
|
560 | + break; |
|
561 | + case 'sender': |
|
562 | + $this->_orderBy = 'uploaderName'; |
|
563 | + break; |
|
564 | + default: |
|
565 | + $this->_orderBy = 'last_upload_date'; |
|
566 | + } |
|
567 | + |
|
568 | + usort($this->receivedWork, array($this, '_cmpWork')); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Deletes all the received work of this person |
|
573 | + */ |
|
574 | + function deleteAllReceivedWork() |
|
575 | 575 | { |
576 | - $course_id = api_get_course_int_id(); |
|
576 | + $course_id = api_get_course_int_id(); |
|
577 | 577 | $dropbox_cnf = getDropboxConf(); |
578 | - // Delete entries in person table concerning received works |
|
579 | - foreach ($this->receivedWork as $w) { |
|
578 | + // Delete entries in person table concerning received works |
|
579 | + foreach ($this->receivedWork as $w) { |
|
580 | 580 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
581 | 581 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
582 | - Database::query($sql); |
|
583 | - } |
|
582 | + Database::query($sql); |
|
583 | + } |
|
584 | 584 | // Check for unused files |
585 | - removeUnusedFiles(); |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Deletes all the received categories and work of this person |
|
590 | - * @param integer $id |
|
591 | - */ |
|
592 | - function deleteReceivedWorkFolder($id) |
|
585 | + removeUnusedFiles(); |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Deletes all the received categories and work of this person |
|
590 | + * @param integer $id |
|
591 | + */ |
|
592 | + function deleteReceivedWorkFolder($id) |
|
593 | 593 | { |
594 | 594 | $dropbox_cnf = getDropboxConf(); |
595 | 595 | $course_id = api_get_course_int_id(); |
596 | 596 | |
597 | - $id = intval($id); |
|
598 | - $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." |
|
597 | + $id = intval($id); |
|
598 | + $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." |
|
599 | 599 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
600 | - if (!Database::query($sql)) return false; |
|
601 | - $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." |
|
600 | + if (!Database::query($sql)) return false; |
|
601 | + $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." |
|
602 | 602 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
603 | - if (!Database::query($sql)) return false; |
|
604 | - $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']." |
|
603 | + if (!Database::query($sql)) return false; |
|
604 | + $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']." |
|
605 | 605 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
606 | - if (!Database::query($sql)) return false; |
|
607 | - return true; |
|
608 | - } |
|
609 | - |
|
610 | - /** |
|
611 | - * Deletes a received dropbox file of this person with id=$id |
|
612 | - * |
|
613 | - * @param integer $id |
|
614 | - */ |
|
615 | - function deleteReceivedWork($id) |
|
606 | + if (!Database::query($sql)) return false; |
|
607 | + return true; |
|
608 | + } |
|
609 | + |
|
610 | + /** |
|
611 | + * Deletes a received dropbox file of this person with id=$id |
|
612 | + * |
|
613 | + * @param integer $id |
|
614 | + */ |
|
615 | + function deleteReceivedWork($id) |
|
616 | 616 | { |
617 | - $course_id = api_get_course_int_id(); |
|
617 | + $course_id = api_get_course_int_id(); |
|
618 | 618 | $dropbox_cnf = getDropboxConf(); |
619 | - $id = intval($id); |
|
620 | - |
|
621 | - // index check |
|
622 | - $found = false; |
|
623 | - foreach ($this->receivedWork as $w) { |
|
624 | - if ($w->id == $id) { |
|
625 | - $found = true; |
|
626 | - break; |
|
627 | - } |
|
628 | - } |
|
629 | - |
|
630 | - if (!$found) { |
|
631 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
632 | - die(get_lang('GeneralError').' (code 216)'); |
|
633 | - } |
|
634 | - } |
|
635 | - // Delete entries in person table concerning received works |
|
619 | + $id = intval($id); |
|
620 | + |
|
621 | + // index check |
|
622 | + $found = false; |
|
623 | + foreach ($this->receivedWork as $w) { |
|
624 | + if ($w->id == $id) { |
|
625 | + $found = true; |
|
626 | + break; |
|
627 | + } |
|
628 | + } |
|
629 | + |
|
630 | + if (!$found) { |
|
631 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
632 | + die(get_lang('GeneralError').' (code 216)'); |
|
633 | + } |
|
634 | + } |
|
635 | + // Delete entries in person table concerning received works |
|
636 | 636 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
637 | 637 | WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'"; |
638 | - Database::query($sql); |
|
639 | - removeUnusedFiles(); // Check for unused files |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * Deletes all the sent dropbox files of this person |
|
644 | - */ |
|
645 | - function deleteAllSentWork() |
|
638 | + Database::query($sql); |
|
639 | + removeUnusedFiles(); // Check for unused files |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * Deletes all the sent dropbox files of this person |
|
644 | + */ |
|
645 | + function deleteAllSentWork() |
|
646 | 646 | { |
647 | - $course_id = api_get_course_int_id(); |
|
647 | + $course_id = api_get_course_int_id(); |
|
648 | 648 | $dropbox_cnf = getDropboxConf(); |
649 | - //delete entries in person table concerning sent works |
|
650 | - foreach ($this->sentWork as $w) { |
|
649 | + //delete entries in person table concerning sent works |
|
650 | + foreach ($this->sentWork as $w) { |
|
651 | 651 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
652 | 652 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
653 | - Database::query($sql); |
|
654 | - removeMoreIfMailing($w->id); |
|
655 | - } |
|
656 | - removeUnusedFiles(); // Check for unused files |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * Deletes a sent dropbox file of this person with id=$id |
|
661 | - * |
|
662 | - * @param unknown_type $id |
|
663 | - */ |
|
664 | - function deleteSentWork($id) |
|
653 | + Database::query($sql); |
|
654 | + removeMoreIfMailing($w->id); |
|
655 | + } |
|
656 | + removeUnusedFiles(); // Check for unused files |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * Deletes a sent dropbox file of this person with id=$id |
|
661 | + * |
|
662 | + * @param unknown_type $id |
|
663 | + */ |
|
664 | + function deleteSentWork($id) |
|
665 | 665 | { |
666 | - $course_id = api_get_course_int_id(); |
|
666 | + $course_id = api_get_course_int_id(); |
|
667 | 667 | $dropbox_cnf = getDropboxConf(); |
668 | 668 | |
669 | - $id = intval($id); |
|
670 | - |
|
671 | - // index check |
|
672 | - $found = false; |
|
673 | - foreach ($this->sentWork as $w) { |
|
674 | - if ($w->id == $id) { |
|
675 | - $found = true; |
|
676 | - break; |
|
677 | - } |
|
678 | - } |
|
679 | - if (!$found) { |
|
680 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
681 | - die(get_lang('GeneralError').' (code 219)'); |
|
682 | - } |
|
683 | - } |
|
684 | - //$file_id = $this->sentWork[$index]->id; |
|
685 | - // Delete entries in person table concerning sent works |
|
669 | + $id = intval($id); |
|
670 | + |
|
671 | + // index check |
|
672 | + $found = false; |
|
673 | + foreach ($this->sentWork as $w) { |
|
674 | + if ($w->id == $id) { |
|
675 | + $found = true; |
|
676 | + break; |
|
677 | + } |
|
678 | + } |
|
679 | + if (!$found) { |
|
680 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
681 | + die(get_lang('GeneralError').' (code 219)'); |
|
682 | + } |
|
683 | + } |
|
684 | + //$file_id = $this->sentWork[$index]->id; |
|
685 | + // Delete entries in person table concerning sent works |
|
686 | 686 | $sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." |
687 | 687 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'"; |
688 | - Database::query($sql); |
|
689 | - removeMoreIfMailing($id); |
|
690 | - removeUnusedFiles(); // Check for unused files |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Updates feedback for received work of this person with id=$id |
|
695 | - * |
|
696 | - * @param string $id |
|
697 | - * @param string $text |
|
698 | - */ |
|
699 | - function updateFeedback($id, $text) |
|
688 | + Database::query($sql); |
|
689 | + removeMoreIfMailing($id); |
|
690 | + removeUnusedFiles(); // Check for unused files |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Updates feedback for received work of this person with id=$id |
|
695 | + * |
|
696 | + * @param string $id |
|
697 | + * @param string $text |
|
698 | + */ |
|
699 | + function updateFeedback($id, $text) |
|
700 | 700 | { |
701 | - $course_id = api_get_course_int_id(); |
|
701 | + $course_id = api_get_course_int_id(); |
|
702 | 702 | $_course = api_get_course_info(); |
703 | 703 | $dropbox_cnf = getDropboxConf(); |
704 | 704 | |
705 | - $id = intval($id); |
|
706 | - |
|
707 | - // index check |
|
708 | - $found = false; |
|
709 | - $wi = -1; |
|
710 | - foreach ($this->receivedWork as $w) { |
|
711 | - $wi++; |
|
712 | - if ($w->id == $id){ |
|
713 | - $found = true; |
|
714 | - break; |
|
715 | - } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
716 | - } |
|
717 | - if (!$found) { |
|
718 | - die(get_lang('GeneralError').' (code 221)'); |
|
719 | - } |
|
720 | - |
|
721 | - $feedback_date = api_get_utc_datetime(); |
|
722 | - $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
723 | - $this->receivedWork[$wi]->feedback = $text; |
|
705 | + $id = intval($id); |
|
706 | + |
|
707 | + // index check |
|
708 | + $found = false; |
|
709 | + $wi = -1; |
|
710 | + foreach ($this->receivedWork as $w) { |
|
711 | + $wi++; |
|
712 | + if ($w->id == $id){ |
|
713 | + $found = true; |
|
714 | + break; |
|
715 | + } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
716 | + } |
|
717 | + if (!$found) { |
|
718 | + die(get_lang('GeneralError').' (code 221)'); |
|
719 | + } |
|
720 | + |
|
721 | + $feedback_date = api_get_utc_datetime(); |
|
722 | + $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
723 | + $this->receivedWork[$wi]->feedback = $text; |
|
724 | 724 | |
725 | 725 | $params = [ |
726 | 726 | 'feedback_date' => $feedback_date, |
@@ -738,11 +738,11 @@ discard block |
||
738 | 738 | ] |
739 | 739 | ); |
740 | 740 | |
741 | - // Update item_property table |
|
741 | + // Update item_property table |
|
742 | 742 | |
743 | - if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
744 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
745 | - } |
|
743 | + if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) { |
|
744 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
745 | + } |
|
746 | 746 | api_item_property_update( |
747 | 747 | $_course, |
748 | 748 | TOOL_DROPBOX, |
@@ -753,31 +753,31 @@ discard block |
||
753 | 753 | $ownerid |
754 | 754 | ); |
755 | 755 | |
756 | - } |
|
756 | + } |
|
757 | 757 | |
758 | - /** |
|
759 | - * Filter the received work |
|
760 | - * @param string $type |
|
761 | - * @param string $value |
|
762 | - */ |
|
763 | - function filter_received_work($type, $value) |
|
758 | + /** |
|
759 | + * Filter the received work |
|
760 | + * @param string $type |
|
761 | + * @param string $value |
|
762 | + */ |
|
763 | + function filter_received_work($type, $value) |
|
764 | 764 | { |
765 | 765 | $dropbox_cnf = getDropboxConf(); |
766 | - $new_received_work = array(); |
|
767 | - foreach ($this->receivedWork as $work) { |
|
768 | - switch ($type) { |
|
769 | - case 'uploader_id': |
|
770 | - if ($work->uploader_id == $value || |
|
771 | - ($work->uploader_id > $dropbox_cnf['mailingIdBase'] && |
|
766 | + $new_received_work = array(); |
|
767 | + foreach ($this->receivedWork as $work) { |
|
768 | + switch ($type) { |
|
769 | + case 'uploader_id': |
|
770 | + if ($work->uploader_id == $value || |
|
771 | + ($work->uploader_id > $dropbox_cnf['mailingIdBase'] && |
|
772 | 772 | getUserOwningThisMailing($work->uploader_id) == $value) |
773 | 773 | ) { |
774 | - $new_received_work[] = $work; |
|
775 | - } |
|
776 | - break; |
|
777 | - default: |
|
778 | - $new_received_work[] = $work; |
|
779 | - } |
|
780 | - } |
|
781 | - $this->receivedWork = $new_received_work; |
|
782 | - } |
|
774 | + $new_received_work[] = $work; |
|
775 | + } |
|
776 | + break; |
|
777 | + default: |
|
778 | + $new_received_work[] = $work; |
|
779 | + } |
|
780 | + } |
|
781 | + $this->receivedWork = $new_received_work; |
|
782 | + } |
|
783 | 783 | } |
@@ -399,10 +399,10 @@ |
||
399 | 399 | if(count($_plugins['menu_administrator']) > 0) { |
400 | 400 | $blocks['plugins']['icon'] = Display::return_icon( |
401 | 401 | 'plugins.png', |
402 | - get_lang('Plugins'), |
|
403 | - array(), |
|
404 | - ICON_SIZE_MEDIUM, |
|
405 | - false |
|
402 | + get_lang('Plugins'), |
|
403 | + array(), |
|
404 | + ICON_SIZE_MEDIUM, |
|
405 | + false |
|
406 | 406 | ); |
407 | 407 | $blocks['plugins']['label'] = api_ucfirst(get_lang('Plugins')); |
408 | 408 | $blocks['plugins']['class'] = 'block-admin-platform'; |
@@ -1231,13 +1231,13 @@ discard block |
||
1231 | 1231 | } |
1232 | 1232 | |
1233 | 1233 | /** |
1234 | - * Get the users by ID |
|
1235 | - * @param array $ids student ids |
|
1236 | - * @param string $active |
|
1237 | - * @param string $order |
|
1238 | - * @param string $limit |
|
1239 | - * @return array $result student information |
|
1240 | - */ |
|
1234 | + * Get the users by ID |
|
1235 | + * @param array $ids student ids |
|
1236 | + * @param string $active |
|
1237 | + * @param string $order |
|
1238 | + * @param string $limit |
|
1239 | + * @return array $result student information |
|
1240 | + */ |
|
1241 | 1241 | public static function get_user_list_by_ids($ids = array(), $active = null, $order = null, $limit = null) |
1242 | 1242 | { |
1243 | 1243 | if (empty($ids)) { |
@@ -2275,7 +2275,7 @@ discard block |
||
2275 | 2275 | * |
2276 | 2276 | * @return array with extra data info of a user i.e array('field_variable'=>'value'); |
2277 | 2277 | */ |
2278 | - public static function get_extra_user_data_by_value($field_variable, $field_value, $all_visibility = true) |
|
2278 | + public static function get_extra_user_data_by_value($field_variable, $field_value, $all_visibility = true) |
|
2279 | 2279 | { |
2280 | 2280 | $extraField = new ExtraFieldValue('user'); |
2281 | 2281 | |
@@ -3352,12 +3352,12 @@ discard block |
||
3352 | 3352 | if ($tag_id == 0) { |
3353 | 3353 | //the tag doesn't exist |
3354 | 3354 | $sql = "INSERT INTO $table_user_tag (tag, field_id,count) VALUES ('$tag','$field_id', count + 1)"; |
3355 | - Database::query($sql); |
|
3355 | + Database::query($sql); |
|
3356 | 3356 | $last_insert_id = Database::insert_id(); |
3357 | 3357 | } else { |
3358 | 3358 | //the tag exists we update it |
3359 | 3359 | $sql = "UPDATE $table_user_tag SET count = count + 1 WHERE id = $tag_id"; |
3360 | - Database::query($sql); |
|
3360 | + Database::query($sql); |
|
3361 | 3361 | $last_insert_id = $tag_id; |
3362 | 3362 | } |
3363 | 3363 | |
@@ -3552,9 +3552,9 @@ discard block |
||
3552 | 3552 | } |
3553 | 3553 | |
3554 | 3554 | /** |
3555 | - * Get extra filtrable user fields (only type select) |
|
3556 | - * @return array |
|
3557 | - */ |
|
3555 | + * Get extra filtrable user fields (only type select) |
|
3556 | + * @return array |
|
3557 | + */ |
|
3558 | 3558 | public static function get_extra_filtrable_fields() |
3559 | 3559 | { |
3560 | 3560 | $extraFieldList = UserManager::get_extra_fields(); |
@@ -3579,9 +3579,9 @@ discard block |
||
3579 | 3579 | } |
3580 | 3580 | |
3581 | 3581 | /** |
3582 | - * Get extra where clauses for finding users based on extra filtrable user fields (type select) |
|
3583 | - * @return string With AND clauses based on user's ID which have the values to search in extra user fields |
|
3584 | - */ |
|
3582 | + * Get extra where clauses for finding users based on extra filtrable user fields (type select) |
|
3583 | + * @return string With AND clauses based on user's ID which have the values to search in extra user fields |
|
3584 | + */ |
|
3585 | 3585 | public static function get_search_form_where_extra_fields() |
3586 | 3586 | { |
3587 | 3587 | $useExtraFields = false; |
@@ -3900,23 +3900,23 @@ discard block |
||
3900 | 3900 | } |
3901 | 3901 | |
3902 | 3902 | /** |
3903 | - * Get users followed by human resource manager |
|
3904 | - * @param int $userId |
|
3905 | - * @param int $userStatus Filter users by status (STUDENT, COURSEMANAGER, etc) |
|
3906 | - * @param bool $getOnlyUserId |
|
3907 | - * @param bool $getSql |
|
3908 | - * @param bool $getCount |
|
3909 | - * @param int $from |
|
3910 | - * @param int $numberItems |
|
3911 | - * @param int $column |
|
3912 | - * @param string $direction |
|
3913 | - * @param int $active |
|
3914 | - * @param string $lastConnectionDate |
|
3915 | - * @param int $status the function is called by who? COURSEMANAGER, DRH? |
|
3916 | - * @param string $keyword |
|
3903 | + * Get users followed by human resource manager |
|
3904 | + * @param int $userId |
|
3905 | + * @param int $userStatus Filter users by status (STUDENT, COURSEMANAGER, etc) |
|
3906 | + * @param bool $getOnlyUserId |
|
3907 | + * @param bool $getSql |
|
3908 | + * @param bool $getCount |
|
3909 | + * @param int $from |
|
3910 | + * @param int $numberItems |
|
3911 | + * @param int $column |
|
3912 | + * @param string $direction |
|
3913 | + * @param int $active |
|
3914 | + * @param string $lastConnectionDate |
|
3915 | + * @param int $status the function is called by who? COURSEMANAGER, DRH? |
|
3916 | + * @param string $keyword |
|
3917 | 3917 | * |
3918 | - * @return array user list |
|
3919 | - */ |
|
3918 | + * @return array user list |
|
3919 | + */ |
|
3920 | 3920 | public static function getUsersFollowedByUser( |
3921 | 3921 | $userId, |
3922 | 3922 | $userStatus = null, |
@@ -291,16 +291,16 @@ |
||
291 | 291 | Duis bibendum elementum justo. Duis posuere. Fusce nulla odio, posuere eget, condimentum nec, venenatis eu, elit. In hac habitasse platea dictumst. Aenean ac sem in enim imperdiet feugiat. Integer tincidunt lectus at elit. Integer magna lacus, vehicula quis, eleifend eget, suscipit vitae, leo. Nunc porta augue nec enim. Curabitur vehicula volutpat enim. Aliquam consequat. Vestibulum rhoncus tellus vitae erat. Integer est. Quisque fermentum leo nec odio. Suspendisse lobortis sollicitudin augue. Nullam urna mi, suscipit eu, sagittis laoreet, ultrices ac, sem. Aliquam enim tortor, hendrerit non, cursus a, tristique sit amet, sapien. Suspendisse potenti. Aenean semper placerat neque.'; |
292 | 292 | switch($type) |
293 | 293 | { |
294 | - case 'description': |
|
294 | + case 'description': |
|
295 | 295 | $descriptions = explode(".",$dummy_text); |
296 | 296 | return $descriptions[rand(0,count($descriptions)-1)]; |
297 | 297 | break; |
298 | - case 'title': |
|
298 | + case 'title': |
|
299 | 299 | $dummy_text = str_replace(array("\n",'.',',',"\t"),array(' ','','',' '),$dummy_text); |
300 | 300 | $titles = explode(" ",$dummy_text); |
301 | 301 | return trim($titles[rand(0,count($titles)-1)]); |
302 | 302 | break; |
303 | - case 'text': |
|
303 | + case 'text': |
|
304 | 304 | $texts = explode("\n",$dummy_text); |
305 | 305 | return $texts[rand(0,count($texts)-1)]; |
306 | 306 | break; |
@@ -11,13 +11,13 @@ |
||
11 | 11 | { |
12 | 12 | public $params = array(); |
13 | 13 | public $thematic_advance_list = array(); |
14 | - public $thematic_plan_list = array(); |
|
14 | + public $thematic_plan_list = array(); |
|
15 | 15 | |
16 | 16 | /** |
17 | - * Create a new Thematic |
|
18 | - * |
|
19 | - * @param array $params |
|
20 | - */ |
|
17 | + * Create a new Thematic |
|
18 | + * |
|
19 | + * @param array $params |
|
20 | + */ |
|
21 | 21 | public function __construct($params) |
22 | 22 | { |
23 | 23 | parent::__construct($params['id'], RESOURCE_THEMATIC); |
@@ -11,12 +11,12 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class CourseSelectForm |
13 | 13 | { |
14 | - /** |
|
15 | - * Display the form |
|
16 | - * @param array $hidden_fields Hidden fields to add to the form. |
|
17 | - * @param boolean the document array will be serialize. This is used in the course_copy.php file |
|
18 | - */ |
|
19 | - public static function display_form($course, $hidden_fields = null, $avoid_serialize = false) |
|
14 | + /** |
|
15 | + * Display the form |
|
16 | + * @param array $hidden_fields Hidden fields to add to the form. |
|
17 | + * @param boolean the document array will be serialize. This is used in the course_copy.php file |
|
18 | + */ |
|
19 | + public static function display_form($course, $hidden_fields = null, $avoid_serialize = false) |
|
20 | 20 | { |
21 | 21 | global $charset; |
22 | 22 | $resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook'); |
@@ -134,50 +134,50 @@ discard block |
||
134 | 134 | </script> |
135 | 135 | <?php |
136 | 136 | |
137 | - //get destination course title |
|
138 | - if (!empty($hidden_fields['destination_course'])) { |
|
137 | + //get destination course title |
|
138 | + if (!empty($hidden_fields['destination_course'])) { |
|
139 | 139 | $sessionTitle = !empty($hidden_fields['destination_session']) ? ' (' . api_get_session_name( |
140 | 140 | $hidden_fields['destination_session'] |
141 | 141 | ) . ')' : null; |
142 | 142 | |
143 | 143 | $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']); |
144 | - echo '<h3>'; |
|
145 | - echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle; |
|
146 | - echo '</h3>'; |
|
147 | - } |
|
144 | + echo '<h3>'; |
|
145 | + echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle; |
|
146 | + echo '</h3>'; |
|
147 | + } |
|
148 | 148 | echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>'; |
149 | - echo '<script type="text/javascript">var myUpload = new upload(1000);</script>'; |
|
149 | + echo '<script type="text/javascript">var myUpload = new upload(1000);</script>'; |
|
150 | 150 | $icon = Display::returnIconPath('myprogress_bar.gif'); |
151 | - echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">'; |
|
152 | - echo '<input type="hidden" name="action" value="course_select_form"/>'; |
|
151 | + echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">'; |
|
152 | + echo '<input type="hidden" name="action" value="course_select_form"/>'; |
|
153 | 153 | |
154 | - if (!empty($hidden_fields['destination_course']) && |
|
154 | + if (!empty($hidden_fields['destination_course']) && |
|
155 | 155 | !empty($hidden_fields['origin_course']) && |
156 | 156 | !empty($hidden_fields['destination_session']) && |
157 | 157 | !empty($hidden_fields['origin_session']) |
158 | 158 | ) { |
159 | - echo '<input type="hidden" name="destination_course" value="'.$hidden_fields['destination_course'].'"/>'; |
|
160 | - echo '<input type="hidden" name="origin_course" value="'.$hidden_fields['origin_course'].'"/>'; |
|
161 | - echo '<input type="hidden" name="destination_session" value="'.$hidden_fields['destination_session'].'"/>'; |
|
162 | - echo '<input type="hidden" name="origin_session" value="'.$hidden_fields['origin_session'].'"/>'; |
|
163 | - } |
|
159 | + echo '<input type="hidden" name="destination_course" value="'.$hidden_fields['destination_course'].'"/>'; |
|
160 | + echo '<input type="hidden" name="origin_course" value="'.$hidden_fields['origin_course'].'"/>'; |
|
161 | + echo '<input type="hidden" name="destination_session" value="'.$hidden_fields['destination_session'].'"/>'; |
|
162 | + echo '<input type="hidden" name="origin_session" value="'.$hidden_fields['origin_session'].'"/>'; |
|
163 | + } |
|
164 | 164 | |
165 | - $element_count = 0; |
|
165 | + $element_count = 0; |
|
166 | 166 | $forum_categories = array(); |
167 | 167 | $forums = array(); |
168 | 168 | $forum_topics = array(); |
169 | 169 | |
170 | 170 | echo '<p>'; |
171 | - echo get_lang('SelectResources'); |
|
172 | - echo '</p>'; |
|
171 | + echo get_lang('SelectResources'); |
|
172 | + echo '</p>'; |
|
173 | 173 | |
174 | 174 | Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt')); |
175 | 175 | |
176 | 176 | foreach ($course->resources as $type => $resources) { |
177 | 177 | if (count($resources) > 0) { |
178 | - switch ($type) { |
|
179 | - //Resources to avoid |
|
180 | - case RESOURCE_FORUMCATEGORY: |
|
178 | + switch ($type) { |
|
179 | + //Resources to avoid |
|
180 | + case RESOURCE_FORUMCATEGORY: |
|
181 | 181 | foreach ($resources as $id => $resource) { |
182 | 182 | $forum_categories[$id] = $resource; |
183 | 183 | } |
@@ -196,33 +196,33 @@ discard block |
||
196 | 196 | $element_count++; |
197 | 197 | break; |
198 | 198 | case RESOURCE_LINKCATEGORY: |
199 | - case RESOURCE_FORUMPOST: |
|
200 | - case RESOURCE_QUIZQUESTION: |
|
201 | - case RESOURCE_SURVEYQUESTION: |
|
202 | - case RESOURCE_SURVEYINVITATION: |
|
203 | - case RESOURCE_SCORM: |
|
204 | - break; |
|
199 | + case RESOURCE_FORUMPOST: |
|
200 | + case RESOURCE_QUIZQUESTION: |
|
201 | + case RESOURCE_SURVEYQUESTION: |
|
202 | + case RESOURCE_SURVEYINVITATION: |
|
203 | + case RESOURCE_SCORM: |
|
204 | + break; |
|
205 | 205 | default : |
206 | - echo '<img id="img_'.$type.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$type'".');" /> '; |
|
207 | - echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />'; |
|
208 | - echo '<div id="div_'.$type.'">'; |
|
209 | - if ($type == RESOURCE_LEARNPATH) { |
|
210 | - Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz')); |
|
211 | - Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments')); |
|
212 | - } |
|
213 | - if ($type == RESOURCE_DOCUMENT) { |
|
206 | + echo '<img id="img_'.$type.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$type'".');" /> '; |
|
207 | + echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />'; |
|
208 | + echo '<div id="div_'.$type.'">'; |
|
209 | + if ($type == RESOURCE_LEARNPATH) { |
|
210 | + Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz')); |
|
211 | + Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments')); |
|
212 | + } |
|
213 | + if ($type == RESOURCE_DOCUMENT) { |
|
214 | 214 | if (api_get_setting('show_glossary_in_documents') != 'none') { |
215 | 215 | Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary')); |
216 | 216 | } |
217 | - } |
|
217 | + } |
|
218 | 218 | |
219 | - echo '<blockquote>'; |
|
219 | + echo '<blockquote>'; |
|
220 | 220 | echo '<div class="btn-group">'; |
221 | - echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>"; |
|
221 | + echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>"; |
|
222 | 222 | echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>"; |
223 | - echo '</div><br />'; |
|
223 | + echo '</div><br />'; |
|
224 | 224 | |
225 | - foreach ($resources as $id => $resource) { |
|
225 | + foreach ($resources as $id => $resource) { |
|
226 | 226 | if ($resource) { |
227 | 227 | Coursecopy\Resource::setClassType($resource); |
228 | 228 | echo '<label class="checkbox">'; |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | $resource->show(); |
231 | 231 | echo '</label>'; |
232 | 232 | } |
233 | - } |
|
234 | - echo '</blockquote>'; |
|
235 | - echo '</div>'; |
|
236 | - echo '<script language="javascript">exp('."'$type'".')</script>'; |
|
237 | - $element_count++; |
|
233 | + } |
|
234 | + echo '</blockquote>'; |
|
235 | + echo '</div>'; |
|
236 | + echo '<script language="javascript">exp('."'$type'".')</script>'; |
|
237 | + $element_count++; |
|
238 | 238 | } |
239 | - } |
|
240 | - } |
|
239 | + } |
|
240 | + } |
|
241 | 241 | |
242 | 242 | //Fixes forum order |
243 | 243 | if (!empty($forum_categories)) { |
@@ -293,65 +293,65 @@ discard block |
||
293 | 293 | echo '<script language="javascript">exp('."'$type'".')</script>'; |
294 | 294 | } |
295 | 295 | |
296 | - if ($avoid_serialize) { |
|
297 | - /*Documents are avoided due the huge amount of memory that the serialize php function "eats" |
|
296 | + if ($avoid_serialize) { |
|
297 | + /*Documents are avoided due the huge amount of memory that the serialize php function "eats" |
|
298 | 298 | (when there are directories with hundred/thousand of files) */ |
299 | - // this is a known issue of serialize |
|
300 | - $course->resources['document']= null; |
|
301 | - } |
|
299 | + // this is a known issue of serialize |
|
300 | + $course->resources['document']= null; |
|
301 | + } |
|
302 | 302 | |
303 | - echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>'; |
|
303 | + echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>'; |
|
304 | 304 | |
305 | - if (is_array($hidden_fields)) { |
|
306 | - foreach ($hidden_fields as $key => $value) { |
|
307 | - echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'; |
|
308 | - } |
|
309 | - } |
|
305 | + if (is_array($hidden_fields)) { |
|
306 | + foreach ($hidden_fields as $key => $value) { |
|
307 | + echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'; |
|
308 | + } |
|
309 | + } |
|
310 | 310 | |
311 | 311 | $recycleOption = isset($_POST['recycle_option']) ? true : false; |
312 | 312 | |
313 | - if (empty($element_count)) { |
|
314 | - Display::display_warning_message(get_lang('NoDataAvailable')); |
|
315 | - } else { |
|
316 | - if (!empty($hidden_fields['destination_session'])) { |
|
317 | - echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'. |
|
313 | + if (empty($element_count)) { |
|
314 | + Display::display_warning_message(get_lang('NoDataAvailable')); |
|
315 | + } else { |
|
316 | + if (!empty($hidden_fields['destination_session'])) { |
|
317 | + echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'. |
|
318 | 318 | get_lang('Ok').'</button>'; |
319 | - } else { |
|
319 | + } else { |
|
320 | 320 | if ($recycleOption) { |
321 | 321 | echo '<br /><button class="save" type="submit">'. |
322 | 322 | get_lang('Ok').'</button>'; |
323 | 323 | } else { |
324 | - echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'. |
|
324 | + echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'. |
|
325 | 325 | get_lang('Ok').'</button>'; |
326 | 326 | } |
327 | - } |
|
328 | - } |
|
327 | + } |
|
328 | + } |
|
329 | 329 | |
330 | - CourseSelectForm :: display_hidden_quiz_questions($course); |
|
331 | - CourseSelectForm :: display_hidden_scorm_directories($course); |
|
332 | - echo '</form>'; |
|
333 | - echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>'; |
|
334 | - } |
|
330 | + CourseSelectForm :: display_hidden_quiz_questions($course); |
|
331 | + CourseSelectForm :: display_hidden_scorm_directories($course); |
|
332 | + echo '</form>'; |
|
333 | + echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>'; |
|
334 | + } |
|
335 | 335 | |
336 | 336 | /** |
337 | 337 | * @param $course |
338 | 338 | */ |
339 | 339 | static function display_hidden_quiz_questions($course) |
340 | 340 | { |
341 | - if(is_array($course->resources)){ |
|
342 | - foreach ($course->resources as $type => $resources) { |
|
343 | - if (count($resources) > 0) { |
|
344 | - switch ($type) { |
|
345 | - case RESOURCE_QUIZQUESTION: |
|
346 | - foreach ($resources as $id => $resource) { |
|
347 | - echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />'; |
|
348 | - } |
|
349 | - break; |
|
350 | - } |
|
351 | - } |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
341 | + if(is_array($course->resources)){ |
|
342 | + foreach ($course->resources as $type => $resources) { |
|
343 | + if (count($resources) > 0) { |
|
344 | + switch ($type) { |
|
345 | + case RESOURCE_QUIZQUESTION: |
|
346 | + foreach ($resources as $id => $resource) { |
|
347 | + echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />'; |
|
348 | + } |
|
349 | + break; |
|
350 | + } |
|
351 | + } |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * @param $course |
@@ -359,30 +359,30 @@ discard block |
||
359 | 359 | static function display_hidden_scorm_directories($course) |
360 | 360 | { |
361 | 361 | if (is_array($course->resources)){ |
362 | - foreach ($course->resources as $type => $resources) { |
|
363 | - if (count($resources) > 0) { |
|
364 | - switch($type) { |
|
365 | - case RESOURCE_SCORM: |
|
366 | - foreach ($resources as $id => $resource) { |
|
367 | - echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />'; |
|
368 | - } |
|
369 | - break; |
|
370 | - } |
|
371 | - } |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
362 | + foreach ($course->resources as $type => $resources) { |
|
363 | + if (count($resources) > 0) { |
|
364 | + switch($type) { |
|
365 | + case RESOURCE_SCORM: |
|
366 | + foreach ($resources as $id => $resource) { |
|
367 | + echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />'; |
|
368 | + } |
|
369 | + break; |
|
370 | + } |
|
371 | + } |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | 375 | |
376 | - /** |
|
377 | - * Get the posted course |
|
378 | - * @param string $from who calls the function? |
|
376 | + /** |
|
377 | + * Get the posted course |
|
378 | + * @param string $from who calls the function? |
|
379 | 379 | * It can be copy_course, create_backup, import_backup or recycle_course |
380 | 380 | * @param int $session_id |
381 | 381 | * @param string $course_code |
382 | - * @return course The course-object with all resources selected by the user |
|
383 | - * in the form given by display_form(...) |
|
384 | - */ |
|
385 | - public static function get_posted_course($from = '', $session_id = 0, $course_code = '') |
|
382 | + * @return course The course-object with all resources selected by the user |
|
383 | + * in the form given by display_form(...) |
|
384 | + */ |
|
385 | + public static function get_posted_course($from = '', $session_id = 0, $course_code = '') |
|
386 | 386 | { |
387 | 387 | $course = null; |
388 | 388 | |
@@ -392,30 +392,30 @@ discard block |
||
392 | 392 | return false; |
393 | 393 | } |
394 | 394 | |
395 | - // Create the resource DOCUMENT objects |
|
396 | - // Loading the results from the checkboxes of ethe javascript |
|
397 | - $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; |
|
395 | + // Create the resource DOCUMENT objects |
|
396 | + // Loading the results from the checkboxes of ethe javascript |
|
397 | + $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; |
|
398 | 398 | |
399 | - $course_info = api_get_course_info($course_code); |
|
400 | - $table_doc = Database::get_course_table(TABLE_DOCUMENT); |
|
401 | - $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
402 | - $course_id = $course_info['real_id']; |
|
399 | + $course_info = api_get_course_info($course_code); |
|
400 | + $table_doc = Database::get_course_table(TABLE_DOCUMENT); |
|
401 | + $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); |
|
402 | + $course_id = $course_info['real_id']; |
|
403 | 403 | |
404 | - /* Searching the documents resource that have been set to null because |
|
404 | + /* Searching the documents resource that have been set to null because |
|
405 | 405 | $avoid_serialize is true in the display_form() function*/ |
406 | - if ($from == 'copy_course') { |
|
407 | - if (is_array($resource)) { |
|
408 | - $resource = array_keys($resource); |
|
406 | + if ($from == 'copy_course') { |
|
407 | + if (is_array($resource)) { |
|
408 | + $resource = array_keys($resource); |
|
409 | 409 | |
410 | - foreach ($resource as $resource_item) { |
|
410 | + foreach ($resource as $resource_item) { |
|
411 | 411 | |
412 | - $condition_session = ''; |
|
413 | - if (!empty($session_id)) { |
|
414 | - $session_id = intval($session_id); |
|
415 | - $condition_session = ' AND d.session_id ='.$session_id; |
|
416 | - } |
|
412 | + $condition_session = ''; |
|
413 | + if (!empty($session_id)) { |
|
414 | + $session_id = intval($session_id); |
|
415 | + $condition_session = ' AND d.session_id ='.$session_id; |
|
416 | + } |
|
417 | 417 | |
418 | - $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size |
|
418 | + $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size |
|
419 | 419 | FROM '.$table_doc.' d, '.$table_prop.' p |
420 | 420 | WHERE |
421 | 421 | d.c_id = '.$course_id.' AND |
@@ -424,8 +424,8 @@ discard block |
||
424 | 424 | p.ref = d.id AND p.visibility != 2 AND |
425 | 425 | d.id = '.$resource_item.$condition_session.' |
426 | 426 | ORDER BY path'; |
427 | - $db_result = Database::query($sql); |
|
428 | - while ($obj = Database::fetch_object($db_result)) { |
|
427 | + $db_result = Database::query($sql); |
|
428 | + while ($obj = Database::fetch_object($db_result)) { |
|
429 | 429 | $doc = new Document( |
430 | 430 | $obj->id, |
431 | 431 | $obj->path, |
@@ -449,25 +449,25 @@ discard block |
||
449 | 449 | } |
450 | 450 | $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties; |
451 | 451 | } |
452 | - } |
|
453 | - } |
|
454 | - } |
|
455 | - } |
|
452 | + } |
|
453 | + } |
|
454 | + } |
|
455 | + } |
|
456 | 456 | |
457 | - if (is_array($course->resources)) { |
|
458 | - foreach ($course->resources as $type => $resources) { |
|
457 | + if (is_array($course->resources)) { |
|
458 | + foreach ($course->resources as $type => $resources) { |
|
459 | 459 | |
460 | - switch ($type) { |
|
461 | - case RESOURCE_SURVEYQUESTION: |
|
462 | - foreach($resources as $id => $obj) { |
|
463 | - if (isset($_POST['resource'][RESOURCE_SURVEY]) && |
|
460 | + switch ($type) { |
|
461 | + case RESOURCE_SURVEYQUESTION: |
|
462 | + foreach($resources as $id => $obj) { |
|
463 | + if (isset($_POST['resource'][RESOURCE_SURVEY]) && |
|
464 | 464 | is_array($_POST['resource'][RESOURCE_SURVEY]) && |
465 | 465 | !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY])) |
466 | 466 | ) { |
467 | - unset($course->resources[$type][$id]); |
|
468 | - } |
|
469 | - } |
|
470 | - break; |
|
467 | + unset($course->resources[$type][$id]); |
|
468 | + } |
|
469 | + } |
|
470 | + break; |
|
471 | 471 | case RESOURCE_FORUMTOPIC: |
472 | 472 | case RESOURCE_FORUMPOST: |
473 | 473 | //Add post from topic |
@@ -519,62 +519,62 @@ discard block |
||
519 | 519 | } |
520 | 520 | } |
521 | 521 | } |
522 | - case RESOURCE_LINKCATEGORY : |
|
523 | - case RESOURCE_FORUMCATEGORY : |
|
524 | - case RESOURCE_QUIZQUESTION : |
|
525 | - case RESOURCE_DOCUMENT: |
|
526 | - // Mark folders to import which are not selected by the user to import, |
|
527 | - // but in which a document was selected. |
|
528 | - $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; |
|
529 | - if (!empty($resources) && is_array($resources)) |
|
530 | - foreach ($resources as $id => $obj) { |
|
531 | - if (isset($obj->file_type) && $obj->file_type == 'folder' && |
|
522 | + case RESOURCE_LINKCATEGORY : |
|
523 | + case RESOURCE_FORUMCATEGORY : |
|
524 | + case RESOURCE_QUIZQUESTION : |
|
525 | + case RESOURCE_DOCUMENT: |
|
526 | + // Mark folders to import which are not selected by the user to import, |
|
527 | + // but in which a document was selected. |
|
528 | + $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; |
|
529 | + if (!empty($resources) && is_array($resources)) |
|
530 | + foreach ($resources as $id => $obj) { |
|
531 | + if (isset($obj->file_type) && $obj->file_type == 'folder' && |
|
532 | 532 | !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) && |
533 | 533 | is_array($documents) |
534 | 534 | ) { |
535 | - foreach ($documents as $id_to_check => $post_value) { |
|
536 | - $obj_to_check = $resources[$id_to_check]; |
|
537 | - $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path)); |
|
538 | - if ($id_to_check != $id && $obj->path == $shared_path_part) { |
|
539 | - $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1; |
|
540 | - break; |
|
541 | - } |
|
542 | - } |
|
543 | - } |
|
544 | - } |
|
545 | - default : |
|
546 | - if (!empty($resources) && is_array($resources)) { |
|
547 | - foreach ($resources as $id => $obj) { |
|
548 | - $resource_is_used_elsewhere = $course->is_linked_resource($obj); |
|
549 | - // check if document is in a quiz (audio/video) |
|
550 | - if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) { |
|
551 | - foreach($course->resources[RESOURCE_QUIZ] as $quiz) { |
|
535 | + foreach ($documents as $id_to_check => $post_value) { |
|
536 | + $obj_to_check = $resources[$id_to_check]; |
|
537 | + $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path)); |
|
538 | + if ($id_to_check != $id && $obj->path == $shared_path_part) { |
|
539 | + $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1; |
|
540 | + break; |
|
541 | + } |
|
542 | + } |
|
543 | + } |
|
544 | + } |
|
545 | + default : |
|
546 | + if (!empty($resources) && is_array($resources)) { |
|
547 | + foreach ($resources as $id => $obj) { |
|
548 | + $resource_is_used_elsewhere = $course->is_linked_resource($obj); |
|
549 | + // check if document is in a quiz (audio/video) |
|
550 | + if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) { |
|
551 | + foreach($course->resources[RESOURCE_QUIZ] as $quiz) { |
|
552 | 552 | $quiz = $quiz->obj; |
553 | - if (isset($quiz->media) && $quiz->media == $id) { |
|
554 | - $resource_is_used_elsewhere = true; |
|
555 | - } |
|
556 | - } |
|
557 | - } |
|
558 | - if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) { |
|
559 | - unset($course->resources[$type][$id]); |
|
560 | - } |
|
561 | - } |
|
562 | - } |
|
563 | - } |
|
564 | - } |
|
565 | - } |
|
566 | - |
|
567 | - return $course; |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Display the form session export |
|
572 | - * @param array $hidden_fields Hidden fields to add to the form. |
|
573 | - * @param boolean the document array will be serialize. This is used in the course_copy.php file |
|
574 | - */ |
|
575 | - public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false) |
|
576 | - { |
|
577 | - ?> |
|
553 | + if (isset($quiz->media) && $quiz->media == $id) { |
|
554 | + $resource_is_used_elsewhere = true; |
|
555 | + } |
|
556 | + } |
|
557 | + } |
|
558 | + if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) { |
|
559 | + unset($course->resources[$type][$id]); |
|
560 | + } |
|
561 | + } |
|
562 | + } |
|
563 | + } |
|
564 | + } |
|
565 | + } |
|
566 | + |
|
567 | + return $course; |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Display the form session export |
|
572 | + * @param array $hidden_fields Hidden fields to add to the form. |
|
573 | + * @param boolean the document array will be serialize. This is used in the course_copy.php file |
|
574 | + */ |
|
575 | + public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false) |
|
576 | + { |
|
577 | + ?> |
|
578 | 578 | <script> |
579 | 579 | function exp(item) { |
580 | 580 | el = document.getElementById('div_'+item); |
@@ -616,65 +616,65 @@ discard block |
||
616 | 616 | </script> |
617 | 617 | <?php |
618 | 618 | |
619 | - //get destination course title |
|
620 | - if(!empty($hidden_fields['destination_course'])) { |
|
621 | - if (!empty($hidden_fields['destination_session'])) { |
|
622 | - $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')'; |
|
623 | - } else { |
|
624 | - $sessionTitle = null; |
|
625 | - } |
|
619 | + //get destination course title |
|
620 | + if(!empty($hidden_fields['destination_course'])) { |
|
621 | + if (!empty($hidden_fields['destination_session'])) { |
|
622 | + $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')'; |
|
623 | + } else { |
|
624 | + $sessionTitle = null; |
|
625 | + } |
|
626 | 626 | $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']); |
627 | - echo '<h3>'; |
|
628 | - echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle; |
|
629 | - echo '</h3>'; |
|
630 | - } |
|
627 | + echo '<h3>'; |
|
628 | + echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle; |
|
629 | + echo '</h3>'; |
|
630 | + } |
|
631 | 631 | |
632 | - echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>'; |
|
633 | - echo '<script type="text/javascript">var myUpload = new upload(1000);</script>'; |
|
632 | + echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>'; |
|
633 | + echo '<script type="text/javascript">var myUpload = new upload(1000);</script>'; |
|
634 | 634 | $icon = Display::returnIconPath('progress_bar.gif'); |
635 | - echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">'; |
|
636 | - echo '<input type="hidden" name="action" value="course_select_form"/>'; |
|
637 | - foreach ($list_course as $course){ |
|
638 | - foreach ($course->resources as $type => $resources) { |
|
639 | - if (count($resources) > 0) { |
|
640 | - echo '<img id="img_'.$course->code.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$course->code'".');" />'; |
|
641 | - echo '<b onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />'; |
|
642 | - echo '<div id="div_'.$course->code.'">'; |
|
643 | - echo '<blockquote>'; |
|
635 | + echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">'; |
|
636 | + echo '<input type="hidden" name="action" value="course_select_form"/>'; |
|
637 | + foreach ($list_course as $course){ |
|
638 | + foreach ($course->resources as $type => $resources) { |
|
639 | + if (count($resources) > 0) { |
|
640 | + echo '<img id="img_'.$course->code.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$course->code'".');" />'; |
|
641 | + echo '<b onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />'; |
|
642 | + echo '<div id="div_'.$course->code.'">'; |
|
643 | + echo '<blockquote>'; |
|
644 | 644 | |
645 | 645 | echo '<div class="btn-group">'; |
646 | - echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>"; |
|
646 | + echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>"; |
|
647 | 647 | echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',false);\" >".get_lang('None')."</a>"; |
648 | - echo '</div><br />'; |
|
648 | + echo '</div><br />'; |
|
649 | 649 | |
650 | - foreach ($resources as $id => $resource) { |
|
651 | - echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">'; |
|
650 | + foreach ($resources as $id => $resource) { |
|
651 | + echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">'; |
|
652 | 652 | echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>'; |
653 | - $resource->show(); |
|
654 | - echo '</label>'; |
|
655 | - } |
|
656 | - echo '</blockquote>'; |
|
657 | - echo '</div>'; |
|
658 | - echo '<script type="text/javascript">exp('."'$course->code'".')</script>'; |
|
659 | - } |
|
660 | - } |
|
661 | - } |
|
662 | - if ($avoid_serialize) { |
|
663 | - //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files) |
|
664 | - // this is a known issue of serialize |
|
665 | - $course->resources['document']= null; |
|
666 | - } |
|
667 | - echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>'; |
|
668 | - if (is_array($hidden_fields)) { |
|
669 | - foreach ($hidden_fields as $key => $value) { |
|
670 | - echo "\n"; |
|
671 | - echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'; |
|
672 | - } |
|
673 | - } |
|
674 | - echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>'; |
|
675 | - CourseSelectForm :: display_hidden_quiz_questions($course); |
|
676 | - CourseSelectForm :: display_hidden_scorm_directories($course); |
|
677 | - echo '</form>'; |
|
678 | - echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>'; |
|
679 | - } |
|
653 | + $resource->show(); |
|
654 | + echo '</label>'; |
|
655 | + } |
|
656 | + echo '</blockquote>'; |
|
657 | + echo '</div>'; |
|
658 | + echo '<script type="text/javascript">exp('."'$course->code'".')</script>'; |
|
659 | + } |
|
660 | + } |
|
661 | + } |
|
662 | + if ($avoid_serialize) { |
|
663 | + //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files) |
|
664 | + // this is a known issue of serialize |
|
665 | + $course->resources['document']= null; |
|
666 | + } |
|
667 | + echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>'; |
|
668 | + if (is_array($hidden_fields)) { |
|
669 | + foreach ($hidden_fields as $key => $value) { |
|
670 | + echo "\n"; |
|
671 | + echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>'; |
|
672 | + } |
|
673 | + } |
|
674 | + echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>'; |
|
675 | + CourseSelectForm :: display_hidden_quiz_questions($course); |
|
676 | + CourseSelectForm :: display_hidden_scorm_directories($course); |
|
677 | + echo '</form>'; |
|
678 | + echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>'; |
|
679 | + } |
|
680 | 680 | } |