* @author Julio Montoya * @package chamilo.backup */ class CourseSelectForm { /** * Display the form * @param array $hidden_fields Hidden fields to add to the form. * @param boolean the document array will be serialize. This is used in the course_copy.php file */ public static function display_form($course, $hidden_fields = null, $avoid_serialize = false) { global $charset; $resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook'); $resource_titles[RESOURCE_EVENT] = get_lang('Events'); $resource_titles[RESOURCE_ANNOUNCEMENT] = get_lang('Announcements'); $resource_titles[RESOURCE_DOCUMENT] = get_lang('Documents'); $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_TEST_CATEGORY] = get_lang('QuestionCategory'); $resource_titles[RESOURCE_LEARNPATH] = get_lang('ToolLearnpath'); $resource_titles[RESOURCE_SCORM] = 'SCORM'; $resource_titles[RESOURCE_TOOL_INTRO] = get_lang('ToolIntro'); $resource_titles[RESOURCE_SURVEY] = get_lang('Survey'); $resource_titles[RESOURCE_GLOSSARY] = get_lang('Glossary'); $resource_titles[RESOURCE_WIKI] = get_lang('Wiki'); $resource_titles[RESOURCE_THEMATIC] = get_lang('Thematic'); $resource_titles[RESOURCE_ATTENDANCE] = get_lang('Attendance'); $resource_titles[RESOURCE_WORK] = get_lang('ToolStudentPublication'); ?> '; echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle; echo ''; } echo ''; echo ''; $icon = Display::returnIconPath('myprogress_bar.gif'); echo '
'; echo ''; if (!empty($hidden_fields['destination_course']) && !empty($hidden_fields['origin_course']) && !empty($hidden_fields['destination_session']) && !empty($hidden_fields['origin_session']) ) { echo ''; echo ''; echo ''; echo ''; } $element_count = 0; $forum_categories = array(); $forums = array(); $forum_topics = array(); echo '

'; echo get_lang('SelectResources'); echo '

'; Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt')); foreach ($course->resources as $type => $resources) { if (count($resources) > 0) { switch ($type) { //Resources to avoid case RESOURCE_FORUMCATEGORY: 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: case RESOURCE_SCORM: break; default : echo ' '; echo ''.$resource_titles[$type].'
'; echo '
'; if ($type == RESOURCE_LEARNPATH) { Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz')); Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments')); } if ($type == RESOURCE_DOCUMENT) { if (api_get_setting('show_glossary_in_documents') != 'none') { Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary')); } } echo '
'; echo '
'; echo "".get_lang('All').""; echo "".get_lang('None').""; echo '

'; foreach ($resources as $id => $resource) { if ($resource) { Coursecopy\Resource::setClassType($resource); echo ''; } } echo '
'; echo '
'; echo ''; $element_count++; } } } //Fixes forum order if (!empty($forum_categories)) { $type = RESOURCE_FORUMCATEGORY; echo ' '; echo ''.$resource_titles[RESOURCE_FORUM].'
'; echo '
'; echo '
    '; foreach ($forum_categories as $forum_category_id => $forum_category) { echo '
  • '; echo ''; echo '
  • '; if (isset($forums[$forum_category_id])) { $my_forums = $forums[$forum_category_id]; echo '
      '; foreach ($my_forums as $forum_id => $forum) { echo '
    • '; echo ''; echo '
    • '; if (isset($forum_topics[$forum_id])) { $my_forum_topics = $forum_topics[$forum_id]; if (!empty($my_forum_topics)) { echo '
        '; foreach ($my_forum_topics as $topic_id => $topic) { echo '
      • '; echo ''; echo '
      • '; } echo '
      '; } } } echo '
    '; } echo '
    '; } echo '
'; echo '
'; echo ''; } if ($avoid_serialize) { /*Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files) */ // this is a known issue of serialize $course->resources['document']= null; } echo ''; if (is_array($hidden_fields)) { foreach ($hidden_fields as $key => $value) { echo ''; } } $recycleOption = isset($_POST['recycle_option']) ? true : false; if (empty($element_count)) { Display::display_warning_message(get_lang('NoDataAvailable')); } else { if (!empty($hidden_fields['destination_session'])) { echo '
'; } else { if ($recycleOption) { echo '
'; } else { echo '
'; } } } CourseSelectForm :: display_hidden_quiz_questions($course); CourseSelectForm :: display_hidden_scorm_directories($course); echo '
'; echo '
'; } /** * @param $course */ static function display_hidden_quiz_questions($course) { if(is_array($course->resources)){ foreach ($course->resources as $type => $resources) { if (count($resources) > 0) { switch ($type) { case RESOURCE_QUIZQUESTION: foreach ($resources as $id => $resource) { echo ''; } break; } } } } } /** * @param $course */ static function display_hidden_scorm_directories($course) { if (is_array($course->resources)){ foreach ($course->resources as $type => $resources) { if (count($resources) > 0) { switch($type) { case RESOURCE_SCORM: foreach ($resources as $id => $resource) { echo ''; } break; } } } } } /** * Get the posted course * @param string $from who calls the function? * It can be copy_course, create_backup, import_backup or recycle_course * @param int $session_id * @param string $course_code * @return course The course-object with all resources selected by the user * in the form given by display_form(...) */ public static function get_posted_course($from = '', $session_id = 0, $course_code = '') { $course = null; if (isset($_POST['course'])) { $course = Course::unserialize(base64_decode($_POST['course'])); } else { return false; } // Create the resource DOCUMENT objects // Loading the results from the checkboxes of ethe javascript $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; $course_info = api_get_course_info($course_code); $table_doc = Database::get_course_table(TABLE_DOCUMENT); $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); $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); foreach ($resource as $resource_item) { $condition_session = ''; if (!empty($session_id)) { $session_id = intval($session_id); $condition_session = ' AND d.session_id ='.$session_id; } $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size FROM '.$table_doc.' d, '.$table_prop.' p WHERE d.c_id = '.$course_id.' AND p.c_id = '.$course_id.' AND tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND d.id = '.$resource_item.$condition_session.' ORDER BY path'; $db_result = Database::query($sql); while ($obj = Database::fetch_object($db_result)) { $doc = new Document( $obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size ); if ($doc) { $course->add_resource($doc); // adding item property $sql = "SELECT * FROM $table_prop WHERE c_id = $course_id AND tool = '".RESOURCE_DOCUMENT."' AND ref = $resource_item "; $res = Database::query($sql); $all_properties = array (); while ($item_property = Database::fetch_array($res,'ASSOC')) { $all_properties[] = $item_property; } $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties; } } } } } if (is_array($course->resources)) { foreach ($course->resources as $type => $resources) { switch ($type) { case RESOURCE_SURVEYQUESTION: foreach($resources as $id => $obj) { if (isset($_POST['resource'][RESOURCE_SURVEY]) && is_array($_POST['resource'][RESOURCE_SURVEY]) && !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY])) ) { unset($course->resources[$type][$id]); } } break; case RESOURCE_FORUMTOPIC: case RESOURCE_FORUMPOST: //Add post from topic if ($type == RESOURCE_FORUMTOPIC) { $posts_to_save = array(); $posts = $course->resources[RESOURCE_FORUMPOST]; foreach ($resources as $thread_id => $obj) { if (!isset($_POST['resource'][RESOURCE_FORUMTOPIC][$thread_id])) { unset($course->resources[RESOURCE_FORUMTOPIC][$thread_id]); continue; } $forum_id = $obj->obj->forum_id; $title = $obj->obj->thread_title; foreach ($posts as $post_id => $post) { if ($post->obj->thread_id == $thread_id && $forum_id == $post->obj->forum_id && $title == $post->obj->post_title ) { //unset($course->resources[RESOURCE_FORUMPOST][$post_id]); $posts_to_save[] = $post_id; } } } if (!empty($posts)) { foreach ($posts as $post_id => $post) { if (!in_array($post_id, $posts_to_save)) { unset($course->resources[RESOURCE_FORUMPOST][$post_id]); } } } } break; case RESOURCE_LEARNPATH: $lps = isset($_POST['resource'][RESOURCE_LEARNPATH]) ? $_POST['resource'][RESOURCE_LEARNPATH] : null; if (!empty($lps)) { foreach ($lps as $id => $obj) { $lp_resource = $course->resources[RESOURCE_LEARNPATH][$id]; if (isset($lp_resource) && !empty($lp_resource) && isset($lp_resource->items)) { foreach ($lp_resource->items as $item) { switch ($item['item_type']) { //Add links added in a LP see #5760 case 'link': $_POST['resource'][RESOURCE_LINK][$item['path']] = 1; break; } } } } } case RESOURCE_LINKCATEGORY : case RESOURCE_FORUMCATEGORY : case RESOURCE_QUIZQUESTION : case RESOURCE_DOCUMENT: // Mark folders to import which are not selected by the user to import, // but in which a document was selected. $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null; if (!empty($resources) && is_array($resources)) foreach ($resources as $id => $obj) { if (isset($obj->file_type) && $obj->file_type == 'folder' && !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) && is_array($documents) ) { foreach ($documents as $id_to_check => $post_value) { $obj_to_check = $resources[$id_to_check]; $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path)); if ($id_to_check != $id && $obj->path == $shared_path_part) { $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1; break; } } } } default : if (!empty($resources) && is_array($resources)) { 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 $quiz) { $quiz = $quiz->obj; if (isset($quiz->media) && $quiz->media == $id) { $resource_is_used_elsewhere = true; } } } if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) { unset($course->resources[$type][$id]); } } } } } } return $course; } /** * Display the form session export * @param array $hidden_fields Hidden fields to add to the form. * @param boolean the document array will be serialize. This is used in the course_copy.php file */ public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false) { ?> '; echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle; echo ''; } echo ''; echo ''; $icon = Display::returnIconPath('progress_bar.gif'); echo '
'; echo ''; foreach ($list_course as $course){ foreach ($course->resources as $type => $resources) { if (count($resources) > 0) { echo 'code'".');" />'; echo 'code'".');" > '.$course->code.'
'; echo '
'; echo '
'; echo '
'; foreach ($resources as $id => $resource) { echo ''; } echo '
'; echo '
'; echo ''; } } } if ($avoid_serialize) { //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files) // this is a known issue of serialize $course->resources['document']= null; } echo ''; if (is_array($hidden_fields)) { foreach ($hidden_fields as $key => $value) { echo "\n"; echo ''; } } echo '
'; CourseSelectForm :: display_hidden_quiz_questions($course); CourseSelectForm :: display_hidden_scorm_directories($course); echo '
'; echo '
'; } }