Browse Source

Merge branch '8986' of https://github.com/AngelFQC/chamilo-lms into 1.9.x

Yannick Warnier 10 years ago
parent
commit
e623a07691

+ 4 - 1
main/admin/add_courses_to_session.php

@@ -114,7 +114,10 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
             }
         }
 
-		if (!$exists) {
+        $courseInfo = api_get_course_info($enreg_course);
+        $courseId = $courseInfo['real_id'];
+
+        if (!$exists) {
 			$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code) VALUES('$id_session','$enreg_course')";
 			Database::query($sql_insert_rel_course);
 

+ 18 - 0
main/course_home/activity.php

@@ -114,6 +114,24 @@ if ($session_id == 0 && api_is_course_admin() && api_is_allowed_to_edit(null, tr
     $content .= CourseHome::show_tools_category($my_list);
     $content .= '</div>';
 
+    if (isset($_configuration['allow_session_course_copy_for_teachers'])) {
+        if ($_configuration['allow_session_course_copy_for_teachers']) {
+            // Adding only maintenance for coaches.
+            $myList = CourseHome::get_tools_category(TOOL_ADMIN_PLATFORM);
+            $onlyMaintenanceList = array();
+
+            foreach ($myList as $item) {
+                if ($item['name'] == 'course_maintenance') {
+                    $item['link'] = 'course_info/maintenance_coach.php';
+
+                    $onlyMaintenanceList[] = $item;
+                }
+            }
+            
+            $items = CourseHome::show_tools_category($onlyMaintenanceList);
+            $content .= return_block(get_lang('Administration'), $items);
+        }
+    }
 } else {
 	$my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
 	if (count($my_list) > 0) {

+ 53 - 0
main/course_info/maintenance_coach.php

@@ -0,0 +1,53 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Maintenance for session coach
+ * @author Julio Montoya <julio.montoya@beeznest.com>
+ * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
+ * @package chamilo.course_info
+ */
+/**
+ * Code
+ */
+// Language files that need to be included
+$language_file = array('admin', 'create_course', 'course_info', 'coursebackup');
+
+require_once '../inc/global.inc.php';
+
+$current_course_tool = TOOL_COURSE_MAINTENANCE;
+$this_section = SECTION_COURSES;
+
+$nameTools = get_lang('Maintenance');
+
+api_protect_course_script(true);
+api_block_anonymous_users();
+
+if (!isset($_configuration['allow_session_course_copy_for_teachers'])
+     || !$_configuration['allow_session_course_copy_for_teachers']){
+    api_not_allowed(true);
+}
+
+Display :: display_header($nameTools);
+
+echo Display::page_subheader(
+    Display::return_icon(
+        'save_import.gif', get_lang('backup')
+    ) . '&nbsp;&nbsp;' . get_lang('backup')
+);
+
+$url = api_get_path(
+        WEB_CODE_PATH
+    ) . 'coursecopy/copy_course_session_selected.php?' . api_get_cidreq();
+
+$link = Display::url(get_lang('CopyCourse'), $url);
+?>
+<div class="sectioncomment">
+    <ul>
+        <li>
+            <?php echo $link; ?><br/>
+            <?php echo get_lang('DescriptionCopyCourse'); ?>
+        </li>
+    </ul>
+</div>
+<?php
+Display::display_footer();

+ 34 - 11
main/coursecopy/classes/CourseBuilder.class.php

@@ -284,7 +284,9 @@ class CourseBuilder
 
         $table = Database :: get_course_table(TABLE_FORUM);
 
-        $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
+        $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = "SELECT * FROM $table WHERE c_id = $course_id $sessionCodition";
         $sql .= " ORDER BY forum_title, forum_category";
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {
@@ -302,7 +304,10 @@ class CourseBuilder
         $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";
+        $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = "SELECT * FROM $table WHERE c_id = $course_id $sessionCodition ORDER BY cat_title";
+
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {
             $forum_category = new ForumCategory($obj);
@@ -318,7 +323,11 @@ class CourseBuilder
         $table = Database :: get_course_table(TABLE_FORUM_THREAD);
         $course_info     = api_get_course_info($course_code);
         $course_id         = $course_info['real_id'];
+
+        $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
+
         $sql = "SELECT * FROM $table WHERE c_id = $course_id
+                $sessionCodition
                 ORDER BY thread_title ";
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {
@@ -403,7 +412,11 @@ class CourseBuilder
     {
         $table = Database :: get_course_table(TABLE_TOOL_INTRO);
         $course_id = api_get_course_int_id();
-        $sql = "SELECT * FROM $table WHERE c_id = $course_id ";
+
+        $sessionCodition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = "SELECT * FROM $table WHERE c_id = $course_id $sessionCodition";
+
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {
             $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
@@ -728,7 +741,9 @@ class CourseBuilder
         $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
         $course_id = api_get_course_int_id();
 
-        $sql = 'SELECT * FROM '.$table_survey.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
+        $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = 'SELECT * FROM '.$table_survey.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {
             $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
@@ -787,7 +802,9 @@ class CourseBuilder
         $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
         $course_id = api_get_course_int_id();
 
-        $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' AND session_id = 0';
+        $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
         $db_result = Database::query($sql);
         $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
         while ($obj = Database::fetch_object($db_result)) {
@@ -826,7 +843,9 @@ class CourseBuilder
         $table = Database :: get_course_table(TABLE_AGENDA);
         $course_id = api_get_course_int_id();
 
-        $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' AND session_id = 0';
+        $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
         $db_result = Database::query($sql);
         while ($obj = Database::fetch_object($db_result)) {
             $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
@@ -1159,7 +1178,9 @@ class CourseBuilder
 
         $course_id = api_get_course_int_id();
 
-        $sql = 'SELECT * FROM '.$table_attendance.' WHERE c_id = '.$course_id.' AND session_id = 0 ';
+        $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = 'SELECT * FROM '.$table_attendance.' WHERE c_id = '.$course_id.' ' . $sessionCondition;
         $db_result = Database::query($sql);
         while ($row = Database::fetch_array($db_result,'ASSOC')) {
             $obj = new Attendance($row);
@@ -1183,13 +1204,15 @@ class CourseBuilder
 
         $course_id = api_get_course_int_id();
 
-        $sql = 'SELECT * FROM '.$table_work.'
+        $sessionCondition = api_get_session_condition($session_id, true, $with_base_content);
+
+        $sql = "SELECT * FROM $table_work
                 WHERE
-                    c_id = '.$course_id.' AND
-                    session_id = 0 AND
+                    c_id = $course_id 
+                    $sessionCondition AND
                     filetype = \'folder\' AND
                     parent_id = 0 AND
-                    active = 1';
+                    active = 1";
         $db_result = Database::query($sql);
         while ($row = Database::fetch_array($db_result,'ASSOC')) {
             $obj = new Work($row);

+ 29 - 13
main/coursecopy/classes/CourseRestorer.class.php

@@ -885,9 +885,10 @@ class CourseRestorer
 	/**
 	 * Restore forums
 	 */
-	public function restore_forums()
+	public function restore_forums($sessionId = 0)
     {
 		if ($this->course->has_resources(RESOURCE_FORUM)) {
+            $sessionId = intval($sessionId);
 			$table_forum = Database::get_course_table(TABLE_FORUM);
 			$resources = $this->course->resources;
 			foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
@@ -901,6 +902,7 @@ class CourseRestorer
                 $params = self::DBUTF8_array($params);
                 $params['c_id'] = $this->destination_course_id;
                 $params['forum_category'] = $cat_id;
+                $params['session_id'] = $sessionId;
                 unset($params['forum_id']);
 
                 $params['forum_comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
@@ -1075,9 +1077,10 @@ class CourseRestorer
 	/**
 	 * Restore tool intro
 	 */
-    public function restore_tool_intro()
+    public function restore_tool_intro($sessionId = 0)
     {
 		if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
+            $sessionId = intval($sessionId);
 			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
 			$resources = $this->course->resources;
 			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
@@ -1085,7 +1088,8 @@ class CourseRestorer
 				Database::query($sql);
                 $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course($tool_intro->intro_text,$this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
 				$sql = "INSERT INTO ".$tool_intro_table." SET c_id = ".$this->destination_course_id." , id='".self::DBUTF8escapestring($tool_intro->id)."', intro_text = '".self::DBUTF8escapestring($tool_intro->intro_text)."'";
-				Database::query($sql);
+				$sql.= ", session_id = $sessionId";
+                Database::query($sql);
 
 				$this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = Database::insert_id();
 			}
@@ -1125,9 +1129,10 @@ class CourseRestorer
 	/**
 	 * Restore events
 	 */
-    public function restore_events()
+    public function restore_events($sessionId = 0)
     {
 		if ($this->course->has_resources(RESOURCE_EVENT)) {
+            $sessionId = intval($sessionId);
 			$table = Database :: get_course_table(TABLE_AGENDA);
 			$resources = $this->course->resources;
 			foreach ($resources[RESOURCE_EVENT] as $id => $event) {
@@ -1141,6 +1146,7 @@ class CourseRestorer
                         all_day = '".$event->all_day."',
         				start_date = '".$event->start_date."',
         				end_date = '".$event->end_date."'";
+                $sql.= ", session_id = $sessionId";
 
 				Database::query($sql);
 				$new_event_id = Database::insert_id();
@@ -1219,9 +1225,10 @@ class CourseRestorer
 	/**
 	 * Restore announcements
 	 */
-    public function restore_announcements()
+    public function restore_announcements($sessionId = 0)
     {
 		if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
+            $sessionId = intval($sessionId);
 			$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
 			$resources = $this->course->resources;
 			foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
@@ -1235,7 +1242,8 @@ class CourseRestorer
 							"content = '".self::DBUTF8escapestring($announcement->content)."', " .
 							"end_date = '".$announcement->date."', " .
 							"display_order = '".$announcement->display_order."', " .
-							"email_sent = '".$announcement->email_sent."'";
+							"email_sent = '".$announcement->email_sent."', "
+                    . "session_id = $sessionId";
 				Database::query($sql);
 				$new_announcement_id = Database::insert_id();
 				$this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id;
@@ -1675,11 +1683,14 @@ class CourseRestorer
     }
 
     /**
-	 * Restore surveys
-	 */
-    public function restore_surveys()
+     * Restore surveys
+     * @param int $sessionId Optional. The session id
+     */
+    public function restore_surveys($sessionId = 0)
     {
-		if ($this->course->has_resources(RESOURCE_SURVEY)) {
+        $sessionId = intval($sessionId);
+
+        if ($this->course->has_resources(RESOURCE_SURVEY)) {
 			$table_sur = Database :: get_course_table(TABLE_SURVEY);
 			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
 			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
@@ -1743,7 +1754,8 @@ class CourseRestorer
 						"invited = '0', " .
 						"answered = '0', " .
 						"invite_mail = '".self::DBUTF8escapestring($survey->invite_mail)."', " .
-						"reminder_mail = '".self::DBUTF8escapestring($survey->reminder_mail)."'";
+						"reminder_mail = '".self::DBUTF8escapestring($survey->reminder_mail)."', ".
+                        "session_id = $sessionId";
 
 				//An existing survey exists with the same code and the same language
 				if (Database::num_rows($result_check) == 1) {
@@ -1777,7 +1789,8 @@ class CourseRestorer
 									"invited = '0', " .
 									"answered = '0', " .
 									"invite_mail = '".self::DBUTF8escapestring($survey->invite_mail)."', " .
-									"reminder_mail = '".self::DBUTF8escapestring($survey->reminder_mail)."'";
+									"reminder_mail = '".self::DBUTF8escapestring($survey->reminder_mail)."', ".
+                                    "session_id = $sessionId";
 
 							//Insert the new source survey
 							Database::query($sql);
@@ -2197,8 +2210,9 @@ class CourseRestorer
      * @deprecated use restore_works
      *
 	 */
-	public function restore_student_publication()
+	public function restore_student_publication($sessionId = 0)
     {
+        $sessionId = intval($sessionId);
 		$work_assignment_table  = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
 		$work_table    			= Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
 		$item_property_table  	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
@@ -2215,6 +2229,7 @@ class CourseRestorer
             unset($folder['id']);
 			$folder['c_id'] = $this->destination_course_id;
             $folder['parent_id'] = 0;
+            $folder['session_id'] = $sessionId;
 			$new_id = Database::insert($work_table, $folder);
 
             if ($new_id) {
@@ -2244,6 +2259,7 @@ class CourseRestorer
                 foreach ($sub_folders  as $sub_folder) {
                     $sub_folder['c_id'] = $this->destination_course_id;
                     $sub_folder['ref'] = $new_id;
+                    $sub_folder['session_id'] = $sessionId;
                     $new_item_id = Database::insert($item_property_table, $sub_folder);
                 }
 

+ 13 - 4
main/coursecopy/classes/CourseSelectForm.class.php

@@ -135,9 +135,13 @@ class CourseSelectForm
 
 		//get destination course title
 		if (!empty($hidden_fields['destination_course'])) {
-			$course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
+            $sessionTitle = !empty($hidden_fields['destination_session']) ? ' (' . api_get_session_name(
+                $hidden_fields['destination_session']
+            ) . ')' : null;
+
+            $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
 			echo '<h3>';
-			echo get_lang('DestinationCourse').' : '.$course_infos['title'];
+			echo get_lang('DestinationCourse').' : '.$course_infos['title'] .  $sessionTitle;
 			echo '</h3>';
 		}
         echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
@@ -604,9 +608,14 @@ class CourseSelectForm
 		//get destination course title
 		if(!empty($hidden_fields['destination_course'])) {
 			require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
-			$course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
+             if (!empty($hidden_fields['destination_session'])) {
+                 $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
+             } else {
+                 $sessionTitle = null;
+             }
+            $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
 			echo '<h3>';
-				echo get_lang('DestinationCourse').' : '.$course_infos['title'];
+				echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
 			echo '</h3>';
 		}
 

+ 407 - 0
main/coursecopy/copy_course_session_selected.php

@@ -0,0 +1,407 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Copy resources from one course in a session to another one.
+ *
+ * @author Christian Fasanando <christian.fasanando@dokeos.com>
+ * @author Julio Montoya <gugli100@gmail.com> Lots of bug fixes/improvements
+ * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> Code conventions
+ * @package chamilo.backup
+ */
+/**
+ * Code
+ */
+/* INIT SECTION */
+
+// Language files that need to be included
+$language_file = array('coursebackup', 'admin');
+require_once '../inc/global.inc.php';
+
+$current_course_tool = TOOL_COURSE_MAINTENANCE;
+
+api_protect_course_script(true, true);
+
+require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
+require_once api_get_path(LIBRARY_PATH) . 'xajax/xajax.inc.php';
+
+require_once 'classes/CourseBuilder.class.php';
+require_once 'classes/CourseRestorer.class.php';
+require_once 'classes/CourseSelectForm.class.php';
+
+$xajax = new xajax();
+$xajax->registerFunction('searchCourses');
+
+if (!api_is_allowed_to_edit()) {
+    api_not_allowed(true);
+}
+
+if (!api_is_coach()) {
+    api_not_allowed(true);
+}
+
+$courseCode = api_get_course_id();
+$courseInfo = api_get_course_info($courseCode);
+$sessionId = api_get_session_id();
+
+if (empty($courseCode) OR empty($sessionId)) {
+    api_not_allowed(true);
+}
+
+// Remove memory and time limits as much as possible as this might be a long process...
+if (function_exists('ini_set')) {
+    ini_set('memory_limit', '256M');
+    ini_set('max_execution_time', 1800);
+}
+
+$this_section = SECTION_COURSES;
+$nameTools = get_lang('CopyCourse');
+$returnLink = api_get_path(
+        WEB_CODE_PATH
+    ) . 'course_info/maintenance_coach.php?' . api_get_cidreq();
+$interbreadcrumb[] = array(
+    'url' => $returnLink,
+    'name' => get_lang('Maintenance')
+);
+
+// Database Table Definitions
+$tbl_session_rel_course_rel_user = Database::get_main_table(
+        TABLE_MAIN_SESSION_COURSE_USER
+);
+$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
+$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
+
+/* FUNCTIONS */
+
+function make_select_session_list($name, $sessions, $attr = array())
+{
+
+    $attrs = '';
+    if (count($attr) > 0) {
+        foreach ($attr as $key => $value) {
+            $attrs .= ' ' . $key . '="' . $value . '"';
+        }
+    }
+    $output = '<select name="' . $name . '" ' . $attrs . '>';
+
+    if (count($sessions) == 0) {
+        $output .= '<option value = "0">' . get_lang(
+                'ThereIsNotStillASession'
+            ) . '</option>';
+    } else {
+        $output .= '<option value = "0">' . get_lang(
+                'SelectASession'
+            ) . '</option>';
+    }
+
+    if (is_array($sessions)) {
+        foreach ($sessions as $session) {
+            $category_name = '';
+            if (!empty($session['category_name'])) {
+                $category_name = ' (' . $session['category_name'] . ')';
+            }
+
+            $output .= '<option value="' . $session['id'] . '">' . $session['name'] . ' ' . $category_name . '</option>';
+        }
+    }
+    $output .= '</select>';
+    return $output;
+}
+
+/**
+ * Show the form to copy courses
+ * @global string $returnLink
+ * @global string $courseCode
+ */
+function displayForm()
+{
+    global $returnLink, $courseCode;
+
+    $courseInfo = api_get_course_info();
+    $sessionId = api_get_session_id();
+    $userId = api_get_user_id();
+
+    $sessions = SessionManager::getSessionsCoachedByUser($userId);
+    $html = '';
+    // Actions
+    $html .= '<div class="actions">';
+    // Link back to the documents overview
+    $html .= '<a href="' . $returnLink . '">' . Display::return_icon(
+            'back.png', get_lang('BackTo') . ' ' . get_lang('Maintenance'), '', ICON_SIZE_MEDIUM
+        ) . '</a>';
+    $html .= '</div>';
+
+    $html .= Display::return_message(
+            get_lang('CopyCourseFromSessionToSessionExplanation')
+    );
+
+    $html .= '<form name="formulaire" method="post" action="' . api_get_self(
+        ) . '?' . api_get_cidreq() . '" >';
+    $html .= '<table border="0" cellpadding="5" cellspacing="0" width="100%">';
+
+    // Source
+    $html .= '<tr><td width="15%"><b>' . get_lang(
+            'OriginCoursesFromSession'
+        ) . ':</b></td>';
+    $html .= '<td width="10%" align="left">' . api_get_session_name(
+            $sessionId
+        ) . '</td>';
+    $html .= '<td width="50%">';
+    $html .= "{$courseInfo['title']} ({$courseInfo['code']})" . '</td></tr>';
+
+    // Destination
+    $html .= '<tr><td width="15%"><b>' . get_lang(
+            'DestinationCoursesFromSession'
+        ) . ':</b></td>';
+    $html .= '<td width="10%" align="left"><div id="ajax_sessions_list_destination">';
+    $html .= '<select name="sessions_list_destination" onchange="javascript: xajax_searchCourses(this.value,\'destination\');">';
+    if (empty($sessions)) {
+        $html .= '<option value = "0">' . get_lang(
+                'ThereIsNotStillASession'
+            ) . '</option>';
+    } else {
+        $html .= '<option value = "0">' . get_lang(
+                'SelectASession'
+            ) . '</option>';
+        foreach ($sessions as $session) {
+            if ($session['id'] == $sessionId) {
+                continue;
+            }
+
+            if (!SessionManager::sessionHasCourse($session['id'], $courseCode)) {
+                continue;
+            }
+
+            $html .= '<option value="' . $session['id'] . '">' . $session['name'] . '</option>';
+        }
+    }
+
+    $html .= '</select ></div></td>';
+
+    $html .= '<td width="50%">';
+    $html .= '<div id="ajax_list_courses_destination">';
+    $html .= '<select id="destination" name="SessionCoursesListDestination[]" style="width:380px;" ></select></div></td>';
+    $html .= '</tr></table>';
+
+    $html .= "<fieldset>";
+    $html .= '<legend>' . get_lang('TypeOfCopy') . ' <small>(' . get_lang('CopyOnlySessionItems') . ')</small></legend>';
+    $html .= '<label class="radio"><input type="radio" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>';
+    $html .= get_lang('FullCopy') . '</label>';
+    $html .= '<label class="radio"><input type="radio" id="copy_option_2" name="copy_option" value="select_items"/>';
+    $html .= ' ' . get_lang('LetMeSelectItems') . '</label><br/>';
+
+    $html .= "</fieldset>";
+
+    $html .= '<button class="save" type="submit" onclick="javascript:if(!confirm(' . "'" . addslashes(
+            api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)
+        ) . "'" . ')) return false;">' . get_lang('CopyCourse') . '</button>';
+    $html .= '</form>';
+    echo $html;
+}
+
+function searchCourses($idSession, $type)
+{
+    $xajaxResponse = new XajaxResponse();
+    $return = null;
+    $courseCode = api_get_course_id();
+
+    if (!empty($type)) {
+        $idSession = intval($idSession);
+        $courseList = SessionManager::get_course_list_by_session_id($idSession);
+
+        $return .= '<select id="destination" name="SessionCoursesListDestination[]" style="width:380px;" >';
+
+        foreach ($courseList as $course) {
+            $course_list_destination[] = $course['code'];
+
+            if ($course['code'] != $courseCode) {
+                continue;
+            }
+
+            $courseTitle = str_replace("'", "\'", $course['title']);
+
+            $return .= '<option value="' . $course['code'] . '" title="' . @htmlspecialchars(
+                    $course['title'] . ' (' . $course['visual_code'] . ')', ENT_QUOTES, api_get_system_encoding()
+                ) . '">' .
+                $course['title'] . ' (' . $course['visual_code'] . ')</option>';
+        }
+        $return .= '</select>';
+        $_SESSION['course_list_destination'] = $course_list_destination;
+
+        // Send response by ajax
+        $xajaxResponse->addAssign(
+            'ajax_list_courses_destination', 'innerHTML', api_utf8_encode($return)
+        );
+    }
+    return $xajaxResponse;
+}
+
+$xajax->processRequests();
+
+/* HTML head extra */
+
+$htmlHeadXtra[] = $xajax->getJavascript(
+    api_get_path(WEB_LIBRARY_PATH) . 'xajax/'
+);
+$htmlHeadXtra[] = '<script>
+	function checkSelected(id_select,id_radio,id_title,id_destination) {
+        var num=0;
+        obj_origin = document.getElementById(id_select);
+        obj_destination = document.getElementById(id_destination);
+
+        for (x=0;x<obj_origin.options.length;x) {
+            if (obj_origin.options[x].selected) {
+                if (obj_destination.options.length > 0) {
+                    for (y=0;y<obj_destination.options.length;y) {
+                        if (obj_origin.options[x].value == obj_destination.options[y].value) {
+                            obj_destination.options[y].selected = true;
+                        }
+                    }
+                }
+                num;
+            } else {
+                if (obj_destination.options.length > 0) {
+                    for (y=0;y<obj_destination.options.length;y) {
+                        if (obj_origin.options[x].value == obj_destination.options[y].value) {
+                            obj_destination.options[y].selected = false;
+                        }
+                    }
+                }
+            }
+        }
+
+    if (num == 1) {
+        document.getElementById(id_radio).disabled = false;
+        document.getElementById(id_title).style.color = \'#000\';
+    } else {
+        document.getElementById(id_radio).disabled = true;
+        document.getElementById(id_title).style.color = \'#aaa\';
+    }
+
+	}
+</script>';
+
+Display::display_header($nameTools);
+
+/* MAIN CODE */
+
+if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') ||
+    (isset($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')
+) {
+
+    $destinationCourse = $destinationSession = '';
+    $originCourse = api_get_course_id();
+    $originSession = api_get_session_id();
+
+    if (isset($_POST['action']) && $_POST['action'] == 'course_select_form') {
+
+        $destinationCourse = $_POST['destination_course'];
+        $destinationSession = $_POST['destination_session'];
+        $course = CourseSelectForm::get_posted_course(
+            'copy_course', $originSession, $originCourse
+        );
+
+        $cr = new CourseRestorer($course);
+        $cr->restore($destinationCourse, $destinationSession);
+
+        Display::display_confirmation_message(get_lang('CopyFinished'));
+
+        displayForm();
+    } else {
+        $arrCourseOrigin = array();
+        $arrCourseDestination = array();
+        $destinationSession = '';
+
+        if (isset($_POST['SessionCoursesListDestination'])) {
+            $arrCourseDestination = $_POST['SessionCoursesListDestination'];
+
+            if (!empty($arrCourseDestination)) {
+                $arrCourseOrigin = SessionManager::get_course_list_by_session_id(
+                    api_get_session_id(),
+                    $courseInfo['title']
+                );
+            }
+        }
+
+        if (isset($_POST['sessions_list_destination'])) {
+            $destinationSession = $_POST['sessions_list_destination'];
+        }
+
+        if ((is_array($arrCourseOrigin) && count($arrCourseOrigin) > 0) && !empty($destinationSession)) {
+            //We need only one value
+            if (count($arrCourseOrigin) > 1 || count($arrCourseDestination) > 1) {
+                Display::display_error_message(
+                    get_lang('YouMustSelectACourseFromOriginalSession')
+                );
+            } else {
+                $courseDestination = $arrCourseDestination[0];
+
+                $cb = new CourseBuilder('', $courseInfo);
+                $course = $cb->build(
+                    $originSession, $courseCode
+                );
+                $cr = new CourseRestorer($course);
+                $cr->restore($courseDestination, $destinationSession);
+
+                Display::display_confirmation_message(get_lang('CopyFinished'));
+            }
+
+            displayForm();
+        } else {
+            Display::display_error_message(
+                get_lang('YouMustSelectACourseFromOriginalSession')
+            );
+            displayForm();
+        }
+    }
+} elseif (isset($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
+    // Else, if a CourseSelectForm is requested, show it
+    if (api_get_setting('show_glossary_in_documents') != 'none') {
+        Display::display_normal_message(
+            get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary')
+        );
+    }
+
+    $arrCourseDestination = array();
+    $destinationSession = '';
+
+    if (isset($_POST['SessionCoursesListDestination'])) {
+        $arrCourseDestination = $_POST['SessionCoursesListDestination'];
+    }
+    if (isset($_POST['sessions_list_destination'])) {
+        $destinationSession = $_POST['sessions_list_destination'];
+    }
+
+    if (!empty($destinationSession)) {
+        Display::display_normal_message(
+            get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz')
+        );
+
+        $cb = new CourseBuilder('', $courseInfo);
+        $course = $cb->build($sessionId, $courseCode);
+        $hiddenFields['destination_course'] = $arrCourseDestination[0];
+        $hiddenFields['destination_session'] = $destinationSession;
+        $hiddenFields['origin_course'] = api_get_course_id();
+        $hiddenFields['origin_session'] = api_get_session_id();
+
+        CourseSelectForm :: display_form($course, $hiddenFields, true);
+
+        echo '<div style="float:right"><a href="javascript:window.back();">' .
+            Display::return_icon(
+                'back.png', get_lang('Back') . ' ' . get_lang('To') . ' ' . get_lang(
+                    'PlatformAdmin'
+                ), array('style' => 'vertical-align:middle')
+            ) .
+            get_lang('Back') . '</a></div>';
+    } else {
+        Display::display_error_message(
+            get_lang('You must select a course from original session and select a destination session')
+        );
+        displayForm();
+    }
+} else {
+    displayForm();
+}
+
+Display::display_footer();

+ 1 - 1
main/inc/lib/course_home.lib.php

@@ -648,7 +648,7 @@ class CourseHome
                     }
                 }
 
-                if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
+                if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) {
                     continue;
                 }
 

+ 69 - 0
main/inc/lib/sessionmanager.lib.php

@@ -5197,4 +5197,73 @@ class SessionManager
         }
     }
 
+    /**
+     * Get the session coached by a user
+     * @param int $coachId The coach id
+     * @param boolean $checkSessionRelUserVisibility Optional. Check the session visibility 
+     * @return array The session list
+     */
+    public static function getSessionsCoachedByUser($coachId, $checkSessionRelUserVisibility = false)
+    {
+        $sessions = self::get_sessions_by_general_coach($coachId);
+        $sessionsByCoach = self::get_sessions_by_coach($coachId);
+
+        if (!empty($sessionsByCoach)) {
+            $sessions = array_merge($sessions, $sessionsByCoach);
+        }
+        //Remove  repeated sessions
+        if (!empty($sessions)) {
+            $cleanSessions = array();
+            foreach ($sessions as $session) {
+                $cleanSessions[$session['id']] = $session;
+            }
+            $sessions = $cleanSessions;
+        }
+
+        if ($checkSessionRelUserVisibility) {
+            if (!empty($sessions)) {
+                $newSessions = array();
+                foreach ($sessions as $session) {
+                    $visibility = api_get_session_visibility($session['id']);
+                    if ($visibility == SESSION_INVISIBLE) {
+                        continue;
+                    }
+                    $newSessions[] = $session;
+                }
+                $sessions = $newSessions;
+            }
+        }
+        return $sessions;
+    }
+
+    /**
+     * Check if the course belongs to the session
+     * @param int $sessionId The session id
+     * @param string $courseCode The course code
+     */
+    public static function sessionHasCourse($sessionId, $courseCode) {
+        $sessionId = intval($sessionId);
+        $courseCode = Database::escape_string($courseCode);
+
+        $courseTablee = Database::get_main_table(TABLE_MAIN_COURSE);
+        $sessionRelCourseTable = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+
+        $sql = "SELECT COUNT(1) AS qty FROM $courseTablee c "
+            . "INNER JOIN $sessionRelCourseTable src "
+            . "ON c.code = src.course_code "
+            . "WHERE src.id_session = $sessionId "
+            . "AND c.code = '$courseCode'";
+
+        $result = Database::query($sql);
+
+        if ($result !== false) {
+            $data = Database::fetch_assoc($result);
+
+            if ($data['qty'] > 0) {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }

+ 2 - 0
main/install/configuration.dist.php

@@ -249,6 +249,8 @@ $_configuration['system_stable']     = NEW_VERSION_STABLE;
 //$_configuration['default_template'] = 'default'; // (main/template/default)
 // Show reduce LP report
 //$_configuration['lp_show_reduced_report'] = false;
+//Allow session-to-session copy
+//$_configuration['allow_session_course_copy_for_teachers'] = true;
 // Hide the logout button
 //$_configuration['hide_logout_button'] = true;