Passed
Push — 1.10.x ( b77fe8...f38c8d )
by
unknown
133:09 queued 81:28
created
main/coursecopy/classes/CourseRestorer.class.php 2 patches
Doc Comments   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
     /**
86 86
      * CourseRestorer constructor.
87
-     * @param array $course
87
+     * @param Course $course
88 88
      */
89 89
     public function __construct($course)
90 90
     {
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 * @param int	    $session_id
134 134
 	 * @param bool	    $update_course_settings Course settings are going to be restore?
135 135
      * @param bool      $respect_base_content
136
-     * @return bool
136
+     * @return false|null
137 137
 	 */
138 138
     public function restore(
139 139
         $destination_course_code = '',
@@ -1154,6 +1154,7 @@  discard block
 block discarded – undo
1154 1154
 
1155 1155
 	/**
1156 1156
 	 * Restore a forum-topic
1157
+	 * @param false|string $forum_id
1157 1158
 	 */
1158 1159
     public function restore_topic($thread_id, $forum_id, $sessionId = 0)
1159 1160
     {
@@ -1210,6 +1211,7 @@  discard block
 block discarded – undo
1210 1211
 	/**
1211 1212
 	 * Restore a forum-post
1212 1213
 	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214
+	 * @param false|string $topic_id
1213 1215
 	 */
1214 1216
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1215 1217
     {
@@ -2307,6 +2309,7 @@  discard block
 block discarded – undo
2307 2309
 
2308 2310
 	/**
2309 2311
 	 * Check availability of a survey code
2312
+	 * @param string $survey_code
2310 2313
 	 */
2311 2314
     public function is_survey_code_available($survey_code)
2312 2315
     {
@@ -2321,6 +2324,7 @@  discard block
 block discarded – undo
2321 2324
 
2322 2325
 	/**
2323 2326
 	 * Restore survey-questions
2327
+	 * @param string $survey_id
2324 2328
 	 */
2325 2329
     public function restore_survey_question($id, $survey_id)
2326 2330
     {
@@ -2777,6 +2781,8 @@  discard block
 block discarded – undo
2777 2781
     * @param string The path origin
2778 2782
     * @param string The path destination
2779 2783
     * @param boolean Option Overwrite
2784
+    * @param string $source
2785
+    * @param string $dest
2780 2786
     * @return void()
2781 2787
     * @deprecated
2782 2788
     */
Please login to merge, or discard this patch.
Indentation   +713 added lines, -713 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 bool
137
-	 */
137
+     */
138 138
     public function restore(
139 139
         $destination_course_code = '',
140 140
         $session_id = 0,
@@ -277,17 +277,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,15 +1150,15 @@  discard block
 block discarded – undo
1150 1150
                 }
1151 1151
             }
1152 1152
         }
1153
-	}
1153
+    }
1154 1154
 
1155
-	/**
1156
-	 * Restore a forum-topic
1157
-	 */
1155
+    /**
1156
+     * Restore a forum-topic
1157
+     */
1158 1158
     public function restore_topic($thread_id, $forum_id, $sessionId = 0)
1159 1159
     {
1160
-		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
1161
-		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1160
+        $table = Database :: get_course_table(TABLE_FORUM_THREAD);
1161
+        $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1162 1162
 
1163 1163
         $params = (array)$topic->obj;
1164 1164
         $params = self::DBUTF8_array($params);
@@ -1194,27 +1194,27 @@  discard block
 block discarded – undo
1194 1194
             $sessionId
1195 1195
         );
1196 1196
 
1197
-		$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1197
+        $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1198 1198
 
1199
-		$topic_replies = -1;
1199
+        $topic_replies = -1;
1200 1200
 
1201
-		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1202
-			if ($post->obj->thread_id == $thread_id) {
1203
-				$topic_replies++;
1204
-				$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1205
-			}
1206
-		}
1207
-		return $new_id;
1208
-	}
1201
+        foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1202
+            if ($post->obj->thread_id == $thread_id) {
1203
+                $topic_replies++;
1204
+                $this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1205
+            }
1206
+        }
1207
+        return $new_id;
1208
+    }
1209 1209
 
1210
-	/**
1211
-	 * Restore a forum-post
1212
-	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1213
-	 */
1210
+    /**
1211
+     * Restore a forum-post
1212
+     * @TODO Restore tree-structure of posts. For example: attachments to posts.
1213
+     */
1214 1214
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1215 1215
     {
1216
-		$table_post = Database :: get_course_table(TABLE_FORUM_POST);
1217
-		$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1216
+        $table_post = Database :: get_course_table(TABLE_FORUM_POST);
1217
+        $post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1218 1218
         $params = (array) $post->obj;
1219 1219
         $params['c_id'] = $this->destination_course_id;
1220 1220
         $params['forum_id'] = $forum_id;
@@ -1249,37 +1249,37 @@  discard block
 block discarded – undo
1249 1249
             null,
1250 1250
             $sessionId
1251 1251
         );
1252
-		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1252
+        $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1253 1253
 
1254
-		return $new_id;
1255
-	}
1254
+        return $new_id;
1255
+    }
1256 1256
 
1257
-	/**
1258
-	 * Restore links
1259
-	 */
1257
+    /**
1258
+     * Restore links
1259
+     */
1260 1260
     public function restore_links($session_id = 0)
1261 1261
     {
1262
-		if ($this->course->has_resources(RESOURCE_LINK)) {
1263
-			$link_table = Database :: get_course_table(TABLE_LINK);
1264
-			$resources = $this->course->resources;
1262
+        if ($this->course->has_resources(RESOURCE_LINK)) {
1263
+            $link_table = Database :: get_course_table(TABLE_LINK);
1264
+            $resources = $this->course->resources;
1265 1265
 
1266
-			foreach ($resources[RESOURCE_LINK] as $id => $link) {
1266
+            foreach ($resources[RESOURCE_LINK] as $id => $link) {
1267 1267
                 $cat_id = $this->restore_link_category(
1268 1268
                     $link->category_id,
1269 1269
                     $session_id
1270 1270
                 );
1271
-				$sql = "SELECT MAX(display_order)
1271
+                $sql = "SELECT MAX(display_order)
1272 1272
 				        FROM $link_table
1273 1273
 				        WHERE
1274 1274
 				            c_id = ".$this->destination_course_id." AND
1275 1275
 				            category_id='" . intval($cat_id). "'";
1276
-				$result = Database::query($sql);
1277
-    			list($max_order) = Database::fetch_array($result);
1276
+                $result = Database::query($sql);
1277
+                list($max_order) = Database::fetch_array($result);
1278 1278
 
1279 1279
                 $params = [];
1280
-    			if (!empty($session_id)) {
1280
+                if (!empty($session_id)) {
1281 1281
                     $params['session_id'] = $session_id;
1282
-    			}
1282
+                }
1283 1283
 
1284 1284
                 $params['c_id'] = $this->destination_course_id;
1285 1285
                 $params['url'] = self::DBUTF8($link->url);
@@ -1308,9 +1308,9 @@  discard block
 block discarded – undo
1308 1308
                     }
1309 1309
                     $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id;
1310 1310
                 }
1311
-			}
1312
-		}
1313
-	}
1311
+            }
1312
+        }
1313
+    }
1314 1314
 
1315 1315
     /**
1316 1316
      * Restore a link-category
@@ -1354,21 +1354,21 @@  discard block
 block discarded – undo
1354 1354
         return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id;
1355 1355
     }
1356 1356
 
1357
-	/**
1358
-	 * Restore tool intro
1359
-	 */
1357
+    /**
1358
+     * Restore tool intro
1359
+     */
1360 1360
     public function restore_tool_intro($sessionId = 0)
1361 1361
     {
1362
-		if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1362
+        if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1363 1363
             $sessionId = intval($sessionId);
1364
-			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1365
-			$resources = $this->course->resources;
1366
-			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1367
-				$sql = "DELETE FROM ".$tool_intro_table."
1364
+            $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1365
+            $resources = $this->course->resources;
1366
+            foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1367
+                $sql = "DELETE FROM ".$tool_intro_table."
1368 1368
 				        WHERE
1369 1369
 				            c_id = ".$this->destination_course_id." AND
1370 1370
 				            id='".self::DBUTF8escapestring($tool_intro->id)."'";
1371
-				Database::query($sql);
1371
+                Database::query($sql);
1372 1372
 
1373 1373
                 $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1374 1374
                     $tool_intro->intro_text,
@@ -1396,21 +1396,21 @@  discard block
 block discarded – undo
1396 1396
 
1397 1397
                     $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id;
1398 1398
                 }
1399
-			}
1400
-		}
1401
-	}
1399
+            }
1400
+        }
1401
+    }
1402 1402
 
1403
-	/**
1404
-	 * Restore events
1405
-	 */
1403
+    /**
1404
+     * Restore events
1405
+     */
1406 1406
     public function restore_events($sessionId = 0)
1407 1407
     {
1408
-		if ($this->course->has_resources(RESOURCE_EVENT)) {
1408
+        if ($this->course->has_resources(RESOURCE_EVENT)) {
1409 1409
             $sessionId = intval($sessionId);
1410
-			$table = Database :: get_course_table(TABLE_AGENDA);
1411
-			$resources = $this->course->resources;
1412
-			foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1413
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1410
+            $table = Database :: get_course_table(TABLE_AGENDA);
1411
+            $resources = $this->course->resources;
1412
+            foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1413
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1414 1414
                 $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1415 1415
                     $event->content,
1416 1416
                     $this->course->code,
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
                     'end_date' => $event->end_date,
1429 1429
                     'session_id' => $sessionId,
1430 1430
                 ];
1431
-				$new_event_id = Database::insert($table, $params);
1431
+                $new_event_id = Database::insert($table, $params);
1432 1432
 
1433 1433
                 if ($new_event_id) {
1434 1434
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id";
@@ -1441,30 +1441,30 @@  discard block
 block discarded – undo
1441 1441
                     $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
1442 1442
                 }
1443 1443
 
1444
-				// Copy event attachment
1444
+                // Copy event attachment
1445 1445
 
1446
-				$origin_path = $this->course->backup_path.'/upload/calendar/';
1447
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1446
+                $origin_path = $this->course->backup_path.'/upload/calendar/';
1447
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1448 1448
 
1449
-				if (!empty($this->course->orig)) {
1449
+                if (!empty($this->course->orig)) {
1450 1450
 
1451
-					$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1452
-					$sql = 'SELECT path, comment, size, filename
1451
+                    $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1452
+                    $sql = 'SELECT path, comment, size, filename
1453 1453
 					        FROM '.$table_attachment.'
1454 1454
 					        WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
1455
-					$attachment_event = Database::query($sql);
1456
-					$attachment_event = Database::fetch_object($attachment_event);
1455
+                    $attachment_event = Database::query($sql);
1456
+                    $attachment_event = Database::fetch_object($attachment_event);
1457 1457
 
1458
-					if (file_exists($origin_path.$attachment_event->path) &&
1458
+                    if (file_exists($origin_path.$attachment_event->path) &&
1459 1459
                         !is_dir($origin_path.$attachment_event->path)
1460 1460
                     ) {
1461
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1462
-						$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1463
-						//$copy_result = true;
1464
-						if ($copy_result) {
1465
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1461
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1462
+                        $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1463
+                        //$copy_result = true;
1464
+                        if ($copy_result) {
1465
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1466 1466
 
1467
-							$params = [
1467
+                            $params = [
1468 1468
                                 'c_id' => $this->destination_course_id,
1469 1469
                                 'path' => self::DBUTF8($new_filename),
1470 1470
                                 'comment' => self::DBUTF8($attachment_event->comment),
@@ -1478,17 +1478,17 @@  discard block
 block discarded – undo
1478 1478
                                 Database::query($sql);
1479 1479
                             }
1480 1480
                         }
1481
-					}
1482
-				} else {
1483
-					// get the info of the file
1484
-					if (!empty($event->attachment_path) &&
1481
+                    }
1482
+                } else {
1483
+                    // get the info of the file
1484
+                    if (!empty($event->attachment_path) &&
1485 1485
                         is_file($origin_path.$event->attachment_path) &&
1486 1486
                         is_readable($origin_path.$event->attachment_path)
1487 1487
                     ) {
1488
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1489
-						$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1490
-						if ($copy_result) {
1491
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1488
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1489
+                        $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1490
+                        if ($copy_result) {
1491
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1492 1492
 
1493 1493
                             $params = [
1494 1494
                                 'c_id' => $this->destination_course_id,
@@ -1504,29 +1504,29 @@  discard block
 block discarded – undo
1504 1504
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id";
1505 1505
                                 Database::query($sql);
1506 1506
                             }
1507
-						}
1508
-					}
1509
-				}
1510
-			}
1511
-		}
1512
-	}
1513
-
1514
-	/**
1515
-	 * Restore course-description
1516
-	 */
1507
+                        }
1508
+                    }
1509
+                }
1510
+            }
1511
+        }
1512
+    }
1513
+
1514
+    /**
1515
+     * Restore course-description
1516
+     */
1517 1517
     public function restore_course_descriptions($session_id = 0)
1518 1518
     {
1519
-		if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1520
-			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1521
-			$resources = $this->course->resources;
1522
-			foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1519
+        if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1520
+            $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1521
+            $resources = $this->course->resources;
1522
+            foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1523 1523
                 $courseDescription = (array) $cd;
1524 1524
 
1525 1525
                 $content = isset($courseDescription['content']) ? $courseDescription['content'] : '';
1526 1526
                 $descriptionType = isset($courseDescription['description_type']) ? $courseDescription['description_type'] : '';
1527 1527
                 $title = isset($courseDescription['title']) ? $courseDescription['title'] : '';
1528 1528
 
1529
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1529
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1530 1530
                 $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1531 1531
                     $content,
1532 1532
                     $this->course->code,
@@ -1536,10 +1536,10 @@  discard block
 block discarded – undo
1536 1536
                 );
1537 1537
 
1538 1538
                 $params = [];
1539
-				if (!empty($session_id)) {
1540
-					$session_id = intval($session_id);
1539
+                if (!empty($session_id)) {
1540
+                    $session_id = intval($session_id);
1541 1541
                     $params['session_id'] = $session_id;
1542
-				}
1542
+                }
1543 1543
                 $params['c_id'] = $this->destination_course_id;
1544 1544
                 $params['description_type'] = self::DBUTF8($descriptionType);
1545 1545
                 $params['title'] = self::DBUTF8($title);
@@ -1555,22 +1555,22 @@  discard block
 block discarded – undo
1555 1555
                     }
1556 1556
                     $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id;
1557 1557
                 }
1558
-			}
1559
-		}
1560
-	}
1558
+            }
1559
+        }
1560
+    }
1561 1561
 
1562
-	/**
1563
-	 * Restore announcements
1564
-	 */
1562
+    /**
1563
+     * Restore announcements
1564
+     */
1565 1565
     public function restore_announcements($sessionId = 0)
1566 1566
     {
1567
-		if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1567
+        if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1568 1568
             $sessionId = intval($sessionId);
1569
-			$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1570
-			$resources = $this->course->resources;
1571
-			foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1569
+            $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1570
+            $resources = $this->course->resources;
1571
+            foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1572 1572
 
1573
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1573
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1574 1574
                 $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1575 1575
                     $announcement->content,
1576 1576
                     $this->course->code,
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
                     'session_id' => $sessionId,
1590 1590
                 ];
1591 1591
 
1592
-				$new_announcement_id = Database::insert($table, $params);
1592
+                $new_announcement_id = Database::insert($table, $params);
1593 1593
 
1594 1594
                 if ($new_announcement_id) {
1595 1595
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id";
@@ -1601,32 +1601,32 @@  discard block
 block discarded – undo
1601 1601
                     $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id;
1602 1602
                 }
1603 1603
 
1604
-				$origin_path = $this->course->backup_path.'/upload/announcements/';
1605
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1604
+                $origin_path = $this->course->backup_path.'/upload/announcements/';
1605
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1606 1606
 
1607
-				// Copy announcement attachment file
1608
-				if (!empty($this->course->orig)) {
1607
+                // Copy announcement attachment file
1608
+                if (!empty($this->course->orig)) {
1609 1609
 
1610
-					$table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1611
-					$sql = 'SELECT path, comment, size, filename
1610
+                    $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1611
+                    $sql = 'SELECT path, comment, size, filename
1612 1612
 					        FROM '.$table_attachment.'
1613 1613
 					        WHERE
1614 1614
 					            c_id = '.$this->destination_course_id.' AND
1615 1615
 					            announcement_id = '.$id;
1616
-					$attachment_event = Database::query($sql);
1617
-					$attachment_event = Database::fetch_object($attachment_event);
1616
+                    $attachment_event = Database::query($sql);
1617
+                    $attachment_event = Database::fetch_object($attachment_event);
1618 1618
 
1619
-					if (file_exists($origin_path.$attachment_event->path) &&
1619
+                    if (file_exists($origin_path.$attachment_event->path) &&
1620 1620
                         !is_dir($origin_path.$attachment_event->path)
1621 1621
                     ) {
1622
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1622
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1623 1623
                         $copy_result = copy(
1624 1624
                             $origin_path.$attachment_event->path,
1625 1625
                             $destination_path.$new_filename
1626 1626
                         );
1627 1627
 
1628
-						if ($copy_result) {
1629
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1628
+                        if ($copy_result) {
1629
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1630 1630
 
1631 1631
                             $params = [
1632 1632
                                 'c_id' => $this->destination_course_id,
@@ -1643,20 +1643,20 @@  discard block
 block discarded – undo
1643 1643
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1644 1644
                                 Database::query($sql);
1645 1645
                             }
1646
-						}
1647
-					}
1648
-				} else {
1649
-					// get the info of the file
1650
-					if (!empty($announcement->attachment_path) &&
1646
+                        }
1647
+                    }
1648
+                } else {
1649
+                    // get the info of the file
1650
+                    if (!empty($announcement->attachment_path) &&
1651 1651
                         is_file($origin_path.$announcement->attachment_path) &&
1652 1652
                         is_readable($origin_path.$announcement->attachment_path)
1653 1653
                     ) {
1654
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1655
-						$copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1654
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1655
+                        $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1656 1656
 
1657
-						if ($copy_result) {
1658
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1659
-							/*$sql = "INSERT INTO ".$table_attachment." SET
1657
+                        if ($copy_result) {
1658
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1659
+                            /*$sql = "INSERT INTO ".$table_attachment." SET
1660 1660
 							        c_id = ".$this->destination_course_id." ,
1661 1661
 							        path = '".self::DBUTF8escapestring($new_filename)."',
1662 1662
 							        comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."',
@@ -1679,12 +1679,12 @@  discard block
 block discarded – undo
1679 1679
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1680 1680
                                 Database::query($sql);
1681 1681
                             }
1682
-						}
1683
-					}
1684
-				}
1685
-			}
1686
-		}
1687
-	}
1682
+                        }
1683
+                    }
1684
+                }
1685
+            }
1686
+        }
1687
+    }
1688 1688
 
1689 1689
     /**
1690 1690
      * Restore Quiz
@@ -1695,13 +1695,13 @@  discard block
 block discarded – undo
1695 1695
         $session_id = 0,
1696 1696
         $respect_base_content = false
1697 1697
     ) {
1698
-		if ($this->course->has_resources(RESOURCE_QUIZ)) {
1699
-			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1700
-			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1701
-			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1702
-			$resources = $this->course->resources;
1698
+        if ($this->course->has_resources(RESOURCE_QUIZ)) {
1699
+            $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1700
+            $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1701
+            $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1702
+            $resources = $this->course->resources;
1703 1703
 
1704
-			foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1704
+            foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1705 1705
 
1706 1706
                 if (isset($quiz->obj)) {
1707 1707
                     //For new imports
@@ -1711,7 +1711,7 @@  discard block
 block discarded – undo
1711 1711
                     $quiz->obj = $quiz;
1712 1712
                 }
1713 1713
 
1714
-				$doc = '';
1714
+                $doc = '';
1715 1715
                 if (!empty($quiz->sound)) {
1716 1716
                     if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
1717 1717
                         $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
@@ -1719,14 +1719,14 @@  discard block
 block discarded – undo
1719 1719
                                 WHERE
1720 1720
                                     c_id = " . $this->destination_course_id . "  AND
1721 1721
                                     id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
1722
-						$doc = Database::query($sql);
1723
-						$doc = Database::fetch_object($doc);
1724
-						$doc = str_replace('/audio/', '', $doc->path);
1725
-					}
1726
-				}
1727
-
1728
-				if ($id != -1) {
1729
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1722
+                        $doc = Database::query($sql);
1723
+                        $doc = Database::fetch_object($doc);
1724
+                        $doc = str_replace('/audio/', '', $doc->path);
1725
+                    }
1726
+                }
1727
+
1728
+                if ($id != -1) {
1729
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1730 1730
                     $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1731 1731
                         $quiz->description,
1732 1732
                         $this->course->code,
@@ -1735,13 +1735,13 @@  discard block
 block discarded – undo
1735 1735
                         $this->course->info['path']
1736 1736
                     );
1737 1737
 
1738
-					global $_custom;
1739
-					if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1738
+                    global $_custom;
1739
+                    if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1740 1740
                         $_custom['exercises_clean_dates_when_restoring']
1741 1741
                     ) {
1742
-						$quiz->start_time = null;
1743
-						$quiz->end_time   = null;
1744
-					}
1742
+                        $quiz->start_time = null;
1743
+                        $quiz->end_time   = null;
1744
+                    }
1745 1745
 
1746 1746
                     $params = array(
1747 1747
                         'c_id' => $this->destination_course_id,
@@ -1773,10 +1773,10 @@  discard block
 block discarded – undo
1773 1773
                         }
1774 1774
                         $params['session_id'] = $my_session_id;
1775 1775
                     } else {
1776
-        				if (!empty($session_id)) {
1777
-        					$session_id = intval($session_id);
1776
+                        if (!empty($session_id)) {
1777
+                            $session_id = intval($session_id);
1778 1778
                             $params['session_id'] = $session_id;
1779
-    				    }
1779
+                        }
1780 1780
                     }
1781 1781
                     $new_id = Database::insert($table_qui, $params);
1782 1782
 
@@ -1785,15 +1785,15 @@  discard block
 block discarded – undo
1785 1785
                         Database::query($sql);
1786 1786
                     }
1787 1787
 
1788
-				} else {
1789
-					// $id = -1 identifies the fictionary test for collecting
1790
-					// orphan questions. We do not store it in the database.
1791
-					$new_id = -1;
1792
-				}
1788
+                } else {
1789
+                    // $id = -1 identifies the fictionary test for collecting
1790
+                    // orphan questions. We do not store it in the database.
1791
+                    $new_id = -1;
1792
+                }
1793 1793
 
1794
-				$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1794
+                $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1795 1795
 
1796
-				$order = 0;
1796
+                $order = 0;
1797 1797
                 if (!empty($quiz->question_ids)) {
1798 1798
                     foreach ($quiz->question_ids as $index => $question_id) {
1799 1799
                         $qid = $this->restore_quiz_question($question_id);
@@ -1806,30 +1806,30 @@  discard block
 block discarded – undo
1806 1806
                         Database::query($sql);
1807 1807
                     }
1808 1808
                 }
1809
-			}
1810
-		}
1811
-	}
1809
+            }
1810
+        }
1811
+    }
1812 1812
 
1813
-	/**
1814
-	 * Restore quiz-questions
1813
+    /**
1814
+     * Restore quiz-questions
1815 1815
      * @params int question id
1816
-	 */
1816
+     */
1817 1817
     public function restore_quiz_question($id)
1818 1818
     {
1819
-		$resources = $this->course->resources;
1819
+        $resources = $this->course->resources;
1820 1820
         $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
1821 1821
 
1822
-		$new_id = 0;
1822
+        $new_id = 0;
1823 1823
 
1824
-		if (is_object($question)) {
1825
-			if ($question->is_restored()) {
1826
-				return $question->destination_id;
1827
-			}
1828
-			$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1829
-			$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1824
+        if (is_object($question)) {
1825
+            if ($question->is_restored()) {
1826
+                return $question->destination_id;
1827
+            }
1828
+            $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1829
+            $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1830 1830
             $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
1831 1831
 
1832
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
1832
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
1833 1833
             $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1834 1834
                 $question->description,
1835 1835
                 $this->course->code,
@@ -1850,7 +1850,7 @@  discard block
 block discarded – undo
1850 1850
                 'extra' => self::DBUTF8($question->extra),
1851 1851
             ];
1852 1852
 
1853
-			$new_id = Database::insert($table_que, $params);
1853
+            $new_id = Database::insert($table_que, $params);
1854 1854
 
1855 1855
             if ($new_id) {
1856 1856
 
@@ -1891,7 +1891,7 @@  discard block
 block discarded – undo
1891 1891
 
1892 1892
                 foreach ($temp as $index => $answer) {
1893 1893
                     //id = '".$index."',
1894
-					$params = [
1894
+                    $params = [
1895 1895
                         'c_id' => $this->destination_course_id,
1896 1896
                         'question_id' => $new_id,
1897 1897
                         'answer' => self::DBUTF8($answer['answer']),
@@ -1908,12 +1908,12 @@  discard block
 block discarded – undo
1908 1908
                         $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId";
1909 1909
                         Database::query($sql);
1910 1910
                     }
1911
-				}
1912
-			} else {
1911
+                }
1912
+            } else {
1913 1913
                 $correct_answers = array();
1914
-				foreach ($question->answers as $index => $answer) {
1914
+                foreach ($question->answers as $index => $answer) {
1915 1915
 
1916
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1916
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1917 1917
                     $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1918 1918
                         $answer['answer'],
1919 1919
                         $this->course->code,
@@ -1952,8 +1952,8 @@  discard block
 block discarded – undo
1952 1952
                     }
1953 1953
 
1954 1954
                     $correct_answers[$answerId] = $answer['correct'];
1955
-				}
1956
-			}
1955
+                }
1956
+            }
1957 1957
 
1958 1958
             //Current course id
1959 1959
             $course_id = api_get_course_int_id();
@@ -2050,12 +2050,12 @@  discard block
 block discarded – undo
2050 2050
                     }
2051 2051
                 }
2052 2052
             }
2053
-			$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2054
-		}
2055
-		return $new_id;
2056
-	}
2053
+            $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2054
+        }
2055
+        return $new_id;
2056
+    }
2057 2057
 
2058
-	/**
2058
+    /**
2059 2059
      * @todo : add session id when used for session
2060 2060
      */
2061 2061
     public function restore_test_category($session_id, $respect_base_content, $destination_course_code)
@@ -2135,21 +2135,21 @@  discard block
 block discarded – undo
2135 2135
         $sessionId = intval($sessionId);
2136 2136
 
2137 2137
         if ($this->course->has_resources(RESOURCE_SURVEY)) {
2138
-			$table_sur = Database :: get_course_table(TABLE_SURVEY);
2139
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2140
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2141
-			$resources = $this->course->resources;
2142
-			foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2138
+            $table_sur = Database :: get_course_table(TABLE_SURVEY);
2139
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2140
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2141
+            $resources = $this->course->resources;
2142
+            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2143 2143
 
2144
-				$sql = 'SELECT survey_id FROM '.$table_sur.'
2144
+                $sql = 'SELECT survey_id FROM '.$table_sur.'
2145 2145
                         WHERE
2146 2146
                             c_id = '.$this->destination_course_id.' AND
2147 2147
                             code = "'.self::DBUTF8escapestring($survey->code).'" AND
2148 2148
                             lang = "'.self::DBUTF8escapestring($survey->lang).'" ';
2149 2149
 
2150
-				$result_check = Database::query($sql);
2150
+                $result_check = Database::query($sql);
2151 2151
 
2152
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2152
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2153 2153
                 $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2154 2154
                     $survey->title,
2155 2155
                     $this->course->code,
@@ -2203,20 +2203,20 @@  discard block
 block discarded – undo
2203 2203
                     'session_id' => $sessionId,
2204 2204
                 ];
2205 2205
 
2206
-				//An existing survey exists with the same code and the same language
2207
-				if (Database::num_rows($result_check) == 1) {
2208
-					switch ($this->file_option) {
2209
-						case FILE_SKIP:
2210
-							//Do nothing
2211
-							break;
2212
-						case FILE_RENAME:
2213
-							$survey_code = $survey->code.'_';
2214
-							$i=1;
2215
-							$temp_survey_code = $survey_code.$i;
2216
-							while (!$this->is_survey_code_available($temp_survey_code)) {
2217
-								$temp_survey_code = $survey_code.++$i;
2218
-							}
2219
-							$survey_code = $temp_survey_code;
2206
+                //An existing survey exists with the same code and the same language
2207
+                if (Database::num_rows($result_check) == 1) {
2208
+                    switch ($this->file_option) {
2209
+                        case FILE_SKIP:
2210
+                            //Do nothing
2211
+                            break;
2212
+                        case FILE_RENAME:
2213
+                            $survey_code = $survey->code.'_';
2214
+                            $i=1;
2215
+                            $temp_survey_code = $survey_code.$i;
2216
+                            while (!$this->is_survey_code_available($temp_survey_code)) {
2217
+                                $temp_survey_code = $survey_code.++$i;
2218
+                            }
2219
+                            $survey_code = $temp_survey_code;
2220 2220
 
2221 2221
                             $params['code'] = $survey_code;
2222 2222
                             $new_id = Database::insert($table_sur, $params);
@@ -2235,25 +2235,25 @@  discard block
 block discarded – undo
2235 2235
                                     Database::query($sql);
2236 2236
                                 }
2237 2237
                             }
2238
-							break;
2239
-						case FILE_OVERWRITE:
2240
-							// Delete the existing survey with the same code and language and import the one of the source course
2241
-							// getting the information of the survey (used for when the survey is shared)
2238
+                            break;
2239
+                        case FILE_OVERWRITE:
2240
+                            // Delete the existing survey with the same code and language and import the one of the source course
2241
+                            // getting the information of the survey (used for when the survey is shared)
2242 2242
 
2243
-							$sql = "SELECT * FROM $table_sur
2243
+                            $sql = "SELECT * FROM $table_sur
2244 2244
 							        WHERE
2245 2245
 							            c_id = ".$this->destination_course_id." AND
2246 2246
 							            survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'";
2247
-							$result = Database::query($sql);
2248
-							$survey_data = Database::fetch_array($result,'ASSOC');
2247
+                            $result = Database::query($sql);
2248
+                            $survey_data = Database::fetch_array($result,'ASSOC');
2249 2249
 
2250
-							// if the survey is shared => also delete the shared content
2251
-							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2250
+                            // if the survey is shared => also delete the shared content
2251
+                            if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2252 2252
                                 SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
2253
-							}
2254
-							SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2253
+                            }
2254
+                            SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2255 2255
 
2256
-							// Insert the new source survey
2256
+                            // Insert the new source survey
2257 2257
                             $new_id = Database::insert($table_sur, $params);
2258 2258
 
2259 2259
                             if ($new_id) {
@@ -2274,11 +2274,11 @@  discard block
 block discarded – undo
2274 2274
                                     Database::query($sql);
2275 2275
                                 }
2276 2276
                             }
2277
-							break;
2278
-						default:
2279
-							break;
2280
-					}
2281
-				} else {
2277
+                            break;
2278
+                        default:
2279
+                            break;
2280
+                    }
2281
+                } else {
2282 2282
                     // No existing survey with the same language and the same code, we just copy the survey
2283 2283
                     $new_id = Database::insert($table_sur, $params);
2284 2284
 
@@ -2300,43 +2300,43 @@  discard block
 block discarded – undo
2300 2300
                             Database::query($sql);
2301 2301
                         }
2302 2302
                     }
2303
-				}
2304
-			}
2305
-		}
2306
-	}
2307
-
2308
-	/**
2309
-	 * Check availability of a survey code
2310
-	 */
2303
+                }
2304
+            }
2305
+        }
2306
+    }
2307
+
2308
+    /**
2309
+     * Check availability of a survey code
2310
+     */
2311 2311
     public function is_survey_code_available($survey_code)
2312 2312
     {
2313
-		$table_sur = Database :: get_course_table(TABLE_SURVEY);
2314
-		$sql = "SELECT * FROM $table_sur
2313
+        $table_sur = Database :: get_course_table(TABLE_SURVEY);
2314
+        $sql = "SELECT * FROM $table_sur
2315 2315
 		        WHERE
2316 2316
 		            c_id = ".$this->destination_course_id." AND
2317 2317
 		            code='".self::DBUTF8escapestring($survey_code)."'";
2318
-		$result = Database::query($sql);
2319
-		if (Database::num_rows($result) > 0) return false; else return true;
2320
-	}
2318
+        $result = Database::query($sql);
2319
+        if (Database::num_rows($result) > 0) return false; else return true;
2320
+    }
2321 2321
 
2322
-	/**
2323
-	 * Restore survey-questions
2324
-	 */
2322
+    /**
2323
+     * Restore survey-questions
2324
+     */
2325 2325
     public function restore_survey_question($id, $survey_id)
2326 2326
     {
2327
-		$resources = $this->course->resources;
2328
-		$question = $resources[RESOURCE_SURVEYQUESTION][$id];
2327
+        $resources = $this->course->resources;
2328
+        $question = $resources[RESOURCE_SURVEYQUESTION][$id];
2329 2329
 
2330
-		$new_id=0;
2330
+        $new_id=0;
2331 2331
 
2332
-		if (is_object($question)) {
2333
-			if ($question->is_restored()) {
2334
-				return $question->destination_id;
2335
-			}
2336
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2337
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2332
+        if (is_object($question)) {
2333
+            if ($question->is_restored()) {
2334
+                return $question->destination_id;
2335
+            }
2336
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2337
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2338 2338
 
2339
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
2339
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
2340 2340
             $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2341 2341
                 $question->survey_question,
2342 2342
                 $this->course->code,
@@ -2390,10 +2390,10 @@  discard block
 block discarded – undo
2390 2390
                 }
2391 2391
                 $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id;
2392 2392
             }
2393
-		}
2393
+        }
2394 2394
 
2395
-		return $new_id;
2396
-	}
2395
+        return $new_id;
2396
+    }
2397 2397
 
2398 2398
     /**
2399 2399
      * Restoring learning paths
@@ -2404,20 +2404,20 @@  discard block
 block discarded – undo
2404 2404
     {
2405 2405
         $session_id = intval($session_id);
2406 2406
 
2407
-		if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2407
+        if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2408 2408
             $table_main = Database::get_course_table(TABLE_LP_MAIN);
2409 2409
             $table_item = Database::get_course_table(TABLE_LP_ITEM);
2410 2410
             $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
2411 2411
 
2412
-			$resources = $this->course->resources;
2412
+            $resources = $this->course->resources;
2413 2413
 
2414
-			$origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2415
-			$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2414
+            $origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2415
+            $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2416 2416
 
2417
-			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2417
+            foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2418 2418
 
2419
-				$condition_session = "";
2420
-				if (!empty($session_id)) {
2419
+                $condition_session = "";
2420
+                if (!empty($session_id)) {
2421 2421
                     if ($respect_base_content) {
2422 2422
                         $my_session_id = $lp->session_id;
2423 2423
                         if (!empty($lp->session_id)) {
@@ -2428,21 +2428,21 @@  discard block
 block discarded – undo
2428 2428
                         $session_id = intval($session_id);
2429 2429
                         $condition_session = $session_id;
2430 2430
                     }
2431
-				}
2432
-
2433
-				// Adding the author's image
2434
-				if (!empty($lp->preview_image)) {
2435
-					$new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2436
-					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2437
-						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2438
-						//$copy_result = true;
2439
-						if ($copy_result) {
2440
-							$lp->preview_image = $new_filename;
2441
-						} else {
2442
-							$lp->preview_image ='';
2443
-						}
2444
-					}
2445
-				}
2431
+                }
2432
+
2433
+                // Adding the author's image
2434
+                if (!empty($lp->preview_image)) {
2435
+                    $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2436
+                    if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2437
+                        $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2438
+                        //$copy_result = true;
2439
+                        if ($copy_result) {
2440
+                            $lp->preview_image = $new_filename;
2441
+                        } else {
2442
+                            $lp->preview_image ='';
2443
+                        }
2444
+                    }
2445
+                }
2446 2446
 
2447 2447
                 if ($this->add_text_in_items) {
2448 2448
                     $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix');
@@ -2489,7 +2489,7 @@  discard block
 block discarded – undo
2489 2489
                     $params['session_id'] = $condition_session;
2490 2490
                 }
2491 2491
 
2492
-				$new_lp_id = Database::insert($table_main, $params);
2492
+                $new_lp_id = Database::insert($table_main, $params);
2493 2493
 
2494 2494
                 if ($new_lp_id) {
2495 2495
 
@@ -2550,13 +2550,13 @@  discard block
 block discarded – undo
2550 2550
                 $old_refs = array();
2551 2551
                 $prerequisite_ids = array();
2552 2552
 
2553
-				foreach ($lp->get_items() as $index => $item) {
2554
-					// we set the ref code here and then we update in a for loop
2555
-					$ref = $item['ref'];
2553
+                foreach ($lp->get_items() as $index => $item) {
2554
+                    // we set the ref code here and then we update in a for loop
2555
+                    $ref = $item['ref'];
2556 2556
 
2557
-					// Dealing with path the same way as ref as some data has
2557
+                    // Dealing with path the same way as ref as some data has
2558 2558
                     // been put into path when it's a local resource
2559
-					// Only fix the path for no scos
2559
+                    // Only fix the path for no scos
2560 2560
                     if ($item['item_type'] == 'sco') {
2561 2561
                         $path = $item['path'];
2562 2562
                     } else {
@@ -2585,128 +2585,128 @@  discard block
 block discarded – undo
2585 2585
                         'launch_data' => self::DBUTF8($item['launch_data']),
2586 2586
                     ];
2587 2587
 
2588
-					$new_item_id = Database::insert($table_item, $params);
2588
+                    $new_item_id = Database::insert($table_item, $params);
2589 2589
 
2590 2590
                     $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
2591 2591
                     Database::query($sql);
2592 2592
 
2593
-					//save a link between old and new item IDs
2594
-					$new_item_ids[$item['id']] = $new_item_id;
2595
-					//save a reference of items that need a parent_item_id refresh
2596
-					$parent_item_ids[$new_item_id] = $item['parent_item_id'];
2597
-					//save a reference of items that need a previous_item_id refresh
2598
-					$previous_item_ids[$new_item_id] = $item['previous_item_id'];
2599
-					//save a reference of items that need a next_item_id refresh
2600
-					$next_item_ids[$new_item_id] = $item['next_item_id'];
2601
-
2602
-					if (!empty($item['prerequisite'])) {
2603
-						if ($lp->lp_type =='2') {
2604
-							// if is an sco
2605
-							$old_prerequisite[$new_item_id]= $item['prerequisite'];
2606
-						} else {
2607
-							$old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2608
-						}
2609
-					}
2610
-
2611
-					if (!empty($ref)) {
2612
-						if ($lp->lp_type =='2') {
2613
-							// if is an sco
2614
-							$old_refs[$new_item_id]= $ref;
2615
-						} else {
2593
+                    //save a link between old and new item IDs
2594
+                    $new_item_ids[$item['id']] = $new_item_id;
2595
+                    //save a reference of items that need a parent_item_id refresh
2596
+                    $parent_item_ids[$new_item_id] = $item['parent_item_id'];
2597
+                    //save a reference of items that need a previous_item_id refresh
2598
+                    $previous_item_ids[$new_item_id] = $item['previous_item_id'];
2599
+                    //save a reference of items that need a next_item_id refresh
2600
+                    $next_item_ids[$new_item_id] = $item['next_item_id'];
2601
+
2602
+                    if (!empty($item['prerequisite'])) {
2603
+                        if ($lp->lp_type =='2') {
2604
+                            // if is an sco
2605
+                            $old_prerequisite[$new_item_id]= $item['prerequisite'];
2606
+                        } else {
2607
+                            $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2608
+                        }
2609
+                    }
2610
+
2611
+                    if (!empty($ref)) {
2612
+                        if ($lp->lp_type =='2') {
2613
+                            // if is an sco
2614
+                            $old_refs[$new_item_id]= $ref;
2615
+                        } else {
2616 2616
                             $old_refs[$new_item_id]= $new_item_ids[$ref];
2617
-						}
2618
-					}
2617
+                        }
2618
+                    }
2619 2619
 
2620
-					$prerequisite_ids[$new_item_id] = $item['prerequisite'];
2621
-				}
2620
+                    $prerequisite_ids[$new_item_id] = $item['prerequisite'];
2621
+                }
2622 2622
 
2623
-				// Updating prerequisites
2624
-				foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2625
-					if($my_old_prerequisite != ''){
2626
-						$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2623
+                // Updating prerequisites
2624
+                foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2625
+                    if($my_old_prerequisite != ''){
2626
+                        $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2627 2627
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2628
-						Database::query($sql);
2629
-					}
2630
-				}
2631
-
2632
-				// Updating refs
2633
-				foreach ($old_refs  as $key=>$my_old_ref) {
2634
-					if ($my_old_ref != '') {
2635
-						$sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2628
+                        Database::query($sql);
2629
+                    }
2630
+                }
2631
+
2632
+                // Updating refs
2633
+                foreach ($old_refs  as $key=>$my_old_ref) {
2634
+                    if ($my_old_ref != '') {
2635
+                        $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2636 2636
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2637
-						Database::query($sql);
2638
-					}
2639
-				}
2640
-
2641
-				foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2642
-					$parent_new_id = 0;
2643
-					if($parent_item_old_id != 0){
2644
-						$parent_new_id = $new_item_ids[$parent_item_old_id];
2645
-					}
2646
-					$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2637
+                        Database::query($sql);
2638
+                    }
2639
+                }
2640
+
2641
+                foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2642
+                    $parent_new_id = 0;
2643
+                    if($parent_item_old_id != 0){
2644
+                        $parent_new_id = $new_item_ids[$parent_item_old_id];
2645
+                    }
2646
+                    $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2647 2647
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2648
-					Database::query($sql);
2649
-				}
2650
-				foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2651
-					$previous_new_id = 0;
2652
-					if($previous_item_old_id != 0){
2653
-						$previous_new_id = $new_item_ids[$previous_item_old_id];
2654
-					}
2655
-					$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2648
+                    Database::query($sql);
2649
+                }
2650
+                foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2651
+                    $previous_new_id = 0;
2652
+                    if($previous_item_old_id != 0){
2653
+                        $previous_new_id = $new_item_ids[$previous_item_old_id];
2654
+                    }
2655
+                    $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2656 2656
 					        WHERE  c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2657
-					Database::query($sql);
2658
-				}
2659
-
2660
-				foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2661
-					$next_new_id = 0;
2662
-					if($next_item_old_id != 0){
2663
-						$next_new_id = $new_item_ids[$next_item_old_id];
2664
-					}
2665
-					$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2657
+                    Database::query($sql);
2658
+                }
2659
+
2660
+                foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2661
+                    $next_new_id = 0;
2662
+                    if($next_item_old_id != 0){
2663
+                        $next_new_id = $new_item_ids[$next_item_old_id];
2664
+                    }
2665
+                    $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2666 2666
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2667
-					Database::query($sql);
2668
-				}
2669
-
2670
-				foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2671
-					$prerequisite_new_id = 0;
2672
-					if($prerequisite_old_id != 0){
2673
-						$prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2674
-					}
2675
-					$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2667
+                    Database::query($sql);
2668
+                }
2669
+
2670
+                foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2671
+                    $prerequisite_new_id = 0;
2672
+                    if($prerequisite_old_id != 0){
2673
+                        $prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2674
+                    }
2675
+                    $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2676 2676
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2677
-					Database::query($sql);
2678
-				}
2679
-				$this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2680
-			}
2681
-		}
2682
-	}
2683
-
2684
-	/**
2685
-	 * Restore works
2677
+                    Database::query($sql);
2678
+                }
2679
+                $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2680
+            }
2681
+        }
2682
+    }
2683
+
2684
+    /**
2685
+     * Restore works
2686 2686
      * @deprecated use restore_works
2687 2687
      *
2688
-	 */
2689
-	public function restore_student_publication($sessionId = 0)
2688
+     */
2689
+    public function restore_student_publication($sessionId = 0)
2690 2690
     {
2691 2691
         $sessionId = intval($sessionId);
2692
-		$work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2693
-		$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2694
-		$item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2692
+        $work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2693
+        $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2694
+        $item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2695 2695
 
2696
-		// Query in student publication
2697
-		$sql = 'SELECT * FROM '.$work_table.'
2696
+        // Query in student publication
2697
+        $sql = 'SELECT * FROM '.$work_table.'
2698 2698
 		        WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) ';
2699 2699
 
2700
-		$result = Database::query($sql);
2701
-		$folders = Database::store_result($result, 'ASSOC');
2700
+        $result = Database::query($sql);
2701
+        $folders = Database::store_result($result, 'ASSOC');
2702 2702
 
2703
-		foreach ($folders  as $folder) {
2704
-		    $old_id = $folder['id'];
2703
+        foreach ($folders  as $folder) {
2704
+            $old_id = $folder['id'];
2705 2705
             unset($folder['id']);
2706
-			$folder['c_id'] = $this->destination_course_id;
2706
+            $folder['c_id'] = $this->destination_course_id;
2707 2707
             $folder['parent_id'] = 0;
2708 2708
             $folder['session_id'] = $sessionId;
2709
-			$new_id = Database::insert($work_table, $folder);
2709
+            $new_id = Database::insert($work_table, $folder);
2710 2710
 
2711 2711
             if ($new_id) {
2712 2712
                 //query in item property
@@ -2765,21 +2765,21 @@  discard block
 block discarded – undo
2765 2765
                     }
2766 2766
                 }
2767 2767
             }
2768
-		}
2768
+        }
2769 2769
 
2770
-		$destination = '../../courses/'.$this->course->destination_path.'/work/';
2771
-		$origin = '../../courses/'.$this->course->info['path'].'/work/';
2772
-		self::allow_create_all_directory($origin,$destination,false);
2773
-	}
2770
+        $destination = '../../courses/'.$this->course->destination_path.'/work/';
2771
+        $origin = '../../courses/'.$this->course->info['path'].'/work/';
2772
+        self::allow_create_all_directory($origin,$destination,false);
2773
+    }
2774 2774
 
2775 2775
     /**
2776
-    * copy all directory and sub directory
2777
-    * @param string The path origin
2778
-    * @param string The path destination
2779
-    * @param boolean Option Overwrite
2780
-    * @return void()
2781
-    * @deprecated
2782
-    */
2776
+     * copy all directory and sub directory
2777
+     * @param string The path origin
2778
+     * @param string The path destination
2779
+     * @param boolean Option Overwrite
2780
+     * @return void()
2781
+     * @deprecated
2782
+     */
2783 2783
     public function allow_create_all_directory($source, $dest, $overwrite = false)
2784 2784
     {
2785 2785
         if (!is_dir($dest)) {
@@ -2790,14 +2790,14 @@  discard block
 block discarded – undo
2790 2790
                 if ($file != '.' && $file != '..') {
2791 2791
                     $path = $source . '/' . $file;
2792 2792
                     if (is_file($path)) {
2793
-                       /* if (!is_file($dest . '/' . $file) || $overwrite)
2793
+                        /* if (!is_file($dest . '/' . $file) || $overwrite)
2794 2794
                         if (!@copy($path, $dest . '/' . $file)) {
2795 2795
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2796 2796
                         }*/
2797 2797
                     } elseif(is_dir($path)) {
2798 2798
                         if (!is_dir($dest . '/' . $file))
2799 2799
                         mkdir($dest . '/' . $file);
2800
-                       self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2800
+                        self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2801 2801
                     }
2802 2802
                 }
2803 2803
             }
@@ -2805,12 +2805,12 @@  discard block
 block discarded – undo
2805 2805
         }
2806 2806
     }
2807 2807
 
2808
-	/**
2809
-	 * Gets the new ID of one specific tool item from the tool name and the old ID
2810
-	 * @param	string	Tool name
2811
-	 * @param	integer	Old ID
2812
-	 * @return	integer	New ID
2813
-	 */
2808
+    /**
2809
+     * Gets the new ID of one specific tool item from the tool name and the old ID
2810
+     * @param	string	Tool name
2811
+     * @param	integer	Old ID
2812
+     * @return	integer	New ID
2813
+     */
2814 2814
     public function get_new_id($tool, $ref)
2815 2815
     {
2816 2816
         // Check if the value exist in the current array.
@@ -2832,25 +2832,25 @@  discard block
 block discarded – undo
2832 2832
         }
2833 2833
 
2834 2834
         return '';
2835
-	}
2835
+    }
2836 2836
 
2837
-	/**
2838
-	 * Restore glossary
2839
-	 */
2837
+    /**
2838
+     * Restore glossary
2839
+     */
2840 2840
     public function restore_glossary($session_id = 0)
2841 2841
     {
2842
-		if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2843
-			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2844
-			$resources = $this->course->resources;
2845
-			foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2842
+        if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2843
+            $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2844
+            $resources = $this->course->resources;
2845
+            foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2846 2846
 
2847 2847
                 $params = [];
2848
-    			if (!empty($session_id)) {
2849
-    				$session_id = intval($session_id);
2848
+                if (!empty($session_id)) {
2849
+                    $session_id = intval($session_id);
2850 2850
                     $params['session_id'] = $session_id;
2851
-    			}
2851
+                }
2852 2852
 
2853
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2853
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2854 2854
                 $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2855 2855
                     $glossary->description,
2856 2856
                     $this->course->code,
@@ -2884,27 +2884,27 @@  discard block
 block discarded – undo
2884 2884
 
2885 2885
                     $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id;
2886 2886
                 }
2887
-			}
2888
-		}
2889
-	}
2887
+            }
2888
+        }
2889
+    }
2890 2890
 
2891 2891
     /**
2892 2892
      * @param int $session_id
2893 2893
      */
2894 2894
     public function restore_wiki($session_id = 0)
2895 2895
     {
2896
-		if ($this->course->has_resources(RESOURCE_WIKI)) {
2897
-			// wiki table of the target course
2898
-			$table_wiki = Database :: get_course_table(TABLE_WIKI);
2899
-			$table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2896
+        if ($this->course->has_resources(RESOURCE_WIKI)) {
2897
+            // wiki table of the target course
2898
+            $table_wiki = Database :: get_course_table(TABLE_WIKI);
2899
+            $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2900 2900
 
2901
-			// storing all the resources that have to be copied in an array
2902
-			$resources = $this->course->resources;
2901
+            // storing all the resources that have to be copied in an array
2902
+            $resources = $this->course->resources;
2903 2903
 
2904
-			foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2905
-				// the sql statement to insert the groups from the old course to the new course
2904
+            foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2905
+                // the sql statement to insert the groups from the old course to the new course
2906 2906
 
2907
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2907
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2908 2908
                 $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2909 2909
                     $wiki->content,
2910 2910
                     $this->course->code,
@@ -2927,7 +2927,7 @@  discard block
 block discarded – undo
2927 2927
                     'session_id' => !empty($session_id) ? intval($session_id) : 0,
2928 2928
                 ];
2929 2929
 
2930
-				$new_id = Database::insert($table_wiki, $params);
2930
+                $new_id = Database::insert($table_wiki, $params);
2931 2931
 
2932 2932
                 if ($new_id) {
2933 2933
 
@@ -2958,9 +2958,9 @@  discard block
 block discarded – undo
2958 2958
 
2959 2959
                     Database::insert($table_wiki_conf, $params);
2960 2960
                 }
2961
-			}
2962
-		}
2963
-	}
2961
+            }
2962
+        }
2963
+    }
2964 2964
 
2965 2965
     /**
2966 2966
      * Restore Thematics
@@ -2968,15 +2968,15 @@  discard block
 block discarded – undo
2968 2968
      */
2969 2969
     public function restore_thematic($session_id = 0)
2970 2970
     {
2971
-		if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2971
+        if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2972 2972
             $table_thematic = Database:: get_course_table(TABLE_THEMATIC);
2973 2973
             $table_thematic_advance = Database:: get_course_table(TABLE_THEMATIC_ADVANCE);
2974 2974
             $table_thematic_plan = Database:: get_course_table(TABLE_THEMATIC_PLAN);
2975 2975
 
2976
-			$resources = $this->course->resources;
2977
-			foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2976
+            $resources = $this->course->resources;
2977
+            foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2978 2978
 
2979
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2979
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2980 2980
                 $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2981 2981
                     $thematic->params['content'],
2982 2982
                     $this->course->code,
@@ -2984,13 +2984,13 @@  discard block
 block discarded – undo
2984 2984
                     $this->course->backup_path,
2985 2985
                     $this->course->info['path']
2986 2986
                 );
2987
-				$thematic->params['c_id']  = $this->destination_course_id;
2988
-				unset($thematic->params['id']);
2987
+                $thematic->params['c_id']  = $this->destination_course_id;
2988
+                unset($thematic->params['id']);
2989 2989
                 unset($thematic->params['iid']);
2990 2990
 
2991
-				$last_id = Database::insert($table_thematic, $thematic->params, false);
2991
+                $last_id = Database::insert($table_thematic, $thematic->params, false);
2992 2992
 
2993
-				if ($last_id) {
2993
+                if ($last_id) {
2994 2994
 
2995 2995
                     $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id";
2996 2996
                     Database::query($sql);
@@ -3003,19 +3003,19 @@  discard block
 block discarded – undo
3003 3003
                         api_get_user_id()
3004 3004
                     );
3005 3005
 
3006
-					foreach ($thematic->thematic_advance_list as $thematic_advance) {
3007
-						unset($thematic_advance['id']);
3006
+                    foreach ($thematic->thematic_advance_list as $thematic_advance) {
3007
+                        unset($thematic_advance['id']);
3008 3008
                         unset($thematic_advance['iid']);
3009
-						$thematic_advance['attendance_id'] = 0;
3010
-						$thematic_advance['thematic_id'] = $last_id;
3011
-						$thematic_advance['c_id']  = $this->destination_course_id;
3009
+                        $thematic_advance['attendance_id'] = 0;
3010
+                        $thematic_advance['thematic_id'] = $last_id;
3011
+                        $thematic_advance['c_id']  = $this->destination_course_id;
3012 3012
                         $my_id = Database::insert(
3013 3013
                             $table_thematic_advance,
3014 3014
                             $thematic_advance,
3015 3015
                             false
3016 3016
                         );
3017 3017
 
3018
-						if ($my_id) {
3018
+                        if ($my_id) {
3019 3019
 
3020 3020
                             $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id";
3021 3021
                             Database::query($sql);
@@ -3027,17 +3027,17 @@  discard block
 block discarded – undo
3027 3027
                                 "ThematicAdvanceAdded",
3028 3028
                                 api_get_user_id()
3029 3029
                             );
3030
-						}
3031
-					}
3030
+                        }
3031
+                    }
3032 3032
 
3033
-					foreach($thematic->thematic_plan_list as $thematic_plan) {
3034
-						unset($thematic_plan['id']);
3033
+                    foreach($thematic->thematic_plan_list as $thematic_plan) {
3034
+                        unset($thematic_plan['id']);
3035 3035
                         unset($thematic_plan['iid']);
3036
-						$thematic_plan['thematic_id'] = $last_id;
3037
-						$thematic_plan['c_id'] = $this->destination_course_id;
3038
-						$my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3036
+                        $thematic_plan['thematic_id'] = $last_id;
3037
+                        $thematic_plan['c_id'] = $this->destination_course_id;
3038
+                        $my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3039 3039
 
3040
-						if ($my_id) {
3040
+                        if ($my_id) {
3041 3041
 
3042 3042
                             $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id";
3043 3043
                             Database::query($sql);
@@ -3049,12 +3049,12 @@  discard block
 block discarded – undo
3049 3049
                                 "ThematicPlanAdded",
3050 3050
                                 api_get_user_id()
3051 3051
                             );
3052
-						}
3053
-					}
3054
-				}
3055
-			}
3056
-		}
3057
-	}
3052
+                        }
3053
+                    }
3054
+                }
3055
+            }
3056
+        }
3057
+    }
3058 3058
 
3059 3059
     /**
3060 3060
      * Restore Attendance
@@ -3062,14 +3062,14 @@  discard block
 block discarded – undo
3062 3062
      */
3063 3063
     public function restore_attendance($session_id = 0)
3064 3064
     {
3065
-		if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3066
-			$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3067
-			$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3065
+        if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3066
+            $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3067
+            $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3068 3068
 
3069
-			$resources = $this->course->resources;
3070
-			foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3069
+            $resources = $this->course->resources;
3070
+            foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3071 3071
 
3072
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
3072
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
3073 3073
                 $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
3074 3074
                     $obj->params['description'],
3075 3075
                     $this->course->code,
@@ -3081,11 +3081,11 @@  discard block
 block discarded – undo
3081 3081
                 unset($obj->params['id']);
3082 3082
                 unset($obj->params['iid']);
3083 3083
 
3084
-				$obj->params['c_id'] = $this->destination_course_id;
3084
+                $obj->params['c_id'] = $this->destination_course_id;
3085 3085
 
3086
-				$last_id = Database::insert($table_attendance, $obj->params);
3086
+                $last_id = Database::insert($table_attendance, $obj->params);
3087 3087
 
3088
-				if (is_numeric($last_id)) {
3088
+                if (is_numeric($last_id)) {
3089 3089
 
3090 3090
                     $sql = "UPDATE $table_attendance SET id = iid WHERE iid = $last_id";
3091 3091
                     Database::query($sql);
@@ -3099,11 +3099,11 @@  discard block
 block discarded – undo
3099 3099
                     );
3100 3100
 
3101 3101
                     foreach ($obj->attendance_calendar as $attendance_calendar) {
3102
-						unset($attendance_calendar['id']);
3102
+                        unset($attendance_calendar['id']);
3103 3103
                         unset($attendance_calendar['iid']);
3104 3104
 
3105
-						$attendance_calendar['attendance_id'] = $last_id;
3106
-						$attendance_calendar['c_id'] = $this->destination_course_id;
3105
+                        $attendance_calendar['attendance_id'] = $last_id;
3106
+                        $attendance_calendar['c_id'] = $this->destination_course_id;
3107 3107
                         $attendanceCalendarId = Database::insert(
3108 3108
                             $table_attendance_calendar,
3109 3109
                             $attendance_calendar
@@ -3111,11 +3111,11 @@  discard block
 block discarded – undo
3111 3111
 
3112 3112
                         $sql = "UPDATE $table_attendance_calendar SET id = iid WHERE iid = $attendanceCalendarId";
3113 3113
                         Database::query($sql);
3114
-					}
3115
-				}
3116
-			}
3117
-		}
3118
-	}
3114
+                    }
3115
+                }
3116
+            }
3117
+        }
3118
+    }
3119 3119
 
3120 3120
     /**
3121 3121
      * Restore Works
@@ -3257,11 +3257,11 @@  discard block
 block discarded – undo
3257 3257
      */
3258 3258
     public function DBUTF8($str)
3259 3259
     {
3260
-		if (UTF8_CONVERT) {
3260
+        if (UTF8_CONVERT) {
3261 3261
             $str = utf8_encode($str);
3262 3262
         }
3263
-		return $str;
3264
-	}
3263
+        return $str;
3264
+    }
3265 3265
 
3266 3266
     /**
3267 3267
      * @param string $str
@@ -3272,8 +3272,8 @@  discard block
 block discarded – undo
3272 3272
         if (UTF8_CONVERT) {
3273 3273
             $str = utf8_encode($str);
3274 3274
         }
3275
-		return Database::escape_string($str);
3276
-	}
3275
+        return Database::escape_string($str);
3276
+    }
3277 3277
 
3278 3278
     /**
3279 3279
      * @param array $array
Please login to merge, or discard this patch.