Completed
Push — 1.11.x ( 6904fa...6a92e6 )
by José
525:44 queued 484:20
created
src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php 1 patch
Indentation   +707 added lines, -707 removed lines patch added patch discarded remove patch
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class CourseRestorer
23 23
 {
24
-	/**
25
-	 * The course-object
26
-	 */
24
+    /**
25
+     * The course-object
26
+     */
27 27
     public $course;
28 28
     public $destination_course_info;
29 29
 
30
-	/**
31
-	 * What to do with files with same name (FILE_SKIP, FILE_RENAME or
32
-	 * FILE_OVERWRITE)
33
-	 */
30
+    /**
31
+     * What to do with files with same name (FILE_SKIP, FILE_RENAME or
32
+     * FILE_OVERWRITE)
33
+     */
34 34
     public $file_option;
35 35
     public $set_tools_invisible_by_default;
36 36
     public $skip_content;
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         'events',
43 43
         'forum_category',
44 44
         'forums',
45
-       // 'forum_topics',
45
+        // 'forum_topics',
46 46
         'glossary',
47 47
         'quizzes',
48 48
         'test_category',
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
         $this->tool_copy_settings = $array;
111 111
     }
112 112
 
113
-	/**
114
-	 * Restore a course.
113
+    /**
114
+     * Restore a course.
115 115
      *
116
-	 * @param string    $destination_course_code code of the Chamilo-course in
117
-	 * @param int	    $session_id
118
-	 * @param bool	    $update_course_settings Course settings are going to be restore?
116
+     * @param string    $destination_course_code code of the Chamilo-course in
117
+     * @param int	    $session_id
118
+     * @param bool	    $update_course_settings Course settings are going to be restore?
119 119
      * @param bool      $respect_base_content
120 120
      * @return false|null
121
-	 */
121
+     */
122 122
     public function restore(
123 123
         $destination_course_code = '',
124 124
         $session_id = 0,
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
         }
262 262
     }
263 263
 
264
-	/**
265
-	 * Restore only harmless course settings:
264
+    /**
265
+     * Restore only harmless course settings:
266 266
      * course_language, visibility, department_name,department_url,
267 267
      * subscribe, unsubscribe ,category_code
268
-	 *
269
-	 * @param string $destination_course_code
270
-	 */
268
+     *
269
+     * @param string $destination_course_code
270
+     */
271 271
     public function restore_course_settings($destination_course_code)
272 272
     {
273
-	    $origin_course_info = api_get_course_info($destination_course_code);
274
-	    $course_info = $this->course->info;
273
+        $origin_course_info = api_get_course_info($destination_course_code);
274
+        $course_info = $this->course->info;
275 275
         $params['course_language'] = $course_info['language'];
276 276
         $params['visibility'] = $course_info['visibility'];
277 277
         $params['department_name'] = $course_info['department_name'];
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
         $params['category_code'] = $course_info['categoryCode'];
281 281
         $params['subscribe'] = $course_info['subscribe_allowed'];
282 282
         $params['unsubscribe'] = $course_info['unsubscribe'];
283
-	    CourseManager::update_attributes($origin_course_info['real_id'], $params);
284
-	}
283
+        CourseManager::update_attributes($origin_course_info['real_id'], $params);
284
+    }
285 285
 
286 286
     /**
287 287
      * Restore documents
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
         $course_info = api_get_course_info($destination_course_code);
296 296
 
297 297
         if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
298
-			$table = Database :: get_course_table(TABLE_DOCUMENT);
299
-			$resources = $this->course->resources;
298
+            $table = Database :: get_course_table(TABLE_DOCUMENT);
299
+            $resources = $this->course->resources;
300 300
             $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
301 301
 
302
-			foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
302
+            foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
303 303
                 if (empty($document->item_properties[0]['id_session'])) {
304 304
                     $my_session_id = 0;
305 305
                 } else {
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                             }
369 369
                         }
370 370
                     }
371
-		    	} elseif ($document->file_type == DOCUMENT) {
371
+                } elseif ($document->file_type == DOCUMENT) {
372 372
                     //Checking if folder exists in the database otherwise we created it
373 373
                     $dir_to_create = dirname($document->path);
374 374
 
@@ -424,19 +424,19 @@  discard block
 block discarded – undo
424 424
                         }
425 425
                     }
426 426
 
427
-					if (file_exists($path.$document->path)) {
428
-						switch ($this->file_option) {
429
-							case FILE_OVERWRITE:
427
+                    if (file_exists($path.$document->path)) {
428
+                        switch ($this->file_option) {
429
+                            case FILE_OVERWRITE:
430 430
                                 $origin_path = $this->course->backup_path.'/'.$document->path;
431 431
 
432
-								if (file_exists($origin_path)) {
433
-        						    copy($origin_path, $path.$document->path);
432
+                                if (file_exists($origin_path)) {
433
+                                    copy($origin_path, $path.$document->path);
434 434
                                     $sql = "SELECT id FROM $table
435 435
                                             WHERE
436 436
                                                 c_id = ".$this->destination_course_id." AND
437 437
                                                 path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'";
438 438
 
439
-        						    $res = Database::query($sql);
439
+                                    $res = Database::query($sql);
440 440
                                     $count = Database::num_rows($res);
441 441
 
442 442
                                     if ($count == 0) {
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
                                             'readonly' => 0
452 452
                                         ];
453 453
 
454
-    									$document_id = Database::insert($table, $params);
454
+                                        $document_id = Database::insert($table, $params);
455 455
 
456 456
                                         if ($document_id) {
457 457
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -559,83 +559,83 @@  discard block
 block discarded – undo
559 559
                                             ],
560 560
                                         ]
561 561
                                     );
562
-								}
562
+                                }
563 563
 
564
-								break;
565
-							case FILE_SKIP:
566
-								$sql = "SELECT id FROM $table
564
+                                break;
565
+                            case FILE_SKIP:
566
+                                $sql = "SELECT id FROM $table
567 567
 								        WHERE
568 568
 								            c_id = ".$this->destination_course_id." AND
569 569
 								            path='/".self::DBUTF8escapestring(substr($document->path, 9))."'";
570
-								$res = Database::query($sql);
571
-								$obj = Database::fetch_object($res);
572
-								$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
573
-								break;
574
-							case FILE_RENAME:
575
-								$i = 1;
576
-								$ext = explode('.', basename($document->path));
577
-								if (count($ext) > 1) {
578
-									$ext = array_pop($ext);
579
-									$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
580
-									$ext = '.'.$ext;
581
-								} else {
582
-									$ext = '';
583
-									$file_name_no_ext = $document->path;
584
-								}
585
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
586
-								$file_exists = file_exists($path.$new_file_name);
587
-								while ($file_exists) {
588
-									$i ++;
589
-									$new_file_name = $file_name_no_ext.'_'.$i.$ext;
590
-									$file_exists = file_exists($path.$new_file_name);
591
-								}
592
-
593
-								if (!empty($session_id)) {
594
-
595
-									$document_path = explode('/',$document->path,3);
596
-									$course_path = $path;
597
-									$orig_base_folder = $document_path[1];
598
-									$orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
599
-
600
-									if (is_dir($orig_base_path)) {
601
-
602
-										$new_base_foldername = $orig_base_folder;
603
-										$new_base_path = $orig_base_path;
604
-
605
-										if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
606
-											unset($_SESSION['new_base_foldername']);
607
-											unset($_SESSION['orig_base_foldername']);
608
-											unset($_SESSION['new_base_path']);
609
-										}
610
-
611
-										$folder_exists = file_exists($new_base_path);
612
-										if ($folder_exists) {
613
-											$_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
614
-											$x = '';
615
-											while ($folder_exists) {
616
-												$x = $x + 1;
617
-												$new_base_foldername = $document_path[1].'_'.$x;
618
-												$new_base_path = $orig_base_path.'_'.$x;
570
+                                $res = Database::query($sql);
571
+                                $obj = Database::fetch_object($res);
572
+                                $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
573
+                                break;
574
+                            case FILE_RENAME:
575
+                                $i = 1;
576
+                                $ext = explode('.', basename($document->path));
577
+                                if (count($ext) > 1) {
578
+                                    $ext = array_pop($ext);
579
+                                    $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
580
+                                    $ext = '.'.$ext;
581
+                                } else {
582
+                                    $ext = '';
583
+                                    $file_name_no_ext = $document->path;
584
+                                }
585
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
586
+                                $file_exists = file_exists($path.$new_file_name);
587
+                                while ($file_exists) {
588
+                                    $i ++;
589
+                                    $new_file_name = $file_name_no_ext.'_'.$i.$ext;
590
+                                    $file_exists = file_exists($path.$new_file_name);
591
+                                }
592
+
593
+                                if (!empty($session_id)) {
594
+
595
+                                    $document_path = explode('/',$document->path,3);
596
+                                    $course_path = $path;
597
+                                    $orig_base_folder = $document_path[1];
598
+                                    $orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
599
+
600
+                                    if (is_dir($orig_base_path)) {
601
+
602
+                                        $new_base_foldername = $orig_base_folder;
603
+                                        $new_base_path = $orig_base_path;
604
+
605
+                                        if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
606
+                                            unset($_SESSION['new_base_foldername']);
607
+                                            unset($_SESSION['orig_base_foldername']);
608
+                                            unset($_SESSION['new_base_path']);
609
+                                        }
610
+
611
+                                        $folder_exists = file_exists($new_base_path);
612
+                                        if ($folder_exists) {
613
+                                            $_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
614
+                                            $x = '';
615
+                                            while ($folder_exists) {
616
+                                                $x = $x + 1;
617
+                                                $new_base_foldername = $document_path[1].'_'.$x;
618
+                                                $new_base_path = $orig_base_path.'_'.$x;
619 619
                                                 if ($_SESSION['new_base_foldername'] == $new_base_foldername) {
620 620
                                                     break;
621 621
                                                 }
622
-												$folder_exists = file_exists($new_base_path);
623
-											}
624
-											$_SESSION['new_base_foldername'] = $new_base_foldername;
625
-											$_SESSION['new_base_path'] = $new_base_path;
626
-										}
627
-
628
-										if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
629
-											$new_base_foldername = $_SESSION['new_base_foldername'];
630
-											$new_base_path = $_SESSION['new_base_path'];
631
-										}
632
-
633
-										$dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
634
-										$basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
635
-										$base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
636
-										$path_title = '/'.$new_base_foldername.'/'.$document_path[2];
637
-
638
-										copy_folder_course_session(
622
+                                                $folder_exists = file_exists($new_base_path);
623
+                                            }
624
+                                            $_SESSION['new_base_foldername'] = $new_base_foldername;
625
+                                            $_SESSION['new_base_path'] = $new_base_path;
626
+                                        }
627
+
628
+                                        if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
629
+                                            $new_base_foldername = $_SESSION['new_base_foldername'];
630
+                                            $new_base_path = $_SESSION['new_base_path'];
631
+                                        }
632
+
633
+                                        $dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
634
+                                        $basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
635
+                                        $base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
636
+                                        $path_title = '/'.$new_base_foldername.'/'.$document_path[2];
637
+
638
+                                        copy_folder_course_session(
639 639
                                             $basedir_dest_path,
640 640
                                             $base_path_document,
641 641
                                             $session_id,
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
                                             'session_id' => $my_session_id,
678 678
                                         ];
679 679
 
680
-										$document_id = Database::insert($table, $params);
680
+                                        $document_id = Database::insert($table, $params);
681 681
 
682 682
                                         if ($document_id) {
683 683
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -706,10 +706,10 @@  discard block
 block discarded – undo
706 706
                                             null,
707 707
                                             $my_session_id
708 708
                                         );
709
-									} else {
710
-									    if (file_exists($path.$document->path)) {
709
+                                    } else {
710
+                                        if (file_exists($path.$document->path)) {
711 711
                                             copy($path.$document->path, $path.$new_file_name);
712
-									    }
712
+                                        }
713 713
                                         //Replace old course code with the new destination code see BT#1985
714 714
                                         if (file_exists($path.$new_file_name)) {
715 715
                                             $file_info = pathinfo($path.$new_file_name);
@@ -768,10 +768,10 @@  discard block
 block discarded – undo
768 768
                                                 $my_session_id
769 769
                                             );
770 770
                                         }
771
-									}
772
-								} else {
771
+                                    }
772
+                                } else {
773 773
 
774
-									copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
774
+                                    copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
775 775
 
776 776
                                     //Replace old course code with the new destination code see BT#1985
777 777
                                     if (file_exists($path.$new_file_name)) {
@@ -831,20 +831,20 @@  discard block
 block discarded – undo
831 831
                                         null,
832 832
                                         $my_session_id
833 833
                                     );
834
-								}
835
-								break;
836
-
837
-						} // end switch
838
-					} else {
839
-					    // end if file exists
840
-						//make sure the source file actually exists
841
-						if (is_file($this->course->backup_path.'/'.$document->path) &&
834
+                                }
835
+                                break;
836
+
837
+                        } // end switch
838
+                    } else {
839
+                        // end if file exists
840
+                        //make sure the source file actually exists
841
+                        if (is_file($this->course->backup_path.'/'.$document->path) &&
842 842
                             is_readable($this->course->backup_path.'/'.$document->path) &&
843 843
                             is_dir(dirname($path.$document->path)) &&
844 844
                             is_writeable(dirname($path.$document->path))
845 845
                         ) {
846
-						    //echo 'Copying';
847
-							copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
846
+                            //echo 'Copying';
847
+                            copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
848 848
 
849 849
                             //Replace old course code with the new destination code see BT#1985
850 850
                             if (file_exists($path.$document->path)) {
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
                                 Database::query($sql);
884 884
                             }
885 885
 
886
-							$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
886
+                            $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
887 887
 
888 888
                             $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
889 889
                             $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
@@ -905,78 +905,78 @@  discard block
 block discarded – undo
905 905
                                 null,
906 906
                                 $my_session_id
907 907
                             );
908
-						} else {
909
-							if (is_file($this->course->backup_path.'/'.$document->path) &&
908
+                        } else {
909
+                            if (is_file($this->course->backup_path.'/'.$document->path) &&
910 910
                                 is_readable($this->course->backup_path.'/'.$document->path)
911 911
                             ) {
912
-								error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
913
-							}
914
-							if (!is_dir(dirname($path.$document->path))) {
915
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
916
-							}
917
-							if (!is_writeable(dirname($path.$document->path))) {
918
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
919
-							}
920
-						}
921
-					} // end file doesn't exist
922
-				}
923
-			} // end for each
924
-
925
-    		// Delete sessions for the copy the new folder in session
926
-    		unset($_SESSION['new_base_foldername']);
927
-    		unset($_SESSION['orig_base_foldername']);
928
-    		unset($_SESSION['new_base_path']);
929
-		}
930
-	}
931
-
932
-	/**
933
-	 * Restore scorm documents
934
-	 * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
912
+                                error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
913
+                            }
914
+                            if (!is_dir(dirname($path.$document->path))) {
915
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
916
+                            }
917
+                            if (!is_writeable(dirname($path.$document->path))) {
918
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
919
+                            }
920
+                        }
921
+                    } // end file doesn't exist
922
+                }
923
+            } // end for each
924
+
925
+            // Delete sessions for the copy the new folder in session
926
+            unset($_SESSION['new_base_foldername']);
927
+            unset($_SESSION['orig_base_foldername']);
928
+            unset($_SESSION['new_base_path']);
929
+        }
930
+    }
931
+
932
+    /**
933
+     * Restore scorm documents
934
+     * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
935 935
      * see #7029
936
-	 */
937
-	public function restore_scorm_documents()
936
+     */
937
+    public function restore_scorm_documents()
938 938
     {
939
-		$perm = api_get_permissions_for_new_directories();
939
+        $perm = api_get_permissions_for_new_directories();
940 940
 
941
-		if ($this->course->has_resources(RESOURCE_SCORM)) {
942
-			$resources = $this->course->resources;
941
+        if ($this->course->has_resources(RESOURCE_SCORM)) {
942
+            $resources = $this->course->resources;
943 943
 
944
-			foreach ($resources[RESOURCE_SCORM] as $document) {
945
-				$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
946
-				@mkdir(dirname($path.$document->path), $perm, true);
944
+            foreach ($resources[RESOURCE_SCORM] as $document) {
945
+                $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
946
+                @mkdir(dirname($path.$document->path), $perm, true);
947 947
 
948
-				if (file_exists($path.$document->path)) {
949
-					switch ($this->file_option) {
950
-						case FILE_OVERWRITE:
951
-							rmdirr($path.$document->path);
948
+                if (file_exists($path.$document->path)) {
949
+                    switch ($this->file_option) {
950
+                        case FILE_OVERWRITE:
951
+                            rmdirr($path.$document->path);
952 952
                             copyDirTo(
953 953
                                 $this->course->backup_path . '/' . $document->path,
954 954
                                 $path . dirname($document->path),
955 955
                                 false
956 956
                             );
957
-							break;
958
-						case FILE_SKIP:
959
-							break;
957
+                            break;
958
+                        case FILE_SKIP:
959
+                            break;
960 960
                         case FILE_RENAME:
961
-							$i = 1;
962
-							$ext = explode('.', basename($document->path));
963
-							if (count($ext) > 1) {
964
-								$ext = array_pop($ext);
965
-								$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
966
-								$ext = '.'.$ext;
967
-							} else {
968
-								$ext = '';
969
-								$file_name_no_ext = $document->path;
970
-							}
971
-
972
-							$new_file_name = $file_name_no_ext.'_'.$i.$ext;
973
-							$file_exists = file_exists($path.$new_file_name);
974
-
975
-							while ($file_exists) {
976
-								$i ++;
977
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
978
-								$file_exists = file_exists($path.$new_file_name);
979
-							}
961
+                            $i = 1;
962
+                            $ext = explode('.', basename($document->path));
963
+                            if (count($ext) > 1) {
964
+                                $ext = array_pop($ext);
965
+                                $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
966
+                                $ext = '.'.$ext;
967
+                            } else {
968
+                                $ext = '';
969
+                                $file_name_no_ext = $document->path;
970
+                            }
971
+
972
+                            $new_file_name = $file_name_no_ext.'_'.$i.$ext;
973
+                            $file_exists = file_exists($path.$new_file_name);
974
+
975
+                            while ($file_exists) {
976
+                                $i ++;
977
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
978
+                                $file_exists = file_exists($path.$new_file_name);
979
+                            }
980 980
 
981 981
                             rename(
982 982
                                 $this->course->backup_path . '/' . $document->path,
@@ -992,30 +992,30 @@  discard block
 block discarded – undo
992 992
                                 $this->course->backup_path . '/' . $document->path
993 993
                             );
994 994
 
995
-							break;
996
-					} // end switch
997
-				} else {
995
+                            break;
996
+                    } // end switch
997
+                } else {
998 998
                     // end if file exists
999 999
                     copyDirTo(
1000 1000
                         $this->course->backup_path . '/' . $document->path,
1001 1001
                         $path . dirname($document->path),
1002 1002
                         false
1003 1003
                     );
1004
-				}
1005
-			} // end for each
1006
-		}
1007
-	}
1008
-
1009
-	/**
1010
-	 * Restore forums
1011
-	 */
1012
-	public function restore_forums($sessionId = 0)
1004
+                }
1005
+            } // end for each
1006
+        }
1007
+    }
1008
+
1009
+    /**
1010
+     * Restore forums
1011
+     */
1012
+    public function restore_forums($sessionId = 0)
1013 1013
     {
1014
-		if ($this->course->has_resources(RESOURCE_FORUM)) {
1014
+        if ($this->course->has_resources(RESOURCE_FORUM)) {
1015 1015
             $sessionId = intval($sessionId);
1016
-			$table_forum = Database::get_course_table(TABLE_FORUM);
1017
-			$resources = $this->course->resources;
1018
-			foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1016
+            $table_forum = Database::get_course_table(TABLE_FORUM);
1017
+            $resources = $this->course->resources;
1018
+            foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1019 1019
                 $params = (array)$forum->obj;
1020 1020
                 $cat_id = '';
1021 1021
                 if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) &&
@@ -1062,33 +1062,33 @@  discard block
 block discarded – undo
1062 1062
                     Database::query($sql);
1063 1063
                 }
1064 1064
 
1065
-				$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1066
-
1067
-				$forum_topics = 0;
1068
-				if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1069
-					foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1070
-						if ($topic->obj->forum_id == $id) {
1071
-							$this->restore_topic($topic_id, $new_id, $sessionId);
1072
-							$forum_topics ++;
1073
-						}
1074
-					}
1075
-				}
1076
-				if ($forum_topics > 0) {
1077
-					$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1065
+                $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1066
+
1067
+                $forum_topics = 0;
1068
+                if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1069
+                    foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1070
+                        if ($topic->obj->forum_id == $id) {
1071
+                            $this->restore_topic($topic_id, $new_id, $sessionId);
1072
+                            $forum_topics ++;
1073
+                        }
1074
+                    }
1075
+                }
1076
+                if ($forum_topics > 0) {
1077
+                    $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1078 1078
                             WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id;
1079
-					Database::query($sql);
1080
-				}
1081
-			}
1082
-		}
1083
-	}
1084
-
1085
-	/**
1086
-	 * Restore forum-categories
1087
-	 */
1079
+                    Database::query($sql);
1080
+                }
1081
+            }
1082
+        }
1083
+    }
1084
+
1085
+    /**
1086
+     * Restore forum-categories
1087
+     */
1088 1088
     public function restore_forum_category($my_id = null, $sessionId = 0)
1089 1089
     {
1090
-		$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1091
-		$resources = $this->course->resources;
1090
+        $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1091
+        $resources = $this->course->resources;
1092 1092
         if (!empty($resources[RESOURCE_FORUMCATEGORY])) {
1093 1093
             foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) {
1094 1094
                 if (!empty($my_id)) {
@@ -1125,16 +1125,16 @@  discard block
 block discarded – undo
1125 1125
                 }
1126 1126
             }
1127 1127
         }
1128
-	}
1128
+    }
1129 1129
 
1130
-	/**
1131
-	 * Restore a forum-topic
1132
-	 * @param false|string $forum_id
1133
-	 */
1130
+    /**
1131
+     * Restore a forum-topic
1132
+     * @param false|string $forum_id
1133
+     */
1134 1134
     public function restore_topic($thread_id, $forum_id, $sessionId = 0)
1135 1135
     {
1136
-		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
1137
-		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1136
+        $table = Database :: get_course_table(TABLE_FORUM_THREAD);
1137
+        $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1138 1138
 
1139 1139
         $params = (array)$topic->obj;
1140 1140
         $params = self::DBUTF8_array($params);
@@ -1171,27 +1171,27 @@  discard block
 block discarded – undo
1171 1171
             $sessionId
1172 1172
         );
1173 1173
 
1174
-		$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1175
-		$topic_replies = -1;
1176
-
1177
-		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1178
-			if ($post->obj->thread_id == $thread_id) {
1179
-				$topic_replies++;
1180
-				$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1181
-			}
1182
-		}
1183
-		return $new_id;
1184
-	}
1185
-
1186
-	/**
1187
-	 * Restore a forum-post
1188
-	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1189
-	 * @param false|string $topic_id
1190
-	 */
1174
+        $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1175
+        $topic_replies = -1;
1176
+
1177
+        foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1178
+            if ($post->obj->thread_id == $thread_id) {
1179
+                $topic_replies++;
1180
+                $this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1181
+            }
1182
+        }
1183
+        return $new_id;
1184
+    }
1185
+
1186
+    /**
1187
+     * Restore a forum-post
1188
+     * @TODO Restore tree-structure of posts. For example: attachments to posts.
1189
+     * @param false|string $topic_id
1190
+     */
1191 1191
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1192 1192
     {
1193
-		$table_post = Database :: get_course_table(TABLE_FORUM_POST);
1194
-		$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1193
+        $table_post = Database :: get_course_table(TABLE_FORUM_POST);
1194
+        $post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1195 1195
         $params = (array) $post->obj;
1196 1196
         $params['c_id'] = $this->destination_course_id;
1197 1197
         $params['forum_id'] = $forum_id;
@@ -1226,37 +1226,37 @@  discard block
 block discarded – undo
1226 1226
             null,
1227 1227
             $sessionId
1228 1228
         );
1229
-		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1229
+        $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1230 1230
 
1231
-		return $new_id;
1232
-	}
1231
+        return $new_id;
1232
+    }
1233 1233
 
1234
-	/**
1235
-	 * Restore links
1236
-	 */
1234
+    /**
1235
+     * Restore links
1236
+     */
1237 1237
     public function restore_links($session_id = 0)
1238 1238
     {
1239
-		if ($this->course->has_resources(RESOURCE_LINK)) {
1240
-			$link_table = Database :: get_course_table(TABLE_LINK);
1241
-			$resources = $this->course->resources;
1239
+        if ($this->course->has_resources(RESOURCE_LINK)) {
1240
+            $link_table = Database :: get_course_table(TABLE_LINK);
1241
+            $resources = $this->course->resources;
1242 1242
 
1243
-			foreach ($resources[RESOURCE_LINK] as $id => $link) {
1243
+            foreach ($resources[RESOURCE_LINK] as $id => $link) {
1244 1244
                 $cat_id = $this->restore_link_category(
1245 1245
                     $link->category_id,
1246 1246
                     $session_id
1247 1247
                 );
1248
-				$sql = "SELECT MAX(display_order)
1248
+                $sql = "SELECT MAX(display_order)
1249 1249
 				        FROM $link_table
1250 1250
 				        WHERE
1251 1251
 				            c_id = ".$this->destination_course_id." AND
1252 1252
 				            category_id='" . intval($cat_id). "'";
1253
-				$result = Database::query($sql);
1254
-    			list($max_order) = Database::fetch_array($result);
1253
+                $result = Database::query($sql);
1254
+                list($max_order) = Database::fetch_array($result);
1255 1255
 
1256 1256
                 $params = [];
1257
-    			if (!empty($session_id)) {
1257
+                if (!empty($session_id)) {
1258 1258
                     $params['session_id'] = $session_id;
1259
-    			}
1259
+                }
1260 1260
 
1261 1261
                 $params['c_id'] = $this->destination_course_id;
1262 1262
                 $params['url'] = self::DBUTF8($link->url);
@@ -1285,9 +1285,9 @@  discard block
 block discarded – undo
1285 1285
                     }
1286 1286
                     $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id;
1287 1287
                 }
1288
-			}
1289
-		}
1290
-	}
1288
+            }
1289
+        }
1290
+    }
1291 1291
 
1292 1292
     /**
1293 1293
      * Restore a link-category
@@ -1331,21 +1331,21 @@  discard block
 block discarded – undo
1331 1331
         return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id;
1332 1332
     }
1333 1333
 
1334
-	/**
1335
-	 * Restore tool intro
1336
-	 */
1334
+    /**
1335
+     * Restore tool intro
1336
+     */
1337 1337
     public function restore_tool_intro($sessionId = 0)
1338 1338
     {
1339
-		if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1339
+        if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1340 1340
             $sessionId = intval($sessionId);
1341
-			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1342
-			$resources = $this->course->resources;
1343
-			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1344
-				$sql = "DELETE FROM ".$tool_intro_table."
1341
+            $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1342
+            $resources = $this->course->resources;
1343
+            foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1344
+                $sql = "DELETE FROM ".$tool_intro_table."
1345 1345
 				        WHERE
1346 1346
 				            c_id = ".$this->destination_course_id." AND
1347 1347
 				            id='".self::DBUTF8escapestring($tool_intro->id)."'";
1348
-				Database::query($sql);
1348
+                Database::query($sql);
1349 1349
 
1350 1350
                 $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1351 1351
                     $tool_intro->intro_text,
@@ -1373,21 +1373,21 @@  discard block
 block discarded – undo
1373 1373
 
1374 1374
                     $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id;
1375 1375
                 }
1376
-			}
1377
-		}
1378
-	}
1376
+            }
1377
+        }
1378
+    }
1379 1379
 
1380
-	/**
1381
-	 * Restore events
1382
-	 */
1380
+    /**
1381
+     * Restore events
1382
+     */
1383 1383
     public function restore_events($sessionId = 0)
1384 1384
     {
1385
-		if ($this->course->has_resources(RESOURCE_EVENT)) {
1385
+        if ($this->course->has_resources(RESOURCE_EVENT)) {
1386 1386
             $sessionId = intval($sessionId);
1387
-			$table = Database :: get_course_table(TABLE_AGENDA);
1388
-			$resources = $this->course->resources;
1389
-			foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1390
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1387
+            $table = Database :: get_course_table(TABLE_AGENDA);
1388
+            $resources = $this->course->resources;
1389
+            foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1390
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1391 1391
                 $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1392 1392
                     $event->content,
1393 1393
                     $this->course->code,
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
                     'end_date' => $event->end_date,
1406 1406
                     'session_id' => $sessionId,
1407 1407
                 ];
1408
-				$new_event_id = Database::insert($table, $params);
1408
+                $new_event_id = Database::insert($table, $params);
1409 1409
 
1410 1410
                 if ($new_event_id) {
1411 1411
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id";
@@ -1418,30 +1418,30 @@  discard block
 block discarded – undo
1418 1418
                     $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
1419 1419
                 }
1420 1420
 
1421
-				// Copy event attachment
1421
+                // Copy event attachment
1422 1422
 
1423
-				$origin_path = $this->course->backup_path.'/upload/calendar/';
1424
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1423
+                $origin_path = $this->course->backup_path.'/upload/calendar/';
1424
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1425 1425
 
1426
-				if (!empty($this->course->orig)) {
1426
+                if (!empty($this->course->orig)) {
1427 1427
 
1428
-					$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1429
-					$sql = 'SELECT path, comment, size, filename
1428
+                    $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1429
+                    $sql = 'SELECT path, comment, size, filename
1430 1430
 					        FROM '.$table_attachment.'
1431 1431
 					        WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
1432
-					$attachment_event = Database::query($sql);
1433
-					$attachment_event = Database::fetch_object($attachment_event);
1432
+                    $attachment_event = Database::query($sql);
1433
+                    $attachment_event = Database::fetch_object($attachment_event);
1434 1434
 
1435
-					if (file_exists($origin_path.$attachment_event->path) &&
1435
+                    if (file_exists($origin_path.$attachment_event->path) &&
1436 1436
                         !is_dir($origin_path.$attachment_event->path)
1437 1437
                     ) {
1438
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1439
-						$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1440
-						//$copy_result = true;
1441
-						if ($copy_result) {
1442
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1438
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1439
+                        $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1440
+                        //$copy_result = true;
1441
+                        if ($copy_result) {
1442
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1443 1443
 
1444
-							$params = [
1444
+                            $params = [
1445 1445
                                 'c_id' => $this->destination_course_id,
1446 1446
                                 'path' => self::DBUTF8($new_filename),
1447 1447
                                 'comment' => self::DBUTF8($attachment_event->comment),
@@ -1455,17 +1455,17 @@  discard block
 block discarded – undo
1455 1455
                                 Database::query($sql);
1456 1456
                             }
1457 1457
                         }
1458
-					}
1459
-				} else {
1460
-					// get the info of the file
1461
-					if (!empty($event->attachment_path) &&
1458
+                    }
1459
+                } else {
1460
+                    // get the info of the file
1461
+                    if (!empty($event->attachment_path) &&
1462 1462
                         is_file($origin_path.$event->attachment_path) &&
1463 1463
                         is_readable($origin_path.$event->attachment_path)
1464 1464
                     ) {
1465
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1466
-						$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1467
-						if ($copy_result) {
1468
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1465
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1466
+                        $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1467
+                        if ($copy_result) {
1468
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1469 1469
 
1470 1470
                             $params = [
1471 1471
                                 'c_id' => $this->destination_course_id,
@@ -1481,29 +1481,29 @@  discard block
 block discarded – undo
1481 1481
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id";
1482 1482
                                 Database::query($sql);
1483 1483
                             }
1484
-						}
1485
-					}
1486
-				}
1487
-			}
1488
-		}
1489
-	}
1490
-
1491
-	/**
1492
-	 * Restore course-description
1493
-	 */
1484
+                        }
1485
+                    }
1486
+                }
1487
+            }
1488
+        }
1489
+    }
1490
+
1491
+    /**
1492
+     * Restore course-description
1493
+     */
1494 1494
     public function restore_course_descriptions($session_id = 0)
1495 1495
     {
1496
-		if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1497
-			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1498
-			$resources = $this->course->resources;
1499
-			foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1496
+        if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1497
+            $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1498
+            $resources = $this->course->resources;
1499
+            foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1500 1500
                 $courseDescription = (array) $cd;
1501 1501
 
1502 1502
                 $content = isset($courseDescription['content']) ? $courseDescription['content'] : '';
1503 1503
                 $descriptionType = isset($courseDescription['description_type']) ? $courseDescription['description_type'] : '';
1504 1504
                 $title = isset($courseDescription['title']) ? $courseDescription['title'] : '';
1505 1505
 
1506
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1506
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1507 1507
                 $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1508 1508
                     $content,
1509 1509
                     $this->course->code,
@@ -1532,22 +1532,22 @@  discard block
 block discarded – undo
1532 1532
                     }
1533 1533
                     $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id;
1534 1534
                 }
1535
-			}
1536
-		}
1537
-	}
1535
+            }
1536
+        }
1537
+    }
1538 1538
 
1539
-	/**
1540
-	 * Restore announcements
1541
-	 */
1539
+    /**
1540
+     * Restore announcements
1541
+     */
1542 1542
     public function restore_announcements($sessionId = 0)
1543 1543
     {
1544
-		if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1544
+        if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1545 1545
             $sessionId = intval($sessionId);
1546
-			$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1547
-			$resources = $this->course->resources;
1548
-			foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1546
+            $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1547
+            $resources = $this->course->resources;
1548
+            foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1549 1549
 
1550
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1550
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1551 1551
                 $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1552 1552
                     $announcement->content,
1553 1553
                     $this->course->code,
@@ -1566,7 +1566,7 @@  discard block
 block discarded – undo
1566 1566
                     'session_id' => $sessionId,
1567 1567
                 ];
1568 1568
 
1569
-				$new_announcement_id = Database::insert($table, $params);
1569
+                $new_announcement_id = Database::insert($table, $params);
1570 1570
 
1571 1571
                 if ($new_announcement_id) {
1572 1572
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id";
@@ -1578,32 +1578,32 @@  discard block
 block discarded – undo
1578 1578
                     $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id;
1579 1579
                 }
1580 1580
 
1581
-				$origin_path = $this->course->backup_path.'/upload/announcements/';
1582
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1581
+                $origin_path = $this->course->backup_path.'/upload/announcements/';
1582
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1583 1583
 
1584
-				// Copy announcement attachment file
1585
-				if (!empty($this->course->orig)) {
1584
+                // Copy announcement attachment file
1585
+                if (!empty($this->course->orig)) {
1586 1586
 
1587
-					$table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1588
-					$sql = 'SELECT path, comment, size, filename
1587
+                    $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1588
+                    $sql = 'SELECT path, comment, size, filename
1589 1589
 					        FROM '.$table_attachment.'
1590 1590
 					        WHERE
1591 1591
 					            c_id = '.$this->destination_course_id.' AND
1592 1592
 					            announcement_id = '.$id;
1593
-					$attachment_event = Database::query($sql);
1594
-					$attachment_event = Database::fetch_object($attachment_event);
1593
+                    $attachment_event = Database::query($sql);
1594
+                    $attachment_event = Database::fetch_object($attachment_event);
1595 1595
 
1596
-					if (file_exists($origin_path.$attachment_event->path) &&
1596
+                    if (file_exists($origin_path.$attachment_event->path) &&
1597 1597
                         !is_dir($origin_path.$attachment_event->path)
1598 1598
                     ) {
1599
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1599
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1600 1600
                         $copy_result = copy(
1601 1601
                             $origin_path.$attachment_event->path,
1602 1602
                             $destination_path.$new_filename
1603 1603
                         );
1604 1604
 
1605
-						if ($copy_result) {
1606
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1605
+                        if ($copy_result) {
1606
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1607 1607
 
1608 1608
                             $params = [
1609 1609
                                 'c_id' => $this->destination_course_id,
@@ -1620,19 +1620,19 @@  discard block
 block discarded – undo
1620 1620
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1621 1621
                                 Database::query($sql);
1622 1622
                             }
1623
-						}
1624
-					}
1625
-				} else {
1626
-					// get the info of the file
1627
-					if (!empty($announcement->attachment_path) &&
1623
+                        }
1624
+                    }
1625
+                } else {
1626
+                    // get the info of the file
1627
+                    if (!empty($announcement->attachment_path) &&
1628 1628
                         is_file($origin_path.$announcement->attachment_path) &&
1629 1629
                         is_readable($origin_path.$announcement->attachment_path)
1630 1630
                     ) {
1631
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1632
-						$copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1631
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1632
+                        $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1633 1633
 
1634
-						if ($copy_result) {
1635
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1634
+                        if ($copy_result) {
1635
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1636 1636
 
1637 1637
                             $params = [
1638 1638
                                 'c_id' => $this->destination_course_id,
@@ -1649,12 +1649,12 @@  discard block
 block discarded – undo
1649 1649
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1650 1650
                                 Database::query($sql);
1651 1651
                             }
1652
-						}
1653
-					}
1654
-				}
1655
-			}
1656
-		}
1657
-	}
1652
+                        }
1653
+                    }
1654
+                }
1655
+            }
1656
+        }
1657
+    }
1658 1658
 
1659 1659
     /**
1660 1660
      * Restore Quiz
@@ -1665,13 +1665,13 @@  discard block
 block discarded – undo
1665 1665
         $session_id = 0,
1666 1666
         $respect_base_content = false
1667 1667
     ) {
1668
-		if ($this->course->has_resources(RESOURCE_QUIZ)) {
1669
-			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1670
-			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1671
-			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1672
-			$resources = $this->course->resources;
1668
+        if ($this->course->has_resources(RESOURCE_QUIZ)) {
1669
+            $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1670
+            $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1671
+            $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1672
+            $resources = $this->course->resources;
1673 1673
 
1674
-			foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1674
+            foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1675 1675
 
1676 1676
                 if (isset($quiz->obj)) {
1677 1677
                     //For new imports
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
                     $quiz->obj = $quiz;
1682 1682
                 }
1683 1683
 
1684
-				$doc = '';
1684
+                $doc = '';
1685 1685
                 if (!empty($quiz->sound)) {
1686 1686
                     if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
1687 1687
                         $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
@@ -1689,14 +1689,14 @@  discard block
 block discarded – undo
1689 1689
                                 WHERE
1690 1690
                                     c_id = " . $this->destination_course_id . "  AND
1691 1691
                                     id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
1692
-						$doc = Database::query($sql);
1693
-						$doc = Database::fetch_object($doc);
1694
-						$doc = str_replace('/audio/', '', $doc->path);
1695
-					}
1696
-				}
1697
-
1698
-				if ($id != -1) {
1699
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1692
+                        $doc = Database::query($sql);
1693
+                        $doc = Database::fetch_object($doc);
1694
+                        $doc = str_replace('/audio/', '', $doc->path);
1695
+                    }
1696
+                }
1697
+
1698
+                if ($id != -1) {
1699
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1700 1700
                     $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1701 1701
                         $quiz->description,
1702 1702
                         $this->course->code,
@@ -1708,13 +1708,13 @@  discard block
 block discarded – undo
1708 1708
                     $quiz->start_time = $quiz->start_time == '0000-00-00 00:00:00' ? null : $quiz->start_time;
1709 1709
                     $quiz->end_time = $quiz->end_time == '0000-00-00 00:00:00' ? null : $quiz->end_time;
1710 1710
 
1711
-					global $_custom;
1712
-					if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1711
+                    global $_custom;
1712
+                    if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1713 1713
                         $_custom['exercises_clean_dates_when_restoring']
1714 1714
                     ) {
1715
-						$quiz->start_time = null;
1716
-						$quiz->end_time   = null;
1717
-					}
1715
+                        $quiz->start_time = null;
1716
+                        $quiz->end_time   = null;
1717
+                    }
1718 1718
 
1719 1719
                     $params = array(
1720 1720
                         'c_id' => $this->destination_course_id,
@@ -1748,10 +1748,10 @@  discard block
 block discarded – undo
1748 1748
                         }
1749 1749
                         $params['session_id'] = $my_session_id;
1750 1750
                     } else {
1751
-        				if (!empty($session_id)) {
1752
-        					$session_id = intval($session_id);
1751
+                        if (!empty($session_id)) {
1752
+                            $session_id = intval($session_id);
1753 1753
                             $params['session_id'] = $session_id;
1754
-    				    }
1754
+                        }
1755 1755
                     }
1756 1756
                     $new_id = Database::insert($table_qui, $params);
1757 1757
 
@@ -1760,15 +1760,15 @@  discard block
 block discarded – undo
1760 1760
                         Database::query($sql);
1761 1761
                     }
1762 1762
 
1763
-				} else {
1764
-					// $id = -1 identifies the fictionary test for collecting
1765
-					// orphan questions. We do not store it in the database.
1766
-					$new_id = -1;
1767
-				}
1763
+                } else {
1764
+                    // $id = -1 identifies the fictionary test for collecting
1765
+                    // orphan questions. We do not store it in the database.
1766
+                    $new_id = -1;
1767
+                }
1768 1768
 
1769
-				$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1769
+                $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1770 1770
 
1771
-				$order = 0;
1771
+                $order = 0;
1772 1772
                 if (!empty($quiz->question_ids)) {
1773 1773
                     foreach ($quiz->question_ids as $index => $question_id) {
1774 1774
                         $qid = $this->restore_quiz_question($question_id);
@@ -1781,30 +1781,30 @@  discard block
 block discarded – undo
1781 1781
                         Database::query($sql);
1782 1782
                     }
1783 1783
                 }
1784
-			}
1785
-		}
1786
-	}
1784
+            }
1785
+        }
1786
+    }
1787 1787
 
1788
-	/**
1789
-	 * Restore quiz-questions
1788
+    /**
1789
+     * Restore quiz-questions
1790 1790
      * @params int question id
1791
-	 */
1791
+     */
1792 1792
     public function restore_quiz_question($id)
1793 1793
     {
1794
-		$resources = $this->course->resources;
1794
+        $resources = $this->course->resources;
1795 1795
         $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
1796 1796
 
1797
-		$new_id = 0;
1797
+        $new_id = 0;
1798 1798
 
1799
-		if (is_object($question)) {
1800
-			if ($question->is_restored()) {
1801
-				return $question->destination_id;
1802
-			}
1803
-			$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1804
-			$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1799
+        if (is_object($question)) {
1800
+            if ($question->is_restored()) {
1801
+                return $question->destination_id;
1802
+            }
1803
+            $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1804
+            $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1805 1805
             $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
1806 1806
 
1807
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
1807
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
1808 1808
             $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1809 1809
                 $question->description,
1810 1810
                 $this->course->code,
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
                 'extra' => self::DBUTF8($question->extra),
1826 1826
             ];
1827 1827
 
1828
-			$new_id = Database::insert($table_que, $params);
1828
+            $new_id = Database::insert($table_que, $params);
1829 1829
 
1830 1830
             if ($new_id) {
1831 1831
 
@@ -1866,7 +1866,7 @@  discard block
 block discarded – undo
1866 1866
 
1867 1867
                 foreach ($temp as $index => $answer) {
1868 1868
                     //id = '".$index."',
1869
-					$params = [
1869
+                    $params = [
1870 1870
                         'c_id' => $this->destination_course_id,
1871 1871
                         'question_id' => $new_id,
1872 1872
                         'answer' => self::DBUTF8($answer['answer']),
@@ -1885,12 +1885,12 @@  discard block
 block discarded – undo
1885 1885
                         $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId";
1886 1886
                         Database::query($sql);
1887 1887
                     }
1888
-				}
1889
-			} else {
1888
+                }
1889
+            } else {
1890 1890
                 $correct_answers = array();
1891
-				foreach ($question->answers as $index => $answer) {
1891
+                foreach ($question->answers as $index => $answer) {
1892 1892
 
1893
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1893
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1894 1894
                     $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1895 1895
                         $answer['answer'],
1896 1896
                         $this->course->code,
@@ -1929,8 +1929,8 @@  discard block
 block discarded – undo
1929 1929
                     }
1930 1930
 
1931 1931
                     $correct_answers[$answerId] = $answer['correct'];
1932
-				}
1933
-			}
1932
+                }
1933
+            }
1934 1934
 
1935 1935
             //Current course id
1936 1936
             $course_id = api_get_course_int_id();
@@ -2027,12 +2027,12 @@  discard block
 block discarded – undo
2027 2027
                     }
2028 2028
                 }
2029 2029
             }
2030
-			$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2031
-		}
2032
-		return $new_id;
2033
-	}
2030
+            $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2031
+        }
2032
+        return $new_id;
2033
+    }
2034 2034
 
2035
-	/**
2035
+    /**
2036 2036
      * @todo : add session id when used for session
2037 2037
      */
2038 2038
     public function restore_test_category($session_id, $respect_base_content, $destination_course_code)
@@ -2112,21 +2112,21 @@  discard block
 block discarded – undo
2112 2112
         $sessionId = intval($sessionId);
2113 2113
 
2114 2114
         if ($this->course->has_resources(RESOURCE_SURVEY)) {
2115
-			$table_sur = Database :: get_course_table(TABLE_SURVEY);
2116
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2117
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2118
-			$resources = $this->course->resources;
2119
-			foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2115
+            $table_sur = Database :: get_course_table(TABLE_SURVEY);
2116
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2117
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2118
+            $resources = $this->course->resources;
2119
+            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2120 2120
 
2121
-				$sql = 'SELECT survey_id FROM '.$table_sur.'
2121
+                $sql = 'SELECT survey_id FROM '.$table_sur.'
2122 2122
                         WHERE
2123 2123
                             c_id = '.$this->destination_course_id.' AND
2124 2124
                             code = "'.self::DBUTF8escapestring($survey->code).'" AND
2125 2125
                             lang = "'.self::DBUTF8escapestring($survey->lang).'" ';
2126 2126
 
2127
-				$result_check = Database::query($sql);
2127
+                $result_check = Database::query($sql);
2128 2128
 
2129
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2129
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2130 2130
                 $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2131 2131
                     $survey->title,
2132 2132
                     $this->course->code,
@@ -2180,20 +2180,20 @@  discard block
 block discarded – undo
2180 2180
                     'session_id' => $sessionId,
2181 2181
                 ];
2182 2182
 
2183
-				//An existing survey exists with the same code and the same language
2184
-				if (Database::num_rows($result_check) == 1) {
2185
-					switch ($this->file_option) {
2186
-						case FILE_SKIP:
2187
-							//Do nothing
2188
-							break;
2189
-						case FILE_RENAME:
2190
-							$survey_code = $survey->code.'_';
2191
-							$i=1;
2192
-							$temp_survey_code = $survey_code.$i;
2193
-							while (!$this->is_survey_code_available($temp_survey_code)) {
2194
-								$temp_survey_code = $survey_code.++$i;
2195
-							}
2196
-							$survey_code = $temp_survey_code;
2183
+                //An existing survey exists with the same code and the same language
2184
+                if (Database::num_rows($result_check) == 1) {
2185
+                    switch ($this->file_option) {
2186
+                        case FILE_SKIP:
2187
+                            //Do nothing
2188
+                            break;
2189
+                        case FILE_RENAME:
2190
+                            $survey_code = $survey->code.'_';
2191
+                            $i=1;
2192
+                            $temp_survey_code = $survey_code.$i;
2193
+                            while (!$this->is_survey_code_available($temp_survey_code)) {
2194
+                                $temp_survey_code = $survey_code.++$i;
2195
+                            }
2196
+                            $survey_code = $temp_survey_code;
2197 2197
 
2198 2198
                             $params['code'] = $survey_code;
2199 2199
                             $new_id = Database::insert($table_sur, $params);
@@ -2212,25 +2212,25 @@  discard block
 block discarded – undo
2212 2212
                                     Database::query($sql);
2213 2213
                                 }
2214 2214
                             }
2215
-							break;
2216
-						case FILE_OVERWRITE:
2217
-							// Delete the existing survey with the same code and language and import the one of the source course
2218
-							// getting the information of the survey (used for when the survey is shared)
2215
+                            break;
2216
+                        case FILE_OVERWRITE:
2217
+                            // Delete the existing survey with the same code and language and import the one of the source course
2218
+                            // getting the information of the survey (used for when the survey is shared)
2219 2219
 
2220
-							$sql = "SELECT * FROM $table_sur
2220
+                            $sql = "SELECT * FROM $table_sur
2221 2221
 							        WHERE
2222 2222
 							            c_id = ".$this->destination_course_id." AND
2223 2223
 							            survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'";
2224
-							$result = Database::query($sql);
2225
-							$survey_data = Database::fetch_array($result,'ASSOC');
2224
+                            $result = Database::query($sql);
2225
+                            $survey_data = Database::fetch_array($result,'ASSOC');
2226 2226
 
2227
-							// if the survey is shared => also delete the shared content
2228
-							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2227
+                            // if the survey is shared => also delete the shared content
2228
+                            if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2229 2229
                                 SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
2230
-							}
2231
-							SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2230
+                            }
2231
+                            SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2232 2232
 
2233
-							// Insert the new source survey
2233
+                            // Insert the new source survey
2234 2234
                             $new_id = Database::insert($table_sur, $params);
2235 2235
 
2236 2236
                             if ($new_id) {
@@ -2251,11 +2251,11 @@  discard block
 block discarded – undo
2251 2251
                                     Database::query($sql);
2252 2252
                                 }
2253 2253
                             }
2254
-							break;
2255
-						default:
2256
-							break;
2257
-					}
2258
-				} else {
2254
+                            break;
2255
+                        default:
2256
+                            break;
2257
+                    }
2258
+                } else {
2259 2259
                     // No existing survey with the same language and the same code, we just copy the survey
2260 2260
                     $new_id = Database::insert($table_sur, $params);
2261 2261
 
@@ -2277,48 +2277,48 @@  discard block
 block discarded – undo
2277 2277
                             Database::query($sql);
2278 2278
                         }
2279 2279
                     }
2280
-				}
2281
-			}
2282
-		}
2283
-	}
2284
-
2285
-	/**
2286
-	 * Check availability of a survey code
2287
-	 * @param string $survey_code
2288
-	 */
2280
+                }
2281
+            }
2282
+        }
2283
+    }
2284
+
2285
+    /**
2286
+     * Check availability of a survey code
2287
+     * @param string $survey_code
2288
+     */
2289 2289
     public function is_survey_code_available($survey_code)
2290 2290
     {
2291
-		$table_sur = Database :: get_course_table(TABLE_SURVEY);
2292
-		$sql = "SELECT * FROM $table_sur
2291
+        $table_sur = Database :: get_course_table(TABLE_SURVEY);
2292
+        $sql = "SELECT * FROM $table_sur
2293 2293
 		        WHERE
2294 2294
 		            c_id = ".$this->destination_course_id." AND
2295 2295
 		            code='".self::DBUTF8escapestring($survey_code)."'";
2296
-		$result = Database::query($sql);
2296
+        $result = Database::query($sql);
2297 2297
         if (Database::num_rows($result) > 0) {
2298 2298
             return false;
2299 2299
         } else {
2300 2300
             return true;
2301 2301
         }
2302
-	}
2302
+    }
2303 2303
 
2304
-	/**
2305
-	 * Restore survey-questions
2306
-	 * @param string $survey_id
2307
-	 */
2304
+    /**
2305
+     * Restore survey-questions
2306
+     * @param string $survey_id
2307
+     */
2308 2308
     public function restore_survey_question($id, $survey_id)
2309 2309
     {
2310
-		$resources = $this->course->resources;
2311
-		$question = $resources[RESOURCE_SURVEYQUESTION][$id];
2310
+        $resources = $this->course->resources;
2311
+        $question = $resources[RESOURCE_SURVEYQUESTION][$id];
2312 2312
         $new_id = 0;
2313 2313
 
2314
-		if (is_object($question)) {
2315
-			if ($question->is_restored()) {
2316
-				return $question->destination_id;
2317
-			}
2318
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2319
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2314
+        if (is_object($question)) {
2315
+            if ($question->is_restored()) {
2316
+                return $question->destination_id;
2317
+            }
2318
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2319
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2320 2320
 
2321
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
2321
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
2322 2322
             $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2323 2323
                 $question->survey_question,
2324 2324
                 $this->course->code,
@@ -2372,10 +2372,10 @@  discard block
 block discarded – undo
2372 2372
                 }
2373 2373
                 $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id;
2374 2374
             }
2375
-		}
2375
+        }
2376 2376
 
2377
-		return $new_id;
2378
-	}
2377
+        return $new_id;
2378
+    }
2379 2379
 
2380 2380
     /**
2381 2381
      * Restoring learning paths
@@ -2386,19 +2386,19 @@  discard block
 block discarded – undo
2386 2386
     {
2387 2387
         $session_id = intval($session_id);
2388 2388
 
2389
-		if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2389
+        if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2390 2390
             $table_main = Database::get_course_table(TABLE_LP_MAIN);
2391 2391
             $table_item = Database::get_course_table(TABLE_LP_ITEM);
2392 2392
             $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
2393 2393
 
2394
-			$resources = $this->course->resources;
2394
+            $resources = $this->course->resources;
2395 2395
 
2396
-			$origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2397
-			$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2396
+            $origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2397
+            $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2398 2398
 
2399
-			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2400
-				$condition_session = '';
2401
-				if (!empty($session_id)) {
2399
+            foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2400
+                $condition_session = '';
2401
+                if (!empty($session_id)) {
2402 2402
                     if ($respect_base_content) {
2403 2403
                         $my_session_id = $lp->session_id;
2404 2404
                         if (!empty($lp->session_id)) {
@@ -2409,20 +2409,20 @@  discard block
 block discarded – undo
2409 2409
                         $session_id = intval($session_id);
2410 2410
                         $condition_session = $session_id;
2411 2411
                     }
2412
-				}
2413
-
2414
-				// Adding the author's image
2415
-				if (!empty($lp->preview_image)) {
2416
-					$new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2417
-					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2418
-						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2419
-						if ($copy_result) {
2420
-							$lp->preview_image = $new_filename;
2421
-						} else {
2422
-							$lp->preview_image ='';
2423
-						}
2424
-					}
2425
-				}
2412
+                }
2413
+
2414
+                // Adding the author's image
2415
+                if (!empty($lp->preview_image)) {
2416
+                    $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2417
+                    if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2418
+                        $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2419
+                        if ($copy_result) {
2420
+                            $lp->preview_image = $new_filename;
2421
+                        } else {
2422
+                            $lp->preview_image ='';
2423
+                        }
2424
+                    }
2425
+                }
2426 2426
 
2427 2427
                 if ($this->add_text_in_items) {
2428 2428
                     $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix');
@@ -2480,7 +2480,7 @@  discard block
 block discarded – undo
2480 2480
                     $params['session_id'] = $condition_session;
2481 2481
                 }
2482 2482
 
2483
-				$new_lp_id = Database::insert($table_main, $params);
2483
+                $new_lp_id = Database::insert($table_main, $params);
2484 2484
 
2485 2485
                 if ($new_lp_id) {
2486 2486
 
@@ -2541,13 +2541,13 @@  discard block
 block discarded – undo
2541 2541
                 $old_refs = array();
2542 2542
                 $prerequisite_ids = array();
2543 2543
 
2544
-				foreach ($lp->get_items() as $index => $item) {
2545
-					// we set the ref code here and then we update in a for loop
2546
-					$ref = $item['ref'];
2544
+                foreach ($lp->get_items() as $index => $item) {
2545
+                    // we set the ref code here and then we update in a for loop
2546
+                    $ref = $item['ref'];
2547 2547
 
2548
-					// Dealing with path the same way as ref as some data has
2548
+                    // Dealing with path the same way as ref as some data has
2549 2549
                     // been put into path when it's a local resource
2550
-					// Only fix the path for no scos
2550
+                    // Only fix the path for no scos
2551 2551
                     if ($item['item_type'] == 'sco') {
2552 2552
                         $path = $item['path'];
2553 2553
                     } else {
@@ -2576,128 +2576,128 @@  discard block
 block discarded – undo
2576 2576
                         'launch_data' => self::DBUTF8($item['launch_data']),
2577 2577
                     ];
2578 2578
 
2579
-					$new_item_id = Database::insert($table_item, $params);
2579
+                    $new_item_id = Database::insert($table_item, $params);
2580 2580
 
2581 2581
                     $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
2582 2582
                     Database::query($sql);
2583 2583
 
2584
-					//save a link between old and new item IDs
2585
-					$new_item_ids[$item['id']] = $new_item_id;
2586
-					//save a reference of items that need a parent_item_id refresh
2587
-					$parent_item_ids[$new_item_id] = $item['parent_item_id'];
2588
-					//save a reference of items that need a previous_item_id refresh
2589
-					$previous_item_ids[$new_item_id] = $item['previous_item_id'];
2590
-					//save a reference of items that need a next_item_id refresh
2591
-					$next_item_ids[$new_item_id] = $item['next_item_id'];
2592
-
2593
-					if (!empty($item['prerequisite'])) {
2594
-						if ($lp->lp_type =='2') {
2595
-							// if is an sco
2596
-							$old_prerequisite[$new_item_id]= $item['prerequisite'];
2597
-						} else {
2598
-							$old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2599
-						}
2600
-					}
2601
-
2602
-					if (!empty($ref)) {
2603
-						if ($lp->lp_type =='2') {
2604
-							// if is an sco
2605
-							$old_refs[$new_item_id]= $ref;
2606
-						} else {
2584
+                    //save a link between old and new item IDs
2585
+                    $new_item_ids[$item['id']] = $new_item_id;
2586
+                    //save a reference of items that need a parent_item_id refresh
2587
+                    $parent_item_ids[$new_item_id] = $item['parent_item_id'];
2588
+                    //save a reference of items that need a previous_item_id refresh
2589
+                    $previous_item_ids[$new_item_id] = $item['previous_item_id'];
2590
+                    //save a reference of items that need a next_item_id refresh
2591
+                    $next_item_ids[$new_item_id] = $item['next_item_id'];
2592
+
2593
+                    if (!empty($item['prerequisite'])) {
2594
+                        if ($lp->lp_type =='2') {
2595
+                            // if is an sco
2596
+                            $old_prerequisite[$new_item_id]= $item['prerequisite'];
2597
+                        } else {
2598
+                            $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2599
+                        }
2600
+                    }
2601
+
2602
+                    if (!empty($ref)) {
2603
+                        if ($lp->lp_type =='2') {
2604
+                            // if is an sco
2605
+                            $old_refs[$new_item_id]= $ref;
2606
+                        } else {
2607 2607
                             $old_refs[$new_item_id]= $new_item_ids[$ref];
2608
-						}
2609
-					}
2608
+                        }
2609
+                    }
2610 2610
 
2611
-					$prerequisite_ids[$new_item_id] = $item['prerequisite'];
2612
-				}
2611
+                    $prerequisite_ids[$new_item_id] = $item['prerequisite'];
2612
+                }
2613 2613
 
2614
-				// Updating prerequisites
2615
-				foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2616
-					if ($my_old_prerequisite != ''){
2617
-						$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2614
+                // Updating prerequisites
2615
+                foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2616
+                    if ($my_old_prerequisite != ''){
2617
+                        $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2618 2618
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2619
-						Database::query($sql);
2620
-					}
2621
-				}
2622
-
2623
-				// Updating refs
2624
-				foreach ($old_refs  as $key=>$my_old_ref) {
2625
-					if ($my_old_ref != '') {
2626
-						$sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2619
+                        Database::query($sql);
2620
+                    }
2621
+                }
2622
+
2623
+                // Updating refs
2624
+                foreach ($old_refs  as $key=>$my_old_ref) {
2625
+                    if ($my_old_ref != '') {
2626
+                        $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2627 2627
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2628
-						Database::query($sql);
2629
-					}
2630
-				}
2631
-
2632
-				foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2633
-					$parent_new_id = 0;
2634
-					if($parent_item_old_id != 0){
2635
-						$parent_new_id = $new_item_ids[$parent_item_old_id];
2636
-					}
2637
-					$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2628
+                        Database::query($sql);
2629
+                    }
2630
+                }
2631
+
2632
+                foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2633
+                    $parent_new_id = 0;
2634
+                    if($parent_item_old_id != 0){
2635
+                        $parent_new_id = $new_item_ids[$parent_item_old_id];
2636
+                    }
2637
+                    $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2638 2638
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2639
-					Database::query($sql);
2640
-				}
2641
-				foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2642
-					$previous_new_id = 0;
2643
-					if ($previous_item_old_id != 0){
2644
-						$previous_new_id = $new_item_ids[$previous_item_old_id];
2645
-					}
2646
-					$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2639
+                    Database::query($sql);
2640
+                }
2641
+                foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2642
+                    $previous_new_id = 0;
2643
+                    if ($previous_item_old_id != 0){
2644
+                        $previous_new_id = $new_item_ids[$previous_item_old_id];
2645
+                    }
2646
+                    $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2647 2647
 					        WHERE  c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2648
-					Database::query($sql);
2649
-				}
2650
-
2651
-				foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2652
-					$next_new_id = 0;
2653
-					if ($next_item_old_id != 0){
2654
-						$next_new_id = $new_item_ids[$next_item_old_id];
2655
-					}
2656
-					$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2648
+                    Database::query($sql);
2649
+                }
2650
+
2651
+                foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2652
+                    $next_new_id = 0;
2653
+                    if ($next_item_old_id != 0){
2654
+                        $next_new_id = $new_item_ids[$next_item_old_id];
2655
+                    }
2656
+                    $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2657 2657
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2658
-					Database::query($sql);
2659
-				}
2660
-
2661
-				foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2662
-					$prerequisite_new_id = 0;
2663
-					if ($prerequisite_old_id != 0){
2664
-						$prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2665
-					}
2666
-					$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2658
+                    Database::query($sql);
2659
+                }
2660
+
2661
+                foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2662
+                    $prerequisite_new_id = 0;
2663
+                    if ($prerequisite_old_id != 0){
2664
+                        $prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2665
+                    }
2666
+                    $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2667 2667
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2668
-					Database::query($sql);
2669
-				}
2670
-				$this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2671
-			}
2672
-		}
2673
-	}
2674
-
2675
-	/**
2676
-	 * Restore works
2668
+                    Database::query($sql);
2669
+                }
2670
+                $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2671
+            }
2672
+        }
2673
+    }
2674
+
2675
+    /**
2676
+     * Restore works
2677 2677
      * @deprecated use restore_works
2678 2678
      *
2679
-	 */
2680
-	public function restore_student_publication($sessionId = 0)
2679
+     */
2680
+    public function restore_student_publication($sessionId = 0)
2681 2681
     {
2682 2682
         $sessionId = intval($sessionId);
2683 2683
         $work_assignment_table = Database:: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2684 2684
         $work_table = Database:: get_course_table(TABLE_STUDENT_PUBLICATION);
2685 2685
         $item_property_table = Database:: get_course_table(TABLE_ITEM_PROPERTY);
2686 2686
 
2687
-		// Query in student publication
2688
-		$sql = 'SELECT * FROM '.$work_table.'
2687
+        // Query in student publication
2688
+        $sql = 'SELECT * FROM '.$work_table.'
2689 2689
 		        WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) ';
2690 2690
 
2691
-		$result = Database::query($sql);
2692
-		$folders = Database::store_result($result, 'ASSOC');
2691
+        $result = Database::query($sql);
2692
+        $folders = Database::store_result($result, 'ASSOC');
2693 2693
 
2694
-		foreach ($folders  as $folder) {
2695
-		    $old_id = $folder['id'];
2694
+        foreach ($folders  as $folder) {
2695
+            $old_id = $folder['id'];
2696 2696
             unset($folder['id']);
2697
-			$folder['c_id'] = $this->destination_course_id;
2697
+            $folder['c_id'] = $this->destination_course_id;
2698 2698
             $folder['parent_id'] = 0;
2699 2699
             $folder['session_id'] = $sessionId;
2700
-			$new_id = Database::insert($work_table, $folder);
2700
+            $new_id = Database::insert($work_table, $folder);
2701 2701
 
2702 2702
             if ($new_id) {
2703 2703
                 // query in item property
@@ -2756,23 +2756,23 @@  discard block
 block discarded – undo
2756 2756
                     }
2757 2757
                 }
2758 2758
             }
2759
-		}
2759
+        }
2760 2760
 
2761 2761
         $destination = '../..'.api_get_path(REL_COURSE_PATH).$this->course->destination_path.'/work/';
2762 2762
         $origin = '../..'.api_get_path(REL_COURSE_PATH).$this->course->info['path'].'/work/';
2763 2763
         self::allow_create_all_directory($origin, $destination, false);
2764
-	}
2764
+    }
2765 2765
 
2766 2766
     /**
2767
-    * copy all directory and sub directory
2768
-    * @param string The path origin
2769
-    * @param string The path destination
2770
-    * @param boolean Option Overwrite
2771
-    * @param string $source
2772
-    * @param string $dest
2773
-    * @return void()
2774
-    * @deprecated
2775
-    */
2767
+     * copy all directory and sub directory
2768
+     * @param string The path origin
2769
+     * @param string The path destination
2770
+     * @param boolean Option Overwrite
2771
+     * @param string $source
2772
+     * @param string $dest
2773
+     * @return void()
2774
+     * @deprecated
2775
+     */
2776 2776
     public function allow_create_all_directory($source, $dest, $overwrite = false)
2777 2777
     {
2778 2778
         if (!is_dir($dest)) {
@@ -2783,7 +2783,7 @@  discard block
 block discarded – undo
2783 2783
                 if ($file != '.' && $file != '..') {
2784 2784
                     $path = $source . '/' . $file;
2785 2785
                     if (is_file($path)) {
2786
-                       /* if (!is_file($dest . '/' . $file) || $overwrite)
2786
+                        /* if (!is_file($dest . '/' . $file) || $overwrite)
2787 2787
                         if (!@copy($path, $dest . '/' . $file)) {
2788 2788
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2789 2789
                         }*/
@@ -2798,12 +2798,12 @@  discard block
 block discarded – undo
2798 2798
         }
2799 2799
     }
2800 2800
 
2801
-	/**
2802
-	 * Gets the new ID of one specific tool item from the tool name and the old ID
2803
-	 * @param	string	Tool name
2804
-	 * @param	integer	Old ID
2805
-	 * @return	integer	New ID
2806
-	 */
2801
+    /**
2802
+     * Gets the new ID of one specific tool item from the tool name and the old ID
2803
+     * @param	string	Tool name
2804
+     * @param	integer	Old ID
2805
+     * @return	integer	New ID
2806
+     */
2807 2807
     public function get_new_id($tool, $ref)
2808 2808
     {
2809 2809
         // Check if the value exist in the current array.
@@ -2825,25 +2825,25 @@  discard block
 block discarded – undo
2825 2825
         }
2826 2826
 
2827 2827
         return '';
2828
-	}
2828
+    }
2829 2829
 
2830
-	/**
2831
-	 * Restore glossary
2832
-	 */
2830
+    /**
2831
+     * Restore glossary
2832
+     */
2833 2833
     public function restore_glossary($session_id = 0)
2834 2834
     {
2835
-		if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2836
-			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2837
-			$resources = $this->course->resources;
2838
-			foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2835
+        if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2836
+            $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2837
+            $resources = $this->course->resources;
2838
+            foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2839 2839
 
2840 2840
                 $params = [];
2841
-    			if (!empty($session_id)) {
2842
-    				$session_id = intval($session_id);
2841
+                if (!empty($session_id)) {
2842
+                    $session_id = intval($session_id);
2843 2843
                     $params['session_id'] = $session_id;
2844
-    			}
2844
+                }
2845 2845
 
2846
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2846
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2847 2847
                 $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2848 2848
                     $glossary->description,
2849 2849
                     $this->course->code,
@@ -2877,27 +2877,27 @@  discard block
 block discarded – undo
2877 2877
 
2878 2878
                     $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id;
2879 2879
                 }
2880
-			}
2881
-		}
2882
-	}
2880
+            }
2881
+        }
2882
+    }
2883 2883
 
2884 2884
     /**
2885 2885
      * @param int $session_id
2886 2886
      */
2887 2887
     public function restore_wiki($session_id = 0)
2888 2888
     {
2889
-		if ($this->course->has_resources(RESOURCE_WIKI)) {
2890
-			// wiki table of the target course
2891
-			$table_wiki = Database :: get_course_table(TABLE_WIKI);
2892
-			$table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2889
+        if ($this->course->has_resources(RESOURCE_WIKI)) {
2890
+            // wiki table of the target course
2891
+            $table_wiki = Database :: get_course_table(TABLE_WIKI);
2892
+            $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2893 2893
 
2894
-			// storing all the resources that have to be copied in an array
2895
-			$resources = $this->course->resources;
2894
+            // storing all the resources that have to be copied in an array
2895
+            $resources = $this->course->resources;
2896 2896
 
2897
-			foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2898
-				// the sql statement to insert the groups from the old course to the new course
2897
+            foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2898
+                // the sql statement to insert the groups from the old course to the new course
2899 2899
 
2900
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2900
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2901 2901
                 $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2902 2902
                     $wiki->content,
2903 2903
                     $this->course->code,
@@ -2932,7 +2932,7 @@  discard block
 block discarded – undo
2932 2932
                     'user_ip' => ''
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
                     $sql = "UPDATE $table_wiki SET page_id = '$new_id', id = iid
@@ -2962,9 +2962,9 @@  discard block
 block discarded – undo
2962 2962
 
2963 2963
                     Database::insert($table_wiki_conf, $params);
2964 2964
                 }
2965
-			}
2966
-		}
2967
-	}
2965
+            }
2966
+        }
2967
+    }
2968 2968
 
2969 2969
     /**
2970 2970
      * Restore Thematics
@@ -2972,15 +2972,15 @@  discard block
 block discarded – undo
2972 2972
      */
2973 2973
     public function restore_thematic($session_id = 0)
2974 2974
     {
2975
-		if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2975
+        if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2976 2976
             $table_thematic = Database::get_course_table(TABLE_THEMATIC);
2977 2977
             $table_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
2978 2978
             $table_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
2979 2979
 
2980
-			$resources = $this->course->resources;
2981
-			foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2980
+            $resources = $this->course->resources;
2981
+            foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2982 2982
 
2983
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2983
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2984 2984
                 $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2985 2985
                     $thematic->params['content'],
2986 2986
                     $this->course->code,
@@ -2988,13 +2988,13 @@  discard block
 block discarded – undo
2988 2988
                     $this->course->backup_path,
2989 2989
                     $this->course->info['path']
2990 2990
                 );
2991
-				$thematic->params['c_id']  = $this->destination_course_id;
2992
-				unset($thematic->params['id']);
2991
+                $thematic->params['c_id']  = $this->destination_course_id;
2992
+                unset($thematic->params['id']);
2993 2993
                 unset($thematic->params['iid']);
2994 2994
 
2995
-				$last_id = Database::insert($table_thematic, $thematic->params, false);
2995
+                $last_id = Database::insert($table_thematic, $thematic->params, false);
2996 2996
 
2997
-				if ($last_id) {
2997
+                if ($last_id) {
2998 2998
 
2999 2999
                     $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id";
3000 3000
                     Database::query($sql);
@@ -3007,12 +3007,12 @@  discard block
 block discarded – undo
3007 3007
                         api_get_user_id()
3008 3008
                     );
3009 3009
 
3010
-					foreach ($thematic->thematic_advance_list as $thematic_advance) {
3011
-						unset($thematic_advance['id']);
3010
+                    foreach ($thematic->thematic_advance_list as $thematic_advance) {
3011
+                        unset($thematic_advance['id']);
3012 3012
                         unset($thematic_advance['iid']);
3013
-						$thematic_advance['attendance_id'] = 0;
3014
-						$thematic_advance['thematic_id'] = $last_id;
3015
-						$thematic_advance['c_id']  = $this->destination_course_id;
3013
+                        $thematic_advance['attendance_id'] = 0;
3014
+                        $thematic_advance['thematic_id'] = $last_id;
3015
+                        $thematic_advance['c_id']  = $this->destination_course_id;
3016 3016
 
3017 3017
                         $my_id = Database::insert(
3018 3018
                             $table_thematic_advance,
@@ -3020,7 +3020,7 @@  discard block
 block discarded – undo
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
@@ -3261,11 +3261,11 @@  discard block
 block discarded – undo
3261 3261
      */
3262 3262
     public function DBUTF8($str)
3263 3263
     {
3264
-		if (UTF8_CONVERT) {
3264
+        if (UTF8_CONVERT) {
3265 3265
             $str = utf8_encode($str);
3266 3266
         }
3267
-		return $str;
3268
-	}
3267
+        return $str;
3268
+    }
3269 3269
 
3270 3270
     /**
3271 3271
      * @param string $str
@@ -3276,8 +3276,8 @@  discard block
 block discarded – undo
3276 3276
         if (UTF8_CONVERT) {
3277 3277
             $str = utf8_encode($str);
3278 3278
         }
3279
-		return Database::escape_string($str);
3280
-	}
3279
+        return Database::escape_string($str);
3280
+    }
3281 3281
 
3282 3282
     /**
3283 3283
      * @param array $array
Please login to merge, or discard this patch.
src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class CourseSelectForm
19 19
 {
20
-	/**
21
-	 * Display the form
20
+    /**
21
+     * Display the form
22 22
      * @param array $course
23
-	 * @param array $hidden_fields Hidden fields to add to the form.
24
-	 * @param boolean $avoid_serialize the document array will be serialize. This is used in the course_copy.php file
25
-	 */
26
-	public static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
23
+     * @param array $hidden_fields Hidden fields to add to the form.
24
+     * @param boolean $avoid_serialize the document array will be serialize. This is used in the course_copy.php file
25
+     */
26
+    public static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
27 27
     {
28 28
         global $charset;
29 29
         $resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
@@ -138,47 +138,47 @@  discard block
 block discarded – undo
138 138
             }
139 139
 		</script>
140 140
 		<?php
141
-		// get destination course title
142
-		if (!empty($hidden_fields['destination_course'])) {
141
+        // get destination course title
142
+        if (!empty($hidden_fields['destination_course'])) {
143 143
             $sessionTitle = !empty($hidden_fields['destination_session']) ? ' (' . api_get_session_name($hidden_fields['destination_session']) . ')' : null;
144 144
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
145
-			echo '<h3>';
146
-			echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
147
-			echo '</h3>';
148
-		}
145
+            echo '<h3>';
146
+            echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
147
+            echo '</h3>';
148
+        }
149 149
         echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
150
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
150
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
151 151
         $icon = Display::returnIconPath('myprogress_bar.gif');
152
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
153
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
152
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
153
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
154 154
 
155
-		if (!empty($hidden_fields['destination_course']) &&
155
+        if (!empty($hidden_fields['destination_course']) &&
156 156
             !empty($hidden_fields['origin_course']) &&
157 157
             !empty($hidden_fields['destination_session']) &&
158 158
             !empty($hidden_fields['origin_session'])
159 159
         ) {
160
-			echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
161
-			echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
162
-			echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
163
-			echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
164
-		}
160
+            echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
161
+            echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
162
+            echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
163
+            echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
164
+        }
165 165
 
166
-		$element_count = 0;
166
+        $element_count = 0;
167 167
         $forum_categories = array();
168 168
         $forums = array();
169 169
         $forum_topics = array();
170 170
 
171 171
         echo '<p>';
172
-		echo get_lang('SelectResources');
173
-		echo '</p>';
172
+        echo get_lang('SelectResources');
173
+        echo '</p>';
174 174
 
175 175
         Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
176 176
 
177 177
         foreach ($course->resources as $type => $resources) {
178 178
             if (count($resources) > 0) {
179
-				switch ($type) {
180
-					//Resources to avoid
181
-					case RESOURCE_FORUMCATEGORY:
179
+                switch ($type) {
180
+                    //Resources to avoid
181
+                    case RESOURCE_FORUMCATEGORY:
182 182
                         foreach ($resources as $id => $resource) {
183 183
                             $forum_categories[$id] = $resource;
184 184
                         }
@@ -204,30 +204,30 @@  discard block
 block discarded – undo
204 204
                     case RESOURCE_SCORM:
205 205
                         break;
206 206
                     default:
207
-						echo '<span id="img_'.$type.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$type'".');" >&nbsp;</span>&nbsp;';
208
-						echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
209
-						echo '<div id="div_'.$type.'">';
210
-						if ($type == RESOURCE_LEARNPATH) {
211
-    						Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
212
-    						Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
213
-						}
214
-						if ($type == RESOURCE_DOCUMENT) {
207
+                        echo '<span id="img_'.$type.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$type'".');" >&nbsp;</span>&nbsp;';
208
+                        echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
209
+                        echo '<div id="div_'.$type.'">';
210
+                        if ($type == RESOURCE_LEARNPATH) {
211
+                            Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
212
+                            Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
213
+                        }
214
+                        if ($type == RESOURCE_DOCUMENT) {
215 215
                             if (api_get_setting('show_glossary_in_documents') != 'none') {
216 216
                                 Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
217 217
                             }
218
-						}
218
+                        }
219 219
 
220
-						echo '<div class="well">';
220
+                        echo '<div class="well">';
221 221
 
222 222
                         echo '<div class="btn-group">';
223
-						echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
223
+                        echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
224 224
                         echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
225
-						echo '</div><br />';
225
+                        echo '</div><br />';
226 226
                         echo '<ul class="list-unstyled">';
227
-						foreach ($resources as $id => $resource) {
227
+                        foreach ($resources as $id => $resource) {
228 228
                             if ($resource) {
229 229
                                 echo '<li>';
230
-								// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
230
+                                // Event obj in 1.9.x in 1.10.x the class is CalendarEvent
231 231
                                 Resource::setClassType($resource);
232 232
                                 echo '<label class="checkbox">';
233 233
                                 echo '<input type="checkbox" name="resource['.$type.']['.$id.']"  id="resource['.$type.']['.$id.']" />';
@@ -235,15 +235,15 @@  discard block
 block discarded – undo
235 235
                                 echo '</label>';
236 236
                                 echo '</li>';
237 237
                             }
238
-						}
238
+                        }
239 239
                         echo '</ul>';
240
-						echo '</div>';
241
-						echo '</div>';
242
-						echo '<script language="javascript">exp('."'$type'".')</script>';
243
-						$element_count++;
240
+                        echo '</div>';
241
+                        echo '</div>';
242
+                        echo '<script language="javascript">exp('."'$type'".')</script>';
243
+                        $element_count++;
244 244
                 }
245
-			}
246
-		}
245
+            }
246
+        }
247 247
 
248 248
         //Fixes forum order
249 249
         if (!empty($forum_categories)) {
@@ -298,65 +298,65 @@  discard block
 block discarded – undo
298 298
             echo '<script language="javascript">exp('."'$type'".')</script>';
299 299
         }
300 300
 
301
-		if ($avoid_serialize) {
302
-			/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
301
+        if ($avoid_serialize) {
302
+            /*Documents are avoided due the huge amount of memory that the serialize php function "eats"
303 303
 			(when there are directories with hundred/thousand of files) */
304
-			// this is a known issue of serialize
305
-			$course->resources['document']= null;
306
-		}
304
+            // this is a known issue of serialize
305
+            $course->resources['document']= null;
306
+        }
307 307
 
308
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
308
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
309 309
 
310
-		if (is_array($hidden_fields)) {
311
-			foreach ($hidden_fields as $key => $value) {
312
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
313
-			}
314
-		}
310
+        if (is_array($hidden_fields)) {
311
+            foreach ($hidden_fields as $key => $value) {
312
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
313
+            }
314
+        }
315 315
 
316 316
         $recycleOption = isset($_POST['recycle_option']) ? true : false;
317 317
 
318
-		if (empty($element_count)) {
319
-		    Display::display_warning_message(get_lang('NoDataAvailable'));
320
-		} else {
321
-    		if (!empty($hidden_fields['destination_session'])) {
322
-    			echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
318
+        if (empty($element_count)) {
319
+            Display::display_warning_message(get_lang('NoDataAvailable'));
320
+        } else {
321
+            if (!empty($hidden_fields['destination_session'])) {
322
+                echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
323 323
                     get_lang('Ok').'</button>';
324
-    		} else {
324
+            } else {
325 325
                 if ($recycleOption) {
326 326
                     echo '<br /><button class="save" type="submit">'.
327 327
                         get_lang('Ok').'</button>';
328 328
                 } else {
329
-    			    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
329
+                    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
330 330
                     get_lang('Ok').'</button>';
331 331
                 }
332
-    		}
333
-		}
332
+            }
333
+        }
334 334
 
335
-		CourseSelectForm::display_hidden_quiz_questions($course);
336
-		CourseSelectForm::display_hidden_scorm_directories($course);
337
-		echo '</form>';
338
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
339
-	}
335
+        CourseSelectForm::display_hidden_quiz_questions($course);
336
+        CourseSelectForm::display_hidden_scorm_directories($course);
337
+        echo '</form>';
338
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
339
+    }
340 340
 
341 341
     /**
342 342
      * @param $course
343 343
      */
344 344
     public static function display_hidden_quiz_questions($course)
345 345
     {
346
-		if(is_array($course->resources)){
347
-			foreach ($course->resources as $type => $resources) {
348
-				if (count($resources) > 0) {
349
-					switch ($type) {
350
-						case RESOURCE_QUIZQUESTION:
351
-							foreach ($resources as $id => $resource) {
352
-								echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
353
-							}
354
-							break;
355
-					}
356
-				}
357
-			}
358
-		}
359
-	}
346
+        if(is_array($course->resources)){
347
+            foreach ($course->resources as $type => $resources) {
348
+                if (count($resources) > 0) {
349
+                    switch ($type) {
350
+                        case RESOURCE_QUIZQUESTION:
351
+                            foreach ($resources as $id => $resource) {
352
+                                echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
353
+                            }
354
+                            break;
355
+                    }
356
+                }
357
+            }
358
+        }
359
+    }
360 360
 
361 361
     /**
362 362
      * @param $course
@@ -364,30 +364,30 @@  discard block
 block discarded – undo
364 364
     public static function display_hidden_scorm_directories($course)
365 365
     {
366 366
         if (is_array($course->resources)){
367
-			foreach ($course->resources as $type => $resources) {
368
-				if (count($resources) > 0) {
369
-					switch($type) {
370
-						case RESOURCE_SCORM:
371
-							foreach ($resources as $id => $resource) {
372
-								echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
373
-							}
374
-							break;
375
-					}
376
-				}
377
-			}
378
-		}
379
-	}
367
+            foreach ($course->resources as $type => $resources) {
368
+                if (count($resources) > 0) {
369
+                    switch($type) {
370
+                        case RESOURCE_SCORM:
371
+                            foreach ($resources as $id => $resource) {
372
+                                echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
373
+                            }
374
+                            break;
375
+                    }
376
+                }
377
+            }
378
+        }
379
+    }
380 380
 
381
-	/**
382
-	 * Get the posted course
383
-	 * @param string $from who calls the function?
381
+    /**
382
+     * Get the posted course
383
+     * @param string $from who calls the function?
384 384
      * It can be copy_course, create_backup, import_backup or recycle_course
385 385
      * @param int $session_id
386 386
      * @param string $course_code
387
-	 * @return course The course-object with all resources selected by the user
388
-	 * in the form given by display_form(...)
389
-	 */
390
-	public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
387
+     * @return course The course-object with all resources selected by the user
388
+     * in the form given by display_form(...)
389
+     */
390
+    public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
391 391
     {
392 392
         $course = null;
393 393
 
@@ -397,30 +397,30 @@  discard block
 block discarded – undo
397 397
             return false;
398 398
         }
399 399
 
400
-		// Create the resource DOCUMENT objects
401
-		// Loading the results from the checkboxes of ethe javascript
402
-		$resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
400
+        // Create the resource DOCUMENT objects
401
+        // Loading the results from the checkboxes of ethe javascript
402
+        $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
403 403
 
404
-		$course_info = api_get_course_info($course_code);
405
-		$table_doc = Database::get_course_table(TABLE_DOCUMENT);
406
-		$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
407
-		$course_id = $course_info['real_id'];
404
+        $course_info = api_get_course_info($course_code);
405
+        $table_doc = Database::get_course_table(TABLE_DOCUMENT);
406
+        $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
407
+        $course_id = $course_info['real_id'];
408 408
 
409
-		/* Searching the documents resource that have been set to null because
409
+        /* Searching the documents resource that have been set to null because
410 410
         $avoid_serialize is true in the display_form() function*/
411
-		if ($from === 'copy_course') {
412
-			if (is_array($resource)) {
413
-				$resource = array_keys($resource);
411
+        if ($from === 'copy_course') {
412
+            if (is_array($resource)) {
413
+                $resource = array_keys($resource);
414 414
 
415
-				foreach	($resource as $resource_item) {
415
+                foreach	($resource as $resource_item) {
416 416
 
417
-					$condition_session = '';
418
-					if (!empty($session_id)) {
419
-						$session_id = intval($session_id);
420
-						$condition_session = ' AND d.session_id ='.$session_id;
421
-					}
417
+                    $condition_session = '';
418
+                    if (!empty($session_id)) {
419
+                        $session_id = intval($session_id);
420
+                        $condition_session = ' AND d.session_id ='.$session_id;
421
+                    }
422 422
 
423
-					$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
423
+                    $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
424 424
 							FROM '.$table_doc.' d, '.$table_prop.' p
425 425
 							WHERE
426 426
 							    d.c_id = '.$course_id.' AND
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
                                 p.ref = d.id AND p.visibility != 2 AND
430 430
                                 d.id = '.$resource_item.$condition_session.'
431 431
 							ORDER BY path';
432
-					$db_result = Database::query($sql);
433
-					while ($obj = Database::fetch_object($db_result)) {
432
+                    $db_result = Database::query($sql);
433
+                    while ($obj = Database::fetch_object($db_result)) {
434 434
                         $doc = new Document(
435 435
                             $obj->id,
436 436
                             $obj->path,
@@ -454,25 +454,25 @@  discard block
 block discarded – undo
454 454
                             }
455 455
                             $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
456 456
                         }
457
-					}
458
-				}
459
-			}
460
-		}
457
+                    }
458
+                }
459
+            }
460
+        }
461 461
 
462
-		if (is_array($course->resources)) {
463
-			foreach ($course->resources as $type => $resources) {
462
+        if (is_array($course->resources)) {
463
+            foreach ($course->resources as $type => $resources) {
464 464
 
465
-				switch ($type) {
466
-					case RESOURCE_SURVEYQUESTION:
467
-						foreach($resources as $id => $obj) {
468
-						    if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
465
+                switch ($type) {
466
+                    case RESOURCE_SURVEYQUESTION:
467
+                        foreach($resources as $id => $obj) {
468
+                            if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
469 469
                                 is_array($_POST['resource'][RESOURCE_SURVEY]) &&
470 470
                                 !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))
471 471
                             ) {
472
-								unset($course->resources[$type][$id]);
473
-							}
474
-						}
475
-						break;
472
+                                unset($course->resources[$type][$id]);
473
+                            }
474
+                        }
475
+                        break;
476 476
                     case RESOURCE_FORUMTOPIC:
477 477
                     case RESOURCE_FORUMPOST:
478 478
                        //Add post from topic
@@ -524,63 +524,63 @@  discard block
 block discarded – undo
524 524
                                 }
525 525
                             }
526 526
                         }
527
-					case RESOURCE_LINKCATEGORY:
528
-					case RESOURCE_FORUMCATEGORY:
529
-					case RESOURCE_QUIZQUESTION:
530
-					case RESOURCE_DOCUMENT:
531
-						// Mark folders to import which are not selected by the user to import,
532
-						// but in which a document was selected.
533
-						$documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
534
-						if (!empty($resources) && is_array($resources))
535
-							foreach ($resources as $id => $obj) {
536
-								if (isset($obj->file_type) && $obj->file_type == 'folder' &&
527
+                    case RESOURCE_LINKCATEGORY:
528
+                    case RESOURCE_FORUMCATEGORY:
529
+                    case RESOURCE_QUIZQUESTION:
530
+                    case RESOURCE_DOCUMENT:
531
+                        // Mark folders to import which are not selected by the user to import,
532
+                        // but in which a document was selected.
533
+                        $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
534
+                        if (!empty($resources) && is_array($resources))
535
+                            foreach ($resources as $id => $obj) {
536
+                                if (isset($obj->file_type) && $obj->file_type == 'folder' &&
537 537
                                     !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) &&
538 538
                                     is_array($documents)
539 539
                                 ) {
540
-									foreach ($documents as $id_to_check => $post_value) {
541
-										$obj_to_check = $resources[$id_to_check];
542
-										$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
543
-										if ($id_to_check != $id && $obj->path == $shared_path_part) {
544
-											$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
545
-											break;
546
-										}
547
-									}
548
-								}
549
-							}
550
-					default :
551
-						if (!empty($resources) && is_array($resources)) {
552
-							foreach ($resources as $id => $obj) {
553
-								$resource_is_used_elsewhere = $course->is_linked_resource($obj);
554
-								// check if document is in a quiz (audio/video)
555
-								if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
556
-									foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
540
+                                    foreach ($documents as $id_to_check => $post_value) {
541
+                                        $obj_to_check = $resources[$id_to_check];
542
+                                        $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
543
+                                        if ($id_to_check != $id && $obj->path == $shared_path_part) {
544
+                                            $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
545
+                                            break;
546
+                                        }
547
+                                    }
548
+                                }
549
+                            }
550
+                    default :
551
+                        if (!empty($resources) && is_array($resources)) {
552
+                            foreach ($resources as $id => $obj) {
553
+                                $resource_is_used_elsewhere = $course->is_linked_resource($obj);
554
+                                // check if document is in a quiz (audio/video)
555
+                                if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
556
+                                    foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
557 557
                                         $quiz = $quiz->obj;
558
-										if (isset($quiz->media) && $quiz->media == $id) {
559
-											$resource_is_used_elsewhere = true;
560
-										}
561
-									}
562
-								}
563
-								if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
564
-									unset($course->resources[$type][$id]);
565
-								}
566
-							}
567
-						}
568
-				}
569
-			}
570
-		}
558
+                                        if (isset($quiz->media) && $quiz->media == $id) {
559
+                                            $resource_is_used_elsewhere = true;
560
+                                        }
561
+                                    }
562
+                                }
563
+                                if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
564
+                                    unset($course->resources[$type][$id]);
565
+                                }
566
+                            }
567
+                        }
568
+                }
569
+            }
570
+        }
571 571
 
572
-		return $course;
573
-	}
572
+        return $course;
573
+    }
574 574
 
575
-	/**
576
-	 * Display the form session export
575
+    /**
576
+     * Display the form session export
577 577
      * @param array $list_course
578
-	 * @param array $hidden_fields Hidden fields to add to the form.
578
+     * @param array $hidden_fields Hidden fields to add to the form.
579 579
      * @param boolean $avoid_serialize the document array will be serialize. This is used in the course_copy.php file
580
-	 */
581
-	 public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
582
-     {
583
-         ?>
580
+     */
581
+        public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
582
+        {
583
+            ?>
584 584
 		<script>
585 585
 			function exp(item) {
586 586
 				el = document.getElementById('div_'+item);
@@ -622,65 +622,65 @@  discard block
 block discarded – undo
622 622
 		</script>
623 623
 		<?php
624 624
 
625
-		//get destination course title
626
-		if(!empty($hidden_fields['destination_course'])) {
627
-             if (!empty($hidden_fields['destination_session'])) {
628
-                 $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
629
-             } else {
630
-                 $sessionTitle = null;
631
-             }
625
+        //get destination course title
626
+        if(!empty($hidden_fields['destination_course'])) {
627
+                if (!empty($hidden_fields['destination_session'])) {
628
+                    $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
629
+                } else {
630
+                    $sessionTitle = null;
631
+                }
632 632
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
633
-			echo '<h3>';
634
-				echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
635
-			echo '</h3>';
636
-		}
633
+            echo '<h3>';
634
+                echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
635
+            echo '</h3>';
636
+        }
637 637
 
638
-		echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
639
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
638
+        echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
639
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
640 640
         $icon = Display::returnIconPath('progress_bar.gif');
641
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
642
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
643
-		foreach ($list_course as $course) {
644
-			foreach ($course->resources as $type => $resources) {
645
-				if (count($resources) > 0) {
646
-					echo '<span id="img_'.$course->code.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$course->code'".');" >&nbsp;</span>';
647
-					echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
648
-					echo '<div id="div_'.$course->code.'">';
649
-					echo '<blockquote>';
641
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
642
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
643
+        foreach ($list_course as $course) {
644
+            foreach ($course->resources as $type => $resources) {
645
+                if (count($resources) > 0) {
646
+                    echo '<span id="img_'.$course->code.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$course->code'".');" >&nbsp;</span>';
647
+                    echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
648
+                    echo '<div id="div_'.$course->code.'">';
649
+                    echo '<blockquote>';
650 650
 
651 651
                     echo '<div class="btn-group">';
652
-					echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
652
+                    echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
653 653
                     echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',false);\" >".get_lang('None')."</a>";
654
-					echo '</div><br />';
654
+                    echo '</div><br />';
655 655
 
656
-					foreach ($resources as $id => $resource) {
657
-						echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
656
+                    foreach ($resources as $id => $resource) {
657
+                        echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
658 658
                         echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>';
659
-						$resource->show();
660
-						echo '</label>';
661
-					}
662
-					echo '</blockquote>';
663
-					echo '</div>';
664
-					echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
665
-				}
666
-			}
667
-		}
668
-		if ($avoid_serialize) {
669
-			//Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
670
-			// this is a known issue of serialize
671
-			$course->resources['document']= null;
672
-		}
673
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
674
-		if (is_array($hidden_fields)) {
675
-			foreach ($hidden_fields as $key => $value) {
676
-				echo "\n";
677
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
678
-			}
679
-		}
680
-		echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
681
-		CourseSelectForm :: display_hidden_quiz_questions($course);
682
-		CourseSelectForm :: display_hidden_scorm_directories($course);
683
-		echo '</form>';
684
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
685
-	}
659
+                        $resource->show();
660
+                        echo '</label>';
661
+                    }
662
+                    echo '</blockquote>';
663
+                    echo '</div>';
664
+                    echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
665
+                }
666
+            }
667
+        }
668
+        if ($avoid_serialize) {
669
+            //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
670
+            // this is a known issue of serialize
671
+            $course->resources['document']= null;
672
+        }
673
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
674
+        if (is_array($hidden_fields)) {
675
+            foreach ($hidden_fields as $key => $value) {
676
+                echo "\n";
677
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
678
+            }
679
+        }
680
+        echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
681
+        CourseSelectForm :: display_hidden_quiz_questions($course);
682
+        CourseSelectForm :: display_hidden_scorm_directories($course);
683
+        echo '</form>';
684
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
685
+    }
686 686
 }
Please login to merge, or discard this patch.
main/exercise/fill_blanks.class.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -726,29 +726,29 @@  discard block
 block discarded – undo
726 726
     }
727 727
 
728 728
     /**
729
-    * Return an array of student state answers for fill the blank questions
730
-    * for each students that answered the question
731
-    * -2  : didn't answer
732
-    * -1  : student answer is wrong
733
-    *  0  : student answer is correct
734
-    * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
735
-    *
736
-    * @param integer $testId
737
-    * @param integer $questionId
738
-    * @param $studentsIdList
739
-    * @param string $startDate
740
-    * @param string $endDate
741
-    * @param bool $useLastAnswerredAttempt
742
-    * @return array
743
-    * (
744
-    *     [student_id] => Array
745
-    *         (
746
-    *             [first fill the blank for question] => -1
747
-    *             [second fill the blank for question] => 2
748
-    *             [third fill the blank for question] => -1
749
-    *         )
750
-    * )
751
-    */
729
+     * Return an array of student state answers for fill the blank questions
730
+     * for each students that answered the question
731
+     * -2  : didn't answer
732
+     * -1  : student answer is wrong
733
+     *  0  : student answer is correct
734
+     * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
735
+     *
736
+     * @param integer $testId
737
+     * @param integer $questionId
738
+     * @param $studentsIdList
739
+     * @param string $startDate
740
+     * @param string $endDate
741
+     * @param bool $useLastAnswerredAttempt
742
+     * @return array
743
+     * (
744
+     *     [student_id] => Array
745
+     *         (
746
+     *             [first fill the blank for question] => -1
747
+     *             [second fill the blank for question] => 2
748
+     *             [third fill the blank for question] => -1
749
+     *         )
750
+     * )
751
+     */
752 752
     public static function getFillTheBlankTabResult(
753 753
         $testId,
754 754
         $questionId,
@@ -757,17 +757,17 @@  discard block
 block discarded – undo
757 757
         $endDate,
758 758
         $useLastAnswerredAttempt = true
759 759
     ) {
760
-       $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
761
-       $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
762
-       $courseId = api_get_course_int_id();
760
+        $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
761
+        $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
762
+        $courseId = api_get_course_int_id();
763 763
 
764 764
 
765
-       // request to have all the answers of student for this question
766
-       // student may have doing it several time
767
-       // student may have not answered the bracket id, in this case, is result of the answer is empty
765
+        // request to have all the answers of student for this question
766
+        // student may have doing it several time
767
+        // student may have not answered the bracket id, in this case, is result of the answer is empty
768 768
 
769
-       // we got the less recent attempt first
770
-       $sql = '
769
+        // we got the less recent attempt first
770
+        $sql = '
771 771
            SELECT * FROM '.$tblTrackEAttempt.' tea
772 772
            LEFT JOIN '.$tblTrackEExercise.' tee
773 773
            ON tee.exe_id = tea.exe_id
@@ -782,51 +782,51 @@  discard block
 block discarded – undo
782 782
            ORDER BY user_id, tea.exe_id;
783 783
        ';
784 784
 
785
-       $res = Database::query($sql);
786
-       $tabUserResult = array();
787
-       $bracketNumber = 0;
788
-       // foreach attempts for all students starting with his older attempt
789
-       while ($data = Database::fetch_array($res)) {
790
-           $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
785
+        $res = Database::query($sql);
786
+        $tabUserResult = array();
787
+        $bracketNumber = 0;
788
+        // foreach attempts for all students starting with his older attempt
789
+        while ($data = Database::fetch_array($res)) {
790
+            $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
791 791
 
792
-           // for each bracket to find in this question
793
-           foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
792
+            // for each bracket to find in this question
793
+            foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
794 794
 
795
-               if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
796
-                   // student has answered this bracket, cool
797
-                   switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
798
-                       case self::FILL_THE_BLANK_MENU :
795
+                if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
796
+                    // student has answered this bracket, cool
797
+                    switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
798
+                        case self::FILL_THE_BLANK_MENU :
799 799
                            // get the indice of the choosen answer in the menu
800 800
                            // we know that the right answer is the first entry of the menu, ie 0
801 801
                            // (remember, menu entries are shuffled when taking the test)
802 802
                            $tabUserResult[$data['user_id']][$bracketNumber] = FillBlanks::getFillTheBlankMenuAnswerNum(
803
-                               $tabAnswer['tabwords'][$bracketNumber],
804
-                               $tabAnswer['studentanswer'][$bracketNumber]
805
-                           );
806
-                           break;
807
-                       default :
803
+                                $tabAnswer['tabwords'][$bracketNumber],
804
+                                $tabAnswer['studentanswer'][$bracketNumber]
805
+                            );
806
+                            break;
807
+                        default :
808 808
                            if (FillBlanks::isGoodStudentAnswer($tabAnswer['studentanswer'][$bracketNumber], $tabAnswer['tabwords'][$bracketNumber])) {
809
-                               $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
810
-                           } else {
811
-                               $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
812
-                           }
813
-                   }
814
-               } else {
815
-                   // student didn't answer this bracket
816
-                   if ($useLastAnswerredAttempt) {
817
-                       // if we take into account the last answered attempt
818
-                       if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
819
-                           $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
820
-                       }
821
-                   } else {
822
-                       // we take the last attempt, even if the student answer the question before
823
-                       $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
824
-                   }
825
-               }
826
-           }
827
-       }
828
-
829
-       return $tabUserResult;
809
+                                $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
810
+                            } else {
811
+                                $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
812
+                            }
813
+                    }
814
+                } else {
815
+                    // student didn't answer this bracket
816
+                    if ($useLastAnswerredAttempt) {
817
+                        // if we take into account the last answered attempt
818
+                        if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
819
+                            $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
820
+                        }
821
+                    } else {
822
+                        // we take the last attempt, even if the student answer the question before
823
+                        $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
824
+                    }
825
+                }
826
+            }
827
+        }
828
+
829
+        return $tabUserResult;
830 830
     }
831 831
 
832 832
     /**
Please login to merge, or discard this patch.
main/resourcelinker/resourcelinker.php 1 patch
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -79,81 +79,81 @@  discard block
 block discarded – undo
79 79
 */
80 80
 if ($from_learnpath == 'yes')
81 81
 {
82
-	//start from clear every time in LearnPath Builder
83
-	$_SESSION['addedresource'] = null;
84
-	$_SESSION['addedresourceid'] = null;
85
-	$_SESSION['addedresourceassigned'] = null;
86
-	unset ($_SESSION['addedresource']);
87
-	unset ($_SESSION['addedresourceid']);
88
-	unset ($_SESSION['addedresourceassigned']);
82
+    //start from clear every time in LearnPath Builder
83
+    $_SESSION['addedresource'] = null;
84
+    $_SESSION['addedresourceid'] = null;
85
+    $_SESSION['addedresourceassigned'] = null;
86
+    unset ($_SESSION['addedresource']);
87
+    unset ($_SESSION['addedresourceid']);
88
+    unset ($_SESSION['addedresourceassigned']);
89 89
 }
90 90
 
91 91
 // Process a new chapter?
92 92
 if (!empty ($_POST['add_dir']) && !empty ($_POST['title']))
93 93
 {
94
-	$title = $_POST['title'];
95
-	$description = '';
96
-	if (!empty ($_POST['description']))
97
-	{
98
-		$description = $_POST['description'];
99
-	}
100
-
101
-	// get max display_order so far in this parent chapter
102
-	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id";
103
-	$res = Database::query($sql);
104
-	$row = Database::fetch_array($res);
105
-	$max_temp = $row[0];
106
-
107
-	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id";
108
-	$res = Database::query($sql);
109
-	$row = Database::fetch_array($res);
110
-	$max_temp2 = $row[0];
111
-	if ($max_temp2 > $max_temp)
112
-	{
113
-		$order = $max_temp2 +1;
114
-	}
115
-	else
116
-	{
117
-		$order = $max_temp +1;
118
-	}
119
-
120
-	$sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )";
121
-	$res = Database::query($sql);
122
-	if ($res !== false)
123
-	{
124
-		$title = '';
125
-		$description = '';
126
-	}
94
+    $title = $_POST['title'];
95
+    $description = '';
96
+    if (!empty ($_POST['description']))
97
+    {
98
+        $description = $_POST['description'];
99
+    }
100
+
101
+    // get max display_order so far in this parent chapter
102
+    $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id";
103
+    $res = Database::query($sql);
104
+    $row = Database::fetch_array($res);
105
+    $max_temp = $row[0];
106
+
107
+    $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id";
108
+    $res = Database::query($sql);
109
+    $row = Database::fetch_array($res);
110
+    $max_temp2 = $row[0];
111
+    if ($max_temp2 > $max_temp)
112
+    {
113
+        $order = $max_temp2 +1;
114
+    }
115
+    else
116
+    {
117
+        $order = $max_temp +1;
118
+    }
119
+
120
+    $sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )";
121
+    $res = Database::query($sql);
122
+    if ($res !== false)
123
+    {
124
+        $title = '';
125
+        $description = '';
126
+    }
127 127
 }
128 128
 
129 129
 // This if when a external link is submitted
130 130
 if (!empty ($_POST['external_link_submit']))
131 131
 {
132
-	$add = true;
133
-	if ($add_2_links != "niet toevoegen")
134
-	{
135
-		// add external link to the links table.
136
-		$pos = strpos($external_link, 'ttp:');
137
-		if ($pos == '')
138
-		{
139
-			$external_link = 'http://'.$external_link;
140
-		}
141
-
142
-		$sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
143
-		$result = Database::query($sql);
144
-		$addedresource[] = "Link";
145
-		$addedresourceid[] = Database::insert_id();
146
-		$_SESSION['addedresource'] = $addedresource;
147
-		$_SESSION['addedresourceid'] = $addedresourceid;
148
-	}
149
-	else
150
-	{
151
-		// do not add external link to the links table
152
-		$addedresource[] = "Externallink";
153
-		$addedresourceid[] = $external_link;
154
-		$_SESSION['addedresource'] = $addedresource;
155
-		$_SESSION['addedresourceid'] = $addedresourceid;
156
-	}
132
+    $add = true;
133
+    if ($add_2_links != "niet toevoegen")
134
+    {
135
+        // add external link to the links table.
136
+        $pos = strpos($external_link, 'ttp:');
137
+        if ($pos == '')
138
+        {
139
+            $external_link = 'http://'.$external_link;
140
+        }
141
+
142
+        $sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
143
+        $result = Database::query($sql);
144
+        $addedresource[] = "Link";
145
+        $addedresourceid[] = Database::insert_id();
146
+        $_SESSION['addedresource'] = $addedresource;
147
+        $_SESSION['addedresourceid'] = $addedresourceid;
148
+    }
149
+    else
150
+    {
151
+        // do not add external link to the links table
152
+        $addedresource[] = "Externallink";
153
+        $addedresourceid[] = $external_link;
154
+        $_SESSION['addedresource'] = $addedresource;
155
+        $_SESSION['addedresourceid'] = $addedresourceid;
156
+    }
157 157
 }
158 158
 
159 159
 // loading the session variables into local array
@@ -163,107 +163,107 @@  discard block
 block discarded – undo
163 163
 // This is when a resource was added to the session
164 164
 if ($add)
165 165
 {
166
-	// adding the new variable to the local array
167
-	if (empty ($_POST['external_link_submit']))
168
-	{
169
-		//that case is already arranged, see upwards
170
-		$addedresource[] = $content;
171
-		$addedresourceid[] = $add;
172
-	}
173
-	$addedresourceassigned[] = 0;
174
-
175
-	// loading the local array into the session variable
176
-	$_SESSION['addedresource'] = $addedresource;
177
-	$_SESSION['addedresourceid'] = $addedresourceid;
166
+    // adding the new variable to the local array
167
+    if (empty ($_POST['external_link_submit']))
168
+    {
169
+        //that case is already arranged, see upwards
170
+        $addedresource[] = $content;
171
+        $addedresourceid[] = $add;
172
+    }
173
+    $addedresourceassigned[] = 0;
174
+
175
+    // loading the local array into the session variable
176
+    $_SESSION['addedresource'] = $addedresource;
177
+    $_SESSION['addedresourceid'] = $addedresourceid;
178
+
179
+    //---------------------------------------
180
+    //we assign to chapters immediately !
181
+    //---------------------------------------
182
+    $resource_added = false;
183
+    if ($from_learnpath == 'yes')
184
+    {
185
+        $i = 0;
186
+        //calculating the last order of the items of this chapter
187
+        $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id";
188
+        $result = Database::query($sql);
189
+        if(Database::num_rows($result)==0){
190
+            $lastorder_item = 0;
191
+        }else{
192
+            $row = Database::fetch_array($result);
193
+            $lastorder_item = ($row[0]);
194
+        }
195
+        $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id";
196
+        $result = Database::query($sql);
197
+        if(Database::num_rows($result)==0){
198
+            $lastorder_chapter = 0;
199
+        }else{
200
+            $row = Database::fetch_array($result);
201
+            $lastorder_chapter = ($row[0]);
202
+        }
203
+        $lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1);
178 204
 
179
-	//---------------------------------------
180
-	//we assign to chapters immediately !
181
-	//---------------------------------------
182
-	$resource_added = false;
183
-	if ($from_learnpath == 'yes')
184
-	{
185
-		$i = 0;
186
-		//calculating the last order of the items of this chapter
187
-		$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id";
188
-		$result = Database::query($sql);
189
-		if(Database::num_rows($result)==0){
190
-			$lastorder_item = 0;
191
-		}else{
192
-			$row = Database::fetch_array($result);
193
-			$lastorder_item = ($row[0]);
194
-		}
195
-		$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id";
196
-		$result = Database::query($sql);
197
-		if(Database::num_rows($result)==0){
198
-			$lastorder_chapter = 0;
199
-		}else{
200
-			$row = Database::fetch_array($result);
201
-			$lastorder_chapter = ($row[0]);
202
-		}
203
-		$lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1);
204
-
205
-		foreach ($addedresource as $addedresource_item)
206
-		{
207
-			// in the case we added a chapter, add this into the chapters list with the correct parent_id
208
-			if ($addedresource_item == "Chap")
209
-			{
210
-				$sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")";
211
-				Database::query($sql);
212
-			}
213
-
214
-			if (!$addedresourceassigned[$i])
215
-			{
216
-				//not to assign it twice
217
-				if ($addedresource_item == "Ass")
218
-				{
219
-					$addedresource_item = "Assignments";
220
-				}
221
-				if ($addedresource_item == "Drop")
222
-				{
223
-					$addedresource_item = "Dropbox";
224
-				}
225
-				if ($addedresource_item == "Intro")
226
-				{
227
-					$addedresource_item = "Introduction_text";
228
-				}
229
-				if ($addedresource_item == "Course_desc")
230
-				{
231
-					$addedresource_item = "Course_description";
232
-				}
233
-				if ($addedresource_item == "Group")
234
-				{
235
-					$addedresource_item = "Groups";
236
-				}
237
-				if ($addedresource_item == "User")
238
-				{
239
-					$addedresource_item = "Users";
240
-				}
241
-				if ($target == '')
242
-				{
243
-					$target = '_self';
244
-				}
245
-				if ($addedresource_item == 'Link')
246
-				{
247
-					$addedresource_item .= ' '.$target;
248
-				}
249
-				$sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')";
250
-				$result = Database::query($sql);
251
-				$addedresourceassigned[$i] = 1;
252
-				$resource_added = true;
253
-			}
254
-			$i ++;
255
-			$lastorder ++;
256
-		}
257
-		//$_SESSION['addedresource']=null;
258
-		//$_SESSION['addedresourceid']=null;
259
-		// cleaning up the session once again
260
-		$_SESSION['addedresource'] = null;
261
-   		$_SESSION['addedresourceid'] = null;
262
-   		$_SESSION['addedresourceassigned'] = null;
263
-   		unset ($_SESSION['addedresource']);
264
-   		unset ($_SESSION['addedresourceid']);
265
-   		unset ($_SESSION['addedresourceassigned']);
266
-	}
205
+        foreach ($addedresource as $addedresource_item)
206
+        {
207
+            // in the case we added a chapter, add this into the chapters list with the correct parent_id
208
+            if ($addedresource_item == "Chap")
209
+            {
210
+                $sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")";
211
+                Database::query($sql);
212
+            }
213
+
214
+            if (!$addedresourceassigned[$i])
215
+            {
216
+                //not to assign it twice
217
+                if ($addedresource_item == "Ass")
218
+                {
219
+                    $addedresource_item = "Assignments";
220
+                }
221
+                if ($addedresource_item == "Drop")
222
+                {
223
+                    $addedresource_item = "Dropbox";
224
+                }
225
+                if ($addedresource_item == "Intro")
226
+                {
227
+                    $addedresource_item = "Introduction_text";
228
+                }
229
+                if ($addedresource_item == "Course_desc")
230
+                {
231
+                    $addedresource_item = "Course_description";
232
+                }
233
+                if ($addedresource_item == "Group")
234
+                {
235
+                    $addedresource_item = "Groups";
236
+                }
237
+                if ($addedresource_item == "User")
238
+                {
239
+                    $addedresource_item = "Users";
240
+                }
241
+                if ($target == '')
242
+                {
243
+                    $target = '_self';
244
+                }
245
+                if ($addedresource_item == 'Link')
246
+                {
247
+                    $addedresource_item .= ' '.$target;
248
+                }
249
+                $sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')";
250
+                $result = Database::query($sql);
251
+                $addedresourceassigned[$i] = 1;
252
+                $resource_added = true;
253
+            }
254
+            $i ++;
255
+            $lastorder ++;
256
+        }
257
+        //$_SESSION['addedresource']=null;
258
+        //$_SESSION['addedresourceid']=null;
259
+        // cleaning up the session once again
260
+        $_SESSION['addedresource'] = null;
261
+            $_SESSION['addedresourceid'] = null;
262
+            $_SESSION['addedresourceassigned'] = null;
263
+            unset ($_SESSION['addedresource']);
264
+            unset ($_SESSION['addedresourceid']);
265
+            unset ($_SESSION['addedresourceassigned']);
266
+    }
267 267
 }
268 268
 
269 269
 /*
@@ -278,64 +278,64 @@  discard block
 block discarded – undo
278 278
 */
279 279
 if ($_GET["source_id"])
280 280
 {
281
-	switch ($_GET["source_id"])
282
-	{
283
-		case "1" : // coming from Agenda
284
-			if ($action == "edit")
285
-			{
286
-				$url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource";
287
-			}
288
-			elseif ($action == "add")
289
-		{
290
-				$url = "../calendar/agenda.php?action=add&originalresource=$originalresource";
291
-			}
292
-			else
293
-			{
294
-				$url = "../calendar/agenda.php?action=add";
295
-			}
296
-			$originaltoolname = get_lang("Agenda");
297
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
298
-			unset($_SESSION['from_learnpath']);
299
-			unset ($from_learnpath);
300
-			break;
301
-		case "2" : // coming from forum: new topic
302
-			$url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5";
303
-			$originaltoolname = get_lang("ForumAddNewTopic");
304
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
305
-			unset($_SESSION['from_learnpath']);
306
-			unset ($from_learnpath);
307
-			break;
308
-		case "3" : // coming from forum: edit topic
309
-			$url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no";
310
-			$originaltoolname = get_lang("ForumEditTopic");
311
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
312
-			unset($_SESSION['from_learnpath']);
313
-			unset ($from_learnpath);
314
-			break;
315
-		case "4" : // coming from exercises: edit topic
316
-			$url = "../exercise/admin.php?modifyAnswers=$modifyAnswers";
317
-			$originaltoolname = get_lang("ExerciseAnswers");
318
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
319
-			unset($_SESSION['from_learnpath']);
320
-			unset ($from_learnpath);
321
-			break;
322
-		case "5" : // coming from learning path
323
-			$from_learnpath = 'yes';
324
-			Session::write('from_learnpath',$from_learnpath);
325
-			break;
326
-			/*************************************** end add [email protected] *********************************/
327
-
328
-	}
329
-	// We do not come from the learning path. We store the name of the tool & url in a session.
330
-	if ($from_learnpath != 'yes')
331
-	{
332
-		if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"])
333
-		{
334
-			$_SESSION["origintoolurl"] = $breadcrumbelement["url"];
335
-			$_SESSION["origintoolname"] = $breadcrumbelement["name"];
336
-			$interbreadcrumb = "";
337
-		}
338
-	}
281
+    switch ($_GET["source_id"])
282
+    {
283
+        case "1" : // coming from Agenda
284
+            if ($action == "edit")
285
+            {
286
+                $url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource";
287
+            }
288
+            elseif ($action == "add")
289
+        {
290
+                $url = "../calendar/agenda.php?action=add&originalresource=$originalresource";
291
+            }
292
+            else
293
+            {
294
+                $url = "../calendar/agenda.php?action=add";
295
+            }
296
+            $originaltoolname = get_lang("Agenda");
297
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
298
+            unset($_SESSION['from_learnpath']);
299
+            unset ($from_learnpath);
300
+            break;
301
+        case "2" : // coming from forum: new topic
302
+            $url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5";
303
+            $originaltoolname = get_lang("ForumAddNewTopic");
304
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
305
+            unset($_SESSION['from_learnpath']);
306
+            unset ($from_learnpath);
307
+            break;
308
+        case "3" : // coming from forum: edit topic
309
+            $url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no";
310
+            $originaltoolname = get_lang("ForumEditTopic");
311
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
312
+            unset($_SESSION['from_learnpath']);
313
+            unset ($from_learnpath);
314
+            break;
315
+        case "4" : // coming from exercises: edit topic
316
+            $url = "../exercise/admin.php?modifyAnswers=$modifyAnswers";
317
+            $originaltoolname = get_lang("ExerciseAnswers");
318
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
319
+            unset($_SESSION['from_learnpath']);
320
+            unset ($from_learnpath);
321
+            break;
322
+        case "5" : // coming from learning path
323
+            $from_learnpath = 'yes';
324
+            Session::write('from_learnpath',$from_learnpath);
325
+            break;
326
+            /*************************************** end add [email protected] *********************************/
327
+
328
+    }
329
+    // We do not come from the learning path. We store the name of the tool & url in a session.
330
+    if ($from_learnpath != 'yes')
331
+    {
332
+        if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"])
333
+        {
334
+            $_SESSION["origintoolurl"] = $breadcrumbelement["url"];
335
+            $_SESSION["origintoolname"] = $breadcrumbelement["name"];
336
+            $interbreadcrumb = "";
337
+        }
338
+    }
339 339
 
340 340
 }
341 341
 
@@ -343,26 +343,26 @@  discard block
 block discarded – undo
343 343
 // the information from the session. Else we use the information of the learningpath itself.
344 344
 if ($from_learnpath != 'yes')
345 345
 {
346
-	$nameTools = get_lang('AddResource');
347
-	$interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]);
346
+    $nameTools = get_lang('AddResource');
347
+    $interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]);
348 348
 }
349 349
 else
350 350
 {
351
-	$learnpath_select_query = "	SELECT * FROM $tbl_learnpath_main
351
+    $learnpath_select_query = "	SELECT * FROM $tbl_learnpath_main
352 352
 		  								WHERE learnpath_id=$learnpath_id";
353
-	$sql_result = Database::query($learnpath_select_query);
354
-	$therow = Database::fetch_array($sql_result);
353
+    $sql_result = Database::query($learnpath_select_query);
354
+    $therow = Database::fetch_array($sql_result);
355 355
 
356
-	$learnpath_chapter_query = "	SELECT * FROM $tbl_learnpath_chapter
356
+    $learnpath_chapter_query = "	SELECT * FROM $tbl_learnpath_chapter
357 357
 		  								WHERE (learnpath_id = '$learnpath_id' and id = '$chapter_id')";
358
-	$sql_result = Database::query($learnpath_chapter_query);
359
-	$therow2 = Database::fetch_array($sql_result);
358
+    $sql_result = Database::query($learnpath_chapter_query);
359
+    $therow2 = Database::fetch_array($sql_result);
360 360
 
361
-	$from_learnpath = 'yes';
362
-	$_SESSION['from_learnpath'] = $from_learnpath;
363
-	$interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath'));
364
-	$interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}");
365
-	$interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}");
361
+    $from_learnpath = 'yes';
362
+    $_SESSION['from_learnpath'] = $from_learnpath;
363
+    $interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath'));
364
+    $interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}");
365
+    $interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}");
366 366
 
367 367
 }
368 368
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 echo "<h3>".$nameTools;
381 381
 if ($from_learnpath == 'yes')
382 382
 {
383
-	echo get_lang("AddResource")." - {$therow2['chapter_name']}";
383
+    echo get_lang("AddResource")." - {$therow2['chapter_name']}";
384 384
 }
385 385
 echo "</h3>";
386 386
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 $result_select_active=Database::query($sql_select_active);
394 394
 while ($row=Database::fetch_array($result_select_active))
395 395
 {
396
-	$active_modules[]=$row['name'];
396
+    $active_modules[]=$row['name'];
397 397
 }
398 398
 
399 399
 
@@ -536,12 +536,12 @@  discard block
 block discarded – undo
536 536
 
537 537
 if ($from_learnpath != 'yes')
538 538
 {
539
-	echo "<tr><td>&nbsp;</td></tr>";
540
-	echo "<tr><td><b>".get_lang('ResourcesAdded')." (";
541
-	echo count($addedresource);
542
-	echo ")</b></td></tr>";
543
-	echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>";
544
-	echo "</td></tr>";
539
+    echo "<tr><td>&nbsp;</td></tr>";
540
+    echo "<tr><td><b>".get_lang('ResourcesAdded')." (";
541
+    echo count($addedresource);
542
+    echo ")</b></td></tr>";
543
+    echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>";
544
+    echo "</td></tr>";
545 545
 }
546 546
 ?>
547 547
         <tr>
@@ -557,11 +557,11 @@  discard block
 block discarded – undo
557 557
 
558 558
 if ($from_learnpath != 'yes')
559 559
 {
560
-	echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>";
560
+    echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>";
561 561
 }
562 562
 else
563 563
 {
564
-	echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".'  '.get_lang('Ok').'  '."\"></form>";
564
+    echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".'  '.get_lang('Ok').'  '."\"></form>";
565 565
 }
566 566
 ?>
567 567
 
@@ -577,40 +577,40 @@  discard block
 block discarded – undo
577 577
 
578 578
 if ($resource_added)
579 579
 {
580
-	Display :: display_normal_message(get_lang("ResourceAdded"));
580
+    Display :: display_normal_message(get_lang("ResourceAdded"));
581 581
 }
582 582
 
583 583
 if ($from_learnpath != 'yes')
584 584
 {
585
-	echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>";
585
+    echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>";
586 586
 }
587 587
 //echo "<hr>";
588 588
 
589 589
 // Agenda items -->
590 590
 if ($content == "Agenda")
591 591
 {
592
-	$TABLEAGENDA 			= Database::get_course_table(TABLE_AGENDA);
593
-	$TABLE_ITEM_PROPERTY 	= Database::get_course_table(TABLE_ITEM_PROPERTY);
592
+    $TABLEAGENDA 			= Database::get_course_table(TABLE_AGENDA);
593
+    $TABLE_ITEM_PROPERTY 	= Database::get_course_table(TABLE_ITEM_PROPERTY);
594 594
 
595
-	$sql="SELECT agenda.*, toolitemproperties.*
595
+    $sql="SELECT agenda.*, toolitemproperties.*
596 596
 					FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
597 597
 					WHERE agenda.id = toolitemproperties.ref
598 598
 					AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
599 599
 					AND (toolitemproperties.to_group_id='0' OR toolitemproperties.to_group_id IS NULL)
600 600
 					AND toolitemproperties.visibility='1'";
601 601
 
602
-	$result = Database::query($sql);
603
-
604
-	while ($myrow = Database::fetch_array($result))
605
-	{
606
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
607
-		echo "<img src='../img/agenda.gif' alt='agenda'>";
608
-		echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />";
609
-		echo "<b>".$myrow["title"]."</b></td></tr><tr><td>";
610
-		echo $myrow["content"]."<br />";
611
-		showorhide_addresourcelink($content, $myrow["id"]);
612
-		echo "</td></tr></table><br />";
613
-	}
602
+    $result = Database::query($sql);
603
+
604
+    while ($myrow = Database::fetch_array($result))
605
+    {
606
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
607
+        echo "<img src='../img/agenda.gif' alt='agenda'>";
608
+        echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />";
609
+        echo "<b>".$myrow["title"]."</b></td></tr><tr><td>";
610
+        echo $myrow["content"]."<br />";
611
+        showorhide_addresourcelink($content, $myrow["id"]);
612
+        echo "</td></tr></table><br />";
613
+    }
614 614
 } // end if ($_GET["resource"]=="Agenda")
615 615
 
616 616
 /*
@@ -620,12 +620,12 @@  discard block
 block discarded – undo
620 620
 */
621 621
 if ($content == "chapter")
622 622
 {
623
-	echo '<table><form name="add_dir" action="'.'" method="POST">'."\n";
624
-	echo '  <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n";
625
-	echo '  <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n";
626
-	echo '  <tr><td></td><td><input type="submit" name="add_dir" value="'.get_lang('AddIt').'"/></td></tr>'."\n";
627
-	echo '</form></table>'."\n";
628
-	//echo "<hr>";
623
+    echo '<table><form name="add_dir" action="'.'" method="POST">'."\n";
624
+    echo '  <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n";
625
+    echo '  <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n";
626
+    echo '  <tr><td></td><td><input type="submit" name="add_dir" value="'.get_lang('AddIt').'"/></td></tr>'."\n";
627
+    echo '</form></table>'."\n";
628
+    //echo "<hr>";
629 629
 }
630 630
 
631 631
 /*
@@ -640,23 +640,23 @@  discard block
 block discarded – undo
640 640
 //				b. one is a student AND the documents tool is active. Student cannot add documents if the documents tool is inactive (teacher can do this)
641 641
 if ($content == "Document" OR (empty($content) AND (api_is_allowed_to_edit() OR in_array(TOOL_DOCUMENT,$active_modules))) AND !$_GET['showresources'])
642 642
 {
643
-	// setting variables for file locations
644
-	$baseServDir = $_configuration['root_sys'];
645
-	$courseDir = $_course['path']."/document";
646
-	$baseWorkDir = $baseServDir.$courseDir;
647
-	// showing the link to move one folder up (when not in the root folder)
648
-	show_folder_up($chapter_id);
649
-	// showing the blue bar with the path in it when we are not in the root
650
-	if (get_levels($folder))
651
-	{
652
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">";
653
-		echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>";
654
-		echo $folder."</b></font></td></tr></table>";
655
-	}
656
-
657
-	// showing the documents and subfolders of the folder we are in.
658
-	show_documents($folder, $chapter_id);
659
-	//echo "<hr>";
643
+    // setting variables for file locations
644
+    $baseServDir = $_configuration['root_sys'];
645
+    $courseDir = $_course['path']."/document";
646
+    $baseWorkDir = $baseServDir.$courseDir;
647
+    // showing the link to move one folder up (when not in the root folder)
648
+    show_folder_up($chapter_id);
649
+    // showing the blue bar with the path in it when we are not in the root
650
+    if (get_levels($folder))
651
+    {
652
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">";
653
+        echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>";
654
+        echo $folder."</b></font></td></tr></table>";
655
+    }
656
+
657
+    // showing the documents and subfolders of the folder we are in.
658
+    show_documents($folder, $chapter_id);
659
+    //echo "<hr>";
660 660
 }
661 661
 
662 662
 /*
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
 */
667 667
 if ($content == "Ad_Valvas")
668 668
 {
669
-	$tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT);
670
-	$sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i
669
+    $tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT);
670
+    $sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i
671 671
 			WHERE
672 672
 				i.tool = '".TOOL_ANNOUNCEMENT."' AND
673 673
 				a.id=i.ref AND
@@ -676,17 +676,17 @@  discard block
 block discarded – undo
676 676
 				i.to_user_id IS NULL
677 677
 			ORDER BY a.display_order ASC";
678 678
 
679
-	$result = Database::query($sql);
680
-	while ($myrow = Database::fetch_array($result))
681
-	{
682
-		echo "<table width=\"100%\"><tr><td>";
683
-		echo "<img src='../img/valves.gif' alt='advalvas'>";
684
-		echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get());
685
-		echo "</td></tr><tr><td>";
686
-		echo $myrow["title"]."<br />";
687
-		showorhide_addresourcelink($content, $myrow["id"]);
688
-		echo "</td></tr></table>";
689
-	}
679
+    $result = Database::query($sql);
680
+    while ($myrow = Database::fetch_array($result))
681
+    {
682
+        echo "<table width=\"100%\"><tr><td>";
683
+        echo "<img src='../img/valves.gif' alt='advalvas'>";
684
+        echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get());
685
+        echo "</td></tr><tr><td>";
686
+        echo $myrow["title"]."<br />";
687
+        showorhide_addresourcelink($content, $myrow["id"]);
688
+        echo "</td></tr></table>";
689
+    }
690 690
 }
691 691
 
692 692
 /*
@@ -696,75 +696,75 @@  discard block
 block discarded – undo
696 696
 */
697 697
 if ($content == "Forum")
698 698
 {
699
-	$TBL_FORUMS 		= Database::get_course_table(TABLE_FORUM);
700
-	$TBL_CATAGORIES 	= Database::get_course_table(TABLE_FORUM_CATEGORY);
701
-	$TBL_FORUMTOPICS 	= Database::get_course_table(TABLE_FORUM_POST);
702
-	$tbl_posts 			= Database::get_course_table(TABLE_FORUM_POST);
703
-	$tbl_posts_text 	= Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
704
-
705
-	echo "<table width='100%'>";
699
+    $TBL_FORUMS 		= Database::get_course_table(TABLE_FORUM);
700
+    $TBL_CATAGORIES 	= Database::get_course_table(TABLE_FORUM_CATEGORY);
701
+    $TBL_FORUMTOPICS 	= Database::get_course_table(TABLE_FORUM_POST);
702
+    $tbl_posts 			= Database::get_course_table(TABLE_FORUM_POST);
703
+    $tbl_posts_text 	= Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
704
+
705
+    echo "<table width='100%'>";
706
+
707
+    // displaying the categories and the forums
708
+    if (!$forum and !$thread)
709
+    {
710
+        $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC";
711
+        $result = Database::query($sql);
712
+        while ($myrow = Database::fetch_array($result))
713
+        {
714
+            if ($myrow["cat_title"] !== $old_cat_title)
715
+            {
716
+                echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
717
+            }
718
+            $old_cat_title = $myrow["cat_title"];
719
+            echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>";
720
+            showorhide_addresourcelink("Forum", $myrow["forum_id"]);
721
+            echo "</td></tr>";
722
+        }
723
+    }
724
+    //displaying all the threads of one forum
725
+    if ($forum)
726
+    {
727
+        // displaying the category title
728
+        $sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
729
+        $result = Database::query($sql);
730
+        $myrow = Database::fetch_array($result);
731
+        echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
732
+
733
+        // displaying the forum title
734
+        $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
735
+        $result = Database::query($sql);
736
+        $myrow = Database::fetch_array($result);
737
+        echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";
738
+
739
+        if (!$thread)
740
+        {
741
+            // displaying all the threads of this forum
742
+            $sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
743
+            $result = Database::query($sql);
744
+            while ($myrow = Database::fetch_array($result))
745
+            {
746
+                echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a>  (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
747
+                showorhide_addresourcelink("Thread", $myrow["topic_id"]);
748
+                echo "</td></tr>";
749
+            }
750
+        }
751
+        else
752
+        {
753
+            // displaying all the replies
754
+            $sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC";
755
+            $result = Database::query($sql);
756
+            while ($myrow = Database::fetch_array($result))
757
+            {
758
+                echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
759
+                echo $myrow["post_text"]."</td>";
760
+                echo "<td>";
761
+                showorhide_addresourcelink("Post", $myrow["post_id"]);
762
+                echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>";
763
+            }
706 764
 
707
-	// displaying the categories and the forums
708
-	if (!$forum and !$thread)
709
-	{
710
-		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC";
711
-		$result = Database::query($sql);
712
-		while ($myrow = Database::fetch_array($result))
713
-		{
714
-			if ($myrow["cat_title"] !== $old_cat_title)
715
-			{
716
-				echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
717
-			}
718
-			$old_cat_title = $myrow["cat_title"];
719
-			echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>";
720
-			showorhide_addresourcelink("Forum", $myrow["forum_id"]);
721
-			echo "</td></tr>";
722
-		}
723
-	}
724
-	//displaying all the threads of one forum
725
-	if ($forum)
726
-	{
727
-		// displaying the category title
728
-		$sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
729
-		$result = Database::query($sql);
730
-		$myrow = Database::fetch_array($result);
731
-		echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
732
-
733
-		// displaying the forum title
734
-		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
735
-		$result = Database::query($sql);
736
-		$myrow = Database::fetch_array($result);
737
-		echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";
738
-
739
-		if (!$thread)
740
-		{
741
-			// displaying all the threads of this forum
742
-			$sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
743
-			$result = Database::query($sql);
744
-			while ($myrow = Database::fetch_array($result))
745
-			{
746
-				echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a>  (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
747
-				showorhide_addresourcelink("Thread", $myrow["topic_id"]);
748
-				echo "</td></tr>";
749
-			}
750
-		}
751
-		else
752
-		{
753
-			// displaying all the replies
754
-			$sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC";
755
-			$result = Database::query($sql);
756
-			while ($myrow = Database::fetch_array($result))
757
-			{
758
-				echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
759
-				echo $myrow["post_text"]."</td>";
760
-				echo "<td>";
761
-				showorhide_addresourcelink("Post", $myrow["post_id"]);
762
-				echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>";
763
-			}
764
-
765
-		}
766
-	}
767
-	echo "</table>";
765
+        }
766
+    }
767
+    echo "</table>";
768 768
 }
769 769
 
770 770
 /*
@@ -774,57 +774,57 @@  discard block
 block discarded – undo
774 774
 */
775 775
 if ($content == "Link")
776 776
 {
777
-	// including the links language file
778
-	include ("../lang/$language/link.inc.php");
779
-
780
-	$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
781
-	if (($learnpath_id != '') and ($content == 'Link'))
782
-	{
783
-		echo "<form name='learnpath_link'><table>";
784
-		echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' ";
785
-		if ($target == '_self')
786
-		{
787
-			echo "selected";
788
-		}
789
-		echo ">".get_lang('SameWindow')."</option><option value='_blank'";
790
-		if ($target == '_blank')
791
-		{
792
-			echo "selected";
793
-		}
794
-		echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>";
795
-	}
796
-
797
-	// showing the links that are in the root (having no category)
798
-	$sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'";
799
-	$result = Database::query($sql);
800
-	if (Database::num_rows($result) > 0)
801
-	{
802
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
803
-		while ($myrow = Database::fetch_array($result))
804
-		{
805
-			echo "<img src='../img/links.gif'>".$myrow["title"];
806
-			echo "<br>";
807
-			showorhide_addresourcelink($content, $myrow["id"]);
808
-			echo "<br><br>";
809
-		}
810
-	}
811
-
812
-	// showing the categories and the links in it.
813
-	$sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
814
-	$resultcategories = Database::query($sqlcategories) or die;
815
-	while ($myrow = @ Database::fetch_array($resultcategories))
816
-	{
817
-		$sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC";
818
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
819
-		$result_links = Database::query($sql_links);
820
-		while ($myrow = Database::fetch_array($result_links))
821
-		{
822
-			echo "<img src='../img/links.gif' />".$myrow["title"];
823
-			echo "<br>";
824
-			showorhide_addresourcelink($content, $myrow["id"]);
825
-			echo "<br><br>";
826
-		}
827
-	}
777
+    // including the links language file
778
+    include ("../lang/$language/link.inc.php");
779
+
780
+    $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
781
+    if (($learnpath_id != '') and ($content == 'Link'))
782
+    {
783
+        echo "<form name='learnpath_link'><table>";
784
+        echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' ";
785
+        if ($target == '_self')
786
+        {
787
+            echo "selected";
788
+        }
789
+        echo ">".get_lang('SameWindow')."</option><option value='_blank'";
790
+        if ($target == '_blank')
791
+        {
792
+            echo "selected";
793
+        }
794
+        echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>";
795
+    }
796
+
797
+    // showing the links that are in the root (having no category)
798
+    $sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'";
799
+    $result = Database::query($sql);
800
+    if (Database::num_rows($result) > 0)
801
+    {
802
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
803
+        while ($myrow = Database::fetch_array($result))
804
+        {
805
+            echo "<img src='../img/links.gif'>".$myrow["title"];
806
+            echo "<br>";
807
+            showorhide_addresourcelink($content, $myrow["id"]);
808
+            echo "<br><br>";
809
+        }
810
+    }
811
+
812
+    // showing the categories and the links in it.
813
+    $sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
814
+    $resultcategories = Database::query($sqlcategories) or die;
815
+    while ($myrow = @ Database::fetch_array($resultcategories))
816
+    {
817
+        $sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC";
818
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
819
+        $result_links = Database::query($sql_links);
820
+        while ($myrow = Database::fetch_array($result_links))
821
+        {
822
+            echo "<img src='../img/links.gif' />".$myrow["title"];
823
+            echo "<br>";
824
+            showorhide_addresourcelink($content, $myrow["id"]);
825
+            echo "<br><br>";
826
+        }
827
+    }
828 828
 }
829 829
 
830 830
 /*
@@ -834,31 +834,31 @@  discard block
 block discarded – undo
834 834
 */
835 835
 if (($content == "Exercise") or ($content == "HotPotatoes"))
836 836
 {
837
-	$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
838
-	$result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
839
-	while ($myrow = Database::fetch_array($result))
840
-	{
841
-		echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
842
-		showorhide_addresourcelink($content, $myrow["id"]);
843
-		echo "<br><br>";
844
-	}
837
+    $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
838
+    $result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
839
+    while ($myrow = Database::fetch_array($result))
840
+    {
841
+        echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
842
+        showorhide_addresourcelink($content, $myrow["id"]);
843
+        echo "<br><br>";
844
+    }
845
+
846
+    if ($from_learnpath == 'yes')
847
+    {
848
+        $uploadPath = "/HotPotatoes_files";
849
+        $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
850
+        $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
851
+        $sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC";
852
+        $result = Database::query($sql);
853
+        while ($myrow = Database::fetch_array($result))
854
+        {
855
+            $path = $myrow["path"];
856
+            echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>";
857
+            showorhide_addresourcelink("HotPotatoes", $myrow["id"]);
858
+            echo "<br><br>";
845 859
 
846
-	if ($from_learnpath == 'yes')
847
-	{
848
-		$uploadPath = "/HotPotatoes_files";
849
-		$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
850
-		$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
851
-		$sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC";
852
-		$result = Database::query($sql);
853
-		while ($myrow = Database::fetch_array($result))
854
-		{
855
-			$path = $myrow["path"];
856
-			echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>";
857
-			showorhide_addresourcelink("HotPotatoes", $myrow["id"]);
858
-			echo "<br><br>";
859
-
860
-		}
861
-	}
860
+        }
861
+    }
862 862
 }
863 863
 
864 864
 /*
@@ -876,10 +876,10 @@  discard block
 block discarded – undo
876 876
       <td align="left"><input name="external_link" type="text" id="external_link" value="http://"></td>
877 877
 	  <?php
878 878
 
879
-	if ($learnpath_id != '')
880
-	{
881
-		echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>";
882
-	}
879
+    if ($learnpath_id != '')
880
+    {
881
+        echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>";
882
+    }
883 883
 ?>
884 884
 	</tr>
885 885
     <tr>
@@ -891,14 +891,14 @@  discard block
 block discarded – undo
891 891
 	  <option value="0"><?php echo get_lang('MainCategory'); ?></option>
892 892
 		<?php
893 893
 
894
-	$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
895
-	$sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC";
896
-	echo $sql;
897
-	$result = Database::query($sql);
898
-	while ($row = Database::fetch_array($result))
899
-	{
900
-		echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
901
-	}
894
+    $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
895
+    $sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC";
896
+    echo $sql;
897
+    $result = Database::query($sql);
898
+    while ($row = Database::fetch_array($result))
899
+    {
900
+        echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
901
+    }
902 902
 ?>
903 903
 
904 904
       </select><?php } ?></td>
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
 */
928 928
 if ($content == "Assignment")
929 929
 {
930
-	echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>";
930
+    echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>";
931 931
 }
932 932
 
933 933
 /*
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
 */
938 938
 if ($content == "Dropbox")
939 939
 {
940
-	echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>";
940
+    echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>";
941 941
 }
942 942
 
943 943
 /*
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 */
948 948
 if ($content == "Introduction_text")
949 949
 {
950
-	echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>";
950
+    echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>";
951 951
 }
952 952
 
953 953
 /*
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 */
958 958
 if ($content == "Course_description")
959 959
 {
960
-	echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>";
960
+    echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>";
961 961
 }
962 962
 
963 963
 /*
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
 */
968 968
 if ($content == "Groups")
969 969
 {
970
-	echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>";
970
+    echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>";
971 971
 }
972 972
 
973 973
 /*
@@ -977,13 +977,13 @@  discard block
 block discarded – undo
977 977
 */
978 978
 if ($content == "Users")
979 979
 {
980
-	echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>";
980
+    echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>";
981 981
 }
982 982
 
983 983
 if ($showresources)
984 984
 {
985
-	//echo "<h4>".get_lang('ResourceAdded')."</h4>";
986
-	display_resources(1);
985
+    //echo "<h4>".get_lang('ResourceAdded')."</h4>";
986
+    display_resources(1);
987 987
 }
988 988
 
989 989
 echo "</td></tr></table>";
Please login to merge, or discard this patch.
main/webservices/cm_webservice_course.php 1 patch
Indentation   +511 added lines, -511 removed lines patch added patch discarded remove patch
@@ -10,521 +10,521 @@
 block discarded – undo
10 10
  */
11 11
 class WSCMCourse extends WSCM
12 12
 {
13
-	/**
14
-	 * Deletes a course (helper method)
15
-	 *
16
-	 * @param string Course id field name
17
-	 * @param string Course id value
18
-	 * @return mixed True if the course was successfully deleted, WSError otherwise
19
-	 */
20
-	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
21
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
22
-		if($course_id instanceof WSCMError) {
23
-			return $course_id;
24
-		} else {
25
-			$course_code = CourseManager::get_course_code_from_course_id($course_id);
26
-			CourseManager::delete_course($course_code);
27
-			return true;
28
-		}
29
-	}
30
-
31
-	/**
32
-	 * Deletes a course
33
-	 *
34
-	 * @param string API secret key
35
-	 * @param string Course id field name
36
-	 * @param string Course id value
37
-	 */
38
-	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
39
-		$verifKey = $this->verifyKey($secret_key);
40
-		if($verifKey instanceof WSError) {
41
-			$this->handleError($verifKey);
42
-		} else {
43
-			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
44
-			if($result instanceof WSError) {
45
-				$this->handleError($result);
46
-			}
47
-		}
48
-	}
49
-
50
-	/**
51
-	 * Deletes multiple courses
52
-	 *
53
-	 * @param string API secret key
54
-	 * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
55
-	 * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
56
-	 * than 0, an error occured
57
-	 */
58
-	public function DeleteCourses($secret_key, $courses) {
59
-		$verifKey = $this->verifyKey($secret_key);
60
-		if($verifKey instanceof WSError) {
61
-			$this->handleError($verifKey);
62
-		} else {
63
-			$results = array();
64
-			foreach($courses as $course) {
65
-				$result_tmp = array();
66
-				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
67
-				$result_tmp['course_id_value'] = $course['course_id_value'];
68
-				if($result_op instanceof WSCMError) {
69
-					// Return the error in the results
70
-					$result_tmp['result'] = $result_op->toArray();
71
-				} else {
72
-					$result_tmp['result'] = $this->getSuccessfulResult();
73
-				}
74
-				$results[] = $result_tmp;
75
-			}
76
-			return $results;
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * Creates a course (helper method)
82
-	 *
83
-	 * @param string Title
84
-	 * @param string Category code
85
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
86
-	 * @param string Tutor name
87
-	 * @param string Course admin user id field name
88
-	 * @param string Course admin user id value
89
-	 * @param string Course language
90
-	 * @param string Course id field name
91
-	 * @param string Course id value
92
-	 * @param array Course extra fields
93
-	 * @return mixed Generated id if creation was successful, WSError otherwise
94
-	 */
95
-	protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
96
-		// Add the original course id field name and value to the extra fields if needed
97
-		$extras_associative = array();
98
-		if($course_id_field_name != "chamilo_course_id") {
99
-			$extras_associative[$course_id_field_name] = $course_id_value;
100
-		}
101
-		foreach($extras as $extra) {
102
-			$extras_associative[$extra['field_name']] = $extra['field_value'];
103
-		}
104
-		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
105
-		if($course_admin_id instanceof WSError) {
106
-			return $course_admin_id;
107
-		}
108
-		if($wanted_code == '') {
109
-			$wanted_code = CourseManager::generate_course_code($title);
110
-		}
111
-		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
112
-		if (!$result) {
113
-			return new WSError(202, 'There was an error creating the course');
114
-		} else {
115
-			// Update extra fields
116
-			foreach($extras_associative as $fname => $fvalue) {
117
-				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
118
-			}
119
-			// Get course id
120
-			$course_info = CourseManager::get_course_information($result);
121
-			return $course_info['real_id'];
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * Creates a course
127
-	 *
128
-	 * @param string API secret key
129
-	 * @param string Title
130
-	 * @param string Category code
131
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
132
-	 * @param string Tutor name
133
-	 * @param string Course admin user id field name
134
-	 * @param string Course admin user id value
135
-	 * @param string Course language
136
-	 * @param string Course id field name
137
-	 * @param string Course id value
138
-	 * @param array Course extra fields
139
-	 * @return int Course id generated
140
-	 */
141
-	public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
142
-		// First, verify the secret key
143
-		$verifKey = $this->verifyKey($secret_key);
144
-		if($verifKey instanceof WSError) {
145
-			$this->handleError($verifKey);
146
-		} else {
147
-			$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
148
-			if($result instanceof WSError) {
149
-				$this->handleError($result);
150
-			} else {
151
-				return $result;
152
-			}
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Create multiple courses
158
-	 *
159
-	 * @param string API secret key
160
-	 * @param array Courses to be created, with elements following the structure presented in CreateCourse
161
-	 * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
162
-	 */
163
-	public function CreateCourses($secret_key, $courses) {
164
-		// First, verify the secret key
165
-		$verifKey = $this->verifyKey($secret_key);
166
-		if($verifKey instanceof WSCMError) {
167
-			$this->handleError($verifKey);
168
-		} else {
169
-			$results = array();
170
-			foreach($courses as $course) {
171
-				$result_tmp = array();
172
-				//reinitialize variables just in case
173
-				$title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
174
-				extract($course);
175
-				$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
176
-				if($result instanceof WSCMError) {
177
-					$result_tmp['result'] = $result->toArray();
178
-					$result_tmp['course_id_value'] = $course_id_value;
179
-					$result_tmp['course_id_generated'] = 0;
180
-				} else {
181
-					$result_tmp['result'] = $this->getSuccessfulResult();
182
-					$result_tmp['course_id_value'] = $course_id_value;
183
-					$result_tmp['course_id_generated'] = $result;
184
-				}
185
-				$results[] = $result_tmp;
186
-			}
187
-			return $results;
188
-		}
189
-	}
190
-
191
-	/**
192
-	 * Edits a course (helper method)
193
-	 *
194
-	 * @param string Course id field name
195
-	 * @param string Course id value
196
-	 * @param string Title
197
-	 * @param string Category code
198
-	 * @param string Department name
199
-	 * @param string Department url
200
-	 * @param string Course language
201
-	 * @param int Visibility
202
-	 * @param int Subscribe (0 = denied, 1 = allowed)
203
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
204
-	 * @param string Visual code
205
-	 * @param array Course extra fields
206
-	 * @return mixed True in case of success, WSError otherwise
207
-	 */
208
-	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
209
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
210
-		if($course_id instanceof WSCMError) {
211
-			return $course_id;
212
-		} else {
213
-			$attributes = array();
214
-			if(!empty($title)) {
215
-				$attributes['title'] = $title;
216
-			}
217
-			if(!empty($category_code)) {
218
-				$attributes['category_code'] = $category_code;
219
-			}
220
-			if(!empty($department_name)) {
221
-				$attributes['department_name'] = $department_name;
222
-			}
223
-			if(!empty($department_url)) {
224
-				$attributes['department_url'] = $department_url;
225
-			}
226
-			if(!empty($language)) {
227
-				$attributes['course_language'] = $language;
228
-			}
229
-			if($visibility != '') {
230
-				$attributes['visibility'] = (int)$visibility;
231
-			}
232
-			if($subscribe != '') {
233
-				$attributes['subscribe'] = (int)$subscribe;
234
-			}
235
-			if($unsubscribe != '') {
236
-				$attributes['unsubscribe'] = (int)$unsubscribe;
237
-			}
238
-			if(!empty($visual_code)) {
239
-				$attributes['visual_code'] = $visual_code;
240
-			}
241
-			if(!empty($attributes)) {
242
-				CourseManager::update_attributes($course_id, $attributes);
243
-			}
244
-			if(!empty($extras)) {
245
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
246
-				$extras_associative = array();
247
-				foreach($extras as $extra) {
248
-					$extras_associative[$extra['field_name']] = $extra['field_value'];
249
-				}
250
-				foreach($extras_associative as $fname => $fvalue) {
251
-					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
252
-				}
253
-			}
254
-			return true;
255
-		}
256
-	}
257
-
258
-	/**
259
-	 * Edits a course
260
-	 *
261
-	 * @param string API secret key
262
-	 * @param string Course id field name
263
-	 * @param string Course id value
264
-	 * @param string Title
265
-	 * @param string Category code
266
-	 * @param string Department name
267
-	 * @param string Department url
268
-	 * @param string Course language
269
-	 * @param int Visibility
270
-	 * @param int Subscribe (0 = denied, 1 = allowed)
271
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
272
-	 * @param string Visual code
273
-	 * @param array Course extra fields
274
-	 */
275
-	public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
276
-		$verifKey = $this->verifyKey($secret_key);
277
-		if($verifKey instanceof WSCMError) {
278
-			$this->handleError($verifKey);
279
-		} else {
280
-			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
281
-			if($result instanceof WSCMError) {
282
-				$this->handleError($result);
283
-			}
284
-		}
285
-	}
286
-
287
-	/**
288
-	 * List courses
289
-	 *
290
-	 * @param string API secret key
291
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
292
-	 * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
293
-	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
294
-	 */
295
-	public function ListCourses($secret_key, $course_id_field_name) {
296
-		$verifKey = $this->verifyKey($secret_key);
297
-		if($verifKey instanceof WSError) {
298
-			$this->handleError($verifKey);
299
-		} else {
300
-			$courses_result = array();
301
-			$category_names = array();
302
-
303
-			$courses = CourseManager::get_courses_list();
304
-			foreach($courses as $course) {
305
-				$course_tmp = array();
306
-				$course_tmp['id'] = $course['id'];
307
-				$course_tmp['code'] = $course['code'];
308
-				$course_tmp['title'] = $course['title'];
309
-				$course_tmp['language'] = $course['course_language'];
310
-				$course_tmp['visibility'] = $course['visibility'];
311
-
312
-				// Determining category name
313
-				if($category_names[$course['category_code']]) {
314
-					$course_tmp['category_name'] = $category_names[$course['category_code']];
315
-				} else {
316
-					$category = CourseManager::get_course_category($course['category_code']);
317
-					$category_names[$course['category_code']] = $category['name'];
318
-					$course_tmp['category_name'] = $category['name'];
319
-				}
320
-
321
-				// Determining number of students registered in course
322
-				$user_list = CourseManager::get_user_list_from_course_code($course['code']);
323
-				$course_tmp['number_students'] = count($user_list);
324
-
325
-				// Determining external course id
326
-				$course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']);
327
-
328
-
329
-				$courses_result[] = $course_tmp;
330
-			}
331
-
332
-			return $courses_result;
333
-		}
334
-	}
335
-
336
-	/**
337
-	 * Subscribe or unsubscribe user to a course (helper method)
338
-	 *
339
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
340
-	 * @param string Course id value.
341
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
342
-	 * @param string User id value
343
-	 * @param int Set to 1 to subscribe, 0 to unsubscribe
344
-	 * @param int Status (STUDENT or TEACHER) Used for subscription only
345
-	 * @return mixed True if subscription or unsubscription was successful, false otherwise
346
-	 */
347
-	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
348
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
349
-		if($course_id instanceof WSError) {
350
-			return $course_id;
351
-		} else {
352
-			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
353
-			if($user_id instanceof WSError) {
354
-				return $user_id;
355
-			} else {
356
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
357
-				if($state == 0) {
358
-					// Unsubscribe user
359
-					CourseManager::unsubscribe_user($user_id, $course_code);
360
-					return true;
361
-				} else {
362
-					// Subscribe user
363
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
364
-						return true;
365
-					} else {
366
-						return new WSError(203, 'An error occured subscribing to this course');
367
-					}
368
-				}
369
-			}
370
-		}
371
-	}
372
-
373
-	/**
374
-	 * Subscribe user to a course
375
-	 *
376
-	 * @param string API secret key
377
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
378
-	 * @param string Course id value.
379
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
380
-	 * @param string User id value
381
-	 * @param int Status (1 = Teacher, 5 = Student)
382
-	 */
383
-	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
384
-		$verifKey = $this->verifyKey($secret_key);
385
-		if($verifKey instanceof WSError) {
386
-			$this->handleError($verifKey);
387
-		} else {
388
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
389
-			if($result instanceof WSError) {
390
-				$this->handleError($result);
391
-			}
392
-		}
393
-	}
394
-
395
-	/**
396
-	 * Unsusbscribe user from course
397
-	 *
398
-	 * @param string API secret key
399
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
400
-	 * @param string Course id value.
401
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
402
-	 * @param string User id value
403
-	 */
404
-	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
405
-		$verifKey = $this->verifyKey($secret_key);
406
-		if($verifKey instanceof WSError) {
407
-			$this->handleError($verifKey);
408
-		} else {
409
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
410
-			if($result instanceof WSError) {
411
-				$this->handleError($result);
412
-			}
413
-		}
414
-	}
415
-
416
-	/**
417
-	 * Returns the descriptions of a course, along with their id
418
-	 *
419
-	 * @param string API secret key
420
-	 * @param string Course id field name
421
-	 * @param string Course id value
422
-	 * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
423
-	 */
424
-	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
425
-		$verifKey = $this->verifyKey($secret_key);
426
-		if($verifKey instanceof WSError) {
427
-			$this->handleError($verifKey);
428
-		} else {
429
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
430
-			if($course_id instanceof WSError) {
431
-				return $course_id;
432
-			} else {
433
-				// Course exists, get its descriptions
434
-				$descriptions = CourseDescription::get_descriptions($course_id);
435
-				$results = array();
436
-				foreach($descriptions as $description) {
437
-					$results[] = array('course_desc_id' => $description->get_description_type(),
438
-						'course_desc_title' => $description->get_title(),
439
-						'course_desc_content' => $description->get_content());
440
-				}
441
-				return $results;
442
-			}
443
-		}
444
-	}
445
-
446
-
447
-	/**
448
-	 * Edit course description
449
-	 *
450
-	 * @param string API secret key
451
-	 * @param string Course id field name
452
-	 * @param string Course id value
453
-	 * @param int Category id from course description
454
-	 * @param string Description title
455
-	 * @param string Course description content
456
-	 */
457
-	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
458
-		$verifKey = $this->verifyKey($secret_key);
459
-		if($verifKey instanceof WSError) {
460
-			$this->handleError($verifKey);
461
-		} else {
462
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
463
-			if($course_id instanceof WSError) {
464
-				return $course_id;
465
-			} else {
466
-				// Create the new course description
467
-				$cd = new CourseDescription();
468
-				$cd->set_description_type($course_desc_id);
469
-				$cd->set_title($course_desc_title);
470
-				$cd->set_content($course_desc_content);
471
-				$cd->set_session_id(0);
472
-
473
-				// Get course info
13
+    /**
14
+     * Deletes a course (helper method)
15
+     *
16
+     * @param string Course id field name
17
+     * @param string Course id value
18
+     * @return mixed True if the course was successfully deleted, WSError otherwise
19
+     */
20
+    protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
21
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
22
+        if($course_id instanceof WSCMError) {
23
+            return $course_id;
24
+        } else {
25
+            $course_code = CourseManager::get_course_code_from_course_id($course_id);
26
+            CourseManager::delete_course($course_code);
27
+            return true;
28
+        }
29
+    }
30
+
31
+    /**
32
+     * Deletes a course
33
+     *
34
+     * @param string API secret key
35
+     * @param string Course id field name
36
+     * @param string Course id value
37
+     */
38
+    public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
39
+        $verifKey = $this->verifyKey($secret_key);
40
+        if($verifKey instanceof WSError) {
41
+            $this->handleError($verifKey);
42
+        } else {
43
+            $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
44
+            if($result instanceof WSError) {
45
+                $this->handleError($result);
46
+            }
47
+        }
48
+    }
49
+
50
+    /**
51
+     * Deletes multiple courses
52
+     *
53
+     * @param string API secret key
54
+     * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
55
+     * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
56
+     * than 0, an error occured
57
+     */
58
+    public function DeleteCourses($secret_key, $courses) {
59
+        $verifKey = $this->verifyKey($secret_key);
60
+        if($verifKey instanceof WSError) {
61
+            $this->handleError($verifKey);
62
+        } else {
63
+            $results = array();
64
+            foreach($courses as $course) {
65
+                $result_tmp = array();
66
+                $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
67
+                $result_tmp['course_id_value'] = $course['course_id_value'];
68
+                if($result_op instanceof WSCMError) {
69
+                    // Return the error in the results
70
+                    $result_tmp['result'] = $result_op->toArray();
71
+                } else {
72
+                    $result_tmp['result'] = $this->getSuccessfulResult();
73
+                }
74
+                $results[] = $result_tmp;
75
+            }
76
+            return $results;
77
+        }
78
+    }
79
+
80
+    /**
81
+     * Creates a course (helper method)
82
+     *
83
+     * @param string Title
84
+     * @param string Category code
85
+     * @param string Wanted code. If it's not defined, it will be generated automatically
86
+     * @param string Tutor name
87
+     * @param string Course admin user id field name
88
+     * @param string Course admin user id value
89
+     * @param string Course language
90
+     * @param string Course id field name
91
+     * @param string Course id value
92
+     * @param array Course extra fields
93
+     * @return mixed Generated id if creation was successful, WSError otherwise
94
+     */
95
+    protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
96
+        // Add the original course id field name and value to the extra fields if needed
97
+        $extras_associative = array();
98
+        if($course_id_field_name != "chamilo_course_id") {
99
+            $extras_associative[$course_id_field_name] = $course_id_value;
100
+        }
101
+        foreach($extras as $extra) {
102
+            $extras_associative[$extra['field_name']] = $extra['field_value'];
103
+        }
104
+        $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
105
+        if($course_admin_id instanceof WSError) {
106
+            return $course_admin_id;
107
+        }
108
+        if($wanted_code == '') {
109
+            $wanted_code = CourseManager::generate_course_code($title);
110
+        }
111
+        $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
112
+        if (!$result) {
113
+            return new WSError(202, 'There was an error creating the course');
114
+        } else {
115
+            // Update extra fields
116
+            foreach($extras_associative as $fname => $fvalue) {
117
+                CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
118
+            }
119
+            // Get course id
120
+            $course_info = CourseManager::get_course_information($result);
121
+            return $course_info['real_id'];
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Creates a course
127
+     *
128
+     * @param string API secret key
129
+     * @param string Title
130
+     * @param string Category code
131
+     * @param string Wanted code. If it's not defined, it will be generated automatically
132
+     * @param string Tutor name
133
+     * @param string Course admin user id field name
134
+     * @param string Course admin user id value
135
+     * @param string Course language
136
+     * @param string Course id field name
137
+     * @param string Course id value
138
+     * @param array Course extra fields
139
+     * @return int Course id generated
140
+     */
141
+    public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
142
+        // First, verify the secret key
143
+        $verifKey = $this->verifyKey($secret_key);
144
+        if($verifKey instanceof WSError) {
145
+            $this->handleError($verifKey);
146
+        } else {
147
+            $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
148
+            if($result instanceof WSError) {
149
+                $this->handleError($result);
150
+            } else {
151
+                return $result;
152
+            }
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Create multiple courses
158
+     *
159
+     * @param string API secret key
160
+     * @param array Courses to be created, with elements following the structure presented in CreateCourse
161
+     * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
162
+     */
163
+    public function CreateCourses($secret_key, $courses) {
164
+        // First, verify the secret key
165
+        $verifKey = $this->verifyKey($secret_key);
166
+        if($verifKey instanceof WSCMError) {
167
+            $this->handleError($verifKey);
168
+        } else {
169
+            $results = array();
170
+            foreach($courses as $course) {
171
+                $result_tmp = array();
172
+                //reinitialize variables just in case
173
+                $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
174
+                extract($course);
175
+                $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
176
+                if($result instanceof WSCMError) {
177
+                    $result_tmp['result'] = $result->toArray();
178
+                    $result_tmp['course_id_value'] = $course_id_value;
179
+                    $result_tmp['course_id_generated'] = 0;
180
+                } else {
181
+                    $result_tmp['result'] = $this->getSuccessfulResult();
182
+                    $result_tmp['course_id_value'] = $course_id_value;
183
+                    $result_tmp['course_id_generated'] = $result;
184
+                }
185
+                $results[] = $result_tmp;
186
+            }
187
+            return $results;
188
+        }
189
+    }
190
+
191
+    /**
192
+     * Edits a course (helper method)
193
+     *
194
+     * @param string Course id field name
195
+     * @param string Course id value
196
+     * @param string Title
197
+     * @param string Category code
198
+     * @param string Department name
199
+     * @param string Department url
200
+     * @param string Course language
201
+     * @param int Visibility
202
+     * @param int Subscribe (0 = denied, 1 = allowed)
203
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
204
+     * @param string Visual code
205
+     * @param array Course extra fields
206
+     * @return mixed True in case of success, WSError otherwise
207
+     */
208
+    protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
209
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
210
+        if($course_id instanceof WSCMError) {
211
+            return $course_id;
212
+        } else {
213
+            $attributes = array();
214
+            if(!empty($title)) {
215
+                $attributes['title'] = $title;
216
+            }
217
+            if(!empty($category_code)) {
218
+                $attributes['category_code'] = $category_code;
219
+            }
220
+            if(!empty($department_name)) {
221
+                $attributes['department_name'] = $department_name;
222
+            }
223
+            if(!empty($department_url)) {
224
+                $attributes['department_url'] = $department_url;
225
+            }
226
+            if(!empty($language)) {
227
+                $attributes['course_language'] = $language;
228
+            }
229
+            if($visibility != '') {
230
+                $attributes['visibility'] = (int)$visibility;
231
+            }
232
+            if($subscribe != '') {
233
+                $attributes['subscribe'] = (int)$subscribe;
234
+            }
235
+            if($unsubscribe != '') {
236
+                $attributes['unsubscribe'] = (int)$unsubscribe;
237
+            }
238
+            if(!empty($visual_code)) {
239
+                $attributes['visual_code'] = $visual_code;
240
+            }
241
+            if(!empty($attributes)) {
242
+                CourseManager::update_attributes($course_id, $attributes);
243
+            }
244
+            if(!empty($extras)) {
245
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
246
+                $extras_associative = array();
247
+                foreach($extras as $extra) {
248
+                    $extras_associative[$extra['field_name']] = $extra['field_value'];
249
+                }
250
+                foreach($extras_associative as $fname => $fvalue) {
251
+                    CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
252
+                }
253
+            }
254
+            return true;
255
+        }
256
+    }
257
+
258
+    /**
259
+     * Edits a course
260
+     *
261
+     * @param string API secret key
262
+     * @param string Course id field name
263
+     * @param string Course id value
264
+     * @param string Title
265
+     * @param string Category code
266
+     * @param string Department name
267
+     * @param string Department url
268
+     * @param string Course language
269
+     * @param int Visibility
270
+     * @param int Subscribe (0 = denied, 1 = allowed)
271
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
272
+     * @param string Visual code
273
+     * @param array Course extra fields
274
+     */
275
+    public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
276
+        $verifKey = $this->verifyKey($secret_key);
277
+        if($verifKey instanceof WSCMError) {
278
+            $this->handleError($verifKey);
279
+        } else {
280
+            $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
281
+            if($result instanceof WSCMError) {
282
+                $this->handleError($result);
283
+            }
284
+        }
285
+    }
286
+
287
+    /**
288
+     * List courses
289
+     *
290
+     * @param string API secret key
291
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
292
+     * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
293
+     * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
294
+     */
295
+    public function ListCourses($secret_key, $course_id_field_name) {
296
+        $verifKey = $this->verifyKey($secret_key);
297
+        if($verifKey instanceof WSError) {
298
+            $this->handleError($verifKey);
299
+        } else {
300
+            $courses_result = array();
301
+            $category_names = array();
302
+
303
+            $courses = CourseManager::get_courses_list();
304
+            foreach($courses as $course) {
305
+                $course_tmp = array();
306
+                $course_tmp['id'] = $course['id'];
307
+                $course_tmp['code'] = $course['code'];
308
+                $course_tmp['title'] = $course['title'];
309
+                $course_tmp['language'] = $course['course_language'];
310
+                $course_tmp['visibility'] = $course['visibility'];
311
+
312
+                // Determining category name
313
+                if($category_names[$course['category_code']]) {
314
+                    $course_tmp['category_name'] = $category_names[$course['category_code']];
315
+                } else {
316
+                    $category = CourseManager::get_course_category($course['category_code']);
317
+                    $category_names[$course['category_code']] = $category['name'];
318
+                    $course_tmp['category_name'] = $category['name'];
319
+                }
320
+
321
+                // Determining number of students registered in course
322
+                $user_list = CourseManager::get_user_list_from_course_code($course['code']);
323
+                $course_tmp['number_students'] = count($user_list);
324
+
325
+                // Determining external course id
326
+                $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']);
327
+
328
+
329
+                $courses_result[] = $course_tmp;
330
+            }
331
+
332
+            return $courses_result;
333
+        }
334
+    }
335
+
336
+    /**
337
+     * Subscribe or unsubscribe user to a course (helper method)
338
+     *
339
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
340
+     * @param string Course id value.
341
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
342
+     * @param string User id value
343
+     * @param int Set to 1 to subscribe, 0 to unsubscribe
344
+     * @param int Status (STUDENT or TEACHER) Used for subscription only
345
+     * @return mixed True if subscription or unsubscription was successful, false otherwise
346
+     */
347
+    protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
348
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
349
+        if($course_id instanceof WSError) {
350
+            return $course_id;
351
+        } else {
352
+            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
353
+            if($user_id instanceof WSError) {
354
+                return $user_id;
355
+            } else {
356
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
357
+                if($state == 0) {
358
+                    // Unsubscribe user
359
+                    CourseManager::unsubscribe_user($user_id, $course_code);
360
+                    return true;
361
+                } else {
362
+                    // Subscribe user
363
+                    if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
364
+                        return true;
365
+                    } else {
366
+                        return new WSError(203, 'An error occured subscribing to this course');
367
+                    }
368
+                }
369
+            }
370
+        }
371
+    }
372
+
373
+    /**
374
+     * Subscribe user to a course
375
+     *
376
+     * @param string API secret key
377
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
378
+     * @param string Course id value.
379
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
380
+     * @param string User id value
381
+     * @param int Status (1 = Teacher, 5 = Student)
382
+     */
383
+    public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
384
+        $verifKey = $this->verifyKey($secret_key);
385
+        if($verifKey instanceof WSError) {
386
+            $this->handleError($verifKey);
387
+        } else {
388
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
389
+            if($result instanceof WSError) {
390
+                $this->handleError($result);
391
+            }
392
+        }
393
+    }
394
+
395
+    /**
396
+     * Unsusbscribe user from course
397
+     *
398
+     * @param string API secret key
399
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
400
+     * @param string Course id value.
401
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
402
+     * @param string User id value
403
+     */
404
+    public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
405
+        $verifKey = $this->verifyKey($secret_key);
406
+        if($verifKey instanceof WSError) {
407
+            $this->handleError($verifKey);
408
+        } else {
409
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
410
+            if($result instanceof WSError) {
411
+                $this->handleError($result);
412
+            }
413
+        }
414
+    }
415
+
416
+    /**
417
+     * Returns the descriptions of a course, along with their id
418
+     *
419
+     * @param string API secret key
420
+     * @param string Course id field name
421
+     * @param string Course id value
422
+     * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
423
+     */
424
+    public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
425
+        $verifKey = $this->verifyKey($secret_key);
426
+        if($verifKey instanceof WSError) {
427
+            $this->handleError($verifKey);
428
+        } else {
429
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
430
+            if($course_id instanceof WSError) {
431
+                return $course_id;
432
+            } else {
433
+                // Course exists, get its descriptions
434
+                $descriptions = CourseDescription::get_descriptions($course_id);
435
+                $results = array();
436
+                foreach($descriptions as $description) {
437
+                    $results[] = array('course_desc_id' => $description->get_description_type(),
438
+                        'course_desc_title' => $description->get_title(),
439
+                        'course_desc_content' => $description->get_content());
440
+                }
441
+                return $results;
442
+            }
443
+        }
444
+    }
445
+
446
+
447
+    /**
448
+     * Edit course description
449
+     *
450
+     * @param string API secret key
451
+     * @param string Course id field name
452
+     * @param string Course id value
453
+     * @param int Category id from course description
454
+     * @param string Description title
455
+     * @param string Course description content
456
+     */
457
+    public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
458
+        $verifKey = $this->verifyKey($secret_key);
459
+        if($verifKey instanceof WSError) {
460
+            $this->handleError($verifKey);
461
+        } else {
462
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
463
+            if($course_id instanceof WSError) {
464
+                return $course_id;
465
+            } else {
466
+                // Create the new course description
467
+                $cd = new CourseDescription();
468
+                $cd->set_description_type($course_desc_id);
469
+                $cd->set_title($course_desc_title);
470
+                $cd->set_content($course_desc_content);
471
+                $cd->set_session_id(0);
472
+
473
+                // Get course info
474 474
                 $course_info = CourseManager::get_course_information(
475 475
                     CourseManager::get_course_code_from_course_id($course_id)
476 476
                 );
477
-				// Check if this course description exists
478
-				$descriptions = CourseDescription::get_descriptions($course_id);
479
-				$exists = false;
480
-				foreach($descriptions as $description) {
481
-					if($description->get_description_type() == $course_desc_id) {
482
-						$exists = true;
483
-					}
484
-				}
477
+                // Check if this course description exists
478
+                $descriptions = CourseDescription::get_descriptions($course_id);
479
+                $exists = false;
480
+                foreach($descriptions as $description) {
481
+                    if($description->get_description_type() == $course_desc_id) {
482
+                        $exists = true;
483
+                    }
484
+                }
485 485
                 $cd->set_course_id($course_info['real_id']);
486
-				if (!$exists) {
487
-					$cd->set_progress(0);
488
-					$cd->insert();
489
-				} else {
490
-					$cd->update();
491
-				}
492
-			}
493
-		}
494
-	}
495
-	public function unreadMessage($username, $password)
496
-	{
497
-		if($this->verifyUserPass($username, $password) == "valid")
498
-		{
499
-			$table_message = Database::get_main_table(TABLE_MESSAGE);
500
-			$user_id = UserManager::get_user_id_from_username($username);
501
-			$condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
502
-
503
-			$sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
504
-
505
-			$sql_result = Database::query($sql_query);
506
-			$result = Database::fetch_array($sql_result);
507
-			return $result['number_messages'];
508
-		}
509
-		return "0";
510
-	}
511
-
512
-	public function get_message_data($username, $password)
513
-	{
514
-		if($this->verifyUserPass($username, $password) == "valid")
515
-		{
516
-			$user_id = get_user_id_from_username($username);
517
-
518
-		}
519
-
520
-	}
521
-
522
-	public function nada($username, $password)
523
-	{
524
-		if($this->verifyUserPass($username, $password) == "valid")
525
-			return $username.$password;
526
-		return $username;
527
-	}
486
+                if (!$exists) {
487
+                    $cd->set_progress(0);
488
+                    $cd->insert();
489
+                } else {
490
+                    $cd->update();
491
+                }
492
+            }
493
+        }
494
+    }
495
+    public function unreadMessage($username, $password)
496
+    {
497
+        if($this->verifyUserPass($username, $password) == "valid")
498
+        {
499
+            $table_message = Database::get_main_table(TABLE_MESSAGE);
500
+            $user_id = UserManager::get_user_id_from_username($username);
501
+            $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
502
+
503
+            $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
504
+
505
+            $sql_result = Database::query($sql_query);
506
+            $result = Database::fetch_array($sql_result);
507
+            return $result['number_messages'];
508
+        }
509
+        return "0";
510
+    }
511
+
512
+    public function get_message_data($username, $password)
513
+    {
514
+        if($this->verifyUserPass($username, $password) == "valid")
515
+        {
516
+            $user_id = get_user_id_from_username($username);
517
+
518
+        }
519
+
520
+    }
521
+
522
+    public function nada($username, $password)
523
+    {
524
+        if($this->verifyUserPass($username, $password) == "valid")
525
+            return $username.$password;
526
+        return $username;
527
+    }
528 528
 
529 529
 
530 530
 
Please login to merge, or discard this patch.
main/webservices/webservice_course.php 1 patch
Indentation   +455 added lines, -455 removed lines patch added patch discarded remove patch
@@ -12,490 +12,490 @@
 block discarded – undo
12 12
  */
13 13
 class WSCourse extends WS
14 14
 {
15
-	/**
16
-	 * Deletes a course (helper method)
17
-	 *
18
-	 * @param string Course id field name
19
-	 * @param string Course id value
20
-	 * @return mixed True if the course was successfully deleted, WSError otherwise
21
-	 */
22
-	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
23
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
24
-		if($course_id instanceof WSError) {
25
-			return $course_id;
26
-		} else {
27
-			$course_code = CourseManager::get_course_code_from_course_id($course_id);
28
-			CourseManager::delete_course($course_code);
29
-			return true;
30
-		}
31
-	}
15
+    /**
16
+     * Deletes a course (helper method)
17
+     *
18
+     * @param string Course id field name
19
+     * @param string Course id value
20
+     * @return mixed True if the course was successfully deleted, WSError otherwise
21
+     */
22
+    protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
23
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
24
+        if($course_id instanceof WSError) {
25
+            return $course_id;
26
+        } else {
27
+            $course_code = CourseManager::get_course_code_from_course_id($course_id);
28
+            CourseManager::delete_course($course_code);
29
+            return true;
30
+        }
31
+    }
32 32
 
33
-	/**
34
-	 * Deletes a course
35
-	 *
36
-	 * @param string API secret key
37
-	 * @param string Course id field name
38
-	 * @param string Course id value
39
-	 */
40
-	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
41
-		$verifKey = $this->verifyKey($secret_key);
42
-		if($verifKey instanceof WSError) {
43
-			$this->handleError($verifKey);
44
-		} else {
45
-			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
46
-			if($result instanceof WSError) {
47
-				$this->handleError($result);
48
-			}
49
-		}
50
-	}
33
+    /**
34
+     * Deletes a course
35
+     *
36
+     * @param string API secret key
37
+     * @param string Course id field name
38
+     * @param string Course id value
39
+     */
40
+    public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
41
+        $verifKey = $this->verifyKey($secret_key);
42
+        if($verifKey instanceof WSError) {
43
+            $this->handleError($verifKey);
44
+        } else {
45
+            $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
46
+            if($result instanceof WSError) {
47
+                $this->handleError($result);
48
+            }
49
+        }
50
+    }
51 51
 
52
-	/**
53
-	 * Deletes multiple courses
54
-	 *
55
-	 * @param string API secret key
56
-	 * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
57
-	 * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
58
-	 * than 0, an error occured
59
-	 */
60
-	public function DeleteCourses($secret_key, $courses) {
61
-		$verifKey = $this->verifyKey($secret_key);
62
-		if($verifKey instanceof WSError) {
63
-			$this->handleError($verifKey);
64
-		} else {
65
-			$results = array();
66
-			foreach($courses as $course) {
67
-				$result_tmp = array();
68
-				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
69
-				$result_tmp['course_id_value'] = $course['course_id_value'];
70
-				if($result_op instanceof WSError) {
71
-					// Return the error in the results
72
-					$result_tmp['result'] = $result_op->toArray();
73
-				} else {
74
-					$result_tmp['result'] = $this->getSuccessfulResult();
75
-				}
76
-				$results[] = $result_tmp;
77
-			}
78
-			return $results;
79
-		}
80
-	}
52
+    /**
53
+     * Deletes multiple courses
54
+     *
55
+     * @param string API secret key
56
+     * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
57
+     * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
58
+     * than 0, an error occured
59
+     */
60
+    public function DeleteCourses($secret_key, $courses) {
61
+        $verifKey = $this->verifyKey($secret_key);
62
+        if($verifKey instanceof WSError) {
63
+            $this->handleError($verifKey);
64
+        } else {
65
+            $results = array();
66
+            foreach($courses as $course) {
67
+                $result_tmp = array();
68
+                $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
69
+                $result_tmp['course_id_value'] = $course['course_id_value'];
70
+                if($result_op instanceof WSError) {
71
+                    // Return the error in the results
72
+                    $result_tmp['result'] = $result_op->toArray();
73
+                } else {
74
+                    $result_tmp['result'] = $this->getSuccessfulResult();
75
+                }
76
+                $results[] = $result_tmp;
77
+            }
78
+            return $results;
79
+        }
80
+    }
81 81
 
82
-	/**
83
-	 * Creates a course (helper method)
84
-	 *
85
-	 * @param string Title
86
-	 * @param string Category code
87
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
88
-	 * @param string Tutor name
89
-	 * @param string Course admin user id field name
90
-	 * @param string Course admin user id value
91
-	 * @param string Course language
92
-	 * @param string Course id field name
93
-	 * @param string Course id value
94
-	 * @param array Course extra fields
95
-	 * @return mixed Generated id if creation was successful, WSError otherwise
96
-	 */
97
-	protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
98
-		// Add the original course id field name and value to the extra fields if needed
99
-		$extras_associative = array();
100
-		if($course_id_field_name != "chamilo_course_id") {
101
-			$extras_associative[$course_id_field_name] = $course_id_value;
102
-		}
103
-		foreach($extras as $extra) {
104
-			$extras_associative[$extra['field_name']] = $extra['field_value'];
105
-		}
106
-		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
107
-		if($course_admin_id instanceof WSError) {
108
-			return $course_admin_id;
109
-		}
110
-		if($wanted_code == '') {
111
-			$wanted_code = CourseManager::generate_course_code($title);
112
-		}
113
-		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
114
-		if (!$result) {
115
-			return new WSError(202, 'There was an error creating the course');
116
-		} else {
117
-			// Update extra fields
118
-			foreach($extras_associative as $fname => $fvalue) {
119
-				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
120
-			}
121
-			// Get course id
122
-			$course_info = CourseManager::get_course_information($result);
123
-			return $course_info['real_id'];
124
-		}
125
-	}
82
+    /**
83
+     * Creates a course (helper method)
84
+     *
85
+     * @param string Title
86
+     * @param string Category code
87
+     * @param string Wanted code. If it's not defined, it will be generated automatically
88
+     * @param string Tutor name
89
+     * @param string Course admin user id field name
90
+     * @param string Course admin user id value
91
+     * @param string Course language
92
+     * @param string Course id field name
93
+     * @param string Course id value
94
+     * @param array Course extra fields
95
+     * @return mixed Generated id if creation was successful, WSError otherwise
96
+     */
97
+    protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
98
+        // Add the original course id field name and value to the extra fields if needed
99
+        $extras_associative = array();
100
+        if($course_id_field_name != "chamilo_course_id") {
101
+            $extras_associative[$course_id_field_name] = $course_id_value;
102
+        }
103
+        foreach($extras as $extra) {
104
+            $extras_associative[$extra['field_name']] = $extra['field_value'];
105
+        }
106
+        $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
107
+        if($course_admin_id instanceof WSError) {
108
+            return $course_admin_id;
109
+        }
110
+        if($wanted_code == '') {
111
+            $wanted_code = CourseManager::generate_course_code($title);
112
+        }
113
+        $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
114
+        if (!$result) {
115
+            return new WSError(202, 'There was an error creating the course');
116
+        } else {
117
+            // Update extra fields
118
+            foreach($extras_associative as $fname => $fvalue) {
119
+                CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
120
+            }
121
+            // Get course id
122
+            $course_info = CourseManager::get_course_information($result);
123
+            return $course_info['real_id'];
124
+        }
125
+    }
126 126
 
127
-	/**
128
-	 * Creates a course
129
-	 *
130
-	 * @param string API secret key
131
-	 * @param string Title
132
-	 * @param string Category code
133
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
134
-	 * @param string Tutor name
135
-	 * @param string Course admin user id field name
136
-	 * @param string Course admin user id value
137
-	 * @param string Course language
138
-	 * @param string Course id field name
139
-	 * @param string Course id value
140
-	 * @param array Course extra fields
141
-	 * @return int Course id generated
142
-	 */
143
-	public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
144
-		// First, verify the secret key
145
-		$verifKey = $this->verifyKey($secret_key);
146
-		if($verifKey instanceof WSError) {
147
-			$this->handleError($verifKey);
148
-		} else {
149
-			$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
150
-			if($result instanceof WSError) {
151
-				$this->handleError($result);
152
-			} else {
153
-				return $result;
154
-			}
155
-		}
156
-	}
127
+    /**
128
+     * Creates a course
129
+     *
130
+     * @param string API secret key
131
+     * @param string Title
132
+     * @param string Category code
133
+     * @param string Wanted code. If it's not defined, it will be generated automatically
134
+     * @param string Tutor name
135
+     * @param string Course admin user id field name
136
+     * @param string Course admin user id value
137
+     * @param string Course language
138
+     * @param string Course id field name
139
+     * @param string Course id value
140
+     * @param array Course extra fields
141
+     * @return int Course id generated
142
+     */
143
+    public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
144
+        // First, verify the secret key
145
+        $verifKey = $this->verifyKey($secret_key);
146
+        if($verifKey instanceof WSError) {
147
+            $this->handleError($verifKey);
148
+        } else {
149
+            $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
150
+            if($result instanceof WSError) {
151
+                $this->handleError($result);
152
+            } else {
153
+                return $result;
154
+            }
155
+        }
156
+    }
157 157
 
158
-	/**
159
-	 * Create multiple courses
160
-	 *
161
-	 * @param string API secret key
162
-	 * @param array Courses to be created, with elements following the structure presented in CreateCourse
163
-	 * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
164
-	 */
165
-	public function CreateCourses($secret_key, $courses) {
166
-		// First, verify the secret key
167
-		$verifKey = $this->verifyKey($secret_key);
168
-		if($verifKey instanceof WSError) {
169
-			$this->handleError($verifKey);
170
-		} else {
171
-			$results = array();
172
-			foreach($courses as $course) {
173
-				$result_tmp = array();
158
+    /**
159
+     * Create multiple courses
160
+     *
161
+     * @param string API secret key
162
+     * @param array Courses to be created, with elements following the structure presented in CreateCourse
163
+     * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
164
+     */
165
+    public function CreateCourses($secret_key, $courses) {
166
+        // First, verify the secret key
167
+        $verifKey = $this->verifyKey($secret_key);
168
+        if($verifKey instanceof WSError) {
169
+            $this->handleError($verifKey);
170
+        } else {
171
+            $results = array();
172
+            foreach($courses as $course) {
173
+                $result_tmp = array();
174 174
                 // re-initialize variables just in case
175 175
                 $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = 0;
176
-				extract($course);
177
-				$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
178
-				if($result instanceof WSError) {
179
-					$result_tmp['result'] = $result->toArray();
180
-					$result_tmp['course_id_value'] = $course_id_value;
181
-					$result_tmp['course_id_generated'] = 0;
182
-				} else {
183
-					$result_tmp['result'] = $this->getSuccessfulResult();
184
-					$result_tmp['course_id_value'] = $course_id_value;
185
-					$result_tmp['course_id_generated'] = $result;
186
-				}
187
-				$results[] = $result_tmp;
188
-			}
189
-			return $results;
190
-		}
191
-	}
176
+                extract($course);
177
+                $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
178
+                if($result instanceof WSError) {
179
+                    $result_tmp['result'] = $result->toArray();
180
+                    $result_tmp['course_id_value'] = $course_id_value;
181
+                    $result_tmp['course_id_generated'] = 0;
182
+                } else {
183
+                    $result_tmp['result'] = $this->getSuccessfulResult();
184
+                    $result_tmp['course_id_value'] = $course_id_value;
185
+                    $result_tmp['course_id_generated'] = $result;
186
+                }
187
+                $results[] = $result_tmp;
188
+            }
189
+            return $results;
190
+        }
191
+    }
192 192
 
193
-	/**
194
-	 * Edits a course (helper method)
195
-	 *
196
-	 * @param string Course id field name
197
-	 * @param string Course id value
198
-	 * @param string Title
199
-	 * @param string Category code
200
-	 * @param string Department name
201
-	 * @param string Department url
202
-	 * @param string Course language
203
-	 * @param int Visibility
204
-	 * @param int Subscribe (0 = denied, 1 = allowed)
205
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
206
-	 * @param string Visual code
207
-	 * @param array Course extra fields
208
-	 * @return mixed True in case of success, WSError otherwise
209
-	 */
210
-	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
211
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
212
-		if($course_id instanceof WSError) {
213
-			return $course_id;
214
-		} else {
215
-			$attributes = array();
216
-			if(!empty($title)) {
217
-				$attributes['title'] = $title;
218
-			}
219
-			if(!empty($category_code)) {
220
-				$attributes['category_code'] = $category_code;
221
-			}
222
-			if(!empty($department_name)) {
223
-				$attributes['department_name'] = $department_name;
224
-			}
225
-			if(!empty($department_url)) {
226
-				$attributes['department_url'] = $department_url;
227
-			}
228
-			if(!empty($language)) {
229
-				$attributes['course_language'] = $language;
230
-			}
231
-			if($visibility != '') {
232
-				$attributes['visibility'] = (int)$visibility;
233
-			}
234
-			if($subscribe != '') {
235
-				$attributes['subscribe'] = (int)$subscribe;
236
-			}
237
-			if($unsubscribe != '') {
238
-				$attributes['unsubscribe'] = (int)$unsubscribe;
239
-			}
240
-			if(!empty($visual_code)) {
241
-				$attributes['visual_code'] = $visual_code;
242
-			}
243
-			if(!empty($attributes)) {
244
-				CourseManager::update_attributes($course_id, $attributes);
245
-			}
246
-			if(!empty($extras)) {
247
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
248
-				$extras_associative = array();
249
-				foreach($extras as $extra) {
250
-					$extras_associative[$extra['field_name']] = $extra['field_value'];
251
-				}
252
-				foreach($extras_associative as $fname => $fvalue) {
253
-					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
254
-				}
255
-			}
256
-			return true;
257
-		}
258
-	}
193
+    /**
194
+     * Edits a course (helper method)
195
+     *
196
+     * @param string Course id field name
197
+     * @param string Course id value
198
+     * @param string Title
199
+     * @param string Category code
200
+     * @param string Department name
201
+     * @param string Department url
202
+     * @param string Course language
203
+     * @param int Visibility
204
+     * @param int Subscribe (0 = denied, 1 = allowed)
205
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
206
+     * @param string Visual code
207
+     * @param array Course extra fields
208
+     * @return mixed True in case of success, WSError otherwise
209
+     */
210
+    protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
211
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
212
+        if($course_id instanceof WSError) {
213
+            return $course_id;
214
+        } else {
215
+            $attributes = array();
216
+            if(!empty($title)) {
217
+                $attributes['title'] = $title;
218
+            }
219
+            if(!empty($category_code)) {
220
+                $attributes['category_code'] = $category_code;
221
+            }
222
+            if(!empty($department_name)) {
223
+                $attributes['department_name'] = $department_name;
224
+            }
225
+            if(!empty($department_url)) {
226
+                $attributes['department_url'] = $department_url;
227
+            }
228
+            if(!empty($language)) {
229
+                $attributes['course_language'] = $language;
230
+            }
231
+            if($visibility != '') {
232
+                $attributes['visibility'] = (int)$visibility;
233
+            }
234
+            if($subscribe != '') {
235
+                $attributes['subscribe'] = (int)$subscribe;
236
+            }
237
+            if($unsubscribe != '') {
238
+                $attributes['unsubscribe'] = (int)$unsubscribe;
239
+            }
240
+            if(!empty($visual_code)) {
241
+                $attributes['visual_code'] = $visual_code;
242
+            }
243
+            if(!empty($attributes)) {
244
+                CourseManager::update_attributes($course_id, $attributes);
245
+            }
246
+            if(!empty($extras)) {
247
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
248
+                $extras_associative = array();
249
+                foreach($extras as $extra) {
250
+                    $extras_associative[$extra['field_name']] = $extra['field_value'];
251
+                }
252
+                foreach($extras_associative as $fname => $fvalue) {
253
+                    CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
254
+                }
255
+            }
256
+            return true;
257
+        }
258
+    }
259 259
 
260
-	/**
261
-	 * Edits a course
262
-	 *
263
-	 * @param string API secret key
264
-	 * @param string Course id field name
265
-	 * @param string Course id value
266
-	 * @param string Title
267
-	 * @param string Category code
268
-	 * @param string Department name
269
-	 * @param string Department url
270
-	 * @param string Course language
271
-	 * @param int Visibility
272
-	 * @param int Subscribe (0 = denied, 1 = allowed)
273
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
274
-	 * @param string Visual code
275
-	 * @param array Course extra fields
276
-	 */
277
-	public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
278
-		$verifKey = $this->verifyKey($secret_key);
279
-		if($verifKey instanceof WSError) {
280
-			$this->handleError($verifKey);
281
-		} else {
282
-			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
283
-			if($result instanceof WSError) {
284
-				$this->handleError($result);
285
-			}
286
-		}
287
-	}
260
+    /**
261
+     * Edits a course
262
+     *
263
+     * @param string API secret key
264
+     * @param string Course id field name
265
+     * @param string Course id value
266
+     * @param string Title
267
+     * @param string Category code
268
+     * @param string Department name
269
+     * @param string Department url
270
+     * @param string Course language
271
+     * @param int Visibility
272
+     * @param int Subscribe (0 = denied, 1 = allowed)
273
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
274
+     * @param string Visual code
275
+     * @param array Course extra fields
276
+     */
277
+    public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
278
+        $verifKey = $this->verifyKey($secret_key);
279
+        if($verifKey instanceof WSError) {
280
+            $this->handleError($verifKey);
281
+        } else {
282
+            $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
283
+            if($result instanceof WSError) {
284
+                $this->handleError($result);
285
+            }
286
+        }
287
+    }
288 288
 
289
-	/**
290
-	 * List courses
291
-	 *
292
-	 * @param string API secret key
293
-	 * @param string A list of visibility filter we want to apply
294
-	 * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
295
-	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
296
-	 */
297
-	public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
298
-		$verifKey = $this->verifyKey($secret_key);
299
-		if($verifKey instanceof WSError) {
300
-			$this->handleError($verifKey);
301
-		} else {
289
+    /**
290
+     * List courses
291
+     *
292
+     * @param string API secret key
293
+     * @param string A list of visibility filter we want to apply
294
+     * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
295
+     * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
296
+     */
297
+    public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
298
+        $verifKey = $this->verifyKey($secret_key);
299
+        if($verifKey instanceof WSError) {
300
+            $this->handleError($verifKey);
301
+        } else {
302 302
             $visibilities = split(',',$visibility);
303 303
             $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0');
304 304
             foreach ($visibilities as $p => $visibility) {
305 305
                 $visibilities[$p] = $vis[$visibility];
306 306
             }
307
-			$courses_result = array();
308
-			$category_names = array();
307
+            $courses_result = array();
308
+            $category_names = array();
309 309
 
310
-			$courses = CourseManager::get_courses_list();
311
-			foreach($courses as $course) {
310
+            $courses = CourseManager::get_courses_list();
311
+            foreach($courses as $course) {
312 312
                 //skip elements that do not match required visibility
313 313
                 if (!in_array($course['visibility'],$visibilities)) { continue; }
314
-				$course_tmp = array();
315
-				$course_tmp['id'] = $course['id'];
316
-				$course_tmp['code'] = $course['code'];
317
-				$course_tmp['title'] = $course['title'];
318
-				$course_tmp['language'] = $course['course_language'];
319
-				$course_tmp['visibility'] = $course['visibility'];
314
+                $course_tmp = array();
315
+                $course_tmp['id'] = $course['id'];
316
+                $course_tmp['code'] = $course['code'];
317
+                $course_tmp['title'] = $course['title'];
318
+                $course_tmp['language'] = $course['course_language'];
319
+                $course_tmp['visibility'] = $course['visibility'];
320 320
 
321
-				// Determining category name
322
-				if($category_names[$course['category_code']]) {
323
-					$course_tmp['category_name'] = $category_names[$course['category_code']];
324
-				} else {
325
-					$category = CourseManager::get_course_category($course['category_code']);
326
-					$category_names[$course['category_code']] = $category['name'];
327
-					$course_tmp['category_name'] = $category['name'];
328
-				}
321
+                // Determining category name
322
+                if($category_names[$course['category_code']]) {
323
+                    $course_tmp['category_name'] = $category_names[$course['category_code']];
324
+                } else {
325
+                    $category = CourseManager::get_course_category($course['category_code']);
326
+                    $category_names[$course['category_code']] = $category['name'];
327
+                    $course_tmp['category_name'] = $category['name'];
328
+                }
329 329
 
330
-				// Determining number of students registered in course
331
-				$user_list = CourseManager::get_user_list_from_course_code($course['code'], 0);
332
-				$course_tmp['number_students'] = count($user_list);
330
+                // Determining number of students registered in course
331
+                $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0);
332
+                $course_tmp['number_students'] = count($user_list);
333 333
 
334
-				// Determining external course id - this code misses the external course id field name
335
-				// $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
334
+                // Determining external course id - this code misses the external course id field name
335
+                // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
336 336
 
337 337
 
338
-				$courses_result[] = $course_tmp;
339
-			}
338
+                $courses_result[] = $course_tmp;
339
+            }
340 340
 
341
-			return $courses_result;
342
-		}
343
-	}
341
+            return $courses_result;
342
+        }
343
+    }
344 344
 
345
-	/**
346
-	 * Subscribe or unsubscribe user to a course (helper method)
347
-	 *
348
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
349
-	 * @param string Course id value.
350
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
351
-	 * @param string User id value
352
-	 * @param int Set to 1 to subscribe, 0 to unsubscribe
353
-	 * @param int Status (STUDENT or TEACHER) Used for subscription only
354
-	 * @return mixed True if subscription or unsubscription was successful, false otherwise
355
-	 */
356
-	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
357
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
358
-		if($course_id instanceof WSError) {
359
-			return $course_id;
360
-		} else {
361
-			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
362
-			if($user_id instanceof WSError) {
363
-				return $user_id;
364
-			} else {
365
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
366
-				if($state == 0) {
367
-					// Unsubscribe user
368
-					CourseManager::unsubscribe_user($user_id, $course_code);
369
-					return true;
370
-				} else {
371
-					// Subscribe user
372
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
373
-						return true;
374
-					} else {
375
-						return new WSError(203, 'An error occured subscribing to this course');
376
-					}
377
-				}
378
-			}
379
-		}
380
-	}
345
+    /**
346
+     * Subscribe or unsubscribe user to a course (helper method)
347
+     *
348
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
349
+     * @param string Course id value.
350
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
351
+     * @param string User id value
352
+     * @param int Set to 1 to subscribe, 0 to unsubscribe
353
+     * @param int Status (STUDENT or TEACHER) Used for subscription only
354
+     * @return mixed True if subscription or unsubscription was successful, false otherwise
355
+     */
356
+    protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
357
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
358
+        if($course_id instanceof WSError) {
359
+            return $course_id;
360
+        } else {
361
+            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
362
+            if($user_id instanceof WSError) {
363
+                return $user_id;
364
+            } else {
365
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
366
+                if($state == 0) {
367
+                    // Unsubscribe user
368
+                    CourseManager::unsubscribe_user($user_id, $course_code);
369
+                    return true;
370
+                } else {
371
+                    // Subscribe user
372
+                    if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
373
+                        return true;
374
+                    } else {
375
+                        return new WSError(203, 'An error occured subscribing to this course');
376
+                    }
377
+                }
378
+            }
379
+        }
380
+    }
381 381
 
382
-	/**
383
-	 * Subscribe user to a course
384
-	 *
385
-	 * @param string API secret key
386
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
387
-	 * @param string Course id value.
388
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
389
-	 * @param string User id value
390
-	 * @param int Status (1 = Teacher, 5 = Student)
391
-	 */
392
-	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
393
-		$verifKey = $this->verifyKey($secret_key);
394
-		if($verifKey instanceof WSError) {
395
-			$this->handleError($verifKey);
396
-		} else {
397
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
398
-			if($result instanceof WSError) {
399
-				$this->handleError($result);
400
-			}
401
-		}
402
-	}
382
+    /**
383
+     * Subscribe user to a course
384
+     *
385
+     * @param string API secret key
386
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
387
+     * @param string Course id value.
388
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
389
+     * @param string User id value
390
+     * @param int Status (1 = Teacher, 5 = Student)
391
+     */
392
+    public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
393
+        $verifKey = $this->verifyKey($secret_key);
394
+        if($verifKey instanceof WSError) {
395
+            $this->handleError($verifKey);
396
+        } else {
397
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
398
+            if($result instanceof WSError) {
399
+                $this->handleError($result);
400
+            }
401
+        }
402
+    }
403 403
 
404
-	/**
405
-	 * Unsusbscribe user from course
406
-	 *
407
-	 * @param string API secret key
408
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
409
-	 * @param string Course id value.
410
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
411
-	 * @param string User id value
412
-	 */
413
-	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
414
-		$verifKey = $this->verifyKey($secret_key);
415
-		if($verifKey instanceof WSError) {
416
-			$this->handleError($verifKey);
417
-		} else {
418
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
419
-			if($result instanceof WSError) {
420
-				$this->handleError($result);
421
-			}
422
-		}
423
-	}
404
+    /**
405
+     * Unsusbscribe user from course
406
+     *
407
+     * @param string API secret key
408
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
409
+     * @param string Course id value.
410
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
411
+     * @param string User id value
412
+     */
413
+    public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
414
+        $verifKey = $this->verifyKey($secret_key);
415
+        if($verifKey instanceof WSError) {
416
+            $this->handleError($verifKey);
417
+        } else {
418
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
419
+            if($result instanceof WSError) {
420
+                $this->handleError($result);
421
+            }
422
+        }
423
+    }
424 424
 
425
-	/**
426
-	 * Returns the descriptions of a course, along with their id
427
-	 *
428
-	 * @param string API secret key
429
-	 * @param string Course id field name
430
-	 * @param string Course id value
431
-	 * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
432
-	 */
433
-	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
434
-		$verifKey = $this->verifyKey($secret_key);
435
-		if($verifKey instanceof WSError) {
436
-			$this->handleError($verifKey);
437
-		} else {
438
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
439
-			if($course_id instanceof WSError) {
440
-				return $course_id;
441
-			} else {
442
-				// Course exists, get its descriptions
443
-				$descriptions = CourseDescription::get_descriptions($course_id);
444
-				$results = array();
445
-				foreach($descriptions as $description) {
446
-					$results[] = array('course_desc_id' => $description->get_description_type(),
447
-										'course_desc_title' => $description->get_title(),
448
-										'course_desc_content' => $description->get_content());
449
-				}
450
-				return $results;
451
-			}
452
-		}
453
-	}
425
+    /**
426
+     * Returns the descriptions of a course, along with their id
427
+     *
428
+     * @param string API secret key
429
+     * @param string Course id field name
430
+     * @param string Course id value
431
+     * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
432
+     */
433
+    public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
434
+        $verifKey = $this->verifyKey($secret_key);
435
+        if($verifKey instanceof WSError) {
436
+            $this->handleError($verifKey);
437
+        } else {
438
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
439
+            if($course_id instanceof WSError) {
440
+                return $course_id;
441
+            } else {
442
+                // Course exists, get its descriptions
443
+                $descriptions = CourseDescription::get_descriptions($course_id);
444
+                $results = array();
445
+                foreach($descriptions as $description) {
446
+                    $results[] = array('course_desc_id' => $description->get_description_type(),
447
+                                        'course_desc_title' => $description->get_title(),
448
+                                        'course_desc_content' => $description->get_content());
449
+                }
450
+                return $results;
451
+            }
452
+        }
453
+    }
454 454
 
455 455
 
456
-	/**
457
-	 * Edit course description
458
-	 *
459
-	 * @param string API secret key
460
-	 * @param string Course id field name
461
-	 * @param string Course id value
462
-	 * @param int Category id from course description
463
-	 * @param string Description title
464
-	 * @param string Course description content
465
-	 */
466
-	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
467
-		$verifKey = $this->verifyKey($secret_key);
468
-		if($verifKey instanceof WSError) {
469
-			$this->handleError($verifKey);
470
-		} else {
471
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
472
-			if($course_id instanceof WSError) {
473
-				return $course_id;
474
-			} else {
475
-				// Create the new course description
476
-				$cd = new CourseDescription();
477
-				$cd->set_description_type($course_desc_id);
478
-				$cd->set_title($course_desc_title);
479
-				$cd->set_content($course_desc_content);
480
-				$cd->set_session_id(0);
481
-				// Get course info
482
-				$course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
456
+    /**
457
+     * Edit course description
458
+     *
459
+     * @param string API secret key
460
+     * @param string Course id field name
461
+     * @param string Course id value
462
+     * @param int Category id from course description
463
+     * @param string Description title
464
+     * @param string Course description content
465
+     */
466
+    public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
467
+        $verifKey = $this->verifyKey($secret_key);
468
+        if($verifKey instanceof WSError) {
469
+            $this->handleError($verifKey);
470
+        } else {
471
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
472
+            if($course_id instanceof WSError) {
473
+                return $course_id;
474
+            } else {
475
+                // Create the new course description
476
+                $cd = new CourseDescription();
477
+                $cd->set_description_type($course_desc_id);
478
+                $cd->set_title($course_desc_title);
479
+                $cd->set_content($course_desc_content);
480
+                $cd->set_session_id(0);
481
+                // Get course info
482
+                $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
483 483
                 $cd->set_course_id($course_info['real_id']);
484
-				// Check if this course description exists
485
-				$descriptions = CourseDescription::get_descriptions($course_id);
486
-				$exists = false;
487
-				foreach($descriptions as $description) {
488
-					if($description->get_description_type() == $course_desc_id) {
489
-						$exists = true;
490
-					}
491
-				}
492
-				if (!$exists) {
493
-					$cd->set_progress(0);
494
-					$cd->insert();
495
-				} else {
496
-					$cd->update();
497
-				}
498
-			}
499
-		}
500
-	}
484
+                // Check if this course description exists
485
+                $descriptions = CourseDescription::get_descriptions($course_id);
486
+                $exists = false;
487
+                foreach($descriptions as $description) {
488
+                    if($description->get_description_type() == $course_desc_id) {
489
+                        $exists = true;
490
+                    }
491
+                }
492
+                if (!$exists) {
493
+                    $cd->set_progress(0);
494
+                    $cd->insert();
495
+                } else {
496
+                    $cd->update();
497
+                }
498
+            }
499
+        }
500
+    }
501 501
 }
Please login to merge, or discard this patch.
main/document/create_document.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
 $is_certificate_mode = false;
79 79
 
80 80
 if (isset($_REQUEST['certificate']) && $_REQUEST['certificate'] == 'true') {
81
-	$is_certificate_mode = true;
81
+    $is_certificate_mode = true;
82 82
 }
83 83
 
84 84
 if ($is_certificate_mode) {
85
-	$nameTools = get_lang('CreateCertificate');
85
+    $nameTools = get_lang('CreateCertificate');
86 86
 } else {
87
-	$nameTools = get_lang('CreateDocument');
87
+    $nameTools = get_lang('CreateDocument');
88 88
 }
89 89
 
90 90
 /*	Constants and variables */
@@ -137,26 +137,26 @@  discard block
 block discarded – undo
137 137
 
138 138
 // Please, do not modify this dirname formatting
139 139
 if (strstr($dir, '..')) {
140
-	$dir = '/';
140
+    $dir = '/';
141 141
 }
142 142
 
143 143
 if ($dir[0] == '.') {
144
-	$dir = substr($dir, 1);
144
+    $dir = substr($dir, 1);
145 145
 }
146 146
 
147 147
 if ($dir[0] != '/') {
148
-	$dir = '/'.$dir;
148
+    $dir = '/'.$dir;
149 149
 }
150 150
 
151 151
 if ($dir[strlen($dir) - 1] != '/') {
152
-	$dir .= '/';
152
+    $dir .= '/';
153 153
 }
154 154
 
155 155
 if ($is_certificate_mode) {
156
-	$document_id 	= DocumentManager::get_document_id(api_get_course_info(), '/certificates');
157
-	$document_data 	= DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
158
-	$folder_id = $document_data['id'];
159
-	$dir = '/certificates/';
156
+    $document_id 	= DocumentManager::get_document_id(api_get_course_info(), '/certificates');
157
+    $document_data 	= DocumentManager::get_document_data_by_id($document_id, api_get_course_id(), true);
158
+    $folder_id = $document_data['id'];
159
+    $dir = '/certificates/';
160 160
 }
161 161
 
162 162
 $doc_tree  = explode('/', $dir);
@@ -167,16 +167,16 @@  discard block
 block discarded – undo
167 167
 
168 168
     // Level correction for group documents.
169 169
     if (!empty($group_properties['directory'])) {
170
-    	$count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
170
+        $count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
171 171
     }
172 172
 }
173 173
 $relative_url = '';
174 174
 for ($i = 0; $i < ($count_dir); $i++) {
175
-	$relative_url .= '../';
175
+    $relative_url .= '../';
176 176
 }
177 177
 
178 178
 if ($relative_url== '') {
179
-	$relative_url = '/';
179
+    $relative_url = '/';
180 180
 }
181 181
 
182 182
 $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
@@ -188,11 +188,11 @@  discard block
 block discarded – undo
188 188
     'cols-size' => [2, 10, 0],
189 189
     'FullPage' => true,
190 190
     'InDocument' => true,
191
-	'CreateDocumentDir'    => $relative_url,
192
-	'CreateDocumentWebDir' => (empty($group_properties['directory']))
193
-                        		? api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'
194
-                        		: api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/',
195
-	'BaseHref'             => api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir
191
+    'CreateDocumentDir'    => $relative_url,
192
+    'CreateDocumentWebDir' => (empty($group_properties['directory']))
193
+                                ? api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/'
194
+                                : api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document'.$group_properties['directory'].'/',
195
+    'BaseHref'             => api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir
196 196
 );
197 197
 
198 198
 if ($is_certificate_mode) {
@@ -204,36 +204,36 @@  discard block
 block discarded – undo
204 204
 $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
205 205
 
206 206
 if (!is_dir($filepath)) {
207
-	$filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
208
-	$dir = '/';
207
+    $filepath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/';
208
+    $dir = '/';
209 209
 }
210 210
 
211 211
 $to_group_id = 0;
212 212
 
213 213
 if (!$is_certificate_mode) {
214
-	if (api_is_in_group()) {
215
-		$interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace'));
216
-		$noPHP_SELF = true;
217
-		$to_group_id = api_get_group_id();
218
-		$path = explode('/', $dir);
219
-		if ('/'.$path[1] != $group_properties['directory']) {
220
-			api_not_allowed(true);
221
-		}
222
-	}
223
-	$interbreadcrumb[] = array("url" => "./document.php?curdirpath=".urlencode($dir)."&".api_get_cidreq(), "name" => get_lang('Documents'));
214
+    if (api_is_in_group()) {
215
+        $interbreadcrumb[] = array ("url" => "../group/group_space.php?".api_get_cidreq(), "name" => get_lang('GroupSpace'));
216
+        $noPHP_SELF = true;
217
+        $to_group_id = api_get_group_id();
218
+        $path = explode('/', $dir);
219
+        if ('/'.$path[1] != $group_properties['directory']) {
220
+            api_not_allowed(true);
221
+        }
222
+    }
223
+    $interbreadcrumb[] = array("url" => "./document.php?curdirpath=".urlencode($dir)."&".api_get_cidreq(), "name" => get_lang('Documents'));
224 224
 } else {
225
-	$interbreadcrumb[]= array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
225
+    $interbreadcrumb[]= array('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('Gradebook'));
226 226
 }
227 227
 
228 228
 if (!$is_allowed_in_course) {
229
-	api_not_allowed(true);
229
+    api_not_allowed(true);
230 230
 }
231 231
 
232 232
 if (!($is_allowed_to_edit ||
233 233
     $_SESSION['group_member_with_upload_rights'] ||
234 234
     DocumentManager::is_my_shared_folder($userId, $dir, api_get_session_id()))
235 235
 ) {
236
-	api_not_allowed(true);
236
+    api_not_allowed(true);
237 237
 }
238 238
 
239 239
 /*	Header */
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 
242 242
 $display_dir = $dir;
243 243
 if (isset($group_properties)) {
244
-	$display_dir = explode('/', $dir);
245
-	unset($display_dir[0]);
246
-	unset($display_dir[1]);
247
-	$display_dir = implode('/', $display_dir);
244
+    $display_dir = explode('/', $dir);
245
+    unset($display_dir[0]);
246
+    unset($display_dir[1]);
247
+    $display_dir = implode('/', $display_dir);
248 248
 }
249 249
 
250 250
 $select_cat = isset($_GET['selectcat']) ? intval($_GET['selectcat']) : null;
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 $form->addElement('header', $nameTools);
262 262
 
263 263
 if ($is_certificate_mode) {//added condition for certicate in gradebook
264
-	$form->addElement('hidden','certificate','true',array('id'=>'certificate'));
265
-	if (isset($_GET['selectcat'])) {
266
-		$form->addElement('hidden','selectcat', $select_cat);
264
+    $form->addElement('hidden','certificate','true',array('id'=>'certificate'));
265
+    if (isset($_GET['selectcat'])) {
266
+        $form->addElement('hidden','selectcat', $select_cat);
267 267
     }
268 268
 }
269 269
 
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
 if ($is_certificate_mode) {
299 299
     $form->addText('title', get_lang('CertificateName'), true, array('cols-size' => [2, 10, 0], 'autofocus'));
300 300
 } else {
301
-	$form->addText('title', get_lang('Title'), true, array('cols-size' => [2, 10, 0], 'autofocus'));
301
+    $form->addText('title', get_lang('Title'), true, array('cols-size' => [2, 10, 0], 'autofocus'));
302 302
 }
303 303
 
304 304
 // Show read-only box only in groups
305 305
 if (!empty($groupId)) {
306
-	$group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly'));
306
+    $group[]= $form->createElement('checkbox', 'readonly', '', get_lang('ReadOnly'));
307 307
 }
308 308
 $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
309 309
 $form->addRule('title', get_lang('FileExists'), 'callback', 'document_exists');
@@ -318,14 +318,14 @@  discard block
 block discarded – undo
318 318
 // new document created
319 319
 
320 320
 if (!$is_certificate_mode &&
321
-	!DocumentManager::is_my_shared_folder($userId, $dir, $current_session_id)
321
+    !DocumentManager::is_my_shared_folder($userId, $dir, $current_session_id)
322 322
 ) {
323
-	$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
323
+    $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
324 324
 
325
-	//$parent_select = $form->addElement('select', 'curdirpath', array(null, get_lang('DestinationDirectory')));
325
+    //$parent_select = $form->addElement('select', 'curdirpath', array(null, get_lang('DestinationDirectory')));
326 326
         $parent_select = $form->addSelect('curdirpath', get_lang('DestinationDirectory'),null, array('cols-size' => [2, 10, 0]) );
327
-	// Following two conditions copied from document.inc.php::build_directory_selector()
328
-	$folder_titles = array();
327
+    // Following two conditions copied from document.inc.php::build_directory_selector()
328
+    $folder_titles = array();
329 329
 
330 330
     if (is_array($folders)) {
331 331
         $escaped_folders = array();
@@ -363,22 +363,22 @@  discard block
 block discarded – undo
363 363
         }
364 364
     }
365 365
 
366
-	if (empty($group_dir)) {
367
-		$parent_select -> addOption(get_lang('HomeDirectory'), '/');
368
-		if (is_array($folders)) {
369
-			foreach ($folders as & $folder) {
370
-				//Hide some folders
371
-				if ($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css') {
366
+    if (empty($group_dir)) {
367
+        $parent_select -> addOption(get_lang('HomeDirectory'), '/');
368
+        if (is_array($folders)) {
369
+            foreach ($folders as & $folder) {
370
+                //Hide some folders
371
+                if ($folder=='/HotPotatoes_files' || $folder=='/certificates' || basename($folder)=='css') {
372 372
                     continue;
373
-				}
374
-				//Admin setting for Hide/Show the folders of all users
375
-				if (api_get_setting('show_users_folders') == 'false' &&
373
+                }
374
+                //Admin setting for Hide/Show the folders of all users
375
+                if (api_get_setting('show_users_folders') == 'false' &&
376 376
                     (strstr($folder, '/shared_folder') || strstr($folder, 'shared_folder_session_'))
377 377
                 ){
378
-					continue;
379
-				}
380
-				//Admin setting for Hide/Show Default folders to all users
381
-				if (api_get_setting('show_default_folders') == 'false' &&
378
+                    continue;
379
+                }
380
+                //Admin setting for Hide/Show Default folders to all users
381
+                if (api_get_setting('show_default_folders') == 'false' &&
382 382
                     (
383 383
                         $folder == '/images' ||
384 384
                         $folder == '/flash' ||
@@ -388,80 +388,80 @@  discard block
 block discarded – undo
388 388
                         $folder == '/video/flv'
389 389
                     )
390 390
                 ){
391
-					continue;
392
-				}
393
-				//Admin setting for Hide/Show chat history folder
394
-				if (api_get_setting('show_chat_folder') == 'false' &&
391
+                    continue;
392
+                }
393
+                //Admin setting for Hide/Show chat history folder
394
+                if (api_get_setting('show_chat_folder') == 'false' &&
395 395
                     $folder=='/chat_files'
396 396
                 ){
397
-					continue;
398
-				}
397
+                    continue;
398
+                }
399 399
 
400
-				$selected = (substr($dir,0,-1) == $folder) ? ' selected="selected"' : '';
401
-				$path_parts = explode('/', $folder);
402
-				$folder_titles[$folder] = cut($folder_titles[$folder], 80);
400
+                $selected = (substr($dir,0,-1) == $folder) ? ' selected="selected"' : '';
401
+                $path_parts = explode('/', $folder);
402
+                $folder_titles[$folder] = cut($folder_titles[$folder], 80);
403 403
                 $space_counter =count($path_parts) - 2;
404 404
                 if ($space_counter > 0) {
405 405
                     $label = str_repeat('&nbsp;&nbsp;&nbsp;', $space_counter).' &mdash; '.$folder_titles[$folder];
406 406
                 } else {
407 407
                     $label = ' &mdash; '.$folder_titles[$folder];
408 408
                 }
409
-				$parent_select -> addOption($label, $folder);
410
-				if ($selected != '') {
411
-					$parent_select->setSelected($folder);
412
-				}
413
-			}
414
-		}
415
-	} else {
416
-		foreach ($folders as & $folder) {
417
-			$selected = (substr($dir,0,-1)==$folder) ? ' selected="selected"' : '';
418
-			$label = $folder_titles[$folder];
419
-			if ($folder == $group_dir) {
420
-				$label = '/ ('.get_lang('HomeDirectory').')';
421
-			} else {
422
-				$path_parts = explode('/', str_replace($group_dir, '', $folder));
423
-				$label = cut($label, 80);
424
-				$label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
425
-			}
426
-			$parent_select -> addOption($label, $folder);
427
-			if ($selected != '') {
428
-				$parent_select->setSelected($folder);
429
-			}
430
-		}
431
-	}
409
+                $parent_select -> addOption($label, $folder);
410
+                if ($selected != '') {
411
+                    $parent_select->setSelected($folder);
412
+                }
413
+            }
414
+        }
415
+    } else {
416
+        foreach ($folders as & $folder) {
417
+            $selected = (substr($dir,0,-1)==$folder) ? ' selected="selected"' : '';
418
+            $label = $folder_titles[$folder];
419
+            if ($folder == $group_dir) {
420
+                $label = '/ ('.get_lang('HomeDirectory').')';
421
+            } else {
422
+                $path_parts = explode('/', str_replace($group_dir, '', $folder));
423
+                $label = cut($label, 80);
424
+                $label = str_repeat('&nbsp;&nbsp;&nbsp;', count($path_parts) - 2).' &mdash; '.$label;
425
+            }
426
+            $parent_select -> addOption($label, $folder);
427
+            if ($selected != '') {
428
+                $parent_select->setSelected($folder);
429
+            }
430
+        }
431
+    }
432 432
 }
433 433
 
434 434
 $form->addHidden('dirValue', '');
435 435
 
436 436
 if ($is_certificate_mode) {
437
-	$form->addButtonCreate(get_lang('CreateCertificate'));
437
+    $form->addButtonCreate(get_lang('CreateCertificate'));
438 438
 } else {
439
-	$form->addButtonCreate(get_lang('CreateDoc'));
439
+    $form->addButtonCreate(get_lang('CreateDoc'));
440 440
 }
441 441
 
442 442
 $form->setDefaults($defaults);
443 443
 
444 444
 // If form validates -> save the new document
445 445
 if ($form->validate()) {
446
-	$values = $form->exportValues();
447
-	$readonly = isset($values['readonly']) ? 1 : 0;
448
-	$values['title'] = trim($values['title']);
446
+    $values = $form->exportValues();
447
+    $readonly = isset($values['readonly']) ? 1 : 0;
448
+    $values['title'] = trim($values['title']);
449 449
 
450 450
     if (!empty($values['dirValue'])) {
451 451
         $dir = $values['dirValue'];
452 452
     }
453 453
 
454 454
     if ($dir[strlen($dir) - 1] != '/') {
455
-		$dir .= '/';
456
-	}
455
+        $dir .= '/';
456
+    }
457 457
     $filepath = $filepath.$dir;
458 458
 
459 459
     // Setting the filename
460
-	$filename = $values['title'];
461
-	$filename = addslashes(trim($filename));
462
-	$filename = Security::remove_XSS($filename);
463
-	$filename = api_replace_dangerous_char($filename);
464
-	$filename = disable_dangerous_file($filename);
460
+    $filename = $values['title'];
461
+    $filename = addslashes(trim($filename));
462
+    $filename = Security::remove_XSS($filename);
463
+    $filename = api_replace_dangerous_char($filename);
464
+    $filename = disable_dangerous_file($filename);
465 465
     $filename .= DocumentManager::getDocumentSuffix(
466 466
         $_course,
467 467
         api_get_session_id(),
@@ -469,14 +469,14 @@  discard block
 block discarded – undo
469 469
     );
470 470
 
471 471
     // Setting the title
472
-	$title = $values['title'];
472
+    $title = $values['title'];
473 473
 
474 474
     // Setting the extension
475
-	$extension = 'html';
475
+    $extension = 'html';
476 476
 
477
-	$content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
477
+    $content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
478 478
 
479
-	/*if (strpos($content, '/css/frames.css') == false) {
479
+    /*if (strpos($content, '/css/frames.css') == false) {
480 480
 		$content = str_replace('</head>', '<link rel="stylesheet" href="./css/frames.css" type="text/css" /><style> body{margin:50px;}</style></head>', $content);
481 481
 	}*/
482 482
 
@@ -489,13 +489,13 @@  discard block
 block discarded – undo
489 489
         exit;
490 490
     }
491 491
 
492
-	if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
493
-		//$content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].'/courses/', $content);
494
-		$content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].api_get_path(REL_COURSE_PATH), $content);
492
+    if ($fp = @fopen($filepath.$filename.'.'.$extension, 'w')) {
493
+        //$content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].'/courses/', $content);
494
+        $content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'].api_get_path(REL_COURSE_PATH), $content);
495 495
 
496
-		fputs($fp, $content);
497
-		fclose($fp);
498
-		chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files());
496
+        fputs($fp, $content);
497
+        fclose($fp);
498
+        chmod($filepath.$filename.'.'.$extension, api_get_permissions_for_new_files());
499 499
 
500 500
         /*
501 501
 		if (!is_dir($filepath.'css')) {
@@ -513,8 +513,8 @@  discard block
 block discarded – undo
513 513
 			api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $userId, null, null, null, null, $current_session_id);
514 514
 		}*/
515 515
 
516
-		$file_size = filesize($filepath.$filename.'.'.$extension);
517
-		$save_file_path = $dir.$filename.'.'.$extension;
516
+        $file_size = filesize($filepath.$filename.'.'.$extension);
517
+        $save_file_path = $dir.$filename.'.'.$extension;
518 518
 
519 519
         $document_id = add_document(
520 520
             $_course,
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
             $readonly
527 527
         );
528 528
 
529
-		if ($document_id) {
530
-			api_item_property_update(
529
+        if ($document_id) {
530
+            api_item_property_update(
531 531
                 $_course,
532 532
                 TOOL_DOCUMENT,
533 533
                 $document_id,
@@ -539,13 +539,13 @@  discard block
 block discarded – undo
539 539
                 null,
540 540
                 $current_session_id
541 541
             );
542
-			// Update parent folders
543
-			item_property_update_on_folder($_course, $dir, $userId);
544
-			$new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
545
-			$new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
542
+            // Update parent folders
543
+            item_property_update_on_folder($_course, $dir, $userId);
544
+            $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
545
+            $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
546 546
             $new_title = htmlspecialchars($new_title);
547
-			if ($new_comment || $new_title) {
548
-				$ct = '';
547
+            if ($new_comment || $new_title) {
548
+                $ct = '';
549 549
                 $params = [];
550 550
                 if ($new_comment) {
551 551
                     $params['comment'] = $new_comment;
@@ -560,38 +560,38 @@  discard block
 block discarded – undo
560 560
                         ['c_id = ? AND id = ?' => [$course_id, $document_id]]
561 561
                     );
562 562
                 }
563
-			}
564
-			$dir= substr($dir,0,-1);
565
-			$selectcat = '';
566
-			if (isset($_REQUEST['selectcat']))
567
-				$selectcat = "&selectcat=".Security::remove_XSS($_REQUEST['selectcat']);
568
-			$certificate_condition = '';
569
-			if ($is_certificate_mode) {
570
-				$df = DocumentManager::get_default_certificate_id($_course['code']);
563
+            }
564
+            $dir= substr($dir,0,-1);
565
+            $selectcat = '';
566
+            if (isset($_REQUEST['selectcat']))
567
+                $selectcat = "&selectcat=".Security::remove_XSS($_REQUEST['selectcat']);
568
+            $certificate_condition = '';
569
+            if ($is_certificate_mode) {
570
+                $df = DocumentManager::get_default_certificate_id($_course['code']);
571 571
                 if (!isset($df)) {
572 572
                     DocumentManager::attach_gradebook_certificate ($_course['code'],$document_id);
573
-				}
574
-				$certificate_condition = '&certificate=true&curdirpath=/certificates';
575
-			}
576
-
577
-			header('Location: document.php?'.api_get_cidreq().'&id='.$folder_id.$selectcat.$certificate_condition);
578
-			exit();
579
-		} else {
580
-			Display :: display_header($nameTools, 'Doc');
581
-			Display :: display_error_message(get_lang('Impossible'));
582
-			Display :: display_footer();
583
-		}
584
-	} else {
585
-		Display :: display_header($nameTools, 'Doc');
586
-		Display :: display_error_message(get_lang('Impossible'));
587
-		Display :: display_footer();
588
-	}
573
+                }
574
+                $certificate_condition = '&certificate=true&curdirpath=/certificates';
575
+            }
576
+
577
+            header('Location: document.php?'.api_get_cidreq().'&id='.$folder_id.$selectcat.$certificate_condition);
578
+            exit();
579
+        } else {
580
+            Display :: display_header($nameTools, 'Doc');
581
+            Display :: display_error_message(get_lang('Impossible'));
582
+            Display :: display_footer();
583
+        }
584
+    } else {
585
+        Display :: display_header($nameTools, 'Doc');
586
+        Display :: display_error_message(get_lang('Impossible'));
587
+        Display :: display_footer();
588
+    }
589 589
 } else {
590
-	// Copied from document.php
591
-	$dir_array = explode('/', $dir);
592
-	$array_len = count($dir_array);
590
+    // Copied from document.php
591
+    $dir_array = explode('/', $dir);
592
+    $array_len = count($dir_array);
593 593
 
594
-	// Breadcrumb for the current directory root path
594
+    // Breadcrumb for the current directory root path
595 595
     if (!empty($document_data)) {
596 596
         if (empty($document_data['parents'])) {
597 597
             $interbreadcrumb[] = array(
@@ -608,11 +608,11 @@  discard block
 block discarded – undo
608 608
         }
609 609
     }
610 610
 
611
-	Display :: display_header($nameTools, "Doc");
612
-	// actions
611
+    Display :: display_header($nameTools, "Doc");
612
+    // actions
613 613
 
614
-	// link back to the documents overview
615
-	if ($is_certificate_mode) {
614
+    // link back to the documents overview
615
+    if ($is_certificate_mode) {
616 616
             $actionsLeft =  '<a href="document.php?certificate=true&id='.$folder_id.'&selectcat=' . Security::remove_XSS($_GET['selectcat']).'">'.
617 617
             Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'),'',ICON_SIZE_MEDIUM).'</a>';
618 618
             $actionsLeft .= '<a id="hide_bar_template" href="#">'.Display::return_icon('expand.png',get_lang('Back'),null,ICON_SIZE_MEDIUM).'</a>';
@@ -625,16 +625,16 @@  discard block
 block discarded – undo
625 625
         echo $toolbar = Display::toolbarAction('actions-documents', array(0 => $actionsLeft, 1 => ''));
626 626
 
627 627
 
628
-	if ($is_certificate_mode) {
629
-		$all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id());
628
+    if ($is_certificate_mode) {
629
+        $all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(api_get_user_id(), api_get_course_id());
630 630
 
631
-		$str_info = '';
632
-		foreach ($all_information_by_create_certificate[0] as $info_value) {
633
-			$str_info.=$info_value.'<br/>';
634
-		}
635
-		$create_certificate = get_lang('CreateCertificateWithTags');
636
-		Display::display_normal_message($create_certificate.': <br /><br/>'.$str_info,false);
637
-	}
631
+        $str_info = '';
632
+        foreach ($all_information_by_create_certificate[0] as $info_value) {
633
+            $str_info.=$info_value.'<br/>';
634
+        }
635
+        $create_certificate = get_lang('CreateCertificateWithTags');
636
+        Display::display_normal_message($create_certificate.': <br /><br/>'.$str_info,false);
637
+    }
638 638
     // HTML-editor
639 639
     echo '<div class="page-create">
640 640
             <div class="row" style="overflow:hidden">
@@ -649,5 +649,5 @@  discard block
 block discarded – undo
649 649
                 '.$form->returnForm().'
650 650
             </div>
651 651
           </div></div>';
652
-	Display :: display_footer();
652
+    Display :: display_footer();
653 653
 }
Please login to merge, or discard this patch.
main/inc/lib/formvalidator/Rule/CompareFields.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,24 +6,24 @@
 block discarded – undo
6 6
  */
7 7
 class HTML_QuickForm_Compare_Fields extends HTML_QuickForm_Rule_Compare 
8 8
 {
9
-	/**
10
-	 * Function to check an array of fields 	 
11
-	 * @param   array of field names
9
+    /**
10
+     * Function to check an array of fields 	 
11
+     * @param   array of field names
12 12
      * @param   string operator ==, >=, etc
13 13
      * @param   string the value to compare
14
-	 * @return boolean True if date is valid
15
-	 */
16
-	function validate($values = [], $operator_and_max_value = null) {
14
+     * @return boolean True if date is valid
15
+     */
16
+    function validate($values = [], $operator_and_max_value = null) {
17 17
         if (is_array($values) && !empty($values) && !empty($operator_and_max_value)) {
18
-           $final_value = 0;
19
-           foreach ($values as $value) {
20
-               $final_value += $value;
21
-           }
22
-           $params = explode('@', $operator_and_max_value);
23
-           $operator    = $params[0];
24
-           $max_value   = $params[1];                      
25
-           return parent::validate(array($final_value, $max_value), $operator);
18
+            $final_value = 0;
19
+            foreach ($values as $value) {
20
+                $final_value += $value;
21
+            }
22
+            $params = explode('@', $operator_and_max_value);
23
+            $operator    = $params[0];
24
+            $max_value   = $params[1];                      
25
+            return parent::validate(array($final_value, $max_value), $operator);
26 26
         }
27 27
         return false;        
28
-	}
28
+    }
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.