Completed
Push — 1.10.x ( 812a9a...914b0e )
by Angel Fernando Quiroz
43:28
created
main/coursecopy/classes/CourseBuilder.class.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         $table_doc = Database:: get_course_table(TABLE_DOCUMENT);
596 596
 
597 597
         if (!empty($courseId) && !empty($session_id)) {
598
-            $session_id  = intval($session_id);
598
+            $session_id = intval($session_id);
599 599
             if ($with_base_content) {
600 600
                 $session_condition = api_get_session_condition(
601 601
                     $session_id,
@@ -804,7 +804,7 @@  discard block
 block discarded – undo
804 804
                 'title' => get_lang('OrphanQuestions', ''),
805 805
                 'type' => 2
806 806
             );
807
-            $newQuiz = new Quiz((object)$obj);
807
+            $newQuiz = new Quiz((object) $obj);
808 808
             if (!empty($orphanQuestionIds)) {
809 809
                 foreach ($orphanQuestionIds as $index => $orphanId) {
810 810
                     $order = $index + 1;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-     * @param array $array
94
+     * @param string[] $array
95 95
      */
96 96
     public function set_tools_to_build($array)
97 97
     {
Please login to merge, or discard this patch.
main/coursecopy/classes/Event.class.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -66,19 +66,19 @@
 block discarded – undo
66 66
         $attachment_comment = null,
67 67
         $all_day = 0
68 68
     ) {
69
-		parent::__construct($id, RESOURCE_EVENT);
69
+        parent::__construct($id, RESOURCE_EVENT);
70 70
 
71
-		$this->title = $title;
72
-		$this->content = $content;
73
-		$this->start_date = $start_date;
74
-		$this->end_date = $end_date;
75
-		$this->all_day = $all_day;
71
+        $this->title = $title;
72
+        $this->content = $content;
73
+        $this->start_date = $start_date;
74
+        $this->end_date = $end_date;
75
+        $this->all_day = $all_day;
76 76
 
77
-		$this->attachment_path = $attachment_path;
78
-		$this->attachment_filename = $attachment_filename;
79
-		$this->attachment_size = $attachment_size;
80
-		$this->attachment_comment = $attachment_comment;
81
-	}
77
+        $this->attachment_path = $attachment_path;
78
+        $this->attachment_filename = $attachment_filename;
79
+        $this->attachment_size = $attachment_size;
80
+        $this->attachment_comment = $attachment_comment;
81
+    }
82 82
 
83 83
     /**
84 84
      * Show this Event
Please login to merge, or discard this patch.
main/coursecopy/classes/ForumPost.class.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,6 +25,6 @@
 block discarded – undo
25 25
     public function show()
26 26
     {
27 27
         parent::show();
28
-        echo $this->obj->title . ' (' . $this->obj->poster_name . ', ' . $this->obj->post_date . ')';
28
+        echo $this->obj->title.' ('.$this->obj->poster_name.', '.$this->obj->post_date.')';
29 29
     }
30 30
 }
Please login to merge, or discard this patch.
main/coursecopy/classes/CourseSelectForm.class.php 3 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 
137 137
 		//get destination course title
138 138
 		if (!empty($hidden_fields['destination_course'])) {
139
-            $sessionTitle = !empty($hidden_fields['destination_session']) ? ' (' . api_get_session_name(
139
+            $sessionTitle = !empty($hidden_fields['destination_session']) ? ' ('.api_get_session_name(
140 140
                 $hidden_fields['destination_session']
141
-            ) . ')' : null;
141
+            ).')' : null;
142 142
 
143 143
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
144 144
 			echo '<h3>';
145
-			echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
145
+			echo get_lang('DestinationCourse').' : '.$course_infos['title'].' ('.$course_infos['code'].') '.$sessionTitle;
146 146
 			echo '</h3>';
147 147
 		}
148 148
         echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 			/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
299 299
 			(when there are directories with hundred/thousand of files) */
300 300
 			// this is a known issue of serialize
301
-			$course->resources['document']= null;
301
+			$course->resources['document'] = null;
302 302
 		}
303 303
 
304 304
 		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 		    Display::display_warning_message(get_lang('NoDataAvailable'));
316 316
 		} else {
317 317
     		if (!empty($hidden_fields['destination_session'])) {
318
-    			echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
318
+    			echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset))."'".')) return false;" >'.
319 319
                     get_lang('Ok').'</button>';
320 320
     		} else {
321 321
                 if ($recycleOption) {
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
      */
340 340
     static function display_hidden_quiz_questions($course)
341 341
     {
342
-		if(is_array($course->resources)){
342
+		if (is_array($course->resources)) {
343 343
 			foreach ($course->resources as $type => $resources) {
344 344
 				if (count($resources) > 0) {
345 345
 					switch ($type) {
@@ -359,10 +359,10 @@  discard block
 block discarded – undo
359 359
      */
360 360
     static function display_hidden_scorm_directories($course)
361 361
     {
362
-        if (is_array($course->resources)){
362
+        if (is_array($course->resources)) {
363 363
 			foreach ($course->resources as $type => $resources) {
364 364
 				if (count($resources) > 0) {
365
-					switch($type) {
365
+					switch ($type) {
366 366
 						case RESOURCE_SCORM:
367 367
 							foreach ($resources as $id => $resource) {
368 368
 								echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 			if (is_array($resource)) {
409 409
 				$resource = array_keys($resource);
410 410
 
411
-				foreach	($resource as $resource_item) {
411
+				foreach ($resource as $resource_item) {
412 412
 
413 413
 					$condition_session = '';
414 414
 					if (!empty($session_id)) {
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
                                         tool = '".RESOURCE_DOCUMENT."' AND
445 445
                                         ref = $resource_item ";
446 446
                             $res = Database::query($sql);
447
-                            $all_properties = array ();
448
-                            while ($item_property = Database::fetch_array($res,'ASSOC')) {
447
+                            $all_properties = array();
448
+                            while ($item_property = Database::fetch_array($res, 'ASSOC')) {
449 449
                                 $all_properties[] = $item_property;
450 450
                             }
451 451
                             $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 
461 461
 				switch ($type) {
462 462
 					case RESOURCE_SURVEYQUESTION:
463
-						foreach($resources as $id => $obj) {
463
+						foreach ($resources as $id => $obj) {
464 464
 						    if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
465 465
                                 is_array($_POST['resource'][RESOURCE_SURVEY]) &&
466 466
                                 !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                                 ) {
536 536
 									foreach ($documents as $id_to_check => $post_value) {
537 537
 										$obj_to_check = $resources[$id_to_check];
538
-										$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
538
+										$shared_path_part = substr($obj_to_check->path, 0, strlen($obj->path));
539 539
 										if ($id_to_check != $id && $obj->path == $shared_path_part) {
540 540
 											$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
541 541
 											break;
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 								$resource_is_used_elsewhere = $course->is_linked_resource($obj);
550 550
 								// check if document is in a quiz (audio/video)
551 551
 								if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
552
-									foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
552
+									foreach ($course->resources[RESOURCE_QUIZ] as $quiz) {
553 553
                                         $quiz = $quiz->obj;
554 554
 										if (isset($quiz->media) && $quiz->media == $id) {
555 555
 											$resource_is_used_elsewhere = true;
@@ -618,15 +618,15 @@  discard block
 block discarded – undo
618 618
 		<?php
619 619
 
620 620
 		//get destination course title
621
-		if(!empty($hidden_fields['destination_course'])) {
621
+		if (!empty($hidden_fields['destination_course'])) {
622 622
              if (!empty($hidden_fields['destination_session'])) {
623
-                 $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
623
+                 $sessionTitle = ' ('.api_get_session_name($hidden_fields['destination_session']).')';
624 624
              } else {
625 625
                  $sessionTitle = null;
626 626
              }
627 627
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
628 628
 			echo '<h3>';
629
-				echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
629
+				echo get_lang('DestinationCourse').' : '.$course_infos['title'].$sessionTitle;
630 630
 			echo '</h3>';
631 631
 		}
632 632
 
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
635 635
 		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.api_get_path(WEB_CODE_PATH).'img/progress_bar.gif\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
636 636
 		echo '<input type="hidden" name="action" value="course_select_form"/>';
637
-		foreach ($list_course as $course){
637
+		foreach ($list_course as $course) {
638 638
 			foreach ($course->resources as $type => $resources) {
639 639
 				if (count($resources) > 0) {
640 640
 					echo '<img id="img_'.$course->code.'" src="../img/1.gif" onclick="javascript:exp('."'$course->code'".');" />';
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 		if ($avoid_serialize) {
663 663
 			//Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
664 664
 			// this is a known issue of serialize
665
-			$course->resources['document']= null;
665
+			$course->resources['document'] = null;
666 666
 		}
667 667
 		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
668 668
 		if (is_array($hidden_fields)) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -527,14 +527,15 @@
 block discarded – undo
527 527
 						// Mark folders to import which are not selected by the user to import,
528 528
 						// but in which a document was selected.
529 529
 						$documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
530
-						if (!empty($resources) && is_array($resources))
531
-							foreach ($resources as $id => $obj) {
530
+						if (!empty($resources) && is_array($resources)) {
531
+													foreach ($resources as $id => $obj) {
532 532
 								if (isset($obj->file_type) && $obj->file_type == 'folder' &&
533 533
                                     !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) &&
534 534
                                     is_array($documents)
535 535
                                 ) {
536 536
 									foreach ($documents as $id_to_check => $post_value) {
537 537
 										$obj_to_check = $resources[$id_to_check];
538
+						}
538 539
 										$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
539 540
 										if ($id_to_check != $id && $obj->path == $shared_path_part) {
540 541
 											$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
Please login to merge, or discard this patch.
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class CourseSelectForm
13 13
 {
14
-	/**
15
-	 * Display the form
16
-	 * @param array $hidden_fields Hidden fields to add to the form.
17
-	 * @param boolean the document array will be serialize. This is used in the course_copy.php file
18
-	 */
19
-	public static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
14
+    /**
15
+     * Display the form
16
+     * @param array $hidden_fields Hidden fields to add to the form.
17
+     * @param boolean the document array will be serialize. This is used in the course_copy.php file
18
+     */
19
+    public static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
20 20
     {
21 21
         global $charset;
22 22
         $resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
@@ -134,50 +134,50 @@  discard block
 block discarded – undo
134 134
 		</script>
135 135
 		<?php
136 136
 
137
-		//get destination course title
138
-		if (!empty($hidden_fields['destination_course'])) {
137
+        //get destination course title
138
+        if (!empty($hidden_fields['destination_course'])) {
139 139
             $sessionTitle = !empty($hidden_fields['destination_session']) ? ' (' . api_get_session_name(
140 140
                 $hidden_fields['destination_session']
141 141
             ) . ')' : null;
142 142
 
143 143
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
144
-			echo '<h3>';
145
-			echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
146
-			echo '</h3>';
147
-		}
144
+            echo '<h3>';
145
+            echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
146
+            echo '</h3>';
147
+        }
148 148
         echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
149
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
149
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
150 150
         $icon = Display::returnIconPath('myprogress_bar.gif');
151
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
152
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
151
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
152
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
153 153
 
154
-		if (!empty($hidden_fields['destination_course']) &&
154
+        if (!empty($hidden_fields['destination_course']) &&
155 155
             !empty($hidden_fields['origin_course']) &&
156 156
             !empty($hidden_fields['destination_session']) &&
157 157
             !empty($hidden_fields['origin_session'])
158 158
         ) {
159
-			echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
160
-			echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
161
-			echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
162
-			echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
163
-		}
159
+            echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
160
+            echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
161
+            echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
162
+            echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
163
+        }
164 164
 
165
-		$element_count = 0;
165
+        $element_count = 0;
166 166
         $forum_categories = array();
167 167
         $forums = array();
168 168
         $forum_topics = array();
169 169
 
170 170
         echo '<p>';
171
-		echo get_lang('SelectResources');
172
-		echo '</p>';
171
+        echo get_lang('SelectResources');
172
+        echo '</p>';
173 173
 
174 174
         Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
175 175
 
176 176
         foreach ($course->resources as $type => $resources) {
177 177
             if (count($resources) > 0) {
178
-				switch ($type) {
179
-					//Resources to avoid
180
-					case RESOURCE_FORUMCATEGORY:
178
+                switch ($type) {
179
+                    //Resources to avoid
180
+                    case RESOURCE_FORUMCATEGORY:
181 181
                         foreach ($resources as $id => $resource) {
182 182
                             $forum_categories[$id] = $resource;
183 183
                         }
@@ -196,33 +196,33 @@  discard block
 block discarded – undo
196 196
                         $element_count++;
197 197
                         break;
198 198
                     case RESOURCE_LINKCATEGORY:
199
-					case RESOURCE_FORUMPOST:
200
-					case RESOURCE_QUIZQUESTION:
201
-					case RESOURCE_SURVEYQUESTION:
202
-					case RESOURCE_SURVEYINVITATION:
203
-					case RESOURCE_SCORM:
204
-						break;
199
+                    case RESOURCE_FORUMPOST:
200
+                    case RESOURCE_QUIZQUESTION:
201
+                    case RESOURCE_SURVEYQUESTION:
202
+                    case RESOURCE_SURVEYINVITATION:
203
+                    case RESOURCE_SCORM:
204
+                        break;
205 205
                     default :
206
-						echo '<img id="img_'.$type.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$type'".');" />&nbsp;';
207
-						echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
208
-						echo '<div id="div_'.$type.'">';
209
-						if ($type == RESOURCE_LEARNPATH) {
210
-    						Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
211
-    						Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
212
-						}
213
-						if ($type == RESOURCE_DOCUMENT) {
206
+                        echo '<img id="img_'.$type.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$type'".');" />&nbsp;';
207
+                        echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
208
+                        echo '<div id="div_'.$type.'">';
209
+                        if ($type == RESOURCE_LEARNPATH) {
210
+                            Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
211
+                            Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
212
+                        }
213
+                        if ($type == RESOURCE_DOCUMENT) {
214 214
                             if (api_get_setting('show_glossary_in_documents') != 'none') {
215 215
                                 Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
216 216
                             }
217
-						}
217
+                        }
218 218
 
219
-						echo '<blockquote>';
219
+                        echo '<blockquote>';
220 220
                         echo '<div class="btn-group">';
221
-						echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
221
+                        echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
222 222
                         echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
223
-						echo '</div><br />';
223
+                        echo '</div><br />';
224 224
 
225
-						foreach ($resources as $id => $resource) {
225
+                        foreach ($resources as $id => $resource) {
226 226
                             if ($resource) {
227 227
                                 Coursecopy\Resource::setClassType($resource);
228 228
                                 echo '<label class="checkbox">';
@@ -230,14 +230,14 @@  discard block
 block discarded – undo
230 230
                                 $resource->show();
231 231
                                 echo '</label>';
232 232
                             }
233
-						}
234
-						echo '</blockquote>';
235
-						echo '</div>';
236
-						echo '<script language="javascript">exp('."'$type'".')</script>';
237
-						$element_count++;
233
+                        }
234
+                        echo '</blockquote>';
235
+                        echo '</div>';
236
+                        echo '<script language="javascript">exp('."'$type'".')</script>';
237
+                        $element_count++;
238 238
                 }
239
-			}
240
-		}
239
+            }
240
+        }
241 241
 
242 242
         //Fixes forum order
243 243
         if (!empty($forum_categories)) {
@@ -293,65 +293,65 @@  discard block
 block discarded – undo
293 293
             echo '<script language="javascript">exp('."'$type'".')</script>';
294 294
         }
295 295
 
296
-		if ($avoid_serialize) {
297
-			/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
296
+        if ($avoid_serialize) {
297
+            /*Documents are avoided due the huge amount of memory that the serialize php function "eats"
298 298
 			(when there are directories with hundred/thousand of files) */
299
-			// this is a known issue of serialize
300
-			$course->resources['document']= null;
301
-		}
299
+            // this is a known issue of serialize
300
+            $course->resources['document']= null;
301
+        }
302 302
 
303
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
303
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
304 304
 
305
-		if (is_array($hidden_fields)) {
306
-			foreach ($hidden_fields as $key => $value) {
307
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
308
-			}
309
-		}
305
+        if (is_array($hidden_fields)) {
306
+            foreach ($hidden_fields as $key => $value) {
307
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
308
+            }
309
+        }
310 310
 
311 311
         $recycleOption = isset($_POST['recycle_option']) ? true : false;
312 312
 
313
-		if (empty($element_count)) {
314
-		    Display::display_warning_message(get_lang('NoDataAvailable'));
315
-		} else {
316
-    		if (!empty($hidden_fields['destination_session'])) {
317
-    			echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
313
+        if (empty($element_count)) {
314
+            Display::display_warning_message(get_lang('NoDataAvailable'));
315
+        } else {
316
+            if (!empty($hidden_fields['destination_session'])) {
317
+                echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
318 318
                     get_lang('Ok').'</button>';
319
-    		} else {
319
+            } else {
320 320
                 if ($recycleOption) {
321 321
                     echo '<br /><button class="save" type="submit">'.
322 322
                         get_lang('Ok').'</button>';
323 323
                 } else {
324
-    			    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
324
+                    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
325 325
                     get_lang('Ok').'</button>';
326 326
                 }
327
-    		}
328
-		}
327
+            }
328
+        }
329 329
 
330
-		CourseSelectForm :: display_hidden_quiz_questions($course);
331
-		CourseSelectForm :: display_hidden_scorm_directories($course);
332
-		echo '</form>';
333
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
334
-	}
330
+        CourseSelectForm :: display_hidden_quiz_questions($course);
331
+        CourseSelectForm :: display_hidden_scorm_directories($course);
332
+        echo '</form>';
333
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
334
+    }
335 335
 
336 336
     /**
337 337
      * @param $course
338 338
      */
339 339
     static function display_hidden_quiz_questions($course)
340 340
     {
341
-		if(is_array($course->resources)){
342
-			foreach ($course->resources as $type => $resources) {
343
-				if (count($resources) > 0) {
344
-					switch ($type) {
345
-						case RESOURCE_QUIZQUESTION:
346
-							foreach ($resources as $id => $resource) {
347
-								echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
348
-							}
349
-							break;
350
-					}
351
-				}
352
-			}
353
-		}
354
-	}
341
+        if(is_array($course->resources)){
342
+            foreach ($course->resources as $type => $resources) {
343
+                if (count($resources) > 0) {
344
+                    switch ($type) {
345
+                        case RESOURCE_QUIZQUESTION:
346
+                            foreach ($resources as $id => $resource) {
347
+                                echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
348
+                            }
349
+                            break;
350
+                    }
351
+                }
352
+            }
353
+        }
354
+    }
355 355
 
356 356
     /**
357 357
      * @param $course
@@ -359,30 +359,30 @@  discard block
 block discarded – undo
359 359
     static function display_hidden_scorm_directories($course)
360 360
     {
361 361
         if (is_array($course->resources)){
362
-			foreach ($course->resources as $type => $resources) {
363
-				if (count($resources) > 0) {
364
-					switch($type) {
365
-						case RESOURCE_SCORM:
366
-							foreach ($resources as $id => $resource) {
367
-								echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
368
-							}
369
-							break;
370
-					}
371
-				}
372
-			}
373
-		}
374
-	}
362
+            foreach ($course->resources as $type => $resources) {
363
+                if (count($resources) > 0) {
364
+                    switch($type) {
365
+                        case RESOURCE_SCORM:
366
+                            foreach ($resources as $id => $resource) {
367
+                                echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
368
+                            }
369
+                            break;
370
+                    }
371
+                }
372
+            }
373
+        }
374
+    }
375 375
 
376
-	/**
377
-	 * Get the posted course
378
-	 * @param string $from who calls the function?
376
+    /**
377
+     * Get the posted course
378
+     * @param string $from who calls the function?
379 379
      * It can be copy_course, create_backup, import_backup or recycle_course
380 380
      * @param int $session_id
381 381
      * @param string $course_code
382
-	 * @return course The course-object with all resources selected by the user
383
-	 * in the form given by display_form(...)
384
-	 */
385
-	public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
382
+     * @return course The course-object with all resources selected by the user
383
+     * in the form given by display_form(...)
384
+     */
385
+    public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
386 386
     {
387 387
         $course = null;
388 388
 
@@ -392,30 +392,30 @@  discard block
 block discarded – undo
392 392
             return false;
393 393
         }
394 394
 
395
-		// Create the resource DOCUMENT objects
396
-		// Loading the results from the checkboxes of ethe javascript
397
-		$resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
395
+        // Create the resource DOCUMENT objects
396
+        // Loading the results from the checkboxes of ethe javascript
397
+        $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
398 398
 
399
-		$course_info = api_get_course_info($course_code);
400
-		$table_doc = Database::get_course_table(TABLE_DOCUMENT);
401
-		$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
402
-		$course_id = $course_info['real_id'];
399
+        $course_info = api_get_course_info($course_code);
400
+        $table_doc = Database::get_course_table(TABLE_DOCUMENT);
401
+        $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
402
+        $course_id = $course_info['real_id'];
403 403
 
404
-		/* Searching the documents resource that have been set to null because
404
+        /* Searching the documents resource that have been set to null because
405 405
         $avoid_serialize is true in the display_form() function*/
406
-		if ($from == 'copy_course') {
407
-			if (is_array($resource)) {
408
-				$resource = array_keys($resource);
406
+        if ($from == 'copy_course') {
407
+            if (is_array($resource)) {
408
+                $resource = array_keys($resource);
409 409
 
410
-				foreach	($resource as $resource_item) {
410
+                foreach	($resource as $resource_item) {
411 411
 
412
-					$condition_session = '';
413
-					if (!empty($session_id)) {
414
-						$session_id = intval($session_id);
415
-						$condition_session = ' AND d.session_id ='.$session_id;
416
-					}
412
+                    $condition_session = '';
413
+                    if (!empty($session_id)) {
414
+                        $session_id = intval($session_id);
415
+                        $condition_session = ' AND d.session_id ='.$session_id;
416
+                    }
417 417
 
418
-					$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
418
+                    $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
419 419
 							FROM '.$table_doc.' d, '.$table_prop.' p
420 420
 							WHERE
421 421
 							    d.c_id = '.$course_id.' AND
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
                                 p.ref = d.id AND p.visibility != 2 AND
425 425
                                 d.id = '.$resource_item.$condition_session.'
426 426
 							ORDER BY path';
427
-					$db_result = Database::query($sql);
428
-					while ($obj = Database::fetch_object($db_result)) {
427
+                    $db_result = Database::query($sql);
428
+                    while ($obj = Database::fetch_object($db_result)) {
429 429
                         $doc = new Document(
430 430
                             $obj->id,
431 431
                             $obj->path,
@@ -449,25 +449,25 @@  discard block
 block discarded – undo
449 449
                             }
450 450
                             $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
451 451
                         }
452
-					}
453
-				}
454
-			}
455
-		}
452
+                    }
453
+                }
454
+            }
455
+        }
456 456
 
457
-		if (is_array($course->resources)) {
458
-			foreach ($course->resources as $type => $resources) {
457
+        if (is_array($course->resources)) {
458
+            foreach ($course->resources as $type => $resources) {
459 459
 
460
-				switch ($type) {
461
-					case RESOURCE_SURVEYQUESTION:
462
-						foreach($resources as $id => $obj) {
463
-						    if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
460
+                switch ($type) {
461
+                    case RESOURCE_SURVEYQUESTION:
462
+                        foreach($resources as $id => $obj) {
463
+                            if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
464 464
                                 is_array($_POST['resource'][RESOURCE_SURVEY]) &&
465 465
                                 !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))
466 466
                             ) {
467
-								unset($course->resources[$type][$id]);
468
-							}
469
-						}
470
-						break;
467
+                                unset($course->resources[$type][$id]);
468
+                            }
469
+                        }
470
+                        break;
471 471
                     case RESOURCE_FORUMTOPIC:
472 472
                     case RESOURCE_FORUMPOST:
473 473
                        //Add post from topic
@@ -519,62 +519,62 @@  discard block
 block discarded – undo
519 519
                                 }
520 520
                             }
521 521
                         }
522
-					case RESOURCE_LINKCATEGORY :
523
-					case RESOURCE_FORUMCATEGORY :
524
-					case RESOURCE_QUIZQUESTION :
525
-					case RESOURCE_DOCUMENT:
526
-						// Mark folders to import which are not selected by the user to import,
527
-						// but in which a document was selected.
528
-						$documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
529
-						if (!empty($resources) && is_array($resources))
530
-							foreach ($resources as $id => $obj) {
531
-								if (isset($obj->file_type) && $obj->file_type == 'folder' &&
522
+                    case RESOURCE_LINKCATEGORY :
523
+                    case RESOURCE_FORUMCATEGORY :
524
+                    case RESOURCE_QUIZQUESTION :
525
+                    case RESOURCE_DOCUMENT:
526
+                        // Mark folders to import which are not selected by the user to import,
527
+                        // but in which a document was selected.
528
+                        $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
529
+                        if (!empty($resources) && is_array($resources))
530
+                            foreach ($resources as $id => $obj) {
531
+                                if (isset($obj->file_type) && $obj->file_type == 'folder' &&
532 532
                                     !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) &&
533 533
                                     is_array($documents)
534 534
                                 ) {
535
-									foreach ($documents as $id_to_check => $post_value) {
536
-										$obj_to_check = $resources[$id_to_check];
537
-										$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
538
-										if ($id_to_check != $id && $obj->path == $shared_path_part) {
539
-											$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
540
-											break;
541
-										}
542
-									}
543
-								}
544
-							}
545
-					default :
546
-						if (!empty($resources) && is_array($resources)) {
547
-							foreach ($resources as $id => $obj) {
548
-								$resource_is_used_elsewhere = $course->is_linked_resource($obj);
549
-								// check if document is in a quiz (audio/video)
550
-								if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
551
-									foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
535
+                                    foreach ($documents as $id_to_check => $post_value) {
536
+                                        $obj_to_check = $resources[$id_to_check];
537
+                                        $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
538
+                                        if ($id_to_check != $id && $obj->path == $shared_path_part) {
539
+                                            $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
540
+                                            break;
541
+                                        }
542
+                                    }
543
+                                }
544
+                            }
545
+                    default :
546
+                        if (!empty($resources) && is_array($resources)) {
547
+                            foreach ($resources as $id => $obj) {
548
+                                $resource_is_used_elsewhere = $course->is_linked_resource($obj);
549
+                                // check if document is in a quiz (audio/video)
550
+                                if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
551
+                                    foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
552 552
                                         $quiz = $quiz->obj;
553
-										if (isset($quiz->media) && $quiz->media == $id) {
554
-											$resource_is_used_elsewhere = true;
555
-										}
556
-									}
557
-								}
558
-								if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
559
-									unset($course->resources[$type][$id]);
560
-								}
561
-							}
562
-						}
563
-				}
564
-			}
565
-		}
566
-
567
-		return $course;
568
-	}
569
-
570
-	/**
571
-	 * Display the form session export
572
-	 * @param array $hidden_fields Hidden fields to add to the form.
573
-	 * @param boolean the document array will be serialize. This is used in the course_copy.php file
574
-	 */
575
-	 public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
576
-     {
577
-         ?>
553
+                                        if (isset($quiz->media) && $quiz->media == $id) {
554
+                                            $resource_is_used_elsewhere = true;
555
+                                        }
556
+                                    }
557
+                                }
558
+                                if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
559
+                                    unset($course->resources[$type][$id]);
560
+                                }
561
+                            }
562
+                        }
563
+                }
564
+            }
565
+        }
566
+
567
+        return $course;
568
+    }
569
+
570
+    /**
571
+     * Display the form session export
572
+     * @param array $hidden_fields Hidden fields to add to the form.
573
+     * @param boolean the document array will be serialize. This is used in the course_copy.php file
574
+     */
575
+        public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
576
+        {
577
+            ?>
578 578
 		<script>
579 579
 			function exp(item) {
580 580
 				el = document.getElementById('div_'+item);
@@ -616,65 +616,65 @@  discard block
 block discarded – undo
616 616
 		</script>
617 617
 		<?php
618 618
 
619
-		//get destination course title
620
-		if(!empty($hidden_fields['destination_course'])) {
621
-             if (!empty($hidden_fields['destination_session'])) {
622
-                 $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
623
-             } else {
624
-                 $sessionTitle = null;
625
-             }
619
+        //get destination course title
620
+        if(!empty($hidden_fields['destination_course'])) {
621
+                if (!empty($hidden_fields['destination_session'])) {
622
+                    $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
623
+                } else {
624
+                    $sessionTitle = null;
625
+                }
626 626
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
627
-			echo '<h3>';
628
-				echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
629
-			echo '</h3>';
630
-		}
627
+            echo '<h3>';
628
+                echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
629
+            echo '</h3>';
630
+        }
631 631
 
632
-		echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
633
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
632
+        echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
633
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
634 634
         $icon = Display::returnIconPath('progress_bar.gif');
635
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
636
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
637
-		foreach ($list_course as $course){
638
-			foreach ($course->resources as $type => $resources) {
639
-				if (count($resources) > 0) {
640
-					echo '<img id="img_'.$course->code.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$course->code'".');" />';
641
-					echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
642
-					echo '<div id="div_'.$course->code.'">';
643
-					echo '<blockquote>';
635
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
636
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
637
+        foreach ($list_course as $course){
638
+            foreach ($course->resources as $type => $resources) {
639
+                if (count($resources) > 0) {
640
+                    echo '<img id="img_'.$course->code.'" src="'.Display::returnIconPath('1.gif').'" onclick="javascript:exp('."'$course->code'".');" />';
641
+                    echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
642
+                    echo '<div id="div_'.$course->code.'">';
643
+                    echo '<blockquote>';
644 644
 
645 645
                     echo '<div class="btn-group">';
646
-					echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
646
+                    echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
647 647
                     echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',false);\" >".get_lang('None')."</a>";
648
-					echo '</div><br />';
648
+                    echo '</div><br />';
649 649
 
650
-					foreach ($resources as $id => $resource) {
651
-						echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
650
+                    foreach ($resources as $id => $resource) {
651
+                        echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
652 652
                         echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>';
653
-						$resource->show();
654
-						echo '</label>';
655
-					}
656
-					echo '</blockquote>';
657
-					echo '</div>';
658
-					echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
659
-				}
660
-			}
661
-		}
662
-		if ($avoid_serialize) {
663
-			//Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
664
-			// this is a known issue of serialize
665
-			$course->resources['document']= null;
666
-		}
667
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
668
-		if (is_array($hidden_fields)) {
669
-			foreach ($hidden_fields as $key => $value) {
670
-				echo "\n";
671
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
672
-			}
673
-		}
674
-		echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
675
-		CourseSelectForm :: display_hidden_quiz_questions($course);
676
-		CourseSelectForm :: display_hidden_scorm_directories($course);
677
-		echo '</form>';
678
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
679
-	}
653
+                        $resource->show();
654
+                        echo '</label>';
655
+                    }
656
+                    echo '</blockquote>';
657
+                    echo '</div>';
658
+                    echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
659
+                }
660
+            }
661
+        }
662
+        if ($avoid_serialize) {
663
+            //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
664
+            // this is a known issue of serialize
665
+            $course->resources['document']= null;
666
+        }
667
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
668
+        if (is_array($hidden_fields)) {
669
+            foreach ($hidden_fields as $key => $value) {
670
+                echo "\n";
671
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
672
+            }
673
+        }
674
+        echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
675
+        CourseSelectForm :: display_hidden_quiz_questions($course);
676
+        CourseSelectForm :: display_hidden_scorm_directories($course);
677
+        echo '</form>';
678
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
679
+    }
680 680
 }
Please login to merge, or discard this patch.
main/coursecopy/classes/Course.class.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
             if (is_array($resources)) {
41 41
                 foreach ($resources as $resource) {
42 42
                     Coursecopy\Resource::setClassType($resource);
43
-                    if ($resource->links_to($resource_to_check) ) {
43
+                    if ($resource->links_to($resource_to_check)) {
44 44
                         return true;
45 45
                     }
46
-                    if ($type == RESOURCE_LEARNPATH && get_class($resource)=='CourseCopyLearnpath') {
46
+                    if ($type == RESOURCE_LEARNPATH && get_class($resource) == 'CourseCopyLearnpath') {
47 47
                         if ($resource->has_item($resource_to_check)) {
48 48
                             return true;
49 49
                         }
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public function has_resources($resource_type = null)
72 72
     {
73
-        if( $resource_type != null) {
73
+        if ($resource_type != null) {
74 74
             return isset($this->resources[$resource_type]) && is_array($this->resources[$resource_type]) && (count(
75 75
                     $this->resources[$resource_type]
76 76
                 ) > 0);
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
                             $description = $resource->content;
178 178
                             break;
179 179
                         case RESOURCE_THEMATIC:
180
-                            $title 			= $resource->title;
181
-                            $description 	= $resource->content;
180
+                            $title = $resource->title;
181
+                            $description = $resource->content;
182 182
                             break;
183 183
                         case RESOURCE_ATTENDANCE:
184
-                            $title 			= $resource->params['name'];
185
-                            $description 	= $resource->params['description'];
184
+                            $title = $resource->params['name'];
185
+                            $description = $resource->params['description'];
186 186
                             break;
187 187
                         case RESOURCE_WORK:
188 188
                             $title = $resource->title;
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -326,9 +326,9 @@  discard block
 block discarded – undo
326 326
     }
327 327
 
328 328
     /**
329
-    * Serialize the course with the best serializer available
330
-    * @return string
331
-    */
329
+     * Serialize the course with the best serializer available
330
+     * @return string
331
+     */
332 332
     public static function serialize($course)
333 333
     {
334 334
         if (extension_loaded('igbinary')) {
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
     }
340 340
 
341 341
     /**
342
-    * Unserialize the course with the best serializer available
343
-    * @param string $course
344
-    */
342
+     * Unserialize the course with the best serializer available
343
+     * @param string $course
344
+     */
345 345
     public static function unserialize($course)
346 346
     {
347 347
         if (extension_loaded('igbinary')) {
Please login to merge, or discard this patch.
main/coursecopy/classes/CourseRecycler.class.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
     }
620 620
 
621 621
     /**
622
-    * Recycle Thematics
623
-    */
622
+     * Recycle Thematics
623
+     */
624 624
     public function recycle_thematic($session_id = 0)
625 625
     {
626 626
         if ($this->course->has_resources(RESOURCE_THEMATIC)) {
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
     }
686 686
 
687 687
     /**
688
-    * Recycle Attendances
689
-    */
688
+     * Recycle Attendances
689
+     */
690 690
     public function recycle_attendance($session_id = 0)
691 691
     {
692 692
         if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     public function recycle_glossary()
161 161
     {
162 162
         if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
163
-            $table_glossary	= Database::get_course_table(TABLE_GLOSSARY);
163
+            $table_glossary = Database::get_course_table(TABLE_GLOSSARY);
164 164
             $ids = implode(',', array_filter(array_keys($this->course->resources[RESOURCE_GLOSSARY])));
165 165
             if (!empty($ids)) {
166 166
                 $sql = "DELETE FROM ".$table_glossary."
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
                     if (trim($learnpath->path) != '') {
557 557
                         // when $learnpath->path value is incorrect for some reason.
558 558
                         // The directory trat contains files of the SCORM package is to be deleted.
559
-                        $scorm_package_dir = realpath($this->course->path . 'scorm/' . $learnpath->path);
559
+                        $scorm_package_dir = realpath($this->course->path.'scorm/'.$learnpath->path);
560 560
                         rmdirr($scorm_package_dir);
561 561
                     }
562 562
                 }
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
             foreach ($resources[RESOURCE_THEMATIC] as $last_id => $thematic) {
633 633
                 if (is_numeric($last_id)) {
634 634
 
635
-                    foreach($thematic->thematic_advance_list as $thematic_advance) {
635
+                    foreach ($thematic->thematic_advance_list as $thematic_advance) {
636 636
                         $cond = array(
637 637
                             'id = ? AND  c_id = ?' => array(
638 638
                                 $thematic_advance['id'],
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
                         Database::delete($table_thematic_advance, $cond);
650 650
                     }
651 651
 
652
-                    foreach($thematic->thematic_plan_list as $thematic_plan) {
652
+                    foreach ($thematic->thematic_plan_list as $thematic_plan) {
653 653
                         $cond = array(
654 654
                             'id = ? AND  c_id = ?' => array(
655 655
                                 $thematic_plan['id'],
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
                         'ThematicDeleted',
679 679
                         api_get_user_id()
680 680
                     );
681
-                    Database::delete($table_thematic,$cond);
681
+                    Database::delete($table_thematic, $cond);
682 682
                 }
683 683
             }
684 684
         }
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
             $resources = $this->course->resources;
697 697
             foreach ($resources[RESOURCE_ATTENDANCE] as $last_id => $obj) {
698 698
                 if (is_numeric($last_id)) {
699
-                    foreach($obj->attendance_calendar as $attendance_calendar) {
699
+                    foreach ($obj->attendance_calendar as $attendance_calendar) {
700 700
                         $cond = array('id = ? AND c_id = ? '=>array($attendance_calendar['id'], $this->course_id));
701 701
                         Database::delete($table_attendance_calendar, $cond);
702 702
                     }
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
     public function recycle_work($session_id = 0)
721 721
     {
722 722
         if ($this->course->has_resources(RESOURCE_WORK)) {
723
-            $table_work          = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
723
+            $table_work = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
724 724
             $table_work_assignment = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
725 725
 
726 726
             $resources = $this->course->resources;
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
     }
39 39
 
40 40
     /**
41
-     * @return bool
41
+     * @return false|null
42 42
      */
43 43
     public function create_user_folder()
44 44
     {
Please login to merge, or discard this patch.
main/coursecopy/classes/Document.class.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 
4 4
 require_once 'Resource.class.php';
5 5
 
6
-define('DOCUMENT','file');
7
-define('FOLDER','folder');
6
+define('DOCUMENT', 'file');
7
+define('FOLDER', 'folder');
8 8
 
9 9
 /**
10 10
  * Class Document
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     public function __construct($id, $path, $comment, $title, $file_type, $size)
32 32
     {
33 33
         parent::__construct($id, RESOURCE_DOCUMENT);
34
-        $this->path = 'document' . $path;
34
+        $this->path = 'document'.$path;
35 35
         $this->comment = $comment;
36 36
         $this->title = $title;
37 37
         $this->file_type = $file_type;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         echo preg_replace('@^document@', '', $this->path);
48 48
         if (!empty($this->title)) {
49 49
             if (strpos($this->path, $this->title) === false) {
50
-                echo " - " . $this->title;
50
+                echo " - ".$this->title;
51 51
             }
52 52
         }
53 53
     }
Please login to merge, or discard this patch.
main/coursecopy/classes/ForumTopic.class.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,6 +47,6 @@
 block discarded – undo
47 47
             $user_info = api_get_user_info($this->obj->thread_poster_id);
48 48
             $extra = $user_info['complete_name'].', '.$extra;
49 49
         }
50
-        echo $this->obj->thread_title . ' (' . $extra . ')';
50
+        echo $this->obj->thread_title.' ('.$extra.')';
51 51
     }
52 52
 }
Please login to merge, or discard this patch.
main/coursecopy/classes/CourseRestorer.class.php 4 patches
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
                                             $this->course->backup_path,
521 521
                                             $this->course->info['path']
522 522
                                         );
523
-                                        file_put_contents($path.$document->path,$content);
523
+                                        file_put_contents($path.$document->path, $content);
524 524
                                     }
525 525
 
526 526
                                     $params = [
@@ -564,14 +564,14 @@  discard block
 block discarded – undo
564 564
 								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
565 565
 								$file_exists = file_exists($path.$new_file_name);
566 566
 								while ($file_exists) {
567
-									$i ++;
567
+									$i++;
568 568
 									$new_file_name = $file_name_no_ext.'_'.$i.$ext;
569 569
 									$file_exists = file_exists($path.$new_file_name);
570 570
 								}
571 571
 
572 572
 								if (!empty($session_id)) {
573 573
 
574
-									$document_path = explode('/',$document->path,3);
574
+									$document_path = explode('/', $document->path, 3);
575 575
 									$course_path = $path;
576 576
 									$orig_base_folder = $document_path[1];
577 577
 									$orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 
590 590
 										$folder_exists = file_exists($new_base_path);
591 591
 										if ($folder_exists) {
592
-											$_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
592
+											$_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session
593 593
 											$x = '';
594 594
 											while ($folder_exists) {
595 595
 												$x = $x + 1;
@@ -609,9 +609,9 @@  discard block
 block discarded – undo
609 609
 											$new_base_path = $_SESSION['new_base_path'];
610 610
 										}
611 611
 
612
-										$dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
613
-										$basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
614
-										$base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
612
+										$dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
613
+										$basedir_dest_path 	= dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
614
+										$base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document"
615 615
 
616 616
 										$path_title = '/'.$new_base_foldername.'/'.$document_path[2];
617 617
 
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
                                         //Replace old course code with the new destination code see BT#1985
632 632
                                         if (file_exists($dest_document_path)) {
633 633
                                             $file_info = pathinfo($dest_document_path);
634
-                                            if (in_array($file_info['extension'], array('html','htm'))) {
634
+                                            if (in_array($file_info['extension'], array('html', 'htm'))) {
635 635
                                                 $content = file_get_contents($dest_document_path);
636 636
                                                 if (UTF8_CONVERT) {
637 637
                                                     $content = utf8_encode($content);
@@ -687,8 +687,8 @@  discard block
 block discarded – undo
687 687
                                         //Replace old course code with the new destination code see BT#1985
688 688
                                         if (file_exists($path.$new_file_name)) {
689 689
                                             $file_info = pathinfo($path.$new_file_name);
690
-                                            if (in_array($file_info['extension'], array('html','htm'))) {
691
-                                                $content    = file_get_contents($path.$new_file_name);
690
+                                            if (in_array($file_info['extension'], array('html', 'htm'))) {
691
+                                                $content = file_get_contents($path.$new_file_name);
692 692
                                                 if (UTF8_CONVERT) {
693 693
                                                     $content = utf8_encode($content);
694 694
                                                 }
@@ -741,8 +741,8 @@  discard block
 block discarded – undo
741 741
                                     //Replace old course code with the new destination code see BT#1985
742 742
                                     if (file_exists($path.$new_file_name)) {
743 743
                                         $file_info = pathinfo($path.$new_file_name);
744
-                                        if (in_array($file_info['extension'], array('html','htm'))) {
745
-                                            $content    = file_get_contents($path.$new_file_name);
744
+                                        if (in_array($file_info['extension'], array('html', 'htm'))) {
745
+                                            $content = file_get_contents($path.$new_file_name);
746 746
                                             if (UTF8_CONVERT) {
747 747
                                                 $content = utf8_encode($content);
748 748
                                             }
@@ -805,8 +805,8 @@  discard block
 block discarded – undo
805 805
                             //Replace old course code with the new destination code see BT#1985
806 806
                             if (file_exists($path.$document->path)) {
807 807
                                 $file_info = pathinfo($path.$document->path);
808
-                                if (in_array($file_info['extension'], array('html','htm'))) {
809
-                                    $content    = file_get_contents($path.$document->path);
808
+                                if (in_array($file_info['extension'], array('html', 'htm'))) {
809
+                                    $content = file_get_contents($path.$document->path);
810 810
                                     if (UTF8_CONVERT) {
811 811
                                         $content = utf8_encode($content);
812 812
                                     }
@@ -896,8 +896,8 @@  discard block
 block discarded – undo
896 896
 						case FILE_OVERWRITE:
897 897
 							rmdirr($path.$document->path);
898 898
                             copyDirTo(
899
-                                $this->course->backup_path . '/' . $document->path,
900
-                                $path . dirname($document->path),
899
+                                $this->course->backup_path.'/'.$document->path,
900
+                                $path.dirname($document->path),
901 901
                                 false
902 902
                             );
903 903
 							break;
@@ -919,23 +919,23 @@  discard block
 block discarded – undo
919 919
 							$file_exists = file_exists($path.$new_file_name);
920 920
 
921 921
 							while ($file_exists) {
922
-								$i ++;
922
+								$i++;
923 923
 								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
924 924
 								$file_exists = file_exists($path.$new_file_name);
925 925
 							}
926 926
 
927 927
                             rename(
928
-                                $this->course->backup_path . '/' . $document->path,
929
-                                $this->course->backup_path . '/' . $new_file_name
928
+                                $this->course->backup_path.'/'.$document->path,
929
+                                $this->course->backup_path.'/'.$new_file_name
930 930
                             );
931 931
                             copyDirTo(
932
-                                $this->course->backup_path . '/' . $new_file_name,
933
-                                $path . dirname($new_file_name),
932
+                                $this->course->backup_path.'/'.$new_file_name,
933
+                                $path.dirname($new_file_name),
934 934
                                 false
935 935
                             );
936 936
                             rename(
937
-                                $this->course->backup_path . '/' . $new_file_name,
938
-                                $this->course->backup_path . '/' . $document->path
937
+                                $this->course->backup_path.'/'.$new_file_name,
938
+                                $this->course->backup_path.'/'.$document->path
939 939
                             );
940 940
 
941 941
 							break;
@@ -943,8 +943,8 @@  discard block
 block discarded – undo
943 943
 				} else {
944 944
                     // end if file exists
945 945
                     copyDirTo(
946
-                        $this->course->backup_path . '/' . $document->path,
947
-                        $path . dirname($document->path),
946
+                        $this->course->backup_path.'/'.$document->path,
947
+                        $path.dirname($document->path),
948 948
                         false
949 949
                     );
950 950
 				}
@@ -962,7 +962,7 @@  discard block
 block discarded – undo
962 962
 			$table_forum = Database::get_course_table(TABLE_FORUM);
963 963
 			$resources = $this->course->resources;
964 964
 			foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
965
-                $params = (array)$forum->obj;
965
+                $params = (array) $forum->obj;
966 966
                 $cat_id = '';
967 967
                 if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) &&
968 968
                     isset($this->course->resources[RESOURCE_FORUMCATEGORY][$params['forum_category']])) {
@@ -1014,13 +1014,13 @@  discard block
 block discarded – undo
1014 1014
 					foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1015 1015
 						if ($topic->obj->forum_id == $id) {
1016 1016
 							$this->restore_topic($topic_id, $new_id, $sessionId);
1017
-							$forum_topics ++;
1017
+							$forum_topics++;
1018 1018
 						}
1019 1019
 					}
1020 1020
 				}
1021 1021
 				if ($forum_topics > 0) {
1022 1022
 					$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1023
-                            WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id;
1023
+                            WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int) $new_id;
1024 1024
 					Database::query($sql);
1025 1025
 				}
1026 1026
 			}
@@ -1090,13 +1090,13 @@  discard block
 block discarded – undo
1090 1090
 		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
1091 1091
 		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1092 1092
 
1093
-        $params = (array)$topic->obj;
1093
+        $params = (array) $topic->obj;
1094 1094
         $params = self::DBUTF8_array($params);
1095 1095
         $params['c_id'] = $this->destination_course_id;
1096 1096
         $params['forum_id'] = $forum_id;
1097 1097
         $params['thread_poster_id'] = $this->first_teacher_id;
1098 1098
         $params['thread_date'] = api_get_utc_datetime();
1099
-        $params['thread_close_date']  = '0000-00-00 00:00:00';
1099
+        $params['thread_close_date'] = '0000-00-00 00:00:00';
1100 1100
         $params['thread_last_post'] = 0;
1101 1101
         $params['thread_replies'] = 0;
1102 1102
         $params['thread_views'] = 0;
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
 				        FROM $link_table
1203 1203
 				        WHERE
1204 1204
 				            c_id = ".$this->destination_course_id." AND
1205
-				            category_id='" . intval($cat_id). "'";
1205
+				            category_id='" . intval($cat_id)."'";
1206 1206
 				$result = Database::query($sql);
1207 1207
     			list($max_order) = Database::fetch_array($result);
1208 1208
 
@@ -1217,7 +1217,7 @@  discard block
 block discarded – undo
1217 1217
                 $params['description'] = self::DBUTF8($link->description);
1218 1218
                 $params['category_id'] = $cat_id;
1219 1219
                 $params['on_homepage'] = $link->on_homepage;
1220
-                $params['display_order'] = $max_order+1;
1220
+                $params['display_order'] = $max_order + 1;
1221 1221
 
1222 1222
                 $id = Database::insert($link_table, $params);
1223 1223
 
@@ -1261,9 +1261,9 @@  discard block
 block discarded – undo
1261 1261
         if (is_object($link_cat) && !$link_cat->is_restored()) {
1262 1262
             $sql = "SELECT MAX(display_order) FROM  $link_cat_table
1263 1263
 			        WHERE c_id = ".$this->destination_course_id." ";
1264
-            $result=Database::query($sql);
1265
-            list($orderMax)=Database::fetch_array($result,'NUM');
1266
-            $display_order=$orderMax+1;
1264
+            $result = Database::query($sql);
1265
+            list($orderMax) = Database::fetch_array($result, 'NUM');
1266
+            $display_order = $orderMax + 1;
1267 1267
 
1268 1268
             $params['c_id'] = $this->destination_course_id;
1269 1269
             $params['category_title'] = self::DBUTF8($link_cat->title);
@@ -1639,9 +1639,9 @@  discard block
 block discarded – undo
1639 1639
                 if (!empty($quiz->sound)) {
1640 1640
                     if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
1641 1641
                         $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
1642
-                        $sql = "SELECT path FROM " . $table_doc . "
1642
+                        $sql = "SELECT path FROM ".$table_doc."
1643 1643
                                 WHERE
1644
-                                    c_id = " . $this->destination_course_id . "  AND
1644
+                                    c_id = " . $this->destination_course_id."  AND
1645 1645
                                     id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
1646 1646
 						$doc = Database::query($sql);
1647 1647
 						$doc = Database::fetch_object($doc);
@@ -1675,19 +1675,19 @@  discard block
 block discarded – undo
1675 1675
                         'random' => $quiz->random,
1676 1676
                         'active' => $quiz->active,
1677 1677
                         'sound' => self::DBUTF8($doc),
1678
-                        'max_attempt' => (int)$quiz->max_attempt,
1679
-                        'results_disabled' => (int)$quiz->results_disabled,
1678
+                        'max_attempt' => (int) $quiz->max_attempt,
1679
+                        'results_disabled' => (int) $quiz->results_disabled,
1680 1680
                         'access_condition' => $quiz->access_condition,
1681 1681
                         'start_time' => $quiz->start_time,
1682 1682
                         'pass_percentage' => $quiz->pass_percentage,
1683 1683
                         'end_time' => $quiz->end_time,
1684
-                        'feedback_type' => (int)$quiz->feedback_type,
1685
-                        'random_answers' => (int)$quiz->random_answers,
1684
+                        'feedback_type' => (int) $quiz->feedback_type,
1685
+                        'random_answers' => (int) $quiz->random_answers,
1686 1686
                         'random_by_category' => $quiz->random_by_category,
1687 1687
                         'review_answers' => $quiz->review_answers,
1688 1688
                         'propagate_neg' => $quiz->propagate_neg,
1689 1689
                         'text_when_finished' => $quiz->text_when_finished,
1690
-                        'expired_time' => (int)$quiz->expired_time,
1690
+                        'expired_time' => (int) $quiz->expired_time,
1691 1691
                     );
1692 1692
 
1693 1693
                     if ($respect_base_content) {
@@ -1723,9 +1723,9 @@  discard block
 block discarded – undo
1723 1723
                         $qid = $this->restore_quiz_question($question_id);
1724 1724
                         $question_order = $quiz->question_orders[$index] ? $quiz->question_orders[$index] : ++$order;
1725 1725
                         $sql = "INSERT IGNORE INTO $table_rel SET
1726
-                                c_id = " . $this->destination_course_id . ",
1727
-                                question_id = " . $qid . ",
1728
-                                exercice_id = " . $new_id . ",
1726
+                                c_id = ".$this->destination_course_id.",
1727
+                                question_id = " . $qid.",
1728
+                                exercice_id = " . $new_id.",
1729 1729
                                 question_order = " . $question_order;
1730 1730
                         Database::query($sql);
1731 1731
                     }
@@ -1800,7 +1800,7 @@  discard block
 block discarded – undo
1800 1800
                             $sql = "UPDATE $table_que SET
1801 1801
                                         picture = '$picture_name'
1802 1802
                                     WHERE
1803
-                                        c_id = " . $this->destination_course_id . " AND
1803
+                                        c_id = ".$this->destination_course_id." AND
1804 1804
                                         id = $new_id ";
1805 1805
                             Database::query($sql);
1806 1806
                         }
@@ -1955,7 +1955,7 @@  discard block
 block discarded – undo
1955 1955
                             }
1956 1956
                         }
1957 1957
 
1958
-                        foreach($correct_answers as $answer_id => $correct_answer) {
1958
+                        foreach ($correct_answers as $answer_id => $correct_answer) {
1959 1959
                             $params = array();
1960 1960
                             $params['correct'] = $new_options[$correct_answer];
1961 1961
                             Database::update(
@@ -1989,7 +1989,7 @@  discard block
 block discarded – undo
1989 1989
         $tab_test_category_id_old_new = array(); // used to build the quiz_question_rel_category table
1990 1990
         if ($this->course->has_resources(RESOURCE_TEST_CATEGORY)) {
1991 1991
             $resources = $this->course->resources;
1992
-            foreach ($resources[RESOURCE_TEST_CATEGORY] as $id => $CourseCopyTestcategory ) {
1992
+            foreach ($resources[RESOURCE_TEST_CATEGORY] as $id => $CourseCopyTestcategory) {
1993 1993
                 $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id;
1994 1994
                 // check if this test_category already exist in the destination BDD
1995 1995
                 // do not Database::escape_string $title and $description, it will be done later
@@ -2135,7 +2135,7 @@  discard block
 block discarded – undo
2135 2135
 							break;
2136 2136
 						case FILE_RENAME:
2137 2137
 							$survey_code = $survey->code.'_';
2138
-							$i=1;
2138
+							$i = 1;
2139 2139
 							$temp_survey_code = $survey_code.$i;
2140 2140
 							while (!$this->is_survey_code_available($temp_survey_code)) {
2141 2141
 								$temp_survey_code = $survey_code.++$i;
@@ -2167,15 +2167,15 @@  discard block
 block discarded – undo
2167 2167
 							$sql = "SELECT * FROM $table_sur
2168 2168
 							        WHERE
2169 2169
 							            c_id = ".$this->destination_course_id." AND
2170
-							            survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'";
2170
+							            survey_id='".self::DBUTF8escapestring(Database::result($result_check, 0, 0))."'";
2171 2171
 							$result = Database::query($sql);
2172
-							$survey_data = Database::fetch_array($result,'ASSOC');
2172
+							$survey_data = Database::fetch_array($result, 'ASSOC');
2173 2173
 
2174 2174
 							// if the survey is shared => also delete the shared content
2175 2175
 							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2176
-                                SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
2176
+                                SurveyManager::delete_survey($survey_data['survey_share'], true, $this->destination_course_id);
2177 2177
 							}
2178
-							SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2178
+							SurveyManager :: delete_survey($survey_data['survey_id'], false, $this->destination_course_id);
2179 2179
 
2180 2180
 							// Insert the new source survey
2181 2181
                             $new_id = Database::insert($table_sur, $params);
@@ -2251,7 +2251,7 @@  discard block
 block discarded – undo
2251 2251
 		$resources = $this->course->resources;
2252 2252
 		$question = $resources[RESOURCE_SURVEYQUESTION][$id];
2253 2253
 
2254
-		$new_id=0;
2254
+		$new_id = 0;
2255 2255
 
2256 2256
 		if (is_object($question)) {
2257 2257
 			if ($question->is_restored()) {
@@ -2356,14 +2356,14 @@  discard block
 block discarded – undo
2356 2356
 
2357 2357
 				// Adding the author's image
2358 2358
 				if (!empty($lp->preview_image)) {
2359
-					$new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2359
+					$new_filename = uniqid('').substr($lp->preview_image, strlen($lp->preview_image) - 7, strlen($lp->preview_image));
2360 2360
 					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2361 2361
 						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2362 2362
 						//$copy_result = true;
2363 2363
 						if ($copy_result) {
2364 2364
 							$lp->preview_image = $new_filename;
2365 2365
 						} else {
2366
-							$lp->preview_image ='';
2366
+							$lp->preview_image = '';
2367 2367
 						}
2368 2368
 					}
2369 2369
 				}
@@ -2524,20 +2524,20 @@  discard block
 block discarded – undo
2524 2524
 					$next_item_ids[$new_item_id] = $item['next_item_id'];
2525 2525
 
2526 2526
 					if (!empty($item['prerequisite'])) {
2527
-						if ($lp->lp_type =='2') {
2527
+						if ($lp->lp_type == '2') {
2528 2528
 							// if is an sco
2529
-							$old_prerequisite[$new_item_id]= $item['prerequisite'];
2529
+							$old_prerequisite[$new_item_id] = $item['prerequisite'];
2530 2530
 						} else {
2531
-							$old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2531
+							$old_prerequisite[$new_item_id] = $new_item_ids[$item['prerequisite']];
2532 2532
 						}
2533 2533
 					}
2534 2534
 
2535 2535
 					if (!empty($ref)) {
2536
-						if ($lp->lp_type =='2') {
2536
+						if ($lp->lp_type == '2') {
2537 2537
 							// if is an sco
2538
-							$old_refs[$new_item_id]= $ref;
2538
+							$old_refs[$new_item_id] = $ref;
2539 2539
 						} else {
2540
-                            $old_refs[$new_item_id]= $new_item_ids[$ref];
2540
+                            $old_refs[$new_item_id] = $new_item_ids[$ref];
2541 2541
 						}
2542 2542
 					}
2543 2543
 
@@ -2546,7 +2546,7 @@  discard block
 block discarded – undo
2546 2546
 
2547 2547
 				// Updating prerequisites
2548 2548
 				foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2549
-					if($my_old_prerequisite != ''){
2549
+					if ($my_old_prerequisite != '') {
2550 2550
 						$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2551 2551
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2552 2552
 						Database::query($sql);
@@ -2564,7 +2564,7 @@  discard block
 block discarded – undo
2564 2564
 
2565 2565
 				foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2566 2566
 					$parent_new_id = 0;
2567
-					if($parent_item_old_id != 0){
2567
+					if ($parent_item_old_id != 0) {
2568 2568
 						$parent_new_id = $new_item_ids[$parent_item_old_id];
2569 2569
 					}
2570 2570
 					$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
@@ -2573,7 +2573,7 @@  discard block
 block discarded – undo
2573 2573
 				}
2574 2574
 				foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2575 2575
 					$previous_new_id = 0;
2576
-					if($previous_item_old_id != 0){
2576
+					if ($previous_item_old_id != 0) {
2577 2577
 						$previous_new_id = $new_item_ids[$previous_item_old_id];
2578 2578
 					}
2579 2579
 					$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
@@ -2583,7 +2583,7 @@  discard block
 block discarded – undo
2583 2583
 
2584 2584
 				foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2585 2585
 					$next_new_id = 0;
2586
-					if($next_item_old_id != 0){
2586
+					if ($next_item_old_id != 0) {
2587 2587
 						$next_new_id = $new_item_ids[$next_item_old_id];
2588 2588
 					}
2589 2589
 					$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
@@ -2593,7 +2593,7 @@  discard block
 block discarded – undo
2593 2593
 
2594 2594
 				foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2595 2595
 					$prerequisite_new_id = 0;
2596
-					if($prerequisite_old_id != 0){
2596
+					if ($prerequisite_old_id != 0) {
2597 2597
 						$prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2598 2598
 					}
2599 2599
 					$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
@@ -2613,9 +2613,9 @@  discard block
 block discarded – undo
2613 2613
 	public function restore_student_publication($sessionId = 0)
2614 2614
     {
2615 2615
         $sessionId = intval($sessionId);
2616
-		$work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2616
+		$work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2617 2617
 		$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2618
-		$item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2618
+		$item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
2619 2619
 
2620 2620
 		// Query in student publication
2621 2621
 		$sql = 'SELECT * FROM '.$work_table.'
@@ -2693,7 +2693,7 @@  discard block
 block discarded – undo
2693 2693
 
2694 2694
 		$destination = '../../courses/'.$this->course->destination_path.'/work/';
2695 2695
 		$origin = '../../courses/'.$this->course->info['path'].'/work/';
2696
-		self::allow_create_all_directory($origin,$destination,false);
2696
+		self::allow_create_all_directory($origin, $destination, false);
2697 2697
 	}
2698 2698
 
2699 2699
     /**
@@ -2712,16 +2712,16 @@  discard block
 block discarded – undo
2712 2712
         if ($handle = opendir($source)) {        // if the folder exploration is sucsessful, continue
2713 2713
             while (false !== ($file = readdir($handle))) { // as long as storing the next file to $file is successful, continue
2714 2714
                 if ($file != '.' && $file != '..') {
2715
-                    $path = $source . '/' . $file;
2715
+                    $path = $source.'/'.$file;
2716 2716
                     if (is_file($path)) {
2717 2717
                        /* if (!is_file($dest . '/' . $file) || $overwrite)
2718 2718
                         if (!@copy($path, $dest . '/' . $file)) {
2719 2719
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2720 2720
                         }*/
2721
-                    } elseif(is_dir($path)) {
2722
-                        if (!is_dir($dest . '/' . $file))
2723
-                        mkdir($dest . '/' . $file);
2724
-                       self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2721
+                    } elseif (is_dir($path)) {
2722
+                        if (!is_dir($dest.'/'.$file))
2723
+                        mkdir($dest.'/'.$file);
2724
+                       self:: allow_create_all_directory($path, $dest.'/'.$file, $overwrite);
2725 2725
                     }
2726 2726
                 }
2727 2727
             }
@@ -2908,7 +2908,7 @@  discard block
 block discarded – undo
2908 2908
                     $this->course->backup_path,
2909 2909
                     $this->course->info['path']
2910 2910
                 );
2911
-				$thematic->params['c_id']  = $this->destination_course_id;
2911
+				$thematic->params['c_id'] = $this->destination_course_id;
2912 2912
 				unset($thematic->params['id']);
2913 2913
                 unset($thematic->params['iid']);
2914 2914
 
@@ -2932,7 +2932,7 @@  discard block
 block discarded – undo
2932 2932
                         unset($thematic_advance['iid']);
2933 2933
 						$thematic_advance['attendance_id'] = 0;
2934 2934
 						$thematic_advance['thematic_id'] = $last_id;
2935
-						$thematic_advance['c_id']  = $this->destination_course_id;
2935
+						$thematic_advance['c_id'] = $this->destination_course_id;
2936 2936
                         $my_id = Database::insert(
2937 2937
                             $table_thematic_advance,
2938 2938
                             $thematic_advance,
@@ -2954,7 +2954,7 @@  discard block
 block discarded – undo
2954 2954
 						}
2955 2955
 					}
2956 2956
 
2957
-					foreach($thematic->thematic_plan_list as $thematic_plan) {
2957
+					foreach ($thematic->thematic_plan_list as $thematic_plan) {
2958 2958
 						unset($thematic_plan['id']);
2959 2959
                         unset($thematic_plan['iid']);
2960 2960
 						$thematic_plan['thematic_id'] = $last_id;
@@ -3070,7 +3070,7 @@  discard block
 block discarded – undo
3070 3070
                 // re-create dir
3071 3071
                 // @todo check security against injection of dir in crafted course backup here!
3072 3072
                 $path = $obj->params['url'];
3073
-                $path = '/'.str_replace('/','',substr($path,1));
3073
+                $path = '/'.str_replace('/', '', substr($path, 1));
3074 3074
 
3075 3075
                 $workData = array();
3076 3076
                 switch ($this->file_option) {
@@ -3092,9 +3092,9 @@  discard block
 block discarded – undo
3092 3092
                         $obj->params['new_dir'] = $obj->params['title'];
3093 3093
 
3094 3094
                         if (!empty($this->course_origin_id)) {
3095
-                            $sql = 'SELECT * FROM ' . $table_work_assignment . '
3095
+                            $sql = 'SELECT * FROM '.$table_work_assignment.'
3096 3096
                                     WHERE
3097
-                                        c_id = ' . $this->course_origin_id . ' AND
3097
+                                        c_id = ' . $this->course_origin_id.' AND
3098 3098
                                         publication_id = ' . $id_work;
3099 3099
 
3100 3100
                             $result = Database::query($sql);
@@ -3206,7 +3206,7 @@  discard block
 block discarded – undo
3206 3206
     public function DBUTF8_array($array)
3207 3207
     {
3208 3208
         if (UTF8_CONVERT) {
3209
-            foreach ($array as &$item)  {
3209
+            foreach ($array as &$item) {
3210 3210
                 $item = utf8_encode($item);
3211 3211
             }
3212 3212
             return $array;
Please login to merge, or discard this patch.
Braces   +11 added lines, -4 removed lines patch added patch discarded remove patch
@@ -512,7 +512,9 @@  discard block
 block discarded – undo
512 512
 
513 513
                                     if (in_array($file_info['extension'], array('html', 'htm'))) {
514 514
                                         $content = file_get_contents($path.$document->path);
515
-                                        if (UTF8_CONVERT) $content = utf8_encode($content);
515
+                                        if (UTF8_CONVERT) {
516
+                                            $content = utf8_encode($content);
517
+                                        }
516 518
                                         $content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
517 519
                                             $content,
518 520
                                             $this->course->code,
@@ -2240,7 +2242,11 @@  discard block
 block discarded – undo
2240 2242
 		            c_id = ".$this->destination_course_id." AND
2241 2243
 		            code='".self::DBUTF8escapestring($survey_code)."'";
2242 2244
 		$result = Database::query($sql);
2243
-		if (Database::num_rows($result) > 0) return false; else return true;
2245
+		if (Database::num_rows($result) > 0) {
2246
+		    return false;
2247
+		} else {
2248
+		    return true;
2249
+		}
2244 2250
 	}
2245 2251
 
2246 2252
 	/**
@@ -2719,8 +2725,9 @@  discard block
 block discarded – undo
2719 2725
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2720 2726
                         }*/
2721 2727
                     } elseif(is_dir($path)) {
2722
-                        if (!is_dir($dest . '/' . $file))
2723
-                        mkdir($dest . '/' . $file);
2728
+                        if (!is_dir($dest . '/' . $file)) {
2729
+                                                mkdir($dest . '/' . $file);
2730
+                        }
2724 2731
                        self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2725 2732
                     }
2726 2733
                 }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -1212,6 +1212,7 @@
 block discarded – undo
1212 1212
 	 * Restore a forum-post
1213 1213
 	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214 1214
 	 * @param false|string $topic_id
1215
+	 * @param false|string $forum_id
1215 1216
 	 */
1216 1217
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1217 1218
     {
Please login to merge, or discard this patch.
Indentation   +717 added lines, -717 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 false|null
137
-	 */
137
+     */
138 138
     public function restore(
139 139
         $destination_course_code = '',
140 140
         $session_id = 0,
@@ -277,17 +277,17 @@  discard block
 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,16 +1150,16 @@  discard block
 block discarded – undo
1150 1150
                 }
1151 1151
             }
1152 1152
         }
1153
-	}
1153
+    }
1154 1154
 
1155
-	/**
1156
-	 * Restore a forum-topic
1157
-	 * @param false|string $forum_id
1158
-	 */
1155
+    /**
1156
+     * Restore a forum-topic
1157
+     * @param false|string $forum_id
1158
+     */
1159 1159
     public function restore_topic($thread_id, $forum_id, $sessionId = 0)
1160 1160
     {
1161
-		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
1162
-		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1161
+        $table = Database :: get_course_table(TABLE_FORUM_THREAD);
1162
+        $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1163 1163
 
1164 1164
         $params = (array)$topic->obj;
1165 1165
         $params = self::DBUTF8_array($params);
@@ -1195,28 +1195,28 @@  discard block
 block discarded – undo
1195 1195
             $sessionId
1196 1196
         );
1197 1197
 
1198
-		$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1198
+        $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1199 1199
 
1200
-		$topic_replies = -1;
1200
+        $topic_replies = -1;
1201 1201
 
1202
-		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1203
-			if ($post->obj->thread_id == $thread_id) {
1204
-				$topic_replies++;
1205
-				$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1206
-			}
1207
-		}
1208
-		return $new_id;
1209
-	}
1202
+        foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1203
+            if ($post->obj->thread_id == $thread_id) {
1204
+                $topic_replies++;
1205
+                $this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1206
+            }
1207
+        }
1208
+        return $new_id;
1209
+    }
1210 1210
 
1211
-	/**
1212
-	 * Restore a forum-post
1213
-	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214
-	 * @param false|string $topic_id
1215
-	 */
1211
+    /**
1212
+     * Restore a forum-post
1213
+     * @TODO Restore tree-structure of posts. For example: attachments to posts.
1214
+     * @param false|string $topic_id
1215
+     */
1216 1216
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1217 1217
     {
1218
-		$table_post = Database :: get_course_table(TABLE_FORUM_POST);
1219
-		$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1218
+        $table_post = Database :: get_course_table(TABLE_FORUM_POST);
1219
+        $post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1220 1220
         $params = (array) $post->obj;
1221 1221
         $params['c_id'] = $this->destination_course_id;
1222 1222
         $params['forum_id'] = $forum_id;
@@ -1251,37 +1251,37 @@  discard block
 block discarded – undo
1251 1251
             null,
1252 1252
             $sessionId
1253 1253
         );
1254
-		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1254
+        $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1255 1255
 
1256
-		return $new_id;
1257
-	}
1256
+        return $new_id;
1257
+    }
1258 1258
 
1259
-	/**
1260
-	 * Restore links
1261
-	 */
1259
+    /**
1260
+     * Restore links
1261
+     */
1262 1262
     public function restore_links($session_id = 0)
1263 1263
     {
1264
-		if ($this->course->has_resources(RESOURCE_LINK)) {
1265
-			$link_table = Database :: get_course_table(TABLE_LINK);
1266
-			$resources = $this->course->resources;
1264
+        if ($this->course->has_resources(RESOURCE_LINK)) {
1265
+            $link_table = Database :: get_course_table(TABLE_LINK);
1266
+            $resources = $this->course->resources;
1267 1267
 
1268
-			foreach ($resources[RESOURCE_LINK] as $id => $link) {
1268
+            foreach ($resources[RESOURCE_LINK] as $id => $link) {
1269 1269
                 $cat_id = $this->restore_link_category(
1270 1270
                     $link->category_id,
1271 1271
                     $session_id
1272 1272
                 );
1273
-				$sql = "SELECT MAX(display_order)
1273
+                $sql = "SELECT MAX(display_order)
1274 1274
 				        FROM $link_table
1275 1275
 				        WHERE
1276 1276
 				            c_id = ".$this->destination_course_id." AND
1277 1277
 				            category_id='" . intval($cat_id). "'";
1278
-				$result = Database::query($sql);
1279
-    			list($max_order) = Database::fetch_array($result);
1278
+                $result = Database::query($sql);
1279
+                list($max_order) = Database::fetch_array($result);
1280 1280
 
1281 1281
                 $params = [];
1282
-    			if (!empty($session_id)) {
1282
+                if (!empty($session_id)) {
1283 1283
                     $params['session_id'] = $session_id;
1284
-    			}
1284
+                }
1285 1285
 
1286 1286
                 $params['c_id'] = $this->destination_course_id;
1287 1287
                 $params['url'] = self::DBUTF8($link->url);
@@ -1310,9 +1310,9 @@  discard block
 block discarded – undo
1310 1310
                     }
1311 1311
                     $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id;
1312 1312
                 }
1313
-			}
1314
-		}
1315
-	}
1313
+            }
1314
+        }
1315
+    }
1316 1316
 
1317 1317
     /**
1318 1318
      * Restore a link-category
@@ -1356,21 +1356,21 @@  discard block
 block discarded – undo
1356 1356
         return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id;
1357 1357
     }
1358 1358
 
1359
-	/**
1360
-	 * Restore tool intro
1361
-	 */
1359
+    /**
1360
+     * Restore tool intro
1361
+     */
1362 1362
     public function restore_tool_intro($sessionId = 0)
1363 1363
     {
1364
-		if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1364
+        if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1365 1365
             $sessionId = intval($sessionId);
1366
-			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1367
-			$resources = $this->course->resources;
1368
-			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1369
-				$sql = "DELETE FROM ".$tool_intro_table."
1366
+            $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1367
+            $resources = $this->course->resources;
1368
+            foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1369
+                $sql = "DELETE FROM ".$tool_intro_table."
1370 1370
 				        WHERE
1371 1371
 				            c_id = ".$this->destination_course_id." AND
1372 1372
 				            id='".self::DBUTF8escapestring($tool_intro->id)."'";
1373
-				Database::query($sql);
1373
+                Database::query($sql);
1374 1374
 
1375 1375
                 $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1376 1376
                     $tool_intro->intro_text,
@@ -1398,21 +1398,21 @@  discard block
 block discarded – undo
1398 1398
 
1399 1399
                     $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id;
1400 1400
                 }
1401
-			}
1402
-		}
1403
-	}
1401
+            }
1402
+        }
1403
+    }
1404 1404
 
1405
-	/**
1406
-	 * Restore events
1407
-	 */
1405
+    /**
1406
+     * Restore events
1407
+     */
1408 1408
     public function restore_events($sessionId = 0)
1409 1409
     {
1410
-		if ($this->course->has_resources(RESOURCE_EVENT)) {
1410
+        if ($this->course->has_resources(RESOURCE_EVENT)) {
1411 1411
             $sessionId = intval($sessionId);
1412
-			$table = Database :: get_course_table(TABLE_AGENDA);
1413
-			$resources = $this->course->resources;
1414
-			foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1415
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1412
+            $table = Database :: get_course_table(TABLE_AGENDA);
1413
+            $resources = $this->course->resources;
1414
+            foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1415
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1416 1416
                 $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1417 1417
                     $event->content,
1418 1418
                     $this->course->code,
@@ -1430,7 +1430,7 @@  discard block
 block discarded – undo
1430 1430
                     'end_date' => $event->end_date,
1431 1431
                     'session_id' => $sessionId,
1432 1432
                 ];
1433
-				$new_event_id = Database::insert($table, $params);
1433
+                $new_event_id = Database::insert($table, $params);
1434 1434
 
1435 1435
                 if ($new_event_id) {
1436 1436
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id";
@@ -1443,30 +1443,30 @@  discard block
 block discarded – undo
1443 1443
                     $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
1444 1444
                 }
1445 1445
 
1446
-				// Copy event attachment
1446
+                // Copy event attachment
1447 1447
 
1448
-				$origin_path = $this->course->backup_path.'/upload/calendar/';
1449
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1448
+                $origin_path = $this->course->backup_path.'/upload/calendar/';
1449
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1450 1450
 
1451
-				if (!empty($this->course->orig)) {
1451
+                if (!empty($this->course->orig)) {
1452 1452
 
1453
-					$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1454
-					$sql = 'SELECT path, comment, size, filename
1453
+                    $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1454
+                    $sql = 'SELECT path, comment, size, filename
1455 1455
 					        FROM '.$table_attachment.'
1456 1456
 					        WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
1457
-					$attachment_event = Database::query($sql);
1458
-					$attachment_event = Database::fetch_object($attachment_event);
1457
+                    $attachment_event = Database::query($sql);
1458
+                    $attachment_event = Database::fetch_object($attachment_event);
1459 1459
 
1460
-					if (file_exists($origin_path.$attachment_event->path) &&
1460
+                    if (file_exists($origin_path.$attachment_event->path) &&
1461 1461
                         !is_dir($origin_path.$attachment_event->path)
1462 1462
                     ) {
1463
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1464
-						$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1465
-						//$copy_result = true;
1466
-						if ($copy_result) {
1467
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1463
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1464
+                        $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1465
+                        //$copy_result = true;
1466
+                        if ($copy_result) {
1467
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1468 1468
 
1469
-							$params = [
1469
+                            $params = [
1470 1470
                                 'c_id' => $this->destination_course_id,
1471 1471
                                 'path' => self::DBUTF8($new_filename),
1472 1472
                                 'comment' => self::DBUTF8($attachment_event->comment),
@@ -1480,17 +1480,17 @@  discard block
 block discarded – undo
1480 1480
                                 Database::query($sql);
1481 1481
                             }
1482 1482
                         }
1483
-					}
1484
-				} else {
1485
-					// get the info of the file
1486
-					if (!empty($event->attachment_path) &&
1483
+                    }
1484
+                } else {
1485
+                    // get the info of the file
1486
+                    if (!empty($event->attachment_path) &&
1487 1487
                         is_file($origin_path.$event->attachment_path) &&
1488 1488
                         is_readable($origin_path.$event->attachment_path)
1489 1489
                     ) {
1490
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1491
-						$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1492
-						if ($copy_result) {
1493
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1490
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1491
+                        $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1492
+                        if ($copy_result) {
1493
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1494 1494
 
1495 1495
                             $params = [
1496 1496
                                 'c_id' => $this->destination_course_id,
@@ -1506,29 +1506,29 @@  discard block
 block discarded – undo
1506 1506
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id";
1507 1507
                                 Database::query($sql);
1508 1508
                             }
1509
-						}
1510
-					}
1511
-				}
1512
-			}
1513
-		}
1514
-	}
1515
-
1516
-	/**
1517
-	 * Restore course-description
1518
-	 */
1509
+                        }
1510
+                    }
1511
+                }
1512
+            }
1513
+        }
1514
+    }
1515
+
1516
+    /**
1517
+     * Restore course-description
1518
+     */
1519 1519
     public function restore_course_descriptions($session_id = 0)
1520 1520
     {
1521
-		if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1522
-			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1523
-			$resources = $this->course->resources;
1524
-			foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1521
+        if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1522
+            $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1523
+            $resources = $this->course->resources;
1524
+            foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1525 1525
                 $courseDescription = (array) $cd;
1526 1526
 
1527 1527
                 $content = isset($courseDescription['content']) ? $courseDescription['content'] : '';
1528 1528
                 $descriptionType = isset($courseDescription['description_type']) ? $courseDescription['description_type'] : '';
1529 1529
                 $title = isset($courseDescription['title']) ? $courseDescription['title'] : '';
1530 1530
 
1531
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1531
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1532 1532
                 $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1533 1533
                     $content,
1534 1534
                     $this->course->code,
@@ -1556,22 +1556,22 @@  discard block
 block discarded – undo
1556 1556
                     }
1557 1557
                     $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id;
1558 1558
                 }
1559
-			}
1560
-		}
1561
-	}
1559
+            }
1560
+        }
1561
+    }
1562 1562
 
1563
-	/**
1564
-	 * Restore announcements
1565
-	 */
1563
+    /**
1564
+     * Restore announcements
1565
+     */
1566 1566
     public function restore_announcements($sessionId = 0)
1567 1567
     {
1568
-		if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1568
+        if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1569 1569
             $sessionId = intval($sessionId);
1570
-			$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1571
-			$resources = $this->course->resources;
1572
-			foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1570
+            $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1571
+            $resources = $this->course->resources;
1572
+            foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1573 1573
 
1574
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1574
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1575 1575
                 $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1576 1576
                     $announcement->content,
1577 1577
                     $this->course->code,
@@ -1590,7 +1590,7 @@  discard block
 block discarded – undo
1590 1590
                     'session_id' => $sessionId,
1591 1591
                 ];
1592 1592
 
1593
-				$new_announcement_id = Database::insert($table, $params);
1593
+                $new_announcement_id = Database::insert($table, $params);
1594 1594
 
1595 1595
                 if ($new_announcement_id) {
1596 1596
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id";
@@ -1602,32 +1602,32 @@  discard block
 block discarded – undo
1602 1602
                     $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id;
1603 1603
                 }
1604 1604
 
1605
-				$origin_path = $this->course->backup_path.'/upload/announcements/';
1606
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1605
+                $origin_path = $this->course->backup_path.'/upload/announcements/';
1606
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1607 1607
 
1608
-				// Copy announcement attachment file
1609
-				if (!empty($this->course->orig)) {
1608
+                // Copy announcement attachment file
1609
+                if (!empty($this->course->orig)) {
1610 1610
 
1611
-					$table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1612
-					$sql = 'SELECT path, comment, size, filename
1611
+                    $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1612
+                    $sql = 'SELECT path, comment, size, filename
1613 1613
 					        FROM '.$table_attachment.'
1614 1614
 					        WHERE
1615 1615
 					            c_id = '.$this->destination_course_id.' AND
1616 1616
 					            announcement_id = '.$id;
1617
-					$attachment_event = Database::query($sql);
1618
-					$attachment_event = Database::fetch_object($attachment_event);
1617
+                    $attachment_event = Database::query($sql);
1618
+                    $attachment_event = Database::fetch_object($attachment_event);
1619 1619
 
1620
-					if (file_exists($origin_path.$attachment_event->path) &&
1620
+                    if (file_exists($origin_path.$attachment_event->path) &&
1621 1621
                         !is_dir($origin_path.$attachment_event->path)
1622 1622
                     ) {
1623
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1623
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1624 1624
                         $copy_result = copy(
1625 1625
                             $origin_path.$attachment_event->path,
1626 1626
                             $destination_path.$new_filename
1627 1627
                         );
1628 1628
 
1629
-						if ($copy_result) {
1630
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1629
+                        if ($copy_result) {
1630
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1631 1631
 
1632 1632
                             $params = [
1633 1633
                                 'c_id' => $this->destination_course_id,
@@ -1644,20 +1644,20 @@  discard block
 block discarded – undo
1644 1644
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1645 1645
                                 Database::query($sql);
1646 1646
                             }
1647
-						}
1648
-					}
1649
-				} else {
1650
-					// get the info of the file
1651
-					if (!empty($announcement->attachment_path) &&
1647
+                        }
1648
+                    }
1649
+                } else {
1650
+                    // get the info of the file
1651
+                    if (!empty($announcement->attachment_path) &&
1652 1652
                         is_file($origin_path.$announcement->attachment_path) &&
1653 1653
                         is_readable($origin_path.$announcement->attachment_path)
1654 1654
                     ) {
1655
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1656
-						$copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1655
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1656
+                        $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1657 1657
 
1658
-						if ($copy_result) {
1659
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1660
-							/*$sql = "INSERT INTO ".$table_attachment." SET
1658
+                        if ($copy_result) {
1659
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1660
+                            /*$sql = "INSERT INTO ".$table_attachment." SET
1661 1661
 							        c_id = ".$this->destination_course_id." ,
1662 1662
 							        path = '".self::DBUTF8escapestring($new_filename)."',
1663 1663
 							        comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."',
@@ -1680,12 +1680,12 @@  discard block
 block discarded – undo
1680 1680
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1681 1681
                                 Database::query($sql);
1682 1682
                             }
1683
-						}
1684
-					}
1685
-				}
1686
-			}
1687
-		}
1688
-	}
1683
+                        }
1684
+                    }
1685
+                }
1686
+            }
1687
+        }
1688
+    }
1689 1689
 
1690 1690
     /**
1691 1691
      * Restore Quiz
@@ -1696,13 +1696,13 @@  discard block
 block discarded – undo
1696 1696
         $session_id = 0,
1697 1697
         $respect_base_content = false
1698 1698
     ) {
1699
-		if ($this->course->has_resources(RESOURCE_QUIZ)) {
1700
-			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1701
-			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1702
-			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1703
-			$resources = $this->course->resources;
1699
+        if ($this->course->has_resources(RESOURCE_QUIZ)) {
1700
+            $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1701
+            $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1702
+            $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1703
+            $resources = $this->course->resources;
1704 1704
 
1705
-			foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1705
+            foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1706 1706
 
1707 1707
                 if (isset($quiz->obj)) {
1708 1708
                     //For new imports
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
                     $quiz->obj = $quiz;
1713 1713
                 }
1714 1714
 
1715
-				$doc = '';
1715
+                $doc = '';
1716 1716
                 if (!empty($quiz->sound)) {
1717 1717
                     if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
1718 1718
                         $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
@@ -1720,14 +1720,14 @@  discard block
 block discarded – undo
1720 1720
                                 WHERE
1721 1721
                                     c_id = " . $this->destination_course_id . "  AND
1722 1722
                                     id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
1723
-						$doc = Database::query($sql);
1724
-						$doc = Database::fetch_object($doc);
1725
-						$doc = str_replace('/audio/', '', $doc->path);
1726
-					}
1727
-				}
1728
-
1729
-				if ($id != -1) {
1730
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1723
+                        $doc = Database::query($sql);
1724
+                        $doc = Database::fetch_object($doc);
1725
+                        $doc = str_replace('/audio/', '', $doc->path);
1726
+                    }
1727
+                }
1728
+
1729
+                if ($id != -1) {
1730
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1731 1731
                     $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1732 1732
                         $quiz->description,
1733 1733
                         $this->course->code,
@@ -1736,13 +1736,13 @@  discard block
 block discarded – undo
1736 1736
                         $this->course->info['path']
1737 1737
                     );
1738 1738
 
1739
-					global $_custom;
1740
-					if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1739
+                    global $_custom;
1740
+                    if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1741 1741
                         $_custom['exercises_clean_dates_when_restoring']
1742 1742
                     ) {
1743
-						$quiz->start_time = null;
1744
-						$quiz->end_time   = null;
1745
-					}
1743
+                        $quiz->start_time = null;
1744
+                        $quiz->end_time   = null;
1745
+                    }
1746 1746
 
1747 1747
                     $params = array(
1748 1748
                         'c_id' => $this->destination_course_id,
@@ -1774,10 +1774,10 @@  discard block
 block discarded – undo
1774 1774
                         }
1775 1775
                         $params['session_id'] = $my_session_id;
1776 1776
                     } else {
1777
-        				if (!empty($session_id)) {
1778
-        					$session_id = intval($session_id);
1777
+                        if (!empty($session_id)) {
1778
+                            $session_id = intval($session_id);
1779 1779
                             $params['session_id'] = $session_id;
1780
-    				    }
1780
+                        }
1781 1781
                     }
1782 1782
                     $new_id = Database::insert($table_qui, $params);
1783 1783
 
@@ -1786,15 +1786,15 @@  discard block
 block discarded – undo
1786 1786
                         Database::query($sql);
1787 1787
                     }
1788 1788
 
1789
-				} else {
1790
-					// $id = -1 identifies the fictionary test for collecting
1791
-					// orphan questions. We do not store it in the database.
1792
-					$new_id = -1;
1793
-				}
1789
+                } else {
1790
+                    // $id = -1 identifies the fictionary test for collecting
1791
+                    // orphan questions. We do not store it in the database.
1792
+                    $new_id = -1;
1793
+                }
1794 1794
 
1795
-				$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1795
+                $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1796 1796
 
1797
-				$order = 0;
1797
+                $order = 0;
1798 1798
                 if (!empty($quiz->question_ids)) {
1799 1799
                     foreach ($quiz->question_ids as $index => $question_id) {
1800 1800
                         $qid = $this->restore_quiz_question($question_id);
@@ -1807,30 +1807,30 @@  discard block
 block discarded – undo
1807 1807
                         Database::query($sql);
1808 1808
                     }
1809 1809
                 }
1810
-			}
1811
-		}
1812
-	}
1810
+            }
1811
+        }
1812
+    }
1813 1813
 
1814
-	/**
1815
-	 * Restore quiz-questions
1814
+    /**
1815
+     * Restore quiz-questions
1816 1816
      * @params int question id
1817
-	 */
1817
+     */
1818 1818
     public function restore_quiz_question($id)
1819 1819
     {
1820
-		$resources = $this->course->resources;
1820
+        $resources = $this->course->resources;
1821 1821
         $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
1822 1822
 
1823
-		$new_id = 0;
1823
+        $new_id = 0;
1824 1824
 
1825
-		if (is_object($question)) {
1826
-			if ($question->is_restored()) {
1827
-				return $question->destination_id;
1828
-			}
1829
-			$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1830
-			$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1825
+        if (is_object($question)) {
1826
+            if ($question->is_restored()) {
1827
+                return $question->destination_id;
1828
+            }
1829
+            $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1830
+            $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1831 1831
             $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
1832 1832
 
1833
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
1833
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
1834 1834
             $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1835 1835
                 $question->description,
1836 1836
                 $this->course->code,
@@ -1851,7 +1851,7 @@  discard block
 block discarded – undo
1851 1851
                 'extra' => self::DBUTF8($question->extra),
1852 1852
             ];
1853 1853
 
1854
-			$new_id = Database::insert($table_que, $params);
1854
+            $new_id = Database::insert($table_que, $params);
1855 1855
 
1856 1856
             if ($new_id) {
1857 1857
 
@@ -1892,7 +1892,7 @@  discard block
 block discarded – undo
1892 1892
 
1893 1893
                 foreach ($temp as $index => $answer) {
1894 1894
                     //id = '".$index."',
1895
-					$params = [
1895
+                    $params = [
1896 1896
                         'c_id' => $this->destination_course_id,
1897 1897
                         'question_id' => $new_id,
1898 1898
                         'answer' => self::DBUTF8($answer['answer']),
@@ -1909,12 +1909,12 @@  discard block
 block discarded – undo
1909 1909
                         $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId";
1910 1910
                         Database::query($sql);
1911 1911
                     }
1912
-				}
1913
-			} else {
1912
+                }
1913
+            } else {
1914 1914
                 $correct_answers = array();
1915
-				foreach ($question->answers as $index => $answer) {
1915
+                foreach ($question->answers as $index => $answer) {
1916 1916
 
1917
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1917
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1918 1918
                     $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1919 1919
                         $answer['answer'],
1920 1920
                         $this->course->code,
@@ -1953,8 +1953,8 @@  discard block
 block discarded – undo
1953 1953
                     }
1954 1954
 
1955 1955
                     $correct_answers[$answerId] = $answer['correct'];
1956
-				}
1957
-			}
1956
+                }
1957
+            }
1958 1958
 
1959 1959
             //Current course id
1960 1960
             $course_id = api_get_course_int_id();
@@ -2051,12 +2051,12 @@  discard block
 block discarded – undo
2051 2051
                     }
2052 2052
                 }
2053 2053
             }
2054
-			$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2055
-		}
2056
-		return $new_id;
2057
-	}
2054
+            $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2055
+        }
2056
+        return $new_id;
2057
+    }
2058 2058
 
2059
-	/**
2059
+    /**
2060 2060
      * @todo : add session id when used for session
2061 2061
      */
2062 2062
     public function restore_test_category($session_id, $respect_base_content, $destination_course_code)
@@ -2136,21 +2136,21 @@  discard block
 block discarded – undo
2136 2136
         $sessionId = intval($sessionId);
2137 2137
 
2138 2138
         if ($this->course->has_resources(RESOURCE_SURVEY)) {
2139
-			$table_sur = Database :: get_course_table(TABLE_SURVEY);
2140
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2141
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2142
-			$resources = $this->course->resources;
2143
-			foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2139
+            $table_sur = Database :: get_course_table(TABLE_SURVEY);
2140
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2141
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2142
+            $resources = $this->course->resources;
2143
+            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2144 2144
 
2145
-				$sql = 'SELECT survey_id FROM '.$table_sur.'
2145
+                $sql = 'SELECT survey_id FROM '.$table_sur.'
2146 2146
                         WHERE
2147 2147
                             c_id = '.$this->destination_course_id.' AND
2148 2148
                             code = "'.self::DBUTF8escapestring($survey->code).'" AND
2149 2149
                             lang = "'.self::DBUTF8escapestring($survey->lang).'" ';
2150 2150
 
2151
-				$result_check = Database::query($sql);
2151
+                $result_check = Database::query($sql);
2152 2152
 
2153
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2153
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2154 2154
                 $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2155 2155
                     $survey->title,
2156 2156
                     $this->course->code,
@@ -2204,20 +2204,20 @@  discard block
 block discarded – undo
2204 2204
                     'session_id' => $sessionId,
2205 2205
                 ];
2206 2206
 
2207
-				//An existing survey exists with the same code and the same language
2208
-				if (Database::num_rows($result_check) == 1) {
2209
-					switch ($this->file_option) {
2210
-						case FILE_SKIP:
2211
-							//Do nothing
2212
-							break;
2213
-						case FILE_RENAME:
2214
-							$survey_code = $survey->code.'_';
2215
-							$i=1;
2216
-							$temp_survey_code = $survey_code.$i;
2217
-							while (!$this->is_survey_code_available($temp_survey_code)) {
2218
-								$temp_survey_code = $survey_code.++$i;
2219
-							}
2220
-							$survey_code = $temp_survey_code;
2207
+                //An existing survey exists with the same code and the same language
2208
+                if (Database::num_rows($result_check) == 1) {
2209
+                    switch ($this->file_option) {
2210
+                        case FILE_SKIP:
2211
+                            //Do nothing
2212
+                            break;
2213
+                        case FILE_RENAME:
2214
+                            $survey_code = $survey->code.'_';
2215
+                            $i=1;
2216
+                            $temp_survey_code = $survey_code.$i;
2217
+                            while (!$this->is_survey_code_available($temp_survey_code)) {
2218
+                                $temp_survey_code = $survey_code.++$i;
2219
+                            }
2220
+                            $survey_code = $temp_survey_code;
2221 2221
 
2222 2222
                             $params['code'] = $survey_code;
2223 2223
                             $new_id = Database::insert($table_sur, $params);
@@ -2236,25 +2236,25 @@  discard block
 block discarded – undo
2236 2236
                                     Database::query($sql);
2237 2237
                                 }
2238 2238
                             }
2239
-							break;
2240
-						case FILE_OVERWRITE:
2241
-							// Delete the existing survey with the same code and language and import the one of the source course
2242
-							// getting the information of the survey (used for when the survey is shared)
2239
+                            break;
2240
+                        case FILE_OVERWRITE:
2241
+                            // Delete the existing survey with the same code and language and import the one of the source course
2242
+                            // getting the information of the survey (used for when the survey is shared)
2243 2243
 
2244
-							$sql = "SELECT * FROM $table_sur
2244
+                            $sql = "SELECT * FROM $table_sur
2245 2245
 							        WHERE
2246 2246
 							            c_id = ".$this->destination_course_id." AND
2247 2247
 							            survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'";
2248
-							$result = Database::query($sql);
2249
-							$survey_data = Database::fetch_array($result,'ASSOC');
2248
+                            $result = Database::query($sql);
2249
+                            $survey_data = Database::fetch_array($result,'ASSOC');
2250 2250
 
2251
-							// if the survey is shared => also delete the shared content
2252
-							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2251
+                            // if the survey is shared => also delete the shared content
2252
+                            if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2253 2253
                                 SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
2254
-							}
2255
-							SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2254
+                            }
2255
+                            SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2256 2256
 
2257
-							// Insert the new source survey
2257
+                            // Insert the new source survey
2258 2258
                             $new_id = Database::insert($table_sur, $params);
2259 2259
 
2260 2260
                             if ($new_id) {
@@ -2275,11 +2275,11 @@  discard block
 block discarded – undo
2275 2275
                                     Database::query($sql);
2276 2276
                                 }
2277 2277
                             }
2278
-							break;
2279
-						default:
2280
-							break;
2281
-					}
2282
-				} else {
2278
+                            break;
2279
+                        default:
2280
+                            break;
2281
+                    }
2282
+                } else {
2283 2283
                     // No existing survey with the same language and the same code, we just copy the survey
2284 2284
                     $new_id = Database::insert($table_sur, $params);
2285 2285
 
@@ -2301,45 +2301,45 @@  discard block
 block discarded – undo
2301 2301
                             Database::query($sql);
2302 2302
                         }
2303 2303
                     }
2304
-				}
2305
-			}
2306
-		}
2307
-	}
2308
-
2309
-	/**
2310
-	 * Check availability of a survey code
2311
-	 * @param string $survey_code
2312
-	 */
2304
+                }
2305
+            }
2306
+        }
2307
+    }
2308
+
2309
+    /**
2310
+     * Check availability of a survey code
2311
+     * @param string $survey_code
2312
+     */
2313 2313
     public function is_survey_code_available($survey_code)
2314 2314
     {
2315
-		$table_sur = Database :: get_course_table(TABLE_SURVEY);
2316
-		$sql = "SELECT * FROM $table_sur
2315
+        $table_sur = Database :: get_course_table(TABLE_SURVEY);
2316
+        $sql = "SELECT * FROM $table_sur
2317 2317
 		        WHERE
2318 2318
 		            c_id = ".$this->destination_course_id." AND
2319 2319
 		            code='".self::DBUTF8escapestring($survey_code)."'";
2320
-		$result = Database::query($sql);
2321
-		if (Database::num_rows($result) > 0) return false; else return true;
2322
-	}
2323
-
2324
-	/**
2325
-	 * Restore survey-questions
2326
-	 * @param string $survey_id
2327
-	 */
2320
+        $result = Database::query($sql);
2321
+        if (Database::num_rows($result) > 0) return false; else return true;
2322
+    }
2323
+
2324
+    /**
2325
+     * Restore survey-questions
2326
+     * @param string $survey_id
2327
+     */
2328 2328
     public function restore_survey_question($id, $survey_id)
2329 2329
     {
2330
-		$resources = $this->course->resources;
2331
-		$question = $resources[RESOURCE_SURVEYQUESTION][$id];
2330
+        $resources = $this->course->resources;
2331
+        $question = $resources[RESOURCE_SURVEYQUESTION][$id];
2332 2332
 
2333
-		$new_id=0;
2333
+        $new_id=0;
2334 2334
 
2335
-		if (is_object($question)) {
2336
-			if ($question->is_restored()) {
2337
-				return $question->destination_id;
2338
-			}
2339
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2340
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2335
+        if (is_object($question)) {
2336
+            if ($question->is_restored()) {
2337
+                return $question->destination_id;
2338
+            }
2339
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2340
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2341 2341
 
2342
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
2342
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
2343 2343
             $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2344 2344
                 $question->survey_question,
2345 2345
                 $this->course->code,
@@ -2393,10 +2393,10 @@  discard block
 block discarded – undo
2393 2393
                 }
2394 2394
                 $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id;
2395 2395
             }
2396
-		}
2396
+        }
2397 2397
 
2398
-		return $new_id;
2399
-	}
2398
+        return $new_id;
2399
+    }
2400 2400
 
2401 2401
     /**
2402 2402
      * Restoring learning paths
@@ -2407,20 +2407,20 @@  discard block
 block discarded – undo
2407 2407
     {
2408 2408
         $session_id = intval($session_id);
2409 2409
 
2410
-		if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2410
+        if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2411 2411
             $table_main = Database::get_course_table(TABLE_LP_MAIN);
2412 2412
             $table_item = Database::get_course_table(TABLE_LP_ITEM);
2413 2413
             $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
2414 2414
 
2415
-			$resources = $this->course->resources;
2415
+            $resources = $this->course->resources;
2416 2416
 
2417
-			$origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2418
-			$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2417
+            $origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2418
+            $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2419 2419
 
2420
-			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2420
+            foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2421 2421
 
2422
-				$condition_session = "";
2423
-				if (!empty($session_id)) {
2422
+                $condition_session = "";
2423
+                if (!empty($session_id)) {
2424 2424
                     if ($respect_base_content) {
2425 2425
                         $my_session_id = $lp->session_id;
2426 2426
                         if (!empty($lp->session_id)) {
@@ -2431,21 +2431,21 @@  discard block
 block discarded – undo
2431 2431
                         $session_id = intval($session_id);
2432 2432
                         $condition_session = $session_id;
2433 2433
                     }
2434
-				}
2435
-
2436
-				// Adding the author's image
2437
-				if (!empty($lp->preview_image)) {
2438
-					$new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2439
-					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2440
-						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2441
-						//$copy_result = true;
2442
-						if ($copy_result) {
2443
-							$lp->preview_image = $new_filename;
2444
-						} else {
2445
-							$lp->preview_image ='';
2446
-						}
2447
-					}
2448
-				}
2434
+                }
2435
+
2436
+                // Adding the author's image
2437
+                if (!empty($lp->preview_image)) {
2438
+                    $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2439
+                    if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2440
+                        $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2441
+                        //$copy_result = true;
2442
+                        if ($copy_result) {
2443
+                            $lp->preview_image = $new_filename;
2444
+                        } else {
2445
+                            $lp->preview_image ='';
2446
+                        }
2447
+                    }
2448
+                }
2449 2449
 
2450 2450
                 if ($this->add_text_in_items) {
2451 2451
                     $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix');
@@ -2492,7 +2492,7 @@  discard block
 block discarded – undo
2492 2492
                     $params['session_id'] = $condition_session;
2493 2493
                 }
2494 2494
 
2495
-				$new_lp_id = Database::insert($table_main, $params);
2495
+                $new_lp_id = Database::insert($table_main, $params);
2496 2496
 
2497 2497
                 if ($new_lp_id) {
2498 2498
 
@@ -2553,13 +2553,13 @@  discard block
 block discarded – undo
2553 2553
                 $old_refs = array();
2554 2554
                 $prerequisite_ids = array();
2555 2555
 
2556
-				foreach ($lp->get_items() as $index => $item) {
2557
-					// we set the ref code here and then we update in a for loop
2558
-					$ref = $item['ref'];
2556
+                foreach ($lp->get_items() as $index => $item) {
2557
+                    // we set the ref code here and then we update in a for loop
2558
+                    $ref = $item['ref'];
2559 2559
 
2560
-					// Dealing with path the same way as ref as some data has
2560
+                    // Dealing with path the same way as ref as some data has
2561 2561
                     // been put into path when it's a local resource
2562
-					// Only fix the path for no scos
2562
+                    // Only fix the path for no scos
2563 2563
                     if ($item['item_type'] == 'sco') {
2564 2564
                         $path = $item['path'];
2565 2565
                     } else {
@@ -2588,128 +2588,128 @@  discard block
 block discarded – undo
2588 2588
                         'launch_data' => self::DBUTF8($item['launch_data']),
2589 2589
                     ];
2590 2590
 
2591
-					$new_item_id = Database::insert($table_item, $params);
2591
+                    $new_item_id = Database::insert($table_item, $params);
2592 2592
 
2593 2593
                     $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
2594 2594
                     Database::query($sql);
2595 2595
 
2596
-					//save a link between old and new item IDs
2597
-					$new_item_ids[$item['id']] = $new_item_id;
2598
-					//save a reference of items that need a parent_item_id refresh
2599
-					$parent_item_ids[$new_item_id] = $item['parent_item_id'];
2600
-					//save a reference of items that need a previous_item_id refresh
2601
-					$previous_item_ids[$new_item_id] = $item['previous_item_id'];
2602
-					//save a reference of items that need a next_item_id refresh
2603
-					$next_item_ids[$new_item_id] = $item['next_item_id'];
2604
-
2605
-					if (!empty($item['prerequisite'])) {
2606
-						if ($lp->lp_type =='2') {
2607
-							// if is an sco
2608
-							$old_prerequisite[$new_item_id]= $item['prerequisite'];
2609
-						} else {
2610
-							$old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2611
-						}
2612
-					}
2613
-
2614
-					if (!empty($ref)) {
2615
-						if ($lp->lp_type =='2') {
2616
-							// if is an sco
2617
-							$old_refs[$new_item_id]= $ref;
2618
-						} else {
2596
+                    //save a link between old and new item IDs
2597
+                    $new_item_ids[$item['id']] = $new_item_id;
2598
+                    //save a reference of items that need a parent_item_id refresh
2599
+                    $parent_item_ids[$new_item_id] = $item['parent_item_id'];
2600
+                    //save a reference of items that need a previous_item_id refresh
2601
+                    $previous_item_ids[$new_item_id] = $item['previous_item_id'];
2602
+                    //save a reference of items that need a next_item_id refresh
2603
+                    $next_item_ids[$new_item_id] = $item['next_item_id'];
2604
+
2605
+                    if (!empty($item['prerequisite'])) {
2606
+                        if ($lp->lp_type =='2') {
2607
+                            // if is an sco
2608
+                            $old_prerequisite[$new_item_id]= $item['prerequisite'];
2609
+                        } else {
2610
+                            $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2611
+                        }
2612
+                    }
2613
+
2614
+                    if (!empty($ref)) {
2615
+                        if ($lp->lp_type =='2') {
2616
+                            // if is an sco
2617
+                            $old_refs[$new_item_id]= $ref;
2618
+                        } else {
2619 2619
                             $old_refs[$new_item_id]= $new_item_ids[$ref];
2620
-						}
2621
-					}
2620
+                        }
2621
+                    }
2622 2622
 
2623
-					$prerequisite_ids[$new_item_id] = $item['prerequisite'];
2624
-				}
2623
+                    $prerequisite_ids[$new_item_id] = $item['prerequisite'];
2624
+                }
2625 2625
 
2626
-				// Updating prerequisites
2627
-				foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2628
-					if($my_old_prerequisite != ''){
2629
-						$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2626
+                // Updating prerequisites
2627
+                foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2628
+                    if($my_old_prerequisite != ''){
2629
+                        $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2630 2630
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2631
-						Database::query($sql);
2632
-					}
2633
-				}
2634
-
2635
-				// Updating refs
2636
-				foreach ($old_refs  as $key=>$my_old_ref) {
2637
-					if ($my_old_ref != '') {
2638
-						$sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2631
+                        Database::query($sql);
2632
+                    }
2633
+                }
2634
+
2635
+                // Updating refs
2636
+                foreach ($old_refs  as $key=>$my_old_ref) {
2637
+                    if ($my_old_ref != '') {
2638
+                        $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2639 2639
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2640
-						Database::query($sql);
2641
-					}
2642
-				}
2643
-
2644
-				foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2645
-					$parent_new_id = 0;
2646
-					if($parent_item_old_id != 0){
2647
-						$parent_new_id = $new_item_ids[$parent_item_old_id];
2648
-					}
2649
-					$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2640
+                        Database::query($sql);
2641
+                    }
2642
+                }
2643
+
2644
+                foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2645
+                    $parent_new_id = 0;
2646
+                    if($parent_item_old_id != 0){
2647
+                        $parent_new_id = $new_item_ids[$parent_item_old_id];
2648
+                    }
2649
+                    $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2650 2650
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2651
-					Database::query($sql);
2652
-				}
2653
-				foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2654
-					$previous_new_id = 0;
2655
-					if($previous_item_old_id != 0){
2656
-						$previous_new_id = $new_item_ids[$previous_item_old_id];
2657
-					}
2658
-					$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2651
+                    Database::query($sql);
2652
+                }
2653
+                foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2654
+                    $previous_new_id = 0;
2655
+                    if($previous_item_old_id != 0){
2656
+                        $previous_new_id = $new_item_ids[$previous_item_old_id];
2657
+                    }
2658
+                    $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2659 2659
 					        WHERE  c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2660
-					Database::query($sql);
2661
-				}
2662
-
2663
-				foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2664
-					$next_new_id = 0;
2665
-					if($next_item_old_id != 0){
2666
-						$next_new_id = $new_item_ids[$next_item_old_id];
2667
-					}
2668
-					$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2660
+                    Database::query($sql);
2661
+                }
2662
+
2663
+                foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2664
+                    $next_new_id = 0;
2665
+                    if($next_item_old_id != 0){
2666
+                        $next_new_id = $new_item_ids[$next_item_old_id];
2667
+                    }
2668
+                    $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2669 2669
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2670
-					Database::query($sql);
2671
-				}
2672
-
2673
-				foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2674
-					$prerequisite_new_id = 0;
2675
-					if($prerequisite_old_id != 0){
2676
-						$prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2677
-					}
2678
-					$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2670
+                    Database::query($sql);
2671
+                }
2672
+
2673
+                foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2674
+                    $prerequisite_new_id = 0;
2675
+                    if($prerequisite_old_id != 0){
2676
+                        $prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2677
+                    }
2678
+                    $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2679 2679
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2680
-					Database::query($sql);
2681
-				}
2682
-				$this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2683
-			}
2684
-		}
2685
-	}
2686
-
2687
-	/**
2688
-	 * Restore works
2680
+                    Database::query($sql);
2681
+                }
2682
+                $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2683
+            }
2684
+        }
2685
+    }
2686
+
2687
+    /**
2688
+     * Restore works
2689 2689
      * @deprecated use restore_works
2690 2690
      *
2691
-	 */
2692
-	public function restore_student_publication($sessionId = 0)
2691
+     */
2692
+    public function restore_student_publication($sessionId = 0)
2693 2693
     {
2694 2694
         $sessionId = intval($sessionId);
2695
-		$work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2696
-		$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2697
-		$item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2695
+        $work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2696
+        $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
2697
+        $item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
2698 2698
 
2699
-		// Query in student publication
2700
-		$sql = 'SELECT * FROM '.$work_table.'
2699
+        // Query in student publication
2700
+        $sql = 'SELECT * FROM '.$work_table.'
2701 2701
 		        WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) ';
2702 2702
 
2703
-		$result = Database::query($sql);
2704
-		$folders = Database::store_result($result, 'ASSOC');
2703
+        $result = Database::query($sql);
2704
+        $folders = Database::store_result($result, 'ASSOC');
2705 2705
 
2706
-		foreach ($folders  as $folder) {
2707
-		    $old_id = $folder['id'];
2706
+        foreach ($folders  as $folder) {
2707
+            $old_id = $folder['id'];
2708 2708
             unset($folder['id']);
2709
-			$folder['c_id'] = $this->destination_course_id;
2709
+            $folder['c_id'] = $this->destination_course_id;
2710 2710
             $folder['parent_id'] = 0;
2711 2711
             $folder['session_id'] = $sessionId;
2712
-			$new_id = Database::insert($work_table, $folder);
2712
+            $new_id = Database::insert($work_table, $folder);
2713 2713
 
2714 2714
             if ($new_id) {
2715 2715
                 //query in item property
@@ -2768,23 +2768,23 @@  discard block
 block discarded – undo
2768 2768
                     }
2769 2769
                 }
2770 2770
             }
2771
-		}
2771
+        }
2772 2772
 
2773
-		$destination = '../../courses/'.$this->course->destination_path.'/work/';
2774
-		$origin = '../../courses/'.$this->course->info['path'].'/work/';
2775
-		self::allow_create_all_directory($origin,$destination,false);
2776
-	}
2773
+        $destination = '../../courses/'.$this->course->destination_path.'/work/';
2774
+        $origin = '../../courses/'.$this->course->info['path'].'/work/';
2775
+        self::allow_create_all_directory($origin,$destination,false);
2776
+    }
2777 2777
 
2778 2778
     /**
2779
-    * copy all directory and sub directory
2780
-    * @param string The path origin
2781
-    * @param string The path destination
2782
-    * @param boolean Option Overwrite
2783
-    * @param string $source
2784
-    * @param string $dest
2785
-    * @return void()
2786
-    * @deprecated
2787
-    */
2779
+     * copy all directory and sub directory
2780
+     * @param string The path origin
2781
+     * @param string The path destination
2782
+     * @param boolean Option Overwrite
2783
+     * @param string $source
2784
+     * @param string $dest
2785
+     * @return void()
2786
+     * @deprecated
2787
+     */
2788 2788
     public function allow_create_all_directory($source, $dest, $overwrite = false)
2789 2789
     {
2790 2790
         if (!is_dir($dest)) {
@@ -2795,14 +2795,14 @@  discard block
 block discarded – undo
2795 2795
                 if ($file != '.' && $file != '..') {
2796 2796
                     $path = $source . '/' . $file;
2797 2797
                     if (is_file($path)) {
2798
-                       /* if (!is_file($dest . '/' . $file) || $overwrite)
2798
+                        /* if (!is_file($dest . '/' . $file) || $overwrite)
2799 2799
                         if (!@copy($path, $dest . '/' . $file)) {
2800 2800
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2801 2801
                         }*/
2802 2802
                     } elseif(is_dir($path)) {
2803 2803
                         if (!is_dir($dest . '/' . $file))
2804 2804
                         mkdir($dest . '/' . $file);
2805
-                       self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2805
+                        self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite);
2806 2806
                     }
2807 2807
                 }
2808 2808
             }
@@ -2810,12 +2810,12 @@  discard block
 block discarded – undo
2810 2810
         }
2811 2811
     }
2812 2812
 
2813
-	/**
2814
-	 * Gets the new ID of one specific tool item from the tool name and the old ID
2815
-	 * @param	string	Tool name
2816
-	 * @param	integer	Old ID
2817
-	 * @return	integer	New ID
2818
-	 */
2813
+    /**
2814
+     * Gets the new ID of one specific tool item from the tool name and the old ID
2815
+     * @param	string	Tool name
2816
+     * @param	integer	Old ID
2817
+     * @return	integer	New ID
2818
+     */
2819 2819
     public function get_new_id($tool, $ref)
2820 2820
     {
2821 2821
         // Check if the value exist in the current array.
@@ -2837,25 +2837,25 @@  discard block
 block discarded – undo
2837 2837
         }
2838 2838
 
2839 2839
         return '';
2840
-	}
2840
+    }
2841 2841
 
2842
-	/**
2843
-	 * Restore glossary
2844
-	 */
2842
+    /**
2843
+     * Restore glossary
2844
+     */
2845 2845
     public function restore_glossary($session_id = 0)
2846 2846
     {
2847
-		if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2848
-			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2849
-			$resources = $this->course->resources;
2850
-			foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2847
+        if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2848
+            $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2849
+            $resources = $this->course->resources;
2850
+            foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2851 2851
 
2852 2852
                 $params = [];
2853
-    			if (!empty($session_id)) {
2854
-    				$session_id = intval($session_id);
2853
+                if (!empty($session_id)) {
2854
+                    $session_id = intval($session_id);
2855 2855
                     $params['session_id'] = $session_id;
2856
-    			}
2856
+                }
2857 2857
 
2858
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2858
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2859 2859
                 $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2860 2860
                     $glossary->description,
2861 2861
                     $this->course->code,
@@ -2889,27 +2889,27 @@  discard block
 block discarded – undo
2889 2889
 
2890 2890
                     $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id;
2891 2891
                 }
2892
-			}
2893
-		}
2894
-	}
2892
+            }
2893
+        }
2894
+    }
2895 2895
 
2896 2896
     /**
2897 2897
      * @param int $session_id
2898 2898
      */
2899 2899
     public function restore_wiki($session_id = 0)
2900 2900
     {
2901
-		if ($this->course->has_resources(RESOURCE_WIKI)) {
2902
-			// wiki table of the target course
2903
-			$table_wiki = Database :: get_course_table(TABLE_WIKI);
2904
-			$table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2901
+        if ($this->course->has_resources(RESOURCE_WIKI)) {
2902
+            // wiki table of the target course
2903
+            $table_wiki = Database :: get_course_table(TABLE_WIKI);
2904
+            $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2905 2905
 
2906
-			// storing all the resources that have to be copied in an array
2907
-			$resources = $this->course->resources;
2906
+            // storing all the resources that have to be copied in an array
2907
+            $resources = $this->course->resources;
2908 2908
 
2909
-			foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2910
-				// the sql statement to insert the groups from the old course to the new course
2909
+            foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2910
+                // the sql statement to insert the groups from the old course to the new course
2911 2911
 
2912
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2912
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2913 2913
                 $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2914 2914
                     $wiki->content,
2915 2915
                     $this->course->code,
@@ -2932,7 +2932,7 @@  discard block
 block discarded – undo
2932 2932
                     'session_id' => !empty($session_id) ? intval($session_id) : 0,
2933 2933
                 ];
2934 2934
 
2935
-				$new_id = Database::insert($table_wiki, $params);
2935
+                $new_id = Database::insert($table_wiki, $params);
2936 2936
 
2937 2937
                 if ($new_id) {
2938 2938
 
@@ -2963,9 +2963,9 @@  discard block
 block discarded – undo
2963 2963
 
2964 2964
                     Database::insert($table_wiki_conf, $params);
2965 2965
                 }
2966
-			}
2967
-		}
2968
-	}
2966
+            }
2967
+        }
2968
+    }
2969 2969
 
2970 2970
     /**
2971 2971
      * Restore Thematics
@@ -2973,15 +2973,15 @@  discard block
 block discarded – undo
2973 2973
      */
2974 2974
     public function restore_thematic($session_id = 0)
2975 2975
     {
2976
-		if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2976
+        if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2977 2977
             $table_thematic = Database:: get_course_table(TABLE_THEMATIC);
2978 2978
             $table_thematic_advance = Database:: get_course_table(TABLE_THEMATIC_ADVANCE);
2979 2979
             $table_thematic_plan = Database:: get_course_table(TABLE_THEMATIC_PLAN);
2980 2980
 
2981
-			$resources = $this->course->resources;
2982
-			foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2981
+            $resources = $this->course->resources;
2982
+            foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2983 2983
 
2984
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2984
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2985 2985
                 $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2986 2986
                     $thematic->params['content'],
2987 2987
                     $this->course->code,
@@ -2989,13 +2989,13 @@  discard block
 block discarded – undo
2989 2989
                     $this->course->backup_path,
2990 2990
                     $this->course->info['path']
2991 2991
                 );
2992
-				$thematic->params['c_id']  = $this->destination_course_id;
2993
-				unset($thematic->params['id']);
2992
+                $thematic->params['c_id']  = $this->destination_course_id;
2993
+                unset($thematic->params['id']);
2994 2994
                 unset($thematic->params['iid']);
2995 2995
 
2996
-				$last_id = Database::insert($table_thematic, $thematic->params, false);
2996
+                $last_id = Database::insert($table_thematic, $thematic->params, false);
2997 2997
 
2998
-				if ($last_id) {
2998
+                if ($last_id) {
2999 2999
 
3000 3000
                     $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id";
3001 3001
                     Database::query($sql);
@@ -3008,19 +3008,19 @@  discard block
 block discarded – undo
3008 3008
                         api_get_user_id()
3009 3009
                     );
3010 3010
 
3011
-					foreach ($thematic->thematic_advance_list as $thematic_advance) {
3012
-						unset($thematic_advance['id']);
3011
+                    foreach ($thematic->thematic_advance_list as $thematic_advance) {
3012
+                        unset($thematic_advance['id']);
3013 3013
                         unset($thematic_advance['iid']);
3014
-						$thematic_advance['attendance_id'] = 0;
3015
-						$thematic_advance['thematic_id'] = $last_id;
3016
-						$thematic_advance['c_id']  = $this->destination_course_id;
3014
+                        $thematic_advance['attendance_id'] = 0;
3015
+                        $thematic_advance['thematic_id'] = $last_id;
3016
+                        $thematic_advance['c_id']  = $this->destination_course_id;
3017 3017
                         $my_id = Database::insert(
3018 3018
                             $table_thematic_advance,
3019 3019
                             $thematic_advance,
3020 3020
                             false
3021 3021
                         );
3022 3022
 
3023
-						if ($my_id) {
3023
+                        if ($my_id) {
3024 3024
 
3025 3025
                             $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id";
3026 3026
                             Database::query($sql);
@@ -3032,17 +3032,17 @@  discard block
 block discarded – undo
3032 3032
                                 "ThematicAdvanceAdded",
3033 3033
                                 api_get_user_id()
3034 3034
                             );
3035
-						}
3036
-					}
3035
+                        }
3036
+                    }
3037 3037
 
3038
-					foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
-						unset($thematic_plan['id']);
3038
+                    foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
+                        unset($thematic_plan['id']);
3040 3040
                         unset($thematic_plan['iid']);
3041
-						$thematic_plan['thematic_id'] = $last_id;
3042
-						$thematic_plan['c_id'] = $this->destination_course_id;
3043
-						$my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3041
+                        $thematic_plan['thematic_id'] = $last_id;
3042
+                        $thematic_plan['c_id'] = $this->destination_course_id;
3043
+                        $my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3044 3044
 
3045
-						if ($my_id) {
3045
+                        if ($my_id) {
3046 3046
 
3047 3047
                             $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id";
3048 3048
                             Database::query($sql);
@@ -3054,12 +3054,12 @@  discard block
 block discarded – undo
3054 3054
                                 "ThematicPlanAdded",
3055 3055
                                 api_get_user_id()
3056 3056
                             );
3057
-						}
3058
-					}
3059
-				}
3060
-			}
3061
-		}
3062
-	}
3057
+                        }
3058
+                    }
3059
+                }
3060
+            }
3061
+        }
3062
+    }
3063 3063
 
3064 3064
     /**
3065 3065
      * Restore Attendance
@@ -3067,14 +3067,14 @@  discard block
 block discarded – undo
3067 3067
      */
3068 3068
     public function restore_attendance($session_id = 0)
3069 3069
     {
3070
-		if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
-			$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
-			$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3070
+        if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
+            $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
+            $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3073 3073
 
3074
-			$resources = $this->course->resources;
3075
-			foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3074
+            $resources = $this->course->resources;
3075
+            foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3076 3076
 
3077
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
3077
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
3078 3078
                 $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
3079 3079
                     $obj->params['description'],
3080 3080
                     $this->course->code,
@@ -3086,11 +3086,11 @@  discard block
 block discarded – undo
3086 3086
                 unset($obj->params['id']);
3087 3087
                 unset($obj->params['iid']);
3088 3088
 
3089
-				$obj->params['c_id'] = $this->destination_course_id;
3089
+                $obj->params['c_id'] = $this->destination_course_id;
3090 3090
 
3091
-				$last_id = Database::insert($table_attendance, $obj->params);
3091
+                $last_id = Database::insert($table_attendance, $obj->params);
3092 3092
 
3093
-				if (is_numeric($last_id)) {
3093
+                if (is_numeric($last_id)) {
3094 3094
 
3095 3095
                     $sql = "UPDATE $table_attendance SET id = iid WHERE iid = $last_id";
3096 3096
                     Database::query($sql);
@@ -3104,11 +3104,11 @@  discard block
 block discarded – undo
3104 3104
                     );
3105 3105
 
3106 3106
                     foreach ($obj->attendance_calendar as $attendance_calendar) {
3107
-						unset($attendance_calendar['id']);
3107
+                        unset($attendance_calendar['id']);
3108 3108
                         unset($attendance_calendar['iid']);
3109 3109
 
3110
-						$attendance_calendar['attendance_id'] = $last_id;
3111
-						$attendance_calendar['c_id'] = $this->destination_course_id;
3110
+                        $attendance_calendar['attendance_id'] = $last_id;
3111
+                        $attendance_calendar['c_id'] = $this->destination_course_id;
3112 3112
                         $attendanceCalendarId = Database::insert(
3113 3113
                             $table_attendance_calendar,
3114 3114
                             $attendance_calendar
@@ -3116,11 +3116,11 @@  discard block
 block discarded – undo
3116 3116
 
3117 3117
                         $sql = "UPDATE $table_attendance_calendar SET id = iid WHERE iid = $attendanceCalendarId";
3118 3118
                         Database::query($sql);
3119
-					}
3120
-				}
3121
-			}
3122
-		}
3123
-	}
3119
+                    }
3120
+                }
3121
+            }
3122
+        }
3123
+    }
3124 3124
 
3125 3125
     /**
3126 3126
      * Restore Works
@@ -3262,11 +3262,11 @@  discard block
 block discarded – undo
3262 3262
      */
3263 3263
     public function DBUTF8($str)
3264 3264
     {
3265
-		if (UTF8_CONVERT) {
3265
+        if (UTF8_CONVERT) {
3266 3266
             $str = utf8_encode($str);
3267 3267
         }
3268
-		return $str;
3269
-	}
3268
+        return $str;
3269
+    }
3270 3270
 
3271 3271
     /**
3272 3272
      * @param string $str
@@ -3277,8 +3277,8 @@  discard block
 block discarded – undo
3277 3277
         if (UTF8_CONVERT) {
3278 3278
             $str = utf8_encode($str);
3279 3279
         }
3280
-		return Database::escape_string($str);
3281
-	}
3280
+        return Database::escape_string($str);
3281
+    }
3282 3282
 
3283 3283
     /**
3284 3284
      * @param array $array
Please login to merge, or discard this patch.