Browse Source

Merge with 1.9.x

Julio Montoya 12 years ago
parent
commit
4ae4de4304
100 changed files with 2994 additions and 3051 deletions
  1. 0 1
      .hgignore
  2. 22 0
      composer.json
  3. 6 2
      documentation/changelog.html
  4. 1 1
      main/admin/access_url_add_courses_to_url.php
  5. 1 2
      main/admin/access_url_add_users_to_url.php
  6. 0 2
      main/admin/access_url_check_user_session.php
  7. 0 2
      main/admin/access_url_edit.php
  8. 0 2
      main/admin/access_url_edit_courses_to_url.php
  9. 2 4
      main/admin/access_url_edit_users_to_url.php
  10. 0 2
      main/admin/access_urls.php
  11. 0 2
      main/admin/add_courses_to_session.php
  12. 0 2
      main/admin/add_courses_to_usergroup.php
  13. 0 2
      main/admin/add_many_session_to_category.php
  14. 0 4
      main/admin/add_sessions_to_promotion.php
  15. 0 2
      main/admin/add_sessions_to_usergroup.php
  16. 0 1
      main/admin/add_users_to_group.php
  17. 68 45
      main/admin/add_users_to_session.php
  18. 0 1
      main/admin/add_users_to_usergroup.php
  19. 0 2
      main/admin/career_dashboard.php
  20. 0 1
      main/admin/careers.php
  21. 88 0
      main/admin/change_user_session.php
  22. 0 1
      main/admin/class_user_import.php
  23. 1 2
      main/admin/configure_inscription.php
  24. 0 2
      main/admin/course_add.php
  25. 2 2
      main/admin/course_category.php
  26. 1 3
      main/admin/course_edit.php
  27. 1 2
      main/admin/course_import.php
  28. 1 11
      main/admin/course_request_accepted.php
  29. 0 11
      main/admin/course_request_edit.php
  30. 3 14
      main/admin/course_request_rejected.php
  31. 1 12
      main/admin/course_request_review.php
  32. 0 5
      main/admin/course_user_import.php
  33. 0 3
      main/admin/dashboard_add_courses_to_user.php
  34. 0 1
      main/admin/dashboard_add_sessions_to_user.php
  35. 0 1
      main/admin/dashboard_add_users_to_user.php
  36. 2 2
      main/admin/example_session.csv
  37. 2 2
      main/admin/example_session.xml
  38. 164 0
      main/admin/extra_field_options.php
  39. 0 1
      main/admin/grade_models.php
  40. 0 1
      main/admin/group_add.php
  41. 0 3
      main/admin/group_edit.php
  42. 0 2
      main/admin/group_list.php
  43. 0 4
      main/admin/inactive_user_list.php
  44. 2 2
      main/admin/index.php
  45. 0 1
      main/admin/languages.php
  46. 4 12
      main/admin/ldap_import_students_to_session.php
  47. 213 198
      main/admin/resume_session.php
  48. 264 405
      main/admin/session_add.php
  49. 0 2
      main/admin/session_category_add.php
  50. 12 12
      main/admin/session_course_edit.php
  51. 3 1
      main/admin/session_course_user.php
  52. 61 73
      main/admin/session_course_user_list.php
  53. 0 397
      main/admin/session_edit.php
  54. 185 206
      main/admin/session_export.php
  55. 200 0
      main/admin/session_fields.php
  56. 70 104
      main/admin/session_import.php
  57. 178 72
      main/admin/session_list.php
  58. 0 3
      main/admin/session_user_import.php
  59. 1 2
      main/admin/settings.lib.php
  60. 0 1
      main/admin/settings.php
  61. 0 3
      main/admin/skills_import.php
  62. 0 2
      main/admin/statistics.php
  63. 3 9
      main/admin/statistics/index.php
  64. 0 174
      main/admin/style_preview.php
  65. 1 3
      main/admin/user_add.php
  66. 1 3
      main/admin/user_edit.php
  67. 266 280
      main/admin/user_fields.php
  68. 108 144
      main/admin/user_fields_options.php
  69. 2 6
      main/admin/user_import.php
  70. 14 7
      main/admin/user_information.php
  71. 1 1
      main/admin/user_move_stats.php
  72. 0 1
      main/admin/usergroup_export.php
  73. 2 4
      main/admin/usergroup_import.php
  74. 0 3
      main/admin/usergroup_user_import.php
  75. 1 1
      main/auth/inscription.php
  76. 4 4
      main/auth/profile.php
  77. 17 15
      main/auth/sso/sso.class.php
  78. 1 1
      main/calendar/agenda_js.php
  79. 0 1
      main/course_info/infocours.php
  80. 1 1
      main/course_info/legal.php
  81. 0 2
      main/course_progress/index.php
  82. 1 1
      main/coursecopy/classes/CourseBuilder.class.php
  83. 1 1
      main/create_course/add_course.php
  84. 0 9
      main/css/academica/default.css
  85. 1 13
      main/css/baby_orange/default.css
  86. 36 31
      main/css/base.css
  87. 6 35
      main/css/blue_lagoon/default.css
  88. 491 261
      main/css/bootstrap-responsive.css
  89. 408 171
      main/css/bootstrap.css
  90. 2 28
      main/css/cool_blue/default.css
  91. 1 11
      main/css/corporate/default.css
  92. 0 13
      main/css/cosmic_campus/default.css
  93. 1 28
      main/css/delicious_bordeaux/default.css
  94. 0 36
      main/css/dokeos_blue/default.css
  95. 1 41
      main/css/dokeos_classic/default.css
  96. 2 36
      main/css/dokeos_classic_2D/default.css
  97. 34 5
      main/document/create_audio.php
  98. 0 1
      main/document/document_lite.php
  99. 16 0
      main/document/save_pixlr.php
  100. 12 9
      main/document/showinframes.php

+ 0 - 1
.hgignore

@@ -14,7 +14,6 @@ courses/*
 main/garbage/*
 !main/garbage/index.html
 !main/garbage/Serializer
-
 #Home
 home/*
 #!home/default_platform_document

+ 22 - 0
composer.json

@@ -0,0 +1,22 @@
+{       
+    "autoload": {
+        "psr-0": { "Chamilo": "src/" },
+        "classmap": [            
+            "main/auth",
+            "main/admin",
+            "main/cron/lang",
+            "main/coursecopy",
+            "main/exercice",
+            "main/gradebook/lib",
+            "main/newscorm",
+            "main/inc/lib",            
+            "main/install",        
+            "main/inc/lib/getid3",
+            "main/survey"
+        ]
+    },   
+    "require": {
+        "php": ">=5.3.2"      
+    },
+    "minimum-stability": "dev"
+}

+ 6 - 2
documentation/changelog.html

@@ -55,7 +55,11 @@
 <h3>New Features</h3>
 <h3>Improvements</h3>
 <h3>Debugging</h3>
-
+<h3>Important changes</h3>
+<ul>
+  <li>Users and sessions extra fields of "double select" type have a modified syntax. If you used this field type in a previous version of Chamilo, you will probably need to update it manually from the database.</li>
+  <li></li>
+</ul>
 
 <h1>Chamilo 1.9.0 - Vogüé, 31st of July, 2012</h1>
 
@@ -2177,4 +2181,4 @@ a simple videoconferencing interface.</p>
         <img src="http://jigsaw.w3.org/css-validator/images/vcss-blue" style="margin: 1em; float: right;" alt="Valid CSS" />
     </a>
 </body>
-</html>
+</html>

+ 1 - 1
main/admin/access_url_add_courses_to_url.php

@@ -14,8 +14,8 @@ $cidReset = true;
 require_once '../inc/global.inc.php';
 $this_section=SECTION_PLATFORM_ADMIN;
 
-require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
 api_protect_global_admin_script();
+
 if (!api_get_multiple_access_url()) {
 	header('Location: index.php');
 	exit;

+ 1 - 2
main/admin/access_url_add_users_to_url.php

@@ -12,9 +12,8 @@
 $language_file = 'admin';
 $cidReset = true;
 require_once '../inc/global.inc.php';
-$this_section=SECTION_PLATFORM_ADMIN;
+$this_section = SECTION_PLATFORM_ADMIN;
 
-require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
 api_protect_global_admin_script();
 if (!api_get_multiple_access_url()) {
 	header('Location: index.php');

+ 0 - 2
main/admin/access_url_check_user_session.php

@@ -11,8 +11,6 @@ $language_file = 'admin';
 $cidReset = true;
 require_once '../inc/global.inc.php';
 
-require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
-
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;
 

+ 0 - 2
main/admin/access_url_edit.php

@@ -18,8 +18,6 @@ if (!api_get_multiple_access_url()) {
 	exit;
 }
 
-require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
-
 // Create the form
 $form = new FormValidator('add_url');
 

+ 0 - 2
main/admin/access_url_edit_courses_to_url.php

@@ -13,8 +13,6 @@ $language_file = 'admin';
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
-require_once api_get_path(LIBRARY_PATH).'access_url_edit_courses_to_url_functions.lib.php';
 
 $xajax = new xajax();
 $xajax -> registerFunction (array('search_courses', 'Accessurleditcoursestourl', 'search_courses'));

+ 2 - 4
main/admin/access_url_edit_users_to_url.php

@@ -13,19 +13,17 @@ $language_file='admin';
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
-require_once api_get_path(LIBRARY_PATH).'access_url_edit_users_to_url_functions.lib.php';
 require_once '../inc/lib/xajax/xajax.inc.php';
 $xajax = new xajax();
-//$xajax->debugOn();
-$xajax -> registerFunction (array('search_users', 'Accessurledituserstourl', 'search_users'));
 
+$xajax -> registerFunction (array('search_users', 'Accessurledituserstourl', 'search_users'));
 
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;
 
 // Access restrictions
 api_protect_global_admin_script();
+
 if (!api_get_multiple_access_url()) {
 	header('Location: index.php');
 	exit;

+ 0 - 2
main/admin/access_urls.php

@@ -23,8 +23,6 @@ $interbreadcrumb[] = array ("url" => 'index.php', 'name' => get_lang('PlatformAd
 $tool_name = get_lang('MultipleAccessURLs');
 Display :: display_header($tool_name);
 
-require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
-
 $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
 $current_access_url_id = api_get_current_access_url_id();
 $url_list = UrlManager::get_url_data();

+ 0 - 2
main/admin/add_courses_to_session.php

@@ -15,8 +15,6 @@ require_once '../inc/global.inc.php';
 
 // including additonal libraries
 
-require_once api_get_path(LIBRARY_PATH).'add_courses_to_session_functions.lib.php';
-
 $id_session = intval($_GET['id_session']);
 
 SessionManager::protect_session_edit($id_session);

+ 0 - 2
main/admin/add_courses_to_usergroup.php

@@ -12,8 +12,6 @@ $cidReset = true;
 
 // including some necessary files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
-require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
 
 $xajax = new xajax();
 

+ 0 - 2
main/admin/add_many_session_to_category.php

@@ -11,8 +11,6 @@ $language_file='admin';
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'add_many_session_to_category_functions.lib.php';
-require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
 
 $xajax = new xajax();
 $xajax -> registerFunction ('search_courses');

+ 0 - 4
main/admin/add_sessions_to_promotion.php

@@ -12,10 +12,6 @@ $cidReset=true;
 
 // including some necessary files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
-require_once api_get_path(LIBRARY_PATH).'promotion.lib.php';
-require_once api_get_path(LIBRARY_PATH).'career.lib.php';
-require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
 
 $xajax = new xajax();
 

+ 0 - 2
main/admin/add_sessions_to_usergroup.php

@@ -12,8 +12,6 @@ $cidReset=true;
 
 // including some necessary files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
-require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
 
 $xajax = new xajax();
 

+ 0 - 1
main/admin/add_users_to_group.php

@@ -12,7 +12,6 @@ $cidReset=true;
 
 // including some necessary files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
 
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;

+ 68 - 45
main/admin/add_users_to_session.php

@@ -12,7 +12,6 @@ $cidReset = true;
 
 // including some necessary files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
 $xajax = new xajax();
 
 $xajax -> registerFunction ('search_users');
@@ -30,8 +29,6 @@ $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('Sessi
 $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
 
 // Database Table Definitions
-$tbl_session						= Database::get_main_table(TABLE_MAIN_SESSION);
-$tbl_course							= Database::get_main_table(TABLE_MAIN_COURSE);
 $tbl_user							= Database::get_main_table(TABLE_MAIN_USER);
 $tbl_session_rel_user				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
 
@@ -44,9 +41,9 @@ if(isset($_REQUEST['add_type']) && $_REQUEST['add_type']!=''){
 	$add_type = Security::remove_XSS($_REQUEST['add_type']);
 }
 
-//checking for extra field with filter on
+//Checking for extra field with filter on
 
-$extra_field_list= UserManager::get_extra_fields();
+$extra_field_list = UserManager::get_extra_fields();
 $new_field_list = array();
 if (is_array($extra_field_list)) {
 	foreach ($extra_field_list as $extra_field) {
@@ -101,7 +98,7 @@ function search_users($needle, $type) {
                 // search users where username or firstname or lastname begins likes $needle
                 $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
                         WHERE (username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%"
-                            OR lastname LIKE "'.$needle.'%") AND user.status<>6 AND user.status<>'.DRH.''.
+                            OR lastname LIKE "'.$needle.'%") AND user.status <> 6 AND user.status<>'.DRH.' '.$cond_user_id.' '.
                             $order_clause.
                             ' LIMIT 11';
                 break;
@@ -165,7 +162,6 @@ function search_users($needle, $type) {
 	            	$return .= '...<br />';
 	            }
 			}
-
 			$xajax_response -> addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));
 		} else {
 			global $nosessionUsersList;
@@ -181,11 +177,11 @@ function search_users($needle, $type) {
 	return $xajax_response;
 }
 
-$xajax -> processRequests();
+$xajax->processRequests();
 
 $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
 $htmlHeadXtra[] = '
-<script type="text/javascript">
+<script>
 function add_user_to_session (code, content) {
 	document.getElementById("user_to_add").value = "";
 	document.getElementById("ajax_list_users_single").innerHTML = "";
@@ -212,9 +208,9 @@ function remove_item(origin) {
 }
 
 function validate_filter() {
-		document.formulaire.add_type.value = \''.$add_type.'\';
-		document.formulaire.form_sent.value=0;
-		document.formulaire.submit();
+    document.formulaire.add_type.value = \''.$add_type.'\';
+    document.formulaire.form_sent.value=0;
+    document.formulaire.submit();
 }
 
 function checked_in_no_session(checked) {
@@ -235,17 +231,17 @@ function change_select(val) {
 $form_sent=0;
 $errorMsg=$firstLetterUser=$firstLetterSession='';
 $UserList=$SessionList=array();
-$sessions=array();
-$noPHP_SELF=true;
+$sessions = array();
+$noPHP_SELF = true;
 
-if($_POST['form_sent']) {
+if ($_POST['form_sent']) {
     $form_sent             = $_POST['form_sent'];
     $firstLetterUser       = $_POST['firstLetterUser'];
     $firstLetterSession    = $_POST['firstLetterSession'];
     $UserList              = $_POST['sessionUsersList'];
 
     if (!is_array($UserList)) {
-	$UserList=array();
+        $UserList=array();
     }
 
     if ($form_sent == 1) {
@@ -271,7 +267,11 @@ if ($ajax_search) {
             INNER JOIN $tbl_session_rel_user
                 ON $tbl_session_rel_user.id_user = u.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
                 AND $tbl_session_rel_user.id_session = ".intval($id_session)."
-                WHERE u.status<>".DRH." AND u.status<>6 $order_clause";
+                WHERE u.status<>".DRH." AND 
+                    u.status<>6 AND
+                    $tbl_session_rel_user.moved_to = 0 AND
+                    $tbl_session_rel_user.moved_status <> ".SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION."                        
+                $order_clause";
 
     if ($_configuration['multiple_access_urls']) {
         $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@@ -283,7 +283,11 @@ if ($ajax_search) {
                 ON $tbl_session_rel_user.id_user = u.user_id AND $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
                 AND $tbl_session_rel_user.id_session = ".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
+                WHERE   access_url_id = $access_url_id AND 
+                        u.status<>".DRH." AND 
+                        u.status<>6 AND 
+                        $tbl_session_rel_user.moved_to = 0 AND
+                        $tbl_session_rel_user.moved_status <> ".SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION."
                 $order_clause";
         }
     }
@@ -298,7 +302,7 @@ if ($ajax_search) {
     $use_extra_fields = false;
     if (is_array($extra_field_list)) {
         if (is_array($new_field_list) && count($new_field_list)>0 ) {
-            $result_list=array();
+            $result_list = array();
             foreach ($new_field_list as $new_field) {
                 $varname = 'field_'.$new_field['variable'];
                 if (UserManager::is_extra_field_available($new_field['variable'])) {
@@ -345,18 +349,26 @@ if ($ajax_search) {
         $sql = "SELECT  user_id, lastname, firstname, username, id_session
                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."
-                    $where_filter AND u.status<>".DRH." AND u.status<>6
+                    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."
+                    $where_filter AND 
+                    u.status<>".DRH." AND 
+                    u.status<>6                    
                     $order_clause";
 
     } else {
         $sql = "SELECT  user_id, lastname, firstname, username, id_session
                 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."
-                WHERE u.status<>".DRH." AND u.status<>6
+                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."
+                WHERE   u.status<>".DRH." AND 
+                        u.status<>6                         
                 $order_clause";
     }
+    
     if ($_configuration['multiple_access_urls']) {
         $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
         $access_url_id = api_get_current_access_url_id();
@@ -364,30 +376,40 @@ if ($ajax_search) {
             $sql = "SELECT  u.user_id, lastname, firstname, username, id_session
                     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  $where_filter AND u.status<>".DRH." AND u.status<>6 
+                        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  $where_filter 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) {
         if ($user['id_session'] != $id_session) {
             $nosessionUsersList[$user['user_id']] = array('fn'=>$user['firstname'],'ln'=>$user['lastname'],'un'=>$user['username']) ;
             unset($users[$uid]);
-	}
+        }
     }
     unset($users); //clean to free memory
 
-    //filling the correct users in list
-    $sql="SELECT  user_id, lastname, firstname, username, id_session
+    //Filling the correct users in list
+    $sql = "SELECT  user_id, lastname, firstname, username, id_session
           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."
-          WHERE u.status<>".DRH." AND u.status<>6 $order_clause";
+          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."
+          WHERE u.status <> ".DRH." AND 
+                u.status <> 6 AND 
+                $tbl_session_rel_user.moved_to = 0 AND
+                $tbl_session_rel_user.moved_status <> ".SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION." 
+          $order_clause";
 
     if ($_configuration['multiple_access_urls']) {
         $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@@ -398,12 +420,18 @@ if ($ajax_search) {
                 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
+                WHERE   access_url_id = $access_url_id AND 
+                        u.status<>".DRH." AND 
+                        u.status<>6 AND 
+                        $tbl_session_rel_user.moved_to = 0 AND
+                        $tbl_session_rel_user.moved_status <> ".SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION." 
+                                                
                 $order_clause";
         }
     }
-    $result=Database::query($sql);
-    $users=Database::store_result($result,'ASSOC');
+    
+    $result = Database::query($sql);
+    $users = Database::store_result($result,'ASSOC');
     foreach ($users as $uid => $user) {
         if ($user['id_session'] == $id_session) {
             $sessionUsersList[$user['user_id']] = $user;
@@ -416,6 +444,7 @@ if ($ajax_search) {
     unset($users); //clean to free memory
 }
 
+
 if ($add_type == 'multiple') {
 	$link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
 	$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple');
@@ -428,6 +457,7 @@ if ($add_type == 'multiple') {
 <div class="actions">
 	<?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>&nbsp;|&nbsp;<?php echo $link_add_group; ?>
 </div>
+
 <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?page=<?php echo Security::remove_XSS($_GET['page']); ?>&id_session=<?php echo $id_session; ?><?php if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
 <?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?>
 <?php
@@ -562,7 +592,6 @@ unset($sessionUsersList);
         } else {
             //@todo see that the call to "valide()" doesn't duplicate the onsubmit of the form (necessary to avoid delete on "enter" key pressed)
 			echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeUsersToSession').'</button>';
-
         }
 		?>
 	</td>
@@ -570,11 +599,10 @@ unset($sessionUsersList);
 </table>
 </form>
 
-<script type="text/javascript">
+<script>
 <!--
 function moveItem(origin , destination){
-
-	for(var i = 0 ; i<origin.options.length ; i++) {
+	for (var i = 0 ; i<origin.options.length ; i++) {
 		if(origin.options[i].selected) {
 			destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
 			origin.options[i]=null;
@@ -587,7 +615,6 @@ function moveItem(origin , destination){
 }
 
 function sortOptions(options) {
-
 	newOptions = new Array();
 	for (i = 0 ; i<options.length ; i++)
 		newOptions[i] = options[i];
@@ -618,9 +645,7 @@ function valide(){
 
 
 function loadUsersInSelect(select){
-
 	var xhr_object = null;
-
 	if(window.XMLHttpRequest) // Firefox
 		xhr_object = new XMLHttpRequest();
 	else if(window.ActiveXObject) // Internet Explorer
@@ -633,7 +658,6 @@ function loadUsersInSelect(select){
 
 	xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 
-
 	nosessionUsers = makepost(document.getElementById('origin_users'));
 	sessionUsers = makepost(document.getElementById('destination_users'));
 	nosessionClasses = makepost(document.getElementById('origin_classes'));
@@ -648,8 +672,7 @@ function loadUsersInSelect(select){
 	}
 }
 
-function makepost(select){
-
+function makepost(select) {
 	var options = select.options;
 	var ret = "";
 	for (i = 0 ; i<options.length ; i++)

+ 0 - 1
main/admin/add_users_to_usergroup.php

@@ -12,7 +12,6 @@ $cidReset = true;
 
 // including some necessary files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
 
 // setting the section (for the tabs)
 $this_section = SECTION_PLATFORM_ADMIN;

+ 0 - 2
main/admin/career_dashboard.php

@@ -6,8 +6,6 @@ $language_file = array('courses', 'index', 'admin');
 $cidReset = true;
 require_once '../inc/global.inc.php';
 $libpath = api_get_path(LIBRARY_PATH);
-require_once $libpath.'career.lib.php';
-require_once $libpath.'promotion.lib.php';
 
 require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
 require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';

+ 0 - 1
main/admin/careers.php

@@ -10,7 +10,6 @@ $language_file = array('admin');
 
 $cidReset = true;
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'career.lib.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 

+ 88 - 0
main/admin/change_user_session.php

@@ -0,0 +1,88 @@
+<?php
+
+/* For licensing terms, see /license.txt */
+$language_file = 'admin';
+$cidReset = true;
+require_once '../inc/global.inc.php';
+
+$user_id = intval($_REQUEST['user_id']);
+$session_id = intval($_REQUEST['id_session']);
+
+if (empty($user_id) && empty($session_id)) {
+    api_not_allowed(true);
+}
+
+SessionManager::protect_session_edit($session_id);
+
+if (api_is_platform_admin()) {
+    $sessions = SessionManager::get_sessions_admin(array('order' => 'name'));
+} else {
+    $sessions = SessionManager::get_sessions_by_general_coach(api_get_session_id());
+}
+
+$message = null;
+$session_to_select = array();
+foreach ($sessions as $session) {
+    if ($session_id != $session['id']) {
+        $session_to_select[$session['id']] = $session['name'];
+    }
+}
+
+$session_name = api_get_session_name($session_id);
+$user_info = api_get_user_info($user_id);
+
+//Check if user was already moved
+$user_status = SessionManager::get_user_status_in_session($session_id, $user_id);
+if (isset($user_status['moved_to']) && $user_status['moved_to'] != 0 || $user_status['moved_status'] == SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION) {
+    api_not_allowed(true);
+}
+
+$form = new FormValidator('change_user_session', 'post', api_get_self());
+$form->addElement('hidden', 'user_id', $user_id);
+$form->addElement('hidden', 'id_session', $session_id);
+$form->addElement('header', get_lang('ChangeUserSession'));
+$form->addElement('label', get_lang('User'), '<b>'.$user_info['complete_name'].'</b>');
+$form->addElement('label', get_lang('CurrentSession'), $session_name);
+
+$form->addElement('select', 'reason_id', get_lang('Action'), SessionManager::get_session_change_user_reasons(), array('id' => 'reason_id'));
+$form->addElement('select', 'new_session_id', get_lang('SessionDestination'), $session_to_select, array('id' => 'new_session_id'));
+
+$form->addElement('button', 'submit', get_lang('Change'));
+
+$content = $form->return_form();
+
+if ($form->validate()) {
+    $values = $form->getSubmitValues();
+    $result = SessionManager::change_user_session($values['user_id'], $values['id_session'], $values['new_session_id'], $values['reason_id']);
+    if ($result) {
+        $message = Display::return_message(get_lang('UserSessionWasChanged'));
+    }
+    header('Location: resume_session.php?id_session='.$values['id_session']);
+    exit;
+}
+
+$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
+$interbreadcrumb[] = array('url' => 'resume_session.php?id_session='.$session_id,'name' => get_lang('SessionOverview'));
+$interbreadcrumb[] = array('url' => '#','name' => get_lang('ChangeUserSession'));
+
+$htmlHeadXtra[] = '<script>
+
+$(document).ready(function() {
+    $("#reason_id").change(function() {
+        value = $(this).val();
+        if (value == "'.SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION.'") {
+            $("#new_session_id").parent().parent().hide();
+        } else {
+            $("#new_session_id").parent().parent().show();
+        }
+    });
+});
+
+</script>';
+
+$tpl = new Template();
+
+$tpl->assign('message', $message);
+$tpl->assign('content', $content);
+$tpl->display_one_col_template();

+ 0 - 1
main/admin/class_user_import.php

@@ -139,7 +139,6 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'import.lib.php';
 require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php';
 

+ 1 - 2
main/admin/configure_inscription.php

@@ -13,7 +13,6 @@ require_once '../inc/global.inc.php';
 api_protect_admin_script();
 
 require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';
-require_once api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php';
 
 // Load terms & conditions from the current lang
 if (get_setting('allow_terms_conditions') == 'true') {
@@ -277,7 +276,7 @@ if ($display_all_form) {
         }
     }
     $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
-    UserManager::set_extra_fields_in_form($form, $extra_data, 'registration');
+    ExtraField::set_extra_fields_in_form($form, $extra_data, 'registration', false, null, 'user');
 }
 
 // Terms and conditions

+ 0 - 2
main/admin/course_add.php

@@ -16,8 +16,6 @@ $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-
 $tool_name = get_lang('AddCourse');
 $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
 $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));

+ 2 - 2
main/admin/course_category.php

@@ -290,7 +290,7 @@ function addNode($code,$name,$canHaveCourses,$parent_id)
 
 	$tree_pos=$row['maxTreePos']+1;
 	
-	$code = generate_course_code($code);
+	$code = CourseManager::generate_course_code($code);
 	Database::query("INSERT INTO $tbl_category(name,code,parent_id,tree_pos,children_count,auth_course_child) VALUES('$name','$code',".(empty($parent_id)?"NULL":"'$parent_id'").",'$tree_pos','0','$canHaveCourses')");
 
 	updateFils($parent_id);
@@ -313,7 +313,7 @@ function editNode($code,$name,$canHaveCourses,$old_code)
 			return false;
 		}
 	}
-	$code = generate_course_code($code);
+	$code = CourseManager::generate_course_code($code);
 	Database::query("UPDATE $tbl_category SET name='$name', code='$code',auth_course_child='$canHaveCourses' WHERE code='$old_code'");
 	$sql = "UPDATE $tbl_course SET category_code = '$code' WHERE category_code = '$old_code' ";	
 	Database::query($sql);

+ 1 - 3
main/admin/course_edit.php

@@ -12,8 +12,6 @@ $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-
 $course_table       = Database::get_main_table(TABLE_MAIN_COURSE);
 $course_user_table  = Database::get_main_table(TABLE_MAIN_COURSE_USER);
 
@@ -198,7 +196,7 @@ if ($form->validate()) {
 	$dbName = $_POST['dbName'];
 	$course_code = $course['code'];
 	$visual_code = $course['visual_code'];	
-	$visual_code = generate_course_code($visual_code);   
+	$visual_code = CourseManager::generate_course_code($visual_code);   
 
     // Check if the visual code is already used by *another* course
     $visual_code_is_used = false;

+ 1 - 2
main/admin/course_import.php

@@ -153,12 +153,11 @@ $language_file = array('admin', 'registration','create_course', 'document');
 
 $cidReset = true;
 
-require '../inc/global.inc.php';
+require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'import.lib.php';
 $defined_auth_sources[] = PLATFORM_AUTH_SOURCE;
 

+ 1 - 11
main/admin/course_request_accepted.php

@@ -18,22 +18,12 @@ $language_file = array('admin', 'create_course');
 
 $cidReset = true;
 
-require '../inc/global.inc.php';
+require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
-require_once api_get_path(CONFIGURATION_PATH).'course_info.conf.php';
-require_once api_get_path(LIBRARY_PATH).'course_request.lib.php';
-
-// Including a configuration file.
-require api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
-
-// Include additional libraries
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-
 // A check whether the course validation feature is enabled.
 $course_validation_feature = api_get_setting('course_validation') == 'true';
 

+ 0 - 11
main/admin/course_request_edit.php

@@ -19,17 +19,6 @@ $tool_name = get_lang('CourseRequestEdit');
 
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
-require_once api_get_path(CONFIGURATION_PATH).'course_info.conf.php';
-require_once api_get_path(LIBRARY_PATH).'course_request.lib.php';
-require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-
-// Including a configuration file.
-require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
-
-// Including additional libraries.
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-
 // A check whether the course validation feature is enabled.
 $course_validation_feature = api_get_setting('course_validation') == 'true';
 

+ 3 - 14
main/admin/course_request_rejected.php

@@ -24,17 +24,6 @@ $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
-require_once api_get_path(CONFIGURATION_PATH).'course_info.conf.php';
-require_once api_get_path(LIBRARY_PATH).'course_request.lib.php';
-require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-
-// Including a configuration file.
-require api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
-
-// Including additional libraries.
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-
 // A check whether the course validation feature is enabled.
 $course_validation_feature = api_get_setting('course_validation') == 'true';
 
@@ -48,9 +37,9 @@ $keyword = Database::escape_string(trim($_GET['keyword']));
 
 if ($course_validation_feature) {
 
-/**
- * Acceptance and creation of the requested course.
- */
+    /**
+     * Acceptance and creation of the requested course.
+     */
     if (!empty($accept_course_request)) {
         $course_request_code = CourseRequestManager::get_course_request_code($accept_course_request);
         $course_id = CourseRequestManager::accept_course_request($accept_course_request);

+ 1 - 12
main/admin/course_request_review.php

@@ -16,22 +16,11 @@
 $language_file = array('admin', 'create_course');
 
 $cidReset = true;
-require '../inc/global.inc.php';
+require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
-require_once api_get_path(CONFIGURATION_PATH).'course_info.conf.php';
-require_once api_get_path(LIBRARY_PATH).'course_request.lib.php';
-require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-
-// Including a configuration file.
-require_once api_get_path(CONFIGURATION_PATH).'add_course.conf.php';
-
-// Including additional libraries.
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-
 // The delete action should be deactivated in this page.
 // Better reject the target request, after that you can delete it.
 define(DELETE_ACTION_ENABLED, false);

+ 0 - 5
main/admin/course_user_import.php

@@ -155,12 +155,7 @@ $this_section = SECTION_PLATFORM_ADMIN;
 // Protecting the admin section.
 api_protect_admin_script();
 
-// Including additional libraries.
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
-
 $tool_name = get_lang('AddUsersToACourse').' CSV';
-
 $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
 
 set_time_limit(0);

+ 0 - 3
main/admin/dashboard_add_courses_to_user.php

@@ -13,11 +13,8 @@ $cidReset=true;
 
 // including some necessary dokeos files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
 
 global $_configuration;
-
-
 // create an ajax object
 $xajax = new xajax();
 $xajax -> registerFunction ('search_courses');

+ 0 - 1
main/admin/dashboard_add_sessions_to_user.php

@@ -13,7 +13,6 @@ $cidReset=true;
 
 // including some necessary dokeos files
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php';
 global $_configuration;
 
 // create an ajax object

+ 0 - 1
main/admin/dashboard_add_users_to_user.php

@@ -13,7 +13,6 @@ $cidReset=true;
 
 // including some necessary dokeos files
 require_once '../inc/global.inc.php';
-require_once '../inc/lib/xajax/xajax.inc.php';
 
 global $_configuration;
 

+ 2 - 2
main/admin/example_session.csv

@@ -1,3 +1,3 @@
 SessionName;Coach;DateStart;DateEnd;Users;Courses
-Session1;jmontoya;2008/08/08;2012/12/12;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]
-Session2;jmontoya;2008/08/08;2012/12/12;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]
+Session1;jmontoya;2012-06-30 11:00:00;2016-06-30 11:00:00;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]
+Session2;jmontoya;2012-06-30 11:00:00;2016-06-30 11:00:00;username1|username2;course1[coach1][username1,username2]|course2[coach1][username1,username2]

+ 2 - 2
main/admin/example_session.xml

@@ -24,8 +24,8 @@
     <Session>
         <SessionName>The Universe</SessionName>
         <Coach>Coach</Coach>
-        <DateStart>2008/08/01</DateStart>
-        <DateEnd>2020/12/12</DateEnd>
+        <DateStart>2012-06-30 11:00:00</DateStart>
+        <DateEnd>2016-06-30 11:00:00</DateEnd>
         <User>jmontoya</User>
         <User>jmontoya2</User>
     	<Course>

+ 164 - 0
main/admin/extra_field_options.php

@@ -0,0 +1,164 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ *  @package chamilo.admin
+ */
+
+// Language files that need to be included.
+$language_file = array('admin');
+
+$cidReset = true;
+require_once '../inc/global.inc.php';
+
+$this_section = SECTION_PLATFORM_ADMIN;
+
+api_protect_admin_script();
+
+//Add the JS needed to use the jqgrid
+$htmlHeadXtra[] = api_get_jqgrid_js();
+
+// setting breadcrumbs
+$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
+
+$tool_name = null;
+
+$action = isset($_GET['action']) ? $_GET['action'] : null;
+$field_id = isset($_GET['field_id']) ? $_GET['field_id'] : null;
+$type = 'session';
+
+if (empty($field_id)) {
+    api_not_allowed();
+}
+
+$extra_field = new ExtraField($type);
+$extra_field_info = $extra_field->get($field_id);
+
+
+$check = Security::check_token('request');
+$token = Security::get_token();    
+
+if ($action == 'add') {
+    $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields'));
+    $interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
+    $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
+    $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
+} elseif ($action == 'edit') {
+    $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields'));
+    $interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
+    $interbreadcrumb[]=array('url' => 'extra_field_options.php?type='.$type.'&field_id='.$extra_field_info['id'], 'name' => get_lang('EditExtraFieldOptions'));
+    
+    $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
+} else {
+    $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('ExtraFields'));
+    $interbreadcrumb[]=array('url' => 'session_fields.php?action=edit&id='.$extra_field_info['id'],'name' => $extra_field_info['field_display_text']);
+    $interbreadcrumb[]=array('url' => '#','name' => get_lang('EditExtraFieldOptions'));
+}
+
+//jqgrid will use this URL to do the selects
+$params = 'field_id='.$field_id.'&type='.$type;
+$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_field_options&'.$params;
+
+//The order is important you need to check the the $column variable in the model.ajax.php file 
+$columns        = array(get_lang('Name'), get_lang('Value'),  get_lang('Order'), get_lang('Actions'));
+  
+//Column config
+$column_model   = array(
+                        array('name'=>'option_display_text', 'index'=>'option_display_text',      'width'=>'180',   'align'=>'left'),
+                        array('name'=>'option_value',       'index'=>'option_value',          'width'=>'',  'align'=>'left','sortable'=>'false'),
+                        array('name'=>'option_order',         'index'=>'option_order',              'width'=>'',  'align'=>'left','sortable'=>'false'),
+                        array('name'=>'actions',            'index'=>'actions',                 'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
+                       );            
+//Autowidth             
+$extra_params['autowidth'] = 'true';
+//height auto 
+$extra_params['height'] = 'auto'; 
+
+//With this function we can add actions to the jgrid (edit, delete, etc)
+$action_links = 'function action_formatter(cellvalue, options, rowObject) {
+                         return \'<a href="?action=edit&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
+                         '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&'.$params.'&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
+                         '\'; 
+                 }';
+$htmlHeadXtra[]='
+<script>
+$(function() {
+    // grid definition see the $obj->display() function
+    '.Display::grid_js('extra_field_options',  $url, $columns, $column_model, $extra_params, array(), $action_links, true).'
+    
+});
+</script>';
+
+// The header.
+Display::display_header($tool_name);
+
+echo Display::page_header($extra_field_info['field_display_text']);
+
+$obj = new ExtraFieldOption($type);
+$obj->field_id = $field_id;
+
+// Action handling: Add
+switch ($action) {
+    case 'add':
+        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
+            api_not_allowed();
+        }        
+        $url  = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&'.$params;
+        $form = $obj->return_form($url, 'add');
+
+        // The validation or display
+        if ($form->validate()) {
+            if ($check) {
+                $values = $form->exportValues();
+                $res    = $obj->save_one_item($values);            
+                if ($res) {
+                    Display::display_confirmation_message(get_lang('ItemAdded'));
+                }
+            }        
+            $obj->display();
+        } else {
+            /*echo '<div class="actions">';
+            echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
+            echo '</div>';            */
+            $form->addElement('hidden', 'sec_token');
+            $form->setConstants(array('sec_token' => $token));
+            $form->display();
+        }
+        break;
+    case 'edit':
+        // Action handling: Editing 
+        $url  = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']).'&'.$params;
+        $form = $obj->return_form($url, 'edit');    
+
+        // The validation or display
+        if ($form->validate()) {            
+            if ($check) {
+                $values = $form->exportValues();                
+                $res    = $obj->update($values);                
+                Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false);                
+            }            
+            $obj->display();
+        } else {
+            /*echo '<div class="actions">';
+            echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
+            echo '</div>';*/
+            $form->addElement('hidden', 'sec_token');
+            $form->setConstants(array('sec_token' => $token));
+            $form->display();
+        }
+        break;
+    case 'delete':
+        // Action handling: delete
+        if ($check) {
+            $res = $obj->delete($_GET['id']);
+            if ($res) {
+                Display::display_confirmation_message(get_lang('ItemDeleted'));
+            }
+        }
+        $obj->display();
+        break;
+    default:
+        $obj->display();   
+        break;
+}
+Display :: display_footer();

+ 0 - 1
main/admin/grade_models.php

@@ -10,7 +10,6 @@ $language_file = array('admin', 'gradebook');
 
 $cidReset = true;
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'grade_model.lib.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 

+ 0 - 1
main/admin/group_add.php

@@ -12,7 +12,6 @@ $cidReset = true;
 // Including necessary libraries.
 require '../inc/global.inc.php';
 $libpath = api_get_path(LIBRARY_PATH);
-require_once $libpath.'fileManage.lib.php';
 require_once $libpath.'fileUpload.lib.php';
 
 // Section for the tabs

+ 0 - 3
main/admin/group_edit.php

@@ -12,10 +12,7 @@ $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script();
 
 $libpath = api_get_path(LIBRARY_PATH);
-require_once $libpath.'fileManage.lib.php';
 require_once $libpath.'fileUpload.lib.php';
-require_once $libpath.'group_portal_manager.lib.php';
-require_once $libpath.'mail.lib.inc.php';
 
 $group_id = isset($_GET['id']) ? intval($_GET['id']) : intval($_POST['id']);
 $tool_name = get_lang('GroupEdit');

+ 0 - 2
main/admin/group_list.php

@@ -10,8 +10,6 @@
 $language_file = array ('registration','admin','userInfo');
 $cidReset = true;
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php';
-require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);

+ 0 - 4
main/admin/inactive_user_list.php

@@ -13,10 +13,6 @@
 $language_file = array ('registration','admin');
 $cidReset = true;
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'sortable_table.class.php';
-require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
-require_once api_get_path(LIBRARY_PATH).'security.lib.php';
-require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
 
 $tbl_stats_access 		= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
 $this_section = SECTION_PLATFORM_ADMIN;

+ 2 - 2
main/admin/index.php

@@ -14,7 +14,6 @@ $cidReset = true;
 
 // Including some necessary chamilo files.
 require_once '../inc/global.inc.php';
-require_once api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.lib.php';
 
 // Setting the section (for the tabs).
 $this_section = SECTION_PLATFORM_ADMIN;
@@ -202,6 +201,7 @@ if (api_is_platform_admin()) {
 }
 
 $items[] = array('url'=>'usergroups.php', 	'label' => get_lang('Classes'));
+$items[] = array('url'=>'session_fields.php', 	'label' => get_lang('ManageSessionFields'));
 
 $blocks['sessions']['items'] = $items;
 $blocks['sessions']['extra'] = null;
@@ -375,7 +375,7 @@ function check_system_version() {
 
     if (ini_get('allow_url_fopen') == 1) {
         // The number of courses
-        $number_of_courses = statistics::count_courses();
+        $number_of_courses = Statistics::count_courses();
 
         // The number of users
         $number_of_users = statistics::count_users();

+ 0 - 1
main/admin/languages.php

@@ -23,7 +23,6 @@ $cidReset = true;
 
 // include global script
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'sortable_table.class.php';
 require_once 'sub_language.class.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 

+ 4 - 12
main/admin/ldap_import_students_to_session.php

@@ -87,18 +87,10 @@ elseif(!empty($annee) && empty($id_session))
 	echo Display::return_icon('course.gif', get_lang('SelectSessionToImportUsersTo')).' '.get_lang('SelectSessionToImportUsersTo').'<br />';
 	echo '<form method="post" action="'.api_get_self().'?annee='.Security::remove_XSS($annee).'"><br />';
 	echo '<select name="id_session">';
-
-	$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
-	$sql = "SELECT id,name,nbr_courses,date_start,date_end " .
-		" FROM $tbl_session ".
-		" ORDER BY name";
-	$result = Database::query($sql);
-
-	$sessions=Database::store_result($result);
-	$nbr_results=count($sessions);
-	foreach($sessions as $row)
-	{
-		echo '<option value="'.$row['id'].'">'.api_htmlentities($row['name'], ENT_COMPAT, api_get_system_encoding()).' ('.$row['date_start'].' - '.$row['date_end'].')</option>';
+    
+    $sessions = SessionManager::get_sessions_list();	
+	foreach ($sessions as $row) {
+		echo '<option value="'.$row['id'].'">'.api_htmlentities($row['name'], ENT_COMPAT, api_get_system_encoding()).' ('.api_get_local_time($row['access_start_date']).' - '.api_get_local_time($row['access_end_date']).')</option>';
 	}
 	echo '</select>';
 	echo '<input type="submit" value="'.get_lang('Submit').'">';

+ 213 - 198
main/admin/resume_session.php

@@ -23,42 +23,18 @@ $tool_name = get_lang('SessionOverview');
 $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
 $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
 
-// Database Table Definitions
-$tbl_session						= Database::get_main_table(TABLE_MAIN_SESSION);
-$tbl_session_rel_class				= Database::get_main_table(TABLE_MAIN_SESSION_CLASS);
-$tbl_session_rel_course				= Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-$tbl_course							= Database::get_main_table(TABLE_MAIN_COURSE);
-$tbl_user							= Database::get_main_table(TABLE_MAIN_USER);
-$tbl_session_rel_user				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
-$tbl_session_rel_course_rel_user	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-$tbl_session_category				= Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
-
-$table_access_url_user              = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
-
-$sql = 'SELECT name, nbr_courses, nbr_users, nbr_classes, DATE_FORMAT(date_start,"%d-%m-%Y") as date_start, DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, lastname, firstname, username, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility
-		FROM '.$tbl_session.' LEFT JOIN '.$tbl_user.' ON id_coach = user_id
-		WHERE '.$tbl_session.'.id='.$id_session;
-
-$rs      = Database::query($sql);
-$session = Database::store_result($rs);
-$session = $session[0];
-
-$sql = 'SELECT name FROM  '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"';
-$rs = Database::query($sql);
-$session_category = '';
-
-if (Database::num_rows($rs)>0) {
-	$rows_session_category = Database::store_result($rs);
-	$rows_session_category = $rows_session_category[0];
-	$session_category = $rows_session_category['name'];
+$session = api_get_session_info($id_session);
+$session_cat_info = SessionManager::get_session_category($session['session_category_id']);
+$session_category = null;
+if (!empty($session_cat_info)) {
+    $session_category = $session_cat_info['name'];
 }
 
 $action = $_GET['action'];
 
 $url_id = api_get_current_access_url_id();     
 
-
-switch($action) {
+switch ($action) {
     case 'add_user_to_url':        
         $user_id = $_REQUEST['user_id'];
         $result = UrlManager::add_user_to_url($user_id, $url_id);
@@ -68,42 +44,15 @@ switch($action) {
         }
         break;
     case 'delete':
-        $idChecked = $_GET['idChecked'];
-        if(is_array($idChecked)) {
-            $my_temp = array();
-            foreach ($idChecked as $id){
-                $my_temp[]= Database::escape_string($id);// forcing the escape_string
-            }
-            $idChecked = $my_temp;
-
-            $idChecked="'".implode("','",$idChecked)."'";
-
-            Database::query("DELETE FROM $tbl_session_rel_course WHERE id_session='$id_session' AND course_code IN($idChecked)");
-            $nbr_affected_rows=Database::affected_rows();
-
-            Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code IN($idChecked)");
-            Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
+        if (isset($_GET['course_code_to_delete'])) {
+            SessionManager::delete_course_in_session($id_session, $_GET['course_code_to_delete']);
         }
-
-        if(!empty($_GET['class'])){
-            Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".Database::escape_string($_GET['class']));
-            $nbr_affected_rows=Database::affected_rows();
-            Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'");
-        }
-
         if (!empty($_GET['user'])) {
-            Database::query("DELETE FROM $tbl_session_rel_user WHERE relation_type<>".SESSION_RELATION_TYPE_RRHH." AND id_session='$id_session' AND id_user=".intval($_GET['user']));
-            $nbr_affected_rows=Database::affected_rows();
-
-            Database::query("UPDATE $tbl_session SET nbr_users=nbr_users-$nbr_affected_rows WHERE id='$id_session'");
-
-            Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND id_user=".intval($_GET['user']));
-            $nbr_affected_rows=Database::affected_rows();
-
-            Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE id_session='$id_session'");
+            SessionManager::unsubscribe_user_from_session($id_session, $_GET['user']);            
         }
         break;
 }
+
 Display::display_header($tool_name);
 
 if (!empty($_GET['warn'])) {
@@ -113,18 +62,20 @@ if (!empty($_GET['warn'])) {
 if (!empty($message)) {
     echo $message;
 }
+$dates = SessionManager::parse_session_dates($session);
+echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']." <small>$dates</small>");
 
-echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']);
-
-$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "session_edit.php?page=resume_session.php&id=$id_session");
+$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "session_add.php?page=resume_session.php&id=$id_session");
 echo Display::page_subheader(get_lang('GeneralProperties').$url);
 
+$coach_info = api_get_user_info($session['id_coach']);
+
 ?>
 <!-- General properties -->
 <table class="data_table">
 <tr>
 	<td><?php echo get_lang('GeneralCoach'); ?> :</td>
-	<td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
+	<td><?php echo $coach_info['complete_name'].' ('.$coach_info['username'].')' ?></td>
 </tr>
 <?php if(!empty($session_category)) { ?>
 <tr>
@@ -133,57 +84,73 @@ echo Display::page_subheader(get_lang('GeneralProperties').$url);
 </tr>
 <?php } ?>
 <tr>
-	<td><?php echo get_lang('Date'); ?> :</td>
-	<td>
-	<?php
-		if ($session['date_start'] == '00-00-0000' && $session['date_end']== '00-00-0000' )
-			echo get_lang('NoTimeLimits');
-		else {
-            if ($session['date_start'] != '00-00-0000') {
-            	//$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits'));
-                $session['date_start'] =  get_lang('From').' '.$session['date_start'];
-            } else {
-            	$session['date_start'] = '';
-            }
-            if ($session['date_end'] == '00-00-0000') {
-                $session['date_end'] ='';
-            } else {
-            	$session['date_end'] = get_lang('Until').' '.$session['date_end'];
-            }
-			echo $session['date_start'].' '.$session['date_end'];
-        }
-        ?>
-	</td>
+	<td><?php echo get_lang('SessionDisplayStartDate'); ?> :</td>
+	<td><?php echo api_get_local_time($session['display_start_date'], null, null, true); ?></td>    
 </tr>
-<!-- show nb_days_before and nb_days_after only if they are different from 0 -->
 <tr>
-	<td>
-		<?php echo api_ucfirst(get_lang('DaysBefore')) ?> :
-	</td>
-	<td>
-		<?php echo intval($session['nb_days_access_before_beginning']) ?>
-	</td>
+    <td><?php echo get_lang('SessionDisplayEndDate'); ?> :</td>
+	<td><?php echo api_get_local_time($session['display_end_date'], null, null, true); ?></td>
 </tr>
-<tr>
-	<td>
-		<?php echo api_ucfirst(get_lang('DaysAfter')) ?> :
-	</td>
-	<td>
-		<?php echo intval($session['nb_days_access_after_end']) ?>
-	</td>
+<tr>    
+    <td><?php echo get_lang('SessionStartDate'); ?> :</td>
+	<td><?php echo api_get_local_time($session['access_start_date'], null, null, true); ?></td>
+</tr>
+<tr>    
+    <td><?php echo get_lang('SessionEndDate'); ?> :</td>
+	<td><?php echo api_get_local_time($session['access_end_date'], null, null, true); ?></td>
+</tr>
+<tr>    
+    <td><?php echo get_lang('SessionCoachStartDate'); ?> :</td>
+	<td><?php echo api_get_local_time($session['coach_access_start_date'], null, null, true); ?></td>
+</tr>
+<tr>    
+    <td><?php echo get_lang('SessionCoachEndDate'); ?> :</td>
+	<td><?php echo api_get_local_time($session['coach_access_end_date'], null, null, true); ?></td>
 </tr>
 <tr>
 	<td>
 		<?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
 	</td>
 	<td>
-		<?php if ($session['visibility']==1) echo get_lang('ReadOnly'); elseif($session['visibility']==2) echo get_lang('Visible');elseif($session['visibility']==3) echo api_ucfirst(get_lang('Invisible'))  ?>
+		<?php        
+        if (isset($session['access_end_date']) && $session['access_end_date'] != '0000-00-00 00:00:00') {            
+            if ($session['visibility'] == 1) 
+                echo get_lang('ReadOnly'); 
+             elseif($session['visibility'] == 2) 
+                 echo get_lang('Visible');
+             elseif($session['visibility'] == 3) 
+                echo api_ucfirst(get_lang('Invisible'));
+        } else {
+            //By default course sessions can be access normally see function api_get_session_visibility() when no date_end is proposed            
+            echo get_lang('Visible'); 
+        }
+        ?>
 	</td>
 </tr>
 
-<?php 
+<?php
+
+$session_field = new SessionField();
+$session_fields = $session_field->get_all();
+foreach ($session_fields as $session_field) {
+    if ($session_field['field_visible'] != '1') {
+        continue;        
+    }
+    $obj = new SessionFieldValue();
+    $result = $obj->get_values_by_handler_and_field_id($id_session, $session_field['id'], true);
+    
+    $session_value = null;
+    if ($result) {
+        $session_value = $result['field_value'];
+    }    
+    echo "<tr>";
+    echo "<td> {$session_field['field_display_text']} </td>";
+    echo "<td> $session_value </td>";
+    echo "</tr>";    
+}
 
-$multiple_url_is_on = api_get_multiple_access_url();
+
+$multiple_url_is_on = api_is_multiple_url_enabled();
 
 if ($multiple_url_is_on) {
     echo '<tr><td>';   
@@ -191,7 +158,7 @@ if ($multiple_url_is_on) {
     echo '</td>';
     echo '<td>';
     $url_list = UrlManager::get_access_url_from_session($id_session);
-    foreach($url_list as $url_data) {
+    foreach ($url_list as $url_data) {
         echo $url_data['url'].'<br />';
     }        
     echo '</td></tr>';
@@ -220,60 +187,26 @@ if ($session['nbr_courses'] == 0){
 	echo '<tr>
 			<td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
 		</tr>';
-} else {
-	// select the courses
-	$sql = "SELECT code,title,visual_code, nbr_users
-			FROM $tbl_course,$tbl_session_rel_course
-			WHERE course_code = code
-			AND	id_session='$id_session'
-			ORDER BY title";
-	$result=Database::query($sql);
-	$courses=Database::store_result($result);
+} else {    
+    $courses = SessionManager::get_course_list_by_session_id($id_session);	
 	foreach ($courses as $course) {
-		//select the number of users
-
-		$sql = " SELECT count(*) 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 sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND srcru.id_session = '".intval($id_session)."'";
-
-		$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 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($id_session)."' AND session_rcru.course_code ='".Database::escape_string($course['code'])."' AND session_rcru.status=2";
-		$rs = Database::query($sql);
-
-		$coachs = array();
-		if (Database::num_rows($rs) > 0) {
-			while($info_coach = Database::fetch_array($rs)) {
-				$coachs[] = api_get_person_name($info_coach['firstname'], $info_coach['lastname']).' ('.$info_coach['username'].')';
-			}
-		} else {
-			$coach = get_lang('None');
-		}
-
-		if (count($coachs) > 0) {
-			$coach = implode('<br />',$coachs);
-		} else {
-			$coach = get_lang('None');
-		}
+        $count_users = SessionManager::get_count_users_in_course_session($course['code'], $id_session);
+        $coaches = SessionManager::get_session_course_coaches_to_string($course['code'], $id_session);
 
 		$orig_param = '&origin=resume_session';
 		//hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
 		echo '
 		<tr>
 			<td>'.Display::url($course['title'].' ('.$course['visual_code'].')', api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session),'</td>
-			<td>'.$coach.'</td>
-			<td>'.$course['nbr_users'].'</td>
+			<td>'.$coaches.'</td>
+			<td>'.$count_users.'</td>
 			<td>
                 <a href="'.api_get_path(WEB_COURSE_PATH).$course['code'].'/?id_session='.$id_session.'">'.Display::return_icon('course_home.gif', get_lang('Course')).'</a>   
                 <a href="session_course_user_list.php?id_session='.$id_session.'&course_code='.$course['code'].'">'.Display::return_icon('user.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
                 <a href="'.api_get_path(WEB_CODE_PATH).'/user/user_import.php?action=import&cidReq='.$course['code'].'&id_session='.$id_session.'">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), null, ICON_SIZE_SMALL).'</a>   
 				<a href="../tracking/courseLog.php?id_session='.$id_session.'&cidReq='.$course['code'].$orig_param.'&hide_course_breadcrumb=1">'.Display::return_icon('statistics.gif', get_lang('Tracking')).'</a>&nbsp;                
 				<a href="session_course_edit.php?id_session='.$id_session.'&page=resume_session.php&course_code='.$course['code'].''.$orig_param.'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
-				<a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&idChecked[]='.$course['code'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>
+				<a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&course_code_to_delete='.$course['code'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>
 			</td>
 		</tr>';
 	}
@@ -286,7 +219,7 @@ if ($session['nbr_courses'] == 0){
 
 $url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "add_users_to_session.php?page=resume_session.php&id_session=$id_session");
 $url .= Display::url(Display::return_icon('import_csv.png', get_lang('ImportUsers'), array(), ICON_SIZE_SMALL), "session_user_import.php?id_session=$id_session");
-echo Display::page_subheader(get_lang('UserList').$url);
+echo Display::page_subheader(get_lang('StudentList').$url);
 
 ?>
 
@@ -297,68 +230,150 @@ echo Display::page_subheader(get_lang('UserList').$url);
         <th>
             <?php echo get_lang('User'); ?>
         </th>
+        <th>
+            <?php echo get_lang('Status'); ?>
+        </th>
+        <th>
+            <?php echo get_lang('Information'); ?>
+        </th>
+        <th>
+            <?php echo get_lang('Destination'); ?>
+        </th>
+        <th>
+            <?php echo get_lang('MovedAt'); ?>
+        </th>
         <th>
             <?php echo get_lang('Actions'); ?>
         </th>
     </tr>
 <?php
-
-if ($session['nbr_users']==0) {
-	echo '<tr>
-			<td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
-		</tr>';
+/*
+if ($session['nbr_users'] == 0) {
+	
 } else {    
-	$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
+*/
+	$orig_param = '&origin=resume_session&id_session='.$id_session; // change breadcrumb in destination page
+    
+    $users = SessionManager::get_users_by_session($id_session, 0);        
+    //$reasons = SessionManager::get_session_change_user_reasons();
     
-    if ($multiple_url_is_on) {           
-        $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 = $id_session AND (access_url_id = $url_id OR access_url_id is null )
-                $order_clause";
+    if (!empty($users)) {
+        foreach ($users as $user) {
+            $user_info = api_get_user_info($user['user_id']);
+            //$link_class = 'class="item_disabled"';
+            $link_class = null;
+            $user_status_in_platform = Display::return_icon('error.png', get_lang('Inactive'));
+            $information = '';
+            $moved_date = '-';
+            
+            if ($user_info['active'] == 1 ) {
+                $user_status_in_platform = Display::return_icon('accept.png', get_lang('Active'));                
+                //$link_class = null;
+            } else {
+                $status_info = get_latest_event_by_user_and_type($user['user_id'], LOG_USER_DEACTIVATED);
+                //var_dump($status_info);
+                if (!empty($status_info)) {
+                    $information .= sprintf(get_lang('UserInactivedSinceX'), api_convert_and_format_date($status_info['default_date'], DATE_TIME_FORMAT_LONG));
+                    $moved_date = api_get_local_time($status_info['default_date']);
+                }
+                $user_info['complete_name_with_username'] = Display::tag('del', $user_info['complete_name_with_username']);
+            }
+            
+            $user_link = '';            
+            if (!empty($user['user_id'])) {
+                $user_link = '<a '.$link_class.' href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.$user_info['complete_name_with_username'].'</a>';
+            }
+            $origin = null;
+            $destination = null;
+            $row_style = null;
+
+            $course_link = '<a href="session_course_user.php?id_user='.$user['user_id'].'&id_session='.$id_session.'">'.Display::return_icon('course.gif', get_lang('BlockCoursesForThisUser')).'&nbsp;</a>';
+            $moved_link =  '<a href="change_user_session.php?user_id='.$user['user_id'].'&id_session='.$id_session.'">'.Display::return_icon('move.png', get_lang('ChangeUserSession')).'</a>&nbsp;';
+
+            //User in this session is subscribed but was moved to another session
+            if (isset($user['moved_to']) && !empty($user['moved_to']) || $user['moved_status'] == SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION) {
+                
+                $variation = SessionManager::get_session_change_user_reasons_variations_by_id($user['moved_status'], 'to');
+                //$information = $reasons[$user['moved_status']].$variation;
+                $information .= $variation;
+
+                $moved_date = isset($user['moved_at']) && $user['moved_at'] != '0000-00-00 00:00:00' ? api_get_local_time($user['moved_at']) : '-';                        
+                $session_info = SessionManager::fetch($user['moved_to']);
+
+                if ($user['moved_status'] != SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION) {
+                    $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$id_session;                
+                    //$origin = Display::url($session['name'], $url);                
+
+                    if ($session_info) {
+                        $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_info['id'];
+                        $destination = Display::url($session_info['name'], $url);
+                        //$destination = $destination;
+                    }            
+                }
+                $row_style = 'style = " background-color: #ddd;"';
+                $course_link=  Display::return_icon('course_na.gif', get_lang('BlockCoursesForThisUser')).'&nbsp;';
+                $moved_link =  Display::return_icon('move_na.png', get_lang('ChangeUserSession')).'&nbsp;';
+                $delete_link = Display::return_icon('delete_na.png', get_lang('Delete')).'&nbsp;';
+            } else {          
+                $session_origin_info = SessionManager::get_session_rel_user_by_moved_to($id_session, $user['user_id']);
+
+                if (!empty($session_origin_info)) {
+                   $moved_date = api_get_local_time($session_origin_info['moved_at']);
+                }            
+                $session_info = SessionManager::fetch($session_origin_info['id_session']);
+                
+                $variation = SessionManager::get_session_change_user_reasons_variations_by_id($session_origin_info['moved_status'], 'from');
+                
+                //$information = $reasons[$session_origin_info['moved_status']].$variation;
+                $information .= $variation;
+
+                if ($session_info) {
+                    $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_info['id'];
+                    $origin = Display::url($session_info['name'], $url);
+
+                    $url = api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$id_session;                
+                    //$destination = Display::url($session['name'], $url);
+                    //$destination = ' / '.$destination;
+                }
+
+                $delete_link = '<a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&user='.$user['user_id'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>';
+
+            }
+
+            $link_to_add_user_in_url = '';
+
+            if ($multiple_url_is_on) {
+                if ($user['access_url_id'] != $url_id) {            
+                    $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), array(), ICON_SIZE_SMALL);
+                    $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), array(), ICON_SIZE_SMALL);
+                    $link_to_add_user_in_url = '<a href="resume_session.php?action=add_user_to_url&id_session='.$id_session.'&user_id='.$user['user_id'].'">'.$add.'</a>';
+                }                
+            }
+
+            echo '<tr '.$row_style.'>
+                    <td width="30%">
+                        '.$user_link.'
+                    </td>
+                    <td>'.$user_status_in_platform.'</td>
+                    <td>'.$information.'</td>
+                    <td>'.$origin.' '.$destination.'</td>
+                    <td>'.$moved_date.'</td>
+                    <td>
+                        <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
+                        '.$course_link.'
+                        '.$moved_link.'
+                        '.$delete_link.'
+                        '.$link_to_add_user_in_url.'
+                    </td>
+                    </tr>';
+        }
     } else {
-        $sql = "SELECT u.user_id, lastname, firstname, username
-                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."
-                AND su.id_session = ".$id_session.$order_clause;
+        echo '<tr>
+			<td colspan="2">'.get_lang('NoUsersForThisSession').'</td>
+		</tr>';
     }
 
-	$result = Database::query($sql);
-	$users  = Database::store_result($result);
-	$orig_param = '&origin=resume_session&id_session='.$id_session; // change breadcrumb in destination page
-	foreach ($users as $user){
-        $user_link = '';
-        if (!empty($user['user_id'])) {
-            $user_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.intval($user['user_id']).'">'.api_htmlentities(api_get_person_name($user['firstname'], $user['lastname']),ENT_QUOTES,$charset).' ('.$user['username'].')</a>';
-        }
-        
-        $link_to_add_user_in_url = '';
-        
-        if ($multiple_url_is_on) {
-            if ($user['access_url_id'] != $url_id) {            
-                $user_link .= ' '.Display::return_icon('warning.png', get_lang('UserNotAddedInURL'), array(), ICON_SIZE_SMALL);
-                $add = Display::return_icon('add.png', get_lang('AddUsersToURL'), array(), ICON_SIZE_SMALL);
-                $link_to_add_user_in_url = '<a href="resume_session.php?action=add_user_to_url&id_session='.$id_session.'&user_id='.$user['user_id'].'">'.$add.'</a>';
-            }                
-        }
-		echo '<tr>
-                <td width="90%">
-                    '.$user_link.'
-                </td>
-                <td>               
-                    <a href="../mySpace/myStudents.php?student='.$user['user_id'].''.$orig_param.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;
-                    <a href="session_course_user.php?id_user='.$user['user_id'].'&id_session='.$id_session.'">'.Display::return_icon('course.gif', get_lang('BlockCoursesForThisUser')).'</a>&nbsp;
-                    <a href="'.api_get_self().'?id_session='.$id_session.'&action=delete&user='.$user['user_id'].'" onclick="javascript:if(!confirm(\''.get_lang('ConfirmYourChoice').'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>
-                    '.$link_to_add_user_in_url.'
-                </td>
-                </tr>';
-	}
-}
 ?>
 </table>
 <?php
-// footer
-Display :: display_footer();
+Display :: display_footer();

+ 264 - 405
main/admin/session_add.php

@@ -7,443 +7,302 @@
 */
 
 // name of the language file that needs to be included
-$language_file='admin';
+$language_file = 'admin';
 
-$cidReset=true;
+$cidReset = true;
 
 // including the global Chamilo file
 require_once '../inc/global.inc.php';
 
-// including additional libraries
-require_once '../inc/lib/xajax/xajax.inc.php';
-
-$xajax = new xajax();
-//$xajax->debugOn();
-$xajax -> registerFunction ('search_coachs');
-
 // setting the section (for the tabs)
-$this_section=SECTION_PLATFORM_ADMIN;
+$this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script(true);
 
 $formSent=0;
 $errorMsg='';
 
-$interbreadcrumb[]=array('url' => 'index.php',       'name' => get_lang('PlatformAdmin'));
-$interbreadcrumb[]=array('url' => 'session_list.php','name' => get_lang('SessionList'));
-
-// Database Table Definitions
-$tbl_user		= Database::get_main_table(TABLE_MAIN_USER);
-
-function search_coachs($needle) {
-	global $tbl_user;
-
-	$xajax_response = new XajaxResponse();
-	$return = '';
-
-	if(!empty($needle)) {
-		// xajax send utf8 datas... datas in db can be non-utf8 datas
-		$charset = api_get_system_encoding();
-		$needle = api_convert_encoding($needle, $charset, 'utf-8');
-
-		$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
-
-		// search users where username or firstname or lastname begins likes $needle
-		$sql = 'SELECT username, lastname, firstname FROM '.$tbl_user.' user
-				WHERE (username LIKE "'.$needle.'%"
-				OR firstname LIKE "'.$needle.'%"
-				OR lastname LIKE "'.$needle.'%")
-				AND status=1'.
-				$order_clause.
-				' LIMIT 10';
-
-		global $_configuration;
-		if ($_configuration['multiple_access_urls']) {
-			$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 username, lastname, firstname FROM '.$tbl_user.' user
-				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 (username LIKE "'.$needle.'%"
-				OR firstname LIKE "'.$needle.'%"
-				OR lastname LIKE "'.$needle.'%")
-				AND status=1'.
-				$order_clause.
-				' LIMIT 10';
-
-			}
-		}
-
-		$rs = Database::query($sql);
-		while ($user = Database :: fetch_array($rs)) {
-			$return .= '<a href="javascript: void(0);" onclick="javascript: fill_coach_field(\''.$user['username'].'\')">'.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')</a><br />';
-		}
-	}
-	$xajax_response -> addAssign('ajax_list_coachs','innerHTML', api_utf8_encode($return));
-	return $xajax_response;
-}
-$xajax -> processRequests();
+$interbreadcrumb[] = array('url' => 'index.php',       'name' => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
+
+$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
+$htmlHeadXtra[] = '<link  href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
+$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui-i18n'));
 
-$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
+$htmlHeadXtra = api_get_datetime_picker_js($htmlHeadXtra);
 
-$htmlHeadXtra[] = '
-<script type="text/javascript">
-function fill_coach_field (username) {
-	document.getElementById("coach_username").value = username;
-	document.getElementById("ajax_list_coachs").innerHTML = "";
+$id = null;
+$url_action = api_get_self();
+if (isset($_GET['id'])) {
+   $id = intval($_GET['id']);
+   $url_action = '?id='.$id;
+}
+
+$add_coach = null;
+
+if ($id) {
+    $tool_name = get_lang('EditSession');    
+    SessionManager::protect_session_edit($id);    
+    $session_info = api_get_session_info($id);    
+    if (!empty($session_info['id_coach'])) {
+        $user_info = api_get_user_info($session_info['id_coach']);        
+        $add_coach = '$("#coach_id").trigger("addItem", [{"title": "'.$user_info['complete_name'].'", "value": "'.$session_info['id_coach'].'"}]);';
+    }
+    $button = get_lang('Update');    
+} else {
+    $tool_name = get_lang('AddSession');
+    $button = get_lang('Add');
 }
-</script>';
 
+$url = api_get_path(WEB_AJAX_PATH).'admin.ajax.php?1=1';
+
+$htmlHeadXtra[] ='
+<script>
+function check() {
+    $("#coach_id option:selected").each(function() {
+        var id = $(this).val();
+        var name = $(this).text();        
+        if (id != "" ) {
+            $.ajax({ 
+                async: false,
+                url: "'.$url.'&a=user_exists", 
+                data: "id="+id,
+                success: function(return_value) {                    
+                    if (return_value == 0 ) {                        
+                        alert("'.get_lang('UserDoesNotExist').'");                        
+                        //Deleting select option tag
+                        $("#coach_id").find("option").remove();
+                        
+                        $(".holder li").each(function () {
+                            if ($(this).attr("rel") == id) {
+                                $(this).remove();
+                            }
+                        });
+                    }
+                },            
+            });                
+        }
+    });
+}
 
-if ($_POST['formSent']) {
-	$formSent = 1;
-	$name                  = $_POST['name'];
-	$year_start            = $_POST['year_start'];
-	$month_start           = $_POST['month_start'];
-	$day_start             = $_POST['day_start'];
-	$year_end              = $_POST['year_end'];
-	$month_end             = $_POST['month_end'];
-	$day_end               = $_POST['day_end'];
-	$nb_days_acess_before  = $_POST['nb_days_acess_before'];
-	$nb_days_acess_after   = $_POST['nb_days_acess_after'];
-	//$nolimit               = $_POST['nolimit'];
-	$coach_username        = $_POST['coach_username'];
-	$id_session_category   = $_POST['session_category'];
-	$id_visibility         = $_POST['session_visibility'];
+$(function() {
+
+    $("#coach_id").fcbkcomplete({
+        json_url: "'.$url.'&a=find_coaches",
+        maxitems: 1,
+        addontab: false,
+        input_min_size: 1,
+        cache: false,
+        complete_text:"'.get_lang('StartToType').'",
+        firstselected: false,        
+        onselect: check,
+        filter_selected: true,
+        newel: true           
+    });
+    
+    '.$add_coach.'        
+
+    $("#display_end_date").datetimepicker({
+        dateFormat: "yy-mm-dd",
+        hour: 9,        
+        onSelect: function(selectedDateTime) {
+            var start = $(this).datetimepicker("getDate");
+            
+            if (!$("#access_end_date").val()) {
+                $("#access_end_date").val(selectedDateTime);
+            }
+            
+            if (!$("#coach_access_end_date").val()) {
+                $("#coach_access_end_date").val(selectedDateTime);
+            }
+        }
+    });
+    
+    $("#display_start_date").datetimepicker({
+        dateFormat: "yy-mm-dd",
+        hour: 9,        
+        onSelect: function(selectedDateTime) {
+            var start = $(this).datetimepicker("getDate");
+            
+            if (!$("#access_start_date").val()) {
+                $("#access_start_date").val(selectedDateTime);
+            }
+            
+            if (!$("#coach_access_start_date").val()) {
+                $("#coach_access_start_date").val(selectedDateTime);
+            }
+        }
+    });
+    
+    $("#access_start_date").datetimepicker({
+        dateFormat: "yy-mm-dd",
+        hour: 9,
+        onSelect: function(selectedDateTime) {
+            var start = $(this).datetimepicker("getDate");        
+            //$("#access_end_date").val(selectedDateTime);                    
+        }
+    });
     
-    $end_limit             = $_POST['end_limit'];
-    $start_limit           = $_POST['start_limit'];  
+    access_start_date_content = $("#access_end_date").val();
     
-    if (empty($end_limit) && empty($start_limit)) {
-        $nolimit = 1;
+    if (access_start_date_content.length > 0) {
+        $("#visibility_container").show();
     } else {
-    	$nolimit = null;
-    }    
-	$return = SessionManager::create_session($name,$year_start,$month_start,$day_start,$year_end,$month_end,$day_end,$nb_days_acess_before,$nb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit, $end_limit);
-
-	if ($return == strval(intval($return))) {
-		// integer => no error on session creation
-		header('Location: add_courses_to_session.php?id_session='.$return.'&add=true&msg=');
-		exit();
-	}
-}
-
-$nb_days_acess_before = 0;
-$nb_days_acess_after = 0;
-
-$thisYear=date('Y');
-$thisMonth=date('m');
-$thisDay=date('d');
+        $("#visibility_container").hide();
+    }
+    
+    $("#access_end_date").datetimepicker({
+        dateFormat: "yy-mm-dd",
+        onSelect: function(selectedDateTime) {            
+            $("#visibility_container").show();
+        }
+    });
+    
+    $("#access_end_date").on("change", function() {        
+        content = $(this).val();
+        if (content.length > 0) {
+            $("#visibility_container").show();
+        } else {
+            $("#visibility_container").hide();
+        }
+        
+    });
+    
+    $("#coach_access_start_date").datetimepicker({
+        dateFormat: "yy-mm-dd",
+        hour: 9,
+        onSelect: function(selectedDateTime) {
+            var start = $(this).datetimepicker("getDate");        
+            //$("#coach_access_end_date").val(selectedDateTime);
+        }
+    });
+    
+    $("#coach_access_end_date").datetimepicker({
+        dateFormat: "yy-mm-dd"
+    });
+
+    var value = 1;
+    $("#advanced_parameters").on("click", function() {    
+        $("#options").toggle(function() {        
+            if (value == 1) {
+                $("#advanced_parameters").addClass("btn-hide");        
+                value = 0;
+            } else {
+                $("#advanced_parameters").removeClass("btn-hide");      
+                value = 1;
+            }
+        });
+    });
+    
+});
+</script>';
 
-$tool_name = get_lang('AddSession');
+$form = new FormValidator('add_session', 'post', $url_action);
+$form->addElement('header', $tool_name);
 
-Display::display_header($tool_name);
+//Name
+$form->addElement('text', 'name', get_lang('SessionName'), array('class' => 'span6'));
+$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
 
-if (!empty($return)) {
-	Display::display_error_message($return,false);
-}
-echo '<div class="actions">';
-echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).'</a>';
-echo '</div>';
-
-?>
-<form class="form-horizontal" method="post" name="form" action="<?php echo api_get_self(); ?>" style="margin:0px;">
-    <input type="hidden" name="formSent" value="1">
-    <div class="control-group">
-        <label class="control-label">
-            <?php echo get_lang('SessionName') ?>
-        </label>
-        <div class="controls">
-            <input type="text" name="name" class="span4" maxlength="50" value="<?php if($formSent) echo api_htmlentities($name,ENT_QUOTES,$charset); ?>">
-        </div>        
-    </div>   
-  
-    <div class="control-group">
-        <label class="control-label">
-            <?php echo get_lang('CoachName') ?>
-        </label>
-        <div class="controls">
-  
-<?php
-
-$sql = 'SELECT COUNT(1) FROM '.$tbl_user.' WHERE status=1';
-$rs = Database::query($sql);
-$count_users = Database::result($rs, 0, 0);
-
-if (intval($count_users)<50) {
-	$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
-	$sql="SELECT user_id, lastname,firstname,username FROM $tbl_user WHERE status='1'".$order_clause;
-	
-	global $_configuration;
-	if ($_configuration['multiple_access_urls']) {
-		$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 user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
-			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 status=1'.$order_clause;
-		}
-	}
-	$result = Database::query($sql);
-	$Coaches = Database::store_result($result);
-	
-	?>
-	<select id="coach_username" class="chzn-select" name="coach_username" style="width:350px;" title="<?php echo get_lang('Select'); ?>" >
-		<option value="0"><?php get_lang('None'); ?></option>
-		<?php foreach($Coaches as $enreg): ?>
-		<option value="<?php echo $enreg['username']; ?>"> <?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
-		<?php endforeach; ?>
-	</select>
-	<?php
-	echo Display::return_icon('synthese_view.gif',get_lang('ActivityCoach'));
+if (empty($id)) {    
+    $form->addRule('name', get_lang('SessionNameAlreadyExists'), 'callback', 'check_session_name');
 } else {
-	?>
-	<input type="text" name="coach_username" id="coach_username" onkeyup="xajax_search_coachs(document.getElementById('coach_username').value)" /><div id="ajax_list_coachs"></div>
-	<?php
+    $form->addElement('hidden', 'id', $id);
 }
-$Categories = SessionManager::get_all_session_category();
-?>	
-        </div>        
-    </div>
-  
-
-
-    <div class="control-group">
-        <label class="control-label">
-            <?php echo get_lang('SessionCategory') ?>
-        </label>
-        <div class="controls">
-            <select id="session_category" class="chzn-select" name="session_category" style="width:350px;" title="<?php echo get_lang('Select'); ?>">
-                <option value="0"><?php get_lang('None'); ?></option>       
-            <?php 
-            if (!empty($Categories)) {
-                foreach($Categories as $Rows) { ?>
-                    <option value="<?php echo $Rows['id']; ?>" <?php if($Rows['id'] == $id_session_category) echo 'selected="selected"'; ?>><?php echo $Rows['name']; ?></option>
-                <?php }
-            }
-            ?>
-        </select>
-        </div>        
-    </div>   
-    
- <div class="control-group">
-        <div class="controls">
-            <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('DefineSessionOptions') ?></a>
-        <div style="display: <?php if($formSent && ($nb_days_acess_before!=0 || $nb_days_acess_after!=0)) echo 'block'; else echo 'none'; ?>;" id="options">
-            <br />
-            <input type="text" name="nb_days_acess_before" value="<?php echo $nb_days_acess_before; ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?><br /><br />
-            <input type="text" name="nb_days_acess_after" value="<?php echo $nb_days_acess_after; ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
-            <br />
-        </div>
-        </div>        
-</div>   
-    
- <div class="control-group">        
-        <div class="controls">                
-    <label for="start_limit">
-        <input id="start_limit" type="checkbox" name="start_limit" onchange="disable_starttime(this)" />
-    <?php echo get_lang('DateStartSession');?>
-    </label> 
- 
-    <div id="start_date" style="display:none">
-       <br />
-    
-  <select name="day_start">
-	<option value="1">01</option>
-	<option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_start == 2)) echo 'selected="selected"'; ?> >02</option>
-	<option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_start == 3)) echo 'selected="selected"'; ?> >03</option>
-	<option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_start == 4)) echo 'selected="selected"'; ?> >04</option>
-	<option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_start == 5)) echo 'selected="selected"'; ?> >05</option>
-	<option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_start == 6)) echo 'selected="selected"'; ?> >06</option>
-	<option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_start == 7)) echo 'selected="selected"'; ?> >07</option>
-	<option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_start == 8)) echo 'selected="selected"'; ?> >08</option>
-	<option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_start == 9)) echo 'selected="selected"'; ?> >09</option>
-	<option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_start == 10)) echo 'selected="selected"'; ?> >10</option>
-	<option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_start == 11)) echo 'selected="selected"'; ?> >11</option>
-	<option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_start == 12)) echo 'selected="selected"'; ?> >12</option>
-	<option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_start == 13)) echo 'selected="selected"'; ?> >13</option>
-	<option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_start == 14)) echo 'selected="selected"'; ?> >14</option>
-	<option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_start == 15)) echo 'selected="selected"'; ?> >15</option>
-	<option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_start == 16)) echo 'selected="selected"'; ?> >16</option>
-	<option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_start == 17)) echo 'selected="selected"'; ?> >17</option>
-	<option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_start == 18)) echo 'selected="selected"'; ?> >18</option>
-	<option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_start == 19)) echo 'selected="selected"'; ?> >19</option>
-	<option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_start == 20)) echo 'selected="selected"'; ?> >20</option>
-	<option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_start == 21)) echo 'selected="selected"'; ?> >21</option>
-	<option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_start == 22)) echo 'selected="selected"'; ?> >22</option>
-	<option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_start == 23)) echo 'selected="selected"'; ?> >23</option>
-	<option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_start == 24)) echo 'selected="selected"'; ?> >24</option>
-	<option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_start == 25)) echo 'selected="selected"'; ?> >25</option>
-	<option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_start == 26)) echo 'selected="selected"'; ?> >26</option>
-	<option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_start == 27)) echo 'selected="selected"'; ?> >27</option>
-	<option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_start == 28)) echo 'selected="selected"'; ?> >28</option>
-	<option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_start == 29)) echo 'selected="selected"'; ?> >29</option>
-	<option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_start == 30)) echo 'selected="selected"'; ?> >30</option>
-	<option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_start == 31)) echo 'selected="selected"'; ?> >31</option>
-  </select>
-  /
-  <select name="month_start">
-	<option value="1">01</option>
-	<option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_start == 2)) echo 'selected="selected"'; ?> >02</option>
-	<option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_start == 3)) echo 'selected="selected"'; ?> >03</option>
-	<option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_start == 4)) echo 'selected="selected"'; ?> >04</option>
-	<option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_start == 5)) echo 'selected="selected"'; ?> >05</option>
-	<option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_start == 6)) echo 'selected="selected"'; ?> >06</option>
-	<option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_start == 7)) echo 'selected="selected"'; ?> >07</option>
-	<option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_start == 8)) echo 'selected="selected"'; ?> >08</option>
-	<option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_start == 9)) echo 'selected="selected"'; ?> >09</option>
-	<option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_start == 10)) echo 'selected="selected"'; ?> >10</option>
-	<option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_start == 11)) echo 'selected="selected"'; ?> >11</option>
-	<option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_start == 12)) echo 'selected="selected"'; ?> >12</option>
-  </select>
-  /
-  <select name="year_start">
-<?php
-for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
-?>
-	<option value="<?php echo $i; ?>" <?php if((!$formSent && $thisYear == $i) || ($formSent && $year_start == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
-<?php
+//Coaches
+//$coaches = SessionManager::get_user_list();
+$form->addElement('select', 'id_coach', get_lang('CoachName'), array(),array('id' => 'coach_id'));
+$form->addRule('id_coach', get_lang('ThisFieldIsRequired'), 'required');
+
+$form->addElement('advanced_settings','<a class="btn btn-show" id="advanced_parameters" href="javascript://">'.get_lang('AdvancedParameters').'</a>');
+$form->addElement('html','<div id="options" style="display:none">');
+
+//Dates
+$form->addElement('text', 'display_start_date', array(get_lang('SessionDisplayStartDate'), get_lang('SessionDisplayStartDateComment')), array('id' => 'display_start_date'));
+$form->addElement('text', 'display_end_date', array(get_lang('SessionDisplayEndDate'), get_lang('SessionDisplayEndDateComment')), array('id' => 'display_end_date'));
+$form->addRule(array('display_start_date', 'display_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '< allow_empty');
+     
+$form->addElement('text', 'access_start_date', array(get_lang('SessionStartDate'), get_lang('SessionStartDateComment')), array('id' => 'access_start_date'));
+$form->addElement('text', 'access_end_date', array(get_lang('SessionEndDate'), get_lang('SessionEndDateComment')), array('id' => 'access_end_date'));
+$form->addRule(array('access_start_date', 'access_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '< allow_empty');
+
+//Visibility
+$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
+
+$form->addElement('html','<div id="visibility_container">');
+$form->addElement('select', 'visibility', get_lang('SessionVisibility'), $visibility_list, array('id' => 'visibility'));
+$form->addElement('html','</div>');
+
+$form->addElement('text', 'coach_access_start_date', array(get_lang('SessionCoachStartDate'), get_lang('SessionCoachStartDateComment')), array('id' => 'coach_access_start_date'));
+$form->addElement('text', 'coach_access_end_date', array(get_lang('SessionCoachEndDate'), get_lang('SessionCoachEndDateComment')), array('id' => 'coach_access_end_date'));
+$form->addRule(array('coach_access_start_date', 'coach_access_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '< allow_empty');
+
+//Session categories
+
+$categories = SessionManager::get_all_session_category();
+
+$select_categories = array();
+if (!empty($categories)) {
+    $select_categories = array('0' => get_lang('None'));
+    foreach ($categories as $row) {
+        $select_categories[$row['id']] = $row['name'];
+    }
 }
-?>
-    </select>  
-    </div>
-       
-        </div>        
-    </div>   
+$form->addElement('select', 'session_category_id', get_lang('SessionCategory'), $select_categories, array('id' => 'session_category_id_name', 'class' => null));
 
+//Extra session fields
+$session_field = new SessionField();
+$extra = $session_field->add_elements($form, $id);
 
-    
- <div class="control-group">
-        <div class="controls">            
-            <label for="end_limit">
-                <input id="end_limit" type="checkbox" name="end_limit" onchange="disable_endtime(this)" />
-                <?php echo get_lang('DateEndSession') ?>
-            </label>
-  <div id="end_date" style="display:none">
-  <br />
-  
-  <select name="day_end">
-	<option value="1">01</option>
-	<option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_end == 2)) echo 'selected="selected"'; ?> >02</option>
-	<option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_end == 3)) echo 'selected="selected"'; ?> >03</option>
-	<option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_end == 4)) echo 'selected="selected"'; ?> >04</option>
-	<option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_end == 5)) echo 'selected="selected"'; ?> >05</option>
-	<option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_end == 6)) echo 'selected="selected"'; ?> >06</option>
-	<option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_end == 7)) echo 'selected="selected"'; ?> >07</option>
-	<option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_end == 8)) echo 'selected="selected"'; ?> >08</option>
-	<option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_end == 9)) echo 'selected="selected"'; ?> >09</option>
-	<option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_end == 10)) echo 'selected="selected"'; ?> >10</option>
-	<option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_end == 11)) echo 'selected="selected"'; ?> >11</option>
-	<option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_end == 12)) echo 'selected="selected"'; ?> >12</option>
-	<option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_end == 13)) echo 'selected="selected"'; ?> >13</option>
-	<option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_end == 14)) echo 'selected="selected"'; ?> >14</option>
-	<option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_end == 15)) echo 'selected="selected"'; ?> >15</option>
-	<option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_end == 16)) echo 'selected="selected"'; ?> >16</option>
-	<option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_end == 17)) echo 'selected="selected"'; ?> >17</option>
-	<option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_end == 18)) echo 'selected="selected"'; ?> >18</option>
-	<option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_end == 19)) echo 'selected="selected"'; ?> >19</option>
-	<option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_end == 20)) echo 'selected="selected"'; ?> >20</option>
-	<option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_end == 21)) echo 'selected="selected"'; ?> >21</option>
-	<option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_end == 22)) echo 'selected="selected"'; ?> >22</option>
-	<option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_end == 23)) echo 'selected="selected"'; ?> >23</option>
-	<option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_end == 24)) echo 'selected="selected"'; ?> >24</option>
-	<option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_end == 25)) echo 'selected="selected"'; ?> >25</option>
-	<option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_end == 26)) echo 'selected="selected"'; ?> >26</option>
-	<option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_end == 27)) echo 'selected="selected"'; ?> >27</option>
-	<option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_end == 28)) echo 'selected="selected"'; ?> >28</option>
-	<option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_end == 29)) echo 'selected="selected"'; ?> >29</option>
-	<option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_end == 30)) echo 'selected="selected"'; ?> >30</option>
-	<option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_end == 31)) echo 'selected="selected"'; ?> >31</option>
-  </select>
-  /
-  <select name="month_end">
-	<option value="1">01</option>
-	<option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_end == 2)) echo 'selected="selected"'; ?> >02</option>
-	<option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_end == 3)) echo 'selected="selected"'; ?> >03</option>
-	<option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_end == 4)) echo 'selected="selected"'; ?> >04</option>
-	<option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_end == 5)) echo 'selected="selected"'; ?> >05</option>
-	<option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_end == 6)) echo 'selected="selected"'; ?> >06</option>
-	<option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_end == 7)) echo 'selected="selected"'; ?> >07</option>
-	<option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_end == 8)) echo 'selected="selected"'; ?> >08</option>
-	<option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_end == 9)) echo 'selected="selected"'; ?> >09</option>
-	<option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_end == 10)) echo 'selected="selected"'; ?> >10</option>
-	<option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_end == 11)) echo 'selected="selected"'; ?> >11</option>
-	<option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_end == 12)) echo 'selected="selected"'; ?> >12</option>
-  </select>
-  /
-  <select name="year_end">
 
-<?php
-for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
-?>
-	<option value="<?php echo $i; ?>" <?php if((!$formSent && ($thisYear+1) == $i) || ($formSent && $year_end == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
-<?php
-}
-?>
-    </select>
-    <br />    <br />
-    <?php echo get_lang('SessionVisibility') ?>
-    <select name="session_visibility" style="width:250px;">
-        <?php
-        $visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
-        foreach($visibility_list as $key=>$item): ?>
-        <option value="<?php echo $key; ?>" <?php if($item == $visibility_id) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
-        <?php endforeach; ?>
-    </select>    
-     </div>  
-       
-        </div>        
-    </div>   
-    
-    
- <div class="control-group">        
-    <div class="controls">
-        <button class="save" type="submit" value="<?php echo get_lang('NextStep') ?>"><?php echo get_lang('NextStep') ?></button>
-    </div>
-</div>
-</form>
-<script type="text/javascript">
-
-function setDisable(select){
-	document.form.day_start.disabled = (select.checked) ? true : false;
-	document.form.month_start.disabled = (select.checked) ? true : false;
-	document.form.year_start.disabled = (select.checked) ? true : false;
-
-	document.form.day_end.disabled = (select.checked) ? true : false;
-	document.form.month_end.disabled = (select.checked) ? true : false;
-	document.form.year_end.disabled = (select.checked) ? true : false;
-
-	document.form.session_visibility.disabled = (select.checked) ? true : false;
-	document.form.session_visibility.selectedIndex = 0;
-    
-    document.form.start_limit.disabled = (select.checked) ? true : false;
-    document.form.start_limit.checked = false;
-    document.form.end_limit.disabled = (select.checked) ? true : false;
-    document.form.end_limit.checked = false;
-       
-    var end_div = document.getElementById('end_date');
-    end_div.style.display = 'none';
-        
-    var start_div = document.getElementById('start_date');
-    start_div.style.display = 'none';        
+$htmlHeadXtra[] ='
+<script>
+
+$(function() {
+    '.$extra['jquery_ready_content'].'
+});
+</script>';
+
+$form->addElement('html','</div>');
+      
+$form->addElement('button', 'submit', $button);
+
+if (!empty($session_info)) {
+    $session_info['display_start_date'] = api_get_local_time($session_info['display_start_date'], null, null, true);
+    $session_info['display_end_date'] = api_get_local_time($session_info['display_end_date'], null, null, true);
+    $session_info['access_start_date'] = api_get_local_time($session_info['access_start_date'], null, null, true);
+    $session_info['access_end_date'] = api_get_local_time($session_info['access_end_date'], null, null, true);
+    $session_info['coach_access_start_date'] = api_get_local_time($session_info['coach_access_start_date'], null, null, true);
+    $session_info['coach_access_end_date'] = api_get_local_time($session_info['coach_access_end_date'], null, null, true);    
+    $form->setDefaults($session_info);
 }
 
-function disable_endtime(select) {
-    var end_div = document.getElementById('end_date');
-    if (end_div.style.display == 'none')
-        end_div.style.display = 'block';
-     else 
-        end_div.style.display = 'none';
+if ($form->validate()) {
+    $params = $form->getSubmitValues();
+    if (isset($params['id'])) {
+        SessionManager::update($params);
+        header('Location: resume_session.php?id_session='.$params['id']);
+		exit;
+    } else {
+        $session_id = SessionManager::add($params);        
+        if ($session_id) {
+            // integer => no error on session creation
+            header('Location: add_courses_to_session.php?id_session='.$session_id.'&add=true&msg=');
+            exit;
+        }
+    }
 }
 
-function disable_starttime(select) {
-    var start_div = document.getElementById('start_date');
-    if (start_div.style.display == 'none')
-        start_div.style.display = 'block';
-     else 
-        start_div.style.display = 'none';
+function check_session_name($name) {    
+    $session = SessionManager::get_session_by_name($name);    
+    return empty($session) ? true : false;
 }
-</script>
-<?php
+
+Display::display_header($tool_name);
+
+echo '<div class="actions">';
+echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).'</a>';
+echo '</div>';
+
+$form->display();
 Display::display_footer();

+ 0 - 2
main/admin/session_category_add.php

@@ -13,8 +13,6 @@ $cidReset=true;
 // including the global Dokeos file
 require_once '../inc/global.inc.php';
 
-// including additional libraries
-require_once '../inc/lib/xajax/xajax.inc.php';
 $xajax = new xajax();
 $xajax -> registerFunction ('search_coachs');
 

+ 12 - 12
main/admin/session_course_edit.php

@@ -13,10 +13,10 @@ require_once '../inc/global.inc.php';
 $id_session = intval($_GET['id_session']);
 SessionManager::protect_session_edit($id_session);
 
-$course_code=trim(stripslashes($_GET['course_code']));
+$course_code = Database::escape_string($_GET['course_code']);
 
-$formSent=0;
-$errorMsg='';
+$formSent = 0;
+$errorMsg = '';
 
 // Database Table Definitions
 $tbl_user			= Database::get_main_table(TABLE_MAIN_USER);
@@ -26,14 +26,15 @@ $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']);
-$tool_name=$course_info['name'];
+$tool_name = $course_info['name'];
 
 $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
 $interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang("SessionList"));
 $interbreadcrumb[]=array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
 $interbreadcrumb[]=array('url' => "session_course_list.php?id_session=$id_session","name" =>api_htmlentities($session_name,ENT_QUOTES,$charset));
 
-$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='".addslashes($course_code)."'");
+$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='".$course_code."'");
 
 if (!list($session_name,$course_title)=Database::fetch_row($result)) {
 	header('Location: session_course_list.php?id_session='.$id_session);
@@ -68,7 +69,7 @@ if ($_POST['formSent']) {
 		$array_intersect = array_diff($coachs_course_session,$id_coachs);
 
 		foreach ($array_intersect as $nocoach_user_id) {
-			$rs2 = SessionManager::set_coach_to_course_session($nocoach_user_id, $id_session, $course_code,true);
+			$rs2 = SessionManager::set_coach_to_course_session($nocoach_user_id, $id_session, $course_code, true);
 		}
 
 		header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session);
@@ -96,19 +97,18 @@ if ($_configuration['multiple_access_urls']) {
     $sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1'".$order_clause;
 }
 
-$result=Database::query($sql);
+$result = Database::query($sql);
 
-$coaches=Database::store_result($result);
+$coaches = Database::store_result($result);
 
 Display::display_header($tool_name);
 
-$tool_name=get_lang('ModifySessionCourse');
-api_display_tool_title($tool_name);
+$tool_name = get_lang('ModifySessionCourse');
+echo Display::page_header($tool_name);
 ?>
 <form method="post" action="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo Security::remove_XSS($_GET['page']) ?>" style="margin:0px;">
 <input type="hidden" name="formSent" value="1">
-
-<table border="0" cellpadding="5" cellspacing="0" width="600px">
+<table>
 
 <?php
 if(!empty($errorMsg)) {

+ 3 - 1
main/admin/session_course_user.php

@@ -93,7 +93,8 @@ if ($_POST['formSent']) {
 			}
 		}
 	}
-	foreach($existingCourses as $existingCourse) {
+    
+	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']);
@@ -121,6 +122,7 @@ if (!empty($_GET['msg'])) {
 // the form header
 $session_info = SessionManager::fetch($id_session);
 $user_info = api_get_user_info($id_user);
+
 echo '<legend>'.$tool_name.': '.$session_info['name'].' - '.$user_info['complete_name'].'</legend>';
 
 $nosessionCourses = $sessionCourses = array();

+ 61 - 73
main/admin/session_course_user_list.php

@@ -11,24 +11,24 @@ $cidReset = true;
 
 require_once '../inc/global.inc.php';
 
-$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_rel_course             = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-$tbl_session_rel_user               = Database::get_main_table(TABLE_MAIN_SESSION_USER);
-$tbl_session_rel_course_rel_user    = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-
 $id_session = intval($_GET['id_session']);
+
 SessionManager::protect_session_edit($id_session);
 
-if (empty($id_session )) {
-    api_not_allowed();
+if (empty($id_session)) {
+    api_not_allowed(true);
+}
+
+$course_info = api_get_course_info($_GET['course_code']);
+
+if (empty($course_info)) {
+    api_not_allowed(true);
 }
 
-$course_code    = Database::escape_string(trim($_GET['course_code']));
+$course_code    = $course_info['code'];
 $page           = intval($_GET['page']);
 $action         = $_REQUEST['action'];
-$default_sort = api_sort_by_first_name() ? 'firstname':'lastname';
+$default_sort   = api_sort_by_first_name() ? 'firstname':'lastname';
 $sort           = in_array($_GET['sort'], array('lastname','firstname','username')) ? $_GET['sort'] : $default_sort;
 $idChecked      = (is_array($_GET['idChecked']) ? $_GET['idChecked'] : (is_array($_POST['idChecked']) ? $_POST['idChecked'] : null));
 
@@ -42,32 +42,19 @@ if (is_array($idChecked)) {
 	$idChecked = $my_temp;
 }
 
-$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='".Database::escape_string($course_code)."' ";
-
-$result = Database::query($sql);
+$session_info = SessionManager::fetch($id_session);
+$courses = SessionManager::get_course_list_by_session_id($id_session);
 
-if (!list($session_name,$course_title)=Database::fetch_row($result)) {
+if (!isset($courses[$course_info['real_id']])) {
 	header('Location: session_course_list.php?id_session='.$id_session);
 	exit();
 }
 
-
-switch($action) {
+switch ($action) {
     case 'delete':
-        if (is_array($idChecked) && count($idChecked)>0 ) {
-            array_map('intval', $idChecked);
-            $idChecked = implode(',',$idChecked);
-        }
-        if (!empty($idChecked)) {
-            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)");
-            $nbr_affected_rows = Database::affected_rows();
-            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."'");
-        }
+        SessionManager::unsubscribe_user_from_course_session($id_session, $idChecked, $course_code);        
         header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
-        exit();
+        exit;
         break;
     case 'add':
         SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code);
@@ -81,29 +68,30 @@ $limit  = 20;
 $from   = $page * $limit;
 $is_western_name_order = api_is_western_name_order();
 
-//scru.status<>2  scru.course_code='".$course_code."'
+$Users = SessionManager::get_users_in_course_session($course_code, $id_session, $sort, $direction, $from, $limit);
+        
+/*
+
 $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
-             FROM $tbl_session_rel_user s INNER JOIN $tbl_user u ON (u.user_id=s.id_user) LEFT JOIN $tbl_session_rel_course_rel_user scru ON (u.user_id=scru.id_user AND  scru.course_code = '".$course_code."' )
-             WHERE s.id_session='$id_session'
+             FROM $tbl_session_rel_user s INNER JOIN $tbl_user u ON (u.user_id=s.id_user) 
+                    LEFT JOIN $tbl_session_rel_course_rel_user scru ON (u.user_id=scru.id_user AND  scru.course_code = '".$course_code."' )
+             WHERE s.id_session='$id_session' 
              ORDER BY $sort $direction LIMIT $from,".($limit+1);
-
+*/
 if ($direction == 'desc') {
     $direction = 'asc';
 } else {
     $direction = 'desc';
 }
 
-$result = Database::query($sql);
-$Users  = Database::store_result($result);
-
 $nbr_results = sizeof($Users);
 
-$tool_name = get_lang('Session').': '.$session_name.' - '.get_lang('Course').': '.$course_title;
+$tool_name = get_lang('Session').': '.$session_info['name'].' - '.get_lang('Course').': '.$course_info['title'];
 
 $interbreadcrumb[] = array("url" => "index.php","name" => get_lang('PlatformAdmin'));
 $interbreadcrumb[] = array("url" => "session_list.php","name" => get_lang('SessionList'));
 $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview'));
-//$interbreadcrumb[]=array("url" => "session_course_list.php?id_session=$id_session","name" => get_lang('ListOfCoursesOfSession')." &quot;".api_htmlentities($session_name,ENT_QUOTES,$charset)."&quot;");
+
 
 Display::display_header($tool_name);
 
@@ -122,7 +110,7 @@ if($page) {
 ?>
 |
 <?php
-if($nbr_results > $limit) {
+if ($nbr_results > $limit) {
 ?>
 <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>"><?php echo get_lang('Next');?></a>
 <?php
@@ -149,38 +137,38 @@ if($nbr_results > $limit) {
 
 <?php
 $i=0;
-
-foreach ($Users as $key=>$enreg) {
-	if ($key == $limit) {
-		break;
-	}
-    ?>
-
-    <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
-        <td><input type="checkbox" name="idChecked[]" value="<?php echo $enreg['user_id']; ?>"></td>
-        <?php if ($is_western_name_order) { ?>
-        <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
-        <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
-        <?php } else { ?>
-        <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
-        <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
-        <?php } ?>
-        <td><?php echo api_htmlentities($enreg['username'],ENT_QUOTES,$charset); ?></td>
-        <td>
-        <?php if ($enreg['is_subscribed']) { ?>
-            <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>&action=delete&idChecked[]=<?php echo $enreg['user_id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
-                <?php Display::display_icon('delete.png', get_lang('Delete')); ?>
-            </a>
-        <?php } else  { ?>
-            <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>&action=add&idChecked[]=<?php echo $enreg['user_id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
-                <?php Display::display_icon('add.png', get_lang('Add'), array(), ICON_SIZE_SMALL); ?>
-            </a>
-        <?php }  ?>
-
-        </td>
-    </tr>
-    <?php
-        $i=$i ? 0 : 1;
+if (!empty($Users)) {
+    foreach ($Users as $key=>$enreg) {
+        if ($key == $limit) {
+            break;
+        }
+        ?>
+        <tr class="<?php echo $i?'row_odd':'row_even'; ?>">
+            <td><input type="checkbox" name="idChecked[]" value="<?php echo $enreg['user_id']; ?>"></td>
+            <?php if ($is_western_name_order) { ?>
+            <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
+            <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
+            <?php } else { ?>
+            <td><?php echo api_htmlentities($enreg['lastname'],ENT_QUOTES,$charset); ?></td>
+            <td><?php echo api_htmlentities($enreg['firstname'],ENT_QUOTES,$charset); ?></td>
+            <?php } ?>
+            <td><?php echo api_htmlentities($enreg['username'],ENT_QUOTES,$charset); ?></td>
+            <td>
+            <?php if ($enreg['is_subscribed']) { ?>
+                <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>&action=delete&idChecked[]=<?php echo $enreg['user_id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
+                    <?php Display::display_icon('delete.png', get_lang('Delete')); ?>
+                </a>
+            <?php } else  { ?>
+                <a href="<?php echo api_get_self(); ?>?id_session=<?php echo $id_session; ?>&course_code=<?php echo urlencode($course_code); ?>&sort=<?php echo $sort; ?>&action=add&idChecked[]=<?php echo $enreg['user_id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
+                    <?php Display::display_icon('add.png', get_lang('Add'), array(), ICON_SIZE_SMALL); ?>
+                </a>
+            <?php }  ?>
+
+            </td>
+        </tr>
+        <?php
+            $i=$i ? 0 : 1;
+    }
 }
 unset($Users);
 ?>
@@ -216,4 +204,4 @@ unset($Users);
 <button class="save" type="submit"> <?php echo get_lang('Ok'); ?></button>
 </form>
 <?php
-Display::display_footer();
+Display::display_footer();

+ 0 - 397
main/admin/session_edit.php

@@ -1,397 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-// name of the language file that needs to be included
-$language_file ='admin';
-$cidReset = true;
-require_once '../inc/global.inc.php';
-
-// setting the section (for the tabs)
-$this_section = SECTION_PLATFORM_ADMIN;
-
-
-
-$formSent = 0;
-
-// Database Table Definitions
-$tbl_user		= Database::get_main_table(TABLE_MAIN_USER);
-$tbl_session	= Database::get_main_table(TABLE_MAIN_SESSION);
-
-$id = intval($_GET['id']);
-
-SessionManager::protect_session_edit($id);
-
-$sql = "SELECT name,date_start,date_end,id_coach, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility
-        FROM $tbl_session WHERE id = $id";
-$result = Database::query($sql);
-
-if (!$infos = Database::fetch_array($result)) {
-    header('Location: session_list.php');
-    exit();
-}
-
-$id_coach   = $infos['id_coach'];
-
-
-
-$tool_name = get_lang('EditSession');
-
-$interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
-$interbreadcrumb[] = array('url' => "session_list.php","name" => get_lang('SessionList'));
-$interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id,"name" => get_lang('SessionOverview'));
-
-list($year_start,$month_start,$day_start)   = explode('-',$infos['date_start']);
-list($year_end,$month_end,$day_end)         = explode('-',$infos['date_end']);
-
-$end_year_disabled = $end_month_disabled = $end_day_disabled = '';
-
-if ($_POST['formSent']) {
-	$formSent = 1;
-
-	$name                  = $_POST['name'];
-	$year_start            = $_POST['year_start'];
-	$month_start           = $_POST['month_start'];
-	$day_start             = $_POST['day_start'];
-	$year_end              = $_POST['year_end'];
-	$month_end             = $_POST['month_end'];
-	$day_end               = $_POST['day_end'];
-	$nb_days_acess_before  = $_POST['nb_days_access_before'];
-	$nb_days_acess_after   = $_POST['nb_days_access_after'];
-	//$nolimit               = $_POST['nolimit'];
-	$id_coach              = $_POST['id_coach'];
-	$id_session_category   = $_POST['session_category'];
-	$id_visibility         = $_POST['session_visibility'];
-
-    $end_limit              = $_POST['end_limit'];
-    $start_limit            = $_POST['start_limit'];
-
-    if (empty($end_limit) && empty($start_limit)) {
-        $nolimit = 1;
-    } else {
-        $nolimit = null;
-    }
-
-	$return = SessionManager::edit_session($id,$name,$year_start,$month_start,$day_start,$year_end,$month_end,$day_end,$nb_days_acess_before,$nb_days_acess_after,$nolimit, $id_coach, $id_session_category,$id_visibility,$start_limit,$end_limit);
-	if ($return == strval(intval($return))) {
-		header('Location: resume_session.php?id_session='.$return);
-		exit();
-	}
-}
-
-$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
-$sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1'".$order_clause;
-
-if ($_configuration['multiple_access_urls']) {
-	$table_access_url_rel_user= 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 DISTINCT u.user_id,lastname,firstname,username FROM $tbl_user u INNER JOIN $table_access_url_rel_user url_rel_user ON (url_rel_user.user_id = u.user_id)
-			  WHERE status='1' AND access_url_id = '$access_url_id' $order_clause";
-	}
-}
-
-$result     = Database::query($sql);
-$Coaches    = Database::store_result($result);
-$thisYear   = date('Y');
-
-// display the header
-Display::display_header($tool_name);
-
-// display the tool title
-// api_display_tool_title($tool_name);
-
-if (!empty($return)) {
-	Display::display_error_message($return,false);
-}
-?>
-
-<form class="form-horizontal" method="post" name="form" action="<?php echo api_get_self(); ?>?page=<?php echo Security::remove_XSS($_GET['page']) ?>&id=<?php echo $id; ?>" style="margin:0px;">
-<fieldset>
-    <legend><?php echo $tool_name; ?></legend>
-    <input type="hidden" name="formSent" value="1">
-
-    <div class="control-group">
-        <label class="control-label">
-            <?php echo get_lang('SessionName') ?>
-        </label>
-        <div class="controls">
-            <input type="text" name="name" class="span4" maxlength="50" value="<?php if($formSent) echo api_htmlentities($name,ENT_QUOTES,$charset); else echo api_htmlentities($infos['name'],ENT_QUOTES,$charset); ?>">
-        </div>
-    </div>
-    <div class="control-group">
-        <label class="control-label">
-            <?php echo get_lang('CoachName') ?>
-        </label>
-        <div class="controls">
-            <select class="chzn-select" name="id_coach" style="width:380px;" title="<?php echo get_lang('Choose'); ?>" >
-                <option value="">----- <?php echo get_lang('None') ?> -----</option>
-                <?php foreach($Coaches as $enreg) { ?>
-                <option value="<?php echo $enreg['user_id']; ?>" <?php if(($enreg['user_id'] == $infos['id_coach']) || ($enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
-                <?php
-                }
-                unset($Coaches);
-                $Categories = SessionManager::get_all_session_category();
-            ?>
-        </select>
-        </div>
-    </div>
-    <div class="control-group">
-        <label class="control-label">
-            <?php echo get_lang('SessionCategory') ?>
-        </label>
-        <div class="controls">
-                <select class="chzn-select" id="session_category" name="session_category" style="width:380px;" title="<?php echo get_lang('Select'); ?>">
-        <option value="0"><?php get_lang('None'); ?></option>
-        <?php
-          if (!empty($Categories)) {
-              foreach($Categories as $Rows)  { ?>
-                <option value="<?php echo $Rows['id']; ?>" <?php if($Rows['id'] == $infos['session_category_id']) echo 'selected="selected"'; ?>><?php echo $Rows['name']; ?></option>
-        <?php }
-          }
-         ?>
-    </select>
-        </div>
-    </div>
-    <div class="control-group">
-        <div class="controls">
-            <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('DefineSessionOptions') ?></a>
-        </div>
-    </div>
-    <div class="control-group">
-        <div class="controls">
-            <div style="display:
-            <?php
-                if($formSent){
-                    if($nb_days_access_before!=0 || $nb_days_access_after!=0)
-                        echo 'block';
-                    else echo 'none';
-                }
-                else{
-                    if($infos['nb_days_access_before_beginning']!=0 || $infos['nb_days_access_after_end']!=0)
-                        echo 'block';
-                    else
-                        echo 'none';
-                }
-            ?>
-                ;" id="options">
-
-            <input type="text" name="nb_days_access_before" value="<?php if($formSent) echo api_htmlentities($nb_days_access_before,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_before_beginning'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?>
-                <br />
-                <br />
-            <input type="text" name="nb_days_access_after" value="<?php if($formSent) echo api_htmlentities($nb_days_access_after,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_after_end'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
-
-            </div>
-        </div>
-    </div>
-
-    <div class="clear"></div>
-    <div class="control-group">
-        <div class="controls">
-            <label for="start_limit">
-                <input id="start_limit" type="checkbox" name="start_limit" onchange="disable_starttime(this)" <?php if ($year_start!="0000") echo "checked"; ?>/>
-            <?php echo get_lang('DateStartSession');?>
-            </label>
-            <div id="start_date" style="<?php echo ($year_start=="0000") ? "display:none" : "display:block" ; ?>">
-            <br />
-              <select name="day_start">
-                <option value="1">01</option>
-                <option value="2" <?php if($day_start == 2) echo 'selected="selected"'; ?> >02</option>
-                <option value="3" <?php if($day_start == 3) echo 'selected="selected"'; ?> >03</option>
-                <option value="4" <?php if($day_start == 4) echo 'selected="selected"'; ?> >04</option>
-                <option value="5" <?php if($day_start == 5) echo 'selected="selected"'; ?> >05</option>
-                <option value="6" <?php if($day_start == 6) echo 'selected="selected"'; ?> >06</option>
-                <option value="7" <?php if($day_start == 7) echo 'selected="selected"'; ?> >07</option>
-                <option value="8" <?php if($day_start == 8) echo 'selected="selected"'; ?> >08</option>
-                <option value="9" <?php if($day_start == 9) echo 'selected="selected"'; ?> >09</option>
-                <option value="10" <?php if($day_start == 10) echo 'selected="selected"'; ?> >10</option>
-                <option value="11" <?php if($day_start == 11) echo 'selected="selected"'; ?> >11</option>
-                <option value="12" <?php if($day_start == 12) echo 'selected="selected"'; ?> >12</option>
-                <option value="13" <?php if($day_start == 13) echo 'selected="selected"'; ?> >13</option>
-                <option value="14" <?php if($day_start == 14) echo 'selected="selected"'; ?> >14</option>
-                <option value="15" <?php if($day_start == 15) echo 'selected="selected"'; ?> >15</option>
-                <option value="16" <?php if($day_start == 16) echo 'selected="selected"'; ?> >16</option>
-                <option value="17" <?php if($day_start == 17) echo 'selected="selected"'; ?> >17</option>
-                <option value="18" <?php if($day_start == 18) echo 'selected="selected"'; ?> >18</option>
-                <option value="19" <?php if($day_start == 19) echo 'selected="selected"'; ?> >19</option>
-                <option value="20" <?php if($day_start == 20) echo 'selected="selected"'; ?> >20</option>
-                <option value="21" <?php if($day_start == 21) echo 'selected="selected"'; ?> >21</option>
-                <option value="22" <?php if($day_start == 22) echo 'selected="selected"'; ?> >22</option>
-                <option value="23" <?php if($day_start == 23) echo 'selected="selected"'; ?> >23</option>
-                <option value="24" <?php if($day_start == 24) echo 'selected="selected"'; ?> >24</option>
-                <option value="25" <?php if($day_start == 25) echo 'selected="selected"'; ?> >25</option>
-                <option value="26" <?php if($day_start == 26) echo 'selected="selected"'; ?> >26</option>
-                <option value="27" <?php if($day_start == 27) echo 'selected="selected"'; ?> >27</option>
-                <option value="28" <?php if($day_start == 28) echo 'selected="selected"'; ?> >28</option>
-                <option value="29" <?php if($day_start == 29) echo 'selected="selected"'; ?> >29</option>
-                <option value="30" <?php if($day_start == 30) echo 'selected="selected"'; ?> >30</option>
-                <option value="31" <?php if($day_start == 31) echo 'selected="selected"'; ?> >31</option>
-              </select>
-              /
-              <select name="month_start">
-                <option value="1">01</option>
-                <option value="2" <?php if($month_start == 2) echo 'selected="selected"'; ?> >02</option>
-                <option value="3" <?php if($month_start == 3) echo 'selected="selected"'; ?> >03</option>
-                <option value="4" <?php if($month_start == 4) echo 'selected="selected"'; ?> >04</option>
-                <option value="5" <?php if($month_start == 5) echo 'selected="selected"'; ?> >05</option>
-                <option value="6" <?php if($month_start == 6) echo 'selected="selected"'; ?> >06</option>
-                <option value="7" <?php if($month_start == 7) echo 'selected="selected"'; ?> >07</option>
-                <option value="8" <?php if($month_start == 8) echo 'selected="selected"'; ?> >08</option>
-                <option value="9" <?php if($month_start == 9) echo 'selected="selected"'; ?> >09</option>
-                <option value="10" <?php if($month_start == 10) echo 'selected="selected"'; ?> >10</option>
-                <option value="11" <?php if($month_start == 11) echo 'selected="selected"'; ?> >11</option>
-                <option value="12" <?php if($month_start == 12) echo 'selected="selected"'; ?> >12</option>
-              </select>
-              /
-              <select name="year_start">
-
-            <?php
-            for($i=$thisYear-5;$i <= ($thisYear+5);$i++) { ?>
-                <option value="<?php echo $i; ?>" <?php if($year_start == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
-            <?php
-            }
-            ?>
-              </select>
-          </div>
-        </div>
-    </div>
-
-    <div class="control-group">
-        <div class="controls">
-            <label for="end_limit">
-                <input id="end_limit" type="checkbox" name="end_limit" onchange="disable_endtime(this)" <?php if ($year_end!="0000") echo "checked"; ?>/>
-            <?php echo get_lang('DateEndSession') ?>
-            </label>
-          <div id="end_date" style="<?php echo ($year_end=="0000") ? "display:none" : "display:block" ; ?>">
-          <br />
-
-          <select name="day_end" <?php echo $end_day_disabled; ?> >
-        	<option value="1">01</option>
-        	<option value="2" <?php if($day_end == 2) echo 'selected="selected"'; ?> >02</option>
-        	<option value="3" <?php if($day_end == 3) echo 'selected="selected"'; ?> >03</option>
-        	<option value="4" <?php if($day_end == 4) echo 'selected="selected"'; ?> >04</option>
-        	<option value="5" <?php if($day_end == 5) echo 'selected="selected"'; ?> >05</option>
-        	<option value="6" <?php if($day_end == 6) echo 'selected="selected"'; ?> >06</option>
-        	<option value="7" <?php if($day_end == 7) echo 'selected="selected"'; ?> >07</option>
-        	<option value="8" <?php if($day_end == 8) echo 'selected="selected"'; ?> >08</option>
-        	<option value="9" <?php if($day_end == 9) echo 'selected="selected"'; ?> >09</option>
-        	<option value="10" <?php if($day_end == 10) echo 'selected="selected"'; ?> >10</option>
-        	<option value="11" <?php if($day_end == 11) echo 'selected="selected"'; ?> >11</option>
-        	<option value="12" <?php if($day_end == 12) echo 'selected="selected"'; ?> >12</option>
-        	<option value="13" <?php if($day_end == 13) echo 'selected="selected"'; ?> >13</option>
-        	<option value="14" <?php if($day_end == 14) echo 'selected="selected"'; ?> >14</option>
-        	<option value="15" <?php if($day_end == 15) echo 'selected="selected"'; ?> >15</option>
-        	<option value="16" <?php if($day_end == 16) echo 'selected="selected"'; ?> >16</option>
-        	<option value="17" <?php if($day_end == 17) echo 'selected="selected"'; ?> >17</option>
-        	<option value="18" <?php if($day_end == 18) echo 'selected="selected"'; ?> >18</option>
-        	<option value="19" <?php if($day_end == 19) echo 'selected="selected"'; ?> >19</option>
-        	<option value="20" <?php if($day_end == 20) echo 'selected="selected"'; ?> >20</option>
-        	<option value="21" <?php if($day_end == 21) echo 'selected="selected"'; ?> >21</option>
-        	<option value="22" <?php if($day_end == 22) echo 'selected="selected"'; ?> >22</option>
-        	<option value="23" <?php if($day_end == 23) echo 'selected="selected"'; ?> >23</option>
-        	<option value="24" <?php if($day_end == 24) echo 'selected="selected"'; ?> >24</option>
-        	<option value="25" <?php if($day_end == 25) echo 'selected="selected"'; ?> >25</option>
-        	<option value="26" <?php if($day_end == 26) echo 'selected="selected"'; ?> >26</option>
-        	<option value="27" <?php if($day_end == 27) echo 'selected="selected"'; ?> >27</option>
-        	<option value="28" <?php if($day_end == 28) echo 'selected="selected"'; ?> >28</option>
-        	<option value="29" <?php if($day_end == 29) echo 'selected="selected"'; ?> >29</option>
-        	<option value="30" <?php if($day_end == 30) echo 'selected="selected"'; ?> >30</option>
-        	<option value="31" <?php if($day_end == 31) echo 'selected="selected"'; ?> >31</option>
-          </select>
-          /
-          <select name="month_end" <?php echo $end_month_disabled; ?> >
-        	<option value="1">01</option>
-        	<option value="2" <?php if($month_end == 2) echo 'selected="selected"'; ?> >02</option>
-        	<option value="3" <?php if($month_end == 3) echo 'selected="selected"'; ?> >03</option>
-        	<option value="4" <?php if($month_end == 4) echo 'selected="selected"'; ?> >04</option>
-        	<option value="5" <?php if($month_end == 5) echo 'selected="selected"'; ?> >05</option>
-        	<option value="6" <?php if($month_end == 6) echo 'selected="selected"'; ?> >06</option>
-        	<option value="7" <?php if($month_end == 7) echo 'selected="selected"'; ?> >07</option>
-        	<option value="8" <?php if($month_end == 8) echo 'selected="selected"'; ?> >08</option>
-        	<option value="9" <?php if($month_end == 9) echo 'selected="selected"'; ?> >09</option>
-        	<option value="10" <?php if($month_end == 10) echo 'selected="selected"'; ?> >10</option>
-        	<option value="11" <?php if($month_end == 11) echo 'selected="selected"'; ?> >11</option>
-        	<option value="12" <?php if($month_end == 12) echo 'selected="selected"'; ?> >12</option>
-          </select>
-          /
-          <select name="year_end" <?php echo $end_year_disabled; ?>>
-
-        <?php
-        for($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
-        ?>
-        	<option value="<?php echo $i; ?>" <?php if($year_end == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
-        <?php
-        }
-        ?>
-          </select>
-           <br />      <br />
-
-            <?php echo get_lang('SessionVisibility') ?> <br />
-            <select name="session_visibility" style="width:250px;">
-                <?php
-                $visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
-                foreach($visibility_list as $key=>$item): ?>
-                <option value="<?php echo $key; ?>" <?php if($key == $infos['visibility']) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
-                <?php endforeach; ?>
-            </select>
-    </div>
-    </div>
-  </div>
-
-    <div class="control-group">
-        <div class="controls">
-            <button class="save" type="submit" value="<?php echo get_lang('ModifyThisSession') ?>"><?php echo get_lang('ModifyThisSession') ?></button>
-        </div>
-    </div>
-</fieldset>
-</form>
-
-<script type="text/javascript">
-
-<?php if($year_start=="0000") echo "setDisable(document.form.nolimit);\r\n"; ?>
-
-function setDisable(select){
-
-	document.form.day_start.disabled = (select.checked) ? true : false;
-	document.form.month_start.disabled = (select.checked) ? true : false;
-	document.form.year_start.disabled = (select.checked) ? true : false;
-
-	document.form.day_end.disabled = (select.checked) ? true : false;
-	document.form.month_end.disabled = (select.checked) ? true : false;
-	document.form.year_end.disabled = (select.checked) ? true : false;
-
-	document.form.session_visibility.disabled = (select.checked) ? true : false;
-	document.form.session_visibility.selectedIndex = 0;
-
-    document.form.start_limit.disabled = (select.checked) ? true : false;
-    document.form.start_limit.checked = false;
-    document.form.end_limit.disabled = (select.checked) ? true : false;
-    document.form.end_limit.checked = false;
-
-    var end_div = document.getElementById('end_date');
-    end_div.style.display = 'none';
-
-    var start_div = document.getElementById('start_date');
-    start_div.style.display = 'none';
-
-
-}
-
-function disable_endtime(select) {
-    var end_div = document.getElementById('end_date');
-    if (end_div.style.display == 'none')
-        end_div.style.display = 'block';
-     else
-        end_div.style.display = 'none';
-}
-
-function disable_starttime(select) {
-    var start_div = document.getElementById('start_date');
-    if (start_div.style.display == 'none')
-        start_div.style.display = 'block';
-     else
-        start_div.style.display = 'none';
-}
-
-</script>
-<?php
-Display::display_footer();

+ 185 - 206
main/admin/session_export.php

@@ -1,249 +1,228 @@
 <?php
+
 /**
-*	@package chamilo.admin
-*/
+ * 	@package chamilo.admin
+ */
 // name of the language file that needs to be included
 $language_file = '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);
-include api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 
 $session_id = intval($_GET['session_id']);
 $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_session = Database::get_main_table(TABLE_MAIN_SESSION);
+$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
+$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'));
+$interbreadcrumb[] = array('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
 
 set_time_limit(0);
 
 if ($_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";
-
-		
-		if ($_configuration['multiple_access_urls']) {
-			$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
+    $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,access_start_date,access_end_date,visibility,session_category_id 
+                FROM $tbl_session INNER JOIN $tbl_user
+				ON $tbl_user.user_id = $tbl_session.id_coach ORDER BY id";
+        if ($_configuration['multiple_access_urls']) {
+            $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,access_start_date,access_end_date,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
+            }
+        }
+        $result = Database::query($sql);
+    } else {
+        $sql = "SELECT id,name,username,access_start_date,access_end_date,visibility,session_category_id
 				FROM $tbl_session
 				INNER JOIN $tbl_user
 					ON $tbl_user.user_id = $tbl_session.id_coach
 				WHERE id='$session_id'";
 
-		$result = Database::query($sql);
-
-	}
-
-	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');
-
-			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))
-		{
-			$archiveFile='export_users_'.$session_id.'_'.date('Y-m-d_H-i-s').'_'.uniqid('').'.'.$file_type;
-		}
-		$fp=fopen($archivePath.$archiveFile,'w');
-
-		if($file_type == 'csv')
-		{
-			$cvs = true;
-			fputs($fp,"SessionName;Coach;DateStart;DateEnd;Visibility;SessionCategory;Users;Courses;\n");
-		}
-		else
-		{
-			$cvs = false;
-			fputs($fp, "<?xml version=\"1.0\" encoding=\"".api_get_system_encoding()."\"?>\n<Sessions>\n");
-		}
-
-		while($row=Database::fetch_array($result))
-		{
-			$add = '';
-			$row['name'] = str_replace(';',',',$row['name']);
-			$row['username'] = str_replace(';',',',$row['username']);
-			$row['date_start'] = str_replace(';',',',$row['date_start']);
-			$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){
-				$add.= $row['name'].';'.$row['username'].';'.$row['date_start'].';'.$row['date_end'].';'.$row['visibility'].';'.$row['session_category'].';';
-			}
-			else {
-				$add = "\t<Session>\n"
-						 ."\t\t<SessionName>$row[name]</SessionName>\n"
-						 ."\t\t<Coach>$row[username]</Coach>\n"
-						 ."\t\t<DateStart>$row[date_start]</DateStart>\n"
-						 ."\t\t<DateEnd>$row[date_end]</DateEnd>\n"
-						 ."\t\t<Visibility>$row[visibility]</Visibility>\n"
-						 ."\t\t<SessionCategory>$row[session_category]</SessionCategory>\n";
-			}
-
-			//users
-			$sql = "SELECT DISTINCT $tbl_user.username FROM $tbl_user
+        $result = Database::query($sql);
+    }
+
+    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');
+
+            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)) {
+            $archiveFile = 'export_users_' . $session_id . '_' . date('Y-m-d_H-i-s') . '_' . uniqid('') . '.' . $file_type;
+        }
+        $fp = fopen($archivePath . $archiveFile, 'w');
+
+        if ($file_type == 'csv') {
+            $cvs = true;
+            fputs($fp, "SessionName;Coach;DateStart;DateEnd;Visibility;SessionCategory;Users;Courses;\n");
+        } else {
+            $cvs = false;
+            fputs($fp, "<?xml version=\"1.0\" encoding=\"" . api_get_system_encoding() . "\"?>\n<Sessions>\n");
+        }
+
+        while ($row = Database::fetch_array($result)) {
+            $add = '';
+            $row['name'] = str_replace(';', ',', $row['name']);
+            $row['username'] = str_replace(';', ',', $row['username']);
+            $row['access_start_date'] = str_replace(';', ',', api_get_local_time($row['access_start_date'], null, null, true));
+            $row['access_end_date'] = str_replace(';', ',', api_get_local_time($row['access_end_date'], null, null, true));
+            $row['visibility'] = str_replace(';', ',', $row['visibility']);
+            $row['session_category'] = str_replace(';', ',', $row['session_category_id']);
+            if ($cvs) {
+                $add.= $row['name'] . ';' . $row['username'] . ';' . $row['access_start_date'] . ';' . $row['access_end_date'] . ';' . $row['visibility'] . ';' . $row['session_category'] . ';';
+            } else {
+                $add = "\t<Session>\n"
+                        . "\t\t<SessionName>$row[name]</SessionName>\n"
+                        . "\t\t<Coach>$row[username]</Coach>\n"
+                        . "\t\t<DateStart>$row[access_start_date]</DateStart>\n"
+                        . "\t\t<DateEnd>$row[access_end_date]</DateEnd>\n"
+                        . "\t\t<Visibility>$row[visibility]</Visibility>\n"
+                        . "\t\t<SessionCategory>$row[session_category]</SessionCategory>\n";
+            }
+
+            //users
+            $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']."'";
-
-			$rsUsers = Database::query($sql);
-			$users = '';
-			while($rowUsers = Database::fetch_array($rsUsers)){
-				if($cvs){
-					$users .= str_replace(';',',',$rowUsers['username']).'|';
-				}
-				else {
-					$users .= "\t\t<User>$rowUsers[username]</User>\n";
-				}
-			}
-			if(!empty($users) && $cvs)
-				$users = api_substr($users , 0, api_strlen($users)-1);
-
-			if($cvs)
-				$users .= ';';
-
-			$add .= $users;
-
-			//courses
-			$sql = "SELECT DISTINCT $tbl_course.code
+						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'] . "'";
+
+            $rsUsers = Database::query($sql);
+            $users = '';
+            while ($rowUsers = Database::fetch_array($rsUsers)) {
+                if ($cvs) {
+                    $users .= str_replace(';', ',', $rowUsers['username']) . '|';
+                } else {
+                    $users .= "\t\t<User>$rowUsers[username]</User>\n";
+                }
+            }
+            if (!empty($users) && $cvs)
+                $users = api_substr($users, 0, api_strlen($users) - 1);
+
+            if ($cvs)
+                $users .= ';';
+
+            $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']."'";
+						AND $tbl_session_course_user.id_session = '" . $row['id'] . "'";
 
-			$rsCourses = Database::query($sql);
+            $rsCourses = Database::query($sql);
 
-			$courses = '';
-			while($rowCourses = Database::fetch_array($rsCourses)){
+            $courses = '';
+            while ($rowCourses = Database::fetch_array($rsCourses)) {
 
-				// get coachs from a course
-				$sql = "SELECT u.username
+                // 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 ";
-
-				$rs_coachs = Database::query($sql);
-				$coachs = array();
-				while ($row_coachs = Database::fetch_array($rs_coachs)) {
-					$coachs[] = $row_coachs['username'];
-				}
-
-				$coachs = implode(",",$coachs);
-
-				if($cvs){
-					$courses .= str_replace(';',',',$rowCourses['code']);
-					$courses .= '['.str_replace(';',',',$coachs).'][';
-				}
-				else {
-					$courses .= "\t\t<Course>\n";
-					$courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n";
-					$courses .= "\t\t\t<Coach>$coachs</Coach>\n";
-				}
-
-				// rel user courses
-				$sql = "SELECT DISTINCT u.username
+						AND scu.id_session = '" . $row['id'] . "' AND scu.status = 2 ";
+
+                $rs_coachs = Database::query($sql);
+                $coachs = array();
+                while ($row_coachs = Database::fetch_array($rs_coachs)) {
+                    $coachs[] = $row_coachs['username'];
+                }
+
+                $coachs = implode(",", $coachs);
+                if ($cvs) {
+                    $courses .= str_replace(';', ',', $rowCourses['code']);
+                    $courses .= '[' . str_replace(';', ',', $coachs) . '][';
+                } else {
+                    $courses .= "\t\t<Course>\n";
+                    $courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n";
+                    $courses .= "\t\t\t<Coach>$coachs</Coach>\n";
+                }
+
+                // 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.id_user = su.id_user AND scu.id_session = su.id_session 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']."'";
-
-				$rsUsersCourse = Database::query($sql);
-				$userscourse = '';
-				while($rowUsersCourse = Database::fetch_array($rsUsersCourse)){
-
-					if($cvs){
-						$userscourse .= str_replace(';',',',$rowUsersCourse['username']).',';
-					}
-					else {
-						$courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n";
-					}
-				}
-				if($cvs){
-					if(!empty($userscourse))
-						$userscourse = api_substr($userscourse , 0, api_strlen($userscourse)-1);
-
-					$courses .= $userscourse.']|';
-				}
-				else {
-					$courses .= "\t\t</Course>\n";
-				}
-			}
-
-			if(!empty($courses) && $cvs)
-				$courses = api_substr($courses , 0, api_strlen($courses)-1);
-			$add .= $courses;
-
-			if($cvs) {
-				$breakline = api_is_windows_os()?"\r\n":"\n";
-				$add .= ";$breakline";
-			} else {
-				$add .= "\t</Session>\n";
-			}
-
-			fputs($fp, $add);
-		}
-
-		if(!$cvs)
-			fputs($fp,"</Sessions>\n");
-		fclose($fp);
-
-		$errorMsg=get_lang('UserListHasBeenExported').'<br/><a class="btn" href="'.$archiveURL.$archiveFile.'">'.get_lang('ClickHereToDownloadTheFile').'</a>';
-	}
+						AND scu.course_code='" . $rowCourses['code'] . "'
+						AND scu.id_session='" . $row['id'] . "'";
+
+                $rsUsersCourse = Database::query($sql);
+                $userscourse = '';
+                while ($rowUsersCourse = Database::fetch_array($rsUsersCourse)) {
+
+                    if ($cvs) {
+                        $userscourse .= str_replace(';', ',', $rowUsersCourse['username']) . ',';
+                    } else {
+                        $courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n";
+                    }
+                }
+                if ($cvs) {
+                    if (!empty($userscourse))
+                        $userscourse = api_substr($userscourse, 0, api_strlen($userscourse) - 1);
+
+                    $courses .= $userscourse . ']|';
+                }
+                else {
+                    $courses .= "\t\t</Course>\n";
+                }
+            }
+
+            if (!empty($courses) && $cvs)
+                $courses = api_substr($courses, 0, api_strlen($courses) - 1);
+            $add .= $courses;
+
+            if ($cvs) {
+                $breakline = api_is_windows_os() ? "\r\n" : "\n";
+                $add .= ";$breakline";
+            } else {
+                $add .= "\t</Session>\n";
+            }
+
+            fputs($fp, $add);
+        }
+
+        if (!$cvs)
+            fputs($fp, "</Sessions>\n");
+        fclose($fp);
+
+        $errorMsg = get_lang('UserListHasBeenExported') . '<br/><a class="btn" href="' . $archiveURL . $archiveFile . '">' . get_lang('ClickHereToDownloadTheFile') . '</a>';
+    }
 }
 
 // display the header
@@ -253,29 +232,29 @@ Display::display_header($tool_name);
 $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);
-	$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
+    $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";
-	}
+    }
 }
 $result = Database::query($sql);
 $Sessions = Database::store_result($result);
 
 echo '<div class="actions">';
-echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).'</a>';
+echo '<a href="../admin/index.php">' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM) . '</a>';
 echo '</div>';
 
 if (!empty($errorMsg)) {
-	Display::display_normal_message($errorMsg, false); //main API
+    Display::display_normal_message($errorMsg, false); //main API
 }
 
 $form = new FormValidator('session_export', 'post', api_get_self());
 $form->addElement('hidden', 'formSent', 1);
-$form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV' , 'csv', null, array('id' => 'file_type_csv'));
+$form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV', 'csv', null, array('id' => 'file_type_csv'));
 $form->addElement('radio', 'file_type', null, 'XML', 'xml', null, array('id' => 'file_type_xml'));
 
 $options = array();
@@ -284,7 +263,7 @@ foreach ($Sessions as $enreg) {
     $options[$enreg['id']] = $enreg['name'];
 }
 
-$form->addElement('select', 'session_id', get_lang('WhichSessionToExport'),  $options);
+$form->addElement('select', 'session_id', get_lang('WhichSessionToExport'), $options);
 $form->addElement('button', 'submit', get_lang('ExportSession'));
 
 $defaults = array();

+ 200 - 0
main/admin/session_fields.php

@@ -0,0 +1,200 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ *  @package chamilo.admin
+ */
+
+// Language files that need to be included.
+$language_file = array('admin');
+
+$cidReset = true;
+require_once '../inc/global.inc.php';
+
+$this_section = SECTION_PLATFORM_ADMIN;
+
+api_protect_admin_script();
+
+//Add the JS needed to use the jqgrid
+$htmlHeadXtra[] = api_get_jqgrid_js();
+
+// setting breadcrumbs
+$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
+
+$tool_name = null;
+
+$action = isset($_GET['action']) ? $_GET['action'] : null;
+
+$check = Security::check_token('request');
+$token = Security::get_token();    
+
+if ($action == 'add') {
+    $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields'));
+    $interbreadcrumb[]=array('url' => '#','name' => get_lang('Add'));
+} elseif ($action == 'edit') {
+    $interbreadcrumb[]=array('url' => 'session_fields.php','name' => get_lang('SessionFields'));    
+    $interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit'));
+} else {
+    $interbreadcrumb[]=array('url' => '#','name' => get_lang('SessionFields'));
+}
+
+//jqgrid will use this URL to do the selects
+$url            = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_extra_fields&type=session';
+
+//The order is important you need to check the the $column variable in the model.ajax.php file 
+$columns        = array(get_lang('Name'), get_lang('FieldLabel'),  get_lang('Type'), get_lang('FieldChangeability'), get_lang('Visibility'), get_lang('Filter'), get_lang('FieldOrder'), get_lang('Actions'));
+
+//Column config
+$column_model   = array(
+                        array('name'=>'field_display_text', 'index'=>'field_display_text',      'width'=>'180',   'align'=>'left'),
+                        array('name'=>'field_variable',     'index'=>'field_variable',          'width'=>'',  'align'=>'left','sortable'=>'true'),
+                        array('name'=>'field_type',         'index'=>'field_type',              'width'=>'',  'align'=>'left','sortable'=>'true'),    
+                        array('name'=>'field_changeable',   'index'=>'field_changeable',        'width'=>'50',  'align'=>'left','sortable'=>'true'),    
+                        array('name'=>'field_visible',      'index'=>'field_visible',           'width'=>'40',  'align'=>'left','sortable'=>'true'),                            
+                        array('name'=>'field_filter',       'index'=>'field_filter',            'width'=>'30',  'align'=>'left','sortable'=>'true'),
+                        array('name'=>'field_order',        'index'=>'field_order',             'width'=>'40',  'align'=>'left','sortable'=>'true'),    
+                        array('name'=>'actions',            'index'=>'actions',                 'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
+);
+
+//Autowidth             
+$extra_params['autowidth'] = 'true';
+//height auto 
+$extra_params['height'] = 'auto';
+$extra_params['sortname'] = 'field_order';
+
+//With this function we can add actions to the jgrid (edit, delete, etc)
+$action_links = 'function action_formatter(cellvalue, options, rowObject) {
+                         return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
+                         '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
+                         '\'; 
+                 }';
+$htmlHeadXtra[]='
+<script>
+$(function() {
+    // grid definition see the $obj->display() function
+    '.Display::grid_js('session_fields',  $url, $columns, $column_model, $extra_params, array(), $action_links,true).'
+            
+    $("#field_type").on("change", function() {      
+        id = $(this).val();        
+        switch(id) {
+            case "1":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_text.png')).'"); 
+                break;
+            case "2":        
+                $("#example").html("'.addslashes(Display::return_icon('userfield_text_area.png')).'"); 
+                break;
+            case "3":     
+                $("#example").html("'.addslashes(Display::return_icon('add_user_field_howto.png')).'");            
+                break;
+            case "4":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_drop_down.png')).'");
+                break;
+            case "5":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_multidropdown.png')).'");
+                break;
+            case "6":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");
+                break;
+            case "7":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_date_time.png')).'");
+                break;
+            case "8":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_doubleselect.png')).'");
+                break;
+            case "9":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_divider.png')).'");
+                break;
+            case "10":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_user_tag.png')).'");
+                break;
+            case "11":
+                $("#example").html("'.addslashes(Display::return_icon('userfield_data.png')).'");                                            
+                break;
+        }
+    });
+
+    var value = 1;
+    $("#advanced_parameters").on("click", function() {
+        $("#options").toggle(function() {        
+            if (value == 1) {
+                $("#advanced_parameters").addClass("btn-hide");        
+                value = 0;
+            } else {
+                $("#advanced_parameters").removeClass("btn-hide");      
+                value = 1;
+            }
+        });
+    });
+});
+</script>';
+
+// The header.
+Display::display_header($tool_name);
+
+$obj = new SessionField();
+
+// Action handling: Add
+switch ($action) {
+    case 'add':
+        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
+            api_not_allowed();
+        }        
+        $url  = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
+        $form = $obj->return_form($url, 'add');
+
+        // The validation or display
+        if ($form->validate()) {          
+            if ($check) {
+                $values = $form->exportValues();       
+                $res    = $obj->save($values);            
+                if ($res) {
+                    Display::display_confirmation_message(get_lang('ItemAdded'));
+                }
+            }        
+            $obj->display();
+        } else {
+            echo '<div class="actions">';
+            echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
+            echo '</div>';            
+            $form->addElement('hidden', 'sec_token');
+            $form->setConstants(array('sec_token' => $token));
+            $form->display();
+        }
+        break;
+    case 'edit':
+        // Action handling: Editing 
+        $url  = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
+        $form = $obj->return_form($url, 'edit');    
+
+        // The validation or display
+        if ($form->validate()) {            
+            if ($check) {
+                $values = $form->exportValues();                
+                $res    = $obj->update($values);                
+                Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false);                
+            }            
+            $obj->display();
+        } else {
+            echo '<div class="actions">';
+            echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
+            echo '</div>';
+            $form->addElement('hidden', 'sec_token');
+            $form->setConstants(array('sec_token' => $token));
+            $form->display();
+        }
+        break;
+    case 'delete':
+        // Action handling: delete
+        if ($check) {
+            $res = $obj->delete($_GET['id']);
+            if ($res) {
+                Display::display_confirmation_message(get_lang('ItemDeleted'));
+            }
+        }
+        $obj->display();
+        break;
+    default:
+        $obj->display();   
+        break;
+}
+Display :: display_footer();

+ 70 - 104
main/admin/session_import.php

@@ -8,24 +8,18 @@
 $language_file = array('admin', 'registration');
 $cidReset = true;
 
-require '../inc/global.inc.php';
+require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-
 $form_sent = 0;
 $error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
 if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
     $error_message = Security::remove_XSS($_GET['message']);
 }
 
-
 $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);
@@ -56,9 +50,7 @@ if ($_POST['formSent']) {
         $session_counter = 0;
 
         if ($file_type == 'xml') {
-
             // XML
-
             // SimpleXML for PHP5 deals with various encodings, but how many they are, what are version issues, do we need to waste time with configuration options?
             // For avoiding complications we go some sort of "PHP4 way" - we convert the input xml-file into UTF-8 before passing it to the parser.
             // Instead of:
@@ -161,7 +153,7 @@ if ($_POST['formSent']) {
                         $params['user_id']          = api_get_user_id();
                         
                         // Looking up for the teacher.
-                        $username       = trim(api_utf8_decode($courseNode->CourseTeacher));
+                        $username = trim(api_utf8_decode($courseNode->CourseTeacher));
                         $sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'";
                         $rs = Database::query($sql);
                         list($user_id, $lastname, $firstname) = Database::fetch_array($rs);
@@ -193,30 +185,7 @@ if ($_POST['formSent']) {
                         }
 
                         $date_start = trim(api_utf8_decode($node_session->DateStart)); // Just in case - encoding conversion.
-
-                        if (!empty($date_start)) {
-                            list($year_start, $month_start, $day_start) = explode('/', $date_start);
-                            if(empty($year_start) || empty($month_start) || empty($day_start)) {
-                                $error_message .= get_lang('WrongDate').' : '.$date_start.'<br />';
-                                break;
-                            } else {
-                                $time_start = mktime(0, 0, 0, $month_start, $day_start, $year_start);
-                            }
-
-                            $date_end = trim(api_utf8_decode($node_session->DateEnd));
-                            if (!empty($date_start)) {
-                                list($year_end, $month_end, $day_end) = explode('/', $date_end);
-                                if (empty($year_end) || empty($month_end) || empty($day_end)) {
-                                    $error_message .= get_lang('Error').' : '.$date_end.'<br />';
-                                    break;
-                                } else {
-                                    $time_end = mktime(0, 0, 0, $month_end, $day_end, $year_end);
-                                }
-                            }
-                            if ($time_end - $time_start < 0) {
-                                $error_message .= get_lang('StartDateShouldBeBeforeEndDate').' : '.$date_end.'<br />';
-                            }
-                        }
+                        $date_end = trim(api_utf8_decode($node_session->DateEnd));                                                
 
                         $visibility = trim(api_utf8_decode($node_session->Visibility));
                         $session_category_id = trim(api_utf8_decode($node_session->SessionCategory));
@@ -239,45 +208,48 @@ if ($_POST['formSent']) {
                                     $session_name .= $suffix;
                                 }
                             }
-                            // Creating the session.
-                            $sql_session = "INSERT IGNORE INTO $tbl_session SET
-                                    name = '".Database::escape_string($session_name)."',
-                                    id_coach = '$coach_id',
-                                    date_start = '$date_start',
-                                    date_end = '$date_end',
-                                    visibility = '$visibility',
-                                    session_category_id = '$session_category_id',
-                                    session_admin_id=".intval($_user['user_id']);
-                            $rs_session = Database::query($sql_session);
-                            $session_id = Database::insert_id();
+                            
+                            $params = array (
+                                'id_coach' => $coach_id,
+                                'visibility' => $visibility,
+                                'name' => $session_name,
+                                'access_start_date' => $date_start,
+                                'access_end_date' => $date_end,
+                                'session_category_id' => $session_category_id,
+                                'session_admin_id' => api_get_user_id(),
+                            );
+                            $session_id = SessionManager::add($params);                            
                             $session_counter++;
 
                         } else {
                             // Update the session if it is needed.
                             $my_session_result = SessionManager::get_session_by_name($session_name);
+                            
                             if ($my_session_result === false) {
-                                // Creating the session.
-                                $sql_session = "INSERT IGNORE INTO $tbl_session SET
-                                        name = '".Database::escape_string($session_name)."',
-                                        id_coach = '$coach_id',
-                                        date_start = '$date_start',
-                                        date_end = '$date_end',
-                                        visibility = '$visibility',
-                                        session_category_id = '$session_category_id',
-                                        session_admin_id=".intval($_user['user_id']);
-                                $rs_session = Database::query($sql_session);
-                                $session_id = Database::insert_id();
+                                $params = array (
+                                    'id_coach' => $coach_id,
+                                    'visibility' => $visibility,
+                                    'name' => $session_name,
+                                    'access_start_date' => $date_start,
+                                    'access_end_date' => $date_end,
+                                    'session_category_id' => $session_category_id,
+                                    'session_admin_id' => api_get_user_id(),
+                                );
+                                $session_id = SessionManager::add($params);                                      
                                 $session_counter++;
                             } else {
-                                // if the session already exists - update it.
-                                $sql_session = "UPDATE $tbl_session SET
-                                        id_coach = '$coach_id',
-                                        date_start = '$date_start',
-                                        date_end = '$date_end',
-                                        visibility = '$visibility',
-                                        session_category_id = '$session_category_id'
-                                    WHERE name = '$session_name'";
-                                $rs_session = Database::query($sql_session);
+                                
+                                $params = array (
+                                    'id' => $my_session_result['id'],
+                                    'id_coach' => $coach_id,
+                                    'visibility' => $visibility,
+                                    'name' => $session_name,
+                                    'access_start_date' => $date_start,
+                                    'access_end_date' => $date_end,
+                                    'session_category_id' => $session_category_id,
+                                    'session_admin_id' => api_get_user_id(),
+                                );
+                                SessionManager::update($params);                                
                                 $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'");
@@ -296,7 +268,6 @@ if ($_POST['formSent']) {
                             UrlManager::add_session_to_url($session_id, 1);
                         }
 
-
                         // Adding users to the new session.
                         foreach ($node_session->User as $node_user) {
                             $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames);
@@ -522,49 +493,44 @@ if ($_POST['formSent']) {
                                 $session_name .= $suffix;
                             }
                         }
-
-                        // Creating the session.
-                        $sql_session = "INSERT IGNORE INTO $tbl_session SET
-                                name = '".Database::escape_string($session_name)."',
-                                id_coach = '$coach_id',
-                                date_start = '$date_start',
-                                date_end = '$date_end',
-                                visibility = '$visibility',
-                                session_category_id = '$session_category_id',
-                                session_admin_id=".intval($_user['user_id']);
-                        $rs_session = Database::query($sql_session);
-                        $session_id = Database::insert_id();
+                        
+                        $params = array (
+                            'id_coach' => $coach_id,
+                            'visibility' => $visibility,
+                            'name' => $session_name,
+                            'access_start_date' => $date_start,
+                            'access_end_date' => $date_end,
+                            'session_category_id' => $session_category_id,
+                            'session_admin_id' => api_get_user_id(),
+                        );
+                        $session_id = SessionManager::add($params); 
                         $session_counter++;
                     } else {
                         $my_session_result = SessionManager::get_session_by_name($session_name);
                         if ($my_session_result === false) {
-
-                            // Creating a session.
-                            $sql_session = "INSERT IGNORE INTO $tbl_session SET
-                                    name = '$session_name',
-                                    id_coach = '$coach_id',
-                                    date_start = '$date_start',
-                                    date_end = '$date_end',
-                                    visibility = '$visibility',
-                                    session_category_id = '$session_category_id'";
-
-                            $rs_session = Database::query($sql_session);
-                            // We get the last insert id.
-                            $my_session_result = SessionManager::get_session_by_name($session_name);
-                            $session_id = $my_session_result['id'];
-                            //echo '<br>';
+                            $params = array (
+                                'id_coach' => $coach_id,
+                                'visibility' => $visibility,
+                                'name' => $session_name,
+                                'access_start_date' => $date_start,
+                                'access_end_date' => $date_end,
+                                'session_category_id' => $session_category_id,
+                                'session_admin_id' => api_get_user_id(),
+                            );
+                            $session_id = SessionManager::add($params); 
                         } else {
-                            // The session already exists, update it then.
-                            $sql_session = "UPDATE $tbl_session SET
-                                    id_coach = '$coach_id',
-                                    date_start = '$date_start',
-                                    date_end = '$date_end',
-                                    visibility = '$visibility',
-                                    session_category_id = '$session_category_id'
-                                WHERE name = '$session_name'";
-                            $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);
+                            $session_id = $my_session_result['id'];
+                            $params = array (
+                                'id' => $session_id,
+                                'id_coach' => $coach_id,
+                                'visibility' => $visibility,
+                                'name' => $session_name,
+                                'access_start_date' => $date_start,
+                                'access_end_date' => $date_end,
+                                'session_category_id' => $session_category_id,
+                                'session_admin_id' => api_get_user_id(),
+                            );
+                            SessionManager::update($params);
                             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'");

+ 178 - 72
main/admin/session_list.php

@@ -11,6 +11,10 @@ api_protect_admin_script(true);
 
 //Add the JS needed to use the jqgrid
 $htmlHeadXtra[] = api_get_jqgrid_js();
+$htmlHeadXtra[] = api_get_js('json-js/json2.js');
+$htmlHeadXtra[] = api_get_js('date/date.js');
+
+$htmlHeadXtra = api_get_datetime_picker_js($htmlHeadXtra);
 
 $action = $_REQUEST['action'];
 $idChecked = $_REQUEST['idChecked'];
@@ -20,12 +24,12 @@ if ($action == 'delete') {
 	header('Location: session_list.php');
 	exit();
 } elseif ($action == 'copy') {
-	SessionManager::copy_session($idChecked);
+	SessionManager::copy_session($idChecked, true, false);
     header('Location: session_list.php');
     exit();
 }
 
-$interbreadcrumb[]=array("url" => "index.php","name" => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array("url" => "index.php","name" => get_lang('PlatformAdmin'));
 
 $tool_name = get_lang('SessionList');
 Display::display_header($tool_name);
@@ -46,114 +50,186 @@ if (isset($_REQUEST['keyword'])) {
     $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=bw';    
 }
 
-//The order is important you need to check the the $column variable in the model.ajax.php file 
-$columns        = array(get_lang('Name'), get_lang('NumberOfCourses'), get_lang('NumberOfUsers'), get_lang('SessionCategoryName'), 
-                        get_lang('StartDate'), get_lang('EndDate'), get_lang('Coach'),  get_lang('Status'), get_lang('Visibility'), get_lang('Actions'));
-
-//$activeurl = '?sidx=session_active';
-//Column config
-$column_model   = array(
-                        array('name'=>'name',           'index'=>'name',          'width'=>'120',  'align'=>'left', 'search' => 'true'),                        
-                        array('name'=>'nbr_courses',    'index'=>'nbr_courses',   'width'=>'30',   'align'=>'left', 'search' => 'true'),
-                        array('name'=>'nbr_users',      'index'=>'nbr_users',     'width'=>'30',   'align'=>'left', 'search' => 'true'),
-                        array('name'=>'category_name',  'index'=>'category_name', 'width'=>'70',   'align'=>'left', 'search' => 'true'),
-                        array('name'=>'date_start',     'index'=>'date_start',    'width'=>'40',   'align'=>'left', 'search' => 'true'),
-                        array('name'=>'date_end',       'index'=>'date_end',      'width'=>'40',   'align'=>'left', 'search' => 'true'),
-                        array('name'=>'coach_name',     'index'=>'coach_name',    'width'=>'80',   'align'=>'left', 'search' => 'false'),                        
-                        array('name'=>'status',         'index'=>'session_active','width'=>'40',   'align'=>'left', 'search' => 'true', 'stype'=>'select',
-                                 
-                              //for the bottom bar
-                              'searchoptions' => array(                                                
-                                                'defaultValue'  => '1', 
-                                                'value'         => '1:'.get_lang('Active').';0:'.get_lang('Inactive')),
-                             
-                              //for the top bar                              
-                              'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive'))),
-                                          
-                                   
-                        array('name'=>'visibility',     'index'=>'visibility',      'width'=>'40',   'align'=>'left', 'search' => 'false'),                        
-                        array('name'=>'actions',        'index'=>'actions',         'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false')
-                       );            
 //Autowidth             
 $extra_params['autowidth'] = 'true';
-
-//height auto 
+//Height auto 
 $extra_params['height'] = 'auto';
-//$extra_params['excel'] = 'excel';
 
 $extra_params['rowList'] = array(10, 20 ,30);
 
+$result = SessionManager::get_session_columns();
+$columns = $result['columns'];
+$column_model = $result['column_model'];
+
+$extra_params['postData'] =array (
+                    'filters' => array(                                        
+                                        "groupOp" => "AND",                                         
+                                        "rules" => $result['rules'], 
+                                        /*array(
+                                            array( "field" => "display_start_date", "op" => "gt", "data" => ""),
+                                            array( "field" => "display_end_date", "op" => "gt", "data" => "")
+                                        ),*/ 
+                                        //'groups' => $groups
+                                )                                
+);
+/*
+     $filters = array('filters' => array( "groupOp" => "AND", 
+                                        "rules" => $rules));
+    
+     $filters = json_encode($filters);
+ var_dump($filters);*/
 
 //With this function we can add actions to the jgrid (edit, delete, etc)
 $action_links = 'function action_formatter(cellvalue, options, rowObject) {
-                         return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
+                         return \'<a href="session_add.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
                          '&nbsp;<a href="add_users_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('user_subscribe_session.png',get_lang('SubscribeUsersToSession'),'',ICON_SIZE_SMALL).'</a>'.
                          '&nbsp;<a href="add_courses_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('courses_to_session.png',get_lang('SubscribeCoursesToSession'),'',ICON_SIZE_SMALL).'</a>'.
                          '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="session_list.php?action=copy&idChecked=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
                          '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;"  href="session_list.php?action=delete&idChecked=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
                          '\'; 
                  }';
+$url_select = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
 ?>
 <script>
 
-
 function setSearchSelect(columnName) {    
-    $("#sessions").jqGrid('setColProp', columnName,
-    {                   
-       searchoptions:{
+    $("#sessions").jqGrid('setColProp', columnName, {                   
+       /*searchoptions:{
             dataInit:function(el){                            
                 $("option[value='1']",el).attr("selected", "selected");
                 setTimeout(function(){
                     $(el).trigger('change');
-                },1000);
+                }, 1000);
             }
-        }
+        }*/
     });
 }
+var added_cols = [];
+var original_cols = [];
+
+function clean_cols(grid, added_cols) {
+    //Cleaning 
+    for (key in added_cols) {
+        //console.log('hide: ' + key);                    
+        grid.hideCol(key);
+    };
+    grid.showCol('name');
+    grid.showCol('display_start_date');
+    grid.showCol('display_end_date');    
+    grid.showCol('course_title');
+}
+
+function show_cols(grid, added_cols) {
+    grid.showCol('name').trigger('reloadGrid');
+    for (key in added_cols) {
+        //console.log('show: ' + key);
+        grid.showCol(key);
+    };    
+}
 
+var second_filters = [];
 
 $(function() {
+    date_pick_today = function(elem) {
+        $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
+        $(elem).datetimepicker('setDate', (new Date()));
+    }
+    date_pick_one_month = function(elem) {
+        $(elem).datetimepicker({dateFormat: "yy-mm-dd"});
+        next_month = Date.today().next().month();
+        $(elem).datetimepicker('setDate', next_month);
+    }
+    
+    //Great hack
+    register_second_select = function(elem) {
+        second_filters[$(elem).val()] = $(elem);        
+    }
+    
+    fill_second_select = function(elem) {
+        $(elem).on("change", function() {
+            composed_id = $(this).val();
+            field_id = composed_id.split("#")[0];
+            id = composed_id.split("#")[1];
+            
+            $.ajax({
+                url: "<?php echo $url_select ?>&a=get_second_select_options", 
+                dataType: "json",
+                data: "type=session&field_id="+field_id+"&option_value_id="+id,
+                success: function(data) {
+                    my_select = second_filters[field_id];
+                    my_select.empty();
+                    $.each(data, function(index, value) {
+                        my_select.append($("<option/>", {
+                            value: index,
+                            text: value
+                        }));
+                    });            
+                }
+            }); 
+        });        
+    }
+
     <?php 
-        echo Display::grid_js('sessions', $url,$columns,$column_model,$extra_params, array(), $action_links,true);      
+        echo Display::grid_js('sessions', $url, $columns, $column_model, $extra_params, array(), $action_links, true);      
     ?>
     
-    setSearchSelect("status");    
+    setSearchSelect("status");
     
-    $("#sessions").jqGrid('navGrid','#sessions_pager', {edit:false,add:false,del:false},
+    var grid = $("#sessions"),
+    prmSearch = {
+        multipleSearch : true, 
+        overlay : false, 
+        width: 600,
+        caption: '<?php echo addslashes(get_lang('Search')); ?>',
+        formclass:'data_table',
+        onSearch : function() {
+            var postdata = grid.jqGrid('getGridParam', 'postData');
+                        
+            if (postdata && postdata.filters) {
+                filters = jQuery.parseJSON(postdata.filters);
+                clean_cols(grid, added_cols);
+                added_cols = [];                
+                $.each(filters, function(key, value){
+                    if (key == 'rules') {
+                        $.each(value, function(key, value) {
+                            //if (added_cols[value.field] == undefined) {
+                                added_cols[value.field] = value.field;
+                            //}
+                            //grid.showCol(value.field);                            
+                        });
+                    }                    
+                });
+                show_cols(grid, added_cols);                
+            }
+       },
+       onReset: function() {      
+            clean_cols(grid, added_cols);
+       }
+    };
+    
+    original_cols = grid.jqGrid('getGridParam', 'colModel');    
+    
+    grid.jqGrid('navGrid','#sessions_pager', 
+        {edit:false,add:false,del:false},
         {height:280,reloadAfterSubmit:false}, // edit options 
         {height:280,reloadAfterSubmit:false}, // add options 
-        {reloadAfterSubmit:false}, // del options 
-        {width:500} // search options
+        {reloadAfterSubmit:false},// del options 
+        prmSearch
     );
-    /*
-    // add custom button to export the data to excel
-    jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
-           caption:"", 
-           onClickButton : function () { 
-               jQuery("#sessions").excelExport();
-           } 
-    });
+                  
+    // create the searching dialog
+    grid.searchGrid(prmSearch);
     
-    jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
-    {
-        try {
-            jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
-        } catch (e) {
-            window.location= 'grid.php?oper=csv';
-        }
-    },buttonicon:'ui-icon-document'})
-    */
-   
+    //Fixes search table
+    var searchDialogAll = $("#fbox_"+grid[0].id);
+    searchDialogAll.addClass("table");
     
-    //Adding search options
-    var options = {
-        'stringResult': true,
-        'autosearch' : true,
-        'searchOnEnter':false      
-    }
-    jQuery("#sessions").jqGrid('filterToolbar',options);    
-    var sgrid = $("#sessions")[0];
-    sgrid.triggerToolbar();
+    var searchDialog = $("#searchmodfbox_"+grid[0].id);    
+    searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
+    searchDialog.css({position:"relative", "z-index":"auto", "float":"left"})    
+    var gbox = $("#gbox_"+grid[0].id);
+    gbox.before(searchDialog);
+    gbox.css({clear:"left"});
 });
 </script>
 <div class="actions">
@@ -162,5 +238,35 @@ echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_add.php">'.Display::
 echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/add_many_session_to_category.php">'.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_list.php">'.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '</div>';
+
+$form = new FormValidator('search');
+
+$form->addElement('header', get_lang('Filter'));
+
+$form->addElement('text', 'start_date_start', get_lang('Between'), array('id' =>'start_date_start'));
+$form->addElement('text', 'start_date_end', get_lang('And'), array('id' =>'start_date_end'));
+$renderer = $form->defaultRenderer();
+
+$renderer->setElementTemplate(get_lang('StartDate').' {label} {element}', 'start_date_start');  
+$renderer->setElementTemplate('{label} {element}', 'start_date_end');  
+
+$form->addElement('html', '<div class="clear"></div>');
+
+$form->addElement('text', 'end_date_start', get_lang('Between'), array('id' =>'end_date_start'));
+$form->addElement('text', 'end_date_end', get_lang('And'), array('id' =>'end_date_end'));
+
+$renderer->setElementTemplate(get_lang('EndDate').' {label} {element}', 'end_date_start');  
+$renderer->setElementTemplate('{label} {element}', 'end_date_end');  
+           
+$options = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
+$form->addElement('select', 'course', get_lang('Course'), $options);
+
+
+//$session_field->add_elements($form);
+
+$form->addElement('button', 'submit', get_lang('Search'), array('id' => 'search_button'));
+
+//$form->display();
+
 echo Display::grid_html('sessions');
 Display::display_footer();

+ 0 - 3
main/admin/session_user_import.php

@@ -13,9 +13,6 @@ require '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-
 $form_sent = 0;
 $error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
 if (isset($_GET['action']) && $_GET['action'] == 'show_message') {

+ 1 - 2
main/admin/settings.lib.php

@@ -605,8 +605,7 @@ function handle_search() {
     $form->display();
     echo '</div>';
     
-    if ($search_enabled == 'true') {
-        require_once api_get_path(LIBRARY_PATH).'sortable_table.class.php';        
+    if ($search_enabled == 'true') {         
         $xapian_path = api_get_path(SYS_PATH).'searchdb';
         
         /*

+ 0 - 1
main/admin/settings.php

@@ -27,7 +27,6 @@ $cidReset = true;
 
 // Including some necessary library files.
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
 require_once 'settings.lib.php';
 

+ 0 - 3
main/admin/skills_import.php

@@ -12,9 +12,6 @@ $language_file = array ('admin', 'registration');
 
 $cidReset = true;
 require '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
 
 function validate_data($skills) {
     $errors = array();

+ 0 - 2
main/admin/statistics.php

@@ -14,8 +14,6 @@ $this_section=SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-
 $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
 $tool_name = get_lang('Statistics');
 Display::display_header($tool_name);

+ 3 - 9
main/admin/statistics/index.php

@@ -18,8 +18,6 @@ $tool_name = get_lang('Statistics');
 Display::display_header($tool_name);
 echo Display::page_header($tool_name);
 
-//require_once 'statistics.lib.php'; moved to autoload
-
 $strCourse = get_lang('Courses');
 $strUsers = get_lang('Users');
 $strSystem = get_lang('System');
@@ -83,8 +81,7 @@ switch ($_GET['report']) {
         break;
     case 'courselastvisit':
         Statistics::print_course_last_visit();
-        break;
-    //---
+        break;    
     case 'users':
         // total amount of users
         Statistics::print_stats(
@@ -118,12 +115,10 @@ switch ($_GET['report']) {
         break;
     case 'zombies':
         ZombieReport::create(array('report' => 'zombies'))->display();
-        break;
-    //---
+        break;    
     case 'activities':
         Statistics::print_activities_stats();
-        break;
-    //---
+        break;    
     case 'messagesent':
         $messages_sent = Statistics::get_messages('sent');
         Statistics::print_stats(get_lang('MessagesSent'), $messages_sent);
@@ -138,5 +133,4 @@ switch ($_GET['report']) {
         Statistics::print_stats(get_lang('CountFriends'), $friends);
         break;
 }
-
 Display::display_footer();

+ 0 - 174
main/admin/style_preview.php

@@ -1,174 +0,0 @@
-<?php
-/* For licensing terms, see /chamilo_license.txt */
-// @deprecated This page is not used
-
-exit;
-$language_file = array('create_course', 'courses', 'admin');
-
-require_once '../inc/global.inc.php';
-
-// Setting the section (for the tabs).
-$this_section = SECTION_PLATFORM_ADMIN;
-
-// Access restriction.
-api_protect_admin_script();
-
-// Manipulation of the platform-wide css setting.
-if (isset($_GET['style']) && $_GET['style'] != '') {
-	$_setting['stylesheets'] = Security::remove_XSS($_GET['style']);
-}
-
-// Hiding the link "Teacher/Student view", it is not needed to be shown here.
-$_setting['student_view_enabled'] = 'false';
-
-require_once api_get_path(INCLUDE_PATH).'header.inc.php';
-
-$week_days_short = api_get_week_days_short();
-$months_long = api_get_months_long();
-
-?>
-  <div class="maincontent" id="content">
-    <h3><?php echo get_lang('Title'); ?></h3>
-    <div id="courseintro">
-      <p><?php echo get_lang('IntroductionText'); ?></p>
-    </div>
-    <div id="courseintro_icons">
-    <a href="#"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a><a href="#"><?php Display::display_icon('delete.gif', get_lang('Delete')); ?></a></div>
-    <div class="normal-message">Normal Message</div>
-    <div class="confirmation-message">Confirmation Message</div>
-    <div class="warning-message">Warning Message</div>
-    <div class="error-message">Error Message</div>
-    <table width="750">
-      <tr>
-        <td>
-        <table>
-            <tr>
-              <td width="220">
-              <table id="smallcalendar" class="data_table">
-                  <tr id="title">
-                    <td width="10%"><a href="#"><?php Display::display_icon('action_prev.png'); ?></a></td>
-                    <td width="80%" colspan="5" align="center"><?php echo $months_long[6]; ?> 2010</td>
-                    <td width="10%"><a href="#"><?php Display::display_icon('action_next.png'); ?></a></td>
-                  </tr>
-                  <tr>
-                    <td class="weekdays"><?php echo $week_days_short[1]; ?></td>
-                    <td class="weekdays"><?php echo $week_days_short[2]; ?></td>
-                    <td class="weekdays"><?php echo $week_days_short[3]; ?></td>
-                    <td class="weekdays"><?php echo $week_days_short[4]; ?></td>
-                    <td class="weekdays"><?php echo $week_days_short[5]; ?></td>
-                    <td class="weekdays"><?php echo $week_days_short[6]; ?></td>
-                    <td class="weekdays"><?php echo $week_days_short[0]; ?></td>
-                  </tr>
-                  <tr>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td class="days_weekend">1</td>
-                  </tr>
-                  <tr>
-                    <td class="days_week">2</td>
-                    <td class="days_week">3</td>
-                    <td class="days_week">4</td>
-                    <td class="days_week">5</td>
-                    <td class="days_week">6</td>
-                    <td class="days_weekend">7</td>
-                    <td class="days_weekend">8</td>
-                  </tr>
-                  <tr>
-                    <td class="days_week">9</td>
-                    <td class="days_week">10</td>
-                    <td class="days_week">11</td>
-                    <td class="days_week">12</td>
-                    <td class="days_week">13</td>
-                    <td class="days_weekend">14</td>
-                    <td class="days_weekend">15</td>
-                  </tr>
-                  <tr>
-                    <td class="days_week">16</td>
-                    <td class="days_week">17</td>
-                    <td class="days_week">18</td>
-                    <td class="days_week">19</td>
-                    <td class="days_week">20</td>
-                    <td class="days_weekend">21</td>
-                    <td class="days_weekend">22</td>
-                  </tr>
-                  <tr>
-                    <td class="days_week">23</td>
-                    <td class="days_today">24</td>
-                    <td class="days_week">25</td>
-                    <td class="days_week">26</td>
-                    <td class="days_week">27</td>
-                    <td class="days_weekend">28</td>
-                    <td class="days_weekend">29</td>
-                  </tr>
-                  <tr>
-                    <td class="days_week">30</td>
-                    <td class="days_week">31</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                    <td>&nbsp;</td>
-                  </tr>
-                </table>
-              </td>
-            </tr>
-          </table>
-        </td>
-        <td width="500">
-          <table width="100%">
-            <tr>
-              <td></td>
-              <td align="right"></td>
-            </tr>
-          </table>
-          <table class="data_table" style="width: 250px;">
-            <tr>
-              <th style="width: 50%;"><a href="#"><?php echo get_lang('FirstName'); ?></a>&nbsp;&#8595; </th>
-              <th><a href="#"><?php echo get_lang('LastName'); ?></a></th>
-            </tr>
-            <tr class="row_odd">
-              <td>Julio</td>
-              <td>Montoya</td>
-            </tr>
-            <tr class="row_even">
-              <td>Yannick</td>
-              <td>Warnier</td>
-            </tr>
-          </table>
-          <table width="100%">
-            <tr>
-              <td></td>
-              <td align="right"></td>
-            </tr>
-          </table>
-        </td>
-      </tr>
-    </table>
-  </div>
-  <div class="menu" id="menu">
-    <form action="#" method="post" id="formLogin" name="formLogin"><br />
-      <label><?php echo get_lang('UserName'); ?></label><br />
-      <input type="text" name="login" id="login" size="15" value="" /><br />
-      <label><?php echo get_lang('Password'); ?></label><br />
-      <input type="password" name="password" id="password" size="15" /><br />
-  	  <button class="login" type="submit" name="submitAuth"disabled="disabled" ><?php echo get_lang('LoginEnter'); ?></button>
-  	  <div class="clear">
-        &nbsp;
-  	  </div>
-    </form>
-    <div class="menusection"><span class="menusectioncaption"><?php echo get_lang('User'); ?></span>
-      <ul class="menulist">
-        <li><a href="#"><?php echo get_lang('CourseManagement'); ?></a></li>
-        <li><a href="#"><?php echo get_lang('CourseCreate'); ?></a></li>
-      </ul>
-    </div>
-    <div class="note"><b>Example notice</b><br />
-      To modify this notice, go to the administration area of the portal.</div>
-  </div>
-<?php
-Display::display_footer();
-?>

+ 1 - 3
main/admin/user_add.php

@@ -10,9 +10,7 @@ $cidReset = true;
 // Including necessary libraries.
 require_once '../inc/global.inc.php';
 $libpath = api_get_path(LIBRARY_PATH);
-require_once $libpath.'fileManage.lib.php';
 require_once $libpath.'fileUpload.lib.php';
-require_once $libpath.'mail.lib.inc.php';
 
 // Section for the tabs
 $this_section = SECTION_PLATFORM_ADMIN;
@@ -207,7 +205,7 @@ $form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
 
 $extra_data = UserManager::get_extra_user_data(0, true);
 
-$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'user_add');
+$return_params = ExtraField::set_extra_fields_in_form($form, $extra_data, 'user_add', false, null, 'user');
 $jquery_ready_content = $return_params['jquery_ready_content'];
 
 // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function

+ 1 - 3
main/admin/user_edit.php

@@ -68,9 +68,7 @@ function show_image(image,width,height) {
 </script>';
 
 $libpath = api_get_path(LIBRARY_PATH);
-require_once $libpath.'fileManage.lib.php';
 require_once $libpath.'fileUpload.lib.php';
-require_once $libpath.'mail.lib.inc.php';
 
 $noPHP_SELF = true;
 $tool_name = get_lang('ModifyUserInfo');
@@ -266,7 +264,7 @@ if (!$user_data['platform_admin']) {
 
 
 // EXTRA FIELDS
-$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'user_edit', true, $user_id);
+$return_params = ExtraField::set_extra_fields_in_form($form, $extra_data, 'user_edit', true, $user_id, 'user');
 $jquery_ready_content = $return_params['jquery_ready_content'];
 
 // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function

+ 266 - 280
main/admin/user_fields.php

@@ -1,8 +1,9 @@
 <?php
+
 /* For licensing terms, see /license.txt */
 /**
-*	@package chamilo.admin
-*/
+ * 	@package chamilo.admin
+ */
 // name of the language file that needs to be included
 $language_file = array('admin', 'registration');
 $cidReset = true;
@@ -11,170 +12,167 @@ $cidReset = true;
 require '../inc/global.inc.php';
 
 // section for the tabs
-$this_section=SECTION_PLATFORM_ADMIN;
+$this_section = SECTION_PLATFORM_ADMIN;
 
 // user permissions
 api_protect_admin_script();
 
 // Database table definitions
-$table_admin	= Database :: get_main_table(TABLE_MAIN_ADMIN);
-$table_user 	= Database :: get_main_table(TABLE_MAIN_USER);
-$table_uf	 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD);
-$table_uf_opt 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
-$table_uf_val 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
+$table_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
+$table_user = Database :: get_main_table(TABLE_MAIN_USER);
+$table_uf = Database :: get_main_table(TABLE_MAIN_USER_FIELD);
+$table_uf_opt = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
+$table_uf_val = Database :: get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
 
-$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
 
 // Display form
-if(1)
-{
-	$tool_name = get_lang('UserFields');
-	Display :: display_header($tool_name, "");
-	//api_display_tool_title($tool_name);
-	if (isset ($_GET['action']))
-	{
-		$check = Security::check_token('get');
-		if($check) {
-			switch ($_GET['action']) {
-				case 'show_message' :
-					Display :: display_normal_message($_GET['message']);
-					break;
-				case 'show_field' :
-					if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_visible'=>'1'))) {
-						Display :: display_confirmation_message(get_lang('FieldShown'));
-					} else {
-						Display :: display_error_message(get_lang('CannotShowField'));
-					}
-					break;
-				case 'hide_field' :
-					if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_visible'=>'0'))) {
-						Display :: display_confirmation_message(get_lang('FieldHidden'));
-					} else {
-						Display :: display_error_message(get_lang('CannotHideField'));
-					}
-					break;
-				case 'thaw_field' :
-					if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_changeable'=>'1'))) {
-						Display :: display_confirmation_message(get_lang('FieldMadeChangeable'));
-					} else {
-						Display :: display_error_message(get_lang('CannotMakeFieldChangeable'));
-					}
-					break;
-				case 'freeze_field' :
-					if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_changeable'=>'0'))) {
-						Display :: display_confirmation_message(get_lang('FieldMadeUnchangeable'));
-					} else {
-						Display :: display_error_message(get_lang('CannotMakeFieldUnchangeable'));
-					}
-					break;
-				case 'moveup' :
-					if (api_is_platform_admin() && !empty($_GET['field_id'])) {
-						if (move_user_field('moveup', $_GET['field_id'])) {
-							Display :: display_confirmation_message(get_lang('FieldMovedUp'));
-						} else {
-							Display :: display_error_message(get_lang('CannotMoveField'));
-						}
-					}
-					break;
-				case 'movedown' :
-					if (api_is_platform_admin() && !empty($_GET['field_id'])) {
-						if (move_user_field('movedown', $_GET['field_id'])) {
-							Display :: display_confirmation_message(get_lang('FieldMovedDown'));
-						} else {
-							Display :: display_error_message(get_lang('CannotMoveField'));
-						}
-					}
-					break;
-				case 'filter_on' :
-					if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_filter'=>'1'))) {
-						Display :: display_confirmation_message(get_lang('FieldFilterSetOn'));
-					} else {
-						Display :: display_error_message(get_lang('CannotShowField'));
-					}
-					break;
-				case 'filter_off' :
-					if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'],array('field_filter'=>'0'))) {
-						Display :: display_confirmation_message(get_lang('FieldFilterSetOff'));
-					} else {
-						Display :: display_error_message(get_lang('CannotShowField'));
-					}
-					break;
-
-				case 'delete':
-					if (api_is_platform_admin() && !empty($_GET['field_id'])) {
-						if (delete_user_fields($_GET['field_id'])) {
-							Display :: display_confirmation_message(get_lang('FieldDeleted'));
-						} else {
-							Display :: display_error_message(get_lang('CannotDeleteField'));
-						}
-					}
-					break;
-			}
-			Security::clear_token();
-		}
-	}
-	if (isset ($_POST['action'])) {
-		$check = Security::check_token('get');
-		if($check) {
-			switch ($_POST['action']) {
-				default:
-					break;
-			}
-			Security::clear_token();
-		}
-	}
-
-	// Create an add-field box
-	$form = new FormValidator('add_field','post','','',null,false);
-	$renderer =& $form->defaultRenderer();
-	$renderer->setElementTemplate('<span>{element}</span> ');
-	//$form->addElement('text','label',get_lang('FieldLabel'));
-	//$form->addElement('text','type',get_lang('FieldType'));
-	//$form->addElement('text','title',get_lang('FieldTitle'));
-	//$form->addElement('text','default',get_lang('FieldDefaultValue'));
-	//$form->addElement('submit','submit',get_lang('Search'));
-	$form->addElement('static','search_advanced_link',null,'<a href="user_fields_add.php?action=fill">'.Display::return_icon('add_user_fields.png', get_lang('AddUserField'),'',ICON_SIZE_MEDIUM).'</a>');
-	echo '<div class="actions">';
-	$form->display();
-	echo '</div>';
-
-	// Create a sortable table with user-data
-	$parameters['sec_token'] = Security::get_token();
-	//$column_show  = array(1,1,1,1,1,1,1,1,1,0,0);
-	//$column_order = array(1,2,3,4,5,6,7,8,9,10,11);
-	$extra_fields = UserManager::get_extra_fields();
-	$number_of_extra_fields = count($extra_fields);
-
-    $table = new SortableTable('user_field', array('UserManager','get_number_of_extra_fields'), array('UserManager','get_extra_fields'),5);
-	$table->set_additional_parameters($parameters);
-	$table->set_header(0, '', false);
-	$table->set_header(1, get_lang('FieldLabel'), false);
-	$table->set_header(2, get_lang('FieldType'), false);
-	$table->set_header(3, get_lang('FieldTitle'),false);
-	$table->set_header(4, get_lang('FieldDefaultValue'),false);
-	$table->set_header(5, get_lang('FieldOrder'), false);
-	$table->set_header(6, get_lang('FieldVisibility'), false);
-	$table->set_header(7, get_lang('FieldChangeability'), false);
-	$table->set_header(8, get_lang('FieldFilter'), false);
-	$table->set_header(9, get_lang('Modify'), false);
-	$table->set_column_filter(5, 'order_filter');
-	$table->set_column_filter(6, 'modify_visibility');
-	$table->set_column_filter(7, 'modify_changeability');
-	$table->set_column_filter(8, 'modify_field_filter');
-	$table->set_column_filter(9, 'edit_filter');
-	$table->set_column_filter(2, 'type_filter');
-	$table->display();
+$tool_name = get_lang('UserFields');
+Display :: display_header($tool_name);
+
+if (isset($_GET['action'])) {
+    $check = Security::check_token('get');
+    if ($check) {
+        switch ($_GET['action']) {
+            case 'show_message' :
+                Display :: display_normal_message($_GET['message']);
+                break;
+            case 'show_field' :
+                if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'], array('field_visible' => '1'))) {
+                    Display :: display_confirmation_message(get_lang('FieldShown'));
+                } else {
+                    Display :: display_error_message(get_lang('CannotShowField'));
+                }
+                break;
+            case 'hide_field' :
+                if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'], array('field_visible' => '0'))) {
+                    Display :: display_confirmation_message(get_lang('FieldHidden'));
+                } else {
+                    Display :: display_error_message(get_lang('CannotHideField'));
+                }
+                break;
+            case 'thaw_field' :
+                if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'], array('field_changeable' => '1'))) {
+                    Display :: display_confirmation_message(get_lang('FieldMadeChangeable'));
+                } else {
+                    Display :: display_error_message(get_lang('CannotMakeFieldChangeable'));
+                }
+                break;
+            case 'freeze_field' :
+                if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'], array('field_changeable' => '0'))) {
+                    Display :: display_confirmation_message(get_lang('FieldMadeUnchangeable'));
+                } else {
+                    Display :: display_error_message(get_lang('CannotMakeFieldUnchangeable'));
+                }
+                break;
+            case 'moveup' :
+                if (api_is_platform_admin() && !empty($_GET['field_id'])) {
+                    if (move_user_field('moveup', $_GET['field_id'])) {
+                        Display :: display_confirmation_message(get_lang('FieldMovedUp'));
+                    } else {
+                        Display :: display_error_message(get_lang('CannotMoveField'));
+                    }
+                }
+                break;
+            case 'movedown' :
+                if (api_is_platform_admin() && !empty($_GET['field_id'])) {
+                    if (move_user_field('movedown', $_GET['field_id'])) {
+                        Display :: display_confirmation_message(get_lang('FieldMovedDown'));
+                    } else {
+                        Display :: display_error_message(get_lang('CannotMoveField'));
+                    }
+                }
+                break;
+            case 'filter_on' :
+                if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'], array('field_filter' => '1'))) {
+                    Display :: display_confirmation_message(get_lang('FieldFilterSetOn'));
+                } else {
+                    Display :: display_error_message(get_lang('CannotShowField'));
+                }
+                break;
+            case 'filter_off' :
+                if (api_is_platform_admin() && !empty($_GET['field_id']) && UserManager :: update_extra_field($_GET['field_id'], array('field_filter' => '0'))) {
+                    Display :: display_confirmation_message(get_lang('FieldFilterSetOff'));
+                } else {
+                    Display :: display_error_message(get_lang('CannotShowField'));
+                }
+                break;
+
+            case 'delete':
+                if (api_is_platform_admin() && !empty($_GET['field_id'])) {
+                    if (delete_user_fields($_GET['field_id'])) {
+                        Display :: display_confirmation_message(get_lang('FieldDeleted'));
+                    } else {
+                        Display :: display_error_message(get_lang('CannotDeleteField'));
+                    }
+                }
+                break;
+        }
+        Security::clear_token();
+    }
+}
+if (isset($_POST['action'])) {
+    $check = Security::check_token('get');
+    if ($check) {
+        switch ($_POST['action']) {
+            default:
+                break;
+        }
+        Security::clear_token();
+    }
 }
 
+// Create an add-field box
+$form = new FormValidator('add_field', 'post', '', '', null, false);
+$renderer = & $form->defaultRenderer();
+$renderer->setElementTemplate('<span>{element}</span> ');
+//$form->addElement('text','label',get_lang('FieldLabel'));
+//$form->addElement('text','type',get_lang('FieldType'));
+//$form->addElement('text','title',get_lang('FieldTitle'));
+//$form->addElement('text','default',get_lang('FieldDefaultValue'));
+//$form->addElement('submit','submit',get_lang('Search'));
+$form->addElement('static', 'search_advanced_link', null, '<a href="user_fields_add.php?action=fill">' . Display::return_icon('add_user_fields.png', get_lang('AddUserField'), '', ICON_SIZE_MEDIUM) . '</a>');
+echo '<div class="actions">';
+$form->display();
+echo '</div>';
+
+// Create a sortable table with user-data
+$parameters['sec_token'] = Security::get_token();
+//$column_show  = array(1,1,1,1,1,1,1,1,1,0,0);
+//$column_order = array(1,2,3,4,5,6,7,8,9,10,11);
+$extra_fields = UserManager::get_extra_fields();
+$number_of_extra_fields = count($extra_fields);
+
+$table = new SortableTable('user_field', array('UserManager', 'get_number_of_extra_fields'), array('UserManager', 'get_extra_fields'), 5);
+$table->set_additional_parameters($parameters);
+$table->set_header(0, '', false);
+$table->set_header(1, get_lang('FieldLabel'), false);
+$table->set_header(2, get_lang('FieldType'), false);
+$table->set_header(3, get_lang('FieldTitle'), false);
+$table->set_header(4, get_lang('FieldDefaultValue'), false);
+$table->set_header(5, get_lang('FieldOrder'), false);
+$table->set_header(6, get_lang('FieldVisibility'), false);
+$table->set_header(7, get_lang('FieldChangeability'), false);
+$table->set_header(8, get_lang('FieldFilter'), false);
+$table->set_header(9, get_lang('Modify'), false);
+$table->set_column_filter(5, 'order_filter');
+$table->set_column_filter(6, 'modify_visibility');
+$table->set_column_filter(7, 'modify_changeability');
+$table->set_column_filter(8, 'modify_field_filter');
+$table->set_column_filter(9, 'edit_filter');
+$table->set_column_filter(2, 'type_filter');
+$table->display();
+
+
 Display::display_footer();
+
 //gateway functions to the UserManager methods (provided for SorteableTable callback mechanism)
-function get_number_of_extra_fields()
-{
-	return UserManager::get_number_of_extra_fields();
+function get_number_of_extra_fields() {
+    return UserManager::get_number_of_extra_fields();
 }
-function get_extra_fields($f,$n,$o,$d)
-{
-	return UserManager::get_extra_fields($f,$n,$o,$d);
+
+function get_extra_fields($f, $n, $o, $d) {
+    return UserManager::get_extra_fields($f, $n, $o, $d);
 }
 
 /**
@@ -189,7 +187,7 @@ function get_extra_fields($f,$n,$o,$d)
  */
 function type_filter($type) {
     $types = UserManager::get_user_field_types();
-	return $types[$type];
+    return $types[$type];
 }
 
 /**
@@ -204,23 +202,23 @@ function type_filter($type) {
  * @version July 2008
  * @since Dokeos 1.8.6
  */
-function order_filter($field_order,$url_params,$row)
-{
-	global $number_of_extra_fields;
-	$return = '';
-	// the up icon only has to appear when the row can be moved up (all but the first row)
-	if ($row[5]<>1) {
-		$return .= '<a href="'.api_get_self().'?action=moveup&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('up.gif', get_lang('Up')).'</a>';
-	} else {
-		$return .= Display::return_icon('blank.gif','',array('width'=>'21px'));
-	}
-
-	// the down icon only has to appear when the row can be moved down (all but the last row)
-	if ($row[5]<>$number_of_extra_fields) {
-		$return .= '<a href="'.api_get_self().'?action=movedown&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('down.gif', get_lang('Down')).'</a>';
-	}
-	return $return;
+function order_filter($field_order, $url_params, $row) {
+    global $number_of_extra_fields;
+    $return = '';
+    // the up icon only has to appear when the row can be moved up (all but the first row)
+    if ($row[5] <> 1) {
+        $return .= '<a href="' . api_get_self() . '?action=moveup&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('up.gif', get_lang('Up')) . '</a>';
+    } else {
+        $return .= Display::return_icon('blank.gif', '', array('width' => '21px'));
+    }
+
+    // the down icon only has to appear when the row can be moved down (all but the last row)
+    if ($row[5] <> $number_of_extra_fields) {
+        $return .= '<a href="' . api_get_self() . '?action=movedown&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('down.gif', get_lang('Down')) . '</a>';
+    }
+    return $return;
 }
+
 /**
  * Modify the visible field to show links and icons
  * @param	int 	The current visibility
@@ -228,10 +226,10 @@ function order_filter($field_order,$url_params,$row)
  * @param	array	The results row
  * @return	string	The link
  */
-function modify_visibility($visibility,$url_params,$row)
-{
-	return ($visibility?'<a href="'.api_get_self().'?action=hide_field&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('visible.gif', get_lang('Hide')).'</a>':'<a href="'.api_get_self().'?action=show_field&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('invisible.gif', get_lang('Show')).'</a>');
+function modify_visibility($visibility, $url_params, $row) {
+    return ($visibility ? '<a href="' . api_get_self() . '?action=hide_field&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('visible.gif', get_lang('Hide')) . '</a>' : '<a href="' . api_get_self() . '?action=show_field&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('invisible.gif', get_lang('Show')) . '</a>');
 }
+
 /**
  * Modify the changeability field to show links and icons
  * @param	int 	The current changeability
@@ -239,23 +237,21 @@ function modify_visibility($visibility,$url_params,$row)
  * @param	array	The results row
  * @return	string	The link
  */
-function modify_changeability($changeability,$url_params,$row)
-{
-	return ($changeability?'<a href="'.api_get_self().'?action=freeze_field&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('right.gif', get_lang('MakeUnchangeable')).'</a>':'<a href="'.api_get_self().'?action=thaw_field&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('wrong.gif', get_lang('MakeChangeable')).'</a>');
+function modify_changeability($changeability, $url_params, $row) {
+    return ($changeability ? '<a href="' . api_get_self() . '?action=freeze_field&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('right.gif', get_lang('MakeUnchangeable')) . '</a>' : '<a href="' . api_get_self() . '?action=thaw_field&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('wrong.gif', get_lang('MakeChangeable')) . '</a>');
 }
 
-function modify_field_filter ($changeability,$url_params,$row)
-{
-	return ($changeability?'<a href="'.api_get_self().'?action=filter_off&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('right.gif', get_lang('FilterOff')).'</a>':'' .
-						   '<a href="'.api_get_self().'?action=filter_on&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('wrong.gif', get_lang('FilterOn')).'</a>');
+function modify_field_filter($changeability, $url_params, $row) {
+    return ($changeability ? '<a href="' . api_get_self() . '?action=filter_off&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('right.gif', get_lang('FilterOff')) . '</a>' : '' .
+                    '<a href="' . api_get_self() . '?action=filter_on&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('wrong.gif', get_lang('FilterOn')) . '</a>');
 }
 
 function edit_filter($id, $url_params, $row) {
-	global $charset;
-	$return = '<a href="user_fields_add.php?action=edit&field_id='.$row[0].'&field_type='.$row[2].'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('edit.png',get_lang('Edit')).'</a>';
-	$return .= ' <a href="'.api_get_self().'?action=delete&field_id='.$row[0].'&sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.
-            Display::return_icon('delete.png',get_lang('Delete')).'</a>';
-	return $return;
+    global $charset;
+    $return = '<a href="user_fields_add.php?action=edit&field_id=' . $row[0] . '&field_type=' . $row[2] . '&sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('edit.png', get_lang('Edit')) . '</a>';
+    $return .= ' <a href="' . api_get_self() . '?action=delete&field_id=' . $row[0] . '&sec_token=' . $_SESSION['sec_token'] . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)) . "'" . ')) return false;">' .
+            Display::return_icon('delete.png', get_lang('Delete')) . '</a>';
+    return $return;
 }
 
 /**
@@ -268,71 +264,64 @@ function edit_filter($id, $url_params, $row) {
  * @version July 2008
  * @since Dokeos 1.8.6
  */
-function move_user_field($direction,$field_id) {
-	// Databse table definitions
-	$table_user_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
-
-	// check the parameters
-	if (!in_array($direction,array('moveup','movedown')) OR !is_numeric($field_id))
-	{
-		return false;
-	}
-
-	// determine the SQL sort direction
-	if ($direction == 'moveup')
-	{
-		$sortdirection = 'DESC';
-	}
-	else
-	{
-		$sortdirection = 'ASC';
-	}
+function move_user_field($direction, $field_id) {
+    // Databse table definitions
+    $table_user_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
+
+    // check the parameters
+    if (!in_array($direction, array('moveup', 'movedown')) OR !is_numeric($field_id)) {
+        return false;
+    }
+
+    // determine the SQL sort direction
+    if ($direction == 'moveup') {
+        $sortdirection = 'DESC';
+    } else {
+        $sortdirection = 'ASC';
+    }
 
     // first reorder user_fields
     reorder_user_fields();
 
-	$found = false;
-	$sql = "SELECT id, field_order FROM $table_user_field ORDER BY field_order $sortdirection";
-	$result = Database::query($sql);
-	while($row = Database::fetch_array($result))
-	{
-		if ($found)
-		{
-			$next_id = $row['id'];
-			$next_order = $row['field_order'];
-			break;
-		}
-
-		if ($field_id == $row['id'])
-		{
-			$this_id = $row['id'];
-			$this_order = $row['field_order'];
-			$found = true;
-		}
-	}
-
-	$sql1 = "UPDATE ".$table_user_field." SET field_order = '".intval($next_order)."' WHERE id =  '".intval($this_id)."'";
-	$sql2 = "UPDATE ".$table_user_field." SET field_order = '".intval($this_order)."' WHERE id =  '".intval($next_id)."'";
-	Database::query($sql1);
-	Database::query($sql2);
-
-	return true;
+    $found = false;
+    $sql = "SELECT id, field_order FROM $table_user_field ORDER BY field_order $sortdirection";
+    $result = Database::query($sql);
+    while ($row = Database::fetch_array($result)) {
+        if ($found) {
+            $next_id = $row['id'];
+            $next_order = $row['field_order'];
+            break;
+        }
+
+        if ($field_id == $row['id']) {
+            $this_id = $row['id'];
+            $this_order = $row['field_order'];
+            $found = true;
+        }
+    }
+
+    $sql1 = "UPDATE " . $table_user_field . " SET field_order = '" . intval($next_order) . "' WHERE id =  '" . intval($this_id) . "'";
+    $sql2 = "UPDATE " . $table_user_field . " SET field_order = '" . intval($this_order) . "' WHERE id =  '" . intval($next_id) . "'";
+    Database::query($sql1);
+    Database::query($sql2);
+
+    return true;
 }
 
 /**
-* Re-order user fields
-*/
+ * Re-order user fields
+ */
 function reorder_user_fields() {
-      // Database table definition
-      $t_user_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
-      $sql = "SELECT * FROM $t_user_field ORDER by field_order ASC";
-      $res = Database::query($sql);
-      $i = 1;
-      while ($row = Database::fetch_array($res)) {
-              $sql_reorder = "UPDATE $t_user_field SET field_order = $i WHERE id = '".$row['id']."'";
-              Database::query($sql_reorder);
-              $i++;
-      }
+    // Database table definition
+    $t_user_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
+    $sql = "SELECT * FROM $t_user_field ORDER by field_order ASC";
+    $res = Database::query($sql);
+    $i = 1;
+    while ($row = Database::fetch_array($res)) {
+        $sql_reorder = "UPDATE $t_user_field SET field_order = $i WHERE id = '" . $row['id'] . "'";
+        Database::query($sql_reorder);
+        $i++;
+    }
 }
 
 /**
@@ -345,42 +334,39 @@ function reorder_user_fields() {
  * @version July 2008
  * @since Dokeos 1.8.6
  */
-function delete_user_fields($field_id)
-{
-	// Database table definitions
-	$table_user_field 			= Database::get_main_table(TABLE_MAIN_USER_FIELD);
-	$table_user_field_options	= Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
-	$table_user_field_values 	= Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
-
-	// delete the fields
-	$sql = "DELETE FROM $table_user_field WHERE id = '".Database::escape_string($field_id)."'";
-	$result = Database::query($sql);
-	if (Database::affected_rows() == 1)
-	{
-		// delete the field options
-		$sql = "DELETE FROM $table_user_field_options WHERE field_id = '".Database::escape_string($field_id)."'";
-		$result = Database::query($sql);
-
-		// delete the field values
-		$sql = "DELETE FROM $table_user_field_values WHERE field_id = '".Database::escape_string($field_id)."'";
-		$result = Database::query($sql);
-
-		// recalculate the field_order because the value is used to show/hide the up/down icon
-		// and the field_order value cannot be bigger than the number of fields
-		$sql = "SELECT * FROM $table_user_field ORDER BY field_order ASC";
-		$result = Database::query($sql);
-		$i = 1;
-		while($row = Database::fetch_array($result))
-		{
-			$sql_reorder = "UPDATE $table_user_field SET field_order = '".Database::escape_string($i)."' WHERE id = '".Database::escape_string($row['id'])."'";
-			$result_reorder = Database::query($sql_reorder);
-			$i++;
-		}
-
-		// field was deleted so we return true
-		return true;
-	} else {
-		// the field was not deleted so we return false
-		return false;
-	}
+function delete_user_fields($field_id) {
+    // Database table definitions
+    $table_user_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
+    $table_user_field_options = Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
+    $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
+
+    // delete the fields
+    $sql = "DELETE FROM $table_user_field WHERE id = '" . Database::escape_string($field_id) . "'";
+    $result = Database::query($sql);
+    if (Database::affected_rows() == 1) {
+        // delete the field options
+        $sql = "DELETE FROM $table_user_field_options WHERE field_id = '" . Database::escape_string($field_id) . "'";
+        $result = Database::query($sql);
+
+        // delete the field values
+        $sql = "DELETE FROM $table_user_field_values WHERE field_id = '" . Database::escape_string($field_id) . "'";
+        $result = Database::query($sql);
+
+        // recalculate the field_order because the value is used to show/hide the up/down icon
+        // and the field_order value cannot be bigger than the number of fields
+        $sql = "SELECT * FROM $table_user_field ORDER BY field_order ASC";
+        $result = Database::query($sql);
+        $i = 1;
+        while ($row = Database::fetch_array($result)) {
+            $sql_reorder = "UPDATE $table_user_field SET field_order = '" . Database::escape_string($i) . "' WHERE id = '" . Database::escape_string($row['id']) . "'";
+            $result_reorder = Database::query($sql_reorder);
+            $i++;
+        }
+
+        // field was deleted so we return true
+        return true;
+    } else {
+        // the field was not deleted so we return false
+        return false;
+    }
 }

+ 108 - 144
main/admin/user_fields_options.php

@@ -1,8 +1,9 @@
 <?php
+
 /* For licensing terms, see /license.txt */
 /**
-*	@package chamilo.admin
-*/
+ * 	@package chamilo.admin
+ */
 // name of the language file that needs to be included
 $language_file = array('admin', 'registration');
 
@@ -13,22 +14,15 @@ $cidReset = true;
 require '../inc/global.inc.php';
 
 // section for the tabs
-$this_section=SECTION_PLATFORM_ADMIN;
+$this_section = SECTION_PLATFORM_ADMIN;
 
 // user permissions
 api_protect_admin_script();
 
-// Database table definitions
-$table_admin				= Database :: get_main_table(TABLE_MAIN_ADMIN);
-$table_user 				= Database :: get_main_table(TABLE_MAIN_USER);
-$table_userfields	 		= Database :: get_main_table(TABLE_MAIN_USER_FIELD);
-$table_userfields_options 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
-$table_userfields_values 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
-
 // breadcrumbs
-$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
-$interbreadcrumb[] = array ('url' => 'user_fields.php', 'name' => get_lang('UserFields'));
-$interbreadcrumb[] = array ('url' => 'user_fields_add.php?action=edit&field_id='.Security::remove_XSS($_GET['field_id']).'&amp;sec_token='.$_SESSION['sec_token'], 'name' => get_lang('EditUserFields'));
+$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array('url' => 'user_fields.php', 'name' => get_lang('UserFields'));
+$interbreadcrumb[] = array('url' => 'user_fields_add.php?action=edit&field_id=' . Security::remove_XSS($_GET['field_id']) . '&amp;sec_token=' . $_SESSION['sec_token'], 'name' => get_lang('EditUserFields'));
 
 // name of the tools
 $tool_name = get_lang('UserFieldsSortOptions');
@@ -36,46 +30,35 @@ $tool_name = get_lang('UserFieldsSortOptions');
 // display header
 Display::display_header($tool_name);
 
-if (isset ($_GET['action']))
-{
-	$check = Security::check_token('get');
-	if($check)
-	{
-		switch ($_GET['action'])
-		{
-			case 'moveup' :
-				if (api_is_platform_admin() && !empty($_GET['option_id']))
-				{
-					if (move_user_field_option('moveup', $_GET['option_id']))
-					{
-						Display :: display_confirmation_message(get_lang('FieldOptionMovedUp'));
-					}
-					else
-					{
-						Display :: display_error_message(get_lang('CannotMoveFieldOption'));
-					}
-				}
-				break;
-			case 'movedown' :
-				if (api_is_platform_admin() && !empty($_GET['option_id']))
-				{
-					if (move_user_field_option('movedown', $_GET['option_id']))
-					{
-						Display :: display_confirmation_message(get_lang('FieldOptionMovedDown'));
-					}
-					else
-					{
-						Display :: display_error_message(get_lang('CannotMoveFieldOption'));
-					}
-				}
-				break;
-		}
-	}
+if (isset($_GET['action'])) {
+    $check = Security::check_token('get');
+    if ($check) {
+        switch ($_GET['action']) {
+            case 'moveup' :
+                if (api_is_platform_admin() && !empty($_GET['option_id'])) {
+                    if (move_user_field_option('moveup', $_GET['option_id'])) {
+                        Display :: display_confirmation_message(get_lang('FieldOptionMovedUp'));
+                    } else {
+                        Display :: display_error_message(get_lang('CannotMoveFieldOption'));
+                    }
+                }
+                break;
+            case 'movedown' :
+                if (api_is_platform_admin() && !empty($_GET['option_id'])) {
+                    if (move_user_field_option('movedown', $_GET['option_id'])) {
+                        Display :: display_confirmation_message(get_lang('FieldOptionMovedDown'));
+                    } else {
+                        Display :: display_error_message(get_lang('CannotMoveFieldOption'));
+                    }
+                }
+                break;
+        }
+    }
 }
 
 // getting all the information of the field
 $field_info = UserManager::get_extra_field_information($_GET['field_id']);
-echo '<strong>'.$field_info['3'].'</strong><br />';
+echo Display::page_header($field_info['3']);
 
 // the total number of options (used in the actions_filter function but declared here for performance reasons)
 $number_of_options = get_number_of_options();
@@ -83,7 +66,7 @@ $number_of_options = get_number_of_options();
 // displaying the sortable table
 $parameters['sec_token'] = Security::get_token();
 $parameters['field_id'] = Security::remove_XSS($_GET['field_id']);
-$table = new SortableTable('options', 'get_number_of_options', 'get_options_data',2);
+$table = new SortableTable('options', 'get_number_of_options', 'get_options_data', 2);
 $table->set_additional_parameters($parameters);
 $table->set_header(0, get_lang('DisplayOrder'), false);
 $table->set_header(1, get_lang('OptionText'), false);
@@ -94,59 +77,50 @@ $table->display();
 // display footer
 Display::display_footer();
 
+function get_options_data($from, $number_of_items, $column, $direction) {
+    // Database table definition
+    $table_userfields_options = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
 
-function get_options_data($from, $number_of_items, $column, $direction)
-{
-	// Database table definition
-	$table_userfields_options 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
-
-	// The sql statement
-	$sql = "SELECT
+    // The sql statement
+    $sql = "SELECT
 				option_order 		AS col0,
 				option_display_text	AS col1,
 				id 					AS col2
-			FROM $table_userfields_options WHERE field_id='".Database::escape_string($_GET['field_id'])."' ORDER BY option_order ASC";
-	$sql .= " LIMIT $from,$number_of_items";
-	$res = Database::query($sql);
-	$return = array ();
-	while ($option = Database::fetch_row($res))
-	{
-		$return[] = $option;
-	}
-	return $return;
+			FROM $table_userfields_options WHERE field_id='" . Database::escape_string($_GET['field_id']) . "' ORDER BY option_order ASC";
+    $sql .= " LIMIT $from,$number_of_items";
+    $res = Database::query($sql);
+    $return = array();
+    while ($option = Database::fetch_row($res)) {
+        $return[] = $option;
+    }
+    return $return;
 }
 
-function get_number_of_options($from=null, $number_of_items=null, $column=null, $direction=null)
-{
-	// Database table definition
-	$table_userfields_options 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
+function get_number_of_options($from = null, $number_of_items = null, $column = null, $direction = null) {
+    // Database table definition
+    $table_userfields_options = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
 
-	// The sql statement
-	$sql = "SELECT count(id) as total FROM $table_userfields_options WHERE field_id='".Database::escape_string($_GET['field_id'])."' ";
-	$res = Database::query($sql);
-	$row = Database::fetch_row($res);
-	return $row[0];
+    // The sql statement
+    $sql = "SELECT count(id) as total FROM $table_userfields_options WHERE field_id='" . Database::escape_string($_GET['field_id']) . "' ";
+    $res = Database::query($sql);
+    $row = Database::fetch_row($res);
+    return $row[0];
 }
 
-function actions_filter($option_id,$url_params,$row)
-{
-	global $number_of_options;
-
-	if ($row[0]<>1)
-	{
-		$return .= '<a href="'.api_get_self().'?action=moveup&amp;option_id='.$option_id.'&amp;field_id='.Security::remove_XSS($_GET['field_id']).'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('up.gif', get_lang('Up')).'</a>';
-	}
-	else
-	{
-		$return .= Display::return_icon('blank.gif','',array('width'=>'21px'));
-	}
-
-	// the down icon only has to appear when the row can be moved down (all but the last row)
-	if ($row[0]<>$number_of_options)
-	{
-		$return .= '<a href="'.api_get_self().'?action=movedown&amp;option_id='.$option_id.'&amp;field_id='.Security::remove_XSS($_GET['field_id']).'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('down.gif', get_lang('Down')).'</a>';
-	}
-	return $return;
+function actions_filter($option_id, $url_params, $row) {
+    global $number_of_options;
+
+    if ($row[0] <> 1) {
+        $return .= '<a href="' . api_get_self() . '?action=moveup&amp;option_id=' . $option_id . '&amp;field_id=' . Security::remove_XSS($_GET['field_id']) . '&amp;sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('up.gif', get_lang('Up')) . '</a>';
+    } else {
+        $return .= Display::return_icon('blank.gif', '', array('width' => '21px'));
+    }
+
+    // the down icon only has to appear when the row can be moved down (all but the last row)
+    if ($row[0] <> $number_of_options) {
+        $return .= '<a href="' . api_get_self() . '?action=movedown&amp;option_id=' . $option_id . '&amp;field_id=' . Security::remove_XSS($_GET['field_id']) . '&amp;sec_token=' . $_SESSION['sec_token'] . '">' . Display::return_icon('down.gif', get_lang('Down')) . '</a>';
+    }
+    return $return;
 }
 
 /**
@@ -159,53 +133,43 @@ function actions_filter($option_id,$url_params,$row)
  * @version July 2008
  * @since Dokeos 1.8.6
  */
-function move_user_field_option($direction,$option_id)
-{
-	// Database table definition
-	$table_userfields_options 	= Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
-
-	// check the parameters
-	if (!in_array($direction,array('moveup','movedown')) OR !is_numeric($option_id))
-	{
-		return false;
-	}
-
-	// determine the SQL sort direction
-	if ($direction == 'moveup')
-	{
-		$sortdirection = 'DESC';
-	}
-	else
-	{
-		$sortdirection = 'ASC';
-	}
-
-	$found = false;
-
-	$sql = "SELECT id, option_order FROM $table_userfields_options  WHERE field_id='".Database::escape_string($_GET['field_id'])."' ORDER BY option_order $sortdirection";
-	$result = Database::query($sql);
-	while($row = Database::fetch_array($result))
-	{
-		if ($found)
-		{
-			$next_id = $row['id'];
-			$next_order = $row['option_order'];
-			break;
-		}
-
-		if ($option_id == $row['id'])
-		{
-			$this_id = $row['id'];
-			$this_order = $row['option_order'];
-			$found = true;
-		}
-	}
-
-	$sql1 = "UPDATE ".$table_userfields_options." SET option_order = '".Database::escape_string($next_order)."' WHERE id =  '".Database::escape_string($this_id)."'";
-	$sql2 = "UPDATE ".$table_userfields_options." SET option_order = '".Database::escape_string($this_order)."' WHERE id =  '".Database::escape_string($next_id)."'";
-	Database::query($sql1);
-	Database::query($sql2);
-
-	return true;
-}
-?>
+function move_user_field_option($direction, $option_id) {
+    // Database table definition
+    $table_userfields_options = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS);
+
+    // check the parameters
+    if (!in_array($direction, array('moveup', 'movedown')) OR !is_numeric($option_id)) {
+        return false;
+    }
+
+    // determine the SQL sort direction
+    if ($direction == 'moveup') {
+        $sortdirection = 'DESC';
+    } else {
+        $sortdirection = 'ASC';
+    }
+
+    $found = false;
+
+    $sql = "SELECT id, option_order FROM $table_userfields_options  WHERE field_id='" . Database::escape_string($_GET['field_id']) . "' ORDER BY option_order $sortdirection";
+    $result = Database::query($sql);
+    while ($row = Database::fetch_array($result)) {
+        if ($found) {
+            $next_id = $row['id'];
+            $next_order = $row['option_order'];
+            break;
+        }
+
+        if ($option_id == $row['id']) {
+            $this_id = $row['id'];
+            $this_order = $row['option_order'];
+            $found = true;
+        }
+    }
+
+    $sql1 = "UPDATE " . $table_userfields_options . " SET option_order = '" . Database::escape_string($next_order) . "' WHERE id =  '" . Database::escape_string($this_id) . "'";
+    $sql2 = "UPDATE " . $table_userfields_options . " SET option_order = '" . Database::escape_string($this_order) . "' WHERE id =  '" . Database::escape_string($next_id) . "'";
+    Database::query($sql1);
+    Database::query($sql2);
+    return true;
+}

+ 2 - 6
main/admin/user_import.php

@@ -10,14 +10,10 @@
  * Validate the imported data.
  */
 
-$language_file = array ('admin', 'registration');
+$language_file = array('admin', 'registration');
 
 $cidReset = true;
-require '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'classmanager.lib.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
+require_once '../inc/global.inc.php';
 
 // Set this option to true to enforce strict purification for usenames.
 $purification_option_for_usernames = false;

+ 14 - 7
main/admin/user_information.php

@@ -97,7 +97,11 @@ if (count($sessions) > 0) {
             $row = array ();
             $row[] = $my_course['code'];
             $row[] = $course_info['title'];
-            $row[] = $my_course['status'] == STUDENT ? get_lang('Student') : get_lang('Teacher');
+            //$row[] = $my_course['status'] == STUDENT ? get_lang('Student') : get_lang('Teacher');
+            
+            $roles = api_detect_user_roles($user['user_id'], $my_course['code'], $id_session);
+            $row[] = api_get_roles_to_string($roles);
+        
             
             $tools = '<a href="course_information.php?code='.$course_info['code'].'&id_session='.$id_session.'">'.Display::return_icon('synthese_view.gif', get_lang('Overview')).'</a>'.
                     '<a href="'.api_get_path(WEB_COURSE_PATH).$course_info['path'].'?id_session='.$id_session.'">'.Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>';
@@ -112,7 +116,7 @@ if (count($sessions) > 0) {
         Display :: display_sortable_table($header, $data, array (), array(), array ('user_id' => intval($_GET['user_id'])));
     }
 } else {
-    echo '<p>'.get_lang('NoSessionsForThisUser').'</p>';
+    Display::display_warning_message(get_lang('NoSessionsForThisUser'));
 }
 
 
@@ -129,12 +133,15 @@ if (Database::num_rows($res) > 0) {
     $header[] = array (get_lang('Title'), true);
     $header[] = array (get_lang('Status'), true);
     $header[] = array ('', false);
-    $data = array ();
+    $data = array();
     while ($course = Database::fetch_object($res)) {
         $row = array ();
         $row[] = $course->code;
         $row[] = $course->title;
-        $row[] = $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher');
+        
+        //$row[] = $course->status == STUDENT ? get_lang('Student') : get_lang('Teacher');
+        $roles = api_detect_user_roles($user['user_id'], $course->code);
+        $row[] = api_get_roles_to_string($roles);
         $tools = '<a href="course_information.php?code='.$course->code.'">'.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>';
@@ -148,7 +155,7 @@ if (Database::num_rows($res) > 0) {
     echo Display::page_subheader(get_lang('Courses'));
     Display :: display_sortable_table($header, $data, array (), array (), array ('user_id' => intval($_GET['user_id'])));    
 } else {
-    echo '<p>'.get_lang('NoCoursesForThisUser').'</p>';
+    Display::display_warning_message(get_lang('NoCoursesForThisUser'));
 }
 
 /**
@@ -174,8 +181,8 @@ if (Database::num_rows($res) > 0) {
     echo '<blockquote>';
     Display :: display_sortable_table($header, $data, array (), array (), array ('user_id' => intval($_GET['user_id'])));
     echo '</blockquote>';
-} else {
-    echo '<p>'.get_lang('NoClassesForThisUser').'</p>';
+} else {    
+    Display::display_warning_message(get_lang('NoClassesForThisUser'));
 }
 
 /**

+ 1 - 1
main/admin/user_move_stats.php

@@ -105,7 +105,7 @@ if (isset($_REQUEST['load_ajax'])) {
                 if (empty($result) || !in_array($user_id, array_keys($result))) {
                     if ($debug) echo 'User added to the session'; 
                     //Registering user to the new session
-                    SessionManager::suscribe_users_to_session($new_session_id,array($user_id),false);                    
+                    SessionManager::suscribe_users_to_session($new_session_id, array($user_id), false);                    
                 }            
                            
                 //Begin with the import process

+ 0 - 1
main/admin/usergroup_export.php

@@ -15,7 +15,6 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
 
 $tool_name = get_lang('Export');

+ 2 - 4
main/admin/usergroup_import.php

@@ -55,10 +55,8 @@ $language_file = array ('admin', 'registration');
 // Resetting the course id.
 $cidReset = true;
 
-// Including some necessary dokeos files.
-include '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
+// Including some necessary dokeos files
+require_once '../inc/global.inc.php';
 
 // Setting the section (for the tabs).
 $this_section = SECTION_PLATFORM_ADMIN;

+ 0 - 3
main/admin/usergroup_user_import.php

@@ -166,9 +166,6 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
 
-require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
-
 $tool_name = get_lang('AddUsersToAClass').' CSV';
 
 $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));

+ 1 - 1
main/auth/inscription.php

@@ -155,7 +155,7 @@ if ($user_already_registered_show_terms == false) {
     }
     // EXTRA FIELDS
     $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
-    UserManager::set_extra_fields_in_form($form, $extra_data, 'registration');
+    ExtraField::set_extra_fields_in_form($form, $extra_data, 'registration', false, null, 'user');
 }
 
 if (isset($_SESSION['user_language_choice']) && $_SESSION['user_language_choice'] != '') {

+ 4 - 4
main/auth/profile.php

@@ -280,7 +280,7 @@ if (is_platform_authentication() && is_profile_editable() && api_get_setting('pr
 
 // EXTRA FIELDS
 $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
-$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'profile', false, api_get_user_id());
+$return_params = ExtraField::set_extra_fields_in_form($form, $extra_data, 'profile', false, api_get_user_id(), 'user');
 $jquery_ready_content = $return_params['jquery_ready_content'];
 
 // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
@@ -612,7 +612,7 @@ if ($form->validate()) {
 
 	// User tag process
 	//1. Deleting all user tags
-	$list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(UserManager::USER_FIELD_TYPE_TAG);
+	$list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(ExtraField::FIELD_TYPE_TAG);
     
 	if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag)>0) {
 		foreach ($list_extra_field_type_tag as $id) {
@@ -622,11 +622,11 @@ if ($form->validate()) {
 
 	//2. Update the extra fields and user tags if available
     
-	if (is_array($extras) && count($extras)> 0) {        
+	if (is_array($extras) && count($extras)> 0) {
 		foreach ($extras as $key => $value) {
 			//3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function
 			UserManager::update_extra_field_value(api_get_user_id(), $key, $value);
-		}        
+		}
 	}
     
     // re-init the system to take new settings into account

+ 17 - 15
main/auth/sso/sso.class.php

@@ -53,6 +53,17 @@ class sso {
         header('Location: '.$this->master_url.'&sso_referer='.urlencode($this->referer).'&sso_target='.urlencode($this->target));
         exit;
     }
+    
+    function redirect_to($sso, $user_id, $logged_in) {           
+        if (isset($sso['target']) && !empty($sso['target'])) {
+            header('Location: '. $sso['target']);    
+        } else {
+            //Use this handy function to deal with platform settings
+            Redirect::session_request_uri($logged_in, $user_id);                                            
+        }                                            
+        exit;
+    }
+    
     /**
      * Validates the received active connection data with the database
      * @return	bool	Return the loginFailed variable value to local.inc.php
@@ -121,13 +132,10 @@ class sso {
                                     if (is_array($my_url_list) && count($my_url_list)>0 ) {
                                         if (in_array($current_access_url_id, $my_url_list)) {
                                             // the user has permission to enter at this site
-                                            $_user['user_id'] = $uData['user_id'];
+                                            $_user['user_id'] = $uData['user_id'];                                            
                                             Session::write('_user',$_user);
-                                            event_login();
-                                            // Redirect to homepage
-                                            $sso_target = isset($sso['target']) ? $sso['target'] : api_get_path(WEB_PATH) .'.index.php';
-                                            header('Location: '. $sso_target);
-                                            exit;
+                                            event_login();                                            
+                                            self::redirect_to($sso, $_user['user_id'], true);                                        
                                         } else {
                                             // user does not have permission for this site
                                             $loginFailed = true;
@@ -152,6 +160,7 @@ class sso {
                                         $_user['user_id'] = $uData['user_id'];
                                         Session::write('_user',$_user);
                                         event_login();
+                                        self::redirect_to($sso, $_user['user_id'], true);
                                     } else {
                                         //Secondary URL admin wants to login 
                                         // so we check as a normal user
@@ -159,6 +168,7 @@ class sso {
                                             $_user['user_id'] = $uData['user_id'];
                                             Session::write('_user',$_user);
                                             event_login();
+                                            self::redirect_to($sso, $_user['user_id'], true);
                                         } else {
                                             $loginFailed = true;
                                             Session::erase('_uid');
@@ -172,15 +182,7 @@ class sso {
                                 $_user['user_id'] = $uData['user_id'];
                                 Session::write('_user',$_user);
                                 event_login();
-                                // Redirect to homepage
-                                /* Login was successfull, stay on Chamilo 
-                                $protocol = api_get_setting('sso_authentication_protocol');
-                                $master_url = api_get_setting('sso_authentication_domain');
-                                $target = $protocol.$master_url;
-                                $sso_target = isset($target) ? $target : api_get_path(WEB_PATH) .'.index.php';
-                                header('Location: '. $sso_target);
-                                exit;
-                                */
+                                self::redirect_to($sso, $_user['user_id'], true);                               
                             }
                         } else {
                             // user account expired

+ 1 - 1
main/calendar/agenda_js.php

@@ -28,7 +28,7 @@ $current_course_tool  = TOOL_CALENDAR_EVENT;
 
 $this_section = SECTION_MYAGENDA;
 
-$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui','jquery-ui-i18n'));
+$htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui-i18n'));
 $htmlHeadXtra[] = api_get_js('qtip2/jquery.qtip.min.js');
 $htmlHeadXtra[] = api_get_js('fullcalendar/fullcalendar.min.js');
 $htmlHeadXtra[] = api_get_js('fullcalendar/gcal.js');

+ 0 - 1
main/course_info/infocours.php

@@ -25,7 +25,6 @@ $this_section = SECTION_COURSES;
 $nameTools = get_lang('ModifInfo');
 
 /*	Libraries */
-require_once api_get_path(INCLUDE_PATH).'conf/course_info.conf.php';
 require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
 

+ 1 - 1
main/course_info/legal.php

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

+ 0 - 2
main/course_progress/index.php

@@ -14,13 +14,11 @@ $language_file = array ('course_description', 'userInfo', 'admin');
 
 // including files
 require_once '../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'attendance.lib.php';
 require_once api_get_path(LIBRARY_PATH).'thematic.lib.php';
 require_once api_get_path(LIBRARY_PATH).'app_view.php';
 require_once 'thematic_controller.php';
 
 require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
-require_once api_get_path(LIBRARY_PATH).'import.lib.php';
 
 // current section
 $this_section = SECTION_COURSES;

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

@@ -488,7 +488,7 @@ class CourseBuilder {
 		// Building a fictional test for collecting orphan questions.
 		$build_orphan_questions = !empty($_POST['recycle_option']); // When a course is emptied this option should be activated (true).
         
-		$sql = "SELECT questions.* FROM $table_que as questions
+		$sql = "SELECT * FROM $table_que as questions 
                 LEFT JOIN $table_rel as quizz_questions 
                     ON (questions.id = quizz_questions.question_id AND questions.c_id = $course_id AND quizz_questions.c_id = $course_id)
                 LEFT JOIN $table_qui as exercices 

+ 1 - 1
main/create_course/add_course.php

@@ -202,7 +202,7 @@ if ($form->validate()) {
     }
 
     if ($wanted_code == '') {
-        $wanted_code = generate_course_code(api_substr($title, 0, CourseManager::MAX_COURSE_LENGTH_CODE));
+        $wanted_code = CourseManager::generate_course_code(api_substr($title, 0, CourseManager::MAX_COURSE_LENGTH_CODE));
     }
     
     // Check whether the requested course code has already been occupied.

+ 0 - 9
main/css/academica/default.css

@@ -229,15 +229,6 @@ ul#navigation .student-connect a {
 	list-style-type: none;
 	margin-bottom: 5px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-}
 
 .courses a {
 	text-decoration:underline;

+ 1 - 13
main/css/baby_orange/default.css

@@ -1067,20 +1067,8 @@ div.system_announcement {
 	margin-bottom: 10px;
 	background-color:#F9F9F9;
 }
-.session_course_item {
-	margin: 0px;
-	margin-bottom:20px;
-	font-size:135%;
-}
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-     font-size:80%; 
-}
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-/*NAVIGATION MENU BAR*/
 
+/*NAVIGATION MENU BAR*/
 
 .menucaption {
 	font-size: 12px;

+ 36 - 31
main/css/base.css

@@ -53,8 +53,8 @@ header #logo {
 }
 
 .subnav {
-    font-size: 11px;
-    font-weight: bold;
+    /*font-size: 11px;
+    font-weight: bold;*/
 }
 
 .subnav .btn-navbar {
@@ -380,7 +380,7 @@ footer .container .row {
     border:1px solid #ccc;
     margin-bottom: 11px;
     height:32px;
-    padding: 2px 2px 2px 14px;
+    padding: 2px 2px 2px 8px;
     vertical-align:middle;    
 }
 
@@ -483,16 +483,11 @@ a.tag {
     margin-bottom: 5px;
     height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-    margin-bottom: 5px;
-    height:35px;
-}
-.session_course_item {
-    /* padding: 0px; */
-    margin: 0px;
-    margin-bottom:15px;
-    font-size:135%;
+
+/* Fixes course items with bootstrap 2.1.1*/
+.course_item h3{
+    margin:0px 0px 5px 0px;
+    line-height: 28px;
 }
 
 .userportal-course-item {
@@ -508,9 +503,6 @@ a.tag {
     margin-bottom: 7px;
 }
 
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-    font-size:80%;
-}
 #maincontent .courseslist li {
     margin-bottom:8px;
 }
@@ -1972,7 +1964,7 @@ div.image-social-content center.friend {
     margin-right:4px;
 }
 
-
+/*
 textarea {
     border:1px solid #CCCCCC;
     padding:5px;
@@ -1981,7 +1973,8 @@ textarea {
     border-radius:5px;
     color:#666666;
 }
-
+*/
+/*
 select {
     color:#555;
     border: 1px solid #CCC;
@@ -1992,7 +1985,7 @@ select {
     -moz-border-radius:5px;
     -webkit-border-radius:5px;
     border-radius:5px;
-}
+}*/
 
 /* Fixes the FB input*/
 input.maininput:focus {
@@ -2011,6 +2004,17 @@ input.maininput:focus {
     margin-bottom: 20px;
 }
 
+/* session.php */
+#session_course_list .big_icon {
+    padding:10px;
+    text-align:center;
+}
+
+#session_course_list .content {
+    text-align:center;
+    margin-bottom: 20px;
+}
+
 .big_icon img {
     padding:5px;
     -moz-border-radius:10px;
@@ -2060,18 +2064,7 @@ input.maininput:focus {
     padding: 18px;
 }
 
-/* Makes the course elements more readable */
-.userportal-course-item {
-
-}
-
-.session_course_item {
-    padding: 6px 0px 6px 5px ;
-}
-
 /* LP tool*/
-
-
 #lp_overview .thumbnail {
     text-align: center;
 }
@@ -2713,6 +2706,11 @@ div.admin_section h4 {
     color: green;
 }
 
+.ribbon h3 {
+    font-size: 18px;
+    line-height: 9px;
+}
+
 .exercise_save_now_button img {
     position: relative;
     top: 4px;
@@ -2894,9 +2892,11 @@ form .formw .freeze {
 .label_tag.admin_event {
     background:red;
 }
+
 .label_tag.course_event {
     background:#458B00;
 }
+
 .label_tag.group_event {
     background:#A0522D;
 }
@@ -3809,7 +3809,7 @@ a.forum_group_link {
 }
 
 #main_content .course_item {
-    padding: 5px 0px 5px 0px;
+    padding: 0px 0px 16px 0px;
 }
 
 /* actions */
@@ -4668,4 +4668,9 @@ i.size-32.icon-new-work{
 
 #filepaths input{
     margin-bottom:5px;    
+}
+
+/* Fixing z-index */
+#ui-datepicker-div {
+    z-index: 1005 !important;
 }

+ 6 - 35
main/css/blue_lagoon/default.css

@@ -7,7 +7,7 @@
 /* Redefining html styles */
 body {
 	/* hack ignored by non-IE to enable ie to support :hover on button */
-     behavior:url("/main/css/csshover3.htc");
+    behavior:url("/main/css/csshover3.htc");
 	font-family: arial, verdana, helvetica, sans-serif;
 	font-size: 12px;
 	color: #000;
@@ -20,7 +20,7 @@ body {
 #main {
 	float: left;
 	margin: 0px auto;
-	margin-top: 5x;
+	margin-top: 5px;
 	width: 96%;
 	padding: 0px 10px 10px 10px;
 	min-height: 320px;
@@ -56,7 +56,7 @@ ul#navigation li a {
     border:1px solid #AFAFAF;
     -moz-border-radius:10px 0px 0px 10px;
     -webkit-border-bottom-right-radius: 10px;
-    -webkit-border-top-right-radius: 10x;
+    -webkit-border-top-right-radius: 10px;
     -khtml-border-bottom-right-radius: 10px;
     -khtml-border-top-right-radius: 10px;
     -moz-box-shadow: 0px 4px 3px #000;
@@ -217,7 +217,7 @@ ul#navigation li a {
 	border:1px solid #AFAFAF;
 	-moz-border-radius:10px 0px 0px 10px;
 	-webkit-border-bottom-right-radius: 10px;
-	-webkit-border-top-right-radius: 10x;
+	-webkit-border-top-right-radius: 10px;
 	-khtml-border-bottom-right-radius: 10px;
 	-khtml-border-top-right-radius: 10px;
 	-moz-box-shadow: 0px 4px 3px #000;
@@ -310,49 +310,20 @@ input[type="text"]:focus, input[type="password"]:focus, textarea:focus {
 	padding-right: 5px;
 	width: auto;
 }
+
 /* user_portal course list */
 .courses {
 	list-style-type: none;
 	margin-bottom: 5px;
 	height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-     font-size:80%; 
-}
 
-/*****************************************************
- *  HEADER STYLES                                    *
- *****************************************************/
 #header {
 	width: 100%;
 	padding: 0;
 	margin: 0;
 }
-/********************************************************
- *  HEADER 1: Title, portal, organisation, course title	*
- ********************************************************/
-#header1 {
-	padding: 4px;
-	color: #8e975b;
-}
-#header1 a {
-	color: #636363;
-	text-decoration: none;
-}
-#header1 a:hover {
-	text-decoration: underline;
-}
+
 #sitename {
 	margin: 0;
 	font-weight: bold;

File diff suppressed because it is too large
+ 491 - 261
main/css/bootstrap-responsive.css


File diff suppressed because it is too large
+ 408 - 171
main/css/bootstrap.css


+ 2 - 28
main/css/cool_blue/default.css

@@ -45,7 +45,7 @@ ul#navigation li a {
     border:1px solid #AFAFAF;
     -moz-border-radius:10px 0px 0px 10px;
     -webkit-border-bottom-right-radius: 10px;
-    -webkit-border-top-right-radius: 10x;
+    -webkit-border-top-right-radius: 10px;
     -khtml-border-bottom-right-radius: 10px;
     -khtml-border-top-right-radius: 10px;
     -moz-box-shadow: 0px 4px 3px #000;
@@ -276,19 +276,6 @@ a:active {
 	margin-bottom: 5px;
 	height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-     font-size:80%; 
-}
 
 /*****************************************************
  *  HEADER STYLES                                    *
@@ -298,20 +285,7 @@ a:active {
 	padding: 0;
 	margin: 0;
 }
-/********************************************************
- *  HEADER 1: Title, portal, organisation, course title	*
- ********************************************************/
-#header1 {
-	padding: 4px;
-	color: #2ea2c5;
-}
-#header1 a {
-	color: #636363;
-	text-decoration: none;
-}
-#header1 a:hover {
-	text-decoration: underline;
-}
+
 #sitename {
 	margin: 0;
 	font-weight: bold;

+ 1 - 11
main/css/corporate/default.css

@@ -140,7 +140,7 @@ ul#navigation li a {
     border:1px solid #AFAFAF;
     -moz-border-radius:10px 0px 0px 10px;
     -webkit-border-bottom-right-radius: 10px;
-    -webkit-border-top-right-radius: 10x;
+    -webkit-border-top-right-radius: 10px;
     -khtml-border-bottom-right-radius: 10px;
     -khtml-border-top-right-radius: 10px;
     -moz-box-shadow: 0px 4px 3px #000;
@@ -277,16 +277,6 @@ ul#navigation .student-connect a {
 	padding: 5px;
 }
 
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-
 .menu {
 	float: right;
 	width: 200px;

+ 0 - 13
main/css/cosmic_campus/default.css

@@ -274,19 +274,6 @@ ul#navigation .student-connect a {
 	margin-bottom: 5px;
 	height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-     font-size:80%; 
-}
 .user_course_category {
 	background-color: #efefef;
 	border: 1px solid #666;

+ 1 - 28
main/css/delicious_bordeaux/default.css

@@ -304,20 +304,6 @@ input[type="text"]:focus, input[type="password"]:focus, textarea:focus {
 	margin-bottom: 5px;
 	height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-     font-size:80%; 
-}
-
 /*****************************************************
  *  HEADER STYLES                                    *
  *****************************************************/
@@ -326,20 +312,7 @@ input[type="text"]:focus, input[type="password"]:focus, textarea:focus {
 	padding: 0;
 	margin: 0;
 }
-/********************************************************
- *  HEADER 1: Title, portal, organisation, course title	*
- ********************************************************/
-#header1 {
-	padding: 4px;
-	color: #975b5b;
-}
-#header1 a {
-	color: #636363;
-	text-decoration: none;
-}
-#header1 a:hover {
-	text-decoration: underline;
-}
+
 #sitename {
 	margin: 0;
 	font-weight: bold;

+ 0 - 36
main/css/dokeos_blue/default.css

@@ -303,42 +303,6 @@ input[type="text"]:focus, input[type="password"]:focus, textarea:focus {
 	margin-bottom: 5px;
 	height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-     font-size:80%; 
-}
-
-/*****************************************************
- *  HEADER STYLES                                    *
- *****************************************************/
-#header {
-	width: 100%;
-	padding: 0;
-	margin: 0;
-}
-/********************************************************
- *  HEADER 1: Title, portal, organisation, course title	*
- ********************************************************/
-#header1 {
-	padding: 4px;
-	color: #8e975b;
-}
-#header1 a {
-	color: #636363;
-	text-decoration: none;
-}
-#header1 a:hover {
-	text-decoration: underline;
-}
 #sitename {
 	margin: 0;
 	font-weight: bold;

+ 1 - 41
main/css/dokeos_classic/default.css

@@ -223,7 +223,7 @@ ul#navigation li a {
 	border:1px solid #AFAFAF;
 	-moz-border-radius:10px 0px 0px 10px;
 	-webkit-border-bottom-right-radius: 10px;
-	-webkit-border-top-right-radius: 10x;
+	-webkit-border-top-right-radius: 10px;
 	-khtml-border-bottom-right-radius: 10px;
 	-khtml-border-top-right-radius: 10px;
 	-moz-box-shadow: 0px 4px 3px #000;
@@ -309,46 +309,6 @@ input[text] {
 	margin-bottom: 5px;
 	height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-.session_course_item .item_closed, .userportal-course-item-title .item_closed {
-     font-size:80%; 
-}
-
-/*****************************************************
- *  HEADER STYLES                                    *
- *****************************************************/
-#header {
-	width: 100%;
-	padding: 0;
-	margin: 0;
-}
-/********************************************************
- *  HEADER 1: Title, portal, organisation, course title	*
- ********************************************************/
-#header1 {
-	font-size: 12px;
-	padding: 4px;
-	background-color: #264269;
-	color: #fff;
-	border-bottom: 1px solid white;
-}
-#header1 a {
-	color: #fff;
-	text-decoration: none;
-}
-#header1 a:hover {
-	background-color: #264269;
-	text-decoration: underline;
-}
 #sitename {
 	margin: 0;
 	font-weight: bold;

+ 2 - 36
main/css/dokeos_classic_2D/default.css

@@ -103,7 +103,7 @@ ul#navigation li a {
 	border:1px solid #AFAFAF;
 	-moz-border-radius:10px 0px 0px 10px;
 	-webkit-border-bottom-right-radius: 10px;
-	-webkit-border-top-right-radius: 10x;
+	-webkit-border-top-right-radius: 10px;
 	-khtml-border-bottom-right-radius: 10px;
 	-khtml-border-top-right-radius: 10px;
 	-moz-box-shadow: 0px 4px 3px #000;
@@ -162,7 +162,7 @@ ul#navigation li a {
     border:1px solid #AFAFAF;
     -moz-border-radius:10px 0px 0px 10px;
     -webkit-border-bottom-right-radius: 10px;
-    -webkit-border-top-right-radius: 10x;
+    -webkit-border-top-right-radius: 10px;
     -khtml-border-bottom-right-radius: 10px;
     -khtml-border-top-right-radius: 10px;
     -moz-box-shadow: 0px 4px 3px #000;
@@ -298,47 +298,13 @@ ul#navigation .student-connect a {
 	margin-bottom: 5px;
 	height: 30px;
 }
-/* user_portal session list */
-.session_course_item .courses {
-	margin-bottom: 5px;
-	height:35px;
-}
-.session_course_item {
-	/* padding: 0px; */
-	margin: 0px;
-	font-size:135%;
-}
-
-/*
-	HEADER STYLES
-*/
 
 #header {
 	margin: 0;
 	padding: 0;
 	width: 100%;
 }
-/*
-------------------------------------------------------------------------------
-	HEADER 1: Title, portal, organisation, course title
-------------------------------------------------------------------------------
-*/
 
-#header1 {
-	background-color: #264269;
-	border-bottom: 1px solid white;
-	color: #fff;
-	font-size: 12px;
-	padding: 4px;
-}
-#header1 a {
-	color: #fff;
-	text-decoration: none;
-}
-#header1 a:hover {
-	background-color: #264269;
-	text-decoration: underline;
-}
 #sitename {
 	font-weight: bold;
 	margin: 0;

+ 34 - 5
main/document/create_audio.php

@@ -22,7 +22,6 @@ $_SESSION['whereami'] = 'document/createaudio';
 $this_section = SECTION_COURSES;
 
 require_once 'document.inc.php';
-require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
 
 $nameTools = get_lang('CreateAudio');
 
@@ -199,6 +198,7 @@ $(document).ready(function(){
 
     $options = $options_pedia = array();
     $selected_language = null;
+	$options_pedia['defaultmessage'] = get_lang('FirstSelectALanguage');//need read before platform languages
 	
     while ($row = Database::fetch_array($result_select)) {       
         if (api_get_setting('platformLanguage')==$row['english_name']) {        
@@ -238,8 +238,8 @@ $(document).ready(function(){
 	if(Security::remove_XSS($_GET['dt2a'])=='pediaphon'){
 		//lang default is a default message
 		$selected_language = "defaultmessage";
-		$options_pedia['defaultmessage'] =get_lang('FirstSelectALanguage');
-		$options['defaultmessage'] =get_lang('FirstSelectALanguage'); 
+		
+		$options['defaultmessage'] = get_lang('FirstSelectALanguage'); 
 		echo '<div>';
 		
 		$form = new FormValidator('form2', 'post', null, '', array('id' => 'form2'));
@@ -413,9 +413,25 @@ function downloadMP3_google($filepath, $dir) {
     // Replacing remaining dangerous non-letter characters.
     $clean_text = str_replace($search, $replace, $filename);
 	
+	$returntext2voice=file_get_contents("http://translate.google.com/translate_tts?tl=".$clean_lang."&q=".urlencode($clean_text)."");
+	
+	//make a temporal file for get the file size
+		$tmpfname = tempnam("/tmp", "CTF");
+		$handle = fopen($tmpfname, "w");
+		fwrite($handle, $returntext2voice);
+		fclose($handle);
+		// Check if there is enough space in the course to save the file
+		if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) {
+			unlink($tmpfname);
+			die(get_lang('UplNotEnoughSpace'));
+		}
+		//erase temporal file
+		unlink($tmpfname);
+		
+	
 	//adding the file
 		//add new file to disk
-		file_put_contents($documentPath, file_get_contents("http://translate.google.com/translate_tts?tl=".$clean_lang."&q=".urlencode($clean_text).""));
+		file_put_contents($documentPath, $returntext2voice);
 		//add document to database
 		$current_session_id = api_get_session_id();
 		$groupId=$_SESSION['_gid'];
@@ -520,7 +536,20 @@ function downloadMP3_pediaphon($filepath, $dir){
 		$search_source=preg_match($find_t2v, $previous_returntext2voice, $hits);
 		$souce_end=substr($hits[0], 0,-1);
 		$returntext2voice = file_get_contents($souce_end);
-				
+		
+		//make a temporal file for get the file size
+			$tmpfname = tempnam("/tmp", "CTF");
+			$handle = fopen($tmpfname, "w");
+			fwrite($handle, $returntext2voice);
+			fclose($handle);
+			// Check if there is enough space in the course to save the file
+			if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) {
+				unlink($tmpfname);
+				die(get_lang('UplNotEnoughSpace'));
+			}
+			//erase temporal file
+			unlink($tmpfname);
+		
 		//save file
 		file_put_contents($documentPath, $returntext2voice);
 		

+ 0 - 1
main/document/document_lite.php

@@ -20,7 +20,6 @@ $lib_path = api_get_path(LIBRARY_PATH);
 require_once $lib_path.'document.lib.php';
 require_once $lib_path.'fileUpload.lib.php';
 require_once $lib_path.'fileDisplay.lib.php';
-//require_once $lib_path.'tablesort.lib.php';moved to autoload
 
 api_protect_course_script(true);
 

+ 16 - 0
main/document/save_pixlr.php

@@ -110,6 +110,22 @@ if(strpos($current_mime, 'image')===false) {
 }
 
 
+//make a temporal file for get the file size
+$tmpfname = tempnam("/tmp", "CTF");
+$handle = fopen($tmpfname, "w");
+fwrite($handle, $contents);
+fclose($handle);
+
+// Check if there is enough space in the course to save the file
+if (!DocumentManager::enough_space(filesize($tmpfname), DocumentManager::get_course_quota())) {
+	unlink($tmpfname);
+	die(get_lang('UplNotEnoughSpace'));
+}
+
+//erase temporal file
+unlink($tmpfname);
+
+
 //path, file and title
 $paintFileName = $filename.'.'.$extension;
 $title = $title.'.'.$extension;

+ 12 - 9
main/document/showinframes.php

@@ -143,6 +143,7 @@ $frameheight = 135;
 if ($is_courseAdmin) {
     $frameheight = 165;
 }
+
 $js_glossary_in_documents = '';
 if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
     $js_glossary_in_documents = '	//	    $(document).ready(function() {
@@ -151,8 +152,6 @@ if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
                                       }, "top.mainFrame",
                                       { load: [
                                                 {type:"script", id:"_fr1", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js"},
-                                                {type:"script", id:"_fr4", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/smoothness/jquery-ui-1.8.21.custom.min.js"},
-                                                {type:"stylesheet", id:"_fr5", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/smoothness/jquery-ui-1.8.21.custom.css"}, 
                                                 {type:"script", id:"_fr2", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"},
                                                 {type:"script", id:"_fr3", src:"'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"}
                                            ]
@@ -177,7 +176,6 @@ if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
                                 //   });';
 }
 
-
 $web_odf_supported_files = DocumentManager::get_web_odf_extension_list();
 if (in_array(strtolower($pathinfo['extension']), $web_odf_supported_files)) {
     $show_web_odf  = true;    
@@ -235,6 +233,7 @@ if ($show_web_odf) {
     $execute_iframe = false;
 }
 
+
 $is_freemind_available = $pathinfo['extension']=='mm' && api_get_setting('enable_freemind') == 'true';
 if ($is_freemind_available){
     $execute_iframe = false;
@@ -298,7 +297,8 @@ if ($jplayer_supported) {
     echo '</div>';     
 }
 
-if ($is_freemind_available) { 
+
+if ($is_freemind_available) {
 	?>	
 	<script type="text/javascript" src="<?php echo api_get_path(WEB_LIBRARY_PATH) ?>swfobject/swfobject.js"></script>
 	<style type="text/css">
@@ -306,12 +306,12 @@ if ($is_freemind_available) {
 			height: 500px;
 			padding-top:10px;
 		}
-	</style>		
+	</style>
 	<div id="flashcontent" onmouseover="giveFocus();">
 		 Flash plugin or Javascript are turned off.
 		 Activate both  and reload to view the mindmap
 	</div>		
-	<script>
+	<script>        
         function giveFocus() { 
 		  document.visorFreeMind.focus();  
 		}
@@ -363,7 +363,6 @@ if ($is_freemind_available) {
 	<?php
 }
 
-
 if ($is_nanogong_available) {
 
 		//make temp audio
@@ -416,8 +415,12 @@ if ($is_nanogong_available) {
 		$_SESSION['temp_audio_nanogong']=$to_sys;      
     echo '</div>';    
 }
-
 if ($execute_iframe) {
     echo '<iframe id="mainFrame" name="mainFrame" border="0" frameborder="0" scrolling="no" style="width:100%;" height="600" src="'.$file_url_web.'&amp;rand='.mt_rand(1, 10000).'" height="500"></iframe>';
 }
-Display::display_footer();
+
+if (api_get_setting('show_glossary_in_documents') == 'isautomatic') {
+    echo '<div id="glossary_popup"></div>';
+}
+
+Display::display_footer();

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