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 '
'; + + //All non categories + echo '
'; + echo "".get_lang('All').""; + echo "".get_lang('None').""; + echo '

'; + + echo ''; + + echo '
'; + echo ''; + + } + + if ($avoid_serialize) { /*Documents are avoided due the huge amount of memory that the serialize php function "eats" @@ -178,11 +301,11 @@ class CourseSelectForm CourseSelectForm :: display_hidden_quiz_questions($course); CourseSelectForm :: display_hidden_scorm_directories($course); echo ''; - echo '
'; + echo '
'; } - function display_hidden_quiz_questions($course) { + static function display_hidden_quiz_questions($course) { if(is_array($course->resources)){ foreach ($course->resources as $type => $resources) { if (count($resources) > 0) { @@ -199,7 +322,7 @@ class CourseSelectForm } } - function display_hidden_scorm_directories($course) { + static function display_hidden_scorm_directories($course) { if (is_array($course->resources)){ foreach ($course->resources as $type => $resources) { if (count($resources) > 0) { @@ -235,6 +358,7 @@ class CourseSelectForm $course_id = $course_info['real_id']; // Searching the documents resource that have been set to null because $avoid_serialize is true in the display_form() function + if ($from == 'copy_course') { if (is_array($resource)) { $resource = array_keys($resource); @@ -270,24 +394,7 @@ class CourseSelectForm } } } - - /*else { - $documents = $_POST['resource'][RESOURCE_DOCUMENT]; - //print_r($course->resources ); - foreach ($resource as $resource_item) { - echo $resource_item; - foreach($documents as $obj) { - print_r($obj); - - if ($obj->id==$resource_item) { - $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size); - print_r($doc); - $course->add_resource($doc); - } - } - } - }*/ - + if (is_array($course->resources)) { foreach ($course->resources as $type => $resources) { switch ($type) { @@ -325,18 +432,14 @@ class CourseSelectForm foreach ($resources as $id => $obj) { $resource_is_used_elsewhere = $course->is_linked_resource($obj); // check if document is in a quiz (audio/video) - if( $type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) - { - foreach($course->resources[RESOURCE_QUIZ] as $qid => $quiz) - { - if($quiz->media == $id) - { + if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) { + foreach($course->resources[RESOURCE_QUIZ] as $qid => $quiz) { + if($quiz->media == $id) { $resource_is_used_elsewhere = true; } } } - if (!isset ($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) - { + if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) { unset ($course->resources[$type][$id]); } } diff --git a/main/coursecopy/classes/Forum.class.php b/main/coursecopy/classes/Forum.class.php old mode 100755 new mode 100644 index 2d1b555814..7b23e0b7d6 --- a/main/coursecopy/classes/Forum.class.php +++ b/main/coursecopy/classes/Forum.class.php @@ -1,4 +1,5 @@ * @package chamilo.backup */ -class Forum extends Resource -{ - /** - * The title - */ - var $title; - /** - * The description - */ - var $description; - /** - * Category-id - */ - var $category_id; - /** - * Last post - */ - var $last_post; - /** - * Number of threads - */ - var $topics; - /** - * Number of posts - */ - var $posts; - /** - * Allow anonimous - */ - var $allow_anonymous; - /** - * Allow edit - */ - var $allow_edit; - /** - * Approval direct post - */ - var $approval_direct_post; - /** - * Allow attachments - */ - var $allow_attachements; - /** - * Allow new threads - */ - var $allow_new_topics; - /** - * Default view - */ - var $default_view; - /** - * Group forum - */ - var $of_group; - /** - * Public/private group forum - */ - var $group_public_private; - /** - * Order - */ - var $order; - /** - * Locked or not - */ - var $locked; - /** - * Session id - */ - var $session_id; - /** - * Image - */ - var $image; - /** - * Create a new Forum - */ - function Forum($id, $title, $description, $category_id, $last_post, $topics, $posts, $allow_anonymous, $allow_edit, $approval_direct_post, $allow_attachements, $allow_new_topics, $default_view, $of_group, $group_public_private, $order, $locked, $session_id, $image) - { - parent::Resource($id,RESOURCE_FORUM); - $this->title = $title; - $this->description = $description; - $this->category_id = $category_id; - $this->last_post = $last_post; - $this->topics = $topics; - $this->posts = $posts; - $this->allow_anonymous = $allow_anonymous; - $this->allow_edit = $allow_edit; - $this->approval_direct_post = $approval_direct_post; - $this->allow_attachements = $allow_attachements; - $this->allow_new_topics = $allow_new_topics; - $this->default_view = $default_view; - $this->of_group = $of_group; - $this->group_public_private = $group_public_private; - $this->order = $order; - $this->locked = $locked; - $this->session_id = $session_id; - $this->image = $image; - } - /** - * Show this resource - */ - function show() - { - parent::show(); - echo $this->title; - } +class Forum extends Resource { + + /** + * The title + */ + var $title; + + /** + * The description + */ + var $description; + + /** + * Category-id + */ + var $category_id; + + /** + * Last post + */ + var $last_post; + + /** + * Number of threads + */ + var $topics; + + /** + * Number of posts + */ + var $posts; + + /** + * Allow anonimous + */ + var $allow_anonymous; + + /** + * Allow edit + */ + var $allow_edit; + + /** + * Approval direct post + */ + var $approval_direct_post; + + /** + * Allow attachments + */ + var $allow_attachements; + + /** + * Allow new threads + */ + var $allow_new_topics; + + /** + * Default view + */ + var $default_view; + + /** + * Group forum + */ + var $of_group; + + /** + * Public/private group forum + */ + var $group_public_private; + + /** + * Order + */ + var $order; + + /** + * Locked or not + */ + var $locked; + + /** + * Session id + */ + var $session_id; + + /** + * Image + */ + var $image; + + /** + * Create a new Forum + */ + /* function Forum($id, $title, $description, $category_id, $last_post, $topics, $posts, $allow_anonymous, $allow_edit, $approval_direct_post, $allow_attachements, + $allow_new_topics, $default_view, $of_group, $group_public_private, $order, $locked, $session_id, $image) + { */ + function Forum($obj) { + parent::Resource($obj->forum_id, RESOURCE_FORUM); + $this->obj = $obj; + + /* + $this->title = $title; + $this->description = $description; + $this->category_id = $category_id; + $this->last_post = $last_post; + $this->topics = $topics; + $this->posts = $posts; + $this->allow_anonymous = $allow_anonymous; + $this->allow_edit = $allow_edit; + $this->approval_direct_post = $approval_direct_post; + $this->allow_attachements = $allow_attachements; + $this->allow_new_topics = $allow_new_topics; + $this->default_view = $default_view; + $this->of_group = $of_group; + $this->group_public_private = $group_public_private; + $this->order = $order; + $this->locked = $locked; + $this->session_id = $session_id; + $this->image = $image; */ + } + + /** + * Show this resource + */ + function show() { + parent::show(); + echo $this->obj->forum_title; + } + } diff --git a/main/coursecopy/classes/ForumCategory.class.php b/main/coursecopy/classes/ForumCategory.class.php old mode 100755 new mode 100644 index e9afcccf25..3d46c67bb5 --- a/main/coursecopy/classes/ForumCategory.class.php +++ b/main/coursecopy/classes/ForumCategory.class.php @@ -1,4 +1,5 @@ * @package chamilo.backup */ -class ForumCategory extends Resource -{ - /** - * The title - */ - var $title; - /** - * The description - */ - var $description; - /** - * The order - */ - var $order; - /** - * Locked flag - */ - var $locked; - /** - * The session id - */ - var $session_id; - /** - * Create a new ForumCategory - */ - function ForumCategory($id, $title, $description, $order, $locked, $session_id) - { - parent::Resource($id,RESOURCE_FORUMCATEGORY); - $this->title = $title; - $this->description = $description; - $this->order = $order; - $this->locked = $locked; - $this->session_id = $session_id; - } - /** - * Show this resource - */ - function show() - { - parent::show(); - echo $this->title; - } +class ForumCategory extends Resource { + + /** + * The title + */ + var $title; + + /** + * The description + */ + var $description; + + /** + * The order + */ + var $order; + + /** + * Locked flag + */ + var $locked; + + /** + * The session id + */ + var $session_id; + + /** + * Create a new ForumCategory + */ + //function ForumCategory($id, $title, $description, $order, $locked, $session_id) + function ForumCategory($obj) { + parent::Resource($obj->cat_id, RESOURCE_FORUMCATEGORY); + $this->obj = $obj; /* + $this->title = $title; + $this->description = $description; + $this->order = $order; + $this->locked = $locked; + $this->session_id = $session_id; */ + } + + /** + * Show this resource + */ + function show() { + parent::show(); + echo $this->obj->cat_title; + } + } diff --git a/main/coursecopy/classes/ForumPost.class.php b/main/coursecopy/classes/ForumPost.class.php old mode 100755 new mode 100644 index fc2d166a2a..de7718f698 --- a/main/coursecopy/classes/ForumPost.class.php +++ b/main/coursecopy/classes/ForumPost.class.php @@ -1,4 +1,5 @@ * @package chamilo.backup */ -class ForumPost extends Resource -{ - /** - * The title - */ - var $title; - /** - * The text - */ - var $text; - /** - * The time - */ - var $post_time; - /** - * Poster id - */ - var $poster_id; - /** - * Poster name - */ - var $poster_name; - /** - * Topic notify - */ - var $topic_notify; - /** - * Parent post - */ - var $parent_post_id; - /** - * Topic id - */ - var $topic_id; - /** - * Forum id - */ - var $forum_id; - /** - * Visible flag - */ - var $visible; - /** - * Create a new ForumPost - */ - function ForumPost($id, $title, $text, $post_time, $poster_id, $poster_name, $topic_notify, $parent_post_id, $topic_id, $forum_id, $visible) - { - parent::Resource($id, RESOURCE_FORUMPOST); - $this->title = $title; - $this->text = $text; - $this->post_time = $post_time; - $this->poster_id = $poster_id; - $this->poster_name = $poster_name; - $this->topic_notify = $topic_notify; - $this->parent_post_id = $parent_post_id; - $this->topic_id = $topic_id; - $this->forum_id = $forum_id; - $this->visible = $visible; - } - /** - * Show this resource - */ - function show() - { - parent::show(); - echo $this->title.' ('.$this->poster_name.', '.$this->post_time.')'; - } +class ForumPost extends Resource { + + /** + * Create a new ForumPost + */ + function ForumPost($obj) { + parent::Resource($obj->post_id, RESOURCE_FORUMPOST); + $this->obj = $obj; + } + + /** + * Show this resource + */ + function show() { + parent::show(); + echo $this->obj->title . ' (' . $this->obj->poster_name . ', ' . $this->obj->post_date . ')'; + } } diff --git a/main/coursecopy/classes/ForumTopic.class.php b/main/coursecopy/classes/ForumTopic.class.php index 4027843b2e..6fd821df50 100644 --- a/main/coursecopy/classes/ForumTopic.class.php +++ b/main/coursecopy/classes/ForumTopic.class.php @@ -1,4 +1,5 @@ * @package chamilo.backup */ -class ForumTopic extends Resource -{ - /** - * The title - */ - var $title; - /** - * The time - */ - var $time; - /** - * Poster id - */ - var $topic_poster_id; - /** - * Poster name - */ - var $topic_poster_name; - /** - * Parent forum - */ - var $forum_id; - /** - * Last post - */ - var $last_post; - /** - * How many replies are there - */ - var $replies; - /** - * How many times has been viewed - */ - var $views; - /** - * Sticky or not - */ - var $sticky; - /** - * Locked or not - */ - var $locked; - /** - * Date of closing - */ - var $time_closed; +class ForumTopic extends Resource { + /** + * Create a new ForumTopic + */ + /* function ForumTopic($id, $title, $time, $topic_poster_id, $topic_poster_name, $forum_id, $last_post, $replies, $views = 0, $sticky = 0, $locked = 0, + $time_closed = null, $weight = 0, $title_qualify = null, $qualify_max = 0) */ + function ForumTopic($obj) { + parent::Resource($obj->thread_id, RESOURCE_FORUMTOPIC); + $this->obj = $obj; + /* + $this->title = $title; + $this->time = $time; + $this->topic_poster_id = $topic_poster_id; + $this->topic_poster_name = $topic_poster_name; + $this->forum_id = $forum_id; + $this->last_post = $last_post; + $this->replies = $replies; + $this->views = $views; + $this->sticky = $sticky; + $this->locked = $locked; + $this->time_closed = $time_closed; + $this->weight = $weight; + $this->title_qualify = $title_qualify; + $this->qualify_max = $qualify_max; */ + } - // From the Gradebook tool? - /** - * Weight - */ - var $weight; - /** - * Weight - */ - var $title_qualify; - /** - * Weight - */ - var $qualify_max; + /** + * Show this resource + */ + function show() { + parent::show(); + echo $this->obj->thread_title . ' (' . $this->obj->topic_poster_name . ', ' . $this->obj->topic_time . ')'; + } - /** - * Create a new ForumTopic - */ - function ForumTopic($id, $title, $time, $topic_poster_id, $topic_poster_name, $forum_id, $last_post, $replies, $views = 0, $sticky = 0, $locked = 0, $time_closed = null, $weight = 0, $title_qualify = null, $qualify_max = 0) - { - parent::Resource($id, RESOURCE_FORUMTOPIC); - $this->title = $title; - $this->time = $time; - $this->topic_poster_id = $topic_poster_id; - $this->topic_poster_name = $topic_poster_name; - $this->forum_id = $forum_id; - $this->last_post = $last_post; - $this->replies = $replies; - $this->views = $views; - $this->sticky = $sticky; - $this->locked = $locked; - $this->time_closed = $time_closed; - $this->weight = $weight; - $this->title_qualify = $title_qualify; - $this->qualify_max = $qualify_max; - } - - /** - * Show this resource - */ - function show() - { - parent::show(); - echo $this->title.' ('.$this->topic_poster_name.', '.$this->topic_time.')'; - } -} +} \ No newline at end of file diff --git a/main/coursecopy/copy_course.php b/main/coursecopy/copy_course.php index 32ac2dfd7d..6e1764b561 100644 --- a/main/coursecopy/copy_course.php +++ b/main/coursecopy/copy_course.php @@ -52,7 +52,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is } else { $cb = new CourseBuilder(); $course = $cb->build(); - } + } $cr = new CourseRestorer($course); $cr->set_file_option($_POST['same_file_name_option']); diff --git a/main/coursecopy/create_backup.php b/main/coursecopy/create_backup.php index dbb6167dc2..a94b1650fd 100644 --- a/main/coursecopy/create_backup.php +++ b/main/coursecopy/create_backup.php @@ -55,19 +55,19 @@ echo Display::page_header($nameTools); if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) { if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') { - $course = CourseSelectForm :: get_posted_course(); + $course = CourseSelectForm::get_posted_course(); } else { $cb = new CourseBuilder(); $course = $cb->build(); } - $zip_file = CourseArchiver :: write_course($course); + $zip_file = CourseArchiver::write_course($course); Display::display_confirmation_message(get_lang('BackupCreated')); echo '
'.get_lang('Download').''; } elseif (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') { $cb = new CourseBuilder('partial'); - $course = $cb->build(); - CourseSelectForm :: display_form($course); + $course = $cb->build(); + CourseSelectForm::display_form($course); } else { $cb = new CourseBuilder(); $course = $cb->build(); diff --git a/main/coursecopy/import_backup.php b/main/coursecopy/import_backup.php index 21c7373b1b..8b6a5dcbb2 100644 --- a/main/coursecopy/import_backup.php +++ b/main/coursecopy/import_backup.php @@ -57,6 +57,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (i if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') { // Partial backup here we recover the documents posted $course = CourseSelectForm::get_posted_course(); + } else { if ($_POST['backup_type'] == 'server') { $filename = $_POST['backup_server']; @@ -73,9 +74,10 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (i $error = true; } } + if (!$error) { // Full backup - $course = CourseArchiver::read_course($filename,$delete_file); + $course = CourseArchiver::read_course($filename, $delete_file); } } @@ -106,7 +108,8 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (i $filename = CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']); $delete_file = true; } - $course = CourseArchiver::read_course($filename,$delete_file); + $course = CourseArchiver::read_course($filename, $delete_file); + if ($course->has_resources() && ($filename !== false)) { CourseSelectForm::display_form($course, array('same_file_name_option' => $_POST['same_file_name_option'])); } elseif ($filename === false) { @@ -118,7 +121,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (i } } else { $user = api_get_user_info(); - $backups = CourseArchiver::get_available_backups($is_platformAdmin?null:$user['user_id']); + $backups = CourseArchiver::get_available_backups($is_platformAdmin ?null:$user['user_id']); $backups_available = count($backups) > 0; $form = new FormValidator('import_backup_form', 'post', 'import_backup.php', '', 'multipart/form-data'); @@ -132,7 +135,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form' ) || (i $form->addElement('file', 'backup', '', 'style="margin-left: 50px;"'); $form->addElement('html', '
'); - if ($backups_available ) { + if ($backups_available) { $form->addElement('radio', 'backup_type', '', get_lang('ServerFile'), 'server', 'id="bt_server" class="checkbox" onclick="javascript: document.import_backup_form.backup_server.disabled=false;document.import_backup_form.backup.disabled=true;"'); $options['null'] = '-'; foreach ($backups as $index => $backup) { diff --git a/main/coursecopy/recycle_course.php b/main/coursecopy/recycle_course.php index 4387c5d594..e0585ceda7 100644 --- a/main/coursecopy/recycle_course.php +++ b/main/coursecopy/recycle_course.php @@ -50,7 +50,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is } else { $cb = new CourseBuilder(); $course = $cb->build(); - } + } $cr = new CourseRecycler($course); $cr->recycle(); Display::display_confirmation_message(get_lang('RecycleFinished')); @@ -64,8 +64,7 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is if (!$course->has_resources()) { echo get_lang('NoResourcesToRecycle'); } else { - Display::display_warning_message(get_lang('RecycleWarning'), false); - + Display::display_warning_message(get_lang('RecycleWarning'), false); $form = new FormValidator('recycle_course', 'post', 'recycle_course.php'); $form->addElement('header',get_lang('SelectOptionForBackup')); diff --git a/main/forum/forumconfig.inc.php b/main/forum/forumconfig.inc.php index 20b6d456c7..45cd06420b 100644 --- a/main/forum/forumconfig.inc.php +++ b/main/forum/forumconfig.inc.php @@ -26,15 +26,6 @@ $forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT); $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); $table_users = Database :: get_main_table(TABLE_MAIN_USER); -/* - Constants -*/ -define('TOOL_FORUM_CATEGORY','forum_category'); -//define('TOOL_FORUM','forum'); defined in main_api -define('TOOL_FORUM_THREAD','forum_thread'); -define('TOOL_FORUM_POST','forum_post'); -define('TOOL_FORUM_ATTACH','forum_attachment'); -define('TOOL_FORUM_THREAD_QUALIFY','forum_thread_qualify'); /* Some configuration settings (these can go to the dokeos config settings afterwards) diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index f1c3cb9794..7401870f29 100644 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -1427,7 +1427,7 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_ * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ -function get_threads($forum_id, $course_code = '') { +function get_threads($forum_id, $course_code = null) { $course_info = api_get_course_info($course_code); if (empty($course_info)) { return array(); @@ -1489,7 +1489,7 @@ function get_threads($forum_id, $course_code = '') { thread.c_id = $course_id AND thread.forum_id='".Database::escape_string($forum_id)."' ORDER BY thread.thread_sticky DESC, thread.thread_date DESC"; - } + } $result = Database::query($sql); while ($row = Database::fetch_array($result, 'ASSOC')) { $thread_list[] = $row; @@ -1940,7 +1940,7 @@ function store_thread($values) { api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id, 'invisible', api_get_user_id()); $visible = 1; } - } + } // We now store the content in the table_post table. $sql = "INSERT INTO $table_posts (c_id, post_title, post_text, thread_id, forum_id, poster_id, poster_name, post_date, post_notification, post_parent_id, visible) @@ -2001,6 +2001,7 @@ function store_thread($values) { } send_notification_mails($last_thread_id, $reply_info); + Session::erase('formelements'); Session::erase('origin'); Session::erase('breadcrumbs'); diff --git a/main/forum/viewforum.php b/main/forum/viewforum.php index 79f35df6d5..8dadd44d6c 100644 --- a/main/forum/viewforum.php +++ b/main/forum/viewforum.php @@ -329,6 +329,7 @@ echo ''; // Getting al the threads $threads = get_threads($my_forum); // Note: This has to be cleaned first. + $whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null; $course_id = api_get_course_int_id(); diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index c164167222..8f4461876d 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -81,6 +81,11 @@ define('TOOL_SEARCH', 'search'); define('TOOL_LEARNPATH', 'learnpath'); define('TOOL_ANNOUNCEMENT', 'announcement'); define('TOOL_FORUM', 'forum'); +define('TOOL_FORUM_CATEGORY','forum_category'); +define('TOOL_FORUM_THREAD','forum_thread'); +define('TOOL_FORUM_POST','forum_post'); +define('TOOL_FORUM_ATTACH','forum_attachment'); +define('TOOL_FORUM_THREAD_QUALIFY','forum_thread_qualify'); define('TOOL_THREAD', 'thread'); define('TOOL_POST', 'post'); define('TOOL_DROPBOX', 'dropbox');