Browse Source

Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

Yannick Warnier 10 years ago
parent
commit
ceb699d277
100 changed files with 1071 additions and 1485 deletions
  1. 0 6
      certificates/index.php
  2. 7 3
      composer.json
  3. 5 1
      documentation/changelog.html
  4. 0 6
      index.php
  5. 4 4
      main/admin/access_url_add_usergroup_to_url.php
  6. 4 5
      main/admin/access_url_check_user_session.php
  7. 17 16
      main/admin/access_url_edit_courses_to_url.php
  8. 0 1
      main/admin/access_url_edit_usergroup_to_url.php
  9. 32 29
      main/admin/add_courses_to_session.php
  10. 0 1
      main/admin/add_sessions_to_promotion.php
  11. 0 1
      main/admin/add_students_to_session.php
  12. 0 2
      main/admin/add_teachers_to_session.php
  13. 51 45
      main/admin/add_users_to_session.php
  14. 1 1
      main/admin/add_users_to_usergroup.php
  15. 3 4
      main/admin/career_dashboard.php
  16. 1 1
      main/admin/class_import.php
  17. 1 1
      main/admin/class_user_import.php
  18. 9 9
      main/admin/configure_inscription.php
  19. 21 17
      main/admin/course_add.php
  20. 19 18
      main/admin/course_edit.php
  21. 8 8
      main/admin/course_export.php
  22. 8 9
      main/admin/course_import.php
  23. 8 4
      main/admin/course_information.php
  24. 16 15
      main/admin/course_list.php
  25. 26 15
      main/admin/course_request_accepted.php
  26. 1 3
      main/admin/course_request_edit.php
  27. 23 19
      main/admin/course_request_rejected.php
  28. 9 9
      main/admin/course_request_review.php
  29. 13 5
      main/admin/course_user_import.php
  30. 8 4
      main/admin/course_user_import_by_email.php
  31. 19 11
      main/admin/dashboard_add_courses_to_user.php
  32. 2 3
      main/admin/dashboard_add_sessions_to_user.php
  33. 7 10
      main/admin/ldap_import_students_to_session.php
  34. 17 18
      main/admin/ldap_synchro.php
  35. 23 18
      main/admin/resume_session.php
  36. 1 1
      main/admin/session_category_add.php
  37. 29 22
      main/admin/session_course_edit.php
  38. 16 8
      main/admin/session_course_list.php
  39. 65 51
      main/admin/session_course_user.php
  40. 18 11
      main/admin/session_course_user_list.php
  41. 105 91
      main/admin/session_export.php
  42. 37 38
      main/admin/session_import.php
  43. 3 2
      main/admin/session_list.php
  44. 1 1
      main/admin/session_user_import.php
  45. 1 1
      main/admin/skill_badge_create.php
  46. 1 1
      main/admin/skill_badge_list.php
  47. 1 1
      main/admin/skills_import.php
  48. 20 14
      main/admin/special_exports.php
  49. 9 8
      main/admin/subscribe_user2course.php
  50. 3 3
      main/admin/teacher_time_report.php
  51. 2 4
      main/admin/user_add.php
  52. 8 21
      main/admin/user_edit.php
  53. 13 5
      main/admin/user_export.php
  54. 1 1
      main/admin/user_import.php
  55. 13 11
      main/admin/user_information.php
  56. 15 13
      main/admin/user_move_stats.php
  57. 1 1
      main/admin/user_update_import.php
  58. 1 1
      main/admin/usergroup_export.php
  59. 1 1
      main/admin/usergroup_import.php
  60. 1 1
      main/admin/usergroup_user_import.php
  61. 0 2
      main/admin/usergroups.php
  62. 0 41
      main/announcements/announcements.php
  63. 2 1
      main/attendance/attendance_controller.php
  64. 1 1
      main/attendance/attendance_sheet.php
  65. 12 12
      main/auth/cas/authcas.php
  66. 4 1
      main/auth/courses_controller.php
  67. 1 1
      main/auth/inscription.php
  68. 13 14
      main/auth/ldap/authldap.php
  69. 10 10
      main/auth/shibboleth/app/shibboleth.class.php
  70. 3 3
      main/auth/shibboleth/db/shibboleth_upgrade.class.php
  71. 4 5
      main/auth/shibboleth/lib/shibboleth_session.class.php
  72. 19 20
      main/blog/blog.php
  73. 0 136
      main/blog/calendar.php
  74. 0 159
      main/blog/tbl_change.js
  75. 5 5
      main/calendar/agenda.php
  76. 1 1
      main/calendar/agenda_list.php
  77. 0 123
      main/calendar/calendar.php
  78. 0 159
      main/calendar/tbl_change.js
  79. 29 18
      main/chat/chat_whoisonline.php
  80. 7 4
      main/course_description/course_description_controller.php
  81. 6 3
      main/course_info/infocours.php
  82. 1 1
      main/course_info/legal.php
  83. 7 2
      main/course_progress/index.php
  84. 27 13
      main/course_progress/thematic_controller.php
  85. 12 12
      main/coursecopy/classes/Announcement.class.php
  86. 1 1
      main/coursecopy/classes/Attendance.class.php
  87. 5 5
      main/coursecopy/classes/Course.class.php
  88. 58 34
      main/coursecopy/classes/CourseBuilder.class.php
  89. 2 2
      main/coursecopy/classes/CourseCopyLearnpath.class.php
  90. 3 2
      main/coursecopy/classes/CourseCopyTestCategory.php
  91. 6 5
      main/coursecopy/classes/CourseDescription.class.php
  92. 2 2
      main/coursecopy/classes/CourseRecycler.class.php
  93. 83 37
      main/coursecopy/classes/CourseRestorer.class.php
  94. 2 2
      main/coursecopy/classes/CourseSelectForm.class.php
  95. 5 4
      main/coursecopy/classes/CourseSession.class.php
  96. 2 2
      main/coursecopy/classes/Document.class.php
  97. 2 2
      main/coursecopy/classes/Event.class.php
  98. 3 2
      main/coursecopy/classes/Forum.class.php
  99. 2 2
      main/coursecopy/classes/ForumCategory.class.php
  100. 2 2
      main/coursecopy/classes/ForumPost.class.php

+ 0 - 6
certificates/index.php

@@ -5,12 +5,7 @@
  * @package chamilo.certificate
  */
 
-/**
- * Initialization
- */
-
 require_once '../main/inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'certificate.lib.php';
 
 $action = isset($_GET['action']) ? $_GET['action'] : null;
 
@@ -42,7 +37,6 @@ switch ($action) {
             $pageFormat = $pdfParams['orientation'] == 'landscape' ? 'A4-L' : 'A4';
 
             $userInfo = api_get_user_info($certificate->user_id);
-
             $pdfName = replace_dangerous_char(get_lang('Certificate') . ' ' . $userInfo['username']);
 
             $pdf = new PDF($pageFormat, $pdfParams['orientation'], $pdfParams);

+ 7 - 3
composer.json

@@ -48,12 +48,17 @@
         "jbroadway/urlify": "1.0.3-stable",
         "monolog/monolog": "~1.0",
         "doctrine/orm": "~2.2,>=2.2.3,<2.5",
+        "doctrine/migrations": "1.0.*@dev",
         "symfony/doctrine-bridge": "2.6.4",
         "symfony/validator": "2.6.4",
         "gedmo/doctrine-extensions": "~2.3",
         "sonata-project/user-bundle": "~2.2",
-        "fxp/composer-asset-plugin": "~1.0",
+	    "ramsey/array_column": "~1.1",
+        "patchwork/utf8": "~1.2",
+        "ddeboer/data-import": "@stable",
+        "phpoffice/phpexcel": "~1.8",
         "webit/eval-math": "dev-master",
+        "fxp/composer-asset-plugin": "~1.0",
         "bower-asset/bootstrap": "3.3.*",
         "bower-asset/fontawesome": "4.3.*",
         "bower-asset/moment": "2.9",
@@ -65,8 +70,7 @@
         "bower-asset/mediaelement": "2.16.*",
         "bower-asset/modernizr": "2.8.*",
         "bower-asset/jqueryui-timepicker-addon": "1.5.*",
-        "ramsey/array_column": "~1.1",
-        "bower-asset/imageMap-resizer": "0.5.3"
+	    "bower-asset/imageMap-resizer": "0.5.3"
     },
     "require-dev": {
         "behat/behat": "2.5.*@stable",

+ 5 - 1
documentation/changelog.html

@@ -59,7 +59,11 @@
 <h3>Stylesheets and theming</h3>
 <h3>Web services</h3>
 <h3>Removals</h3>
-
+<ul>
+  <li>main/reservation code was removed</li>
+  <li>main/metadata code was removed</li>
+  <li>Tables "userinfo_def" and "userinfo_def_content" were removed as well as the code.</li>
+</ul>
 
 <h1>Chamilo 1.9.10.2 - Sipán, 19th of March, 2015</h1>
 <h3>Release notes - summary</h3>

+ 0 - 6
index.php

@@ -13,7 +13,6 @@ define('CHAMILO_HOMEPAGE', true);
 $cidReset = true;
 
 require_once 'main/inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'userportal.lib.php';
 require_once 'main/chat/chat_functions.lib.php';
 
 // The section (for the tabs).
@@ -101,11 +100,6 @@ if (!empty($_POST['submitAuth'])) {
         Database::free_result($result_last_login);
 
         //Event::event_login();
-        if (api_is_platform_admin()) {
-            // decode all open event informations and fill the track_c_* tables
-            include api_get_path(LIBRARY_PATH).'stats.lib.inc.php';
-            decodeOpenInfos();
-        }
     }
     // End login -- if ($_POST['submitAuth'])
 } else {

+ 4 - 4
main/admin/access_url_add_usergroup_to_url.php

@@ -24,10 +24,10 @@ $firstLetterUserGroup = null;
 $courses = array();
 $url_list = array();
 
-$tbl_access_url_rel_course 	= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
-$tbl_access_url 			= Database :: get_main_table(TABLE_MAIN_ACCESS_URL);
-$tbl_user 					= Database :: get_main_table(TABLE_MAIN_USER);
-$tbl_course					= Database :: get_main_table(TABLE_MAIN_COURSE);
+$tbl_access_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+$tbl_access_url = Database:: get_main_table(TABLE_MAIN_ACCESS_URL);
+$tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
+$tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
 
 $tool_name = get_lang('AddUserGroupToURL');
 $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));

+ 4 - 5
main/admin/access_url_check_user_session.php

@@ -21,9 +21,7 @@ $interbreadcrumb[]=array('url' => 'session_list.php','name' => get_lang('Session
 // Database Table Definitions
 $tbl_user							= Database::get_main_table(TABLE_MAIN_USER);
 $tbl_session_rel_user				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
-
 $table_access_url_user              = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-
 $url_id                             = api_get_current_access_url_id();
 
 $action = $_GET['action'];
@@ -72,9 +70,10 @@ foreach($session_list  as $session_item) {
     $sql = "SELECT u.user_id, lastname, firstname, username, access_url_id
             FROM $tbl_user u
             INNER JOIN $tbl_session_rel_user su
-            ON u.user_id = su.id_user AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-            LEFT OUTER JOIN $table_access_url_user uu ON (uu.user_id = u.user_id)
-            WHERE su.id_session = $session_id AND $access_where
+            ON u.user_id = su.user_id AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
+            LEFT OUTER JOIN $table_access_url_user uu
+            ON (uu.user_id = u.user_id)
+            WHERE su.session_id = $session_id AND $access_where
             $order_clause";
 
     $result = Database::query($sql);

+ 17 - 16
main/admin/access_url_edit_courses_to_url.php

@@ -83,17 +83,17 @@ $UserList = $SessionList = array();
 $users = $sessions = array();
 
 if (isset($_POST['form_sent']) && $_POST['form_sent']) {
-	$form_sent=$_POST['form_sent'];
-	$course_list=$_POST['course_list'];
+	$form_sent = $_POST['form_sent'];
+	$course_list = $_POST['course_list'];
 
 	if (!is_array($course_list)) {
-		$course_list=array();
+		$course_list = array();
 	}
 
 	if ($form_sent == 1) {
 		if ($access_url_id==0) {
 			header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
-		} elseif(is_array($course_list) ) {
+		} elseif (is_array($course_list)) {
 			UrlManager::update_urls_rel_course($course_list, $access_url_id);
 			header('Location: access_urls.php?action=show_message&message='.get_lang('CoursesWereEdited'));
 		}
@@ -115,16 +115,16 @@ $no_course_list = $course_list = array();
 $ajax_search = $add_type == 'unique' ? true : false;
 
 if($ajax_search) {
-	$courses=UrlManager::get_url_rel_course_data($access_url_id);
-	foreach($courses as $course) {
-		$course_list[$course['course_code']] = $course ;
+	$courses = UrlManager::get_url_rel_course_data($access_url_id);
+	foreach ($courses as $course) {
+		$course_list[$course['c_id']] = $course;
 	}
 } else {
-	$courses=UrlManager::get_url_rel_course_data();
+	$courses = UrlManager::get_url_rel_course_data();
 
-	foreach($courses as $course) {
-		if($course['access_url_id'] == $access_url_id) {
-			$course_list[$course['course_code']] = $course ;
+	foreach ($courses as $course) {
+		if ($course['access_url_id'] == $access_url_id) {
+			$course_list[$course['c_id']] = $course;
 		}
 	}
 
@@ -132,12 +132,13 @@ if($ajax_search) {
 	$sql="SELECT code, title
 	  	  	FROM $tbl_course u
 			ORDER BY title, code";
-	$result=Database::query($sql);
-	$courses=Database::store_result($result);
+	$result = Database::query($sql);
+	$courses = Database::store_result($result);
 	$course_list_leys = array_keys($course_list);
-	foreach($courses as $course) {
-		if (!in_array($course['code'],$course_list_leys))
-			$no_course_list[$course['code']] = $course ;
+	foreach ($courses as $course) {
+		if (!in_array($course['id'], $course_list_leys)) {
+			$no_course_list[$course['id']] = $course;
+		}
 	}
 }
 

+ 0 - 1
main/admin/access_url_edit_usergroup_to_url.php

@@ -317,7 +317,6 @@ function loadUsersInSelect(select){
 	else  // XMLHttpRequest non supporté par le navigateur
 	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
 
-	//xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
 	xhr_object.open("POST", "loadUsersInSelect.ajax.php");
 	xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 	nosessionUsers = makepost(document.getElementById('origin_users'));

+ 32 - 29
main/admin/add_courses_to_session.php

@@ -115,24 +115,25 @@ $ajax_search = $add_type == 'unique' ? true : false;
 $nosessionCourses = $sessionCourses = array();
 if ($ajax_search) {
 
-    $sql="SELECT code, title, visual_code, id_session
+    $sql="SELECT course.id, code, title, visual_code, session_id
 			FROM $tbl_course course
 			INNER JOIN $tbl_session_rel_course session_rel_course
-				ON course.code = session_rel_course.course_code
-				AND session_rel_course.id_session = ".intval($sessionId)."
+				ON
+				    course.id = session_rel_course.c_id AND
+				    session_rel_course.session_id = ".intval($sessionId)."
 			ORDER BY ".(sizeof($courses)?"(code IN(".implode(',',$courses).")) DESC,":"")." title";
 
     if (api_is_multiple_url_enabled()) {
-        $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+        $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
         $access_url_id = api_get_current_access_url_id();
         if ($access_url_id != -1){
-            $sql="SELECT code, title, visual_code, id_session
+            $sql="SELECT course.id, code, title, visual_code, session_id
 			FROM $tbl_course course
 			INNER JOIN $tbl_session_rel_course session_rel_course
-				ON course.code = session_rel_course.course_code
-				AND session_rel_course.id_session = ".intval($sessionId)."
-				INNER JOIN $tbl_course_rel_access_url url_course ON (url_course.course_code=course.code)
-				WHERE access_url_id = $access_url_id
+				ON course.id = session_rel_course.c_id
+				AND session_rel_course.session_id = ".intval($sessionId)."
+				INNER JOIN $tbl_course_rel_access_url url_course ON (url_course.c_id = course.id)
+            WHERE access_url_id = $access_url_id
 			ORDER BY ".(sizeof($courses)?"(code IN(".implode(',',$courses).")) DESC,":"")." title";
         }
     }
@@ -141,26 +142,29 @@ if ($ajax_search) {
     $Courses = Database::store_result($result);
 
     foreach ($Courses as $course) {
-        $sessionCourses[$course['code']] = $course ;
+        $sessionCourses[$course['id']] = $course ;
     }
 } else {
-    $sql = "SELECT code, title, visual_code, id_session
+    $sql = "SELECT course.id, code, title, visual_code, session_id
 			FROM $tbl_course course
 			LEFT JOIN $tbl_session_rel_course session_rel_course
-				ON course.code = session_rel_course.course_code
-				AND session_rel_course.id_session = ".intval($sessionId)."
+            ON
+                course.id = session_rel_course.c_id AND
+                session_rel_course.session_id = ".intval($sessionId)."
 			ORDER BY ".(sizeof($courses)?"(code IN(".implode(',',$courses).")) DESC,":"")." title";
 
     if (api_is_multiple_url_enabled()) {
-        $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+        $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
         $access_url_id = api_get_current_access_url_id();
         if ($access_url_id != -1){
-            $sql="SELECT code, title, visual_code, id_session
+            $sql="SELECT course.id, code, title, visual_code, session_id
 				FROM $tbl_course course
 				LEFT JOIN $tbl_session_rel_course session_rel_course
-					ON course.code = session_rel_course.course_code
-					AND session_rel_course.id_session = ".intval($sessionId)."
-				INNER JOIN $tbl_course_rel_access_url url_course ON (url_course.course_code=course.code)
+                ON
+                    course.id = session_rel_course.c_id AND
+                    session_rel_course.session_id = ".intval($sessionId)."
+				INNER JOIN $tbl_course_rel_access_url url_course
+				ON (url_course.c_id = course.id)
 				WHERE access_url_id = $access_url_id
 				ORDER BY ".(sizeof($courses)?"(code IN(".implode(',',$courses).")) DESC,":"")." title";
         }
@@ -168,13 +172,14 @@ if ($ajax_search) {
     $result = Database::query($sql);
     $Courses = Database::store_result($result);
     foreach ($Courses as $course) {
-        if ($course['id_session'] == $sessionId) {
-            $sessionCourses[$course['code']] = $course ;
+        if ($course['session_id'] == $sessionId) {
+            $sessionCourses[$course['id']] = $course ;
         } else {
-            $nosessionCourses[$course['code']] = $course ;
+            $nosessionCourses[$course['id']] = $course ;
         }
     }
 }
+
 unset($Courses);
 ?>
     <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $sessionId; ?><?php if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
@@ -198,15 +203,13 @@ unset($Courses);
                 } else {
                     ?>
                     <div id="ajax_list_courses_multiple">
-                        <select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" class="form-control"> <?php
-                            foreach($nosessionCourses as $enreg) {
-                                ?>
-                                <option value="<?php echo $enreg['code']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES).'"'; if(in_array($enreg['code'],$CourseList)) echo 'selected="selected"'; ?>>
+                        <select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" class="form-control">
+                            <?php foreach ($nosessionCourses as $enreg) { ?>
+                                <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES).'"'; if(in_array($enreg['code'],$CourseList)) echo 'selected="selected"'; ?>>
                                     <?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?>
                                 </option>
-                            <?php
-                            }
-                            ?></select>
+                            <?php } ?>
+                        </select>
                     </div>
                 <?php
                 }
@@ -266,7 +269,7 @@ unset($Courses);
                     <?php
                     foreach($sessionCourses as $enreg) {
                         ?>
-                        <option value="<?php echo $enreg['code']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>">
+                        <option value="<?php echo $enreg['id']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>">
                             <?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?>
                         </option>
                     <?php

+ 0 - 1
main/admin/add_sessions_to_promotion.php

@@ -322,7 +322,6 @@ function loadUsersInSelect(select) {
     else  // XMLHttpRequest non supporté par le navigateur
     alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
 
-    //xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
     xhr_object.open("POST", "loadUsersInSelect.ajax.php");
     xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
     nosessionUsers = makepost(document.getElementById('session_not_in_promotion'));

+ 0 - 1
main/admin/add_students_to_session.php

@@ -154,7 +154,6 @@ echo Display::input('hidden', 'form_sent', '1');
         else  // XMLHttpRequest non supporté par le navigateur
             alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
 
-        //xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
         xhr_object.open("POST", "loadUsersInSelect.ajax.php");
         xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         nosessionUsers = makepost(document.getElementById('session_not_in_promotion'));

+ 0 - 2
main/admin/add_teachers_to_session.php

@@ -158,7 +158,6 @@ echo Display::input('hidden', 'form_sent', '1');
         else  // XMLHttpRequest non supporté par le navigateur
             alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
 
-        //xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
         xhr_object.open("POST", "loadUsersInSelect.ajax.php");
         xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
         nosessionUsers = makepost(document.getElementById('session_not_in_promotion'));
@@ -170,7 +169,6 @@ echo Display::input('hidden', 'form_sent', '1');
         xhr_object.onreadystatechange = function() {
             if(xhr_object.readyState == 4) {
                 document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
-                //alert(xhr_object.responseText);
             }
         }
     }

+ 51 - 45
main/admin/add_users_to_session.php

@@ -82,6 +82,7 @@ function search_users($needle, $type)
         $needle = Database::escape_string($needle);
         $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
         $showOfficialCode = false;
+
         global $_configuration;
         if (isset($_configuration['order_user_list_by_official_code']) &&
             $_configuration['order_user_list_by_official_code']
@@ -101,8 +102,8 @@ function search_users($needle, $type)
         if (!empty($id_session)) {
             $id_session = intval($id_session);
             // check id_user from session_rel_user table
-            $sql = 'SELECT id_user FROM '.$tbl_session_rel_user.'
-                    WHERE id_session ="'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' ';
+            $sql = 'SELECT user_id FROM '.$tbl_session_rel_user.'
+                    WHERE session_id = "'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' ';
             $res = Database::query($sql);
             $user_ids = array();
             if (Database::num_rows($res) > 0) {
@@ -114,6 +115,7 @@ function search_users($needle, $type)
                 $cond_user_id = ' AND user.user_id NOT IN('.implode(",",$user_ids).')';
             }
         }
+
         switch ($type) {
             case 'single':
                 // search users where username or firstname or lastname begins likes $needle
@@ -142,9 +144,9 @@ function search_users($needle, $type)
             case 'any_session':
                 $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname, official_code
                         FROM '.$tbl_user.' user
-                        LEFT OUTER JOIN '.$tbl_session_rel_user.' s ON (s.id_user = user.user_id)
+                        LEFT OUTER JOIN '.$tbl_session_rel_user.' s ON (s.user_id = user.user_id)
                         WHERE
-                            s.id_user IS null AND
+                            s.user_id IS NULL AND
                             user.status<>'.DRH.' AND
                             user.status<>6 '.$cond_user_id.
                         $order_clause;
@@ -159,7 +161,8 @@ function search_users($needle, $type)
                     case 'single':
                         $sql = 'SELECT user.user_id, username, lastname, firstname, official_code
                         FROM '.$tbl_user.' user
-                        INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
+                        INNER JOIN '.$tbl_user_rel_access_url.' url_user
+                        ON (url_user.user_id = user.user_id)
                         WHERE
                             access_url_id = '.$access_url_id.' AND
                             (
@@ -185,11 +188,13 @@ function search_users($needle, $type)
                     case 'any_session' :
                         $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname, official_code
                             FROM '.$tbl_user.' user
-                            LEFT OUTER JOIN '.$tbl_session_rel_user.' s ON (s.id_user = user.user_id)
-                            INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
+                            LEFT OUTER JOIN '.$tbl_session_rel_user.' s
+                            ON (s.user_id = user.user_id)
+                            INNER JOIN '.$tbl_user_rel_access_url.' url_user
+                            ON (url_user.user_id=user.user_id)
                             WHERE
                                 access_url_id = '.$access_url_id.' AND
-                                s.id_user IS null AND
+                                s.user_id IS null AND
                                 user.status<>'.DRH.' AND
                                 user.status<>6 '.$cond_user_id.
                             $order_clause;
@@ -292,13 +297,13 @@ $sessions = array();
 $noPHP_SELF = true;
 
 if (isset($_POST['form_sent']) && $_POST['form_sent']) {
-    $form_sent             = $_POST['form_sent'];
-    $firstLetterUser       = $_POST['firstLetterUser'];
-    $firstLetterSession    = $_POST['firstLetterSession'];
-    $UserList              = $_POST['sessionUsersList'];
+    $form_sent = $_POST['form_sent'];
+    $firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : '';
+    $firstLetterSession = isset($_POST['firstLetterSession']) ? $_POST['firstLetterSession'] : '';
+    $UserList = $_POST['sessionUsersList'];
 
     if (!is_array($UserList)) {
-        $UserList=array();
+        $UserList = array();
     }
 
     if ($form_sent == 1) {
@@ -328,12 +333,12 @@ if (isset($_configuration['order_user_list_by_official_code']) &&
 }
 
 if ($ajax_search) {
-    $sql = "SELECT user_id, lastname, firstname, username, id_session, official_code
+    $sql = "SELECT u.user_id, lastname, firstname, username, session_id, official_code
             FROM $tbl_user u
             INNER JOIN $tbl_session_rel_user
-                ON $tbl_session_rel_user.id_user = u.user_id AND
+                ON $tbl_session_rel_user.user_id = u.user_id AND
                 $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                AND $tbl_session_rel_user.id_session = ".intval($id_session)."
+                AND $tbl_session_rel_user.session_id = ".intval($id_session)."
             WHERE u.status<>".DRH." AND u.status<>6
             $order_clause";
 
@@ -341,12 +346,12 @@ if ($ajax_search) {
         $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
         $access_url_id = api_get_current_access_url_id();
         if ($access_url_id != -1) {
-            $sql="SELECT u.user_id, lastname, firstname, username, id_session, official_code
+            $sql="SELECT u.user_id, lastname, firstname, username, session_id, official_code
             FROM $tbl_user u
             INNER JOIN $tbl_session_rel_user
-                ON $tbl_session_rel_user.id_user = u.user_id AND
+                ON $tbl_session_rel_user.user_id = u.user_id AND
                 $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                AND $tbl_session_rel_user.id_session = ".intval($id_session)."
+                AND $tbl_session_rel_user.session_id = ".intval($id_session)."
             INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
             WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
             $order_clause";
@@ -366,14 +371,14 @@ if ($ajax_search) {
         if ($sessionUser['status_in_session'] != 0) {
             continue;
         }
-        
+
         if (!array_key_exists($sessionUser['user_id'], $sessionUsersList)) {
             continue;
         }
 
-        if ($sessionUser['count'] != $countSessionCoursesList) {
+        /*if ($sessionUser['count'] != $countSessionCoursesList) {
             unset($sessionUsersList[$sessionUser['user_id']]);
-        }
+        }*/
     }
 
     unset($users); //clean to free memory
@@ -427,21 +432,20 @@ if ($ajax_search) {
         $order_clause = " AND u.creator_id = " . api_get_user_id() . $order_clause;
     }
     if ($use_extra_fields) {
-        $sql = "SELECT  user_id, lastname, firstname, username, id_session, official_code
+        $sql = "SELECT  user_id, lastname, firstname, username, session_id, official_code
                FROM $tbl_user u
                     LEFT JOIN $tbl_session_rel_user
-                    ON $tbl_session_rel_user.id_user = u.user_id AND
-                    $tbl_session_rel_user.id_session = '$id_session' AND
+                    ON $tbl_session_rel_user.user_id = u.user_id AND
+                    $tbl_session_rel_user.session_id = '$id_session' AND
                     $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
                 $where_filter AND u.status<>".DRH." AND u.status<>6
                 $order_clause";
-
     } else {
-        $sql = "SELECT  user_id, lastname, firstname, username, id_session, official_code
+        $sql = "SELECT  user_id, lastname, firstname, username, session_id, official_code
                 FROM $tbl_user u
                 LEFT JOIN $tbl_session_rel_user
-                ON $tbl_session_rel_user.id_user = u.user_id AND
-                $tbl_session_rel_user.id_session = '$id_session' AND
+                ON $tbl_session_rel_user.user_id = u.user_id AND
+                $tbl_session_rel_user.session_id = '$id_session' AND
                 $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
                 WHERE u.status<>".DRH." AND u.status<>6
                 $order_clause";
@@ -450,13 +454,14 @@ if ($ajax_search) {
         $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
         $access_url_id = api_get_current_access_url_id();
         if ($access_url_id != -1) {
-            $sql = "SELECT  u.user_id, lastname, firstname, username, id_session, official_code
+            $sql = "SELECT  u.user_id, lastname, firstname, username, session_id, official_code
                     FROM $tbl_user u
                     LEFT JOIN $tbl_session_rel_user
-                        ON $tbl_session_rel_user.id_user = u.user_id AND
-                        $tbl_session_rel_user.id_session = '$id_session' AND
+                        ON $tbl_session_rel_user.user_id = u.user_id AND
+                        $tbl_session_rel_user.session_id = '$id_session' AND
                         $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
-                    INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
+                    INNER JOIN $tbl_user_rel_access_url url_user
+                    ON (url_user.user_id = u.user_id)
                     WHERE access_url_id = $access_url_id $where_filter AND u.status<>".DRH." AND u.status<>6
                     $order_clause";
         }
@@ -478,11 +483,11 @@ if ($ajax_search) {
     unset($users); //clean to free memory
 
     //filling the correct users in list
-    $sql="SELECT  user_id, lastname, firstname, username, id_session, official_code
+    $sql="SELECT  user_id, lastname, firstname, username, session_id, official_code
           FROM $tbl_user u
           LEFT JOIN $tbl_session_rel_user
-          ON $tbl_session_rel_user.id_user = u.user_id AND
-            $tbl_session_rel_user.id_session = '$id_session' AND
+          ON $tbl_session_rel_user.user_id = u.user_id AND
+            $tbl_session_rel_user.session_id = '$id_session' AND
             $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
           WHERE u.status<>".DRH." AND u.status<>6 $order_clause";
 
@@ -490,17 +495,18 @@ if ($ajax_search) {
         $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
         $access_url_id = api_get_current_access_url_id();
         if ($access_url_id != -1) {
-            $sql="SELECT  u.user_id, lastname, firstname, username, id_session, official_code
-                FROM $tbl_user u
-                LEFT JOIN $tbl_session_rel_user
-                    ON $tbl_session_rel_user.id_user = u.user_id AND
-                    $tbl_session_rel_user.id_session = '$id_session' AND
-                    $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-                INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
-                WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
-                $order_clause";
+            $sql = "SELECT  u.user_id, lastname, firstname, username, session_id, official_code
+                    FROM $tbl_user u
+                    LEFT JOIN $tbl_session_rel_user
+                        ON $tbl_session_rel_user.user_id = u.user_id AND
+                        $tbl_session_rel_user.session_id = '$id_session' AND
+                        $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
+                    INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
+                    WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
+                    $order_clause";
         }
     }
+
     $result = Database::query($sql);
     $users = Database::store_result($result,'ASSOC');
     foreach ($users as $uid => $user) {

+ 1 - 1
main/admin/add_users_to_usergroup.php

@@ -132,7 +132,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'export') {
             $data[] = array($user['username'], $groupInfo['name']);
         }
         $filename = 'export_user_class_' . api_get_local_time();
-        Export::export_table_csv($data, $filename);
+        Export::arrayToCsv($data, $filename);
         exit;
     }
 }

+ 3 - 4
main/admin/career_dashboard.php

@@ -1,12 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * Careers dashboard
  * @package chamilo.admin.career
  */
-/**
- * Code
- */
+
 $cidReset = true;
 require_once '../inc/global.inc.php';
 $libpath = api_get_path(LIBRARY_PATH);
@@ -22,7 +21,7 @@ $htmlHeadXtra[] = api_get_jqgrid_js();
 $interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
 $interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions'));
 
-Display :: display_header($nameTools);
+Display :: display_header(null);
 
 $form = new FormValidator('filter_form','GET', api_get_self());
 

+ 1 - 1
main/admin/class_import.php

@@ -78,7 +78,7 @@ $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
 $form->addButtonImport(get_lang('Import'));
 
 if ($form->validate()) {
-    $classes = Import::csv_to_array($_FILES['import_file']['tmp_name']);
+    $classes = Import::csvToArray($_FILES['import_file']['tmp_name']);
     $errors = validate_data($classes);
     if (count($errors) == 0) {
         $number_of_added_classes = save_data($classes);

+ 1 - 1
main/admin/class_user_import.php

@@ -127,7 +127,7 @@ function save_data($users_classes) {
  * @return array All course-information read from the file
  */
 function parse_csv_data($file) {
-    $courses = Import::csv_to_array($file);
+    $courses = Import::csvToArray($file);
     return $courses;
 }
 

+ 9 - 9
main/admin/configure_inscription.php

@@ -11,7 +11,7 @@ require_once '../inc/global.inc.php';
 api_protect_admin_script();
 
 // Load terms & conditions from the current lang
-if (get_setting('allow_terms_conditions') == 'true') {
+if (api_get_setting('allow_terms_conditions') == 'true') {
     $get = array_keys($_GET);
     if (isset($get)) {
         if ($get[0] == 'legal') {
@@ -59,7 +59,7 @@ if (!empty($_SESSION['user_language_choice'])) {
 } elseif (!empty($_SESSION['_user']['language'])) {
     $lang = $_SESSION['_user']['language'];
 } else {
-    $lang = get_setting('platformLanguage');
+    $lang = api_get_setting('platformLanguage');
 }
 
 // ----- Ensuring availability of main files in the corresponding language -----
@@ -109,7 +109,7 @@ if (!empty($homep_new)) {
 }
 
 if (!empty($action)) {
-    if ($_POST['formSent']) {
+    if (isset($_POST['formSent'])) {
         switch ($action) {
             case 'edit_top':
                 // Filter
@@ -159,12 +159,12 @@ echo Display::page_header($tool_name);
 
 // The following security condition has been removed, because it makes no sense here. See Bug #1846.
 //// Forbidden to self-register
-//if (get_setting('allow_registration') == 'false') {
+//if (api_get_setting('allow_registration') == 'false') {
 //    api_not_allowed();
 //}
 
 //api_display_tool_title($tool_name);
-if (get_setting('allow_registration') == 'approval') {
+if (api_get_setting('allow_registration') == 'approval') {
     Display::display_normal_message(get_lang('YourAccountHasToBeApproved'));
 }
 //if openid was not found
@@ -173,7 +173,7 @@ if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
 }
 
 $form = new FormValidator('registration');
-if (get_setting('allow_terms_conditions') == 'true') {
+if (api_get_setting('allow_terms_conditions') == 'true') {
     $display_all_form = !isset($_SESSION['update_term_and_condition']['user_id']);
 } else {
     $display_all_form = true;
@@ -229,12 +229,12 @@ if ($display_all_form) {
     }
 
     //	LANGUAGE
-    if (get_setting('registration', 'language') == 'true') {
+    if (api_get_setting('registration', 'language') == 'true') {
         $form->addElement('select_language', 'language', get_lang('Language'), '', array('disabled' => 'disabled'));
     }
 
     //	STUDENT/TEACHER
-    if (get_setting('allow_registration_as_teacher') != 'false') {
+    if (api_get_setting('allow_registration_as_teacher') != 'false') {
         $form->addElement('radio', 'status', get_lang('Status'), get_lang('RegStudent'), STUDENT, array('disabled' => 'disabled'));
         $form->addElement('radio', 'status', null, get_lang('RegAdmin'), COURSEMANAGER, array('disabled' => 'disabled'));
     }
@@ -271,7 +271,7 @@ if ($display_all_form) {
 }
 
 // Terms and conditions
-if (get_setting('allow_terms_conditions') == 'true') {
+if (api_get_setting('allow_terms_conditions') == 'true') {
     $language = api_get_interface_language();
     $language = api_get_language_id($language);
     $term_preview = LegalManager::get_last_condition($language);

+ 21 - 17
main/admin/course_add.php

@@ -40,18 +40,24 @@ $form = new FormValidator('update_course');
 $form->addElement('header', $tool_name);
 
 // Title
-$form->addText('title', get_lang('Title'), true, array ('class' => 'span6'));
+$form->addText('title', get_lang('Title'), true);
 $form->applyFilter('title', 'html_filter');
 $form->applyFilter('title', 'trim');
 
 // Code
-$form->addText('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('class' => 'span3', 'maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE));
+$form->addText('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE));
 
 $form->applyFilter('visual_code', 'api_strtoupper');
 $form->applyFilter('visual_code', 'html_filter');
 $form->addRule('visual_code', get_lang('Max'), 'maxlength', CourseManager::MAX_COURSE_LENGTH_CODE);
 
-$form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, ' id="course_teachers" class="chzn-select"  style="width:350px" multiple="multiple" ');
+$form->addElement(
+    'select',
+    'course_teachers',
+    get_lang('CourseTeachers'),
+    $teachers,
+    ' id="course_teachers" class="chzn-select"  style="width:350px" multiple="multiple" '
+);
 $form->applyFilter('course_teachers', 'html_filter');
 
 // Category code
@@ -123,33 +129,31 @@ $form->add_progress_bar();
 $form->addButtonCreate(get_lang('CreateCourse'));
 
 // Set some default values.
-$values['course_language']  = api_get_setting('platformLanguage');
-$values['disk_quota']       = round(api_get_setting('default_document_quotum')/1024/1024, 1);
+$values['course_language'] = api_get_setting('platformLanguage');
+$values['disk_quota'] = round(api_get_setting('default_document_quotum')/1024/1024, 1);
 
 $default_course_visibility = api_get_setting('courses_default_creation_visibility');
 
 if (isset($default_course_visibility)) {
-    $values['visibility']       = api_get_setting('courses_default_creation_visibility');
+    $values['visibility'] = api_get_setting('courses_default_creation_visibility');
 } else {
-    $values['visibility']       = COURSE_VISIBILITY_OPEN_PLATFORM;
+    $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
 }
-$values['subscribe']        = 1;
-$values['unsubscribe']      = 0;
+$values['subscribe'] = 1;
+$values['unsubscribe'] = 0;
+$values['course_teachers'] = array(api_get_user_id());
 
 $form->setDefaults($values);
 
 // Validate the form
 if ($form->validate()) {
-    $course          = $form->exportValues();
-    $teacher_id      = $course['tutor_id'];
-    $course_teachers = $course['course_teachers'];
+    $course = $form->exportValues();
 
+    $course_teachers = isset($course['course_teachers']) ? $course['course_teachers'] : null;
     $course['disk_quota'] = $course['disk_quota']*1024*1024;
-
-    $course['exemplary_content']    = empty($course['exemplary_content']) ? false : true;
-    $course['teachers']             = $course_teachers;
-    $course['user_id']              = $teacher_id;
-    $course['wanted_code']          = $course['visual_code'];
+    $course['exemplary_content'] = empty($course['exemplary_content']) ? false : true;
+    $course['teachers'] = $course_teachers;
+    $course['wanted_code'] = $course['visual_code'];
     $course['gradebook_model_id']   = isset($course['gradebook_model_id']) ? $course['gradebook_model_id'] : null;
     // Fixing category code
     $course['course_category'] = $course['category_code'];

+ 19 - 18
main/admin/course_edit.php

@@ -34,6 +34,7 @@ $interbreadcrumb[] = array("url" => "course_list.php", "name" => get_lang('Cours
 // Get all course categories
 $table_user = Database :: get_main_table(TABLE_MAIN_USER);
 $course_code = $courseInfo['code'];
+$courseId = $courseInfo['real_id'];
 
 // Get course teachers
 $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
@@ -43,7 +44,7 @@ $sql = "SELECT user.user_id,lastname,firstname
         WHERE
             course_user.status='1' AND
             course_user.user_id=user.user_id AND
-            course_user.course_code='" . $course_code . "'" .
+            course_user.c_id ='" . $courseId . "'" .
         $order_clause;
 $res = Database::query($sql);
 $course_teachers = array();
@@ -122,11 +123,11 @@ if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
     $form->addElement('checkbox', 'add_teachers_to_sessions_courses', null, get_lang('TeachersWillBeAddedAsCoachInAllCourseSessions'));
 }
 
-$coursesInSession = SessionManager::get_session_by_course($courseInfo['code']);
+$coursesInSession = SessionManager::get_session_by_course($courseInfo['real_id']);
 if (!empty($coursesInSession)) {
     foreach ($coursesInSession as $session) {
         $sessionId = $session['id'];
-        $coaches = SessionManager::getCoachesByCourseSession($sessionId, $courseInfo['code']);
+        $coaches = SessionManager::getCoachesByCourseSession($sessionId, $courseInfo['real_id']);
         $teachers = $allTeachers;
 
         $sessionTeachers = array();
@@ -296,8 +297,6 @@ if ($form->validate()) {
         $warn = substr($warn, 0, -1);
     }
 
-    $tutor_id = isset($course['tutor_name']) ? $course['tutor_name'] : null;
-    $tutor_name = isset($platform_teachers[$tutor_id]) ? $platform_teachers[$tutor_id] : null;
     $teachers = $course['course_teachers'];
 
     $title = $course['title'];
@@ -315,10 +314,10 @@ if ($form->validate()) {
         $department_url = 'http://' . $department_url;
     }
 
-    $sql = "UPDATE $course_table SET course_language='" . Database::escape_string($course_language) . "',
+    $sql = "UPDATE $course_table SET
+                course_language='" . Database::escape_string($course_language) . "',
                 title='" . Database::escape_string($title) . "',
                 category_code='" . Database::escape_string($category_code) . "',
-                tutor_name='" . Database::escape_string($tutor_name) . "',
                 visual_code='" . Database::escape_string($visual_code) . "',
                 department_name='" . Database::escape_string($department_name) . "',
                 department_url='" . Database::escape_string($department_url) . "',
@@ -343,7 +342,7 @@ if ($form->validate()) {
         if (!empty($sessionCoaches)) {
             foreach ($sessionCoaches as $sessionId => $teacherInfo) {
                 $coachesToSubscribe = $teacherInfo['coaches_by_session'];
-                SessionManager::updateCoaches($sessionId, $course['code'], $coachesToSubscribe, true);
+                SessionManager::updateCoaches($sessionId, $courseId, $coachesToSubscribe, true);
             }
         }
 
@@ -360,7 +359,7 @@ if ($form->validate()) {
                 if (!empty($coachesToSubscribe)) {
                     SessionManager::updateCoaches(
                         $sessionId,
-                        $course['code'],
+                        $courseId,
                         $coachesToSubscribe,
                         true
                     );
@@ -369,18 +368,20 @@ if ($form->validate()) {
         }
     }
 
+    // No need to register me as a teacher.
+    /*
     $sql = "INSERT IGNORE INTO " . $course_user_table . " SET
-                course_code = '" . Database::escape_string($course_code) . "',
-                user_id = '" . $tutor_id . "',
-                status = '1',
-                role = '',
-                tutor_id='0',
-                sort='0',
-                user_course_cat='0'";
+            c_id = " . $courseInfo['real_id'] . ",
+            user_id = '" . $tutor_id . "',
+            status = '1',
+            is_tutor ='0',
+            sort = '0',
+            user_course_cat='0'";
     Database::query($sql);
-
+    */
     if (array_key_exists('add_teachers_to_sessions_courses', $courseInfo)) {
-        $sql = "UPDATE $course_table SET add_teachers_to_sessions_courses = '$addTeacherToSessionCourses'
+        $sql = "UPDATE $course_table SET
+                add_teachers_to_sessions_courses = '$addTeacherToSessionCourses'
                 WHERE id = " . $courseInfo['real_id'];
         Database::query($sql);
     }

+ 8 - 8
main/admin/course_export.php

@@ -1,12 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
 * 	This tool allows platform admins to export courses to CSV file
 *	@package chamilo.admin
 */
-/**
- * Code
- */
+
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
@@ -25,12 +24,12 @@ $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
 
 $course_list = CourseManager::get_courses_list();
 $formSent = null;
+$courses = $selected_courses = array();
 
 if (isset($_POST['formSent']) && $_POST['formSent']) {
 	$formSent = $_POST['formSent'];
-	$select_type=intval($_POST['select_type']);
+	$select_type = intval($_POST['select_type']);
 	$file_type = 'csv';
-	$courses = $selected_courses = array();
 
 	if ($select_type == 2) {
 		// Get selected courses from courses list in form sent
@@ -87,9 +86,8 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
 if (!empty($msg)) {
 	Display::display_normal_message($msg, false);
 }
+// @todo use FormValidator!
 ?>
-
-
 <form method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
     <input type="hidden" name="formSent" value="1">
     <legend><?php echo $tool_name; ?></legend>
@@ -117,7 +115,9 @@ if (!empty($msg)) {
         <?php
         foreach($course_list as $course) {
         ?>
-        	<option value="<?php echo $course['code']; ?>" <?php if(is_array($selected_courses) && in_array($course['code'],$selected_courses)) echo 'selected="selected"'; ?>><?php echo $course['title'].' ('.$course['code'].') ' ?></option>
+        	<option value="<?php echo $course['code']; ?>" <?php if(is_array($selected_courses) && in_array($course['code'],$selected_courses)) echo 'selected="selected"'; ?>>
+                <?php echo $course['title'].' ('.$course['code'].') ' ?>
+            </option>
         <?php
         }
         ?>

+ 8 - 9
main/admin/course_import.php

@@ -112,12 +112,12 @@ function save_data($courses)
         }
 
         $params = array();
-        $params['title']            = $course['Title'];
-        $params['wanted_code']      = $course['Code'];
-        $params['tutor_name']       = null;
-        $params['course_category']  = $course['CourseCategory'];
-        $params['course_language']  = $course_language;
-        $params['user_id']          = $creatorId;
+        $params['title'] = $course['Title'];
+        $params['wanted_code'] = $course['Code'];
+        $params['tutor_name'] = null;
+        $params['course_category'] = $course['CourseCategory'];
+        $params['course_language'] = $course_language;
+        $params['user_id'] = $creatorId;
 
         $addMeAsTeacher = isset($_POST['add_me_as_teacher']) ? $_POST['add_me_as_teacher'] : false;
         $params['add_user_as_teacher'] = $addMeAsTeacher;
@@ -151,7 +151,7 @@ function save_data($courses)
  */
 function parse_csv_data($file)
 {
-    $courses = Import::csv_to_array($file);
+    $courses = Import::csvToArray($file);
     return $courses;
 }
 
@@ -211,9 +211,8 @@ $form = new FormValidator('import', 'post', api_get_self(), null, array('enctype
 $form->addHeader($tool_name);
 $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
 $form->addElement('checkbox', 'add_me_as_teacher', null, get_lang('AddMeAsTeacherInCourses'));
-$form->addElement('button', 'save', get_lang('Import'));
+$form->addButtonImport(get_lang('Import'), 'save');
 $form->addElement('hidden', 'formSent', 1);
-//$form->setDefaults(array('add_me_as_teacher' => 0));
 $form->display();
 
 ?>

+ 8 - 4
main/admin/course_information.php

@@ -78,6 +78,7 @@ $code = Database::escape_string($_GET['code']);
 $sql = "SELECT * FROM $table_course WHERE code = '".$code."'";
 $res = Database::query($sql);
 $course = Database::fetch_object($res);
+$courseId = $course->id;
 $tool_name = $course->title.' ('.$course->visual_code.')';
 Display::display_header($tool_name);
 ?>
@@ -104,15 +105,17 @@ $table->display();
 echo Display::page_header(get_lang('Users'));
 $table_course_user     = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 $table_user            = Database :: get_main_table(TABLE_MAIN_USER);
-$sql = "SELECT *,cu.status as course_status
+$sql = "SELECT *, cu.status as course_status
         FROM $table_course_user cu, $table_user u";
 if (api_is_multiple_url_enabled()) {
     $sql .= " INNER JOIN ".Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER)." url_rel_user
         ON u.user_id = url_rel_user.user_id
         AND url_rel_user.access_url_id = ".intval(api_get_current_access_url_id());
 }
-$sql .= " WHERE cu.user_id = u.user_id AND cu.course_code = '".$code."'
-        AND cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH;
+$sql .= " WHERE
+            cu.user_id = u.user_id AND
+            cu.c_id = '".$courseId."' AND
+            cu.relation_type <> ".COURSE_RELATION_TYPE_RRHH;
 $res = Database::query($sql);
 $is_western_name_order = api_is_western_name_order();
 if (Database::num_rows($res) > 0) {
@@ -150,8 +153,9 @@ if (Database::num_rows($res) > 0) {
 } else {
     echo get_lang('NoUsersInCourse');
 }
+$courseInfo = api_get_course_info($course->code);
 
-$session_list = SessionManager::get_session_by_course($course->code);
+$session_list = SessionManager::get_session_by_course($courseInfo['real_id']);
 
 $url = api_get_path(WEB_CODE_PATH);
 if (!empty($session_list)) {

+ 16 - 15
main/admin/course_list.php

@@ -20,21 +20,22 @@ $sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
 function get_number_of_courses()
 {
     $course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
-    $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table";
+    $sql = "SELECT COUNT(code) AS total_number_of_items FROM $course_table c";
 
     if ((api_is_platform_admin() || api_is_session_admin()) &&
         api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
     ) {
         $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
-        $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (code=url_rel_course.course_code)";
+        $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course
+                 ON (c.id = url_rel_course.c_id)";
     }
 
     if (isset ($_GET['keyword'])) {
         $keyword = Database::escape_string("%".$_GET['keyword']."%");
         $sql .= " WHERE (
-                        title LIKE '".$keyword."' OR
-                        code LIKE '".$keyword."' OR
-                        visual_code LIKE '".$keyword."'
+                        c.title LIKE '".$keyword."' OR
+                        c.code LIKE '".$keyword."' OR
+                        c.visual_code LIKE '".$keyword."'
                 )
         ";
     } elseif (isset($_GET['keyword_code'])) {
@@ -47,13 +48,13 @@ function get_number_of_courses()
         $keyword_unsubscribe = Database::escape_string($_GET['keyword_unsubscribe']);
 
         $sql .= " WHERE
-                    (code LIKE '".$keyword_code."' OR visual_code LIKE '".$keyword_code."') AND
-                    title LIKE '".$keyword_title."' AND
-                    category_code LIKE '".$keyword_category."' AND
-                    course_language LIKE '".$keyword_language."' AND
-                    visibility LIKE '".$keyword_visibility."' AND
-                    subscribe LIKE '".$keyword_subscribe."' AND
-                    unsubscribe LIKE '".$keyword_unsubscribe."'
+                    (c.code LIKE '".$keyword_code."' OR c.visual_code LIKE '".$keyword_code."') AND
+                    c.title LIKE '".$keyword_title."' AND
+                    c.category_code LIKE '".$keyword_category."' AND
+                    c.course_language LIKE '".$keyword_language."' AND
+                    c.visibility LIKE '".$keyword_visibility."' AND
+                    c.subscribe LIKE '".$keyword_subscribe."' AND
+                    c.unsubscribe LIKE '".$keyword_unsubscribe."'
         ";
     }
 
@@ -61,7 +62,7 @@ function get_number_of_courses()
     if ((api_is_platform_admin() || api_is_session_admin()) &&
         api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
     ) {
-        $sql.= " AND url_rel_course.access_url_id=".api_get_current_access_url_id();
+        $sql.= " AND url_rel_course.access_url_id = ".api_get_current_access_url_id();
     }
 
     $res = Database::query($sql);
@@ -100,7 +101,7 @@ function get_course_data($from, $number_of_items, $column, $direction)
         api_is_multiple_url_enabled() && api_get_current_access_url_id() != -1
     ) {
         $access_url_rel_course_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
-        $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (code=url_rel_course.course_code)";
+        $sql.= " INNER JOIN $access_url_rel_course_table url_rel_course ON (id = url_rel_course.c_id)";
     }
 
     if (isset ($_GET['keyword'])) {
@@ -182,7 +183,7 @@ function get_course_data_by_session($from, $number_of_items, $column, $direction
                     c.visual_code
             FROM $course_table c
             INNER JOIN $session_rel_course r ON c.code = r.course_code
-            INNER JOIN $session s ON r.id_session = s.id
+            INNER JOIN $session s ON r.session_id = s.id
             ";
 
     if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {

+ 26 - 15
main/admin/course_request_accepted.php

@@ -23,8 +23,8 @@ api_protect_admin_script();
 $course_validation_feature = api_get_setting('course_validation') == 'true';
 
 // Filltering passed to this page parameters.
-$delete_course_request = intval($_GET['delete_course_request']);
-$message = trim(Security::remove_XSS(stripslashes(urldecode($_GET['message']))));
+$delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
+$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
 $is_error_message = !empty($_GET['is_error_message']);
 
 if ($course_validation_feature) {
@@ -84,17 +84,28 @@ function get_request_data($from, $number_of_items, $column, $direction)
     $keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : null;
     $course_request_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
 
-    $sql = "SELECT id AS col0,
-                   code AS col1,
-                   title AS col2,
-                   category_code AS col3,
-                   tutor_name AS col4,
-                   request_date AS col5,
-                   id  AS col6
-                   FROM $course_request_table WHERE status = ".COURSE_REQUEST_ACCEPTED;
+    $from = intval($from);
+    $number_of_items = intval($number_of_items);
+    $column = intval($column);
+    $direction = !in_array(strtolower(trim($direction)), ['asc','desc']) ? 'asc' : $direction;
+
+    $sql = "SELECT
+                id AS col0,
+               code AS col1,
+               title AS col2,
+               category_code AS col3,
+               tutor_name AS col4,
+               request_date AS col5,
+               id  AS col6
+           FROM $course_request_table
+           WHERE status = ".COURSE_REQUEST_ACCEPTED;
 
     if ($keyword != '') {
-        $sql .= " AND (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
+        $sql .= " AND (
+                title LIKE '%".$keyword."%' OR
+                code LIKE '%".$keyword."%' OR
+                visual_code LIKE '%".$keyword."%'
+            )";
     }
     $sql .= " ORDER BY col$column $direction ";
     $sql .= " LIMIT $from,$number_of_items";
@@ -115,8 +126,10 @@ function get_request_data($from, $number_of_items, $column, $direction)
 function modify_filter($id)
 {
     $code = CourseRequestManager::get_course_request_code($id);
-    $result = '<a href="course_request_edit.php?id='.$id.'&caller=1">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
-        '&nbsp;<a href="?delete_course_request='.$id.'">'.Display::return_icon('delete.gif', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
+    $result = '<a href="course_request_edit.php?id='.$id.'&caller=1">'.
+        Display::return_icon('edit.png', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
+        '&nbsp;<a href="?delete_course_request='.$id.'">'.
+        Display::return_icon('delete.png', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
 
     return $result;
 }
@@ -149,7 +162,6 @@ $form->addButtonSearch(get_lang('Search'));
 
 // The action bar.
 echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
-//echo '<a href="course_list.php">'.Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
 echo ' <a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
 echo ' <a href="course_request_rejected.php">'.Display::return_icon('course_request_rejected.gif', get_lang('RejectedCourseRequests')).get_lang('RejectedCourseRequests').'</a>';
 echo '</div>';
@@ -159,7 +171,6 @@ echo '</div>';
 
 // Create a sortable table with the course data.
 $table = new SortableTable('course_requests_accepted', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
-//$table->set_additional_parameters($parameters);
 $table->set_header(0, '', false);
 $table->set_header(1, get_lang('Code'));
 $table->set_header(2, get_lang('Title'));

+ 1 - 3
main/admin/course_request_edit.php

@@ -31,10 +31,8 @@ if ($course_validation_feature) {
         $is_error_message = true;
     } else {
 
-        global $_configuration;
-        $dbnamelength = strlen($_configuration['db_prefix']);
         // Ensure the database prefix + database name do not get over 40 characters.
-        $maxlength = 40 - $dbnamelength;
+        $maxlength = 40;
 
         // Build the form.
         $form = new FormValidator('add_course', 'post', 'course_request_edit.php?id='.$id.'&caller='.$caller);

+ 23 - 19
main/admin/course_request_rejected.php

@@ -23,12 +23,12 @@ api_protect_admin_script();
 $course_validation_feature = api_get_setting('course_validation') == 'true';
 
 // Filltering passed to this page parameters.
-$accept_course_request = intval($_GET['accept_course_request']);
-$delete_course_request = intval($_GET['delete_course_request']);
-$request_info = intval($_GET['request_info']);
-$message = trim(Security::remove_XSS(stripslashes(urldecode($_GET['message']))));
+$accept_course_request = isset($_GET['accept_course_request']) ? intval($_GET['accept_course_request']) : '';
+$delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
+$request_info = isset($_GET['request_info']) ? intval($_GET['request_info']) : '';
+$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
 $is_error_message = !empty($_GET['is_error_message']);
-$keyword = Database::escape_string(trim($_GET['keyword']));
+$keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
 
 if ($course_validation_feature) {
 
@@ -109,17 +109,23 @@ function get_number_of_requests() {
  */
 function get_request_data($from, $number_of_items, $column, $direction) {
     global $keyword;
-
     $course_request_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
 
-    $sql = "SELECT id AS col0,
-                   code AS col1,
-                   title AS col2,
-                   category_code AS col3,
-                   tutor_name AS col4,
-                   request_date AS col5,
-                   id  AS col6
-                   FROM $course_request_table WHERE status = ".COURSE_REQUEST_REJECTED;
+    $from = intval($from);
+    $number_of_items = intval($number_of_items);
+    $column = intval($column);
+    $direction = !in_array(strtolower(trim($direction)), ['asc','desc']) ? 'asc' : $direction;
+
+    $sql = "SELECT
+                id AS col0,
+               code AS col1,
+               title AS col2,
+               category_code AS col3,
+               tutor_name AS col4,
+               request_date AS col5,
+               id  AS col6
+           FROM $course_request_table
+           WHERE status = ".COURSE_REQUEST_REJECTED;
 
     if ($keyword != '') {
         $sql .= " AND (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
@@ -142,12 +148,12 @@ function get_request_data($from, $number_of_items, $column, $direction) {
  */
 function modify_filter($id) {
     $code = CourseRequestManager::get_course_request_code($id);
-    $result = '<a href="course_request_edit.php?id='.$id.'&caller=2">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
-        '&nbsp;<a href="?accept_course_request='.$id.'">'.Display::return_icon('action_accept.gif', get_lang('AcceptThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ANewCourseWillBeCreated'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
+    $result = '<a href="course_request_edit.php?id='.$id.'&caller=2">'.Display::return_icon('edit.png', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
+        '&nbsp;<a href="?accept_course_request='.$id.'">'.Display::return_icon('accept.png', get_lang('AcceptThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ANewCourseWillBeCreated'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
     if (!CourseRequestManager::additional_info_asked($id)) {
         $result .= '&nbsp;<a href="?request_info='.$id.'">'.Display::return_icon('request_info.gif', get_lang('AskAdditionalInfo'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('AdditionalInfoWillBeAsked'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
     }
-    $result .= '&nbsp;<a href="?delete_course_request='.$id.'">'.Display::return_icon('delete.gif', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
+    $result .= '&nbsp;<a href="?delete_course_request='.$id.'">'.Display::return_icon('delete.png', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
 
     return $result;
 }
@@ -182,7 +188,6 @@ $form->addButtonSearch(get_lang('Search'));
 
 // The action bar.
 echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
-//echo '<a href="course_list.php">'.Display::return_icon('courses.gif', get_lang('CourseList')).get_lang('CourseList').'</a>';
 echo ' <a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
 echo ' <a href="course_request_accepted.php">'.Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').'</a>';
 echo '</div>';
@@ -192,7 +197,6 @@ echo '</div>';
 
 // Create a sortable table with the course data.
 $table = new SortableTable('course_requests_rejected', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
-//$table->set_additional_parameters($parameters);
 $table->set_header(0, '', false);
 $table->set_header(1, get_lang('Code'));
 $table->set_header(2, get_lang('Title'));

+ 9 - 9
main/admin/course_request_review.php

@@ -24,13 +24,13 @@ api_protect_admin_script();
 $course_validation_feature = api_get_setting('course_validation') == 'true';
 
 // Filltering passed to this page parameters.
-$accept_course_request = intval($_GET['accept_course_request']);
-$reject_course_request = intval($_GET['reject_course_request']);
-$request_info = intval($_GET['request_info']);
-$delete_course_request = intval($_GET['delete_course_request']);
-$message = trim(Security::remove_XSS(stripslashes(urldecode($_GET['message']))));
-$is_error_message = !empty($_GET['is_error_message']);
-$keyword = Database::escape_string(trim($_GET['keyword']));
+$accept_course_request = isset($_GET['accept_course_request']) ? intval($_GET['accept_course_request']) : '';
+$reject_course_request = isset($_GET['reject_course_request']) ? intval($_GET['reject_course_request']) : '';
+$request_info = isset($_GET['request_info']) ? intval($_GET['request_info']) : '';
+$delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
+$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
+$is_error_message = isset($_GET['is_error_message']) ? !empty($_GET['is_error_message']) : '';
+$keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
 
 if ($course_validation_feature) {
 
@@ -188,14 +188,14 @@ function email_filter($teacher)
 function modify_filter($id)
 {
     $code = CourseRequestManager::get_course_request_code($id);
-    $result = '<a href="course_request_edit.php?id='.$id.'&caller=0">'.Display::return_icon('edit.gif', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
+    $result = '<a href="course_request_edit.php?id='.$id.'&caller=0">'.Display::return_icon('edit.png', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
         '&nbsp;<a href="?accept_course_request='.$id.'">'.Display::return_icon('accept.png', get_lang('AcceptThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ANewCourseWillBeCreated'), $code), ENT_QUOTES)).'\')) return false;'),16).'</a>'.
         '&nbsp;<a href="?reject_course_request='.$id.'">'.Display::return_icon('error.png', get_lang('RejectThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeRejected'), $code), ENT_QUOTES)).'\')) return false;'),16).'</a>';
     if (!CourseRequestManager::additional_info_asked($id)) {
         $result .= '&nbsp;<a href="?request_info='.$id.'">'.Display::return_icon('request_info.gif', get_lang('AskAdditionalInfo'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('AdditionalInfoWillBeAsked'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
     }
     if (DELETE_ACTION_ENABLED) {
-        $result .= '&nbsp;<a href="?delete_course_request='.$id.'">'.Display::return_icon('delete.gif', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
+        $result .= '&nbsp;<a href="?delete_course_request='.$id.'">'.Display::return_icon('delete.png', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
     }
 
     return $result;

+ 13 - 5
main/admin/course_user_import.php

@@ -1,10 +1,12 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * This tool allows platform admins to update course-user relations by uploading
  * a CSV file
  * @package chamilo.admin
  */
+
 /**
  * Validates the imported data.
  */
@@ -86,14 +88,17 @@ function save_data($users_courses)
         $res = Database::query($sql);
         $db_subscriptions = array();
         while ($obj = Database::fetch_object($res)) {
-            $db_subscriptions[$obj->course_code] = $obj->status;
+            $db_subscriptions[$obj->c_id] = $obj->status;
         }
 
         $to_subscribe   = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
         $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
 
         if ($_POST['subscribe']) {
-            foreach ($to_subscribe as $course_code) {
+            foreach ($to_subscribe as $courseId) {
+                $courseInfo = api_get_course_info_by_id($courseId);
+                $course_code = $courseInfo['code'];
+
                 if (CourseManager :: course_exists($course_code)) {
                     CourseManager::subscribe_user(
                         $user_id,
@@ -108,7 +113,10 @@ function save_data($users_courses)
         }
 
         if ($_POST['unsubscribe']) {
-            foreach ($to_unsubscribe as $course_code) {
+            foreach ($to_unsubscribe as $courseId) {
+                $courseInfo = api_get_course_info_by_id($courseId);
+                $course_code = $courseInfo['code'];
+
                 if (CourseManager :: course_exists($course_code)) {
                     CourseManager::unsubscribe_user($user_id, $course_code);
                     $course_info = CourseManager::get_course_information($course_code);
@@ -129,7 +137,7 @@ function save_data($users_courses)
  */
 function parse_csv_data($file)
 {
-    $courses = Import :: csv_to_array($file);
+    $courses = Import :: csvToArray($file);
     return $courses;
 }
 
@@ -211,7 +219,7 @@ $form->display();
 <b>UserName</b>;<b>CourseCode</b>;<b>Status</b>
 jdoe;course01;<?php echo COURSEMANAGER; ?>
 
-    adam;course01;<?php echo STUDENT; ?>
+adam;course01;<?php echo STUDENT; ?>
 </pre>
         <?php
         echo COURSEMANAGER.': '.get_lang('Teacher').'<br />';

+ 8 - 4
main/admin/course_user_import_by_email.php

@@ -90,14 +90,16 @@ function save_data($users_courses)
         $res = Database::query($sql);
         $db_subscriptions = array();
         while ($obj = Database::fetch_object($res)) {
-            $db_subscriptions[$obj->course_code] = $obj->status;
+            $db_subscriptions[$obj->c_id] = $obj->status;
         }
 
         $to_subscribe   = array_diff(array_keys($csv_subscriptions), array_keys($db_subscriptions));
         $to_unsubscribe = array_diff(array_keys($db_subscriptions), array_keys($csv_subscriptions));
 
         if ($_POST['subscribe']) {
-            foreach ($to_subscribe as $course_code) {
+            foreach ($to_subscribe as $courseId) {
+                $courseInfo = api_get_course_info_by_id($courseId);
+                $course_code = $courseInfo['code'];
                 if (CourseManager :: course_exists($course_code)) {
                     $course_info = CourseManager::get_course_information($course_code);
                     $inserted_in_course[$course_code] = $course_info['title'];
@@ -113,7 +115,9 @@ function save_data($users_courses)
         }
 
         if ($_POST['unsubscribe']) {
-            foreach ($to_unsubscribe as $course_code) {
+            foreach ($to_unsubscribe as $courseId) {
+                $courseInfo = api_get_course_info_by_id($courseId);
+                $course_code = $courseInfo['code'];
                 if (CourseManager :: course_exists($course_code)) {
                     CourseManager::unsubscribe_user($user_id, $course_code);
                     $course_info = CourseManager::get_course_information($course_code);
@@ -134,7 +138,7 @@ function save_data($users_courses)
  */
 function parse_csv_data($file)
 {
-    $courses = Import :: csv_to_array($file);
+    $courses = Import :: csvToArray($file);
     return $courses;
 }
 

+ 19 - 11
main/admin/dashboard_add_courses_to_user.php

@@ -10,8 +10,6 @@ $cidReset = true;
 
 require_once '../inc/global.inc.php';
 
-global $_configuration;
-
 $xajax = new xajax();
 $xajax->registerFunction('search_courses');
 
@@ -56,7 +54,7 @@ if (!api_is_platform_admin()) {
 
 function search_courses($needle, $type)
 {
-    global $_configuration, $tbl_course, $tbl_course_rel_access_url,$user_id;
+    global $tbl_course, $tbl_course_rel_access_url,$user_id;
 
     $xajax_response = new xajaxResponse();
     $return = '';
@@ -76,12 +74,20 @@ function search_courses($needle, $type)
             $without_assigned_courses = " AND c.code NOT IN(".implode(',',$assigned_courses_code).")";
         }
 
-        if ($_configuration['multiple_access_urls']) {
-            $sql = "SELECT c.code, c.title FROM $tbl_course c LEFT JOIN $tbl_course_rel_access_url a ON (a.course_code = c.code)
-                WHERE  c.code LIKE '$needle%' $without_assigned_courses AND access_url_id = ".api_get_current_access_url_id()."";
+        if (api_is_multiple_url_enabled()) {
+            $sql = "SELECT c.code, c.title
+                    FROM $tbl_course c
+					LEFT JOIN $tbl_course_rel_access_url a
+                    ON (a.c_id = c.id)
+                	WHERE
+                		c.code LIKE '$needle%' $without_assigned_courses AND
+                		access_url_id = ".api_get_current_access_url_id();
         } else {
-            $sql = "SELECT c.code, c.title FROM $tbl_course c
-                WHERE  c.code LIKE '$needle%' $without_assigned_courses ";
+            $sql = "SELECT c.code, c.title
+            		FROM $tbl_course c
+                	WHERE
+                		c.code LIKE '$needle%'
+                		$without_assigned_courses ";
         }
 
 		$rs	= Database::query($sql);
@@ -156,7 +162,7 @@ $UserList = array();
 $msg = '';
 if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
     $courses_list = $_POST['CoursesList'];
-    $affected_rows = CourseManager::suscribe_courses_to_hr_manager($user_id,$courses_list);
+    $affected_rows = CourseManager::subscribeCoursesToDrhManager($user_id, $courses_list);
     if ($affected_rows)	{
         $msg = get_lang('AssignedCoursesHaveBeenUpdatedSuccessfully');
     }
@@ -195,14 +201,16 @@ if (isset($_POST['firstLetterCourse'])) {
 if (api_is_multiple_url_enabled()) {
 	$sql = " SELECT c.code, c.title
             FROM $tbl_course c
-            LEFT JOIN $tbl_course_rel_access_url a ON (a.course_code = c.code)
+            LEFT JOIN $tbl_course_rel_access_url a
+            ON (a.c_id = c.id)
             WHERE
                 c.code LIKE '$needle' $without_assigned_courses AND
                 access_url_id = ".api_get_current_access_url_id()."
             ORDER BY c.title";
 
 } else {
-	$sql= " SELECT c.code, c.title FROM $tbl_course c
+	$sql= " SELECT c.code, c.title
+	        FROM $tbl_course c
             WHERE  c.code LIKE '$needle' $without_assigned_courses
             ORDER BY c.title";
 }

+ 2 - 3
main/admin/dashboard_add_sessions_to_user.php

@@ -9,7 +9,6 @@
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
-global $_configuration;
 
 // create an ajax object
 $xajax = new xajax();
@@ -57,7 +56,7 @@ if (!api_is_platform_admin() && !api_is_session_admin()) {
 
 function search_sessions($needle, $type)
 {
-    global $_configuration, $tbl_session_rel_access_url, $tbl_session, $user_id;
+    global $tbl_session_rel_access_url, $tbl_session, $user_id;
 
     $xajax_response = new xajaxResponse();
     $return = '';
@@ -74,7 +73,7 @@ function search_sessions($needle, $type)
             $without_assigned_sessions = " AND s.id NOT IN(".implode(',', $assigned_sessions_id).")";
         }
 
-        if ($_configuration['multiple_access_urls']) {
+        if (api_is_multiple_url_enabled()) {
             $sql 	= " SELECT s.id, s.name FROM $tbl_session s
                         LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
                         WHERE  s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()."";

+ 7 - 10
main/admin/ldap_import_students_to_session.php

@@ -158,24 +158,21 @@ elseif (!empty($annee) && !empty($id_session) && ($_POST['confirmed']=='yes'))
 			$userid_match_login[$tmp] = $user_id;
 		}
 	}
-	if (!empty($_POST['id_session']))
-	{
+	if (!empty($_POST['id_session'])) {
 		$num = 0;
 		$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
 		$tbl_session	  = Database::get_main_table(TABLE_MAIN_SESSION);
-		foreach($UserList as $user_id)
-		{
+		foreach ($UserList as $user_id) {
 			$sql = 'INSERT INTO '.$tbl_session_user.' SET
-					id_user="'.intval($user_id).'",
-					id_session = "'.intval($id_session).'"';
+					user_id ="'.intval($user_id).'",
+					session_id = "'.intval($id_session).'"';
 			$res_user = Database::query($sql);
-			if ($res_user)
-			{
+			if ($res_user) {
 				$num++;
 			}
 		}
-		if($num>0)
-		{
+
+		if($num>0) {
 			$sql = 'UPDATE '.$tbl_session.' SET nbr_users = (nbr_users + '.$num.') WHERE id = '.intval($id_session);
 			$res = Database::query($sql);
 		}

+ 17 - 18
main/admin/ldap_synchro.php

@@ -124,42 +124,41 @@ foreach($Sessions as $session){
 			print "> $name_session: ".count($UserAdd).get_lang('Added').' '.get_lang('And').' '.count($UserUpdate).' '.get_lang('Modified')."\n";
 		}
 
-		// Une fois les utilisateurs importer dans la base des utilisateurs, on peux les affecter a� la session
-		$result=Database::query("SELECT course_code FROM $tbl_session_rel_course " .
-				"WHERE id_session='$id_session'");
+		// Une fois les utilisateurs importer dans la base des utilisateurs, on peux les affecter la session
+		$result=Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id='$id_session'");
 		$CourseList=array();
-		while($row=Database::fetch_array($result))
-		{
-			$CourseList[]=$row['course_code'];
+		while($row=Database::fetch_array($result)) {
+			$CourseList[]= $row['c_id'];
 		}
-		foreach($CourseList as $enreg_course)
-		{
+
+		foreach ($CourseList as $enreg_course) {
 			// On ajoute la relation entre l'utilisateur et le cours
-			foreach($UserList as $enreg_user)
-			{
-				Database::query("INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$enreg_user')");
+			foreach ($UserList as $enreg_user) {
+				$sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(session_id,c_id,user_id)
+						VALUES('$id_session','$enreg_course','$enreg_user')";
+				Database::query($sql);
 			}
-			$sql = "SELECT COUNT(id_user) as nbUsers " .
+			$sql = "SELECT COUNT(user_id) as nbUsers " .
 					"FROM $tbl_session_rel_course_rel_user " .
-					"WHERE id_session='$id_session' AND course_code='$enreg_course'";
+					"WHERE session_id='$id_session' AND c_id='$enreg_course'";
 			$rs = Database::query($sql);
 			list($nbr_users) = Database::fetch_array($rs);
-			$sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'";
+			$sql = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users
+					WHERE session_id='$id_session' AND c_id = '$enreg_course'";
 			Database::query($sql);
 		}
 		// On ajoute la relation entre l'utilisateur et la session
 		foreach($UserList as $enreg_user){
-			$sql = "INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) " .
+			$sql = "INSERT IGNORE INTO $tbl_session_rel_user(session_id, user_id) " .
 					"VALUES('$id_session','$enreg_user')";
 			Database::query($sql);
 		}
-		$sql = "SELECT COUNT(id_user) as nbUsers " .
+		$sql = "SELECT COUNT(user_id) as nbUsers " .
 				"FROM $tbl_session_rel_user " .
-				"WHERE id_session='$id_session' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."";
+				"WHERE session_id='$id_session' AND relation_type<>".SESSION_RELATION_TYPE_RRHH."";
 		$rs = Database::query($sql);
 		list($nbr_users) = Database::fetch_array($rs);
 		$sql = "UPDATE $tbl_session SET nbr_users=$nbr_users WHERE id='$id_session'";
 		Database::query($sql);
 	}
 }
-?>

+ 23 - 18
main/admin/resume_session.php

@@ -1,9 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
 *	@author Bart Mollet, Julio Montoya lot of fixes
 *	@package chamilo.admin
 */
+
 $cidReset = true;
 require_once '../inc/global.inc.php';
 
@@ -76,12 +78,12 @@ $url_id = api_get_current_access_url_id();
 
 switch ($action) {
     case 'move_up':
-        SessionManager::moveUp($sessionId, $_GET['course_code']);
+        SessionManager::moveUp($sessionId, $_GET['course_id']);
         header('Location: resume_session.php?id_session='.$sessionId);
         exit;
         break;
     case 'move_down':
-        SessionManager::moveDown($sessionId, $_GET['course_code']);
+        SessionManager::moveDown($sessionId, $_GET['course_id']);
         header('Location: resume_session.php?id_session='.$sessionId);
         exit;
         break;
@@ -288,13 +290,15 @@ if ($session['nbr_courses'] == 0) {
 } else {
 	// select the courses
 
-    $orderBy = "ORDER BY position";
+    //$orderBy = "ORDER BY position";
+    $orderBy = '';
 
-	$sql = "SELECT code,title,visual_code, nbr_users
-			FROM $tbl_course, $tbl_session_rel_course
+	$sql = "SELECT c.id, code, title, visual_code, nbr_users
+			FROM $tbl_course c INNER JOIN $tbl_session_rel_course sc
+			ON (c.id = sc.c_id)
 			WHERE
-			    course_code = code AND
-			    id_session='$sessionId'
+			    sc.c_id = c.id AND
+			    session_id='$sessionId'
 			$orderBy";
 
     $result = Database::query($sql);
@@ -305,25 +309,26 @@ if ($session['nbr_courses'] == 0) {
 		//select the number of users
 
 		$sql = "SELECT count(*)
-                FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
+                FROM $tbl_session_rel_user sru,
+                $tbl_session_rel_course_rel_user srcru
 				WHERE
-				    srcru.id_user = sru.id_user AND
-				    srcru.id_session = sru.id_session AND
-				    srcru.course_code = '".Database::escape_string($course['code'])."' AND
+				    srcru.user_id = sru.user_id AND
+				    srcru.session_id = sru.session_id AND
+				    srcru.c_id = '".intval($course['id'])."' AND
 				    sru.relation_type <> ".SESSION_RELATION_TYPE_RRHH." AND
-				    srcru.id_session = '".intval($sessionId)."'";
+				    srcru.session_id = '".intval($sessionId)."'";
 
 		$rs = Database::query($sql);
 		$course['nbr_users'] = Database::result($rs, 0, 0);
 
 		// Get coachs of the courses in session
 
-		$sql = "SELECT user.lastname,user.firstname,user.username
+		$sql = "SELECT user.lastname, user.firstname, user.username
                 FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
 				WHERE
-				    session_rcru.id_user = user.user_id AND
-				    session_rcru.id_session = '".intval($sessionId)."' AND
-				    session_rcru.course_code ='".Database::escape_string($course['code'])."' AND
+				    session_rcru.user_id = user.user_id AND
+				    session_rcru.session_id = '".intval($sessionId)."' AND
+				    session_rcru.c_id ='".intval($course['id'])."' AND
 				    session_rcru.status=2";
 		$rs = Database::query($sql);
 
@@ -345,7 +350,7 @@ if ($session['nbr_courses'] == 0) {
         $orderButtons = null;
 
         $upIcon = 'up.png';
-        $urlUp = api_get_self().'?id_session='.$sessionId.'&course_code='.$course['code'].'&action=move_up';
+        $urlUp = api_get_self().'?id_session='.$sessionId.'&course_id='.$course['id'].'&action=move_up';
 
         if ($count == 0) {
             $upIcon = 'up_na.png';
@@ -358,7 +363,7 @@ if ($session['nbr_courses'] == 0) {
         );
 
         $downIcon = 'down.png';
-        $downUrl = api_get_self().'?id_session='.$sessionId.'&course_code='.$course['code'].'&action=move_down';
+        $downUrl = api_get_self().'?id_session='.$sessionId.'&course_id='.$course['id'].'&action=move_down';
 
         if ($count +1 == count($courses)) {
             $downIcon = 'down_na.png';

+ 1 - 1
main/admin/session_category_add.php

@@ -63,7 +63,7 @@ if (!empty($return)) {
 <tr >
 <td colspan="2">
 	<a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}"><?php echo get_lang('AddTimeLimit') ?></a>
-		<div style="display: <?php if($formSent && ($nb_days_acess_before!=0 || $nb_days_acess_after!=0)) echo 'block'; else echo 'none'; ?>;" id="options">
+		<div style="display: none" id="options">
 	<br>
 	<div>
 <table border="0" cellpadding="5" cellspacing="0" width="100%">

+ 29 - 22
main/admin/session_course_edit.php

@@ -1,9 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * Implements the edition of course-session settings
  * @package chamilo.admin
  */
+
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
@@ -12,24 +14,29 @@ $id_session = intval($_GET['id_session']);
 SessionManager::protect_session_edit($id_session);
 $course_code = $_GET['course_code'];
 
-$formSent=0;
-$errorMsg='';
+$formSent = 0;
+$errorMsg = '';
 
 // Database Table Definitions
-$tbl_user			= Database::get_main_table(TABLE_MAIN_USER);
-$tbl_course			= Database::get_main_table(TABLE_MAIN_COURSE);
-$tbl_session		= Database::get_main_table(TABLE_MAIN_SESSION);
-$tbl_session_course	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
+$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
+$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
 $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 
 $course_info = api_get_course_info($_REQUEST['course_code']);
+$courseId = $course_info['real_id'];
 $tool_name = $course_info['name'];
+$sql = "SELECT s.name, c.title
+        FROM $tbl_session_course sc, $tbl_session s, $tbl_course c
+        WHERE
+            sc.session_id = s.id AND
+            sc.c_id = c.id AND
+            sc.session_id='$id_session' AND
+            sc.c_id ='".$courseId."'";
+$result = Database::query($sql);
 
-$result = Database::query("SELECT s.name, c.title FROM $tbl_session_course sc,$tbl_session s,$tbl_course c
-WHERE sc.id_session=s.id AND sc.course_code=c.code AND sc
-.id_session='$id_session' AND sc.course_code='".Database::escape_string($course_code)."'");
-
-if (!list($session_name,$course_title)=Database::fetch_row($result)) {
+if (!list($session_name,$course_title) = Database::fetch_row($result)) {
 	header('Location: session_course_list.php?id_session='.$id_session);
 	exit();
 }
@@ -41,11 +48,12 @@ $interbreadcrumb[]=array('url' => "session_course_list.php?id_session=$id_sessio
 
 $arr_infos = array();
 if (isset($_POST['formSent']) && $_POST['formSent']) {
-	$formSent=1;
+	$formSent = 1;
 
 	// get all tutor by course_code in the session
-	$sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user
-	        WHERE id_session = '$id_session' AND course_code = '".Database::escape_string($course_code)."' AND status = 2";
+	$sql = "SELECT user_id
+	        FROM $tbl_session_rel_course_rel_user
+	        WHERE session_id = '$id_session' AND c_id = '".$courseId."' AND status = 2";
 	$rs_coachs = Database::query($sql);
 
 	$coachs_course_session = array();
@@ -61,7 +69,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
 
 		foreach ($id_coachs as $id_coach) {
 			$id_coach = intval($id_coach);
-			$rs1 = SessionManager::set_coach_to_course_session($id_coach, $id_session, $course_code);
+			$rs1 = SessionManager::set_coach_to_course_session($id_coach, $id_session, $courseId);
 		}
 
 		// set status to 0 other tutors from multiple list
@@ -71,30 +79,29 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
 			$rs2 = SessionManager::set_coach_to_course_session(
 				$nocoach_user_id,
 				$id_session,
-				$course_code,
+                $courseId,
 				true
 			);
 		}
 
 		header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session);
 		exit();
-
 	}
 } else {
-	$sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user
-	        WHERE id_session = '$id_session' AND course_code = '".Database::escape_string($course_code)."' AND status = 2 ";
+	$sql = "SELECT user_id FROM $tbl_session_rel_course_rel_user
+	        WHERE session_id = '$id_session' AND c_id = '".$courseId."' AND status = 2 ";
 	$rs = Database::query($sql);
 
 	if (Database::num_rows($rs) > 0) {
 		while ($infos = Database::fetch_array($rs)) {
-			$arr_infos[] = $infos['id_user'];
+			$arr_infos[] = $infos['user_id'];
 		}
 	}
 }
 
 $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
-global $_configuration;
-if ($_configuration['multiple_access_urls']) {
+
+if (api_is_multiple_url_enabled()) {
     $tbl_access_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
     $access_url_id = api_get_current_access_url_id();
     $sql="SELECT u.user_id,lastname,firstname,username

+ 16 - 8
main/admin/session_course_list.php

@@ -43,9 +43,9 @@ if ($action == 'delete') {
 		}
 		$idChecked = $my_temp;
 		$idChecked="'".implode("','", $idChecked)."'";
-		$result = Database::query("DELETE FROM $tbl_session_rel_course WHERE id_session='$id_session' AND course_code IN($idChecked)");
+		$result = Database::query("DELETE FROM $tbl_session_rel_course WHERE session_id='$id_session' AND c_id IN($idChecked)");
 		$nbr_affected_rows=Database::affected_rows($result);
-		Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code IN($idChecked)");
+		Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE session_id='$id_session' AND c_id IN($idChecked)");
 		Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
 	}
 	header('Location: '.api_get_self().'?id_session='.$id_session.'&sort='.$sort);
@@ -55,7 +55,11 @@ if ($action == 'delete') {
 $limit  = 20;
 $from   = $page * $limit;
 
-$sql = "SELECT code, title, nbr_users FROM $tbl_session_rel_course, $tbl_course WHERE course_code=code AND id_session='$id_session' ORDER BY $sort LIMIT $from,".($limit+1);
+$sql = "SELECT c.id, c.code, c.title, nbr_users
+		FROM $tbl_session_rel_course, $tbl_course c
+		WHERE c_id = c.id AND session_id='$id_session'
+		ORDER BY $sort
+		LIMIT $from,".($limit+1);
 $result=Database::query($sql);
 $Courses=Database::store_result($result);
 $tool_name = api_htmlentities($session_name,ENT_QUOTES,$charset).' : '.get_lang('CourseListInSession');
@@ -76,14 +80,18 @@ $tableHeader[] = array(get_lang('NbUsers'));
 $tableHeader[] = array(get_lang('Actions'));
 
 $tableCourses = array();
-foreach($Courses as $key=>$enreg) {
+
+foreach ($Courses as $key=>$enreg) {
 	$course = array();
-	$course[] = '<input type="checkbox" name="idChecked[]" value="'.$enreg['code'].'">';
+	$course[] = '<input type="checkbox" name="idChecked[]" value="'.$enreg['id'].'">';
 	$course[] = api_htmlentities($enreg['title'],ENT_QUOTES,$charset);
 	$course[] = '<a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$enreg['code'].'">'.$enreg['nbr_users'].' '.get_lang('Users').'</a>';
-	$course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['code'].'/?id_session='.$id_session.'">'.Display::return_icon('course_home.gif', get_lang('Course')).'</a>
-                <a href="session_course_edit.php?id_session='.$id_session.'&page=session_course_list.php&course_code='.$enreg['code'].'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>
-				<a href="'.api_get_self().'?id_session='.$id_session.'&sort='.$sort.'&action=delete&idChecked[]='.$enreg['code'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
+	$course[] = '<a href="'.api_get_path(WEB_COURSE_PATH).$enreg['code'].'/?id_session='.$id_session.'">'.
+		Display::return_icon('course_home.gif', get_lang('Course')).'</a>
+			<a href="session_course_edit.php?id_session='.$id_session.'&page=session_course_list.php&course_code='.$enreg['code'].'">'.
+		Display::return_icon('edit.png', get_lang('Edit')).'</a>
+			<a href="'.api_get_self().'?id_session='.$id_session.'&sort='.$sort.'&action=delete&idChecked[]='.$enreg['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.
+		Display::return_icon('delete.png', get_lang('Delete')).'</a>';
 	$tableCourses[] = $course;
 }
 echo '<form method="post" action="'.api_get_self().'">';

+ 65 - 51
main/admin/session_course_user.php

@@ -37,32 +37,38 @@ if (empty($id_user) || empty($id_session)) {
 }
 
 if (!api_is_platform_admin()) {
-    $sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
+    $sql = 'SELECT session_admin_id
+            FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).'
+            WHERE id='.$id_session;
     $rs = Database::query($sql);
     if (Database::result($rs,0,0)!=$_user['user_id']) {
         api_not_allowed(true);
     }
 }
 
-$formSent=0;
-$errorMsg=$firstLetterCourse=$firstLetterSession='';
-$CourseList=$SessionList=array();
-$courses=$sessions=array();
-$noPHP_SELF=true;
+$formSent = 0;
+$errorMsg = $firstLetterCourse = $firstLetterSession = '';
+$CourseList = $SessionList = array();
+$courses = $sessions = array();
+$noPHP_SELF = true;
 
 if (isset($_POST['formSent']) && $_POST['formSent']) {
-    $formSent			= $_POST['formSent'];
-    $CourseList			= $_POST['SessionCoursesList'];
+    $formSent = $_POST['formSent'];
+    $CourseList = $_POST['SessionCoursesList'];
 
     if (!is_array($CourseList)) {
         $CourseList=array();
     }
 
-    $sql="SELECT distinct code
-			FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course
-			ON course.code = session_rel_course.course_code inner join $tbl_session_rel_course_rel_user as srcru
-			ON (srcru.id_session =  session_rel_course.id_session)
-			WHERE id_user = $id_user and session_rel_course.id_session = $id_session";
+    $sql = "SELECT DISTINCT course.id
+			FROM $tbl_course course
+			LEFT JOIN $tbl_session_rel_course session_rel_course
+			ON course.id = session_rel_course.c_id
+			INNER JOIN $tbl_session_rel_course_rel_user as srcru
+			ON (srcru.session_id = session_rel_course.session_id)
+			WHERE
+			    user_id = $id_user AND
+			    session_rel_course.session_id = $id_session";
 
     $rs = Database::query($sql);
     $existingCourses = Database::store_result($rs);
@@ -70,37 +76,41 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
         header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user.'&msg='.get_lang('MaybeYouWantToDeleteThisUserFromSession'));
         exit;
     }
-    foreach($CourseList as $enreg_course) {
+
+    foreach ($CourseList as $enreg_course) {
         $exists = false;
         foreach($existingCourses as $existingCourse) {
-            if($enreg_course == $existingCourse['course_code']) {
+            if ($enreg_course == $existingCourse['id']) {
                 $exists=true;
             }
         }
+
         if(!$exists) {
             $enreg_course = Database::escape_string($enreg_course);
             $sql_delete = "DELETE FROM $tbl_session_rel_course_rel_user
-							WHERE id_user='".$id_user."' AND course_code='".$enreg_course."' AND id_session=$id_session";
+						   WHERE user_id = '".$id_user."' AND c_id='".$enreg_course."' AND session_id=$id_session";
             $result = Database::query($sql_delete);
             if (Database::affected_rows($result)) {
                 //update session rel course table
-                $sql_update  = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users - 1 WHERE id_session='$id_session' AND course_code='$enreg_course'";
+                $sql_update  = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users - 1
+                                WHERE session_id='$id_session' AND c_id = '$enreg_course'";
                 Database::query($sql_update);
             }
         }
     }
-    foreach($existingCourses as $existingCourse) {
-        //$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code, id_coach) VALUES('$id_session','$enreg_course','$id_coach')";
-        if (!in_array($existingCourse['code'], $CourseList)){
-            $existingCourse = Database::escape_string($existingCourse['code']);
-            $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$existingCourse','$id_user')";
-            $result = Database::query($sql_insert);
+
+    foreach ($existingCourses as $existingCourse) {
+        if (!in_array($existingCourse['id'], $CourseList)){
+            $existingCourse = Database::escape_string($existingCourse['id']);
+            $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(session_id,c_id,user_id)
+                    VALUES ('$id_session','$existingCourse','$id_user')";
+            $result = Database::query($sql);
             if (Database::affected_rows($result)) {
                 //update session rel course table
-                $sql_update  = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users + 1 WHERE id_session='$id_session' AND course_code='$existingCourse'";
-                Database::query($sql_update);
+                $sql  = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users + 1
+                         WHERE session_id='$id_session' AND c_id = '$existingCourse'";
+                Database::query($sql);
             }
-
         }
     }
     header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user.'&msg='.get_lang('CoursesUpdated'));
@@ -121,29 +131,33 @@ echo '<legend>'.$tool_name.': '.$session_info['name'].' - '.$user_info['complete
 
 $nosessionCourses = $sessionCourses = array();
 // actual user
-$sql = "SELECT code, title, visual_code, srcru.id_session
-        FROM $tbl_course course inner JOIN $tbl_session_rel_course_rel_user   as srcru
-        ON course.code = srcru.course_code  WHERE srcru.id_user = $id_user AND id_session = $id_session";
+$sql = "SELECT course.id, code, title, visual_code, srcru.session_id
+        FROM $tbl_course course
+        INNER JOIN $tbl_session_rel_course_rel_user as srcru
+        ON course.id = srcru.c_id
+        WHERE srcru.user_id = $id_user AND session_id = $id_session";
 
 //all
-$sql_all="SELECT code, title, visual_code, src.id_session " .
-    "FROM $tbl_course course inner JOIN $tbl_session_rel_course  as src  " .
-    "ON course.code = src.course_code AND id_session = $id_session";
+$sql_all="SELECT course.id, code, title, visual_code, src.session_id
+        FROM $tbl_course course
+        INNER JOIN $tbl_session_rel_course  as src
+        ON course.id = src.c_id AND session_id = $id_session";
 $result=Database::query($sql);
 $Courses=Database::store_result($result);
 
-$result=Database::query($sql_all);
-$CoursesAll=Database::store_result($result);
+$result = Database::query($sql_all);
+$CoursesAll = Database::store_result($result);
 
 $course_temp = array();
-foreach($Courses as $course) {
-    $course_temp[] = $course['code'];
+foreach ($Courses as $course) {
+    $course_temp[] = $course['id'];
 }
+
 foreach($CoursesAll as $course) {
-    if (in_array($course['code'], $course_temp)) {
-        $nosessionCourses[$course['code']] = $course ;
+    if (in_array($course['id'], $course_temp)) {
+        $nosessionCourses[$course['id']] = $course ;
     } else {
-        $sessionCourses[$course['code']] = $course ;
+        $sessionCourses[$course['id']] = $course ;
     }
 }
 
@@ -171,7 +185,7 @@ unset($Courses);
                     <select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" style="width:320px;"> <?php
                         foreach($nosessionCourses as $enreg) {
                             ?>
-                            <option value="<?php echo $enreg['code']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES).'"'; if(in_array($enreg['code'],$CourseList)) echo 'selected="selected"'; ?>><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
+                            <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES).'"'; if(in_array($enreg['code'],$CourseList)) echo 'selected="selected"'; ?>><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
                         <?php
                         }
                         ?>  </select></div> <?php
@@ -192,17 +206,17 @@ unset($Courses);
                 echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('EditSessionCourses').'</button>';
                 ?>
             </td>
-            <td width="45%" align="center"><select id='destination' name="SessionCoursesList[]" multiple="multiple" size="20" style="width:320px;">
-                    <?php
-                    foreach($sessionCourses as $enreg) {
-                        ?>
-                        <option value="<?php echo $enreg['code']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>"><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
-                    <?php
-                    }
-                    unset($sessionCourses);
-                    ?>
-
-                </select></td>
+            <td width="45%" align="center">
+                <select id='destination' name="SessionCoursesList[]" multiple="multiple" size="20" style="width:320px;">
+            <?php
+            foreach($sessionCourses as $enreg) {
+                ?>
+                <option value="<?php echo $enreg['id']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>"><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
+            <?php
+            }
+            unset($sessionCourses);
+            ?>
+            </select></td>
         </tr>
     </table>
 </form>

+ 18 - 11
main/admin/session_course_user_list.php

@@ -22,7 +22,10 @@ if (empty($id_session )) {
     api_not_allowed();
 }
 
-$course_code    = Database::escape_string(trim($_GET['course_code']));
+$course_code = Database::escape_string(trim($_GET['course_code']));
+$courseInfo = api_get_course_info($course_code);
+$courseId = $courseInfo['real_id'];
+
 $page           = isset($_GET['page']) ? intval($_GET['page']) : null;
 $action         = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
 $default_sort   = api_sort_by_first_name() ? 'firstname':'lastname';
@@ -41,9 +44,9 @@ if (is_array($idChecked)) {
 
 $sql = "SELECT s.name, c.title
         FROM $tbl_session_rel_course src
-		INNER JOIN $tbl_session s ON s.id = src.id_session
-		INNER JOIN $tbl_course c ON c.code = src.course_code
-		WHERE src.id_session='$id_session' AND src.course_code='$course_code' ";
+		INNER JOIN $tbl_session s ON s.id = src.session_id
+		INNER JOIN $tbl_course c ON c.id = src.c_id
+		WHERE src.session_id='$id_session' AND src.c_id='$courseId' ";
 
 $result = Database::query($sql);
 if (!list($session_name,$course_title) = Database::fetch_row($result)) {
@@ -55,12 +58,16 @@ switch ($action) {
     case 'delete':
         if (is_array($idChecked) && count($idChecked)>0) {
             array_map('intval', $idChecked);
-            $idChecked = implode(',',$idChecked);
+            $idChecked = implode(',', $idChecked);
         }
         if (!empty($idChecked)) {
-            $result = Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='".$course_code."' AND id_user IN($idChecked)");
+            $sql = "DELETE FROM $tbl_session_rel_course_rel_user
+                    WHERE session_id='$id_session' AND c_id='".$courseId."' AND user_id IN($idChecked)";
+            $result = Database::query($sql);
             $nbr_affected_rows = Database::affected_rows($result);
-            Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE id_session='$id_session' AND course_code='".$course_code."'");
+            $sql = "UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows
+                    WHERE session_id='$id_session' AND c_id='".$courseId."'";
+            Database::query($sql);
         }
         header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
         exit();
@@ -77,12 +84,12 @@ $limit  = 20;
 $from   = $page * $limit;
 $is_western_name_order = api_is_western_name_order();
 $sql = "SELECT DISTINCT
-         u.user_id,".($is_western_name_order ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname').", u.username, scru.id_user as is_subscribed
+         u.user_id,".($is_western_name_order ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname').", u.username, scru.user_id as is_subscribed
          FROM $tbl_session_rel_user s
-         INNER JOIN $tbl_user u ON (u.user_id=s.id_user)
+         INNER JOIN $tbl_user u ON (u.user_id=s.user_id)
          LEFT JOIN $tbl_session_rel_course_rel_user scru
-         ON (s.id_session = scru.id_session AND s.id_user = scru.id_user AND scru.course_code = '".$course_code."' )
-         WHERE s.id_session='$id_session'
+         ON (s.session_id = scru.session_id AND s.user_id = scru.user_id AND scru.c_id = '".$courseId."' )
+         WHERE s.session_id='$id_session'
          ORDER BY $sort $direction
          LIMIT $from,".($limit+1);
 

+ 105 - 91
main/admin/session_export.php

@@ -1,114 +1,114 @@
 <?php
+/* For licensing terms, see /license.txt */
+
 /**
 *	@package chamilo.admin
 */
 
 $cidReset = true;
 
-include '../inc/global.inc.php';
+require_once '../inc/global.inc.php';
 
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script(true);
 
-$session_id = intval($_GET['session_id']);
+$session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
 $formSent = 0;
 $errorMsg = '';
 
 // Database Table Definitions
-$tbl_user					= Database::get_main_table(TABLE_MAIN_USER);
-$tbl_course      			= Database::get_main_table(TABLE_MAIN_COURSE);
-$tbl_course_user 			= Database::get_main_table(TABLE_MAIN_COURSE_USER);
-$tbl_session      			= Database::get_main_table(TABLE_MAIN_SESSION);
-$tbl_session_user      		= Database::get_main_table(TABLE_MAIN_SESSION_USER);
-$tbl_session_course      	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-$tbl_session_course_user 	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-
+$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
+$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
+$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
+$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
+$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 
 $archivePath = api_get_path(SYS_ARCHIVE_PATH);
-$archiveURL  = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
+$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
 
-$tool_name   = get_lang('ExportSessionListXMLCSV');
+$tool_name = get_lang('ExportSessionListXMLCSV');
 
 global $_configuration;
 
-
 $interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
 
 set_time_limit(0);
 
-if ($_POST['formSent']) {
+if (isset($_POST['formSent'])) {
 	$formSent = $_POST['formSent'];
 	$file_type = ($_POST['file_type'] == 'csv')?'csv':'xml';
 	$session_id = $_POST['session_id'];
 	if (empty($session_id)) {
-		$sql = "SELECT id,name,id_coach,username,date_start,date_end,visibility,session_category_id FROM $tbl_session INNER JOIN $tbl_user
-					ON $tbl_user.user_id = $tbl_session.id_coach ORDER BY id";
-
+		$sql = "SELECT
+					s.id,
+					name,
+					id_coach,
+					username,
+					date_start,
+					date_end,
+					visibility,
+					session_category_id
+				FROM $tbl_session s
+				INNER JOIN $tbl_user
+				ON $tbl_user.user_id = s.id_coach
+				ORDER BY id";
 
-		if ($_configuration['multiple_access_urls']) {
+		if (api_is_multiple_url_enabled()) {
 			$tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
 			$access_url_id = api_get_current_access_url_id();
 			if ($access_url_id != -1){
-			$sql = "SELECT id, name,id_coach,username,date_start,date_end,visibility,session_category_id FROM $tbl_session s INNER JOIN $tbl_session_rel_access_url as session_rel_url
-				ON (s.id= session_rel_url.session_id) INNER JOIN $tbl_user u ON (u.user_id = s.id_coach)
-				WHERE access_url_id = $access_url_id
-				ORDER BY id";
-
+			$sql = "SELECT s.id, name,id_coach,username,date_start,date_end,visibility,session_category_id
+					FROM $tbl_session s
+					INNER JOIN $tbl_session_rel_access_url as session_rel_url
+					ON (s.id= session_rel_url.session_id)
+					INNER JOIN $tbl_user u ON (u.user_id = s.id_coach)
+					WHERE access_url_id = $access_url_id
+					ORDER BY id";
 			}
 		}
-		$result=Database::query($sql);
-	}
-	else
-	{
-		$sql = "SELECT id,name,username,date_start,date_end,visibility,session_category_id
-				FROM $tbl_session
+
+		$result = Database::query($sql);
+	} else {
+		$sql = "SELECT s.id,name,username,date_start,date_end,visibility,session_category_id
+				FROM $tbl_session s
 				INNER JOIN $tbl_user
-					ON $tbl_user.user_id = $tbl_session.id_coach
+					ON $tbl_user.user_id = s.id_coach
 				WHERE id='$session_id'";
-
 		$result = Database::query($sql);
-
 	}
 
-	if(Database::num_rows($result))
-	{
-		if(!file_exists($archivePath))
-		{
+	if (Database::num_rows($result)) {
+		if (!file_exists($archivePath)) {
 			mkdir($archivePath, api_get_permissions_for_new_directories(), true);
 		}
 
-		if(!file_exists($archivePath.'index.html'))
-		{
-			$fp=fopen($archivePath.'index.html','w');
-
+		if (!file_exists($archivePath.'index.html')) {
+			$fp = fopen($archivePath.'index.html','w');
 			fputs($fp,'<html><head></head><body></body></html>');
-
 			fclose($fp);
 		}
 
 		$archiveFile='export_sessions_'.$session_id.'_'.date('Y-m-d_H-i-s').'.'.$file_type;
 
-		while( file_exists($archivePath.$archiveFile))
-		{
+		while( file_exists($archivePath.$archiveFile)) {
 			$archiveFile='export_users_'.$session_id.'_'.date('Y-m-d_H-i-s').'_'.uniqid('').'.'.$file_type;
 		}
-		$fp=fopen($archivePath.$archiveFile,'w');
 
-		if($file_type == 'csv')
-		{
+		$fp = fopen($archivePath.$archiveFile, 'w');
+
+		if ($file_type == 'csv') {
 			$cvs = true;
 			fputs($fp,"SessionName;Coach;DateStart;DateEnd;Visibility;SessionCategory;Users;Courses;\n");
-		}
-		else
-		{
+		} else {
 			$cvs = false;
 			fputs($fp, "<?xml version=\"1.0\" encoding=\"".api_get_system_encoding()."\"?>\n<Sessions>\n");
 		}
 
-		while($row=Database::fetch_array($result))
-		{
+		while($row=Database::fetch_array($result)) {
 			$add = '';
 			$row['name'] = str_replace(';',',',$row['name']);
 			$row['username'] = str_replace(';',',',$row['username']);
@@ -116,10 +116,9 @@ if ($_POST['formSent']) {
 			$row['date_end'] = str_replace(';',',',$row['date_end']);
 			$row['visibility'] = str_replace(';',',',$row['visibility']);
 			$row['session_category'] = str_replace(';',',',$row['session_category_id']);
-			if($cvs){
+			if ($cvs) {
 				$add.= $row['name'].';'.$row['username'].';'.$row['date_start'].';'.$row['date_end'].';'.$row['visibility'].';'.$row['session_category'].';';
-			}
-			else {
+			} else {
 				$add = "\t<Session>\n"
 						 ."\t\t<SessionName>$row[name]</SessionName>\n"
 						 ."\t\t<Coach>$row[username]</Coach>\n"
@@ -130,14 +129,17 @@ if ($_POST['formSent']) {
 			}
 
 			//users
-			$sql = "SELECT DISTINCT $tbl_user.username FROM $tbl_user
+			$sql = "SELECT DISTINCT $tbl_user.username
+					FROM $tbl_user
 					INNER JOIN $tbl_session_user
-						ON $tbl_user.user_id = $tbl_session_user.id_user AND $tbl_session_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
-						AND $tbl_session_user.id_session = '".$row['id']."'";
+					ON
+						$tbl_user.user_id = $tbl_session_user.user_id AND
+						$tbl_session_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
+						$tbl_session_user.session_id = '".$row['id']."'";
 
 			$rsUsers = Database::query($sql);
 			$users = '';
-			while($rowUsers = Database::fetch_array($rsUsers)){
+			while ($rowUsers = Database::fetch_array($rsUsers)){
 				if($cvs){
 					$users .= str_replace(';',',',$rowUsers['username']).'|';
 				}
@@ -145,7 +147,8 @@ if ($_POST['formSent']) {
 					$users .= "\t\t<User>$rowUsers[username]</User>\n";
 				}
 			}
-			if(!empty($users) && $cvs)
+
+			if (!empty($users) && $cvs)
 				$users = api_substr($users , 0, api_strlen($users)-1);
 
 			if($cvs)
@@ -154,23 +157,25 @@ if ($_POST['formSent']) {
 			$add .= $users;
 
 			//courses
-			$sql = "SELECT DISTINCT $tbl_course.code
-					FROM $tbl_course
-					INNER JOIN $tbl_session_course_user
-						ON $tbl_course.code = $tbl_session_course_user.course_code
-						AND $tbl_session_course_user.id_session = '".$row['id']."'";
+			$sql = "SELECT DISTINCT c.code, sc.id, c_id
+					FROM $tbl_course c
+					INNER JOIN $tbl_session_course_user sc
+						ON c.id = sc.c_id
+						AND sc.session_id = '".$row['id']."'";
 
 			$rsCourses = Database::query($sql);
 
 			$courses = '';
-			while($rowCourses = Database::fetch_array($rsCourses)){
-
+			while ($rowCourses = Database::fetch_array($rsCourses)) {
 				// get coachs from a course
 				$sql = "SELECT u.username
 					FROM $tbl_session_course_user scu
-					INNER JOIN $tbl_user u ON u.user_id = scu.id_user
-					WHERE scu.course_code = '{$rowCourses['code']}'
-						AND scu.id_session = '".$row['id']."' AND scu.status = 2 ";
+					INNER JOIN $tbl_user u
+					ON u.user_id = scu.user_id
+					WHERE
+						scu.c_id = '{$rowCourses['c_id']}' AND
+						scu.session_id = '".$row['id']."' AND
+						scu.status = 2 ";
 
 				$rs_coachs = Database::query($sql);
 				$coachs = array();
@@ -180,11 +185,10 @@ if ($_POST['formSent']) {
 
 				$coachs = implode(",",$coachs);
 
-				if($cvs){
+				if ($cvs) {
 					$courses .= str_replace(';',',',$rowCourses['code']);
 					$courses .= '['.str_replace(';',',',$coachs).'][';
-				}
-				else {
+				} else {
 					$courses .= "\t\t<Course>\n";
 					$courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n";
 					$courses .= "\t\t\t<Coach>$coachs</Coach>\n";
@@ -193,26 +197,35 @@ if ($_POST['formSent']) {
 				// rel user courses
 				$sql = "SELECT DISTINCT u.username
 						FROM $tbl_session_course_user scu
-						INNER JOIN $tbl_session_user su ON scu.id_user = su.id_user AND scu.id_session = su.id_session AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
+						INNER JOIN $tbl_session_user su
+						ON
+							scu.user_id = su.user_id AND
+							scu.session_id = su.session_id AND
+							su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
 						INNER JOIN $tbl_user u
-						ON scu.id_user = u.user_id
-						AND scu.course_code='".$rowCourses['code']."'
-						AND scu.id_session='".$row['id']."'";
+						ON
+							scu.user_id = u.user_id AND
+							scu.c_id='".$rowCourses['c_id']."' AND
+							scu.session_id='".$row['id']."'";
 
 				$rsUsersCourse = Database::query($sql);
 				$userscourse = '';
-				while($rowUsersCourse = Database::fetch_array($rsUsersCourse)){
-
-					if($cvs){
+				while ($rowUsersCourse = Database::fetch_array($rsUsersCourse)){
+					if ($cvs) {
 						$userscourse .= str_replace(';',',',$rowUsersCourse['username']).',';
-					}
-					else {
+					} else {
 						$courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n";
 					}
 				}
-				if($cvs){
-					if(!empty($userscourse))
-						$userscourse = api_substr($userscourse , 0, api_strlen($userscourse)-1);
+
+				if ($cvs) {
+					if (!empty($userscourse)) {
+						$userscourse = api_substr(
+							$userscourse,
+							0,
+							api_strlen($userscourse) - 1
+						);
+					}
 
 					$courses .= $userscourse.']|';
 				}
@@ -225,7 +238,7 @@ if ($_POST['formSent']) {
 				$courses = api_substr($courses , 0, api_strlen($courses)-1);
 			$add .= $courses;
 
-			if($cvs) {
+		 	if ($cvs) {
 				$breakline = api_is_windows_os()?"\r\n":"\n";
 				$add .= ";$breakline";
 			} else {
@@ -249,14 +262,15 @@ Display::display_header($tool_name);
 //select of sessions
 $sql = "SELECT id, name FROM $tbl_session ORDER BY name";
 
-if ($_configuration['multiple_access_urls']) {
-	$tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
+if (api_is_multiple_url_enabled()) {
+	$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
 	$access_url_id = api_get_current_access_url_id();
 	if ($access_url_id != -1){
-	$sql = "SELECT id, name FROM $tbl_session s INNER JOIN $tbl_session_rel_access_url as session_rel_url
-		ON (s.id= session_rel_url.session_id)
-		WHERE access_url_id = $access_url_id
-		ORDER BY name";
+	$sql = "SELECT s.id, name FROM $tbl_session s
+			INNER JOIN $tbl_session_rel_access_url as session_rel_url
+			ON (s.id = session_rel_url.session_id)
+			WHERE access_url_id = $access_url_id
+			ORDER BY name";
 	}
 }
 $result = Database::query($sql);

+ 37 - 38
main/admin/session_import.php

@@ -37,7 +37,6 @@ set_time_limit(0);
 $purification_option_for_usernames = false;
 $inserted_in_course = array();
 
-global $_configuration;
 $warn = null;
 if (isset($_POST['formSent']) && $_POST['formSent']) {
     if (isset($_FILES['import_file']['tmp_name']) &&
@@ -278,15 +277,14 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                                 $rs_session = Database::query($sql_session);
                                 $session_id = Database::query("SELECT id FROM $tbl_session WHERE name='$session_name'");
                                 list($session_id) = Database::fetch_array($session_id);
-                                Database::query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'");
-                                Database::query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'");
-                                Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'");
+                                Database::query("DELETE FROM $tbl_session_user WHERE session_id ='$session_id'");
+                                Database::query("DELETE FROM $tbl_session_course WHERE session_id='$session_id'");
+                                Database::query("DELETE FROM $tbl_session_course_user WHERE session_id='$session_id'");
                             }
                         }
 
                         // Associate the session with access_url.
-                        global $_configuration;
-                        if ($_configuration['multiple_access_urls']) {
+                        if (api_is_multiple_url_enabled()) {
                             $access_url_id = api_get_current_access_url_id();
                             UrlManager::add_session_to_url($session_id, $access_url_id);
                         } else {
@@ -301,8 +299,8 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                             $user_id = UserManager::get_user_id_from_username($username);
                             if ($user_id !== false) {
                                 $sql = "INSERT IGNORE INTO $tbl_session_user SET
-                                        id_user='$user_id',
-                                        id_session = '$session_id'";
+                                        user_id ='$user_id',
+                                        session_id = '$session_id'";
                                 $rs_user = Database::query($sql);
                                 $user_counter++;
                             }
@@ -315,15 +313,15 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                             if (CourseManager::course_exists($course_code)) {
                                 // If the course exists we continue.
                                 $course_info = CourseManager::get_course_information($course_code);
+                                $courseId = $course_info['c_id'];
 
-                                $session_course_relation = SessionManager::relation_session_course_exist($session_id, $course_code);
+                                $session_course_relation = SessionManager::relation_session_course_exist($session_id, $courseId);
                                 if (!$session_course_relation) {
                                     $sql_course = "INSERT INTO $tbl_session_course SET
-                                            course_code = '$course_code',
-                                            id_session='$session_id'";
+                                            c_id = '$courseId',
+                                            session_id='$session_id'";
                                     $rs_course = Database::query($sql_course);
-                                    $course_info = api_get_course_info($course['code']);
-                                    SessionManager::installCourse($id_session, $course_info['real_id']);
+                                    SessionManager::installCourse($id_session, $courseId);
                                 }
 
                                 $course_coaches = explode(',', $node_course->Coach);
@@ -334,9 +332,9 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                                     $coach_id = UserManager::get_user_id_from_username($course_coach);
                                     if ($coach_id !== false) {
                                         $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
-                                                id_user='$coach_id',
-                                                course_code='$course_code',
-                                                id_session = '$session_id',
+                                                user_id='$coach_id',
+                                                c_id = '$courseId',
+                                                session_id = '$session_id',
                                                 status = 2 ";
                                         $rs_coachs = Database::query($sql);
                                     } else {
@@ -353,23 +351,23 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                                     if ($user_id !== false) {
                                         // Adding to session_rel_user table.
                                         $sql = "INSERT IGNORE INTO $tbl_session_user SET
-                                                id_user='$user_id',
-                                                id_session = '$session_id'";
+                                                user_id ='$user_id',
+                                                session_id = '$session_id'";
                                         $rs_user = Database::query($sql);
                                         $user_counter++;
                                         // Adding to session_rel_user_rel_course table.
                                         $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
-                                                id_user='$user_id',
-                                                course_code='$course_code',
-                                                id_session = '$session_id'";
+                                                user_id = '$user_id',
+                                                c_id = '$courseId',
+                                                session_id = '$session_id'";
                                         $rs_users = Database::query($sql);
                                         $users_in_course_counter++;
                                     } else {
                                         $error_message .= get_lang('UserDoesNotExist').' : '.$username.'<br />';
                                     }
                                 }
-                                $update_session_course = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE course_code='$course_code'";
-                                Database::query($update_session_course);
+                                $sql = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE c_id='$courseId'";
+                                Database::query($sql);
                                 $inserted_in_course[$course_code] = $course_info['title'];
 
                             }
@@ -382,13 +380,15 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                                     if ($vcourse['code'] == $course_code) {
                                         // Ignore, this has already been inserted.
                                     } else {
+                                        $course_info = api_get_course_info($course['code']);
+                                        $courseId = $course_info['real_id'];
 
                                         $sql_course = "INSERT INTO $tbl_session_course SET
-                                                course_code = '".$vcourse['code']."',
-                                                id_session='$session_id'";
+                                                c_id = '".$courseId."',
+                                                session_id='$session_id'";
                                         $rs_course = Database::query($sql_course);
-                                        $course_info = api_get_course_info($course['code']);
-                                        SessionManager::installCourse($id_session, $course_info['real_id']);
+
+                                        SessionManager::installCourse($id_session, $courseId);
 
                                         $course_coaches = explode(",",$node_course->Coach);
 
@@ -398,9 +398,9 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                                             $coach_id = UserManager::get_user_id_from_username($course_coach);
                                             if ($coach_id !== false) {
                                                 $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
-                                                        id_user='$coach_id',
-                                                        course_code='{$vcourse['code']}',
-                                                        id_session = '$session_id',
+                                                        user_id='$coach_id',
+                                                        c_id = $courseId,
+                                                        session_id = '$session_id',
                                                         status = 2 ";
                                                 $rs_coachs = Database::query($sql);
                                             } else {
@@ -417,25 +417,24 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
                                             if ($user_id !== false) {
                                                 // Adding to session_rel_user table.
                                                 $sql = "INSERT IGNORE INTO $tbl_session_user SET
-                                                        id_user='$user_id',
-                                                        id_session = '$session_id'";
+                                                        user_id ='$user_id',
+                                                        session_id = '$session_id'";
                                                 $rs_user = Database::query($sql);
                                                 $user_counter++;
                                                 // Adding to session_rel_user_rel_course table.
                                                 $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
-                                                        id_user='$user_id',
-                                                        course_code='{$vcourse['code']}',
-                                                        id_session = '$session_id'";
+                                                        user_id ='$user_id',
+                                                        c_id ='$courseId',
+                                                        session_id = '$session_id'";
                                                 $rs_users = Database::query($sql);
                                                 $users_in_course_counter++;
                                             } else {
                                                 $error_message .= get_lang('UserDoesNotExist').' : '.$username.'<br />';
                                             }
                                         }
-                                        $update_session_course = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE course_code='$course_code'";
-                                        Database::query($update_session_course);
+                                        $sql = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE c_id='$courseId'";
+                                        Database::query($sql);
                                         $inserted_in_course[$course_code] = $course_info['title'];
-
                                     }
                                     $inserted_in_course[$vcourse['code']] = $vcourse['title'];
                                 }

+ 3 - 2
main/admin/session_list.php

@@ -18,7 +18,7 @@ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
 $idChecked = isset($_REQUEST['idChecked']) ? $_REQUEST['idChecked'] : null;
 
 if ($action == 'delete') {
-	SessionManager::delete_session($idChecked);
+	SessionManager::delete($idChecked);
 	header('Location: session_list.php');
 	exit();
 } elseif ($action == 'copy') {
@@ -49,8 +49,9 @@ $courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null;
 if (!empty($courseId)) {
     $courseInfo = api_get_course_info_by_id($courseId);
     $parents = getParentsToString($courseInfo['categoryCode']);
-    $courseList[] = array('id' => $courseInfo['id'], 'text' => $parents.$courseInfo['title']);
+    $courseList[] = array('id' => $courseInfo['code'], 'text' => $parents.$courseInfo['title']);
 }
+
 $sessionFilter->addElement('select_ajax', 'course_name', get_lang('SearchCourse'), null, array('url' => $url, 'defaults' => $courseList));
 $url = api_get_self();
 $actions = '

+ 1 - 1
main/admin/session_user_import.php

@@ -39,7 +39,7 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
         $send_mail = $_POST['sendMail'] ? 1 : 0;
 
         // CSV
-        $users = Import::csv_to_array($_FILES['import_file']['tmp_name']);
+        $users = Import::csvToArray($_FILES['import_file']['tmp_name']);
         $user_list = array();
         foreach ($users as $user_data) {
             $username = $user_data['username'];

+ 1 - 1
main/admin/skill_badge_create.php

@@ -95,7 +95,7 @@ $interbreadcrumb = array(
 );
 
 $tpl = new Template(get_lang('CreateBadge'));
-$tpl->assign('platformAdminEmail', get_setting('emailAdministrator'));
+$tpl->assign('platformAdminEmail', api_get_setting('emailAdministrator'));
 $tpl->assign('skill', $skill);
 
 $contentTemplate = $tpl->get_template('skill/badge_create.tpl');

+ 1 - 1
main/admin/skill_badge_list.php

@@ -39,7 +39,7 @@ $interbreadcrumb = array(
 
 $tpl = new Template(get_lang('Skills'));
 $tpl->assign('errorMessage', $errorMessage);
-$tpl->assign('platformAdminEmail', get_setting('emailAdministrator'));
+$tpl->assign('platformAdminEmail', api_get_setting('emailAdministrator'));
 $tpl->assign('skills', $skills);
 
 $contentTemplate = $tpl->get_template('skill/badge_list.tpl');

+ 1 - 1
main/admin/skills_import.php

@@ -83,7 +83,7 @@ function save_data($skills)
  */
 function parse_csv_data($file)
 {
-	$skills = Import :: csv_to_array($file);
+	$skills = Import :: csvToArray($file);
 	foreach ($skills as $index => $skill) {
 		$skills[$index] = $skill;
 	}

+ 20 - 14
main/admin/special_exports.php

@@ -1,5 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * Special exports
  *
@@ -7,6 +8,7 @@
  * @author Julio Montoya Fixing pclzip folder + some clean <gugli100@gmail.com>
  * @package chamilo.include.export
  */
+
 // including the global file
 $cidReset = true;
 require_once  '../inc/global.inc.php';
@@ -204,7 +206,7 @@ function fullexportspecial(){
     $code_course = '';
     $list_course = array();
     $zip_folder = new PclZip($FileZip['TEMP_FILE_ZIP']);
-    $list_course = Database::get_course_list();
+    $list_course = CourseManager::get_course_list();
 
     $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
     $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
@@ -217,7 +219,7 @@ function fullexportspecial(){
             } else {
                 $querypath = $FileZip['PATH'];
             }
-            $course_id 		= $_course['real_id'];
+            $course_id = $_course['real_id'];
 
             //Add tem to the zip file course
             $sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props
@@ -232,15 +234,18 @@ function fullexportspecial(){
             while ($rows_course_file = Database::fetch_assoc($query)) {
                 $rows_course_file['path'];
                 $zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'],
-                                 PCLZIP_OPT_ADD_PATH, $_course['directory'],
-                                 PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory']."/document".$FileZip['PATH_REMOVE']
-                                );
+                    PCLZIP_OPT_ADD_PATH, $_course['directory'],
+                    PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory']."/document".$FileZip['PATH_REMOVE']
+                );
             }
             //Add tem to the zip file session course
             $code_course = $_course['code'];
-            $sql_session = "SELECT id, name, course_code FROM $tbl_session_course
-                INNER JOIN  $tbl_session ON id_session = id
-                WHERE course_code = '$code_course' ";
+            $sql_session = "SELECT s.id, name, c_id
+                            FROM $tbl_session_course sc
+                            INNER JOIN $tbl_session  s
+                            ON sc.session_id = s.id
+                            WHERE c_id = '$course_id' ";
+
             $query_session = Database::query($sql_session);
             while ($rows_session = Database::fetch_assoc($query_session)) {
                 $session_id = $rows_session['id'];
@@ -255,21 +260,22 @@ function fullexportspecial(){
                 $query_session_doc = Database::query($sql_session_doc);
                 while ($rows_course_session_file = Database::fetch_assoc($query_session_doc)) {
                     $zip_folder->add($FileZip['PATH_COURSE'].$_course['directory'].'/document'.$rows_course_session_file['path'],
-                                     PCLZIP_OPT_ADD_PATH, $_course['directory']."/".$rows_session['name'],
-                                     PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory'].'/document'.$FileZip['PATH_REMOVE']
-                                    );
+                         PCLZIP_OPT_ADD_PATH, $_course['directory']."/".$rows_session['name'],
+                         PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory'].'/document'.$FileZip['PATH_REMOVE']
+                     );
                 }
             }
         }
+
         $name = rename_zip($FileZip);
-        if($name === false){
+        if ($name === false){
             $export = false;
             return false;
-        }else{
+        } else {
             $export = true;
             return $name;
         }
-    }else{
+    } else {
         Display::display_error_message(get_lang('ErrorMsgSpecialExport')); //main API
         $export = false;
         return false;

+ 9 - 8
main/admin/subscribe_user2course.php

@@ -1,5 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
 *	This script allows platform admins to add users to courses.
 *	It displays a list of users and a list of courses;
@@ -65,8 +66,8 @@ if (is_array($extra_field_list)) {
 /* React on POSTed request */
 if (isset($_POST['form_sent']) && $_POST['form_sent']) {
     $form_sent = $_POST['form_sent'];
-    $users = is_array($_POST['UserList']) ? $_POST['UserList'] : array() ;
-    $courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array() ;
+    $users = isset($_POST['UserList']) && is_array($_POST['UserList']) ? $_POST['UserList'] : array() ;
+    $courses = isset($_POST['CourseList']) && is_array($_POST['CourseList']) ? $_POST['CourseList'] : array() ;
     $first_letter_user = $_POST['firstLetterUser'];
     $first_letter_course = $_POST['firstLetterCourse'];
 
@@ -207,13 +208,13 @@ $sql = "SELECT code,visual_code,title
         ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
 
 if (api_is_multiple_url_enabled()) {
-    $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+    $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
     $access_url_id = api_get_current_access_url_id();
     if ($access_url_id != -1){
         $sql = "SELECT code, visual_code, title
                 FROM $tbl_course as course
                 INNER JOIN $tbl_course_rel_access_url course_rel_url
-                ON (course_rel_url.course_code= course.code)
+                ON (course_rel_url.c_id = course.id)
                 WHERE
                     access_url_id =  $access_url_id  AND
                     (visual_code LIKE '".$first_letter_course."%' )
@@ -226,19 +227,19 @@ $db_courses = Database::store_result($result);
 unset($result);
 
 if (api_is_multiple_url_enabled()) {
-    $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
+    $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
     $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
     $access_url_id = api_get_current_access_url_id();
     if ($access_url_id != -1){
         $sqlNbCours = "	SELECT course_rel_user.course_code, course.title
             FROM $tbl_course_user as course_rel_user
             INNER JOIN $tbl_course as course
-            ON course.code = course_rel_user.course_code
+            ON course.id = course_rel_user.c_id
             INNER JOIN $tbl_course_rel_access_url course_rel_url
-            ON (course_rel_url.course_code= course.code)
+            ON (course_rel_url.c_id = course.id)
             WHERE
                 access_url_id =  $access_url_id  AND
-                course_rel_user.user_id='".$_user['user_id']."' AND
+                course_rel_user.user_id='".api_get_user_id()."' AND
                 course_rel_user.status='1'
             ORDER BY course.title";
     }

+ 3 - 3
main/admin/teacher_time_report.php

@@ -80,10 +80,10 @@ if (!empty($selectedCourse)) {
         );
     }
 
-    $sessionsByCourse = SessionManager::get_session_by_course($selectedCourse);
+    $sessionsByCourse = SessionManager::get_session_by_course($course['real_id']);
 
     foreach ($sessionsByCourse as $session) {
-        $coaches = CourseManager::get_coachs_from_course($session['id'], $selectedCourse);
+        $coaches = CourseManager::get_coachs_from_course($session['id'], $course['real_id']);
 
         if ($coaches) {
             foreach ($coaches as $coach) {
@@ -138,7 +138,7 @@ if (!empty($selectedSession)) {
             'name' => $course['title']
         );
 
-        $coaches = CourseManager::get_coachs_from_course($selectedSession, $course['code']);
+        $coaches = CourseManager::get_coachs_from_course($selectedSession, $course['id']);
 
         if ($coaches) {
             foreach ($coaches as $coach) {

+ 2 - 4
main/admin/user_add.php

@@ -339,7 +339,8 @@ if( $form->validate()) {
             $hr_dept_id,
             $extra,
             null,
-            $send_mail
+            $send_mail,
+			$platform_admin
         );
 
 		Security::clear_token();
@@ -379,9 +380,6 @@ if( $form->validate()) {
 			foreach ($extra as $key => $value) {
 				UserManager::update_extra_field_value($user_id, $key, $value);
 			}
-			if ($platform_admin) {
-                UserManager::add_user_as_admin($user_id);
-			}
 			$message = get_lang('UserAdded');
 		}
 		if (isset($user['submit_plus'])) {

+ 8 - 21
main/admin/user_edit.php

@@ -97,7 +97,12 @@ $extra_data = UserManager :: get_extra_user_data($user_id, true);
 $user_data = array_merge($user_data, $extra_data);
 
 // Create the form
-$form = new FormValidator('user_edit', 'post', '', '', array('style' => 'width: 60%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
+$form = new FormValidator(
+    'user_edit',
+    'post',
+    '',
+    ''
+);
 $form->addElement('header', '', $tool_name);
 $form->addElement('hidden', 'user_id', $user_id);
 
@@ -131,7 +136,7 @@ $form->applyFilter('official_code', 'html_filter');
 $form->applyFilter('official_code', 'trim');
 
 // Email
-$form->addElement('text', 'email', get_lang('Email'), array('size' => '40'));
+$form->addElement('text', 'email', get_lang('Email'));
 $form->addRule('email', get_lang('EmailWrong'), 'email');
 if (api_get_setting('registration', 'email') == 'true') {
     $form->addRule('email', get_lang('EmailWrong'), 'required');
@@ -144,7 +149,7 @@ if (api_get_setting('login_is_email') == 'true') {
 
 // OpenID
 if (api_get_setting('openid_authentication') == 'true') {
-	$form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => '40'));
+	$form->addElement('text', 'openid', get_lang('OpenIDURL'));
 }
 
 // Phone
@@ -159,7 +164,6 @@ if (strlen($user_data['picture_uri']) > 0) {
 }
 
 // Username
-
 if (api_get_setting('login_is_email') != 'true') {
     $form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH));
     $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
@@ -220,23 +224,6 @@ $form->addElement(
 
 $display = isset($user_data['status']) && ($user_data['status'] == STUDENT || (isset($_POST['status']) && $_POST['status'] == STUDENT)) ? 'block' : 'none';
 
-/*
-$form->addElement('html', '<div id="drh_list" style="display:'.$display.';">');
-$drh_select = $form->addElement('select', 'hr_dept_id', get_lang('Drh'), array(), 'id="drh_select"');
-$drh_list = UserManager :: get_user_list(array('status' => DRH), api_sort_by_first_name() ? array('firstname', 'lastname') : array('lastname', 'firstname'));
-
-if (count($drh_list) == 0) {
-	$drh_select->addOption('- '.get_lang('ThereIsNotStillAResponsible', '').' -', 0);
-} else {
-	$drh_select->addOption('- '.get_lang('SelectAResponsible').' -', 0);
-}
-
-foreach($drh_list as $drh) {
-	$drh_select->addOption(api_get_person_name($drh['firstname'], $drh['lastname']), $drh['user_id']);
-}
-$form->addElement('html', '</div>');
-*/
-
 // Platform admin
 if (api_is_platform_admin()) {
 	$group = array();

+ 13 - 5
main/admin/user_export.php

@@ -31,9 +31,10 @@ if (api_is_multiple_url_enabled()) {
 	$tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
 	$access_url_id = api_get_current_access_url_id();
 	if ($access_url_id != -1){
-	$sql = "SELECT code,visual_code,title FROM $course_table as c
+	$sql = "SELECT code,visual_code,title
+		FROM $course_table as c
 		INNER JOIN $tbl_course_rel_access_url as course_rel_url
-		ON (c.code = course_rel_url.course_code)
+		ON (c.id = course_rel_url.c_id)
 		WHERE access_url_id = $access_url_id
 		ORDER BY visual_code";
 	}
@@ -59,6 +60,8 @@ if ($form->validate()) {
 	$export = $form->exportValues();
 	$file_type = $export['file_type'];
 	$course_code = Database::escape_string($export['course_code']);
+	$courseInfo = api_get_course_info($course_code);
+	$courseId = $courseInfo['real_id'];
 
 	$sql = "SELECT  u.user_id 	AS UserId,
 					u.lastname 	AS LastName,
@@ -71,7 +74,12 @@ if ($form->validate()) {
 					u.official_code	AS OfficialCode,
 					u.phone		AS Phone";
 	if (strlen($course_code) > 0) {
-		$sql .= " FROM $user_table u, $course_user_table cu WHERE u.user_id = cu.user_id AND course_code = '$course_code' AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH." ORDER BY lastname,firstname";
+		$sql .= " FROM $user_table u, $course_user_table cu
+					WHERE
+						u.user_id = cu.user_id AND
+						cu.c_id = '$courseId' AND
+						cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
+					ORDER BY lastname,firstname";
 		$filename = 'export_users_'.$course_code.'_'.date('Y-m-d_H-i-s');
 	} else {
 		global $_configuration;
@@ -119,11 +127,11 @@ if ($form->validate()) {
 
 	switch($file_type) {
 		case 'xml':
-			Export::export_table_xml($data,$filename,'Contact','Contacts');
+			Export::arrayToXml($data, $filename, 'Contact', 'Contacts');
 			exit;
 			break;
 		case 'csv':
-			Export::export_table_csv($data,$filename);
+			Export::arrayToCsv($data,$filename);
 			exit;
 			break;
 	}

+ 1 - 1
main/admin/user_import.php

@@ -247,7 +247,7 @@ function save_data($users)
  */
 function parse_csv_data($file)
 {
-    $users = Import :: csv_to_array($file);
+    $users = Import :: csvToArray($file);
     foreach ($users as $index => $user) {
         if (isset ($user['Courses'])) {
             $user['Courses'] = explode('|', trim($user['Courses']));

+ 13 - 11
main/admin/user_information.php

@@ -154,12 +154,11 @@ if (count($sessions) > 0) {
 
         $csvContent[] = array($session_item['session_name']);
         $csvContent[] = $headerList;
-
         foreach ($session_item['courses'] as $my_course) {
             $courseInfo = api_get_course_info($my_course['code']);
             $sessionStatus = SessionManager::get_user_status_in_session(
                 $user['user_id'],
-                $my_course['code'],
+                $courseInfo['real_id'],
                 $id_session
             );
             $status = null;
@@ -258,9 +257,11 @@ $courseToolInformationTotal = null;
 /**
  * Show the courses in which this user is subscribed
  */
-$sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c'.
-    ' WHERE cu.user_id = '.$user['user_id'].' AND cu.course_code = c.code '.
-    ' AND cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
+$sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c
+        WHERE
+            cu.user_id = '.$user['user_id'].' AND
+            cu.c_id = c.id AND
+            cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
 $res = Database::query($sql);
 if (Database::num_rows($res) > 0) {
     $header = array(
@@ -283,14 +284,15 @@ if (Database::num_rows($res) > 0) {
     $data = array();
     $courseToolInformationTotal = null;
     while ($course = Database::fetch_object($res)) {
-        $courseInfo = api_get_course_info($course->code);
+        $courseInfo = api_get_course_info_by_id($course->c_id);
+        $courseCode = $courseInfo['code'];
         $courseToolInformation = null;
 
-        $tools = '<a href="course_information.php?code='.$course->code.'">'.Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
+        $tools = '<a href="course_information.php?code='.$courseCode.'">'.Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
             '<a href="'.api_get_path(WEB_COURSE_PATH).$course->directory.'">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>' .
-            '<a href="course_edit.php?course_code='.$course->code.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
+            '<a href="course_edit.php?course_code='.$courseCode.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
         if ($course->status == STUDENT) {
-            $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$course->code.'&user_id='.$user['user_id'].'">'.
+            $tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseCode.'&user_id='.$user['user_id'].'">'.
                 Display::return_icon('delete.png', get_lang('Delete')).'</a>';
         }
 
@@ -309,7 +311,7 @@ if (Database::num_rows($res) > 0) {
         );
 
         $row = array(
-            Display::url($course->code, $courseInfo['course_public_url']),
+            Display::url($courseCode, $courseInfo['course_public_url']),
             $course->title,
             $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher'),
             $timeSpent,
@@ -391,7 +393,7 @@ if (isset($_GET['action'])) {
             }
             break;
         case 'export':
-            Export :: export_table_csv_utf8($csvContent, 'user_information_'.$user);
+            Export :: arrayToCsv($csvContent, 'user_information_'.$user);
             exit;
             break;
     }

+ 15 - 13
main/admin/user_move_stats.php

@@ -5,6 +5,7 @@
  * User move script (to move between courses and sessions)
  * @package chamilo.admin
  */
+
 $cidReset = true;
 require_once '../inc/global.inc.php';
 $this_section=SECTION_PLATFORM_ADMIN;
@@ -359,8 +360,8 @@ if (isset($_REQUEST['load_ajax'])) {
                                     $created_dir = '/'.$created_dir;
                                     $now = api_get_utc_datetime();
                                     //Creating directory
-                                    $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET " .
-                                        "url         = '".$created_dir."',
+                                    $sql_add_publication = "INSERT INTO " . $TBL_STUDENT_PUBLICATION . " SET
+                                           url         = '".$created_dir."',
 	                                       c_id        = $course_id,
 	                                       title        = '".$parent_data['title']."',
 	                                       description  = '".$parent_data['description']." folder_moved_from_session_id_$origin_session_id ',
@@ -581,15 +582,16 @@ $htmlHeadXtra[] = '<script type="text/javascript">
  </script>';
 
 function get_courses_list_by_user_id_based_in_exercises($user_id) {
-    $TABLETRACK_EXERCICES       = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
+    $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
     $user_id = intval($user_id);
-    //$sql = "SELECT DISTINCT exe_user_id, c_id, session_id as id_session FROM $TABLETRACK_EXERCICES WHERE exe_user_id = $user_id GROUP BY exe_user_id, c_id ORDER by exe_user_id, c_id ASC";
-    $sql = "SELECT DISTINCT exe_user_id, c_id, session_id as id_session
-            FROM $TABLETRACK_EXERCICES WHERE exe_user_id = $user_id ORDER by exe_user_id, c_id ASC";
+    $sql = "SELECT DISTINCT exe_user_id, c_id, session_id
+            FROM $TABLETRACK_EXERCICES
+            WHERE exe_user_id = $user_id
+            ORDER by exe_user_id, c_id ASC";
 
     $res = Database::query($sql);
     $course_list = array();
-    while($row = Database::fetch_array($res,'ASSOC')) {
+    while ($row = Database::fetch_array($res,'ASSOC')) {
         $course_list []= $row;
     }
     return $course_list;
@@ -641,7 +643,7 @@ foreach ($session_list as $session_data) {
 $combinations = array();
 
 if (!empty($user_list)) {
-    foreach ($user_list  as $user) {
+    foreach ($user_list as $user) {
         $user_id = $user['user_id'];
         $name = $user['firstname'].' '.$user['lastname'];
         $course_list_registered = CourseManager::get_courses_list_by_user_id(
@@ -652,22 +654,22 @@ if (!empty($user_list)) {
 
         $new_course_list = array();
         foreach ($course_list_registered as $course_reg) {
-            if (empty($course_reg['id_session'])) {
-                $course_reg['id_session'] = 0;
+            if (empty($course_reg['session_id'])) {
+                $course_reg['session_id'] = 0;
             }
             // Recover the code for historical reasons. If it can be proven
             // that the code can be safely replaced by c_id in the following
             // PHP code, feel free to do so
-            $courseInfo = api_get_course_info_by_id($course_reg['c_id']);
+            $courseInfo = api_get_course_info_by_id($course_reg['real_id']);
             $course_reg['code'] = $courseInfo['code'];
-            $new_course_list[] = $course_reg['code'].'_'.$course_reg['id_session'];
+            $new_course_list[] = $course_reg['code'].'_'.$course_reg['session_id'];
         }
 
         $course_list = get_courses_list_by_user_id_based_in_exercises($user_id);
 
         if (is_array($course_list) && !empty($course_list)) {
             foreach ($course_list as $my_course) {
-                $key = $my_course['code'].'_'.$my_course['id_session'];
+                $key = $my_course['code'].'_'.$my_course['session_id'];
 
                 if (!in_array($key, $new_course_list)) {
                     $my_course['not_registered'] = 1;

+ 1 - 1
main/admin/user_update_import.php

@@ -244,7 +244,7 @@ function updateUsers($users)
  */
 function parse_csv_data($file)
 {
-    $users = Import :: csv_to_array($file);
+    $users = Import :: csvToArray($file);
     foreach ($users as $index => $user) {
         if (isset ($user['Courses'])) {
             $user['Courses'] = explode('|', trim($user['Courses']));

+ 1 - 1
main/admin/usergroup_export.php

@@ -28,7 +28,7 @@ if ($form->validate()) {
     $data = $userGroup->getDataToExport();
     $data = array_merge($header, $data);
     $filename = 'export_classes_'.api_get_local_time();
-    Export::export_table_csv($data, $filename);
+    Export::arrayToCsv($data, $filename);
     exit;
 }
 

+ 1 - 1
main/admin/usergroup_import.php

@@ -103,7 +103,7 @@ $form->addGroup($group, '', get_lang('FileType'), '<br/>');
 $form->addButtonImport(get_lang('Import'));
 
 if ($form->validate()) {
-    $classes = Import::csv_to_array($_FILES['import_file']['tmp_name']);
+    $classes = Import::csvToArray($_FILES['import_file']['tmp_name']);
     $errors = validate_data($classes);
     if (count($errors) == 0) {
         $number_of_added_classes = save_data($classes);

+ 1 - 1
main/admin/usergroup_user_import.php

@@ -118,7 +118,7 @@ function save_data($users_classes, $deleteUsersNotInList = false) {
  * @return array All course-information read from the file
  */
 function parse_csv_data($file) {
-    $courses = Import::csv_to_array($file);
+    $courses = Import::csvToArray($file);
     return $courses;
 }
 $cidReset = true;

+ 0 - 2
main/admin/usergroups.php

@@ -104,9 +104,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'add') {
     // Setting the form elements
     $form->addElement('header', get_lang('Add'));
     $form->addElement('text', 'name', get_lang('Name'), array('size' => '70', 'id' => 'name'));
-    //$form->applyFilter('note_title', 'html_filter');
     $form->addHtmlEditor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
-    //$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
     $form->addButtonCreate(get_lang('Add'));
 
     // Setting the rules

+ 0 - 41
main/announcements/announcements.php

@@ -411,47 +411,6 @@ switch ($action) {
 if (!empty($_GET['remind_inactive'])) {
     $to[] = 'USER:'.intval($_GET['remind_inactive']);
 }
-/*
-if (api_is_allowed_to_edit(false,true) OR
-    (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
-) {
-
-    //
-    if (!empty($_GET['action']) and $_GET['action']=='modify' AND isset($_GET['id'])) {
-        if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
-            api_not_allowed();
-        }
-
-        // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
-        $id = intval($_GET['id']);
-
-        if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
-            $sql = "SELECT * FROM  $tbl_announcement WHERE c_id = $course_id AND id = '$id'";
-            $rs 	= Database::query($sql);
-            $myrow  = Database::fetch_array($rs);
-            $last_id = $id;
-            $userUpload = isset($_FILES['user_upload']) ? $_FILES['user_upload'] : null;
-            $edit_attachment = AnnouncementManager::edit_announcement_attachment_file(
-                $last_id,
-                $userUpload,
-                $file_comment
-            );
-
-            if ($myrow) {
-                $announcement_to_modify 	= $myrow['id'];
-                $content_to_modify 			= $myrow['content'];
-                $title_to_modify 			= $myrow['title'];
-
-                if ($originalresource!=="no")  {
-                    $to = AnnouncementManager::load_edit_users("announcement", $announcement_to_modify);
-                }
-                $display_announcement_list = false;
-            }
-        }
-    }
-}*/
-
-$htmlHeadXtra[] = AnnouncementManager::to_javascript();
 
 if (!empty($group_id)) {
     $group_properties  = GroupManager :: get_group_properties($group_id);

+ 2 - 1
main/attendance/attendance_controller.php

@@ -179,6 +179,7 @@ class AttendanceController
     public function attendanceSetVisible($attendanceId)
     {
         $attendance = new Attendance();
+        $affectedRows = null;
         if (!empty($attendanceId)) {
             $affectedRows = $attendance->changeVisibility($attendanceId, 1);
         }
@@ -289,7 +290,7 @@ class AttendanceController
             }
 
             if (api_is_allowed_to_edit(null, true) ||
-                api_is_coach(api_get_session_id(), api_get_course_id()) ||
+                api_is_coach(api_get_session_id(), api_get_course_int_id()) ||
                 $isDrhOfCourse
             ) {
                 $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id);

+ 1 - 1
main/attendance/attendance_sheet.php

@@ -17,7 +17,7 @@ $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
 );
 
 if (api_is_allowed_to_edit(null, true) ||
-    api_is_coach(api_get_session_id(), api_get_course_id()) ||
+    api_is_coach(api_get_session_id(), api_get_course_int_id()) ||
     $isDrhOfCourse
 ) {
     $param_gradebook = '';

+ 12 - 12
main/auth/cas/authcas.php

@@ -16,7 +16,7 @@ require_once(api_get_path(SYS_PATH).'main/auth/external_login/functions.inc.php'
 *
 **/
 function cas_configured() {
-	global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri; 
+	global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
     $res = false;
     if (!empty($cas_auth_ver) && !empty($cas_auth_server) && !empty($cas_auth_port)) {
         $res = true;
@@ -33,7 +33,7 @@ function cas_configured() {
 
 function cas_is_authenticated()
 {
-	global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri; 
+	global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
 	global $PHPCAS_CLIENT;
 	global $logout;
 
@@ -42,13 +42,13 @@ function cas_is_authenticated()
     }
 
 
-	if (!is_object($PHPCAS_CLIENT) ) 
+	if (!is_object($PHPCAS_CLIENT) )
 	{
 		phpCAS::client($cas_auth_ver,$cas_auth_server,$cas_auth_port,$cas_auth_uri);
 		phpCAS::setNoCasServerValidation();
 	}
-	$auth = phpCAS::checkAuthentication(); 
-  
+	$auth = phpCAS::checkAuthentication();
+
 	if ($auth) {
 		$login= trim(phpCAS::getUser());
 		/*
@@ -85,7 +85,7 @@ function cas_is_authenticated()
 		if (!$logout){
 		    // get user info from username
 		    $tab_user_info = UserManager::get_user_info($login);
-		    
+
 		    // user found in the chamilo database
 		    if (is_array($tab_user_info)) {
 		        // if option is on we update user automatically from ldap server
@@ -105,13 +105,13 @@ function cas_is_authenticated()
 		        // if option is on we can ADD user automatically from ldap server or by modify own profil
 		        $user_added = false;
 		        switch (api_get_setting("cas_add_user_activate")) {
-		            case PLATFORM_AUTH_SOURCE : 
+		            case PLATFORM_AUTH_SOURCE :
 		                // user will have to modify firstname, lastname, email in chamilo profil edit
 		                $userdata = get_lang("EditInProfil");
           				UserManager::create_user($userdata, $userdata, '5', $userdata, $login, 'casplaceholder', '','','','',CAS_AUTH_SOURCE);
           				$user_added = $login;
 		                break;
-		            case LDAP_AUTH_SOURCE : 
+		            case LDAP_AUTH_SOURCE :
 		                // user info are read from ldap connexion
 	                    // get user info from ldap server
 	                    // user has already been authenticated by CAS
@@ -137,8 +137,8 @@ function cas_is_authenticated()
 //				"FROM $user_table ".
 //				"WHERE username = '$login' ";
 //
-//			$result = api_sql_query($sql,__FILE__,__LINE__);
-//			if(mysql_num_rows($result) == 0) { 
+//			$result = Database::query($sql,__FILE__,__LINE__);
+//			if(mysql_num_rows($result) == 0) {
 //				require_once(api_get_path(SYS_PATH).'main/inc/lib/usermanager.lib.php');
 //				$rnumber=rand(0,256000);
 //				UserManager::create_user($firstName, $lastName, $status, $email, $login, md5('casplaceholder'.$rnumber), $official_code='',$language='',$phone='',$picture_uri='',$auth_source = PLATFORM_AUTH_SOURCE);
@@ -153,8 +153,8 @@ function cas_is_authenticated()
 //		}
 		return $login;
 	}
-	else 
-	{ 
+	else
+	{
 		return false;
 	}
 }

+ 4 - 1
main/auth/courses_controller.php

@@ -245,7 +245,10 @@ class CoursesController
      */
     public function change_course_category($course_code, $category_id)
     {
-        $result = $this->model->store_changecoursecategory($course_code, $category_id);
+        $courseInfo = api_get_course_info($course_code);
+        $courseId = $courseInfo['real_id'];
+
+        $result = $this->model->updateCourseCategory($courseId, $category_id);
         $message = '';
         if ($result) {
             $message = get_lang('EditCourseCategorySucces');

+ 1 - 1
main/auth/inscription.php

@@ -30,7 +30,7 @@ if (!empty($_SESSION['user_language_choice'])) {
 } elseif (!empty($_SESSION['_user']['language'])) {
     $user_selected_language = $_SESSION['_user']['language'];
 } else {
-    $user_selected_language = get_setting('platformLanguage');
+    $user_selected_language = api_get_setting('platformLanguage');
 }
 
 $form = new FormValidator('registration');

+ 13 - 14
main/auth/ldap/authldap.php

@@ -426,9 +426,9 @@ function ldap_get_number_of_users() {
  * @author    Mustapha Alouani
  */
 function ldap_get_user_data($from, $number_of_items, $column, $direction) {
-    
+
     global $extldap_user_correspondance;
-    
+
     $users = array();
     $is_western_name_order = api_is_western_name_order();
     if (isset($_GET['submit'])) {
@@ -554,40 +554,39 @@ function ldap_add_user_to_session($UserList, $id_session) {
 
     $id_session = (int) $id_session;
     // Once users are imported in the users base, we can assign them to the session
-    $result=Database::query("SELECT course_code FROM $tbl_session_rel_course " .
-            "WHERE id_session='$id_session'");
+    $result=Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id ='$id_session'");
     $CourseList=array();
     while ($row=Database::fetch_array($result)) {
-        $CourseList[]=$row['course_code'];
+        $CourseList[]=$row['c_id'];
     }
     foreach ($CourseList as $enreg_course) {
         foreach ($UserList as $enreg_user) {
             $enreg_user = (int) $enreg_user;
             Database::query("INSERT IGNORE ".
               " INTO $tbl_session_rel_course_rel_user ".
-              "(id_session,course_code,id_user) VALUES ".
+              "(session_id,c_id,user_id) VALUES ".
               "('$id_session','$enreg_course','$enreg_user')");
         }
-        $sql = "SELECT COUNT(id_user) as nbUsers ".
+        $sql = "SELECT COUNT(user_id) as nbUsers ".
                " FROM $tbl_session_rel_course_rel_user " .
-               " WHERE id_session='$id_session' ".
-               " AND course_code='$enreg_course'";
+               " WHERE session_id='$id_session' ".
+               " AND c_id='$enreg_course'";
         $rs = Database::query($sql);
         list($nbr_users) = Database::fetch_array($rs);
         Database::query("UPDATE $tbl_session_rel_course  ".
                " SET nbr_users=$nbr_users " .
-               " WHERE id_session='$id_session' ".
-               " AND course_code='$enreg_course'");
+               " WHERE session_id='$id_session' ".
+               " AND c_id='$enreg_course'");
     }
     foreach ($UserList as $enreg_user) {
         $enreg_user = (int) $enreg_user;
         Database::query("INSERT IGNORE INTO $tbl_session_rel_user ".
-               " (id_session, id_user) " .
+               " (session_id, user_id) " .
                " VALUES('$id_session','$enreg_user')");
     }
     // We update the number of users in the session
-    $sql = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_user ".
-           " WHERE id_session='$id_session' ".
+    $sql = "SELECT COUNT(user_id) as nbUsers FROM $tbl_session_rel_user ".
+           " WHERE session_id='$id_session' ".
            " AND relation_type<>".SESSION_RELATION_TYPE_RRHH." ";
     $rs = Database::query($sql);
     list($nbr_users) = Database::fetch_array($rs);

+ 10 - 10
main/auth/shibboleth/app/shibboleth.class.php

@@ -98,7 +98,7 @@ class Shibboleth
             /*
              * Tests if the user tried to login directly in a protected course before to come here
              * (this variable could be set in the modified code of /chamilo/inc/lib/main_api.lib.php)
-             * 
+             *
              * Note:
              *       this part was added to give the possibility to access Chamilo directly on a course URL from a link diplayed in a portal.
              *       This is not a direct Shibboleth related functionnality, but this could be used in a shibbolethized
@@ -109,7 +109,7 @@ class Shibboleth
              */
         }
         if ($url) {
-            //needed to log the user in his courses. Normally it is done by visiting /chamilo/index.php    
+            //needed to log the user in his courses. Normally it is done by visiting /chamilo/index.php
 //            $include_path = api_get_path(INCLUDE_PATH);
 //            require("$include_path/local.inc.php");
 //
@@ -160,7 +160,7 @@ class Shibboleth
     /**
      * Infer the rights/status the user can have in Chamilo based on his affiliation attribute
      *
-     * @param  ShibbolethUser $user      
+     * @param  ShibbolethUser $user
      * @return The Chamilo user status, one of TEACHER, STUDENT or UNKNOWN
      */
     public static function infer_user_status($user)
@@ -200,9 +200,9 @@ class Shibboleth
     /**
      * Return true if the user can ask for a greater status than student.
      * This happens for staff members.
-     * 
+     *
      * @param ShibbolethUser $user
-     * @return boolean 
+     * @return boolean
      */
     public static function infer_status_request($user)
     {
@@ -242,9 +242,9 @@ class Shibboleth
 
         $signagure = <<<EOT
 
-_________________________ 
-$firstname $lastname 
-$email 
+_________________________
+$firstname $lastname
+$email
 $status
 EOT;
 
@@ -257,9 +257,9 @@ EOT;
             $header .= "Cc: $shibb_admin_email";
         }
 
-        $administrator_email = get_setting('emailAdministrator');
+        $administrator_email = api_get_setting('emailAdministrator');
         $result = mail($administrator_email, $subject, $message);
         return (bool) $result;
     }
 
-}
+}

+ 3 - 3
main/auth/shibboleth/db/shibboleth_upgrade.class.php

@@ -64,7 +64,7 @@ class ShibbolethUpgrade
     }
 
     public static function create_shibb_persistent_id_field_if_missing()
-    {        
+    {
         $db_name = Database :: get_main_database();
 
         $sql = "SELECT * FROM $db_name.user LIMIT 1";
@@ -78,8 +78,8 @@ class ShibbolethUpgrade
         }
 
         $sql = "ALTER table $db_name.user ADD COLUMN shibb_persistent_id varchar(255) NULL DEFAULT NULL;";
-        $result = api_sql_query($sql);
+        $result = Database::query($sql);
         return (bool) $result;
     }
 
-}
+}

+ 4 - 5
main/auth/shibboleth/lib/shibboleth_session.class.php

@@ -2,10 +2,9 @@
 
 namespace Shibboleth;
 
-use \ChamiloSession as Session;
-use \Chamilo;
-use \Database;
-use \Redirect;
+use Chamilo;
+use ChamiloSession as Session;
+use Database;
 
 
 /**
@@ -57,7 +56,7 @@ class ShibbolethSession
         /* This must be set for local.inc.php to register correctly the global variables in session
          * This is BAD. Logic should be migrated into a function and stop relying on global variables.
          */
-        global $_uid, $is_allowedCreateCourse, $is_platformAdmin, $_real_cid, $_courseUser, $is_courseAdmin;
+        global $_uid, $is_allowedCreateCourse, $is_platformAdmin, $_real_cid, $is_courseAdmin;
         global $is_courseMember, $is_courseTutor, $is_courseCoach, $is_allowed_in_course, $is_sessionAdmin, $_gid;
         $_uid = $uid;
 

+ 19 - 20
main/blog/blog.php

@@ -34,11 +34,11 @@ $action = isset($_GET['action']) ? $_GET['action'] : null;
 	PROCESSING
 */
 
-$safe_post_file_comment = isset($_GET['post_file_comment']) ? Security::remove_XSS($_POST['post_file_comment']) : null;
-$safe_comment_text      = isset($_GET['comment_text']) ? Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['comment_text'])), COURSEMANAGERLOWSECURITY) : null;
-$safe_comment_title     = isset($_GET['comment_title']) ? Security::remove_XSS($_POST['comment_title']) : null;
-$safe_task_name         = isset($_GET['task_name']) ? Security::remove_XSS($_POST['task_name']) : null;
-$safe_task_description  = isset($_GET['task_description']) ? Security::remove_XSS($_POST['task_description']) : null;
+$safe_post_file_comment = isset($_POST['post_file_comment']) ? Security::remove_XSS($_POST['post_file_comment']) : null;
+$safe_comment_text      = isset($_POST['comment_text']) ? Security::remove_XSS(stripslashes(api_html_entity_decode($_POST['comment_text'])), COURSEMANAGERLOWSECURITY) : null;
+$safe_comment_title     = isset($_POST['comment_title']) ? Security::remove_XSS($_POST['comment_title']) : null;
+$safe_task_name         = isset($_POST['task_name']) ? Security::remove_XSS($_POST['task_name']) : null;
+$safe_task_description  = isset($_POST['task_description']) ? Security::remove_XSS($_POST['task_description']) : null;
 
 if (!empty($_POST['new_post_submit'])) {
 	Blog:: create_post(
@@ -72,6 +72,7 @@ if (!empty($_POST['new_comment_submit'])) {
 }
 
 if (!empty($_POST['new_task_submit'])) {
+
 	Blog:: create_task(
 		$blog_id,
 		$safe_task_name,
@@ -106,7 +107,7 @@ if (!empty($_POST['assign_task_submit'])) {
 		$blog_id,
 		$_POST['task_user_id'],
 		$_POST['task_task_id'],
-		$_POST['task_year'] . "-" . $_POST['task_month'] . "-" . $_POST['task_day']
+		$_POST['task_day']
 	);
 	$return_message = array(
 		'type' => 'confirmation',
@@ -119,7 +120,7 @@ if (isset($_POST['assign_task_edit_submit'])) {
 		$blog_id,
 		$_POST['task_user_id'],
 		$_POST['task_task_id'],
-		$_POST['task_year'] . "-" . $_POST['task_month'] . "-" . $_POST['task_day'],
+		$_POST['task_day'],
 		$_POST['old_user_id'],
 		$_POST['old_task_id'],
 		$_POST['old_target_date']
@@ -219,9 +220,8 @@ if (isset($_GET['action']) && $_GET['action'] == 'view_post') {
 /*
 	DISPLAY
 */
-$htmlHeadXtra[] = '<script src="tbl_change.js" type="text/javascript"></script>';
 
-// Set bredcrumb
+// Set breadcrumb
 switch ($action) {
 	case 'new_post' :
 		$nameTools = get_lang('NewPost');
@@ -426,20 +426,19 @@ switch ($action) {
 		break;
 	case 'manage_tasks' :
 		if (api_is_allowed('BLOG_'.$blog_id, 'task_management')) {
-			if (isset($_GET['do']) && $_GET['do'] == 'add')
-			{
-				Blog :: display_new_task_form($blog_id);
+			if (isset($_GET['do']) && $_GET['do'] == 'add') {
+				Blog:: display_new_task_form($blog_id);
 			}
-			if (isset($_GET['do']) && $_GET['do'] == 'assign')
-			{
-				Blog :: display_assign_task_form($blog_id);
+			if (isset($_GET['do']) && $_GET['do'] == 'assign') {
+				Blog:: display_assign_task_form($blog_id);
 			}
-			if (isset($_GET['do']) && $_GET['do'] == 'edit')
-			{
-				Blog :: display_edit_task_form($blog_id, intval($_GET['task_id']));
+			if (isset($_GET['do']) && $_GET['do'] == 'edit') {
+				Blog:: display_edit_task_form(
+					$blog_id,
+					intval($_GET['task_id'])
+				);
 			}
-			if (isset($_GET['do']) && $_GET['do'] == 'edit_assignment')
-			{
+			if (isset($_GET['do']) && $_GET['do'] == 'edit_assignment') {
 				Blog :: display_edit_assigned_task_form($blog_id, intval($_GET['task_id']), intval($_GET['user_id']));
 			}
 			Blog :: display_task_list($blog_id);

+ 0 - 136
main/blog/calendar.php

@@ -1,136 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Blog calendar
- * @package chamilo.blogs
- */
-/**
- * Code
- */
-
-// including the global
-require_once '../inc/global.inc.php';
-
-// the variables for the days and the months
-// Defining the shorts for the days
-$DaysShort = api_get_week_days_short();
-// Defining the days of the week to allow translation of the days
-$DaysLong = api_get_week_days_long();
-// Defining the months of the year to allow translation of the months
-$MonthsLong = api_get_months_long();
-
-?>
-<html>
-<head>
-<title>Calendar</title>
-
-<style type="text/css">
-table.calendar
-{
-	width: 100%;
-	font-size: 11px;
-	font-family: verdana, arial, helvetica, sans-serif;
-}
-table.calendar .monthyear
-{
-	background-color: #4171B5;
-	text-align: center;
-	color: #ffffff;
-}
-table.calendar .daynames
-{
-	background-color: #D3DFF1;
-	text-align: center;
-}
-table.calendar td
-{
-	width: 25px;
-	height: 25px;
-	background-color: #f5f5f5;
-	text-align: center;
-}
-table.calendar td.selected
-{
-	border: 1px solid #ff0000;
-	background-color: #FFCECE;
-}
-table.calendar td a
-{
-	width: 25px;
-	height: 25px;
-	text-decoration: none;
-}
-table.calendar td a:hover
-{
-	background-color: #ffff00;
-}
-table.calendar .monthyear a
-{
-	text-align: center;
-	color: #ffffff;
-}
-table.calendar .monthyear a:hover
-{
-	text-align: center;
-	color: #ff0000;
-	background-color: #ffff00;
-}
-</style>
-<script type="text/javascript">
-<!--
-    /* added 2004-06-10 by Michael Keck
-     *       we need this for Backwards-Compatibility and resolving problems
-     *       with non DOM browsers, which may have problems with css 2 (like NC 4)
-    */
-    var isDOM      = (typeof(document.getElementsByTagName) != 'undefined'
-                      && typeof(document.createElement) != 'undefined')
-                   ? 1 : 0;
-    var isIE4      = (typeof(document.all) != 'undefined'
-                      && parseInt(navigator.appVersion) >= 4)
-                   ? 1 : 0;
-    var isNS4      = (typeof(document.layers) != 'undefined')
-                   ? 1 : 0;
-    var capable    = (isDOM || isIE4 || isNS4)
-                   ? 1 : 0;
-    // Uggly fix for Opera and Konqueror 2.2 that are half DOM compliant
-    if (capable) {
-        if (typeof(window.opera) != 'undefined') {
-            var browserName = ' ' + navigator.userAgent.toLowerCase();
-            if ((browserName.indexOf('konqueror 7') == 0)) {
-                capable = 0;
-            }
-        } else if (typeof(navigator.userAgent) != 'undefined') {
-            var browserName = ' ' + navigator.userAgent.toLowerCase();
-            if ((browserName.indexOf('konqueror') > 0) && (browserName.indexOf('konqueror/3') == 0)) {
-                capable = 0;
-            }
-        } // end if... else if...
-    } // end if
-//-->
-</script>
-<script type="text/javascript" src="tbl_change.js"></script>
-<script type="text/javascript">
-<!--
-var month_names = new Array(
-<?php
-foreach($MonthsLong as $index => $month){
-	echo '"'.$month.'",';
-}
-?>
-"");
-var day_names = new Array(
-<?php
-foreach($DaysShort as $index => $day)
-{
-	echo '"'.$day.'",';
-}
-?>
-"");
-//-->
-</script>
-</head>
-<body onLoad="initCalendar();">
-<div id="calendar_data"></div>
-<div id="clock_data"></div>
-</body>
-</html>

+ 0 - 159
main/blog/tbl_change.js

@@ -1,159 +0,0 @@
-var day;
-var month;
-var year;
-var hour;
-var minute;
-var second;
-var clock_set = 0;
-
-/**
- * Opens calendar window.
- *
- * @param   string      form name
- * @param   string      field name
- */
-function openCalendar(form, field) {
-    window.open("./calendar.php", "calendar", "width=260,height=250,status=no");
-	day = eval("document." + form + "." + field + "day.options["+ "document." + form + "." + field + "day.selectedIndex].value");
-    month = eval("document." + form + "." + field + "month.options["+ "document." + form + "." + field + "month.selectedIndex].value");
-   	month = month-1;
-    year = eval("document." + form + "." + field + "year.options["+ "document." + form + "." + field + "year.selectedIndex].value");
-	formName = form;
-	fieldName =field;
-}
-
-/**
- * Formats number to two digits.
- *
- * @param   int number to format.
- */
-function formatNum2(i, valtype) {
-    f = (i < 10 ? '0' : '') + i;
-    if (valtype && valtype != '') {
-        switch(valtype) {
-            case 'month':
-                f = (f > 12 ? 12 : f);
-                break;
-
-            case 'day':
-                f = (f > 31 ? 31 : f);
-                break;
-        }
-    }
-
-    return f;
-}
-
-/**
- * Formats number to four digits.
- *
- * @param   int number to format.
- */
-function formatNum4(i) {
-    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
-}
-
-/**
- * Initializes calendar window.
- */
-function initCalendar() {
-    if (!year && !month && !day) {
-		day = window.opener.day;
-		month = window.opener.month;
-		year  = window.opener.year;
-        if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
-            dt      = new Date();
-            year    = dt.getFullYear();
-            month   = dt.getMonth();
-            day     = dt.getDate();
-        }
-    } else {
-        /* Moving in calendar */
-        if (month > 11) {
-            month = 0;
-            year++;
-        }
-        if (month < 0) {
-            month = 11;
-            year--;
-        }
-    }
-
-    if (document.getElementById) {
-        cnt = document.getElementById("calendar_data");
-    } else if (document.all) {
-        cnt = document.all["calendar_data"];
-    }
-
-    cnt.innerHTML = "";
-
-    str = ""
-
-    //heading table
-    str += '<table class="calendar"><tr><th class="monthyear" width="50%">';
-    str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
-    str += month_names[month];
-    str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
-    str += '</th><th class="monthyear" width="50%">';
-    str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
-    str += year;
-    str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
-    str += '</th></tr></table>';
-
-    str += '<table class="calendar"><tr>';
-    for (i = 0; i < 7; i++) {
-        str += "<th  class='daynames'>" + day_names[i] + "</th>";
-    }
-    str += "</tr>";
-
-    var firstDay = new Date(year, month, 1).getDay();
-    var lastDay = new Date(year, month + 1, 0).getDate();
-
-    str += "<tr>";
-
-    dayInWeek = 0;
-    for (i = 0; i < firstDay; i++) {
-        str += "<td>&nbsp;</td>";
-        dayInWeek++;
-    }
-    for (i = 1; i <= lastDay; i++) {
-        if (dayInWeek == 7) {
-            str += "</tr><tr>";
-            dayInWeek = 0;
-        }
-
-        dispmonth = 1 + month;
-        actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
-        if (i == day) {
-            style = ' class="selected"';
-        } else {
-            style = '';
-        }
-        str += "<td" + style + "><a href=\"javascript:returnDate(" + i +","+month+","+year + ");\">" + i + "</a></td>"
-        dayInWeek++;
-    }
-    for (i = dayInWeek; i < 7; i++) {
-        str += "<td>&nbsp;</td>";
-    }
-
-    str += "</tr></table>";
-
-    cnt.innerHTML = str;
-}
-
-/**
- * Returns date from calendar.
- *
- * @param   string     date text
- */
-function returnDate(d,m,y) {
-	cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"day.selectedIndex = "+(d-1);
-	eval(cmd);
-	cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"month.selectedIndex = "+m;
-	eval(cmd);
-	date = new Date();
-    year = date.getFullYear()-1;
-	cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"year.selectedIndex = "+(y-year);
-	eval(cmd);
-    window.close();
-}

+ 5 - 5
main/calendar/agenda.php

@@ -5,7 +5,7 @@
  * @package chamilo.calendar
  */
 
-use \ChamiloSession as Session;
+use ChamiloSession as Session;
 
 // use anonymous mode when accessing this course tool
 $use_anonymous = true;
@@ -63,7 +63,7 @@ $nameTools = get_lang('Agenda');
 Event::event_access_tool(TOOL_CALENDAR_EVENT);
 
 // permission stuff - also used by loading from global in agenda.inc.php
-$is_allowed_to_edit = api_is_allowed_to_edit(false, true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
+$is_allowed_to_edit = api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous());
 $agenda = new Agenda();
 $agenda->type = $type;
 $actions = $agenda->displayActions('calendar');
@@ -88,10 +88,10 @@ $agenda->type = $event_type;
 $message = null;
 $content = null;
 
-if (api_is_allowed_to_edit(false, true) OR
+if (api_is_allowed_to_edit(false, true) ||
     (api_get_course_setting('allow_user_edit_agenda') &&
     !api_is_anonymous() &&
-    api_is_allowed_to_session_edit(false, true)) OR
+    api_is_allowed_to_session_edit(false, true)) ||
     GroupManager::user_has_access(api_get_user_id(), $group_id,  GroupManager::GROUP_TOOL_CALENDAR) &&
     GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)
 ) {
@@ -239,7 +239,7 @@ if (api_is_allowed_to_edit(false, true) OR
                 header("Location: $agendaUrl");
                 exit;
             } else {
-                $content = $form->return_form();
+                $content = $form->returnForm();
             }
             break;
         case 'importical':

+ 1 - 1
main/calendar/agenda_list.php

@@ -14,7 +14,7 @@ $interbreadcrumb[] = array(
 $agenda = new Agenda();
 $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
 $agenda->setType($type);
-$events = $agenda->get_events(
+$events = $agenda->getEvents(
     null,
     null,
     api_get_course_int_id(),

+ 0 - 123
main/calendar/calendar.php

@@ -1,123 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-require_once dirname(__FILE__).'/../inc/global.inc.php';
-
-//session
-if(isset($_GET['id_session']))
-	$_SESSION['id_session'] = Security::remove_XSS($_GET['id_session']);
-
-// the variables for the days and the months
-// Defining the shorts for the days
-$DaysShort = api_get_week_days_short();
-// Defining the days of the week to allow translation of the days
-$DaysLong = api_get_week_days_long();
-// Defining the months of the year to allow translation of the months
-$MonthsLong = api_get_months_long();
-
-$iso_lang = api_get_language_isocode($language_interface);
-
-header('Content-Type: text/html; charset='. api_get_system_encoding());
-
-?>
-<!DOCTYPE html
-     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $iso_lang; ?>" lang="<?php echo $iso_lang; ?>">
-<head>
-<title>Calendar</title>
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>">
-<style type="text/css">
-/*<![CDATA[*/
-@import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/<?php echo api_get_setting('stylesheets'); ?>/default.css";
-.data_table th
-{
-	font-size: 10px;
-}
-.data_table td
-{
-	font-size: 10px;
-	width: 25px;
-	height: 25px;
-}
-table.calendar td
-{
-
-	background-color: #f5f5f5;
-	text-align: center;
-}
-.data_table td.selected
-{
-	border: 1px solid #ff0000;
-	background-color: #FFCECE;
-}
-.data_table td a
-{
-	width: 25px;
-	height: 25px;
-	text-decoration: none;
-}
-.data_table td a:hover
-{
-	background-color: #ffff00;
-}
-</style>
-<script type="text/javascript">
-/* <![CDATA[ */
-    /* added 2004-06-10 by Michael Keck
-     *       we need this for Backwards-Compatibility and resolving problems
-     *       with non DOM browsers, which may have problems with css 2 (like NC 4)
-    */
-    var isDOM      = (typeof(document.getElementsByTagName) != 'undefined'
-                      && typeof(document.createElement) != 'undefined')
-                   ? 1 : 0;
-    var isIE4      = (typeof(document.all) != 'undefined'
-                      && parseInt(navigator.appVersion) >= 4)
-                   ? 1 : 0;
-    var isNS4      = (typeof(document.layers) != 'undefined')
-                   ? 1 : 0;
-    var capable    = (isDOM || isIE4 || isNS4)
-                   ? 1 : 0;
-    // Uggly fix for Opera and Konqueror 2.2 that are half DOM compliant
-    if (capable) {
-        if (typeof(window.opera) != 'undefined') {
-            var browserName = ' ' + navigator.userAgent.toLowerCase();
-            if ((browserName.indexOf('konqueror 7') == 0)) {
-                capable = 0;
-            }
-        } else if (typeof(navigator.userAgent) != 'undefined') {
-            var browserName = ' ' + navigator.userAgent.toLowerCase();
-            if ((browserName.indexOf('konqueror') > 0) && (browserName.indexOf('konqueror/3') == 0)) {
-                capable = 0;
-            }
-        } // end if... else if...
-    } // end if
-/* ]]> */
-</script>
-<script type="text/javascript" src="tbl_change.js"></script>
-<script type="text/javascript">
-/* <![CDATA[ */
-var month_names = new Array(
-<?php
-foreach($MonthsLong as $index => $month)
-{
-	echo '"'.$month.'",';
-}
-?>
-"");
-var day_names = new Array(
-<?php
-foreach($DaysShort as $index => $day)
-{
-	echo '"'.$day.'",';
-}
-?>
-"");
-/* ]]> */
-</script>
-</head>
-<body dir="<?php echo api_get_text_direction(); ?>" onLoad="javascript: initCalendar();">
-<div id="calendar_data"></div>
-<div id="clock_data"></div>
-</body>
-</html>

+ 0 - 159
main/calendar/tbl_change.js

@@ -1,159 +0,0 @@
-var day;
-var month;
-var year;
-var hour;
-var minute;
-var second;
-var clock_set = 0;
-
-/**
- * Opens calendar window.
- *
- * @param   string      form name
- * @param   string      field name
- */
-function openCalendar(form, field) {
-    window.open("./calendar.php", "calendar", "width=260,height=250,status=no,toolbar=no");
-	day = eval("document." + form + "." + field + "day.options["+ "document." + form + "." + field + "day.selectedIndex].value");
-    month = eval("document." + form + "." + field + "month.options["+ "document." + form + "." + field + "month.selectedIndex].value");
-   	month = month-1;
-    year = eval("document." + form + "." + field + "year.options["+ "document." + form + "." + field + "year.selectedIndex].value");
-	formName = form;
-	fieldName =field;
-}
-
-/**
- * Formats number to two digits.
- *
- * @param   int number to format.
- */
-function formatNum2(i, valtype) {
-    f = (i < 10 ? '0' : '') + i;
-    if (valtype && valtype != '') {
-        switch(valtype) {
-            case 'month':
-                f = (f > 12 ? 12 : f);
-                break;
-
-            case 'day':
-                f = (f > 31 ? 31 : f);
-                break;
-        }
-    }
-
-    return f;
-}
-
-/**
- * Formats number to four digits.
- *
- * @param   int number to format.
- */
-function formatNum4(i) {
-    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
-}
-
-/**
- * Initializes calendar window.
- */
-function initCalendar() {
-    if (!year && !month && !day) {
-		day = window.opener.day;
-		month = window.opener.month;
-		year  = window.opener.year;
-        if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
-            dt      = new Date();
-            year    = dt.getFullYear();
-            month   = dt.getMonth();
-            day     = dt.getDate();
-        }
-    } else {
-        /* Moving in calendar */
-        if (month > 11) {
-            month = 0;
-            year++;
-        }
-        if (month < 0) {
-            month = 11;
-            year--;
-        }
-    }
-
-    if (document.getElementById) {
-        cnt = document.getElementById("calendar_data");
-    } else if (document.all) {
-        cnt = document.all["calendar_data"];
-    }
-
-    cnt.innerHTML = "";
-
-    str = ""
-
-    //heading table
-    str += '<table class="data_table"><tr><th class="monthyear" width="50%">';
-    str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
-    str += month_names[month];
-    str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
-    str += '</th><th class="monthyear" width="50%">';
-    str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
-    str += year;
-    str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
-    str += '</th></tr></table>';
-
-    str += '<table class="data_table"><tr>';
-    for (i = 0; i < 7; i++) {
-        str += "<td class='weekdays'>" + day_names[i] + "</td>";
-    }
-    str += "</tr>";
-
-    var firstDay = new Date(year, month, 1).getDay();
-    var lastDay = new Date(year, month + 1, 0).getDate();
-
-    str += "<tr>";
-
-    dayInWeek = 0;
-    for (i = 0; i < firstDay; i++) {
-        str += "<td>&nbsp;</td>";
-        dayInWeek++;
-    }
-    for (i = 1; i <= lastDay; i++) {
-        if (dayInWeek == 7) {
-            str += "</tr><tr>";
-            dayInWeek = 0;
-        }
-
-        dispmonth = 1 + month;
-        actVal = formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
-        if (i == day) {
-            style = ' class="selected"';
-        } else {
-            style = '';
-        }
-        str += "<td" + style + "><a href=\"javascript:returnDate(" + i +","+month+","+year + ");\">" + i + "</a></td>"
-        dayInWeek++;
-    }
-    for (i = dayInWeek; i < 7; i++) {
-        str += "<td>&nbsp;</td>";
-    }
-
-    str += "</tr></table>";
-
-    cnt.innerHTML = str;
-}
-
-/**
- * Returns date from calendar.
- *
- * @param   string     date text
- */
-function returnDate(d,m,y) {
-	cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"day.selectedIndex = "+(d-1);
-	eval(cmd);
-	cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"month.selectedIndex = "+m;
-	eval(cmd);
-	date = new Date();
-	year = date.getFullYear()-1;
-	cmd = "window.opener.document."+window.opener.formName+"."+window.opener.fieldName+"year.selectedIndex = "+(y-year);
-	eval(cmd);
-    window.close();
-}

+ 29 - 18
main/chat/chat_whoisonline.php

@@ -12,6 +12,7 @@ define('FRAME', 'online');
 require_once '../inc/global.inc.php';
 
 $course = api_get_course_id();
+$courseInfo = api_get_course_info();
 $group_id = api_get_group_id();
 $session_id = api_get_session_id();
 $user_id = api_get_user_id();
@@ -50,13 +51,14 @@ if (!empty($course)) {
     if (empty($session_id)) {
 		$query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email,t3.status
 				  FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_course_user t3
-				  WHERE t2.c_id = $course_id AND
-				  		t1.user_id=t2.user_id AND
-				  		t3.user_id=t2.user_id AND
-						t3.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND
-						t3.course_code = '".$_course['sysCode']."' AND
-						t2.last_connection>'".$date_inter."' $extra_condition
-						ORDER BY username";
+				  WHERE
+				  	t2.c_id = $course_id AND
+					t1.user_id=t2.user_id AND
+					t3.user_id=t2.user_id AND
+					t3.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND
+					t3.c_id = '".$courseInfo['real_id']."' AND
+					t2.last_connection>'".$date_inter."' $extra_condition
+				  ORDER BY username";
         $result = Database::query($query);
         $users = Database::store_result($result);
 	} else {
@@ -65,9 +67,11 @@ if (!empty($course)) {
                   FROM $tbl_user t1, $tbl_chat_connected t2, $tbl_session_course_user t3
 		          WHERE
 		          t2.c_id = $course_id AND
-		          t1.user_id=t2.user_id AND t3.id_user=t2.user_id AND
-		          t3.id_session = '".$session_id."' AND
-		          t3.course_code = '".$_course['sysCode']."' AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
+		          t1.user_id=t2.user_id AND t3.user_id=t2.user_id AND
+		          t3.session_id = '".$session_id."' AND
+		          t3.c_id = '".$_course['real_id']."' AND
+		          t2.last_connection>'".$date_inter."' $extra_condition
+		          ORDER BY username";
 		$result = Database::query($query);
 		while ($learner = Database::fetch_array($result)) {
             $users[$learner['user_id']] = $learner;
@@ -76,8 +80,14 @@ if (!empty($course)) {
 		// select session coach
 		$query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email
 		          FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session t3
-		          WHERE t2.c_id = $course_id AND
-		             t1.user_id=t2.user_id AND t3.id_coach=t2.user_id AND t3.id = '".$session_id."' AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
+		          WHERE
+					t2.c_id = $course_id AND
+					t1.user_id=t2.user_id AND
+					t3.id_coach=t2.user_id AND
+					t3.id = '".$session_id."' AND
+					t2.last_connection > '".$date_inter."'
+					$extra_condition
+				  ORDER BY username";
 		$result = Database::query($query);
 		if ($coach = Database::fetch_array($result)) {
 			$users[$coach['user_id']] = $coach;
@@ -87,12 +97,13 @@ if (!empty($course)) {
 		$query = "SELECT DISTINCT t1.user_id,username,firstname,lastname,picture_uri,email
 				FROM $tbl_user t1,$tbl_chat_connected t2,$tbl_session_course_user t3
 				WHERE
-				t2.c_id = $course_id AND
-				t1.user_id=t2.user_id
-				AND t3.id_user=t2.user_id AND t3.status=2
-				AND t3.id_session = '".$session_id."'
-				AND t3.course_code = '".$_course['sysCode']."'
-				AND t2.last_connection>'".$date_inter."' $extra_condition ORDER BY username";
+					t2.c_id = $course_id AND
+					t1.user_id=t2.user_id
+					AND t3.user_id =t2.user_id AND t3.status=2
+					AND t3.session_id = '".$session_id."'
+					AND t3.c_id = '".$course_id."'
+					AND t2.last_connection>'".$date_inter."' $extra_condition
+				ORDER BY username";
 
 		$result = Database::query($query);
 		$course_coaches = array();

+ 7 - 4
main/course_description/course_description_controller.php

@@ -35,7 +35,7 @@ class CourseDescriptionController
         $course_description->set_session_id($session_id);
         $data = array();
         $course_description_data = $course_description->get_description_data();
-        $data['descriptions'] = $course_description_data['descriptions'];
+        $data['descriptions'] = isset($course_description_data['descriptions']) ? $course_description_data['descriptions'] : '';
         $data['default_description_titles'] = $course_description->get_default_description_title();
         $data['default_description_title_editable'] = $course_description->get_default_description_title_editable();
         $data['default_description_icon'] = $course_description->get_default_description_icon();
@@ -45,6 +45,7 @@ class CourseDescriptionController
         if (!is_array($data['descriptions'])) {
             $data['descriptions'] = array($data['descriptions']);
         }
+
         foreach ($data['descriptions'] as $description) {
             if (!empty($description['content'])
                 && strpos($description['content'], '<iframe') !== false
@@ -73,6 +74,8 @@ class CourseDescriptionController
         $course_description->set_session_id($session_id);
         $data = array();
         $data['id'] = $id;
+        $affected_rows = null;
+        $message = array();
         if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
             if (!empty($_POST['title']) && !empty($_POST['contentDescription'])) {
                 $check = Security::check_token();
@@ -85,7 +88,7 @@ class CourseDescriptionController
                     }
                     $description_type = $_POST['description_type'];
                     $id = $_POST['id'];
-                    $progress = $_POST['progress'];
+                    $progress = isset($_POST['progress']) ? $_POST['progress'] : '';
                     $course_description->set_description_type($description_type);
                     $course_description->set_title($title);
                     $course_description->set_content($content);
@@ -137,7 +140,7 @@ class CourseDescriptionController
                 if (isset($_GET['id_session'])) {
                     $session_id = intval($_GET['id_session']);
                 }
-                $course_description_data = $course_description->get_data_by_id(
+		$course_description_data = $course_description->get_data_by_id(
                     $id,
                     null,
                     $session_id
@@ -146,7 +149,7 @@ class CourseDescriptionController
                 $data['description_title'] = $course_description_data['description_title'];
                 $data['description_content'] = $course_description_data['description_content'];
                 $data['progress'] = $course_description_data['progress'];
-                $data['descriptions'] = $course_description->get_data_by_description_type(
+		$data['descriptions'] = $course_description->get_data_by_description_type(
                     $description_type,
                     null,
                     $session_id

+ 6 - 3
main/course_info/infocours.php

@@ -31,6 +31,7 @@ $currentCourseRepository = $_course['path'];
 $is_allowedToEdit = $is_courseAdmin || $is_platformAdmin;
 
 $course_code = api_get_course_id();
+$courseId = api_get_course_int_id();
 $course_access_settings = CourseManager:: get_access_settings($course_code);
 
 //LOGIC FUNCTIONS
@@ -62,7 +63,7 @@ $s_tutor = Database::result($q_tutor, 0, 'tutor_name');
 $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
 $s_sql_course_titular = "SELECT DISTINCT username, lastname, firstname
     FROM $tbl_user as user, $tbl_course_user as course_rel_user
-    WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND course_code='".$course_code."'
+    WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND c_id ='".$courseId."'
     ORDER BY ".$target_name." ASC";
 $q_result_titulars = Database::query($s_sql_course_titular);
 
@@ -414,7 +415,7 @@ if ($form->validate() && is_settings_editable()) {
     $updateValues = $form->exportValues();
 
     $visibility = $updateValues['visibility'];
-    $deletePicture = $updateValues['delete_picture'];
+    $deletePicture = isset($updateValues['delete_picture']) ? $updateValues['delete_picture'] : '';
 
     if ($deletePicture) {
         CourseManager::deleteCoursePicture($course_code);
@@ -476,6 +477,8 @@ if ($form->validate() && is_settings_editable()) {
         $updateValues[$index] = Database::escape_string($value);
     }
 
+    $activeLegal = isset($updateValues['activate_legal']) ? $updateValues['activate_legal'] : '';
+
     $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
     $sql = "UPDATE $table_course SET
         title 				    = '".$updateValues['title']."',
@@ -487,7 +490,7 @@ if ($form->validate() && is_settings_editable()) {
         subscribe  			    = '".$updateValues['subscribe']."',
         unsubscribe  		    = '".$updateValues['unsubscribe']."',
         legal                   = '".$updateValues['legal']."',
-        activate_legal          = '".$updateValues['activate_legal']."',
+        activate_legal          = '".$activeLegal."',
         registration_code 	    = '".$updateValues['course_registration_password']."'
         WHERE code = '".$course_code."'";
     Database::query($sql);

+ 1 - 1
main/course_info/legal.php

@@ -120,7 +120,7 @@ if (empty($session_id)) {
         header('Location: '.$url);
     }
 
-    $userStatus = SessionManager::get_user_status_in_session($user_id, $course_code, $session_id);
+    $userStatus = SessionManager::get_user_status_in_session($user_id, $course_info['real_id'], $session_id);
 
     if (isset($userStatus) || api_check_user_access_to_legal($course_info['visibility'])) {
         $user_accepted_legal = CourseManager::is_user_accepted_legal(

+ 7 - 2
main/course_progress/index.php

@@ -78,7 +78,7 @@ $thematic = new Thematic();
 
 // thematic controller object
 $thematic_controller = new ThematicController();
-
+$thematic_data = [];
 if (!empty($thematic_id)) {
     // thematic data by id
     $thematic_data = $thematic->get_thematic_list($thematic_id);
@@ -197,7 +197,12 @@ if ($action == 'thematic_details') {
 }
 if ($action == 'thematic_plan_list' || $action == 'thematic_plan_delete') {
     $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action='.$_SESSION['thematic_control'], 'name' => get_lang('ThematicControl'));
-    $interbreadcrumb[] = array ('url' => '#', 'name' => get_lang('ThematicPlan').' ('.$thematic_data['title'].') ');
+    if (!empty($thematic_data)) {
+        $interbreadcrumb[] = array(
+            'url' => '#',
+            'name' => get_lang('ThematicPlan').' ('.$thematic_data['title'].') '
+        );
+    }
 }
 if ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
     $interbreadcrumb[] = array ('url' => 'index.php?'.api_get_cidreq().'&action='.$_SESSION['thematic_control'], 'name' => get_lang('ThematicControl'));

+ 27 - 13
main/course_progress/thematic_controller.php

@@ -113,7 +113,7 @@ class ThematicController
                 case 'thematic_import_select':
                     break;
                 case 'thematic_import':
-                    $csv_import_array = Import::csv_to_array($_FILES['file']['tmp_name'], 'horizontal');
+                    $csv_import_array = Import::csvToArray($_FILES['file']['tmp_name']);
 
                     if (isset($_POST['replace']) && $_POST['replace']) {
                         // Remove current thematic.
@@ -126,22 +126,35 @@ class ThematicController
                     // Import the progress.
                     $current_thematic = null;
 
-                    foreach ($csv_import_array as $data) {
-                        foreach ($data as $key => $item) {
-                            if ($key == 'title') {
-                                $thematic->set_thematic_attributes(null, $item[0], $item[1], api_get_session_id());
+                    foreach ($csv_import_array as $item) {
+                        $key = $item['type'];
+                        switch ($key) {
+                            case 'title':
+                                $thematic->set_thematic_attributes(null, $item['data1'], $item['data2'], api_get_session_id());
                                 $current_thematic = $thematic->thematic_save();
                                 $description_type = 0;
-                            }
-                            if ($key == 'plan') {
-                                $thematic->set_thematic_plan_attributes($current_thematic, $item[0], $item[1], $description_type);
+                                break;
+                            case 'plan':
+                                $thematic->set_thematic_plan_attributes(
+                                    $current_thematic,
+                                    $item['data1'],
+                                    $item['data2'],
+                                    $description_type
+                                );
                                 $thematic->thematic_plan_save();
                                 $description_type++;
-                            }
-                            if ($key == 'progress') {
-                                $thematic->set_thematic_advance_attributes(null, $current_thematic, 0, $item[2], $item[0], $item[1]);
+                                break;
+                            case 'progress':
+                                $thematic->set_thematic_advance_attributes(
+                                    null,
+                                    $current_thematic,
+                                    0,
+                                    $item['data3'],
+                                    $item['data1'],
+                                    $item['data2']
+                                );
                                 $thematic->thematic_advance_save();
-                            }
+                                break;
                         }
                     }
                     $action = 'thematic_details';
@@ -149,6 +162,7 @@ class ThematicController
                 case 'thematic_export':
                     $list = $thematic->get_thematic_list();
                     $csv = array();
+                    $csv[] = array('type', 'data1', 'data2', 'data3');
                     foreach ($list as $theme) {
                         $csv[] = array('title', $theme['title'], $theme['content']);
                         $data = $thematic->get_thematic_plan_data($theme['id']);
@@ -164,7 +178,7 @@ class ThematicController
                             }
                         }
                     }
-                    Export::export_table_csv($csv);
+                    Export::arrayToCsv($csv);
                     exit;
                     // Don't continue building a normal page.
                     return;

+ 12 - 12
main/coursecopy/classes/Announcement.class.php

@@ -30,15 +30,15 @@ class Announcement extends Resource
 	 * Has the e-mail been sent?
 	 */
     public $email_sent;
-	
+
     public $attachment_path;
-	
+
     public $attachment_filename;
-	
+
     public $attachment_size;
-	
+
     public $attachment_comment;
-	
+
 	/**
 	 * Create a new announcement
 	 * @param int $id
@@ -47,22 +47,22 @@ class Announcement extends Resource
 	 * @param string $date
 	 * @param int display_order
 	 */
-    function Announcement($id, $title, $content, $date, $display_order, $email_sent, $path, $filename, $size, $comment)
+    function __construct($id, $title, $content, $date, $display_order, $email_sent, $path, $filename, $size, $comment)
     {
-		parent::Resource($id,RESOURCE_ANNOUNCEMENT);
-		
+		parent::__construct($id,RESOURCE_ANNOUNCEMENT);
+
 		$this->content	= $content;
 		$this->title 	= $title;
 		$this->date 	= $date;
 		$this->display_order	= $display_order;
-		$this->email_sent	 	= $email_sent;		
-		
+		$this->email_sent	 	= $email_sent;
+
 		$this->attachment_path 	= $path;
 		$this->attachment_filename = $filename;
 		$this->attachment_size 	= $size;
-		$this->attachment_comment 	= $comment;		
+		$this->attachment_comment 	= $comment;
 	}
-	
+
 	/**
 	 * Show this announcement
 	 */

+ 1 - 1
main/coursecopy/classes/Attendance.class.php

@@ -20,7 +20,7 @@ class Attendance extends Resource
 	 */
     public function __construct($params)
     {
-		parent::Resource($params['id'], RESOURCE_ATTENDANCE);
+		parent::__construct($params['id'], RESOURCE_ATTENDANCE);
 		$this->params = $params;
 	}
 

+ 5 - 5
main/coursecopy/classes/Course.class.php

@@ -24,11 +24,11 @@ class Course
      */
     public function __construct()
     {
-        $this->resources    = array();
-        $this->code         = '';
-        $this->path         = '';
-        $this->backup_path  = '';
-        $this->encoding     = api_get_system_encoding();
+        $this->resources = array();
+        $this->code = '';
+        $this->path = '';
+        $this->backup_path = '';
+        $this->encoding = api_get_system_encoding();
     }
 
     /**

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

@@ -80,15 +80,9 @@ class CourseBuilder
         $this->course = new Course();
         $this->course->code = $_course['official_code'];
         $this->course->type = $type;
-        $this->course->path = api_get_path(
-                SYS_COURSE_PATH
-            ).$_course['path'].'/';
-        $this->course->backup_path = api_get_path(
-                SYS_COURSE_PATH
-            ).$_course['path'];
-        $this->course->encoding = api_get_system_encoding(
-        ); //current platform encoding
-        $this->course->db_name = $_course['dbName'];
+        $this->course->path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/';
+        $this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['path'];
+        $this->course->encoding = api_get_system_encoding();
         $this->course->info = $_course;
     }
 
@@ -219,12 +213,15 @@ class CourseBuilder
                 $session_condition = api_get_session_condition(
                     $session_id,
                     true,
-                    true
+                    true,
+                    'd.session_id'
                 );
             } else {
                 $session_condition = api_get_session_condition(
                     $session_id,
-                    true
+                    true,
+                    false,
+                    'd.session_id'
                 );
             }
 
@@ -442,22 +439,36 @@ class CourseBuilder
                 $session_condition = api_get_session_condition(
                     $session_id,
                     true,
-                    true
+                    true,
+                    'l.session_id'
                 );
             } else {
                 $session_condition = api_get_session_condition(
                     $session_id,
-                    true
+                    true,
+                    false,
+                    'l.session_id'
                 );
             }
             $sql = "SELECT  l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
                     FROM $table l, $table_prop p
-                    WHERE l.c_id = $course_id AND p.c_id = $course_id AND p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 $session_condition
+                    WHERE
+                        l.c_id = $course_id AND
+                        p.c_id = $course_id AND
+                        p.ref=l.id AND
+                        p.tool = '".TOOL_LINK."' AND
+                        p.visibility != 2 $session_condition
                     ORDER BY l.display_order";
         } else {
             $sql = "SELECT l.id, l.title, l.url, l.description, l.category_id, l.on_homepage
                     FROM $table l, $table_prop p
-                    WHERE l.c_id = $course_id AND p.c_id = $course_id AND p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 AND l.session_id = 0
+                    WHERE
+                        l.c_id = $course_id AND
+                        p.c_id = $course_id AND
+                        p.ref=l.id AND
+                        p.tool = '".TOOL_LINK."' AND
+                        p.visibility != 2 AND
+                        l.session_id = 0
                     ORDER BY l.display_order";
         }
 
@@ -622,15 +633,17 @@ class CourseBuilder
 
         // Building normal tests.
         $sql = "SELECT * FROM $table_que WHERE c_id = $course_id ";
+        $result = Database::query($sql);
 
-        $db_result = Database::query($sql);
-        while ($obj = Database::fetch_object($db_result)) {
+        while ($obj = Database::fetch_object($result)) {
             // find the question category
+
             // @todo : need to be adapted for multi category questions in 1.10
-            $question_category_id = Testcategory::getCategoryForQuestion(
+            $question_category_id = TestCategory::getCategoryForQuestion(
                 $obj->id,
                 $course_id
             );
+
             // build the backup resource question object
             $question = new QuizQuestion(
                 $obj->id,
@@ -644,7 +657,9 @@ class CourseBuilder
                 $obj->extra,
                 $question_category_id
             );
-            $sql = 'SELECT * FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
+
+            $sql = 'SELECT * FROM '.$table_ans.'
+                    WHERE c_id = '.$course_id.' AND question_id = '.$obj->id;
             $db_result2 = Database::query($sql);
 
             while ($obj2 = Database::fetch_object($db_result2)) {
@@ -703,11 +718,11 @@ class CourseBuilder
                  )
         ";
 
-        $db_result = Database::query($sql);
-        if (Database::num_rows($db_result) > 0) {
+        $result = Database::query($sql);
+        if (Database::num_rows($result) > 0) {
             $build_orphan_questions = true;
             $orphanQuestionIds = array();
-            while ($obj = Database::fetch_object($db_result)) {
+            while ($obj = Database::fetch_object($result)) {
 
                 // Orphan questions
                 if (!empty($obj->question_id)) {
@@ -718,7 +733,7 @@ class CourseBuilder
                 if (!isset($this->course->resources[$obj->id])) {
                     // find the question category
                     // @todo : need to be adapted for multi category questions in 1.10
-                    $question_category_id = Testcategory::getCategoryForQuestion(
+                    $question_category_id = TestCategory::getCategoryForQuestion(
                         $obj->id,
                         $course_id
                     );
@@ -856,12 +871,12 @@ class CourseBuilder
         $course_id = api_get_course_int_id();
 
         // get all test category in course
-        $tab_test_categories_id = Testcategory::getCategoryListInfo(
+        $tab_test_categories_id = TestCategory::getCategoryListInfo(
             "id",
             $course_id
         );
         foreach ($tab_test_categories_id as $test_category_id) {
-            $test_category = new Testcategory($test_category_id);
+            $test_category = new TestCategory($test_category_id);
             $copy_course_test_category = new CourseCopyTestcategory(
                 $test_category_id,
                 $test_category->name,
@@ -954,7 +969,7 @@ class CourseBuilder
         $id_list = array()
     ) {
         $table = Database:: get_course_table(TABLE_ANNOUNCEMENT);
-        $course_id = api_get_course_int_id();
+        $courseId = api_get_course_int_id();
 
         $sessionCondition = api_get_session_condition(
             $session_id,
@@ -962,22 +977,27 @@ class CourseBuilder
             $with_base_content
         );
 
-        $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$course_id.' '.$sessionCondition;
+        $sql = 'SELECT * FROM '.$table.' WHERE c_id = '.$courseId.' '.$sessionCondition;
         $db_result = Database::query($sql);
         $table_attachment = Database:: get_course_table(
             TABLE_ANNOUNCEMENT_ATTACHMENT
         );
         while ($obj = Database::fetch_object($db_result)) {
-            $sql = 'SELECT path, comment, filename, size  FROM '.$table_attachment.' WHERE c_id = '.$course_id.' AND announcement_id = '.$obj->id.'';
+
+            $sql = 'SELECT path, comment, filename, size
+                    FROM '.$table_attachment.'
+                    WHERE c_id = '.$courseId.' AND announcement_id = '.$obj->id.'';
             $result = Database::query($sql);
             $attachment_obj = Database::fetch_object($result);
             $att_path = $att_filename = $att_size = $atth_comment = '';
+
             if (!empty($attachment_obj)) {
                 $att_path = $attachment_obj->path;
                 $att_filename = $attachment_obj->filename;
                 $att_size = $attachment_obj->size;
                 $atth_comment = $attachment_obj->comment;
             }
+
             $announcement = new Announcement(
                 $obj->id,
                 $obj->title,
@@ -991,7 +1011,6 @@ class CourseBuilder
                 $atth_comment
             );
             $this->course->add_resource($announcement);
-
         }
     }
 
@@ -1297,9 +1316,12 @@ class CourseBuilder
             $this->course->encoding = api_get_system_encoding(
             ); //current platform encoding
             $code_course = $_course['code'];
-            $sql_session = "SELECT id, name, course_code  FROM $tbl_session_course
-                INNER JOIN  $tbl_session ON id_session = id
-                WHERE course_code = '$code_course' ";
+            $courseId = $_course['real_id'];
+            $sql_session = "SELECT s.id, name, c_id
+                FROM $tbl_session_course sc
+                INNER JOIN $tbl_session s
+                ON sc.session_id = s.id
+                WHERE sc.c_id = '$courseId' ";
             $query_session = Database::query($sql_session);
             while ($rows_session = Database::fetch_assoc($query_session)) {
                 $session = new CourseSession(
@@ -1465,11 +1487,13 @@ class CourseBuilder
             $with_base_content
         );
 
-        $sql = 'SELECT * FROM '.$table_attendance.' WHERE c_id = '.$course_id.' '.$sessionCondition;
+        $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);
-            $sql = 'SELECT * FROM '.$table_attendance_calendar.' WHERE c_id = '.$course_id.' AND attendance_id = '.$row['id'];
+            $sql = 'SELECT * FROM '.$table_attendance_calendar.'
+                    WHERE c_id = '.$course_id.' AND attendance_id = '.$row['id'];
 
             $result = Database::query($sql);
             while ($sub_row = Database::fetch_array($result, 'ASSOC')) {

+ 2 - 2
main/coursecopy/classes/CourseCopyLearnpath.class.php

@@ -108,7 +108,7 @@ class CourseCopyLearnpath extends Resource
 	 * @param string $visibility
 	 * @param array  $items
 	 */
-	public function CourseCopyLearnpath(
+	public function __construct(
 		$id,
 		$type,
 		$name,
@@ -137,7 +137,7 @@ class CourseCopyLearnpath extends Resource
 		$session_id,
 		$items
 	) {
-		parent::Resource($id,RESOURCE_LEARNPATH);
+		parent::__construct($id, RESOURCE_LEARNPATH);
 		$this->lp_type = $type;
 		$this->name = $name;
 		$this->path = $path;

+ 3 - 2
main/coursecopy/classes/CourseCopyTestCategory.php

@@ -25,8 +25,9 @@ class CourseCopyTestcategory extends Resource
      * @param string $title
      * @param string $description
      */
-    function CourseCopyTestcategory($id, $title, $description) {
-        parent::Resource($id, RESOURCE_TEST_CATEGORY);
+    public function __construct($id, $title, $description)
+    {
+        parent::__construct($id, RESOURCE_TEST_CATEGORY);
         $this->title = $title;
         $this->description = $description;
     }

+ 6 - 5
main/coursecopy/classes/CourseDescription.class.php

@@ -13,24 +13,25 @@ class CourseDescription extends Resource
 	/**
 	 * The title
 	 */
-	var $title;
+	public $title;
 	/**
 	 * The content
 	 */
-	var $content;
+	public $content;
 	/**
 	 * The description type
 	 */
-	var $description_type;
+	public $description_type;
+
 	/**
 	 * Create a new course description
 	 * @param int $id
 	 * @param string $title
 	 * @param string $content
 	 */
-	function __construct($id,$title,$content,$description_type)
+	public function __construct($id,$title,$content,$description_type)
 	{
-		parent::Resource($id,RESOURCE_COURSEDESCRIPTION);
+		parent::__construct($id,RESOURCE_COURSEDESCRIPTION);
 		$this->title = $title;
 		$this->content = $content;
 		$this->description_type = $description_type;

+ 2 - 2
main/coursecopy/classes/CourseRecycler.class.php

@@ -21,7 +21,7 @@ class CourseRecycler
      * @param course $course The course-object which contains the items to
      * delete
      */
-    public function CourseRecycler($course)
+    public function __construct($course)
     {
         $this->course = $course;
         $this->course_info = api_get_course_info($this->course->code);
@@ -459,7 +459,7 @@ class CourseRecycler
     {
         if (isset($this->course->resources[RESOURCE_TEST_CATEGORY])) {
             foreach ($this->course->resources[RESOURCE_TEST_CATEGORY] as $tab_test_cat) {
-                $obj_cat = new Testcategory($tab_test_cat->source_id);
+                $obj_cat = new TestCategory($tab_test_cat->source_id);
                 $obj_cat->removeCategory();
             }
         }

+ 83 - 37
main/coursecopy/classes/CourseRestorer.class.php

@@ -90,9 +90,9 @@ class CourseRestorer
         } else {
             $this->course_origin_id = null;
         }
-		$this->file_option 						= FILE_RENAME;
-		$this->set_tools_invisible_by_default 	= false;
-		$this->skip_content 					= array();
+        $this->file_option = FILE_RENAME;
+        $this->set_tools_invisible_by_default = false;
+        $this->skip_content = array();
 	}
 
 	/**
@@ -198,7 +198,7 @@ class CourseRestorer
 		$condition_session = "";
 
 		if (!empty($session_id)) {
-			$condition_session = " , id_session='".intval($session_id)."'";
+			$condition_session = " , session_id ='".intval($session_id)."'";
 		}
 
 		foreach ($this->course->resources as $type => $resources) {
@@ -818,7 +818,7 @@ class CourseRestorer
 
 				if (file_exists($path.$document->path)) {
 					switch ($this->file_option) {
-						case FILE_OVERWRITE :
+						case FILE_OVERWRITE:
 							rmdirr($path.$document->path);
                             copyDirTo(
                                 $this->course->backup_path . '/' . $document->path,
@@ -1123,11 +1123,15 @@ class CourseRestorer
 			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
 			$resources = $this->course->resources;
 			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
-				$sql = "DELETE FROM ".$tool_intro_table." WHERE c_id = ".$this->destination_course_id."  AND id='".self::DBUTF8escapestring($tool_intro->id)."'";
+				$sql = "DELETE FROM ".$tool_intro_table."
+				        WHERE c_id = ".$this->destination_course_id."  AND id='".self::DBUTF8escapestring($tool_intro->id)."'";
 				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)."'";
-				$sql.= ", session_id = $sessionId";
+				$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)."'
+				            session_id = $sessionId";
                 Database::query($sql);
 
 				$this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = Database::insert_id();
@@ -1156,7 +1160,12 @@ class CourseRestorer
 			$result=Database::query($sql);
 			list($orderMax)=Database::fetch_array($result,'NUM');
 			$display_order=$orderMax+1;
-			$sql = "INSERT INTO ".$link_cat_table." SET c_id = ".$this->destination_course_id." , category_title = '".self::DBUTF8escapestring($link_cat->title)."', description='".self::DBUTF8escapestring($link_cat->description)."', display_order='".$display_order."' $condition_session ";
+			$sql = "INSERT INTO $link_cat_table SET
+			            c_id = ".$this->destination_course_id.",
+			            category_title = '".self::DBUTF8escapestring($link_cat->title)."',
+			            description = '".self::DBUTF8escapestring($link_cat->description)."',
+			            display_order = '".$display_order."'
+			            $condition_session ";
 			Database::query($sql);
 			$new_id = Database::insert_id();
 			$this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id;
@@ -1190,8 +1199,8 @@ class CourseRestorer
         				content = '".self::DBUTF8escapestring($event->content)."',
                         all_day = '".$event->all_day."',
         				start_date = '".$event->start_date."',
-        				end_date = '".$event->end_date."'";
-                $sql.= ", session_id = $sessionId";
+        				end_date = '".$event->end_date."',
+        				session_id = $sessionId";
 
 				Database::query($sql);
 				$new_event_id = Database::insert_id();
@@ -1205,7 +1214,9 @@ class CourseRestorer
 				if (!empty($this->course->orig)) {
 
 					$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
-					$sql = 'SELECT path, comment, size, filename FROM '.$table_attachment.' WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
+					$sql = 'SELECT path, comment, size, filename
+					        FROM '.$table_attachment.'
+					        WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
 					$attachment_event = Database::query($sql);
 					$attachment_event = Database::fetch_object($attachment_event);
 
@@ -1215,7 +1226,13 @@ class CourseRestorer
 						//$copy_result = true;
 						if ($copy_result) {
 							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
-							$sql = "INSERT INTO ".$table_attachment." SET c_id = ".$this->destination_course_id." , path = '".self::DBUTF8escapestring($new_filename)."', comment = '".self::DBUTF8escapestring($attachment_event->comment)."', size = '".$attachment_event->size."', filename = '".$attachment_event->filename."' , agenda_id = '".$new_event_id."' ";
+							$sql = "INSERT INTO ".$table_attachment." SET
+                                        c_id = ".$this->destination_course_id.",
+                                        path = '".self::DBUTF8escapestring($new_filename)."',
+                                        comment = '".self::DBUTF8escapestring($attachment_event->comment)."',
+                                        size = '".$attachment_event->size."',
+                                        filename = '".$attachment_event->filename."',
+                                        agenda_id = '".$new_event_id."' ";
 							Database::query($sql);
 						}
 					}
@@ -1226,7 +1243,13 @@ class CourseRestorer
 						$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
 						if ($copy_result) {
 							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
-							$sql = "INSERT INTO ".$table_attachment." SET c_id = ".$this->destination_course_id." , path = '".self::DBUTF8escapestring($new_filename)."', comment = '".self::DBUTF8escapestring($event->attachment_comment)."', size = '".$event->attachment_size."', filename = '".$event->attachment_filename."' , agenda_id = '".$new_event_id."' ";
+							$sql = "INSERT INTO ".$table_attachment." SET
+                                c_id = ".$this->destination_course_id.",
+                                path = '".self::DBUTF8escapestring($new_filename)."',
+                                comment = '".self::DBUTF8escapestring($event->attachment_comment)."',
+                                size = '".$event->attachment_size."',
+                                filename = '".$event->attachment_filename."',
+                                agenda_id = '".$new_event_id."' ";
 							Database::query($sql);
 						}
 					}
@@ -1266,7 +1289,12 @@ class CourseRestorer
 					$session_id = intval($session_id);
 					$condition_session = " , session_id = '$session_id' ";
 				}
-				$sql = "INSERT INTO ".$table." SET c_id = ".$this->destination_course_id." , description_type = '".self::DBUTF8escapestring($cd->description_type)."',title = '".self::DBUTF8escapestring($cd->title)."', content = '".self::DBUTF8escapestring($description_content)."' $condition_session";
+				$sql = "INSERT INTO ".$table." SET
+				        c_id = ".$this->destination_course_id." ,
+				        description_type = '".self::DBUTF8escapestring($cd->description_type)."',
+				        title = '".self::DBUTF8escapestring($cd->title)."',
+				        content = '".self::DBUTF8escapestring($description_content)."'
+				        $condition_session";
 				Database::query($sql);
 				$this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = Database::insert_id();
 			}
@@ -1294,18 +1322,17 @@ class CourseRestorer
                 );
 
 				$sql = "INSERT INTO ".$table." " ."SET
-							c_id = ".$this->destination_course_id." ,
-							title = '".self::DBUTF8escapestring($announcement->title)."'," .
-							"content = '".self::DBUTF8escapestring($announcement->content)."', " .
-							"end_date = '".$announcement->date."', " .
-							"display_order = '".$announcement->display_order."', " .
-							"email_sent = '".$announcement->email_sent."', "
-                    . "session_id = $sessionId";
+							c_id = ".$this->destination_course_id.",
+							title = '".self::DBUTF8escapestring($announcement->title)."',
+							content = '".self::DBUTF8escapestring($announcement->content)."',
+							end_date = '".$announcement->date."',
+							display_order = '".$announcement->display_order."',
+							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;
 
-
 				$origin_path = $this->course->backup_path.'/upload/announcements/';
 				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
 
@@ -1314,30 +1341,49 @@ class CourseRestorer
 
 					$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
 
-					$sql = 'SELECT path, comment, size, filename FROM '.$table_attachment.' WHERE c_id = '.$this->destination_course_id.' AND announcement_id = '.$id;
+					$sql = 'SELECT path, comment, size, filename
+					        FROM '.$table_attachment.'
+					        WHERE c_id = '.$this->destination_course_id.' AND announcement_id = '.$id;
 					$attachment_event = Database::query($sql);
 					$attachment_event = Database::fetch_object($attachment_event);
 
-					if (file_exists($origin_path.$attachment_event->path) && !is_dir($origin_path.$attachment_event->path) ) {
+					if (file_exists($origin_path.$attachment_event->path) &&
+                        !is_dir($origin_path.$attachment_event->path)
+                    ) {
 						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
 						$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
 						//error_log($destination_path.$new_filename); error_log($copy_result);
 						//$copy_result = true;
 						if ($copy_result) {
 							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
-							$sql = "INSERT INTO ".$table_attachment." SET c_id = ".$this->destination_course_id." , path = '".self::DBUTF8escapestring($new_filename)."', comment = '".self::DBUTF8escapestring($attachment_event->comment)."', size = '".$attachment_event->size."', filename = '".$attachment_event->filename."' , announcement_id = '".$new_announcement_id."' ";
+							$sql = "INSERT INTO ".$table_attachment." SET
+							        c_id = ".$this->destination_course_id.",
+							        path = '".self::DBUTF8escapestring($new_filename)."',
+							        comment = '".self::DBUTF8escapestring($attachment_event->comment)."',
+							        size = '".$attachment_event->size."',
+							        filename = '".$attachment_event->filename."',
+							        announcement_id = '".$new_announcement_id."'
+							        ";
 							Database::query($sql);
 						}
 					}
 				} else {
 					// get the info of the file
-					if(!empty($announcement->attachment_path) && is_file($origin_path.$announcement->attachment_path) && is_readable($origin_path.$announcement->attachment_path)) {
+					if (!empty($announcement->attachment_path) &&
+                        is_file($origin_path.$announcement->attachment_path) &&
+                        is_readable($origin_path.$announcement->attachment_path)
+                    ) {
 						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
 						$copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
 
 						if ($copy_result) {
 							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
-							$sql = "INSERT INTO ".$table_attachment." SET c_id = ".$this->destination_course_id." , path = '".self::DBUTF8escapestring($new_filename)."', comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."', size = '".$announcement->attachment_size."', filename = '".$announcement->attachment_filename."' , announcement_id = '".$new_announcement_id."' ";
+							$sql = "INSERT INTO ".$table_attachment." SET
+							        c_id = ".$this->destination_course_id." ,
+							        path = '".self::DBUTF8escapestring($new_filename)."',
+							        comment = '".self::DBUTF8escapestring($announcement->attachment_comment)."',
+							        size = '".$announcement->attachment_size."', filename = '".$announcement->attachment_filename."',
+							        announcement_id = '".$new_announcement_id."' ";
 							Database::query($sql);
 						}
 					}
@@ -1685,25 +1731,25 @@ class CourseRestorer
                 $title = $CourseCopyTestcategory->title;
                 $description = $CourseCopyTestcategory->description;
 
-                if (Testcategory::category_exists_with_title($title)) {
+                if (TestCategory::category_exists_with_title($title)) {
                     switch ($this->file_option) {
                         case FILE_SKIP:
                             //Do nothing
                             break;
                         case FILE_RENAME:
                             $new_title = $title."_";
-                            while (Testcategory::category_exists_with_title(
+                            while (TestCategory::category_exists_with_title(
                                 $new_title
                             )) {
                                 $new_title .= "_";
                             }
-                            $test_category = new Testcategory(0, $new_title, $description);
+                            $test_category = new TestCategory(0, $new_title, $description);
                             $new_id = $test_category->addCategoryInBDD();
                             $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $new_id;
                             break;
                         case FILE_OVERWRITE:
-                            $id = Testcategory::get_category_id_for_title($title);
-                            $my_cat = new Testcategory($id);
+                            $id = TestCategory::get_category_id_for_title($title);
+                            $my_cat = new TestCategory($id);
                             $my_cat->name = $title;
                             $my_cat->modifyCategory();
                             $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $id;
@@ -1711,7 +1757,7 @@ class CourseRestorer
                     }
                 } else {
                     // create a new test_category
-                    $test_category = new Testcategory(0, $title, $description);
+                    $test_category = new TestCategory(0, $title, $description);
                     $new_id = $test_category->addCategoryInBDD();
                     $tab_test_category_id_old_new[$CourseCopyTestcategory->source_id] = $new_id;
                 }
@@ -1728,7 +1774,7 @@ class CourseRestorer
                     $new_quiz_question_id = $resources[RESOURCE_QUIZQUESTION][$id]->destination_id;
                     $question_category = $CourseCopyQuestion->question_category;
                     if ($question_category > 0) {
-                        Testcategory::add_category_for_question_id(
+                        TestCategory::add_category_for_question_id(
                             $tab_test_category_id_old_new[$question_category],
                             $new_quiz_question_id,
                             $course_id
@@ -1877,9 +1923,9 @@ class CourseRestorer
 
 							// if the survey is shared => also delete the shared content
 							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
-								survey_manager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
+                                SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
 							}
-							$return = survey_manager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
+							$return = SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
 
 							//Insert the new source survey
 							Database::query($sql);

+ 2 - 2
main/coursecopy/classes/CourseSelectForm.class.php

@@ -561,9 +561,9 @@ 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_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
+	 public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
      {
-?>
+         ?>
 		<script>
 			function exp(item) {
 				el = document.getElementById('div_'+item);

+ 5 - 4
main/coursecopy/classes/CourseSession.class.php

@@ -13,17 +13,18 @@ class CourseSession extends Resource
     // The title session
 	public $title;
 
-	/*
+	/**
 	 * Create a new Session
 	 * @param int $id
 	 * @param string $title
 	 */
-	function CourseSession($id,$title) {
-		parent::Resource($id,RESOURCE_SESSION_COURSE);
+	public function __construct($id,$title)
+	{
+		parent::__construct($id, RESOURCE_SESSION_COURSE);
 		$this->title = $title;
 	}
 
-	/*
+	/**
 	 * Show this Event
 	 */
 	function show() {

+ 2 - 2
main/coursecopy/classes/Document.class.php

@@ -28,9 +28,9 @@ class Document extends Resource
      * @param string $file_type (DOCUMENT or FOLDER);
      * @param int $size
      */
-    public function Document($id, $path, $comment, $title, $file_type, $size)
+    public function __construct($id, $path, $comment, $title, $file_type, $size)
     {
-        parent::Resource($id, RESOURCE_DOCUMENT);
+        parent::__construct($id, RESOURCE_DOCUMENT);
         $this->path = 'document' . $path;
         $this->comment = $comment;
         $this->title = $title;

+ 2 - 2
main/coursecopy/classes/Event.class.php

@@ -55,9 +55,9 @@ class CalendarEvent extends Resource
 	 * @param string $hour
 	 * @param int $duration
 	 */
-	function CalendarEvent($id, $title, $content, $start_date, $end_date, $attachment_path = null, $attachment_filename= null, $attachment_size= null, $attachment_comment= null, $all_day = 0)
+	function __construct($id, $title, $content, $start_date, $end_date, $attachment_path = null, $attachment_filename= null, $attachment_size= null, $attachment_comment= null, $all_day = 0)
 	{
-		parent::Resource($id,RESOURCE_EVENT);
+		parent::__construct($id,RESOURCE_EVENT);
 
 		$this->title 				= $title;
 		$this->content 				= $content;

+ 3 - 2
main/coursecopy/classes/Forum.class.php

@@ -106,8 +106,9 @@ class Forum extends Resource
     /* 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);
+    function __construct($obj)
+    {
+        parent::__construct($obj->forum_id, RESOURCE_FORUM);
         $this->obj = $obj;
 
         /*

+ 2 - 2
main/coursecopy/classes/ForumCategory.class.php

@@ -13,9 +13,9 @@ class ForumCategory extends Resource
     /**
      * Create a new ForumCategory
      */
-    function ForumCategory($obj)
+    public function __construct($obj)
     {
-        parent::Resource($obj->cat_id, RESOURCE_FORUMCATEGORY);
+        parent::__construct($obj->cat_id, RESOURCE_FORUMCATEGORY);
         $this->obj = $obj;
     }
 

+ 2 - 2
main/coursecopy/classes/ForumPost.class.php

@@ -14,9 +14,9 @@ class ForumPost extends Resource
     /**
      * Create a new ForumPost
      */
-    public function ForumPost($obj)
+    public function __construct($obj)
     {
-        parent::Resource($obj->post_id, RESOURCE_FORUMPOST);
+        parent::__construct($obj->post_id, RESOURCE_FORUMPOST);
         $this->obj = $obj;
     }
 

Some files were not shown because too many files changed in this diff