@@ -36,16 +36,16 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | class CourseRestorer |
| 38 | 38 | { |
| 39 | - /** |
|
| 40 | - * The course-object |
|
| 41 | - */ |
|
| 39 | + /** |
|
| 40 | + * The course-object |
|
| 41 | + */ |
|
| 42 | 42 | public $course; |
| 43 | 43 | public $destination_course_info; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * What to do with files with same name (FILE_SKIP, FILE_RENAME or |
|
| 47 | - * FILE_OVERWRITE) |
|
| 48 | - */ |
|
| 45 | + /** |
|
| 46 | + * What to do with files with same name (FILE_SKIP, FILE_RENAME or |
|
| 47 | + * FILE_OVERWRITE) |
|
| 48 | + */ |
|
| 49 | 49 | public $file_option; |
| 50 | 50 | public $set_tools_invisible_by_default; |
| 51 | 51 | public $skip_content; |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | 'events', |
| 58 | 58 | 'forum_category', |
| 59 | 59 | 'forums', |
| 60 | - // 'forum_topics', |
|
| 60 | + // 'forum_topics', |
|
| 61 | 61 | 'glossary', |
| 62 | 62 | 'quizzes', |
| 63 | 63 | 'test_category', |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | public $add_text_in_items = false; |
| 83 | 83 | public $destination_course_id; |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Create a new CourseRestorer |
|
| 87 | - */ |
|
| 85 | + /** |
|
| 86 | + * Create a new CourseRestorer |
|
| 87 | + */ |
|
| 88 | 88 | public function __construct($course) |
| 89 | 89 | { |
| 90 | 90 | $this->course = $course; |
@@ -97,17 +97,17 @@ discard block |
||
| 97 | 97 | $this->file_option = FILE_RENAME; |
| 98 | 98 | $this->set_tools_invisible_by_default = false; |
| 99 | 99 | $this->skip_content = array(); |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Set the file-option |
|
| 104 | - * @param int $option (optional) What to do with files with same name |
|
| 102 | + /** |
|
| 103 | + * Set the file-option |
|
| 104 | + * @param int $option (optional) What to do with files with same name |
|
| 105 | 105 | * FILE_SKIP, FILE_RENAME or FILE_OVERWRITE |
| 106 | - */ |
|
| 106 | + */ |
|
| 107 | 107 | public function set_file_option($option = FILE_OVERWRITE) |
| 108 | 108 | { |
| 109 | - $this->file_option = $option; |
|
| 110 | - } |
|
| 109 | + $this->file_option = $option; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | 113 | * @param string $status |
@@ -125,15 +125,15 @@ discard block |
||
| 125 | 125 | $this->tool_copy_settings = $array; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Restore a course. |
|
| 128 | + /** |
|
| 129 | + * Restore a course. |
|
| 130 | 130 | * |
| 131 | - * @param string $destination_course_code code of the Chamilo-course in |
|
| 132 | - * @param int $session_id |
|
| 133 | - * @param bool $update_course_settings Course settings are going to be restore? |
|
| 131 | + * @param string $destination_course_code code of the Chamilo-course in |
|
| 132 | + * @param int $session_id |
|
| 133 | + * @param bool $update_course_settings Course settings are going to be restore? |
|
| 134 | 134 | * @param bool $respect_base_content |
| 135 | 135 | * @return bool |
| 136 | - */ |
|
| 136 | + */ |
|
| 137 | 137 | public function restore( |
| 138 | 138 | $destination_course_code = '', |
| 139 | 139 | $session_id = 0, |
@@ -271,17 +271,17 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Restore only harmless course settings: |
|
| 274 | + /** |
|
| 275 | + * Restore only harmless course settings: |
|
| 276 | 276 | * course_language, visibility, department_name,department_url, |
| 277 | 277 | * subscribe, unsubscribe ,category_code |
| 278 | - * |
|
| 279 | - * @param string $destination_course_code |
|
| 280 | - */ |
|
| 278 | + * |
|
| 279 | + * @param string $destination_course_code |
|
| 280 | + */ |
|
| 281 | 281 | public function restore_course_settings($destination_course_code) |
| 282 | 282 | { |
| 283 | - $origin_course_info = api_get_course_info($destination_course_code); |
|
| 284 | - $course_info = $this->course->info; |
|
| 283 | + $origin_course_info = api_get_course_info($destination_course_code); |
|
| 284 | + $course_info = $this->course->info; |
|
| 285 | 285 | $params['course_language'] = $course_info['language']; |
| 286 | 286 | $params['visibility'] = $course_info['visibility']; |
| 287 | 287 | $params['department_name'] = $course_info['department_name']; |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | $params['category_code'] = $course_info['categoryCode']; |
| 291 | 291 | $params['subscribe'] = $course_info['subscribe_allowed']; |
| 292 | 292 | $params['unsubscribe'] = $course_info['unsubscribe']; |
| 293 | - CourseManager::update_attributes($origin_course_info['real_id'], $params); |
|
| 294 | - } |
|
| 293 | + CourseManager::update_attributes($origin_course_info['real_id'], $params); |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * Restore documents |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | $course_info = api_get_course_info($destination_course_code); |
| 306 | 306 | |
| 307 | 307 | if ($this->course->has_resources(RESOURCE_DOCUMENT)) { |
| 308 | - $table = Database :: get_course_table(TABLE_DOCUMENT); |
|
| 309 | - $resources = $this->course->resources; |
|
| 308 | + $table = Database :: get_course_table(TABLE_DOCUMENT); |
|
| 309 | + $resources = $this->course->resources; |
|
| 310 | 310 | $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; |
| 311 | 311 | |
| 312 | - foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { |
|
| 312 | + foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { |
|
| 313 | 313 | |
| 314 | 314 | if (empty($document->item_properties[0]['id_session'])) { |
| 315 | 315 | $my_session_id = 0; |
@@ -317,9 +317,9 @@ discard block |
||
| 317 | 317 | $my_session_id = $session_id; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - if ($document->file_type == FOLDER) { |
|
| 321 | - $visibility = $document->item_properties[0]['visibility']; |
|
| 322 | - $new = substr($document->path, 8); |
|
| 320 | + if ($document->file_type == FOLDER) { |
|
| 321 | + $visibility = $document->item_properties[0]['visibility']; |
|
| 322 | + $new = substr($document->path, 8); |
|
| 323 | 323 | |
| 324 | 324 | $folderList = explode('/', $new); |
| 325 | 325 | $tempFolder = ''; |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | - } elseif ($document->file_type == DOCUMENT) { |
|
| 380 | + } elseif ($document->file_type == DOCUMENT) { |
|
| 381 | 381 | //Checking if folder exists in the database otherwise we created it |
| 382 | 382 | $dir_to_create = dirname($document->path); |
| 383 | 383 | |
@@ -423,19 +423,19 @@ discard block |
||
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if (file_exists($path.$document->path)) { |
|
| 427 | - switch ($this->file_option) { |
|
| 428 | - case FILE_OVERWRITE : |
|
| 426 | + if (file_exists($path.$document->path)) { |
|
| 427 | + switch ($this->file_option) { |
|
| 428 | + case FILE_OVERWRITE : |
|
| 429 | 429 | $origin_path = $this->course->backup_path.'/'.$document->path; |
| 430 | 430 | |
| 431 | - if (file_exists($origin_path)) { |
|
| 432 | - copy($origin_path, $path.$document->path); |
|
| 431 | + if (file_exists($origin_path)) { |
|
| 432 | + copy($origin_path, $path.$document->path); |
|
| 433 | 433 | $sql = "SELECT id FROM $table |
| 434 | 434 | WHERE |
| 435 | 435 | c_id = ".$this->destination_course_id." AND |
| 436 | 436 | path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'"; |
| 437 | 437 | |
| 438 | - $res = Database::query($sql); |
|
| 438 | + $res = Database::query($sql); |
|
| 439 | 439 | $count = Database::num_rows($res); |
| 440 | 440 | |
| 441 | 441 | if ($count == 0) { |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | 'session_id' => $my_session_id, |
| 450 | 450 | ]; |
| 451 | 451 | |
| 452 | - $document_id = Database::insert($table, $params); |
|
| 452 | + $document_id = Database::insert($table, $params); |
|
| 453 | 453 | |
| 454 | 454 | if ($document_id) { |
| 455 | 455 | $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; |
@@ -540,84 +540,84 @@ discard block |
||
| 540 | 540 | ], |
| 541 | 541 | ] |
| 542 | 542 | ); |
| 543 | - } |
|
| 543 | + } |
|
| 544 | 544 | |
| 545 | - break; |
|
| 546 | - case FILE_SKIP : |
|
| 547 | - $sql = "SELECT id FROM $table |
|
| 545 | + break; |
|
| 546 | + case FILE_SKIP : |
|
| 547 | + $sql = "SELECT id FROM $table |
|
| 548 | 548 | WHERE |
| 549 | 549 | c_id = ".$this->destination_course_id." AND |
| 550 | 550 | path='/".self::DBUTF8escapestring(substr($document->path, 9))."'"; |
| 551 | - $res = Database::query($sql); |
|
| 552 | - $obj = Database::fetch_object($res); |
|
| 553 | - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; |
|
| 554 | - break; |
|
| 555 | - case FILE_RENAME : |
|
| 556 | - $i = 1; |
|
| 557 | - $ext = explode('.', basename($document->path)); |
|
| 558 | - if (count($ext) > 1) { |
|
| 559 | - $ext = array_pop($ext); |
|
| 560 | - $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
| 561 | - $ext = '.'.$ext; |
|
| 562 | - } else { |
|
| 563 | - $ext = ''; |
|
| 564 | - $file_name_no_ext = $document->path; |
|
| 565 | - } |
|
| 566 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 567 | - $file_exists = file_exists($path.$new_file_name); |
|
| 568 | - while ($file_exists) { |
|
| 569 | - $i ++; |
|
| 570 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 571 | - $file_exists = file_exists($path.$new_file_name); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - if (!empty($session_id)) { |
|
| 575 | - |
|
| 576 | - $document_path = explode('/',$document->path,3); |
|
| 577 | - $course_path = $path; |
|
| 578 | - $orig_base_folder = $document_path[1]; |
|
| 579 | - $orig_base_path = $course_path.$document_path[0].'/'.$document_path[1]; |
|
| 580 | - |
|
| 581 | - if (is_dir($orig_base_path)) { |
|
| 582 | - |
|
| 583 | - $new_base_foldername = $orig_base_folder; |
|
| 584 | - $new_base_path = $orig_base_path; |
|
| 585 | - |
|
| 586 | - if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { |
|
| 587 | - unset($_SESSION['new_base_foldername']); |
|
| 588 | - unset($_SESSION['orig_base_foldername']); |
|
| 589 | - unset($_SESSION['new_base_path']); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - $folder_exists = file_exists($new_base_path); |
|
| 593 | - if ($folder_exists) { |
|
| 594 | - $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session |
|
| 595 | - $x = ''; |
|
| 596 | - while ($folder_exists) { |
|
| 597 | - $x = $x + 1; |
|
| 598 | - $new_base_foldername = $document_path[1].'_'.$x; |
|
| 599 | - $new_base_path = $orig_base_path.'_'.$x; |
|
| 551 | + $res = Database::query($sql); |
|
| 552 | + $obj = Database::fetch_object($res); |
|
| 553 | + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; |
|
| 554 | + break; |
|
| 555 | + case FILE_RENAME : |
|
| 556 | + $i = 1; |
|
| 557 | + $ext = explode('.', basename($document->path)); |
|
| 558 | + if (count($ext) > 1) { |
|
| 559 | + $ext = array_pop($ext); |
|
| 560 | + $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
| 561 | + $ext = '.'.$ext; |
|
| 562 | + } else { |
|
| 563 | + $ext = ''; |
|
| 564 | + $file_name_no_ext = $document->path; |
|
| 565 | + } |
|
| 566 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 567 | + $file_exists = file_exists($path.$new_file_name); |
|
| 568 | + while ($file_exists) { |
|
| 569 | + $i ++; |
|
| 570 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 571 | + $file_exists = file_exists($path.$new_file_name); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + if (!empty($session_id)) { |
|
| 575 | + |
|
| 576 | + $document_path = explode('/',$document->path,3); |
|
| 577 | + $course_path = $path; |
|
| 578 | + $orig_base_folder = $document_path[1]; |
|
| 579 | + $orig_base_path = $course_path.$document_path[0].'/'.$document_path[1]; |
|
| 580 | + |
|
| 581 | + if (is_dir($orig_base_path)) { |
|
| 582 | + |
|
| 583 | + $new_base_foldername = $orig_base_folder; |
|
| 584 | + $new_base_path = $orig_base_path; |
|
| 585 | + |
|
| 586 | + if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { |
|
| 587 | + unset($_SESSION['new_base_foldername']); |
|
| 588 | + unset($_SESSION['orig_base_foldername']); |
|
| 589 | + unset($_SESSION['new_base_path']); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + $folder_exists = file_exists($new_base_path); |
|
| 593 | + if ($folder_exists) { |
|
| 594 | + $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session |
|
| 595 | + $x = ''; |
|
| 596 | + while ($folder_exists) { |
|
| 597 | + $x = $x + 1; |
|
| 598 | + $new_base_foldername = $document_path[1].'_'.$x; |
|
| 599 | + $new_base_path = $orig_base_path.'_'.$x; |
|
| 600 | 600 | if ($_SESSION['new_base_foldername'] == $new_base_foldername) { |
| 601 | 601 | break; |
| 602 | 602 | } |
| 603 | - $folder_exists = file_exists($new_base_path); |
|
| 604 | - } |
|
| 605 | - $_SESSION['new_base_foldername'] = $new_base_foldername; |
|
| 606 | - $_SESSION['new_base_path'] = $new_base_path; |
|
| 607 | - } |
|
| 603 | + $folder_exists = file_exists($new_base_path); |
|
| 604 | + } |
|
| 605 | + $_SESSION['new_base_foldername'] = $new_base_foldername; |
|
| 606 | + $_SESSION['new_base_path'] = $new_base_path; |
|
| 607 | + } |
|
| 608 | 608 | |
| 609 | - if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { |
|
| 610 | - $new_base_foldername = $_SESSION['new_base_foldername']; |
|
| 611 | - $new_base_path = $_SESSION['new_base_path']; |
|
| 612 | - } |
|
| 609 | + if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { |
|
| 610 | + $new_base_foldername = $_SESSION['new_base_foldername']; |
|
| 611 | + $new_base_path = $_SESSION['new_base_path']; |
|
| 612 | + } |
|
| 613 | 613 | |
| 614 | - $dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" |
|
| 615 | - $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" |
|
| 616 | - $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" |
|
| 614 | + $dest_document_path = $new_base_path.'/'.$document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" |
|
| 615 | + $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" |
|
| 616 | + $base_path_document = $course_path.$document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" |
|
| 617 | 617 | |
| 618 | - $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; |
|
| 618 | + $path_title = '/'.$new_base_foldername.'/'.$document_path[2]; |
|
| 619 | 619 | |
| 620 | - copy_folder_course_session( |
|
| 620 | + copy_folder_course_session( |
|
| 621 | 621 | $basedir_dest_path, |
| 622 | 622 | $base_path_document, |
| 623 | 623 | $session_id, |
@@ -659,7 +659,7 @@ discard block |
||
| 659 | 659 | 'session_id' => $my_session_id, |
| 660 | 660 | ]; |
| 661 | 661 | |
| 662 | - $document_id = Database::insert($table, $params); |
|
| 662 | + $document_id = Database::insert($table, $params); |
|
| 663 | 663 | |
| 664 | 664 | if ($document_id) { |
| 665 | 665 | $sql = "UPDATE $table SET id = iid WHERE iid = $document_id"; |
@@ -680,11 +680,11 @@ discard block |
||
| 680 | 680 | $my_session_id |
| 681 | 681 | ); |
| 682 | 682 | |
| 683 | - } else { |
|
| 683 | + } else { |
|
| 684 | 684 | |
| 685 | - if (file_exists($path.$document->path)) { |
|
| 685 | + if (file_exists($path.$document->path)) { |
|
| 686 | 686 | copy($path.$document->path, $path.$new_file_name); |
| 687 | - } |
|
| 687 | + } |
|
| 688 | 688 | |
| 689 | 689 | //Replace old course code with the new destination code see BT#1985 |
| 690 | 690 | if (file_exists($path.$new_file_name)) { |
@@ -735,10 +735,10 @@ discard block |
||
| 735 | 735 | $my_session_id |
| 736 | 736 | ); |
| 737 | 737 | } |
| 738 | - } |
|
| 739 | - } else { |
|
| 738 | + } |
|
| 739 | + } else { |
|
| 740 | 740 | |
| 741 | - copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name); |
|
| 741 | + copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name); |
|
| 742 | 742 | |
| 743 | 743 | //Replace old course code with the new destination code see BT#1985 |
| 744 | 744 | if (file_exists($path.$new_file_name)) { |
@@ -789,20 +789,20 @@ discard block |
||
| 789 | 789 | null, |
| 790 | 790 | $my_session_id |
| 791 | 791 | ); |
| 792 | - } |
|
| 793 | - break; |
|
| 794 | - |
|
| 795 | - } // end switch |
|
| 796 | - } else { |
|
| 797 | - // end if file exists |
|
| 798 | - //make sure the source file actually exists |
|
| 799 | - if (is_file($this->course->backup_path.'/'.$document->path) && |
|
| 792 | + } |
|
| 793 | + break; |
|
| 794 | + |
|
| 795 | + } // end switch |
|
| 796 | + } else { |
|
| 797 | + // end if file exists |
|
| 798 | + //make sure the source file actually exists |
|
| 799 | + if (is_file($this->course->backup_path.'/'.$document->path) && |
|
| 800 | 800 | is_readable($this->course->backup_path.'/'.$document->path) && |
| 801 | 801 | is_dir(dirname($path.$document->path)) && |
| 802 | 802 | is_writeable(dirname($path.$document->path)) |
| 803 | 803 | ) { |
| 804 | - //echo 'Copying'; |
|
| 805 | - copy($this->course->backup_path.'/'.$document->path, $path.$document->path); |
|
| 804 | + //echo 'Copying'; |
|
| 805 | + copy($this->course->backup_path.'/'.$document->path, $path.$document->path); |
|
| 806 | 806 | |
| 807 | 807 | //Replace old course code with the new destination code see BT#1985 |
| 808 | 808 | if (file_exists($path.$document->path)) { |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | Database::query($sql); |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | - $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; |
|
| 843 | + $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id; |
|
| 844 | 844 | api_item_property_update( |
| 845 | 845 | $course_info, |
| 846 | 846 | TOOL_DOCUMENT, |
@@ -853,78 +853,78 @@ discard block |
||
| 853 | 853 | null, |
| 854 | 854 | $my_session_id |
| 855 | 855 | ); |
| 856 | - } else { |
|
| 857 | - //echo 'not Copying'; |
|
| 858 | - if (is_file($this->course->backup_path.'/'.$document->path) && is_readable($this->course->backup_path.'/'.$document->path)) { |
|
| 859 | - error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found'); |
|
| 860 | - } |
|
| 861 | - if (!is_dir(dirname($path.$document->path))) { |
|
| 862 | - error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found'); |
|
| 863 | - } |
|
| 864 | - if (!is_writeable(dirname($path.$document->path))) { |
|
| 865 | - error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable'); |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - } // end file doesn't exist |
|
| 869 | - } |
|
| 870 | - } // end for each |
|
| 871 | - |
|
| 872 | - // Delete sessions for the copy the new folder in session |
|
| 873 | - unset($_SESSION['new_base_foldername']); |
|
| 874 | - unset($_SESSION['orig_base_foldername']); |
|
| 875 | - unset($_SESSION['new_base_path']); |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * Restore scorm documents |
|
| 881 | - * TODO @TODO check that the restore function with renaming doesn't break the scorm structure! |
|
| 856 | + } else { |
|
| 857 | + //echo 'not Copying'; |
|
| 858 | + if (is_file($this->course->backup_path.'/'.$document->path) && is_readable($this->course->backup_path.'/'.$document->path)) { |
|
| 859 | + error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found'); |
|
| 860 | + } |
|
| 861 | + if (!is_dir(dirname($path.$document->path))) { |
|
| 862 | + error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found'); |
|
| 863 | + } |
|
| 864 | + if (!is_writeable(dirname($path.$document->path))) { |
|
| 865 | + error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable'); |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + } // end file doesn't exist |
|
| 869 | + } |
|
| 870 | + } // end for each |
|
| 871 | + |
|
| 872 | + // Delete sessions for the copy the new folder in session |
|
| 873 | + unset($_SESSION['new_base_foldername']); |
|
| 874 | + unset($_SESSION['orig_base_foldername']); |
|
| 875 | + unset($_SESSION['new_base_path']); |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * Restore scorm documents |
|
| 881 | + * TODO @TODO check that the restore function with renaming doesn't break the scorm structure! |
|
| 882 | 882 | * see #7029 |
| 883 | - */ |
|
| 884 | - public function restore_scorm_documents() |
|
| 883 | + */ |
|
| 884 | + public function restore_scorm_documents() |
|
| 885 | 885 | { |
| 886 | - $perm = api_get_permissions_for_new_directories(); |
|
| 886 | + $perm = api_get_permissions_for_new_directories(); |
|
| 887 | 887 | |
| 888 | - if ($this->course->has_resources(RESOURCE_SCORM)) { |
|
| 889 | - $resources = $this->course->resources; |
|
| 888 | + if ($this->course->has_resources(RESOURCE_SCORM)) { |
|
| 889 | + $resources = $this->course->resources; |
|
| 890 | 890 | |
| 891 | - foreach ($resources[RESOURCE_SCORM] as $document) { |
|
| 892 | - $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; |
|
| 891 | + foreach ($resources[RESOURCE_SCORM] as $document) { |
|
| 892 | + $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/'; |
|
| 893 | 893 | |
| 894 | - @mkdir(dirname($path.$document->path), $perm, true); |
|
| 894 | + @mkdir(dirname($path.$document->path), $perm, true); |
|
| 895 | 895 | |
| 896 | - if (file_exists($path.$document->path)) { |
|
| 897 | - switch ($this->file_option) { |
|
| 898 | - case FILE_OVERWRITE: |
|
| 899 | - rmdirr($path.$document->path); |
|
| 896 | + if (file_exists($path.$document->path)) { |
|
| 897 | + switch ($this->file_option) { |
|
| 898 | + case FILE_OVERWRITE: |
|
| 899 | + rmdirr($path.$document->path); |
|
| 900 | 900 | copyDirTo( |
| 901 | 901 | $this->course->backup_path . '/' . $document->path, |
| 902 | 902 | $path . dirname($document->path), |
| 903 | 903 | false |
| 904 | 904 | ); |
| 905 | - break; |
|
| 906 | - case FILE_SKIP: |
|
| 907 | - break; |
|
| 905 | + break; |
|
| 906 | + case FILE_SKIP: |
|
| 907 | + break; |
|
| 908 | 908 | case FILE_RENAME: |
| 909 | - $i = 1; |
|
| 910 | - $ext = explode('.', basename($document->path)); |
|
| 911 | - if (count($ext) > 1) { |
|
| 912 | - $ext = array_pop($ext); |
|
| 913 | - $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
| 914 | - $ext = '.'.$ext; |
|
| 915 | - } else { |
|
| 916 | - $ext = ''; |
|
| 917 | - $file_name_no_ext = $document->path; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 921 | - $file_exists = file_exists($path.$new_file_name); |
|
| 922 | - |
|
| 923 | - while ($file_exists) { |
|
| 924 | - $i ++; |
|
| 925 | - $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 926 | - $file_exists = file_exists($path.$new_file_name); |
|
| 927 | - } |
|
| 909 | + $i = 1; |
|
| 910 | + $ext = explode('.', basename($document->path)); |
|
| 911 | + if (count($ext) > 1) { |
|
| 912 | + $ext = array_pop($ext); |
|
| 913 | + $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1)); |
|
| 914 | + $ext = '.'.$ext; |
|
| 915 | + } else { |
|
| 916 | + $ext = ''; |
|
| 917 | + $file_name_no_ext = $document->path; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 921 | + $file_exists = file_exists($path.$new_file_name); |
|
| 922 | + |
|
| 923 | + while ($file_exists) { |
|
| 924 | + $i ++; |
|
| 925 | + $new_file_name = $file_name_no_ext.'_'.$i.$ext; |
|
| 926 | + $file_exists = file_exists($path.$new_file_name); |
|
| 927 | + } |
|
| 928 | 928 | |
| 929 | 929 | rename( |
| 930 | 930 | $this->course->backup_path . '/' . $document->path, |
@@ -940,30 +940,30 @@ discard block |
||
| 940 | 940 | $this->course->backup_path . '/' . $document->path |
| 941 | 941 | ); |
| 942 | 942 | |
| 943 | - break; |
|
| 944 | - } // end switch |
|
| 945 | - } else { |
|
| 943 | + break; |
|
| 944 | + } // end switch |
|
| 945 | + } else { |
|
| 946 | 946 | // end if file exists |
| 947 | 947 | copyDirTo( |
| 948 | 948 | $this->course->backup_path . '/' . $document->path, |
| 949 | 949 | $path . dirname($document->path), |
| 950 | 950 | false |
| 951 | 951 | ); |
| 952 | - } |
|
| 953 | - } // end for each |
|
| 954 | - } |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * Restore forums |
|
| 959 | - */ |
|
| 960 | - public function restore_forums($sessionId = 0) |
|
| 952 | + } |
|
| 953 | + } // end for each |
|
| 954 | + } |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * Restore forums |
|
| 959 | + */ |
|
| 960 | + public function restore_forums($sessionId = 0) |
|
| 961 | 961 | { |
| 962 | - if ($this->course->has_resources(RESOURCE_FORUM)) { |
|
| 962 | + if ($this->course->has_resources(RESOURCE_FORUM)) { |
|
| 963 | 963 | $sessionId = intval($sessionId); |
| 964 | - $table_forum = Database::get_course_table(TABLE_FORUM); |
|
| 965 | - $resources = $this->course->resources; |
|
| 966 | - foreach ($resources[RESOURCE_FORUM] as $id => $forum) { |
|
| 964 | + $table_forum = Database::get_course_table(TABLE_FORUM); |
|
| 965 | + $resources = $this->course->resources; |
|
| 966 | + foreach ($resources[RESOURCE_FORUM] as $id => $forum) { |
|
| 967 | 967 | $params = (array)$forum->obj; |
| 968 | 968 | $cat_id = ''; |
| 969 | 969 | if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) && |
@@ -1009,33 +1009,33 @@ discard block |
||
| 1009 | 1009 | Database::query($sql); |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id; |
|
| 1013 | - |
|
| 1014 | - $forum_topics = 0; |
|
| 1015 | - if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) { |
|
| 1016 | - foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) { |
|
| 1017 | - if ($topic->obj->forum_id == $id) { |
|
| 1018 | - $this->restore_topic($topic_id, $new_id, $sessionId); |
|
| 1019 | - $forum_topics ++; |
|
| 1020 | - } |
|
| 1021 | - } |
|
| 1022 | - } |
|
| 1023 | - if ($forum_topics > 0) { |
|
| 1024 | - $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics." |
|
| 1012 | + $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id; |
|
| 1013 | + |
|
| 1014 | + $forum_topics = 0; |
|
| 1015 | + if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) { |
|
| 1016 | + foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) { |
|
| 1017 | + if ($topic->obj->forum_id == $id) { |
|
| 1018 | + $this->restore_topic($topic_id, $new_id, $sessionId); |
|
| 1019 | + $forum_topics ++; |
|
| 1020 | + } |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1023 | + if ($forum_topics > 0) { |
|
| 1024 | + $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics." |
|
| 1025 | 1025 | WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id; |
| 1026 | - Database::query($sql); |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Restore forum-categories |
|
| 1034 | - */ |
|
| 1026 | + Database::query($sql); |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Restore forum-categories |
|
| 1034 | + */ |
|
| 1035 | 1035 | public function restore_forum_category($my_id = null, $sessionId = 0) |
| 1036 | 1036 | { |
| 1037 | - $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY); |
|
| 1038 | - $resources = $this->course->resources; |
|
| 1037 | + $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY); |
|
| 1038 | + $resources = $this->course->resources; |
|
| 1039 | 1039 | if (!empty($resources[RESOURCE_FORUMCATEGORY])) { |
| 1040 | 1040 | foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) { |
| 1041 | 1041 | if (!empty($my_id)) { |
@@ -1082,15 +1082,15 @@ discard block |
||
| 1082 | 1082 | } |
| 1083 | 1083 | } |
| 1084 | 1084 | } |
| 1085 | - } |
|
| 1085 | + } |
|
| 1086 | 1086 | |
| 1087 | - /** |
|
| 1088 | - * Restore a forum-topic |
|
| 1089 | - */ |
|
| 1087 | + /** |
|
| 1088 | + * Restore a forum-topic |
|
| 1089 | + */ |
|
| 1090 | 1090 | public function restore_topic($thread_id, $forum_id, $sessionId = 0) |
| 1091 | 1091 | { |
| 1092 | - $table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
| 1093 | - $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]; |
|
| 1092 | + $table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
| 1093 | + $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]; |
|
| 1094 | 1094 | |
| 1095 | 1095 | $params = (array)$topic->obj; |
| 1096 | 1096 | $params = self::DBUTF8_array($params); |
@@ -1126,27 +1126,27 @@ discard block |
||
| 1126 | 1126 | $sessionId |
| 1127 | 1127 | ); |
| 1128 | 1128 | |
| 1129 | - $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id; |
|
| 1129 | + $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id; |
|
| 1130 | 1130 | |
| 1131 | - $topic_replies = -1; |
|
| 1131 | + $topic_replies = -1; |
|
| 1132 | 1132 | |
| 1133 | - foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) { |
|
| 1134 | - if ($post->obj->thread_id == $thread_id) { |
|
| 1135 | - $topic_replies++; |
|
| 1136 | - $this->restore_post($post_id, $new_id, $forum_id, $sessionId); |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - return $new_id; |
|
| 1140 | - } |
|
| 1133 | + foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) { |
|
| 1134 | + if ($post->obj->thread_id == $thread_id) { |
|
| 1135 | + $topic_replies++; |
|
| 1136 | + $this->restore_post($post_id, $new_id, $forum_id, $sessionId); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + return $new_id; |
|
| 1140 | + } |
|
| 1141 | 1141 | |
| 1142 | - /** |
|
| 1143 | - * Restore a forum-post |
|
| 1144 | - * @TODO Restore tree-structure of posts. For example: attachments to posts. |
|
| 1145 | - */ |
|
| 1142 | + /** |
|
| 1143 | + * Restore a forum-post |
|
| 1144 | + * @TODO Restore tree-structure of posts. For example: attachments to posts. |
|
| 1145 | + */ |
|
| 1146 | 1146 | public function restore_post($id, $topic_id, $forum_id, $sessionId = 0) |
| 1147 | 1147 | { |
| 1148 | - $table_post = Database :: get_course_table(TABLE_FORUM_POST); |
|
| 1149 | - $post = $this->course->resources[RESOURCE_FORUMPOST][$id]; |
|
| 1148 | + $table_post = Database :: get_course_table(TABLE_FORUM_POST); |
|
| 1149 | + $post = $this->course->resources[RESOURCE_FORUMPOST][$id]; |
|
| 1150 | 1150 | $params = (array) $post->obj; |
| 1151 | 1151 | $params['c_id'] = $this->destination_course_id; |
| 1152 | 1152 | $params['forum_id'] = $forum_id; |
@@ -1181,37 +1181,37 @@ discard block |
||
| 1181 | 1181 | null, |
| 1182 | 1182 | $sessionId |
| 1183 | 1183 | ); |
| 1184 | - $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id; |
|
| 1184 | + $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id; |
|
| 1185 | 1185 | |
| 1186 | - return $new_id; |
|
| 1187 | - } |
|
| 1186 | + return $new_id; |
|
| 1187 | + } |
|
| 1188 | 1188 | |
| 1189 | - /** |
|
| 1190 | - * Restore links |
|
| 1191 | - */ |
|
| 1189 | + /** |
|
| 1190 | + * Restore links |
|
| 1191 | + */ |
|
| 1192 | 1192 | public function restore_links($session_id = 0) |
| 1193 | 1193 | { |
| 1194 | - if ($this->course->has_resources(RESOURCE_LINK)) { |
|
| 1195 | - $link_table = Database :: get_course_table(TABLE_LINK); |
|
| 1196 | - $resources = $this->course->resources; |
|
| 1194 | + if ($this->course->has_resources(RESOURCE_LINK)) { |
|
| 1195 | + $link_table = Database :: get_course_table(TABLE_LINK); |
|
| 1196 | + $resources = $this->course->resources; |
|
| 1197 | 1197 | |
| 1198 | - foreach ($resources[RESOURCE_LINK] as $id => $link) { |
|
| 1198 | + foreach ($resources[RESOURCE_LINK] as $id => $link) { |
|
| 1199 | 1199 | $cat_id = $this->restore_link_category( |
| 1200 | 1200 | $link->category_id, |
| 1201 | 1201 | $session_id |
| 1202 | 1202 | ); |
| 1203 | - $sql = "SELECT MAX(display_order) |
|
| 1203 | + $sql = "SELECT MAX(display_order) |
|
| 1204 | 1204 | FROM $link_table |
| 1205 | 1205 | WHERE |
| 1206 | 1206 | c_id = ".$this->destination_course_id." AND |
| 1207 | 1207 | category_id='" . intval($cat_id). "'"; |
| 1208 | - $result = Database::query($sql); |
|
| 1209 | - list($max_order) = Database::fetch_array($result); |
|
| 1208 | + $result = Database::query($sql); |
|
| 1209 | + list($max_order) = Database::fetch_array($result); |
|
| 1210 | 1210 | |
| 1211 | 1211 | $params = []; |
| 1212 | - if (!empty($session_id)) { |
|
| 1212 | + if (!empty($session_id)) { |
|
| 1213 | 1213 | $params['session_id'] = $session_id; |
| 1214 | - } |
|
| 1214 | + } |
|
| 1215 | 1215 | |
| 1216 | 1216 | $params['c_id'] = $this->destination_course_id; |
| 1217 | 1217 | $params['url'] = self::DBUTF8($link->url); |
@@ -1240,9 +1240,9 @@ discard block |
||
| 1240 | 1240 | } |
| 1241 | 1241 | $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id; |
| 1242 | 1242 | } |
| 1243 | - } |
|
| 1244 | - } |
|
| 1245 | - } |
|
| 1243 | + } |
|
| 1244 | + } |
|
| 1245 | + } |
|
| 1246 | 1246 | |
| 1247 | 1247 | /** |
| 1248 | 1248 | * Restore a link-category |
@@ -1286,21 +1286,21 @@ discard block |
||
| 1286 | 1286 | return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id; |
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | - /** |
|
| 1290 | - * Restore tool intro |
|
| 1291 | - */ |
|
| 1289 | + /** |
|
| 1290 | + * Restore tool intro |
|
| 1291 | + */ |
|
| 1292 | 1292 | public function restore_tool_intro($sessionId = 0) |
| 1293 | 1293 | { |
| 1294 | - if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) { |
|
| 1294 | + if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) { |
|
| 1295 | 1295 | $sessionId = intval($sessionId); |
| 1296 | - $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO); |
|
| 1297 | - $resources = $this->course->resources; |
|
| 1298 | - foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) { |
|
| 1299 | - $sql = "DELETE FROM ".$tool_intro_table." |
|
| 1296 | + $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO); |
|
| 1297 | + $resources = $this->course->resources; |
|
| 1298 | + foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) { |
|
| 1299 | + $sql = "DELETE FROM ".$tool_intro_table." |
|
| 1300 | 1300 | WHERE |
| 1301 | 1301 | c_id = ".$this->destination_course_id." AND |
| 1302 | 1302 | id='".self::DBUTF8escapestring($tool_intro->id)."'"; |
| 1303 | - Database::query($sql); |
|
| 1303 | + Database::query($sql); |
|
| 1304 | 1304 | |
| 1305 | 1305 | $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 1306 | 1306 | $tool_intro->intro_text, |
@@ -1328,21 +1328,21 @@ discard block |
||
| 1328 | 1328 | |
| 1329 | 1329 | $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id; |
| 1330 | 1330 | } |
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - } |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + } |
|
| 1334 | 1334 | |
| 1335 | - /** |
|
| 1336 | - * Restore events |
|
| 1337 | - */ |
|
| 1335 | + /** |
|
| 1336 | + * Restore events |
|
| 1337 | + */ |
|
| 1338 | 1338 | public function restore_events($sessionId = 0) |
| 1339 | 1339 | { |
| 1340 | - if ($this->course->has_resources(RESOURCE_EVENT)) { |
|
| 1340 | + if ($this->course->has_resources(RESOURCE_EVENT)) { |
|
| 1341 | 1341 | $sessionId = intval($sessionId); |
| 1342 | - $table = Database :: get_course_table(TABLE_AGENDA); |
|
| 1343 | - $resources = $this->course->resources; |
|
| 1344 | - foreach ($resources[RESOURCE_EVENT] as $id => $event) { |
|
| 1345 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1342 | + $table = Database :: get_course_table(TABLE_AGENDA); |
|
| 1343 | + $resources = $this->course->resources; |
|
| 1344 | + foreach ($resources[RESOURCE_EVENT] as $id => $event) { |
|
| 1345 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1346 | 1346 | $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 1347 | 1347 | $event->content, |
| 1348 | 1348 | $this->course->code, |
@@ -1360,7 +1360,7 @@ discard block |
||
| 1360 | 1360 | 'end_date' => $event->end_date, |
| 1361 | 1361 | 'session_id' => $sessionId, |
| 1362 | 1362 | ]; |
| 1363 | - $new_event_id = Database::insert($table, $params); |
|
| 1363 | + $new_event_id = Database::insert($table, $params); |
|
| 1364 | 1364 | |
| 1365 | 1365 | if ($new_event_id) { |
| 1366 | 1366 | $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id"; |
@@ -1373,30 +1373,30 @@ discard block |
||
| 1373 | 1373 | $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id; |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | - // Copy event attachment |
|
| 1376 | + // Copy event attachment |
|
| 1377 | 1377 | |
| 1378 | - $origin_path = $this->course->backup_path.'/upload/calendar/'; |
|
| 1379 | - $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
| 1378 | + $origin_path = $this->course->backup_path.'/upload/calendar/'; |
|
| 1379 | + $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/'; |
|
| 1380 | 1380 | |
| 1381 | - if (!empty($this->course->orig)) { |
|
| 1381 | + if (!empty($this->course->orig)) { |
|
| 1382 | 1382 | |
| 1383 | - $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 1384 | - $sql = 'SELECT path, comment, size, filename |
|
| 1383 | + $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 1384 | + $sql = 'SELECT path, comment, size, filename |
|
| 1385 | 1385 | FROM '.$table_attachment.' |
| 1386 | 1386 | WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id; |
| 1387 | - $attachment_event = Database::query($sql); |
|
| 1388 | - $attachment_event = Database::fetch_object($attachment_event); |
|
| 1387 | + $attachment_event = Database::query($sql); |
|
| 1388 | + $attachment_event = Database::fetch_object($attachment_event); |
|
| 1389 | 1389 | |
| 1390 | - if (file_exists($origin_path.$attachment_event->path) && |
|
| 1390 | + if (file_exists($origin_path.$attachment_event->path) && |
|
| 1391 | 1391 | !is_dir($origin_path.$attachment_event->path) |
| 1392 | 1392 | ) { |
| 1393 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1394 | - $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename); |
|
| 1395 | - //$copy_result = true; |
|
| 1396 | - if ($copy_result) { |
|
| 1397 | - $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 1393 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1394 | + $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename); |
|
| 1395 | + //$copy_result = true; |
|
| 1396 | + if ($copy_result) { |
|
| 1397 | + $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 1398 | 1398 | |
| 1399 | - $params = [ |
|
| 1399 | + $params = [ |
|
| 1400 | 1400 | 'c_id' => $this->destination_course_id, |
| 1401 | 1401 | 'path' => self::DBUTF8($new_filename), |
| 1402 | 1402 | 'comment' => self::DBUTF8($attachment_event->comment), |
@@ -1410,17 +1410,17 @@ discard block |
||
| 1410 | 1410 | Database::query($sql); |
| 1411 | 1411 | } |
| 1412 | 1412 | } |
| 1413 | - } |
|
| 1414 | - } else { |
|
| 1415 | - // get the info of the file |
|
| 1416 | - if (!empty($event->attachment_path) && |
|
| 1413 | + } |
|
| 1414 | + } else { |
|
| 1415 | + // get the info of the file |
|
| 1416 | + if (!empty($event->attachment_path) && |
|
| 1417 | 1417 | is_file($origin_path.$event->attachment_path) && |
| 1418 | 1418 | is_readable($origin_path.$event->attachment_path) |
| 1419 | 1419 | ) { |
| 1420 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1421 | - $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename); |
|
| 1422 | - if ($copy_result) { |
|
| 1423 | - $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 1420 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1421 | + $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename); |
|
| 1422 | + if ($copy_result) { |
|
| 1423 | + $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT); |
|
| 1424 | 1424 | |
| 1425 | 1425 | $params = [ |
| 1426 | 1426 | 'c_id' => $this->destination_course_id, |
@@ -1436,23 +1436,23 @@ discard block |
||
| 1436 | 1436 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id"; |
| 1437 | 1437 | Database::query($sql); |
| 1438 | 1438 | } |
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - } |
|
| 1443 | - } |
|
| 1444 | - } |
|
| 1445 | - |
|
| 1446 | - /** |
|
| 1447 | - * Restore course-description |
|
| 1448 | - */ |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1445 | + |
|
| 1446 | + /** |
|
| 1447 | + * Restore course-description |
|
| 1448 | + */ |
|
| 1449 | 1449 | public function restore_course_descriptions($session_id = 0) |
| 1450 | 1450 | { |
| 1451 | - if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) { |
|
| 1452 | - $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); |
|
| 1453 | - $resources = $this->course->resources; |
|
| 1454 | - foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) { |
|
| 1455 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1451 | + if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) { |
|
| 1452 | + $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); |
|
| 1453 | + $resources = $this->course->resources; |
|
| 1454 | + foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) { |
|
| 1455 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1456 | 1456 | $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 1457 | 1457 | $cd->content, |
| 1458 | 1458 | $this->course->code, |
@@ -1462,10 +1462,10 @@ discard block |
||
| 1462 | 1462 | ); |
| 1463 | 1463 | |
| 1464 | 1464 | $params = []; |
| 1465 | - if (!empty($session_id)) { |
|
| 1466 | - $session_id = intval($session_id); |
|
| 1465 | + if (!empty($session_id)) { |
|
| 1466 | + $session_id = intval($session_id); |
|
| 1467 | 1467 | $params['session_id'] = $session_id; |
| 1468 | - } |
|
| 1468 | + } |
|
| 1469 | 1469 | $params['c_id'] = $this->destination_course_id; |
| 1470 | 1470 | $params['description_type'] = self::DBUTF8($cd->description_type); |
| 1471 | 1471 | $params['title'] = self::DBUTF8($cd->title); |
@@ -1481,22 +1481,22 @@ discard block |
||
| 1481 | 1481 | } |
| 1482 | 1482 | $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id; |
| 1483 | 1483 | } |
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - } |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + } |
|
| 1487 | 1487 | |
| 1488 | - /** |
|
| 1489 | - * Restore announcements |
|
| 1490 | - */ |
|
| 1488 | + /** |
|
| 1489 | + * Restore announcements |
|
| 1490 | + */ |
|
| 1491 | 1491 | public function restore_announcements($sessionId = 0) |
| 1492 | 1492 | { |
| 1493 | - if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { |
|
| 1493 | + if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) { |
|
| 1494 | 1494 | $sessionId = intval($sessionId); |
| 1495 | - $table = Database :: get_course_table(TABLE_ANNOUNCEMENT); |
|
| 1496 | - $resources = $this->course->resources; |
|
| 1497 | - foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) { |
|
| 1495 | + $table = Database :: get_course_table(TABLE_ANNOUNCEMENT); |
|
| 1496 | + $resources = $this->course->resources; |
|
| 1497 | + foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) { |
|
| 1498 | 1498 | |
| 1499 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1499 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1500 | 1500 | $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 1501 | 1501 | $announcement->content, |
| 1502 | 1502 | $this->course->code, |
@@ -1515,7 +1515,7 @@ discard block |
||
| 1515 | 1515 | 'session_id' => $sessionId, |
| 1516 | 1516 | ]; |
| 1517 | 1517 | |
| 1518 | - $new_announcement_id = Database::insert($table, $params); |
|
| 1518 | + $new_announcement_id = Database::insert($table, $params); |
|
| 1519 | 1519 | |
| 1520 | 1520 | if ($new_announcement_id) { |
| 1521 | 1521 | $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id"; |
@@ -1527,32 +1527,32 @@ discard block |
||
| 1527 | 1527 | $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id; |
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | - $origin_path = $this->course->backup_path.'/upload/announcements/'; |
|
| 1531 | - $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/'; |
|
| 1530 | + $origin_path = $this->course->backup_path.'/upload/announcements/'; |
|
| 1531 | + $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/'; |
|
| 1532 | 1532 | |
| 1533 | - // Copy announcement attachment file |
|
| 1534 | - if (!empty($this->course->orig)) { |
|
| 1533 | + // Copy announcement attachment file |
|
| 1534 | + if (!empty($this->course->orig)) { |
|
| 1535 | 1535 | |
| 1536 | - $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
| 1537 | - $sql = 'SELECT path, comment, size, filename |
|
| 1536 | + $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
| 1537 | + $sql = 'SELECT path, comment, size, filename |
|
| 1538 | 1538 | FROM '.$table_attachment.' |
| 1539 | 1539 | WHERE |
| 1540 | 1540 | c_id = '.$this->destination_course_id.' AND |
| 1541 | 1541 | announcement_id = '.$id; |
| 1542 | - $attachment_event = Database::query($sql); |
|
| 1543 | - $attachment_event = Database::fetch_object($attachment_event); |
|
| 1542 | + $attachment_event = Database::query($sql); |
|
| 1543 | + $attachment_event = Database::fetch_object($attachment_event); |
|
| 1544 | 1544 | |
| 1545 | - if (file_exists($origin_path.$attachment_event->path) && |
|
| 1545 | + if (file_exists($origin_path.$attachment_event->path) && |
|
| 1546 | 1546 | !is_dir($origin_path.$attachment_event->path) |
| 1547 | 1547 | ) { |
| 1548 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1548 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1549 | 1549 | $copy_result = copy( |
| 1550 | 1550 | $origin_path.$attachment_event->path, |
| 1551 | 1551 | $destination_path.$new_filename |
| 1552 | 1552 | ); |
| 1553 | 1553 | |
| 1554 | - if ($copy_result) { |
|
| 1555 | - $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
| 1554 | + if ($copy_result) { |
|
| 1555 | + $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
| 1556 | 1556 | |
| 1557 | 1557 | $params = [ |
| 1558 | 1558 | 'c_id' => $this->destination_course_id, |
@@ -1569,20 +1569,20 @@ discard block |
||
| 1569 | 1569 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId"; |
| 1570 | 1570 | Database::query($sql); |
| 1571 | 1571 | } |
| 1572 | - } |
|
| 1573 | - } |
|
| 1574 | - } else { |
|
| 1575 | - // get the info of the file |
|
| 1576 | - if (!empty($announcement->attachment_path) && |
|
| 1572 | + } |
|
| 1573 | + } |
|
| 1574 | + } else { |
|
| 1575 | + // get the info of the file |
|
| 1576 | + if (!empty($announcement->attachment_path) && |
|
| 1577 | 1577 | is_file($origin_path.$announcement->attachment_path) && |
| 1578 | 1578 | is_readable($origin_path.$announcement->attachment_path) |
| 1579 | 1579 | ) { |
| 1580 | - $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1581 | - $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename); |
|
| 1580 | + $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php |
|
| 1581 | + $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename); |
|
| 1582 | 1582 | |
| 1583 | - if ($copy_result) { |
|
| 1584 | - $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
| 1585 | - /*$sql = "INSERT INTO ".$table_attachment." SET |
|
| 1583 | + if ($copy_result) { |
|
| 1584 | + $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT); |
|
| 1585 | + /*$sql = "INSERT INTO ".$table_attachment." SET |
|
| 1586 | 1586 | c_id = ".$this->destination_course_id." , |
| 1587 | 1587 | path = '".self::DBUTF8escapestring($new_filename)."', |
| 1588 | 1588 | comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."', |
@@ -1605,12 +1605,12 @@ discard block |
||
| 1605 | 1605 | $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId"; |
| 1606 | 1606 | Database::query($sql); |
| 1607 | 1607 | } |
| 1608 | - } |
|
| 1609 | - } |
|
| 1610 | - } |
|
| 1611 | - } |
|
| 1612 | - } |
|
| 1613 | - } |
|
| 1608 | + } |
|
| 1609 | + } |
|
| 1610 | + } |
|
| 1611 | + } |
|
| 1612 | + } |
|
| 1613 | + } |
|
| 1614 | 1614 | |
| 1615 | 1615 | /** |
| 1616 | 1616 | * Restore Quiz |
@@ -1621,13 +1621,13 @@ discard block |
||
| 1621 | 1621 | $session_id = 0, |
| 1622 | 1622 | $respect_base_content = false |
| 1623 | 1623 | ) { |
| 1624 | - if ($this->course->has_resources(RESOURCE_QUIZ)) { |
|
| 1625 | - $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); |
|
| 1626 | - $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
| 1627 | - $table_doc = Database :: get_course_table(TABLE_DOCUMENT); |
|
| 1628 | - $resources = $this->course->resources; |
|
| 1624 | + if ($this->course->has_resources(RESOURCE_QUIZ)) { |
|
| 1625 | + $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST); |
|
| 1626 | + $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); |
|
| 1627 | + $table_doc = Database :: get_course_table(TABLE_DOCUMENT); |
|
| 1628 | + $resources = $this->course->resources; |
|
| 1629 | 1629 | |
| 1630 | - foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) { |
|
| 1630 | + foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) { |
|
| 1631 | 1631 | |
| 1632 | 1632 | if (isset($quiz->obj)) { |
| 1633 | 1633 | //For new imports |
@@ -1637,7 +1637,7 @@ discard block |
||
| 1637 | 1637 | $quiz->obj = $quiz; |
| 1638 | 1638 | } |
| 1639 | 1639 | |
| 1640 | - $doc = ''; |
|
| 1640 | + $doc = ''; |
|
| 1641 | 1641 | if (!empty($quiz->sound)) { |
| 1642 | 1642 | if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) && |
| 1643 | 1643 | $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) { |
@@ -1645,14 +1645,14 @@ discard block |
||
| 1645 | 1645 | WHERE |
| 1646 | 1646 | c_id = " . $this->destination_course_id . " AND |
| 1647 | 1647 | id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id; |
| 1648 | - $doc = Database::query($sql); |
|
| 1649 | - $doc = Database::fetch_object($doc); |
|
| 1650 | - $doc = str_replace('/audio/', '', $doc->path); |
|
| 1651 | - } |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - if ($id != -1) { |
|
| 1655 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1648 | + $doc = Database::query($sql); |
|
| 1649 | + $doc = Database::fetch_object($doc); |
|
| 1650 | + $doc = str_replace('/audio/', '', $doc->path); |
|
| 1651 | + } |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + if ($id != -1) { |
|
| 1655 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1656 | 1656 | $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 1657 | 1657 | $quiz->description, |
| 1658 | 1658 | $this->course->code, |
@@ -1661,13 +1661,13 @@ discard block |
||
| 1661 | 1661 | $this->course->info['path'] |
| 1662 | 1662 | ); |
| 1663 | 1663 | |
| 1664 | - global $_custom; |
|
| 1665 | - if (isset($_custom['exercises_clean_dates_when_restoring']) && |
|
| 1664 | + global $_custom; |
|
| 1665 | + if (isset($_custom['exercises_clean_dates_when_restoring']) && |
|
| 1666 | 1666 | $_custom['exercises_clean_dates_when_restoring'] |
| 1667 | 1667 | ) { |
| 1668 | - $quiz->start_time = null; |
|
| 1669 | - $quiz->end_time = null; |
|
| 1670 | - } |
|
| 1668 | + $quiz->start_time = null; |
|
| 1669 | + $quiz->end_time = null; |
|
| 1670 | + } |
|
| 1671 | 1671 | |
| 1672 | 1672 | $params = array( |
| 1673 | 1673 | 'c_id' => $this->destination_course_id, |
@@ -1699,10 +1699,10 @@ discard block |
||
| 1699 | 1699 | } |
| 1700 | 1700 | $params['session_id'] = $my_session_id; |
| 1701 | 1701 | } else { |
| 1702 | - if (!empty($session_id)) { |
|
| 1703 | - $session_id = intval($session_id); |
|
| 1702 | + if (!empty($session_id)) { |
|
| 1703 | + $session_id = intval($session_id); |
|
| 1704 | 1704 | $params['session_id'] = $session_id; |
| 1705 | - } |
|
| 1705 | + } |
|
| 1706 | 1706 | } |
| 1707 | 1707 | $new_id = Database::insert($table_qui, $params); |
| 1708 | 1708 | |
@@ -1711,15 +1711,15 @@ discard block |
||
| 1711 | 1711 | Database::query($sql); |
| 1712 | 1712 | } |
| 1713 | 1713 | |
| 1714 | - } else { |
|
| 1715 | - // $id = -1 identifies the fictionary test for collecting |
|
| 1716 | - // orphan questions. We do not store it in the database. |
|
| 1717 | - $new_id = -1; |
|
| 1718 | - } |
|
| 1714 | + } else { |
|
| 1715 | + // $id = -1 identifies the fictionary test for collecting |
|
| 1716 | + // orphan questions. We do not store it in the database. |
|
| 1717 | + $new_id = -1; |
|
| 1718 | + } |
|
| 1719 | 1719 | |
| 1720 | - $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id; |
|
| 1720 | + $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id; |
|
| 1721 | 1721 | |
| 1722 | - $order = 0; |
|
| 1722 | + $order = 0; |
|
| 1723 | 1723 | if (!empty($quiz->question_ids)) { |
| 1724 | 1724 | foreach ($quiz->question_ids as $index => $question_id) { |
| 1725 | 1725 | $qid = $this->restore_quiz_question($question_id); |
@@ -1732,30 +1732,30 @@ discard block |
||
| 1732 | 1732 | Database::query($sql); |
| 1733 | 1733 | } |
| 1734 | 1734 | } |
| 1735 | - } |
|
| 1736 | - } |
|
| 1737 | - } |
|
| 1735 | + } |
|
| 1736 | + } |
|
| 1737 | + } |
|
| 1738 | 1738 | |
| 1739 | - /** |
|
| 1740 | - * Restore quiz-questions |
|
| 1739 | + /** |
|
| 1740 | + * Restore quiz-questions |
|
| 1741 | 1741 | * @params int question id |
| 1742 | - */ |
|
| 1742 | + */ |
|
| 1743 | 1743 | public function restore_quiz_question($id) |
| 1744 | 1744 | { |
| 1745 | - $resources = $this->course->resources; |
|
| 1745 | + $resources = $this->course->resources; |
|
| 1746 | 1746 | $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null; |
| 1747 | 1747 | |
| 1748 | - $new_id = 0; |
|
| 1748 | + $new_id = 0; |
|
| 1749 | 1749 | |
| 1750 | - if (is_object($question)) { |
|
| 1751 | - if ($question->is_restored()) { |
|
| 1752 | - return $question->destination_id; |
|
| 1753 | - } |
|
| 1754 | - $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
| 1755 | - $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
| 1750 | + if (is_object($question)) { |
|
| 1751 | + if ($question->is_restored()) { |
|
| 1752 | + return $question->destination_id; |
|
| 1753 | + } |
|
| 1754 | + $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
| 1755 | + $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
| 1756 | 1756 | $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION); |
| 1757 | 1757 | |
| 1758 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1758 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1759 | 1759 | $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 1760 | 1760 | $question->description, |
| 1761 | 1761 | $this->course->code, |
@@ -1776,7 +1776,7 @@ discard block |
||
| 1776 | 1776 | 'extra' => self::DBUTF8($question->extra), |
| 1777 | 1777 | ]; |
| 1778 | 1778 | |
| 1779 | - $new_id = Database::insert($table_que, $params); |
|
| 1779 | + $new_id = Database::insert($table_que, $params); |
|
| 1780 | 1780 | |
| 1781 | 1781 | if ($new_id) { |
| 1782 | 1782 | |
@@ -1817,7 +1817,7 @@ discard block |
||
| 1817 | 1817 | |
| 1818 | 1818 | foreach ($temp as $index => $answer) { |
| 1819 | 1819 | //id = '".$index."', |
| 1820 | - $params = [ |
|
| 1820 | + $params = [ |
|
| 1821 | 1821 | 'c_id' => $this->destination_course_id, |
| 1822 | 1822 | 'question_id' => $new_id, |
| 1823 | 1823 | 'answer' => self::DBUTF8($answer['answer']), |
@@ -1834,12 +1834,12 @@ discard block |
||
| 1834 | 1834 | $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId"; |
| 1835 | 1835 | Database::query($sql); |
| 1836 | 1836 | } |
| 1837 | - } |
|
| 1838 | - } else { |
|
| 1837 | + } |
|
| 1838 | + } else { |
|
| 1839 | 1839 | $correct_answers = array(); |
| 1840 | - foreach ($question->answers as $index => $answer) { |
|
| 1840 | + foreach ($question->answers as $index => $answer) { |
|
| 1841 | 1841 | |
| 1842 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1842 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 1843 | 1843 | $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 1844 | 1844 | $answer['answer'], |
| 1845 | 1845 | $this->course->code, |
@@ -1878,8 +1878,8 @@ discard block |
||
| 1878 | 1878 | } |
| 1879 | 1879 | |
| 1880 | 1880 | $correct_answers[$answerId] = $answer['correct']; |
| 1881 | - } |
|
| 1882 | - } |
|
| 1881 | + } |
|
| 1882 | + } |
|
| 1883 | 1883 | |
| 1884 | 1884 | //Current course id |
| 1885 | 1885 | $course_id = api_get_course_int_id(); |
@@ -1976,12 +1976,12 @@ discard block |
||
| 1976 | 1976 | } |
| 1977 | 1977 | } |
| 1978 | 1978 | } |
| 1979 | - $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id; |
|
| 1980 | - } |
|
| 1981 | - return $new_id; |
|
| 1982 | - } |
|
| 1979 | + $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id; |
|
| 1980 | + } |
|
| 1981 | + return $new_id; |
|
| 1982 | + } |
|
| 1983 | 1983 | |
| 1984 | - /** |
|
| 1984 | + /** |
|
| 1985 | 1985 | * @todo : add session id when used for session |
| 1986 | 1986 | */ |
| 1987 | 1987 | public function restore_test_category($session_id, $respect_base_content, $destination_course_code) |
@@ -2061,21 +2061,21 @@ discard block |
||
| 2061 | 2061 | $sessionId = intval($sessionId); |
| 2062 | 2062 | |
| 2063 | 2063 | if ($this->course->has_resources(RESOURCE_SURVEY)) { |
| 2064 | - $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
| 2065 | - $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
| 2066 | - $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
| 2067 | - $resources = $this->course->resources; |
|
| 2068 | - foreach ($resources[RESOURCE_SURVEY] as $id => $survey) { |
|
| 2064 | + $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
| 2065 | + $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
| 2066 | + $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
| 2067 | + $resources = $this->course->resources; |
|
| 2068 | + foreach ($resources[RESOURCE_SURVEY] as $id => $survey) { |
|
| 2069 | 2069 | |
| 2070 | - $sql = 'SELECT survey_id FROM '.$table_sur.' |
|
| 2070 | + $sql = 'SELECT survey_id FROM '.$table_sur.' |
|
| 2071 | 2071 | WHERE |
| 2072 | 2072 | c_id = '.$this->destination_course_id.' AND |
| 2073 | 2073 | code = "'.self::DBUTF8escapestring($survey->code).'" AND |
| 2074 | 2074 | lang = "'.self::DBUTF8escapestring($survey->lang).'" '; |
| 2075 | 2075 | |
| 2076 | - $result_check = Database::query($sql); |
|
| 2076 | + $result_check = Database::query($sql); |
|
| 2077 | 2077 | |
| 2078 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2078 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2079 | 2079 | $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 2080 | 2080 | $survey->title, |
| 2081 | 2081 | $this->course->code, |
@@ -2129,20 +2129,20 @@ discard block |
||
| 2129 | 2129 | 'session_id' => $sessionId, |
| 2130 | 2130 | ]; |
| 2131 | 2131 | |
| 2132 | - //An existing survey exists with the same code and the same language |
|
| 2133 | - if (Database::num_rows($result_check) == 1) { |
|
| 2134 | - switch ($this->file_option) { |
|
| 2135 | - case FILE_SKIP: |
|
| 2136 | - //Do nothing |
|
| 2137 | - break; |
|
| 2138 | - case FILE_RENAME: |
|
| 2139 | - $survey_code = $survey->code.'_'; |
|
| 2140 | - $i=1; |
|
| 2141 | - $temp_survey_code = $survey_code.$i; |
|
| 2142 | - while (!$this->is_survey_code_available($temp_survey_code)) { |
|
| 2143 | - $temp_survey_code = $survey_code.++$i; |
|
| 2144 | - } |
|
| 2145 | - $survey_code = $temp_survey_code; |
|
| 2132 | + //An existing survey exists with the same code and the same language |
|
| 2133 | + if (Database::num_rows($result_check) == 1) { |
|
| 2134 | + switch ($this->file_option) { |
|
| 2135 | + case FILE_SKIP: |
|
| 2136 | + //Do nothing |
|
| 2137 | + break; |
|
| 2138 | + case FILE_RENAME: |
|
| 2139 | + $survey_code = $survey->code.'_'; |
|
| 2140 | + $i=1; |
|
| 2141 | + $temp_survey_code = $survey_code.$i; |
|
| 2142 | + while (!$this->is_survey_code_available($temp_survey_code)) { |
|
| 2143 | + $temp_survey_code = $survey_code.++$i; |
|
| 2144 | + } |
|
| 2145 | + $survey_code = $temp_survey_code; |
|
| 2146 | 2146 | |
| 2147 | 2147 | $params['code'] = $survey_code; |
| 2148 | 2148 | $new_id = Database::insert($table_sur, $params); |
@@ -2161,25 +2161,25 @@ discard block |
||
| 2161 | 2161 | Database::query($sql); |
| 2162 | 2162 | } |
| 2163 | 2163 | } |
| 2164 | - break; |
|
| 2165 | - case FILE_OVERWRITE: |
|
| 2166 | - // Delete the existing survey with the same code and language and import the one of the source course |
|
| 2167 | - // getting the information of the survey (used for when the survey is shared) |
|
| 2164 | + break; |
|
| 2165 | + case FILE_OVERWRITE: |
|
| 2166 | + // Delete the existing survey with the same code and language and import the one of the source course |
|
| 2167 | + // getting the information of the survey (used for when the survey is shared) |
|
| 2168 | 2168 | |
| 2169 | - $sql = "SELECT * FROM $table_sur |
|
| 2169 | + $sql = "SELECT * FROM $table_sur |
|
| 2170 | 2170 | WHERE |
| 2171 | 2171 | c_id = ".$this->destination_course_id." AND |
| 2172 | 2172 | survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'"; |
| 2173 | - $result = Database::query($sql); |
|
| 2174 | - $survey_data = Database::fetch_array($result,'ASSOC'); |
|
| 2173 | + $result = Database::query($sql); |
|
| 2174 | + $survey_data = Database::fetch_array($result,'ASSOC'); |
|
| 2175 | 2175 | |
| 2176 | - // if the survey is shared => also delete the shared content |
|
| 2177 | - if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) { |
|
| 2176 | + // if the survey is shared => also delete the shared content |
|
| 2177 | + if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) { |
|
| 2178 | 2178 | SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id); |
| 2179 | - } |
|
| 2180 | - SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id); |
|
| 2179 | + } |
|
| 2180 | + SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id); |
|
| 2181 | 2181 | |
| 2182 | - // Insert the new source survey |
|
| 2182 | + // Insert the new source survey |
|
| 2183 | 2183 | $new_id = Database::insert($table_sur, $params); |
| 2184 | 2184 | |
| 2185 | 2185 | if ($new_id) { |
@@ -2200,11 +2200,11 @@ discard block |
||
| 2200 | 2200 | Database::query($sql); |
| 2201 | 2201 | } |
| 2202 | 2202 | } |
| 2203 | - break; |
|
| 2204 | - default: |
|
| 2205 | - break; |
|
| 2206 | - } |
|
| 2207 | - } else { |
|
| 2203 | + break; |
|
| 2204 | + default: |
|
| 2205 | + break; |
|
| 2206 | + } |
|
| 2207 | + } else { |
|
| 2208 | 2208 | // No existing survey with the same language and the same code, we just copy the survey |
| 2209 | 2209 | $new_id = Database::insert($table_sur, $params); |
| 2210 | 2210 | |
@@ -2226,43 +2226,43 @@ discard block |
||
| 2226 | 2226 | Database::query($sql); |
| 2227 | 2227 | } |
| 2228 | 2228 | } |
| 2229 | - } |
|
| 2230 | - } |
|
| 2231 | - } |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - /** |
|
| 2235 | - * Check availability of a survey code |
|
| 2236 | - */ |
|
| 2229 | + } |
|
| 2230 | + } |
|
| 2231 | + } |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + /** |
|
| 2235 | + * Check availability of a survey code |
|
| 2236 | + */ |
|
| 2237 | 2237 | public function is_survey_code_available($survey_code) |
| 2238 | 2238 | { |
| 2239 | - $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
| 2240 | - $sql = "SELECT * FROM $table_sur |
|
| 2239 | + $table_sur = Database :: get_course_table(TABLE_SURVEY); |
|
| 2240 | + $sql = "SELECT * FROM $table_sur |
|
| 2241 | 2241 | WHERE |
| 2242 | 2242 | c_id = ".$this->destination_course_id." AND |
| 2243 | 2243 | code='".self::DBUTF8escapestring($survey_code)."'"; |
| 2244 | - $result = Database::query($sql); |
|
| 2245 | - if (Database::num_rows($result) > 0) return false; else return true; |
|
| 2246 | - } |
|
| 2244 | + $result = Database::query($sql); |
|
| 2245 | + if (Database::num_rows($result) > 0) return false; else return true; |
|
| 2246 | + } |
|
| 2247 | 2247 | |
| 2248 | - /** |
|
| 2249 | - * Restore survey-questions |
|
| 2250 | - */ |
|
| 2248 | + /** |
|
| 2249 | + * Restore survey-questions |
|
| 2250 | + */ |
|
| 2251 | 2251 | public function restore_survey_question($id, $survey_id) |
| 2252 | 2252 | { |
| 2253 | - $resources = $this->course->resources; |
|
| 2254 | - $question = $resources[RESOURCE_SURVEYQUESTION][$id]; |
|
| 2253 | + $resources = $this->course->resources; |
|
| 2254 | + $question = $resources[RESOURCE_SURVEYQUESTION][$id]; |
|
| 2255 | 2255 | |
| 2256 | - $new_id=0; |
|
| 2256 | + $new_id=0; |
|
| 2257 | 2257 | |
| 2258 | - if (is_object($question)) { |
|
| 2259 | - if ($question->is_restored()) { |
|
| 2260 | - return $question->destination_id; |
|
| 2261 | - } |
|
| 2262 | - $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
| 2263 | - $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
| 2258 | + if (is_object($question)) { |
|
| 2259 | + if ($question->is_restored()) { |
|
| 2260 | + return $question->destination_id; |
|
| 2261 | + } |
|
| 2262 | + $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); |
|
| 2263 | + $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); |
|
| 2264 | 2264 | |
| 2265 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2265 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2266 | 2266 | $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 2267 | 2267 | $question->survey_question, |
| 2268 | 2268 | $this->course->code, |
@@ -2316,10 +2316,10 @@ discard block |
||
| 2316 | 2316 | } |
| 2317 | 2317 | $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id; |
| 2318 | 2318 | } |
| 2319 | - } |
|
| 2319 | + } |
|
| 2320 | 2320 | |
| 2321 | - return $new_id; |
|
| 2322 | - } |
|
| 2321 | + return $new_id; |
|
| 2322 | + } |
|
| 2323 | 2323 | |
| 2324 | 2324 | /** |
| 2325 | 2325 | * Restoring learning paths |
@@ -2330,20 +2330,20 @@ discard block |
||
| 2330 | 2330 | { |
| 2331 | 2331 | $session_id = intval($session_id); |
| 2332 | 2332 | |
| 2333 | - if ($this->course->has_resources(RESOURCE_LEARNPATH)) { |
|
| 2333 | + if ($this->course->has_resources(RESOURCE_LEARNPATH)) { |
|
| 2334 | 2334 | $table_main = Database::get_course_table(TABLE_LP_MAIN); |
| 2335 | 2335 | $table_item = Database::get_course_table(TABLE_LP_ITEM); |
| 2336 | 2336 | $table_tool = Database::get_course_table(TABLE_TOOL_LIST); |
| 2337 | 2337 | |
| 2338 | - $resources = $this->course->resources; |
|
| 2338 | + $resources = $this->course->resources; |
|
| 2339 | 2339 | |
| 2340 | - $origin_path = $this->course->backup_path.'/upload/learning_path/images/'; |
|
| 2341 | - $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/'; |
|
| 2340 | + $origin_path = $this->course->backup_path.'/upload/learning_path/images/'; |
|
| 2341 | + $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/'; |
|
| 2342 | 2342 | |
| 2343 | - foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) { |
|
| 2343 | + foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) { |
|
| 2344 | 2344 | |
| 2345 | - $condition_session = ""; |
|
| 2346 | - if (!empty($session_id)) { |
|
| 2345 | + $condition_session = ""; |
|
| 2346 | + if (!empty($session_id)) { |
|
| 2347 | 2347 | if ($respect_base_content) { |
| 2348 | 2348 | $my_session_id = $lp->session_id; |
| 2349 | 2349 | if (!empty($lp->session_id)) { |
@@ -2354,21 +2354,21 @@ discard block |
||
| 2354 | 2354 | $session_id = intval($session_id); |
| 2355 | 2355 | $condition_session = $session_id; |
| 2356 | 2356 | } |
| 2357 | - } |
|
| 2358 | - |
|
| 2359 | - // Adding the author's image |
|
| 2360 | - if (!empty($lp->preview_image)) { |
|
| 2361 | - $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image)); |
|
| 2362 | - if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) { |
|
| 2363 | - $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename); |
|
| 2364 | - //$copy_result = true; |
|
| 2365 | - if ($copy_result) { |
|
| 2366 | - $lp->preview_image = $new_filename; |
|
| 2367 | - } else { |
|
| 2368 | - $lp->preview_image =''; |
|
| 2369 | - } |
|
| 2370 | - } |
|
| 2371 | - } |
|
| 2357 | + } |
|
| 2358 | + |
|
| 2359 | + // Adding the author's image |
|
| 2360 | + if (!empty($lp->preview_image)) { |
|
| 2361 | + $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image)); |
|
| 2362 | + if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) { |
|
| 2363 | + $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename); |
|
| 2364 | + //$copy_result = true; |
|
| 2365 | + if ($copy_result) { |
|
| 2366 | + $lp->preview_image = $new_filename; |
|
| 2367 | + } else { |
|
| 2368 | + $lp->preview_image =''; |
|
| 2369 | + } |
|
| 2370 | + } |
|
| 2371 | + } |
|
| 2372 | 2372 | |
| 2373 | 2373 | if ($this->add_text_in_items) { |
| 2374 | 2374 | $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix'); |
@@ -2415,7 +2415,7 @@ discard block |
||
| 2415 | 2415 | $params['session_id'] = $condition_session; |
| 2416 | 2416 | } |
| 2417 | 2417 | |
| 2418 | - $new_lp_id = Database::insert($table_main, $params); |
|
| 2418 | + $new_lp_id = Database::insert($table_main, $params); |
|
| 2419 | 2419 | |
| 2420 | 2420 | if ($new_lp_id) { |
| 2421 | 2421 | |
@@ -2476,13 +2476,13 @@ discard block |
||
| 2476 | 2476 | $old_refs = array(); |
| 2477 | 2477 | $prerequisite_ids = array(); |
| 2478 | 2478 | |
| 2479 | - foreach ($lp->get_items() as $index => $item) { |
|
| 2480 | - // we set the ref code here and then we update in a for loop |
|
| 2481 | - $ref = $item['ref']; |
|
| 2479 | + foreach ($lp->get_items() as $index => $item) { |
|
| 2480 | + // we set the ref code here and then we update in a for loop |
|
| 2481 | + $ref = $item['ref']; |
|
| 2482 | 2482 | |
| 2483 | - // Dealing with path the same way as ref as some data has |
|
| 2483 | + // Dealing with path the same way as ref as some data has |
|
| 2484 | 2484 | // been put into path when it's a local resource |
| 2485 | - // Only fix the path for no scos |
|
| 2485 | + // Only fix the path for no scos |
|
| 2486 | 2486 | if ($item['item_type'] == 'sco') { |
| 2487 | 2487 | $path = $item['path']; |
| 2488 | 2488 | } else { |
@@ -2511,128 +2511,128 @@ discard block |
||
| 2511 | 2511 | 'launch_data' => self::DBUTF8($item['launch_data']), |
| 2512 | 2512 | ]; |
| 2513 | 2513 | |
| 2514 | - $new_item_id = Database::insert($table_item, $params); |
|
| 2514 | + $new_item_id = Database::insert($table_item, $params); |
|
| 2515 | 2515 | |
| 2516 | 2516 | $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id"; |
| 2517 | 2517 | Database::query($sql); |
| 2518 | 2518 | |
| 2519 | - //save a link between old and new item IDs |
|
| 2520 | - $new_item_ids[$item['id']] = $new_item_id; |
|
| 2521 | - //save a reference of items that need a parent_item_id refresh |
|
| 2522 | - $parent_item_ids[$new_item_id] = $item['parent_item_id']; |
|
| 2523 | - //save a reference of items that need a previous_item_id refresh |
|
| 2524 | - $previous_item_ids[$new_item_id] = $item['previous_item_id']; |
|
| 2525 | - //save a reference of items that need a next_item_id refresh |
|
| 2526 | - $next_item_ids[$new_item_id] = $item['next_item_id']; |
|
| 2527 | - |
|
| 2528 | - if (!empty($item['prerequisite'])) { |
|
| 2529 | - if ($lp->lp_type =='2') { |
|
| 2530 | - // if is an sco |
|
| 2531 | - $old_prerequisite[$new_item_id]= $item['prerequisite']; |
|
| 2532 | - } else { |
|
| 2533 | - $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']]; |
|
| 2534 | - } |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - if (!empty($ref)) { |
|
| 2538 | - if ($lp->lp_type =='2') { |
|
| 2539 | - // if is an sco |
|
| 2540 | - $old_refs[$new_item_id]= $ref; |
|
| 2541 | - } else { |
|
| 2519 | + //save a link between old and new item IDs |
|
| 2520 | + $new_item_ids[$item['id']] = $new_item_id; |
|
| 2521 | + //save a reference of items that need a parent_item_id refresh |
|
| 2522 | + $parent_item_ids[$new_item_id] = $item['parent_item_id']; |
|
| 2523 | + //save a reference of items that need a previous_item_id refresh |
|
| 2524 | + $previous_item_ids[$new_item_id] = $item['previous_item_id']; |
|
| 2525 | + //save a reference of items that need a next_item_id refresh |
|
| 2526 | + $next_item_ids[$new_item_id] = $item['next_item_id']; |
|
| 2527 | + |
|
| 2528 | + if (!empty($item['prerequisite'])) { |
|
| 2529 | + if ($lp->lp_type =='2') { |
|
| 2530 | + // if is an sco |
|
| 2531 | + $old_prerequisite[$new_item_id]= $item['prerequisite']; |
|
| 2532 | + } else { |
|
| 2533 | + $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']]; |
|
| 2534 | + } |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + if (!empty($ref)) { |
|
| 2538 | + if ($lp->lp_type =='2') { |
|
| 2539 | + // if is an sco |
|
| 2540 | + $old_refs[$new_item_id]= $ref; |
|
| 2541 | + } else { |
|
| 2542 | 2542 | $old_refs[$new_item_id]= $new_item_ids[$ref]; |
| 2543 | - } |
|
| 2544 | - } |
|
| 2543 | + } |
|
| 2544 | + } |
|
| 2545 | 2545 | |
| 2546 | - $prerequisite_ids[$new_item_id] = $item['prerequisite']; |
|
| 2547 | - } |
|
| 2546 | + $prerequisite_ids[$new_item_id] = $item['prerequisite']; |
|
| 2547 | + } |
|
| 2548 | 2548 | |
| 2549 | - // Updating prerequisites |
|
| 2550 | - foreach ($old_prerequisite as $key=>$my_old_prerequisite) { |
|
| 2551 | - if($my_old_prerequisite != ''){ |
|
| 2552 | - $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."' |
|
| 2549 | + // Updating prerequisites |
|
| 2550 | + foreach ($old_prerequisite as $key=>$my_old_prerequisite) { |
|
| 2551 | + if($my_old_prerequisite != ''){ |
|
| 2552 | + $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."' |
|
| 2553 | 2553 | WHERE c_id = ".$this->destination_course_id." AND id = '".$key."' "; |
| 2554 | - Database::query($sql); |
|
| 2555 | - } |
|
| 2556 | - } |
|
| 2557 | - |
|
| 2558 | - // Updating refs |
|
| 2559 | - foreach ($old_refs as $key=>$my_old_ref) { |
|
| 2560 | - if ($my_old_ref != '') { |
|
| 2561 | - $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."' |
|
| 2554 | + Database::query($sql); |
|
| 2555 | + } |
|
| 2556 | + } |
|
| 2557 | + |
|
| 2558 | + // Updating refs |
|
| 2559 | + foreach ($old_refs as $key=>$my_old_ref) { |
|
| 2560 | + if ($my_old_ref != '') { |
|
| 2561 | + $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."' |
|
| 2562 | 2562 | WHERE c_id = ".$this->destination_course_id." AND id = '".$key."' "; |
| 2563 | - Database::query($sql); |
|
| 2564 | - } |
|
| 2565 | - } |
|
| 2566 | - |
|
| 2567 | - foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) { |
|
| 2568 | - $parent_new_id = 0; |
|
| 2569 | - if($parent_item_old_id != 0){ |
|
| 2570 | - $parent_new_id = $new_item_ids[$parent_item_old_id]; |
|
| 2571 | - } |
|
| 2572 | - $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."' |
|
| 2563 | + Database::query($sql); |
|
| 2564 | + } |
|
| 2565 | + } |
|
| 2566 | + |
|
| 2567 | + foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) { |
|
| 2568 | + $parent_new_id = 0; |
|
| 2569 | + if($parent_item_old_id != 0){ |
|
| 2570 | + $parent_new_id = $new_item_ids[$parent_item_old_id]; |
|
| 2571 | + } |
|
| 2572 | + $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."' |
|
| 2573 | 2573 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
| 2574 | - Database::query($sql); |
|
| 2575 | - } |
|
| 2576 | - foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) { |
|
| 2577 | - $previous_new_id = 0; |
|
| 2578 | - if($previous_item_old_id != 0){ |
|
| 2579 | - $previous_new_id = $new_item_ids[$previous_item_old_id]; |
|
| 2580 | - } |
|
| 2581 | - $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."' |
|
| 2574 | + Database::query($sql); |
|
| 2575 | + } |
|
| 2576 | + foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) { |
|
| 2577 | + $previous_new_id = 0; |
|
| 2578 | + if($previous_item_old_id != 0){ |
|
| 2579 | + $previous_new_id = $new_item_ids[$previous_item_old_id]; |
|
| 2580 | + } |
|
| 2581 | + $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."' |
|
| 2582 | 2582 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
| 2583 | - Database::query($sql); |
|
| 2584 | - } |
|
| 2585 | - |
|
| 2586 | - foreach ($next_item_ids as $new_item_id => $next_item_old_id) { |
|
| 2587 | - $next_new_id = 0; |
|
| 2588 | - if($next_item_old_id != 0){ |
|
| 2589 | - $next_new_id = $new_item_ids[$next_item_old_id]; |
|
| 2590 | - } |
|
| 2591 | - $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."' |
|
| 2583 | + Database::query($sql); |
|
| 2584 | + } |
|
| 2585 | + |
|
| 2586 | + foreach ($next_item_ids as $new_item_id => $next_item_old_id) { |
|
| 2587 | + $next_new_id = 0; |
|
| 2588 | + if($next_item_old_id != 0){ |
|
| 2589 | + $next_new_id = $new_item_ids[$next_item_old_id]; |
|
| 2590 | + } |
|
| 2591 | + $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."' |
|
| 2592 | 2592 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
| 2593 | - Database::query($sql); |
|
| 2594 | - } |
|
| 2595 | - |
|
| 2596 | - foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) { |
|
| 2597 | - $prerequisite_new_id = 0; |
|
| 2598 | - if($prerequisite_old_id != 0){ |
|
| 2599 | - $prerequisite_new_id = $new_item_ids[$prerequisite_old_id]; |
|
| 2600 | - } |
|
| 2601 | - $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."' |
|
| 2593 | + Database::query($sql); |
|
| 2594 | + } |
|
| 2595 | + |
|
| 2596 | + foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) { |
|
| 2597 | + $prerequisite_new_id = 0; |
|
| 2598 | + if($prerequisite_old_id != 0){ |
|
| 2599 | + $prerequisite_new_id = $new_item_ids[$prerequisite_old_id]; |
|
| 2600 | + } |
|
| 2601 | + $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."' |
|
| 2602 | 2602 | WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'"; |
| 2603 | - Database::query($sql); |
|
| 2604 | - } |
|
| 2605 | - $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id; |
|
| 2606 | - } |
|
| 2607 | - } |
|
| 2608 | - } |
|
| 2609 | - |
|
| 2610 | - /** |
|
| 2611 | - * Restore works |
|
| 2603 | + Database::query($sql); |
|
| 2604 | + } |
|
| 2605 | + $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id; |
|
| 2606 | + } |
|
| 2607 | + } |
|
| 2608 | + } |
|
| 2609 | + |
|
| 2610 | + /** |
|
| 2611 | + * Restore works |
|
| 2612 | 2612 | * @deprecated use restore_works |
| 2613 | 2613 | * |
| 2614 | - */ |
|
| 2615 | - public function restore_student_publication($sessionId = 0) |
|
| 2614 | + */ |
|
| 2615 | + public function restore_student_publication($sessionId = 0) |
|
| 2616 | 2616 | { |
| 2617 | 2617 | $sessionId = intval($sessionId); |
| 2618 | - $work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); |
|
| 2619 | - $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
| 2620 | - $item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
| 2618 | + $work_assignment_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT); |
|
| 2619 | + $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); |
|
| 2620 | + $item_property_table = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
| 2621 | 2621 | |
| 2622 | - // Query in student publication |
|
| 2623 | - $sql = 'SELECT * FROM '.$work_table.' |
|
| 2622 | + // Query in student publication |
|
| 2623 | + $sql = 'SELECT * FROM '.$work_table.' |
|
| 2624 | 2624 | WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) '; |
| 2625 | 2625 | |
| 2626 | - $result = Database::query($sql); |
|
| 2627 | - $folders = Database::store_result($result, 'ASSOC'); |
|
| 2626 | + $result = Database::query($sql); |
|
| 2627 | + $folders = Database::store_result($result, 'ASSOC'); |
|
| 2628 | 2628 | |
| 2629 | - foreach ($folders as $folder) { |
|
| 2630 | - $old_id = $folder['id']; |
|
| 2629 | + foreach ($folders as $folder) { |
|
| 2630 | + $old_id = $folder['id']; |
|
| 2631 | 2631 | unset($folder['id']); |
| 2632 | - $folder['c_id'] = $this->destination_course_id; |
|
| 2632 | + $folder['c_id'] = $this->destination_course_id; |
|
| 2633 | 2633 | $folder['parent_id'] = 0; |
| 2634 | 2634 | $folder['session_id'] = $sessionId; |
| 2635 | - $new_id = Database::insert($work_table, $folder); |
|
| 2635 | + $new_id = Database::insert($work_table, $folder); |
|
| 2636 | 2636 | |
| 2637 | 2637 | if ($new_id) { |
| 2638 | 2638 | //query in item property |
@@ -2691,21 +2691,21 @@ discard block |
||
| 2691 | 2691 | } |
| 2692 | 2692 | } |
| 2693 | 2693 | } |
| 2694 | - } |
|
| 2694 | + } |
|
| 2695 | 2695 | |
| 2696 | - $destination = '../../courses/'.$this->course->destination_path.'/work/'; |
|
| 2697 | - $origin = '../../courses/'.$this->course->info['path'].'/work/'; |
|
| 2698 | - self::allow_create_all_directory($origin,$destination,false); |
|
| 2699 | - } |
|
| 2696 | + $destination = '../../courses/'.$this->course->destination_path.'/work/'; |
|
| 2697 | + $origin = '../../courses/'.$this->course->info['path'].'/work/'; |
|
| 2698 | + self::allow_create_all_directory($origin,$destination,false); |
|
| 2699 | + } |
|
| 2700 | 2700 | |
| 2701 | 2701 | /** |
| 2702 | - * copy all directory and sub directory |
|
| 2703 | - * @param string The path origin |
|
| 2704 | - * @param string The path destination |
|
| 2705 | - * @param boolean Option Overwrite |
|
| 2706 | - * @return void() |
|
| 2707 | - * @deprecated |
|
| 2708 | - */ |
|
| 2702 | + * copy all directory and sub directory |
|
| 2703 | + * @param string The path origin |
|
| 2704 | + * @param string The path destination |
|
| 2705 | + * @param boolean Option Overwrite |
|
| 2706 | + * @return void() |
|
| 2707 | + * @deprecated |
|
| 2708 | + */ |
|
| 2709 | 2709 | public function allow_create_all_directory($source, $dest, $overwrite = false) |
| 2710 | 2710 | { |
| 2711 | 2711 | if (!is_dir($dest)) { |
@@ -2716,14 +2716,14 @@ discard block |
||
| 2716 | 2716 | if ($file != '.' && $file != '..') { |
| 2717 | 2717 | $path = $source . '/' . $file; |
| 2718 | 2718 | if (is_file($path)) { |
| 2719 | - /* if (!is_file($dest . '/' . $file) || $overwrite) |
|
| 2719 | + /* if (!is_file($dest . '/' . $file) || $overwrite) |
|
| 2720 | 2720 | if (!@copy($path, $dest . '/' . $file)) { |
| 2721 | 2721 | echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>'; |
| 2722 | 2722 | }*/ |
| 2723 | 2723 | } elseif(is_dir($path)) { |
| 2724 | 2724 | if (!is_dir($dest . '/' . $file)) |
| 2725 | 2725 | mkdir($dest . '/' . $file); |
| 2726 | - self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite); |
|
| 2726 | + self:: allow_create_all_directory($path, $dest . '/' . $file, $overwrite); |
|
| 2727 | 2727 | } |
| 2728 | 2728 | } |
| 2729 | 2729 | } |
@@ -2731,12 +2731,12 @@ discard block |
||
| 2731 | 2731 | } |
| 2732 | 2732 | } |
| 2733 | 2733 | |
| 2734 | - /** |
|
| 2735 | - * Gets the new ID of one specific tool item from the tool name and the old ID |
|
| 2736 | - * @param string Tool name |
|
| 2737 | - * @param integer Old ID |
|
| 2738 | - * @return integer New ID |
|
| 2739 | - */ |
|
| 2734 | + /** |
|
| 2735 | + * Gets the new ID of one specific tool item from the tool name and the old ID |
|
| 2736 | + * @param string Tool name |
|
| 2737 | + * @param integer Old ID |
|
| 2738 | + * @return integer New ID |
|
| 2739 | + */ |
|
| 2740 | 2740 | public function get_new_id($tool, $ref) |
| 2741 | 2741 | { |
| 2742 | 2742 | // Check if the value exist in the current array. |
@@ -2758,25 +2758,25 @@ discard block |
||
| 2758 | 2758 | } |
| 2759 | 2759 | |
| 2760 | 2760 | return ''; |
| 2761 | - } |
|
| 2761 | + } |
|
| 2762 | 2762 | |
| 2763 | - /** |
|
| 2764 | - * Restore glossary |
|
| 2765 | - */ |
|
| 2763 | + /** |
|
| 2764 | + * Restore glossary |
|
| 2765 | + */ |
|
| 2766 | 2766 | public function restore_glossary($session_id = 0) |
| 2767 | 2767 | { |
| 2768 | - if ($this->course->has_resources(RESOURCE_GLOSSARY)) { |
|
| 2769 | - $table_glossary = Database :: get_course_table(TABLE_GLOSSARY); |
|
| 2770 | - $resources = $this->course->resources; |
|
| 2771 | - foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) { |
|
| 2768 | + if ($this->course->has_resources(RESOURCE_GLOSSARY)) { |
|
| 2769 | + $table_glossary = Database :: get_course_table(TABLE_GLOSSARY); |
|
| 2770 | + $resources = $this->course->resources; |
|
| 2771 | + foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) { |
|
| 2772 | 2772 | |
| 2773 | 2773 | $params = []; |
| 2774 | - if (!empty($session_id)) { |
|
| 2775 | - $session_id = intval($session_id); |
|
| 2774 | + if (!empty($session_id)) { |
|
| 2775 | + $session_id = intval($session_id); |
|
| 2776 | 2776 | $params['session_id'] = $session_id; |
| 2777 | - } |
|
| 2777 | + } |
|
| 2778 | 2778 | |
| 2779 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2779 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2780 | 2780 | $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 2781 | 2781 | $glossary->description, |
| 2782 | 2782 | $this->course->code, |
@@ -2810,27 +2810,27 @@ discard block |
||
| 2810 | 2810 | |
| 2811 | 2811 | $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id; |
| 2812 | 2812 | } |
| 2813 | - } |
|
| 2814 | - } |
|
| 2815 | - } |
|
| 2813 | + } |
|
| 2814 | + } |
|
| 2815 | + } |
|
| 2816 | 2816 | |
| 2817 | 2817 | /** |
| 2818 | 2818 | * @param int $session_id |
| 2819 | 2819 | */ |
| 2820 | 2820 | public function restore_wiki($session_id = 0) |
| 2821 | 2821 | { |
| 2822 | - if ($this->course->has_resources(RESOURCE_WIKI)) { |
|
| 2823 | - // wiki table of the target course |
|
| 2824 | - $table_wiki = Database :: get_course_table(TABLE_WIKI); |
|
| 2825 | - $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF); |
|
| 2822 | + if ($this->course->has_resources(RESOURCE_WIKI)) { |
|
| 2823 | + // wiki table of the target course |
|
| 2824 | + $table_wiki = Database :: get_course_table(TABLE_WIKI); |
|
| 2825 | + $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF); |
|
| 2826 | 2826 | |
| 2827 | - // storing all the resources that have to be copied in an array |
|
| 2828 | - $resources = $this->course->resources; |
|
| 2827 | + // storing all the resources that have to be copied in an array |
|
| 2828 | + $resources = $this->course->resources; |
|
| 2829 | 2829 | |
| 2830 | - foreach ($resources[RESOURCE_WIKI] as $id => $wiki) { |
|
| 2831 | - // the sql statement to insert the groups from the old course to the new course |
|
| 2830 | + foreach ($resources[RESOURCE_WIKI] as $id => $wiki) { |
|
| 2831 | + // the sql statement to insert the groups from the old course to the new course |
|
| 2832 | 2832 | |
| 2833 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2833 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2834 | 2834 | $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 2835 | 2835 | $wiki->content, |
| 2836 | 2836 | $this->course->code, |
@@ -2853,7 +2853,7 @@ discard block |
||
| 2853 | 2853 | 'session_id' => !empty($session_id) ? intval($session_id) : 0, |
| 2854 | 2854 | ]; |
| 2855 | 2855 | |
| 2856 | - $new_id = Database::insert($table_wiki, $params); |
|
| 2856 | + $new_id = Database::insert($table_wiki, $params); |
|
| 2857 | 2857 | |
| 2858 | 2858 | if ($new_id) { |
| 2859 | 2859 | |
@@ -2884,9 +2884,9 @@ discard block |
||
| 2884 | 2884 | |
| 2885 | 2885 | Database::insert($table_wiki_conf, $params); |
| 2886 | 2886 | } |
| 2887 | - } |
|
| 2888 | - } |
|
| 2889 | - } |
|
| 2887 | + } |
|
| 2888 | + } |
|
| 2889 | + } |
|
| 2890 | 2890 | |
| 2891 | 2891 | /** |
| 2892 | 2892 | * Restore Thematics |
@@ -2894,15 +2894,15 @@ discard block |
||
| 2894 | 2894 | */ |
| 2895 | 2895 | public function restore_thematic($session_id = 0) |
| 2896 | 2896 | { |
| 2897 | - if ($this->course->has_resources(RESOURCE_THEMATIC)) { |
|
| 2897 | + if ($this->course->has_resources(RESOURCE_THEMATIC)) { |
|
| 2898 | 2898 | $table_thematic = Database:: get_course_table(TABLE_THEMATIC); |
| 2899 | 2899 | $table_thematic_advance = Database:: get_course_table(TABLE_THEMATIC_ADVANCE); |
| 2900 | 2900 | $table_thematic_plan = Database:: get_course_table(TABLE_THEMATIC_PLAN); |
| 2901 | 2901 | |
| 2902 | - $resources = $this->course->resources; |
|
| 2903 | - foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) { |
|
| 2902 | + $resources = $this->course->resources; |
|
| 2903 | + foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) { |
|
| 2904 | 2904 | |
| 2905 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2905 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2906 | 2906 | $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 2907 | 2907 | $thematic->params['content'], |
| 2908 | 2908 | $this->course->code, |
@@ -2910,13 +2910,13 @@ discard block |
||
| 2910 | 2910 | $this->course->backup_path, |
| 2911 | 2911 | $this->course->info['path'] |
| 2912 | 2912 | ); |
| 2913 | - $thematic->params['c_id'] = $this->destination_course_id; |
|
| 2914 | - unset($thematic->params['id']); |
|
| 2913 | + $thematic->params['c_id'] = $this->destination_course_id; |
|
| 2914 | + unset($thematic->params['id']); |
|
| 2915 | 2915 | unset($thematic->params['iid']); |
| 2916 | 2916 | |
| 2917 | - $last_id = Database::insert($table_thematic, $thematic->params, false); |
|
| 2917 | + $last_id = Database::insert($table_thematic, $thematic->params, false); |
|
| 2918 | 2918 | |
| 2919 | - if ($last_id) { |
|
| 2919 | + if ($last_id) { |
|
| 2920 | 2920 | |
| 2921 | 2921 | $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id"; |
| 2922 | 2922 | Database::query($sql); |
@@ -2929,19 +2929,19 @@ discard block |
||
| 2929 | 2929 | api_get_user_id() |
| 2930 | 2930 | ); |
| 2931 | 2931 | |
| 2932 | - foreach ($thematic->thematic_advance_list as $thematic_advance) { |
|
| 2933 | - unset($thematic_advance['id']); |
|
| 2932 | + foreach ($thematic->thematic_advance_list as $thematic_advance) { |
|
| 2933 | + unset($thematic_advance['id']); |
|
| 2934 | 2934 | unset($thematic_advance['iid']); |
| 2935 | - $thematic_advance['attendance_id'] = 0; |
|
| 2936 | - $thematic_advance['thematic_id'] = $last_id; |
|
| 2937 | - $thematic_advance['c_id'] = $this->destination_course_id; |
|
| 2935 | + $thematic_advance['attendance_id'] = 0; |
|
| 2936 | + $thematic_advance['thematic_id'] = $last_id; |
|
| 2937 | + $thematic_advance['c_id'] = $this->destination_course_id; |
|
| 2938 | 2938 | $my_id = Database::insert( |
| 2939 | 2939 | $table_thematic_advance, |
| 2940 | 2940 | $thematic_advance, |
| 2941 | 2941 | false |
| 2942 | 2942 | ); |
| 2943 | 2943 | |
| 2944 | - if ($my_id) { |
|
| 2944 | + if ($my_id) { |
|
| 2945 | 2945 | |
| 2946 | 2946 | $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id"; |
| 2947 | 2947 | Database::query($sql); |
@@ -2953,17 +2953,17 @@ discard block |
||
| 2953 | 2953 | "ThematicAdvanceAdded", |
| 2954 | 2954 | api_get_user_id() |
| 2955 | 2955 | ); |
| 2956 | - } |
|
| 2957 | - } |
|
| 2956 | + } |
|
| 2957 | + } |
|
| 2958 | 2958 | |
| 2959 | - foreach($thematic->thematic_plan_list as $thematic_plan) { |
|
| 2960 | - unset($thematic_plan['id']); |
|
| 2959 | + foreach($thematic->thematic_plan_list as $thematic_plan) { |
|
| 2960 | + unset($thematic_plan['id']); |
|
| 2961 | 2961 | unset($thematic_plan['iid']); |
| 2962 | - $thematic_plan['thematic_id'] = $last_id; |
|
| 2963 | - $thematic_plan['c_id'] = $this->destination_course_id; |
|
| 2964 | - $my_id = Database::insert($table_thematic_plan, $thematic_plan, false); |
|
| 2962 | + $thematic_plan['thematic_id'] = $last_id; |
|
| 2963 | + $thematic_plan['c_id'] = $this->destination_course_id; |
|
| 2964 | + $my_id = Database::insert($table_thematic_plan, $thematic_plan, false); |
|
| 2965 | 2965 | |
| 2966 | - if ($my_id) { |
|
| 2966 | + if ($my_id) { |
|
| 2967 | 2967 | |
| 2968 | 2968 | $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id"; |
| 2969 | 2969 | Database::query($sql); |
@@ -2975,12 +2975,12 @@ discard block |
||
| 2975 | 2975 | "ThematicPlanAdded", |
| 2976 | 2976 | api_get_user_id() |
| 2977 | 2977 | ); |
| 2978 | - } |
|
| 2979 | - } |
|
| 2980 | - } |
|
| 2981 | - } |
|
| 2982 | - } |
|
| 2983 | - } |
|
| 2978 | + } |
|
| 2979 | + } |
|
| 2980 | + } |
|
| 2981 | + } |
|
| 2982 | + } |
|
| 2983 | + } |
|
| 2984 | 2984 | |
| 2985 | 2985 | /** |
| 2986 | 2986 | * Restore Attendance |
@@ -2988,14 +2988,14 @@ discard block |
||
| 2988 | 2988 | */ |
| 2989 | 2989 | public function restore_attendance($session_id = 0) |
| 2990 | 2990 | { |
| 2991 | - if ($this->course->has_resources(RESOURCE_ATTENDANCE)) { |
|
| 2992 | - $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
| 2993 | - $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 2991 | + if ($this->course->has_resources(RESOURCE_ATTENDANCE)) { |
|
| 2992 | + $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE); |
|
| 2993 | + $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
| 2994 | 2994 | |
| 2995 | - $resources = $this->course->resources; |
|
| 2996 | - foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) { |
|
| 2995 | + $resources = $this->course->resources; |
|
| 2996 | + foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) { |
|
| 2997 | 2997 | |
| 2998 | - // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2998 | + // check resources inside html from ckeditor tool and copy correct urls into recipient course |
|
| 2999 | 2999 | $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
| 3000 | 3000 | $obj->params['description'], |
| 3001 | 3001 | $this->course->code, |
@@ -3007,11 +3007,11 @@ discard block |
||
| 3007 | 3007 | unset($obj->params['id']); |
| 3008 | 3008 | unset($obj->params['iid']); |
| 3009 | 3009 | |
| 3010 | - $obj->params['c_id'] = $this->destination_course_id; |
|
| 3010 | + $obj->params['c_id'] = $this->destination_course_id; |
|
| 3011 | 3011 | |
| 3012 | - $last_id = Database::insert($table_attendance, $obj->params); |
|
| 3012 | + $last_id = Database::insert($table_attendance, $obj->params); |
|
| 3013 | 3013 | |
| 3014 | - if (is_numeric($last_id)) { |
|
| 3014 | + if (is_numeric($last_id)) { |
|
| 3015 | 3015 | |
| 3016 | 3016 | $sql = "UPDATE $table_attendance SET id = iid WHERE iid = $last_id"; |
| 3017 | 3017 | Database::query($sql); |
@@ -3025,11 +3025,11 @@ discard block |
||
| 3025 | 3025 | ); |
| 3026 | 3026 | |
| 3027 | 3027 | foreach ($obj->attendance_calendar as $attendance_calendar) { |
| 3028 | - unset($attendance_calendar['id']); |
|
| 3028 | + unset($attendance_calendar['id']); |
|
| 3029 | 3029 | unset($attendance_calendar['iid']); |
| 3030 | 3030 | |
| 3031 | - $attendance_calendar['attendance_id'] = $last_id; |
|
| 3032 | - $attendance_calendar['c_id'] = $this->destination_course_id; |
|
| 3031 | + $attendance_calendar['attendance_id'] = $last_id; |
|
| 3032 | + $attendance_calendar['c_id'] = $this->destination_course_id; |
|
| 3033 | 3033 | $attendanceCalendarId = Database::insert( |
| 3034 | 3034 | $table_attendance_calendar, |
| 3035 | 3035 | $attendance_calendar |
@@ -3037,11 +3037,11 @@ discard block |
||
| 3037 | 3037 | |
| 3038 | 3038 | $sql = "UPDATE $table_attendance_calendar SET id = iid WHERE iid = $attendanceCalendarId"; |
| 3039 | 3039 | Database::query($sql); |
| 3040 | - } |
|
| 3041 | - } |
|
| 3042 | - } |
|
| 3043 | - } |
|
| 3044 | - } |
|
| 3040 | + } |
|
| 3041 | + } |
|
| 3042 | + } |
|
| 3043 | + } |
|
| 3044 | + } |
|
| 3045 | 3045 | |
| 3046 | 3046 | /** |
| 3047 | 3047 | * Restore Works |
@@ -3183,11 +3183,11 @@ discard block |
||
| 3183 | 3183 | */ |
| 3184 | 3184 | public function DBUTF8($str) |
| 3185 | 3185 | { |
| 3186 | - if (UTF8_CONVERT) { |
|
| 3186 | + if (UTF8_CONVERT) { |
|
| 3187 | 3187 | $str = utf8_encode($str); |
| 3188 | 3188 | } |
| 3189 | - return $str; |
|
| 3190 | - } |
|
| 3189 | + return $str; |
|
| 3190 | + } |
|
| 3191 | 3191 | |
| 3192 | 3192 | /** |
| 3193 | 3193 | * @param string $str |
@@ -3198,8 +3198,8 @@ discard block |
||
| 3198 | 3198 | if (UTF8_CONVERT) { |
| 3199 | 3199 | $str = utf8_encode($str); |
| 3200 | 3200 | } |
| 3201 | - return Database::escape_string($str); |
|
| 3202 | - } |
|
| 3201 | + return Database::escape_string($str); |
|
| 3202 | + } |
|
| 3203 | 3203 | |
| 3204 | 3204 | /** |
| 3205 | 3205 | * @param array $array |