diff --git a/main/coursecopy/classes/CourseArchiver.class.php b/main/coursecopy/classes/CourseArchiver.class.php
index 2e3a10e24d..5b00889b03 100644
--- a/main/coursecopy/classes/CourseArchiver.class.php
+++ b/main/coursecopy/classes/CourseArchiver.class.php
@@ -3,7 +3,6 @@
/* For licensing terms, see /license.txt */
require_once 'Course.class.php';
-require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
/**
* Some functions to write a course-object to a zip-file and to read a course-
@@ -18,7 +17,7 @@ class CourseArchiver {
/**
* Delete old temp-dirs
*/
- function clean_backup_dir() {
+ static function clean_backup_dir() {
$dir = api_get_path(SYS_ARCHIVE_PATH);
if ($handle = @ opendir($dir)) {
while (($file = readdir($handle)) !== false) {
@@ -69,7 +68,9 @@ class CourseArchiver {
if ($res === false) {
error_log(__FILE__ . ' line ' . __LINE__ . ': ' . (ini_get('track_errors') != false ? $php_errormsg : 'error not recorded because track_errors is off in your php.ini'), 0);
}
-
+
+ //Documents
+
// Copy all documents to the temp-dir
if (is_array($course->resources[RESOURCE_DOCUMENT])) {
foreach ($course->resources[RESOURCE_DOCUMENT] as $id => $document) {
@@ -156,7 +157,7 @@ class CourseArchiver {
/**
*
*/
- function import_uploaded_file($file) {
+ static function import_uploaded_file($file) {
$new_filename = uniqid('') . '.zip';
$new_dir = api_get_path(SYS_ARCHIVE_PATH);
if (is_dir($new_dir) && is_writable($new_dir)) {
@@ -172,7 +173,7 @@ class CourseArchiver {
* @param boolean $delete Delete the file after reading the course?
* @todo Check if the archive is a correct Chamilo-export
*/
- function read_course($filename, $delete = false) {
+ static function read_course($filename, $delete = false) {
CourseArchiver::clean_backup_dir();
// Create a temp directory
$tmp_dir_name = 'CourseArchiver_' . uniqid('');
diff --git a/main/coursecopy/classes/CourseBuilder.class.php b/main/coursecopy/classes/CourseBuilder.class.php
index 95b14c33df..1040d64651 100644
--- a/main/coursecopy/classes/CourseBuilder.class.php
+++ b/main/coursecopy/classes/CourseBuilder.class.php
@@ -34,19 +34,24 @@ class CourseBuilder {
var $course;
/* With this array you can filter the tools you want to be parsed by default all tools are included*/
- var $tools_to_build = array('events',
+ var $tools_to_build = array(
'announcements',
- 'tool_intro',
- 'surveys',
+ 'attendance',
+ 'course_descriptions',
'documents',
- 'quizzes',
+ 'events',
+ 'forum_category',
+ 'forums',
+ 'forum_topics',
'glossary',
+ 'quizzes',
'learnpaths',
'links',
- 'course_descriptions',
- 'wiki',
+ 'surveys',
+ 'tool_intro',
'thematic',
- 'attendance');
+ 'wiki'
+ );
/* With this array you can filter wich elements of the tools are going to be added in the course obj (only works with LPs) */
var $specific_id_list = array();
@@ -111,7 +116,7 @@ class CourseBuilder {
$course_id = $course_info['real_id'];
foreach ($this->tools_to_build as $tool) {
- $function_build = 'build_'.$tool;
+ $function_build = 'build_'.$tool;
$this->$function_build($session_id, $course_code, $with_base_content, $this->specific_id_list[$tool]);
}
@@ -256,49 +261,59 @@ class CourseBuilder {
}
}
}
+
/**
* Build the forums
*/
- function build_forums($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
+ function build_forums($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) {
+ $course_info = api_get_course_info($course_code);
+ $course_id = $course_info['real_id'];
+
$table = Database :: get_course_table(TABLE_FORUM);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
+
+ $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
+ $sql .= " ORDER BY forum_title, forum_category";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
- $forum = new Forum($obj->forum_id, $obj->forum_title, $obj->forum_comment, $obj->forum_category, $obj->forum_last_post, $obj->forum_threads, $obj->forum_posts, $obj->allow_anonymous, $obj->allow_edit, $obj->approval_direct_post, $obj->allow_attachements, $obj->allow_new_threads, $obj->default_view, $obj->forum_of_group, $obj->forum_group_public_private, $obj->forum_order, $obj->locked, $obj->session_id, $obj->forum_image);
- $this->course->add_resource($forum);
- $this->build_forum_category($obj->forum_category);
+ //$forum = new Forum($obj->forum_id, $obj->forum_title, $obj->forum_comment, $obj->forum_category, $obj->forum_last_post, $obj->forum_threads, $obj->forum_posts, $obj->allow_anonymous, $obj->allow_edit, $obj->approval_direct_post, $obj->allow_attachements, $obj->allow_new_threads, $obj->default_view, $obj->forum_of_group, $obj->forum_group_public_private, $obj->forum_order, $obj->locked, $obj->session_id, $obj->forum_image);
+ $forum = new Forum($obj);
+ $this->course->add_resource($forum);
}
- $this->build_forum_topics();
- $this->build_forum_posts();
+ //$this->build_forum_topics();
+ //$this->build_forum_posts();
}
/**
* Build a forum-category
*/
- function build_forum_category($id) {
+ function build_forum_category($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) {
$table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $table WHERE c_id = $course_id AND cat_id = $id";
+ $course_info = api_get_course_info($course_code);
+ $course_id = $course_info['real_id'];
+
+ $sql = "SELECT * FROM $table WHERE c_id = $course_id ORDER BY cat_title";
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
- $forum_category = new ForumCategory($obj->cat_id, $obj->cat_title, $obj->cat_comment, $obj->cat_order, $obj->locked, $obj->session_id);
- $this->course->add_resource($forum_category);
+ //$forum_category = new ForumCategory($obj->cat_id, $obj->cat_title, $obj->cat_comment, $obj->cat_order, $obj->locked, $obj->session_id);
+ $forum_category = new ForumCategory($obj);
+ $this->course->add_resource($forum_category);
}
}
/**
* Build the forum-topics
*/
- function build_forum_topics() {
+ function build_forum_topics($session_id = 0, $course_code = null, $with_base_content = false, $id_list = array()) {
$table = Database :: get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
+ $course_info = api_get_course_info($course_code);
+ $course_id = $course_info['real_id'];
+ $sql = "SELECT * FROM $table WHERE c_id = $course_id ORDER BY thread_title ";
$db_result = Database::query($sql);
- while ($obj = Database::fetch_object($db_result))
- {
- $forum_topic = new ForumTopic($obj->thread_id, $obj->thread_title, $obj->thread_date, $obj->thread_poster_id, $obj->thread_poster_name, $obj->forum_id, $obj->thread_last_post, $obj->thread_replies, $obj->thread_views, $obj->thread_sticky, $obj->locked, $obj->thread_close_date, $obj->thread_weight, $obj->thread_title_qualify, $obj->thread_qualify_max);
+ while ($obj = Database::fetch_object($db_result)) {
+ //$forum_topic = new ForumTopic($obj->thread_id, $obj->thread_title, $obj->thread_date, $obj->thread_poster_id, $obj->thread_poster_name, $obj->forum_id, $obj->thread_last_post, $obj->thread_replies, $obj->thread_views, $obj->thread_sticky, $obj->locked, $obj->thread_close_date, $obj->thread_weight, $obj->thread_title_qualify, $obj->thread_qualify_max);
+ $forum_topic = new ForumTopic($obj);
$this->course->add_resource($forum_topic);
+ $this->build_forum_posts($obj->thread_id, $obj->forum_id);
}
}
@@ -306,13 +321,18 @@ class CourseBuilder {
* Build the forum-posts
* TODO: All tree structure of posts should be built, attachments for example.
*/
- function build_forum_posts() {
+ function build_forum_posts($thread_id = null, $forum_id = null) {
$table = Database :: get_course_table(TABLE_FORUM_POST);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $table WHERE c_id = $course_id ";
+ if (!empty($thread_id) && !empty($forum_id)) {
+ $forum_id = intval($forum_id);
+ $thread_id = intval($thread_id);
+ $sql .= " AND thread_id = $thread_id AND forum_id = $forum_id ";
+ }
$db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) {
- $forum_post = new ForumPost($obj->post_id, $obj->post_title, $obj->post_text, $obj->post_date, $obj->poster_id, $obj->poster_name, $obj->post_notification, $obj->post_parent_id, $obj->thread_id, $obj->forum_id, $obj->visible);
+ $forum_post = new ForumPost($obj);
$this->course->add_resource($forum_post);
}
}
@@ -322,8 +342,7 @@ class CourseBuilder {
*/
function build_links($session_id = 0, $course_code = '', $with_base_content = false, $id_list = array()) {
$course_info = api_get_course_info($course_code);
- $course_id = $course_info['real_id'];
-
+ $course_id = $course_info['real_id'];
$table = Database :: get_course_table(TABLE_LINK);
$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
@@ -362,6 +381,7 @@ class CourseBuilder {
}
}
}
+
/**
* Build tool intro
*/
@@ -375,6 +395,7 @@ class CourseBuilder {
$this->course->add_resource($tool_intro);
}
}
+
/**
* Build a link category
*/
@@ -393,6 +414,7 @@ class CourseBuilder {
}
return 0;
}
+
/**
* Build the Quizzes
*/
diff --git a/main/coursecopy/classes/CourseRecycler.class.php b/main/coursecopy/classes/CourseRecycler.class.php
index 46fc92cea8..941bb09939 100644
--- a/main/coursecopy/classes/CourseRecycler.class.php
+++ b/main/coursecopy/classes/CourseRecycler.class.php
@@ -138,7 +138,7 @@ class CourseRecycler
if ($this->course->has_resources(RESOURCE_FORUMCATEGORY)) {
$table_category = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUMCATEGORY])));
- echo $sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id." AND cat_id IN(".$forum_ids.");";
+ $sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id." AND cat_id IN(".$forum_ids.");";
Database::query($sql);
}
@@ -153,37 +153,37 @@ class CourseRecycler
$table_thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
$table_thread_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
-
-
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUM])));
- $sql = "DELETE FROM ".$table_attachment.
- " USING ".$table_attachment." INNER JOIN ".$table_post.
- " WHERE c_id = ".$this->course_id." AND ".$table_attachment.".post_id = ".$table_post.".post_id".
+ $sql = "DELETE FROM $table_attachment USING $table_attachment
+ INNER JOIN $table_post
+ WHERE ".$table_post.".c_id = ".$this->course_id." AND
+ ".$table_attachment.".c_id = ".$this->course_id." AND
+ ".$table_attachment.".post_id = ".$table_post.".post_id".
" AND ".$table_post.".forum_id IN(".$forum_ids.");";
Database::query($sql);
$sql = "DELETE FROM ".$table_mail_queue." USING ".$table_mail_queue." INNER JOIN ".$table_post.
- " WHERE c_id = ".$this->course_id." AND ".$table_mail_queue.".post_id = ".$table_post.".post_id".
+ " WHERE ".$table_post.".c_id = ".$this->course_id." AND ".$table_mail_queue.".c_id = ".$this->course_id." AND ".$table_mail_queue.".post_id = ".$table_post.".post_id".
" AND ".$table_post.".forum_id IN(".$forum_ids.");";
Database::query($sql);
// Just in case, deleting in the same table using thread_id as record-linker.
$sql = "DELETE FROM ".$table_mail_queue.
" USING ".$table_mail_queue." INNER JOIN ".$table_thread.
- " WHERE c_id = ".$this->course_id." AND ".$table_mail_queue.".thread_id = ".$table_thread.".thread_id".
+ " WHERE $table_mail_queue.c_id = ".$this->course_id." AND $table_thread.c_id = ".$this->course_id." AND ".$table_mail_queue.".thread_id = ".$table_thread.".thread_id".
" AND ".$table_thread.".forum_id IN(".$forum_ids.");";
Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify.
" USING ".$table_thread_qualify." INNER JOIN ".$table_thread.
- " WHERE c_id = ".$this->course_id." AND ".$table_thread_qualify.".thread_id = ".$table_thread.".thread_id".
+ " WHERE $table_thread_qualify.c_id = ".$this->course_id." AND $table_thread.c_id = ".$this->course_id." AND ".$table_thread_qualify.".thread_id = ".$table_thread.".thread_id".
" AND ".$table_thread.".forum_id IN(".$forum_ids.");";
Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify_log.
" USING ".$table_thread_qualify_log." INNER JOIN ".$table_thread.
- " WHERE c_id = ".$this->course_id." AND ".$table_thread_qualify_log.".thread_id = ".$table_thread.".thread_id".
+ " WHERE $table_thread_qualify_log.c_id = ".$this->course_id." AND $table_thread.c_id = ".$this->course_id." AND ".$table_thread_qualify_log.".thread_id = ".$table_thread.".thread_id".
" AND ".$table_thread.".forum_id IN(".$forum_ids.");";
Database::query($sql);
diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php
index f6e7b6389d..5b49400abb 100644
--- a/main/coursecopy/classes/CourseRestorer.class.php
+++ b/main/coursecopy/classes/CourseRestorer.class.php
@@ -33,7 +33,7 @@ define('FILE_SKIP', 1);
define('FILE_RENAME', 2);
define('FILE_OVERWRITE', 3);
-define('UTF8_CONVERT', false);
+define('UTF8_CONVERT', true);
/**
* Class to restore items from a course object to a Chamilo-course
@@ -58,21 +58,25 @@ class CourseRestorer
var $set_tools_invisible_by_default;
var $skip_content;
- var $tools_to_restore = array(
- 'events',
+ var $tools_to_restore = array(
'announcements',
- 'tool_intro',
- 'surveys',
- 'documents',
- 'quizzes',
+ 'attendance',
+ 'course_descriptions',
+ 'documents',
+ 'events',
+ // 'forum_category',
+ 'forums',
+ // 'forum_topics',
'glossary',
+ 'quizzes',
'learnpaths',
- 'links',
- 'course_descriptions',
- 'wiki',
+ 'links',
+ 'surveys',
+ //'scorm_documents', ??
+ 'tool_intro',
'thematic',
- 'attendance',
- 'scorm_documents');
+ 'wiki'
+ );
/** Setting per tool */
var $tool_copy_settings = array();
@@ -128,6 +132,16 @@ class CourseRestorer
$this->course->destination_path = $course_info['path'];
}
$this->destination_course_id = $course_info['real_id'];
+
+ //Getting first teacher (for the forums)
+ $teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['code']);
+ $this->first_teacher_id = api_get_user_id();
+ if (!empty($teacher_list)) {
+ foreach ($teacher_list as $teacher) {
+ $this->first_teacher_id = $teacher['user_id'];
+ break;
+ }
+ }
if (empty($this->course)) {
return false;
@@ -708,13 +722,18 @@ class CourseRestorer
function restore_forums() {
if ($this->course->has_resources(RESOURCE_FORUM)) {
$table_forum = Database::get_course_table(TABLE_FORUM);
- $table_topic = Database::get_course_table(TABLE_FORUM_THREAD);
- $table_post = Database::get_course_table(TABLE_FORUM_POST);
$resources = $this->course->resources;
- foreach ($resources[RESOURCE_FORUM] as $id => $forum)
- {
- $cat_id = $this->restore_forum_category($forum->category_id);
+ foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
+ $params = (array)$forum->obj;
+ $cat_id = $this->restore_forum_category($params['forum_category']);
+ self::DBUTF8_array($params);
+ $params['c_id'] = $this->destination_course_id;
+ $params['forum_category'] = $cat_id;
+ unset($params['forum_id']);
+ $new_id = Database::insert($table_forum, $params);
+
+ /*
$sql = "INSERT INTO ".$table_forum." SET
forum_title = '".self::DBUTF8escapestring($forum->title).
"', c_id= '".$this->destination_course_id.
@@ -735,35 +754,38 @@ class CourseRestorer
", locked = ".(int)self::DBUTF8escapestring($forum->locked).
", session_id = ".(int)self::DBUTF8escapestring($forum->session_id).
", forum_image = '".self::DBUTF8escapestring($forum->image)."'";
- Database::query($sql);
- $new_id = Database::insert_id();
+ Database::query($sql);*/
+ //$new_id = Database::insert_id();
$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
$forum_topics = 0;
- if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
- foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
- if ($topic->forum_id == $id) {
+ if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
+ foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
+ if ($topic->obj->forum_id == $id) {
$this->restore_topic($topic_id, $new_id);
$forum_topics ++;
}
}
}
if ($forum_topics > 0) {
- $last_post = $this->course->resources[RESOURCE_FORUMPOST][$forum->last_post];
- $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics.", forum_last_post = ".(int)$last_post->destination_id." WHERE forum_id = ".(int)$new_id;
+ //$last_post = $this->course->resources[RESOURCE_FORUMPOST][$forum->last_post];
+ $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
+ WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id;
Database::query($sql);
}
}
}
}
+
/**
* Restore forum-categories
- */
+ */
function restore_forum_category($id) {
$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$resources = $this->course->resources;
$forum_cat = $resources[RESOURCE_FORUMCATEGORY][$id];
- if (!$forum_cat->is_restored()) {
- $title = $forum_cat->title;
+
+ if ($forum_cat && !$forum_cat->is_restored()) {
+ $title = $forum_cat->obj->cat_title;
if (!empty($title)) {
if (!preg_match('/.*\((.+)\)$/', $title, $matches)) {
// This is for avoiding repetitive adding of training code after several backup/restore cycles.
@@ -772,6 +794,12 @@ class CourseRestorer
}
}
}
+ $params = (array) $forum_cat->obj;
+ $params['c_id'] = $this->destination_course_id;
+ unset($params['cat_id']);
+ self::DBUTF8_array($params);
+ $new_id = Database::insert($forum_cat_table, $params);
+ /*
$sql = "INSERT INTO ".$forum_cat_table." SET
c_id = ".$this->destination_course_id." ,
cat_title = '".self::DBUTF8escapestring($title).
@@ -779,20 +807,47 @@ class CourseRestorer
"', cat_order = ".(int)self::DBUTF8escapestring($forum_cat->order).
", locked = ".(int)self::DBUTF8escapestring($forum_cat->locked).
", session_id = ".(int)self::DBUTF8escapestring($forum_cat->session_id);
- Database::query($sql);
- $new_id = Database::insert_id();
+ Database::query($sql);*/
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
return $new_id;
}
return $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id;
}
+
/**
* Restore a forum-topic
*/
function restore_topic($id, $forum_id) {
$table = Database :: get_course_table(TABLE_FORUM_THREAD);
+
$resources = $this->course->resources;
$topic = $resources[RESOURCE_FORUMTOPIC][$id];
+
+ $params = (array)$topic->obj;
+ self::DBUTF8_array($params);
+ $params['c_id'] = $this->destination_course_id;
+ $params['forum_id'] = $forum_id;
+ $params['thread_poster_id'] = $this->first_teacher_id;
+ $params['thread_date'] = api_get_utc_datetime();
+ $params['thread_close_date'] = '0000-00-00 00:00:00';
+ $params['thread_last_post'] = 0;
+ $params['thread_replies'] = 0;
+ unset($params['thread_id']);
+ $new_id = Database::insert($table, $params);
+ api_item_property_update($this->destination_course_info, TOOL_FORUM_THREAD, $new_id, 'ThreadAdded', api_get_user_id(), 0, 0, null, null);
+
+ //Save a post for this thread
+ /*
+ $post_params = array(
+ 'c_id' => $this->destination_course_id,
+ 'post_title' => $params['thread_title'],
+ 'post_text' => $params['thread_title'],
+ );
+
+ *
+ */
+
+ /*
$sql = "INSERT INTO ".$table." SET
c_id = ".$this->destination_course_id." ,
thread_title = '".self::DBUTF8escapestring($topic->title).
@@ -806,32 +861,33 @@ class CourseRestorer
", thread_close_date = '".self::DBUTF8escapestring($topic->time_closed).
"', thread_weight = ".(float)self::DBUTF8escapestring($topic->weight).
", thread_title_qualify = '".self::DBUTF8escapestring($topic->title_qualify).
- "', thread_qualify_max = ".(float)self::DBUTF8escapestring($topic->qualify_max);
- Database::query($sql);
- $new_id = Database::insert_id();
+ "', thread_qualify_max = ".(float)self::DBUTF8escapestring($topic->qualify_max);*/
+ //Database::query($sql);
+ //$new_id = Database::insert_id();
$this->course->resources[RESOURCE_FORUMTOPIC][$id]->destination_id = $new_id;
+
$topic_replies = -1;
- foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post)
- {
- if ($post->topic_id == $id)
- {
+ var_dump($this->course->resources);exit;
+ foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post){
+ if ($post->obj->topic_id == $id) {
$topic_replies ++;
$this->restore_post($post_id, $new_id, $forum_id);
}
}
+ /*
$last_post = $this->course->resources[RESOURCE_FORUMPOST][$topic->last_post];
- if (is_object($last_post))
- {
+ if (is_object($last_post)) {
$sql = "UPDATE ".$table." SET thread_last_post = ".(int)$last_post->destination_id;
Database::query($sql);
}
- if ($topic_replies >= 0)
- {
+
+ if ($topic_replies >= 0) {
$sql = "UPDATE ".$table." SET thread_replies = ".$topic_replies;
Database::query($sql);
- }
+ }*/
return $new_id;
}
+
/**
* Restore a forum-post
* @TODO Restore tree-structure of posts. For example: attachments to posts.
@@ -840,6 +896,16 @@ class CourseRestorer
$table_post = Database :: get_course_table(TABLE_FORUM_POST);
$resources = $this->course->resources;
$post = $resources[RESOURCE_FORUMPOST][$id];
+ $params = (array) $post->obj;
+ $params['c_id'] = $this->destination_course_id;
+ $params['forum_id'] = $forum_id;
+ $params['thread_id'] = $topic_id;
+ $params['poster_id'] = $this->first_teacher_id;
+ $params['post_date'] = api_get_utc_datetime();
+ unset($params['post_id']);
+
+ $new_id = Database::insert($table_post, $params, true);
+ /*
$sql = "INSERT INTO ".$table_post." SET
c_id = ".$this->destination_course_id." ,
post_title = '".self::DBUTF8escapestring($post->title).
@@ -853,10 +919,11 @@ class CourseRestorer
", post_parent_id = ".(int)self::DBUTF8escapestring($post->parent_post_id).
", visible = ".(int)self::DBUTF8escapestring($post->visible);
Database::query($sql);
- $new_id = Database::insert_id();
+ $new_id = Database::insert_id();*/
$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
return $new_id;
}
+
/**
* Restore links
*/
@@ -1961,4 +2028,16 @@ class CourseRestorer
if (UTF8_CONVERT) $str = utf8_encode($str);
return Database::escape_string($str);
}
+
+ function DBUTF8_array($array) {
+ if (UTF8_CONVERT) {
+
+ foreach ($array as &$item) {
+ $item = utf8_encode($item);
+ }
+ return $array;
+ } else {
+ return $array;
+ }
+ }
}
\ No newline at end of file
diff --git a/main/coursecopy/classes/CourseSelectForm.class.php b/main/coursecopy/classes/CourseSelectForm.class.php
index d5b9134f3c..df11847866 100644
--- a/main/coursecopy/classes/CourseSelectForm.class.php
+++ b/main/coursecopy/classes/CourseSelectForm.class.php
@@ -16,7 +16,7 @@ class CourseSelectForm
* @param array $hidden_fiels Hidden fields to add to the form.
* @param boolean the document array will be serialize. This is used in the course_copy.php file
*/
- function display_form($course, $hidden_fields = null, $avoid_serialize=false) {
+ static function display_form($course, $hidden_fields = null, $avoid_serialize=false) {
global $charset;
$resource_titles[RESOURCE_EVENT] = get_lang('Events');
$resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements');
@@ -24,6 +24,9 @@ class CourseSelectForm
$resource_titles[RESOURCE_LINK] = get_lang('Links');
$resource_titles[RESOURCE_COURSEDESCRIPTION] = get_lang('CourseDescription');
$resource_titles[RESOURCE_FORUM] = get_lang('Forums');
+
+ $resource_titles[RESOURCE_FORUMCATEGORY] = get_lang('ForumCategory');
+
$resource_titles[RESOURCE_QUIZ] = get_lang('Tests');
$resource_titles[RESOURCE_LEARNPATH] = get_lang('Learnpaths');
$resource_titles[RESOURCE_SCORM] = 'SCORM';
@@ -46,6 +49,25 @@ class CourseSelectForm
document.getElementById('img_'+item).src='../img/0.gif';
}
}
+
+ function setCheckboxForum(type, value, item_id) {
+ //console.log("#resource["+type+"]["+value+"]");
+ //$("#resource["+type+"]["+value+"]").attr('checked', value);
+
+ d = document.course_select_form;
+ for (i = 0; i < d.elements.length; i++) {
+ if (d.elements[i].type == "checkbox") {
+ var name = d.elements[i].attributes.getNamedItem('name').nodeValue;
+
+ if( name.indexOf(type) > 0 || type == 'all' ){
+ if ($(d.elements[i]).attr('rel') == item_id) {
+ d.elements[i].checked = value;
+ }
+ }
+ }
+ }
+ }
+
function setCheckbox(type,value) {
d = document.course_select_form;
for (i = 0; i < d.elements.length; i++) {
@@ -102,14 +124,34 @@ class CourseSelectForm
}
$element_count = 0;
- foreach ($course->resources as $type => $resources) {
+ $forum_categories = array();
+ $forums = array();
+ $forum_topics = array();
+
+ foreach ($course->resources as $type => $resources) {
if (count($resources) > 0) {
switch ($type) {
- //Resources to avoid
- case RESOURCE_LINKCATEGORY :
+ //Resources to avoid
case RESOURCE_FORUMCATEGORY :
- case RESOURCE_FORUMPOST :
- case RESOURCE_FORUMTOPIC :
+ foreach ($resources as $id => $resource) {
+ $forum_categories[$id] = $resource;
+ }
+ $element_count++;
+ break;
+ case RESOURCE_FORUM:
+ foreach ($resources as $id => $resource) {
+ $forums[$resource->obj->forum_category][$id] = $resource;
+ }
+ $element_count++;
+ break;
+ case RESOURCE_FORUMTOPIC:
+ foreach ($resources as $id => $resource) {
+ $forum_topics[$resource->obj->forum_id][$id] = $resource;
+ }
+ $element_count++;
+ break;
+ case RESOURCE_LINKCATEGORY :
+ case RESOURCE_FORUMPOST :
case RESOURCE_QUIZQUESTION:
case RESOURCE_SURVEYQUESTION:
case RESOURCE_SURVEYINVITATION:
@@ -149,6 +191,87 @@ class CourseSelectForm
}
}
}
+
+ //Fixes forum order
+ //var_dump($forum_topics);exit;
+ if (!empty($forum_categories)) {
+ $type = RESOURCE_FORUMCATEGORY;
+
+ echo '
';
+ echo ''.$resource_titles[RESOURCE_FORUM].'
';
+ echo '