Przeglądaj źródła

Minor - some merges from 1.9.x

Julio Montoya 10 lat temu
rodzic
commit
8e3c8be5d5
64 zmienionych plików z 823 dodań i 456 usunięć
  1. 0 1
      main/admin/access_url_add_courses_to_url.php
  2. 1 1
      main/admin/access_url_add_users_to_url.php
  3. 3 5
      main/admin/access_url_edit.php
  4. 1 1
      main/admin/access_url_edit_course_category_to_url.php
  5. 61 43
      main/admin/access_urls.php
  6. 11 3
      main/admin/add_many_session_to_category.php
  7. 2 0
      main/admin/add_sessions_to_promotion.php
  8. 1 1
      main/admin/add_sessions_to_usergroup.php
  9. 2 2
      main/admin/archive_cleanup.php
  10. 12 4
      main/admin/course_add.php
  11. 1 1
      main/admin/course_edit.php
  12. 3 2
      main/admin/course_export.php
  13. 0 1
      main/admin/course_import.php
  14. 108 11
      main/admin/course_list.php
  15. 1 1
      main/admin/course_request_accepted.php
  16. 30 16
      main/admin/course_request_edit.php
  17. 0 6
      main/admin/course_user_import.php
  18. 1 1
      main/admin/dashboard_add_courses_to_user.php
  19. 2 6
      main/admin/dashboard_add_sessions_to_user.php
  20. 0 2
      main/admin/dashboard_add_users_to_user.php
  21. 1 1
      main/admin/group_add.php
  22. 1 1
      main/admin/group_edit.php
  23. 1 1
      main/admin/group_list.php
  24. 0 1
      main/admin/inactive_user_list.php
  25. 6 25
      main/admin/languages.php
  26. 10 10
      main/admin/promotions.php
  27. 1 0
      main/admin/session_category_add.php
  28. 9 11
      main/admin/session_user_import.php
  29. 17 10
      main/admin/settings.lib.php
  30. 1 1
      main/admin/settings.php
  31. 1 1
      main/admin/skills_import.php
  32. 1 1
      main/admin/specific_fields_add.php
  33. 0 1
      main/admin/statistics/index.php
  34. 57 13
      main/admin/system_announcements.php
  35. 1 1
      main/admin/system_status.php
  36. 20 2
      main/admin/user_add.php
  37. 29 14
      main/admin/user_edit.php
  38. 1 1
      main/admin/user_export.php
  39. 8 1
      main/admin/user_import.php
  40. 3 3
      main/admin/user_information.php
  41. 1 2
      main/admin/user_move_stats.php
  42. 1 2
      main/admin/usergroup_export.php
  43. 2 6
      main/admin/usergroup_import.php
  44. 9 6
      main/admin/usergroup_user_import.php
  45. 5 3
      main/admin/usergroups.php
  46. 0 1
      main/course_info/infocours.php
  47. 1 1
      main/course_progress/index.php
  48. 1 1
      main/coursecopy/classes/Course.class.php
  49. 0 1
      main/coursecopy/classes/CourseArchiver.class.php
  50. 0 1
      main/coursecopy/classes/CourseRecycler.class.php
  51. 40 44
      main/coursecopy/classes/Document.class.php
  52. 1 1
      main/coursecopy/classes/Link.class.php
  53. 3 10
      main/coursecopy/classes/QuizQuestion.class.php
  54. 1 1
      main/coursecopy/classes/QuizQuestionOption.class.php
  55. 15 19
      main/coursecopy/classes/Resource.class.php
  56. 2 2
      main/coursecopy/copy_course.php
  57. 1 1
      main/coursecopy/import_backup.php
  58. 2 2
      main/coursecopy/recycle_course.php
  59. 1 0
      main/create_course/add_course.php
  60. 238 56
      main/cron/import_csv.php
  61. 2 2
      main/dashboard/index.php
  62. 68 72
      main/document/create_audio.php
  63. 15 13
      main/document/create_draw.php
  64. 6 2
      main/document/create_paint.php

+ 0 - 1
main/admin/access_url_add_courses_to_url.php

@@ -21,7 +21,6 @@ if (!api_get_multiple_access_url()) {
 	exit;
 }
 
-
 $form_sent = 0;
 $first_letter_course = '';
 $courses = array ();

+ 1 - 1
main/admin/access_url_add_users_to_url.php

@@ -1,6 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**	
+/**
 * This script allows platform admins to add users to urls.
 *	It displays a list of users and a list of courses;
 *	you can select multiple users and courses and then click on

+ 3 - 5
main/admin/access_url_edit.php

@@ -12,7 +12,6 @@ $cidReset = true;
 require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 
-//api_protect_admin_script();
 api_protect_global_admin_script();
 
 if (!api_get_multiple_access_url()) {
@@ -107,15 +106,14 @@ if ($form->validate()) {
 	$form->setConstants(array('sec_token' => $token));
 }
 
-
 $form->addElement('text','url', get_lang('URLIP'), array('class'=>'span6'));
 $form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
 $form->addRule('url', '', 'maxlength',254);
 
 $types = array(
-  1=>get_lang('AccessURL'),
-  2=>get_lang('SincroServer'),
-  3=>get_lang('SincroClient'),
+    1=>get_lang('AccessURL'),
+    2=>get_lang('SincroServer'),
+    3=>get_lang('SincroClient'),
 );
 $form->addElement('select', 'url_type', get_lang('Type'), $types);
 

+ 1 - 1
main/admin/access_url_edit_course_category_to_url.php

@@ -334,4 +334,4 @@ function makepost(select){
 }
 </script>
 <?php
-Display::display_footer();
+Display::display_footer();

+ 61 - 43
main/admin/access_urls.php

@@ -16,8 +16,8 @@ $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_global_admin_script();
 
 if (!api_get_multiple_access_url()) {
-    header('Location: index.php');
-    exit;
+	header('Location: index.php');
+	exit;
 }
 
 $interbreadcrumb[] = array ("url" => 'index.php', 'name' => get_lang('PlatformAdmin'));
@@ -28,68 +28,71 @@ $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();
 
+// Actions
 if (isset ($_GET['action'])) {
     if ($_GET['action'] == 'show_message') {
         Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
-    } else {
-        $check = Security::check_token('get');
-        if ($check) {
-            $url_id = Database::escape_string($_GET['url_id']);
-
-            switch ($_GET['action']) {
-                case 'delete_url' :
-                    $result = UrlManager::delete($url_id);
-                    if ($result) {
-                        Display :: display_normal_message(get_lang('URLDeleted'));
-                    } else {
-                        Display :: display_error_message(get_lang('CannotDeleteURL'));
-                    }
-                    break;
-                case 'lock' :
-                    UrlManager::set_url_status('lock',$url_id);
-                    Display :: display_normal_message(get_lang('URLInactive'));
-                    break;
-                case 'unlock';
-                    UrlManager::set_url_status('unlock',$url_id);
-                    Display :: display_normal_message(get_lang('URLActive'));
-                    break;
-                case 'register';
-                    // we are going to register the admin
-                    if(api_is_platform_admin()) {
-                        if($current_access_url_id!=-1) {
-                            $url_str = '';
-                            foreach($url_list as $my_url) {
-                                if (!in_array($my_url['id'],$my_user_url_list)){
-                                    UrlManager::add_user_to_url(api_get_user_id(),$my_url['id']);
-                                    $url_str.=$my_url['url'].' <br />';
-                                }
+    }
+
+    $check = Security::check_token('get');
+    if ($check) {
+		$url_id = Database::escape_string($_GET['url_id']);
+
+        switch ($_GET['action']) {
+            case 'delete_url':
+                $result = UrlManager::delete($url_id);
+                if ($result) {
+                    Display :: display_normal_message(get_lang('URLDeleted'));
+                } else {
+                    Display :: display_error_message(get_lang('CannotDeleteURL'));
+                }
+                break;
+            case 'lock':
+                UrlManager::set_url_status('lock', $url_id);
+                Display::display_normal_message(get_lang('URLInactive'));
+                break;
+            case 'unlock':
+                UrlManager::set_url_status('unlock', $url_id);
+                Display::display_normal_message(get_lang('URLActive'));
+                break;
+            case 'register':
+                // we are going to register the admin
+                if (api_is_platform_admin()) {
+                    if ($current_access_url_id!=-1) {
+                        $url_str = '';
+                        foreach ($url_list as $my_url) {
+                            if (!in_array($my_url['id'], $my_user_url_list)) {
+                                UrlManager::add_user_to_url(api_get_user_id(), $my_url['id']);
+                                $url_str.=$my_url['url'].' <br />';
                             }
-                            Display :: display_normal_message(get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',false);
                         }
+                        Display :: display_normal_message(get_lang('AdminUserRegisteredToThisURL').': '.$url_str.'<br />',false);
                     }
-                    break;
-            }
+                }
+                break;
         }
     }
     Security::clear_token();
 }
+
 $parameters['sec_token'] = Security::get_token();
 
 // checking if the admin is registered in all sites
+
 $url_string='';
 $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
-foreach($url_list as $my_url) {
-    if (!in_array($my_url['id'],$my_user_url_list)){
+foreach ($url_list as $my_url) {
+    if (!in_array($my_url['id'], $my_user_url_list)){
         $url_string.=$my_url['url'].' <br />';
     }
 }
 if(!empty($url_string)) {
-    Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,false);
+	Display :: display_warning_message(get_lang('AdminShouldBeRegisterInSite').'<br />'.$url_string,false);
 }
 
 // checking the current installation
 if ($current_access_url_id==-1) {
-    Display :: display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
+	Display::display_warning_message(get_lang('URLNotConfiguredPleaseChangedTo').': '.api_get_path(WEB_PATH));
 } elseif(api_is_platform_admin()) {
     $quant= UrlManager::relation_url_user_exist(api_get_user_id(),$current_access_url_id);
     if ($quant==0) {
@@ -102,6 +105,22 @@ echo '<div class="actions">';
 echo Display::url(Display::return_icon('new_link.png',  get_lang('AddUrl'), array(), ICON_SIZE_MEDIUM),          api_get_path(WEB_CODE_PATH).'admin/access_url_edit.php');
 echo Display::url(Display::return_icon('user.png',      get_lang('ManageUsers'), array(), ICON_SIZE_MEDIUM),     api_get_path(WEB_CODE_PATH).'admin/access_url_edit_users_to_url.php');
 echo Display::url(Display::return_icon('course.png',    get_lang('ManageCourses'), array(), ICON_SIZE_MEDIUM),   api_get_path(WEB_CODE_PATH).'admin/access_url_edit_courses_to_url.php');
+//echo Display::url(Display::return_icon('session.png',   get_lang('ManageSessions'), array(), ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH).'admin/access_url_edit_sessions_to_url.php');
+
+$userGroup = new Usergroup();
+if ($userGroup->getUseMultipleUrl()) {
+    echo Display::url(
+        Display::return_icon('class.png', get_lang('ManageUserGroup'), array(), ICON_SIZE_MEDIUM),
+        api_get_path(WEB_CODE_PATH).'admin/access_url_edit_usergroup_to_url.php'
+    );
+}
+
+if (isMultipleUrlSupport()) {
+    echo Display::url(
+        Display::return_icon('folder.png', get_lang('ManageCourseCategories'), array(), ICON_SIZE_MEDIUM),
+        api_get_path(WEB_CODE_PATH).'admin/access_url_edit_course_category_to_url.php'
+    );
+}
 //echo Display::url(Display::return_icon('session.png',   get_lang('ManageSessions'), array(), ICON_SIZE_MEDIUM),          api_get_path(WEB_CODE_PATH).'admin/access_url_edit_sessions_to_url.php');
 echo '</div>';
 
@@ -167,5 +186,4 @@ $table->set_header(5, get_lang('Active'));
 $table->set_header(6, get_lang('Modify'), false);
 $table->display();
 
-/*        FOOTER    */
-Display :: display_footer();
+Display :: display_footer();

+ 11 - 3
main/admin/add_many_session_to_category.php

@@ -107,7 +107,7 @@ if (isset($_GET['msg']) && $_GET['msg'] == 'ok') {
     $OkMsg = get_lang('SessionCategoryUpdate');
 }
 
-$page = isset($_GET['page']) ? $_GET['page'] : null;
+$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
 
 Display::display_header($tool_name);
 
@@ -124,10 +124,18 @@ if ((isset($_POST['CategorySessionId']) && $_POST['formSent'] == 0) || isset($_G
 $rows_session_category = SessionManager::get_all_session_category();
 if (empty($rows_session_category)) {
     Display::display_warning_message(get_lang('YouNeedToAddASessionCategoryFirst'));
+    Display::display_footer();
+    exit;
 }
 
-$sql = "SELECT id, name  FROM $tbl_session $where ORDER BY name";
-$result = Database::query($sql);
+if (api_get_multiple_access_url()) {
+    $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
+    $access_url_id = api_get_current_access_url_id();
+    $sql = "SELECT s.id, s.name  FROM $tbl_session s INNER JOIN $table_access_url_rel_session u ON s.id = u.session_id $where AND u.access_url_id = $access_url_id ORDER BY name";
+} else {
+    $sql = "SELECT id, name  FROM $tbl_session $where ORDER BY name";
+} 
+$result=Database::query($sql);
 $rows_session = Database::store_result($result);
 ?>
 <form name="formulaire" method="post"

+ 2 - 0
main/admin/add_sessions_to_promotion.php

@@ -344,3 +344,5 @@ function makepost(select) {
     return ret;
 }
 </script>
+<?php
+Display::display_footer();

+ 1 - 1
main/admin/add_sessions_to_usergroup.php

@@ -317,7 +317,7 @@ function loadUsersInSelect(select){
     else if(window.ActiveXObject) // Internet Explorer
         xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
     else  // XMLHttpRequest non supporté par le navigateur
-        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
+    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
 
     xhr_object.open("POST", "loadUsersInSelect.ajax.php");
 

+ 2 - 2
main/admin/archive_cleanup.php

@@ -37,8 +37,8 @@ if ($form->validate()) {
 	if ($result) {
         // Creating temp folders
         /** @var ChamiloLMS\Component\DataFilesystem\DataFilesystem $filesystem */
-        $filesystem = $app['chamilo.filesystem'];
-        $filesystem->createFolders($app['temp.paths']->folders);
+/*        $filesystem = $app['chamilo.filesystem'];
+        $filesystem->createFolders($app['temp.paths']->folders); */
 
 		$message = 'ArchiveDirCleanupSucceeded';
 		$type = 'confirmation';

+ 12 - 4
main/admin/course_add.php

@@ -60,11 +60,19 @@ $form->addRule('visual_code', get_lang('Max'), 'maxlength', CourseManager::MAX_C
 $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, ' id="course_teachers" class="chzn-select"  style="width:350px" multiple="multiple" ');
 $form->applyFilter('course_teachers', 'html_filter');
 
-$categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), array(), array('style' => 'width:350px', 'class'=>'chzn-select', 'id'=>'category_code'));
-$categories_select->addOption('-','');
-$form->applyFilter('category_code', 'html_filter');
 //This function fills the category_code select ...
-CourseManager::select_and_sort_categories($categories_select);
+$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
+
+$form->addElement(
+    'select_ajax',
+    'category_code',
+    get_lang('CourseFaculty'),
+    null,
+    array(
+        'url' => $url
+    //    'formatResult' => 'function(item) { return item.name + "'" +item.code; }'
+    )
+);
 
 // Course department
 $form->add_textfield('department_name', get_lang('CourseDepartment'), false, array ('size' => '60'));

+ 1 - 1
main/admin/course_edit.php

@@ -3,7 +3,7 @@
 /**
 *	@package chamilo.admin
 */
-/* Initialization section */
+
 // name of the language file that needs to be included
 $language_file = 'admin';
 $cidReset = true;

+ 3 - 2
main/admin/course_export.php

@@ -25,9 +25,10 @@ $archivePath = api_get_path(SYS_ARCHIVE_PATH);
 $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
 
 $course_list = CourseManager::get_courses_list();
+$formSent = null;
 
-if ($_POST['formSent']) {
-	$formSent	=$_POST['formSent'];
+if (isset($_POST['formSent']) && $_POST['formSent']) {
+	$formSent = $_POST['formSent'];
 	$select_type=intval($_POST['select_type']);
 	$file_type = 'csv';
 	$courses = $selected_courses = array();

+ 0 - 1
main/admin/course_import.php

@@ -138,7 +138,6 @@ function save_data($courses) {
                     CourseManager::add_user_to_course($teacher['user_id'], $course_info['code'], COURSEMANAGER);
                 }
             }
-
             $msg .= '<a href="'.api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/">
                     '.$course_info['title'].'</a> '.get_lang('Created').'<br />';
         }

+ 108 - 11
main/admin/course_list.php

@@ -16,8 +16,7 @@ $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
 
-require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
-require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/category.class.php';
+$sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
 
 /**
  * Get the number of courses which will be displayed
@@ -64,6 +63,11 @@ function get_number_of_courses()
 
 /**
  * Get course data to display
+ * @param int $from
+ * @param int $number_of_items
+ * @param int $column
+ * @param string $direction
+ * @return array
  */
 function get_course_data($from, $number_of_items, $column, $direction) {
     $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
@@ -111,7 +115,6 @@ function get_course_data($from, $number_of_items, $column, $direction) {
     $res = Database::query($sql);
     $courses = array ();
     while ($course = Database::fetch_array($res)) {
-
         // Place colour icons in front of courses.
         $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
         $course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a> '.$show_visual_code;
@@ -123,10 +126,61 @@ function get_course_data($from, $number_of_items, $column, $direction) {
     return $courses;
 }
 
+/**
+ * Get course data to display filtered by session name
+ * @param int $from
+ * @param int $number_of_items
+ * @param int $column
+ * @param string $direction
+ * @return array
+ */
+function get_course_data_by_session($from, $number_of_items, $column, $direction)
+{
+    $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
+    $session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
+    $session = Database::get_main_table(TABLE_MAIN_SESSION);
+
+    $sql = "SELECT  c.code AS col0,
+                    c.title AS col1,
+                    c.code AS col2,
+                    c.course_language AS col3,
+                    c.category_code AS col4,
+                    c.subscribe AS col5,
+                    c.unsubscribe AS col6,
+                    c.code AS col7,
+                    c.visibility AS col8,
+                    c.directory as col9,
+                    c.visual_code
+            FROM $course_table c
+            INNER JOIN $session_rel_course r ON c.code = r.course_code
+            INNER JOIN $session s ON r.id_session = s.id
+            ";
+
+    if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
+        $sessionId = intval($_GET['session_id']);
+        $sql.= " WHERE s.id = ".$sessionId;
+    }
+
+    $sql .= " ORDER BY col$column $direction ";
+    $sql .= " LIMIT $from,$number_of_items";
+    $res = Database::query($sql);
+    $courses = array ();
+    while ($course = Database::fetch_array($res)) {
+        // Place colour icons in front of courses.
+        $show_visual_code = $course['visual_code'] != $course[2] ? Display::label($course['visual_code'], 'info') : null;
+        $course[1] = get_course_visibility_icon($course[8]).'<a href="'.api_get_path(WEB_COURSE_PATH).$course[9].'/index.php">'.$course[1].'</a> '.$show_visual_code;
+        $course[5] = $course[5] == SUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
+        $course[6] = $course[6] == UNSUBSCRIBE_ALLOWED ? get_lang('Yes') : get_lang('No');
+        $course_rem = array($course[0], $course[1], $course[2], $course[3], $course[4], $course[5], $course[6], $course[7]);
+        $courses[] = $course_rem;
+    }
+    return $courses;
+}
 /**
  * Filter to display the edit-buttons
  */
-function modify_filter($code) {
+function modify_filter($code)
+{
 	$icourse = api_get_course_info($code);
         return
         '<a href="course_information.php?code='.$code.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;'.
@@ -194,9 +248,20 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
     $form->addElement('header', $tool_name);
     $form->add_textfield('keyword_code', get_lang('CourseCode'), false);
     $form->add_textfield('keyword_title', get_lang('Title'), false);
-    $categories = array();
-    $categories_select = $form->addElement('select', 'keyword_category', get_lang('CourseFaculty'), $categories);
-    CourseManager::select_and_sort_categories($categories_select);
+
+    // Category code
+    $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
+
+    $form->addElement(
+        'select_ajax',
+        'keyword_category',
+        get_lang('CourseFaculty'),
+        null,
+        array(
+            'url' => $url
+        )
+    );
+
     $el = $form->addElement('select_language', 'keyword_language', get_lang('CourseLanguage'));
     $el->addOption(get_lang('All'), '%');
     $form->addElement('radio', 'keyword_visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
@@ -211,7 +276,7 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
     $form->addElement('radio', 'keyword_unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
     $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
     $form->addElement('radio', 'keyword_unsubscribe', null, get_lang('All'), '%');
-    $form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'),'class="btn"');
+    $form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'), 'class="btn"');
     $defaults['keyword_language'] = '%';
     $defaults['keyword_visibility'] = '%';
     $defaults['keyword_subscribe'] = '%';
@@ -248,15 +313,47 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
     $form->addElement('style_submit_button', 'submit', get_lang('SearchCourse'), 'class="btn"');
     $form->addElement('static', 'search_advanced_link', null, '<a href="course_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
 
+    // Create a filter by session
+    $sessionFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-search'), false);
+    $url = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=search_session';
+    $sessionList = array();
+    if (!empty($sessionId)) {
+        $sessionList = array();
+        $sessionInfo = SessionManager::fetch($sessionId);
+        $sessionList[] = array('id' => $sessionInfo['id'], 'text' => $sessionInfo['name']);
+    }
+    $sessionFilter->addElement('select_ajax', 'session_name', get_lang('SearchCourseBySession'), null, array('url' => $url, 'defaults' => $sessionList));
+    $courseListUrl = api_get_self();
+    $actions = '
+    <script>
+    $(function() {
+        $("#session_name").on("change", function() {
+           var sessionId = $(this).val();
+           window.location = "'.$courseListUrl.'?session_id="+sessionId;
+        });
+    });
+    </script>';
+    $actions .= '<div class="pull-right">';
     $actions .= '<a href="course_add.php">'.Display::return_icon('new_course.png', get_lang('AddCourse'),'',ICON_SIZE_MEDIUM).'</a> ';
-
     if (api_get_setting('course_validation') == 'true') {
         $actions .= '<a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests'),'',ICON_SIZE_MEDIUM).'</a>';
     }
+    $actions .= '</div>';
+
+    $actions .= '<div class="pull-right">';
+    $actions .= $sessionFilter->return_form();
+    $actions .= '</div>';
+
     $actions .= $form->return_form();
 
-    // Create a sortable table with the course data
-    $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data', 2);
+    if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
+        // Create a sortable table with the course data filtered by session
+        $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data_by_session', 2);
+    } else {
+        // Create a sortable table with the course data
+        $table = new SortableTable('courses', 'get_number_of_courses', 'get_course_data', 2);
+    }
+
     $parameters=array();
 
     if (isset ($_GET['keyword'])) {

+ 1 - 1
main/admin/course_request_accepted.php

@@ -18,7 +18,7 @@ $language_file = array('admin', 'create_course');
 
 $cidReset = true;
 
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 

+ 30 - 16
main/admin/course_request_edit.php

@@ -13,7 +13,7 @@
 $language_file = array('admin', 'create_course');
 
 $cidReset = true;
-require '../inc/global.inc.php';
+//require '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 $tool_name = get_lang('CourseRequestEdit');
 
@@ -45,7 +45,7 @@ if ($course_validation_feature) {
         $form = new FormValidator('add_course', 'post', 'course_request_edit.php?id='.$id.'&caller='.$caller);
 
         // Form title.
-        $form->addElement('header', '', $tool_name);
+        $form->addElement('header', $tool_name);
 
         // Title.
         $form->addElement('text', 'title', get_lang('CourseName'), array('size' => '60', 'id' => 'title'));
@@ -53,9 +53,25 @@ if ($course_validation_feature) {
         $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
 
         // Course category.
-        $categories_select = $form->addElement('select', 'category_code', get_lang('Fac'), array());
-        $form->applyFilter('category_code', 'html_filter');
-        CourseManager::select_and_sort_categories($categories_select);
+        $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_category';
+
+        $categoryList = array();
+
+        if (!empty($course_request_info['category_code'])) {
+            $data = getCategory($course_request_info['category_code']);
+            $categoryList[] = array('id' => $data['code'], 'text' => $data['name']);
+        }
+
+        $form->addElement(
+            'select_ajax',
+            'category_code',
+            get_lang('CourseFaculty'),
+            null,
+            array(
+                'url' => $url,
+                'defaults' => $categoryList
+            )
+        );
 
         // Course code.
         $form->add_textfield('wanted_code', get_lang('Code'), false, array('size' => '$maxlength', 'maxlength' => $maxlength));
@@ -86,15 +102,15 @@ if ($course_validation_feature) {
         $form->addElement('checkbox', 'exemplary_content', get_lang('FillWithExemplaryContent'));
 
         // Submit buttons.
-        $submit_buttons[] = FormValidator::createElement('style_submit_button', 'save_button', get_lang('Save'), array('class' => 'save'));
+        $submit_buttons[] = $form->createElement('style_submit_button', 'save_button', get_lang('Save'), array('class' => 'save'));
         if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED) {
-            $submit_buttons[] = FormValidator::createElement('style_submit_button', 'accept_button', get_lang('Accept'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'icons/16/accept.png);'));
+            $submit_buttons[] = $form->createElement('style_submit_button', 'accept_button', get_lang('Accept'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'icons/16/accept.png);'));
         }
         if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && $course_request_info['status'] != COURSE_REQUEST_REJECTED) {
-            $submit_buttons[] = FormValidator::createElement('style_submit_button', 'reject_button', get_lang('Reject'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'icons/16/error.png);'));
+            $submit_buttons[] = $form->createElement('style_submit_button', 'reject_button', get_lang('Reject'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'icons/16/error.png);'));
         }
         if ($course_request_info['status'] != COURSE_REQUEST_ACCEPTED && intval($course_request_info['info']) <= 0) {
-            $submit_buttons[] = FormValidator::createElement('style_submit_button', 'ask_info_button', get_lang('AskAdditionalInfo'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'request_info.gif);'));
+            $submit_buttons[] = $form->createElement('style_submit_button', 'ask_info_button', get_lang('AskAdditionalInfo'), array('class' => 'save', 'style' => 'background-image: url('.api_get_path(WEB_IMG_PATH).'request_info.gif);'));
         }
         $form->addGroup($submit_buttons);
 
@@ -152,7 +168,8 @@ if ($course_validation_feature) {
                 $is_error_message = false;
 
                 // Update the course request.
-                $update_ok = CourseRequestManager::update_course_request($id,
+                $update_ok = CourseRequestManager::update_course_request(
+                    $id,
                     $course_request_values['wanted_code'],
                     $course_request_values['title'],
                     $course_request_values['description'],
@@ -165,7 +182,7 @@ if ($course_validation_feature) {
                 );
 
                 if ($update_ok) {
-                    $message[] = sprintf(get_lang(CourseRequestUpdated), $course_request_values['wanted_code']);
+                    $message[] = sprintf(get_lang('CourseRequestUpdated'), $course_request_values['wanted_code']);
 
                     switch ($submit_button) {
                         case 'accept_button':
@@ -197,7 +214,7 @@ if ($course_validation_feature) {
                     //$message = 'The button "'.$submit_button.'" has been pressed.';
 
                 } else {
-                    $message[] = sprintf(get_lang(CourseRequestUpdateFailed), $course_request_values['wanted_code']);
+                    $message[] = sprintf(get_lang('CourseRequestUpdateFailed'), $course_request_values['wanted_code']);
                     $is_error_message = true;
                 }
 
@@ -218,14 +235,11 @@ if ($course_validation_feature) {
             }
         }
     }
-
 } else {
-
     // Prepare an error message notifying that the course validation feature has not been enabled.
-    $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
+    $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?search_field=course_validation&submit_button=&category=search_setting';
     $message = sprintf(get_lang('PleaseActivateCourseValidationFeature'), sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation')));
     $is_error_message = true;
-
 }
 
 // Functions.

+ 0 - 6
main/admin/course_user_import.php

@@ -125,9 +125,6 @@ $language_file = array ('admin', 'registration');
 
 $cidReset = true;
 
-// Including the global Dokeos file.
-include '../inc/global.inc.php';
-
 // Setting the section (for the tabs).
 $this_section = SECTION_PLATFORM_ADMIN;
 
@@ -175,9 +172,6 @@ if ($form->validate()) {
 // Displaying the header.
 Display :: display_header($tool_name);
 
-// Displaying the tool title.
-// api_display_tool_title($tool_name);
-
 if (isset($errors) && count($errors) != 0) {
 	$error_message = '<ul>';
 	foreach ($errors as $index => $error_course) {

+ 1 - 1
main/admin/dashboard_add_courses_to_user.php

@@ -12,7 +12,7 @@ $language_file = 'admin';
 $cidReset = true;
 
 // including some necessary dokeos files
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 
 global $_configuration;
 // create an ajax object

+ 2 - 6
main/admin/dashboard_add_sessions_to_user.php

@@ -11,8 +11,6 @@ $language_file='admin';
 // resetting the course id
 $cidReset=true;
 
-// including some necessary dokeos files
-require_once '../inc/global.inc.php';
 global $_configuration;
 
 // create an ajax object
@@ -98,8 +96,7 @@ function search_sessions($needle,$type) {
 
 $xajax->processRequests();
 $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
-$htmlHeadXtra[] = '
-<script>
+$htmlHeadXtra[] = '<script>
 function valide() {
 	var options = document.getElementById("destination").options;
 	for (i = 0 ; i<options.length ; i++) {
@@ -115,7 +112,6 @@ function remove_item(origin) {
 		}
 	}
 }
--->
 </script>';
 
 $formSent=0;
@@ -147,6 +143,7 @@ echo Display::page_header(sprintf(get_lang('AssignSessionsToX'), api_get_person_
 
 $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
 $assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
+
 $without_assigned_sessions = '';
 if (count($assigned_sessions_id) > 0) {
 	$without_assigned_sessions = " AND s.id NOT IN(".implode(',',$assigned_sessions_id).")";
@@ -257,7 +254,6 @@ if(!empty($msg)) {
   </select></td>
 </tr>
 </table>
-
 </form>
 
 <?php

+ 0 - 2
main/admin/dashboard_add_users_to_user.php

@@ -6,8 +6,6 @@
 *	@package chamilo.admin
 */
 
-// name of the language file that needs to be included
-$language_file='admin';
 // resetting the course id
 $cidReset=true;
 

+ 1 - 1
main/admin/group_add.php

@@ -10,7 +10,7 @@ $language_file = array('admin', 'registration', 'userInfo');
 $cidReset = true;
 
 // Including necessary libraries.
-require '../inc/global.inc.php';
+//require '../inc/global.inc.php';
 
 // Section for the tabs
 $this_section = SECTION_PLATFORM_ADMIN;

+ 1 - 1
main/admin/group_edit.php

@@ -6,7 +6,7 @@
 // Language files that should be included
 $language_file = array('admin', 'userInfo');
 $cidReset = true;
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script();
 

+ 1 - 1
main/admin/group_list.php

@@ -9,7 +9,7 @@
 // name of the language file that needs to be included
 $language_file = array('registration', 'admin', 'userInfo');
 $cidReset = true;
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);

+ 0 - 1
main/admin/inactive_user_list.php

@@ -32,5 +32,4 @@ while($row = Database::fetch_array($result)) {
     //$last_connection_date = UserManager:: delete_inactive_student($user_id, 2, true);
 }
 
-/*  		FOOTER    */
 Display :: display_footer();

+ 6 - 25
main/admin/languages.php

@@ -121,23 +121,19 @@ $htmlHeadXtra[] = '<script>
 $tbl_admin_languages = Database :: get_main_table(TABLE_MAIN_LANGUAGE);
 $tbl_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
 
-/*
-  ==============================================================================
-  STORING THE CHANGES
-  ==============================================================================
- */
-
 // we change the availability
 if ($action == 'makeunavailable') {
     if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
         SubLanguageManager::make_unavailable_language($_GET['id']);
     }
 }
+
 if ($action == 'makeavailable') {
     if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
         SubLanguageManager::make_available_language($_GET['id']);
     }
 }
+
 if ($action == 'setplatformlanguage') {
     if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
         SubLanguageManager::set_platform_language($_GET['id']);
@@ -180,11 +176,6 @@ if (isset($_POST['Submit']) && $_POST['Submit']) {
 }
 
 
-/*
-  ==============================================================================
-  MAIN CODE
-  ==============================================================================
- */
 // setting the name of the tool
 $tool_name = get_lang('PlatformLanguages');
 
@@ -194,7 +185,7 @@ $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdm
 // including the header file (which includes the banner itself)
 Display :: display_header($tool_name);
 
-if ($action == 'make_unavailable_confirmed') {
+if (isset($_GET['action']) && $_GET['action'] == 'make_unavailable_confirmed') {
     $language_info = SubLanguageManager::get_all_information_of_language($_GET['id']);
     if ($language_info['available'] == 1) {
         SubLanguageManager::make_unavailable_language($_GET['id']);
@@ -215,16 +206,9 @@ $sql_select_lang = "SELECT * FROM $tbl_settings_current WHERE  category='Languag
 $result_select_lang = Database::query($sql_select_lang);
 $row_lang = Database::fetch_array($result_select_lang);
 
-/*
-  --------------------------------------
-  DISPLAY THE TABLE
-  --------------------------------------
- */
-
 // the table data
 $language_data = array();
 while ($row = Database::fetch_array($result_select)) {
-
     $row_td = array();
     $row_td[] = $row['id'];
     // the first column is the original name of the language OR a form containing the original name
@@ -252,7 +236,10 @@ while ($row = Database::fetch_array($result_select)) {
     }
 
     $allow_delete_sub_language = null;
+    $allow_add_term_sub_language = null;
+
     if (api_get_setting('allow_use_sub_language') == 'true') {
+
         $verified_if_is_sub_language = SubLanguageManager::check_if_language_is_sub_language($row['id']);
 
         if ($verified_if_is_sub_language === false) {
@@ -301,10 +288,4 @@ $table->set_form_actions($form_actions);
 echo '<div id="id_content_message">&nbsp;</div>';
 $table->display();
 
-/*
-  ==============================================================================
-  FOOTER
-  ==============================================================================
- */
 Display :: display_footer();
-?>

+ 10 - 10
main/admin/promotions.php

@@ -54,22 +54,22 @@ $url            = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_promotions';
 //The order is important you need to check the model.ajax.php the $column variable
 $columns        = array(get_lang('Name'),get_lang('Career'),get_lang('Description'),get_lang('Actions'));
 $column_model   = array(
-                        array('name'=>'name',           'index'=>'name',        'width'=>'180',   'align'=>'left'),
-                        array('name'=>'career',         'index'=>'career',      'width'=>'100',  'align'=>'left'),
-                        array('name'=>'description',    'index'=>'description', 'width'=>'500',  'align'=>'left','sortable'=>'false'),
-                        array('name'=>'actions',        'index'=>'actions',     'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false'),
-                       );
+    array('name'=>'name',           'index'=>'name',        'width'=>'180',   'align'=>'left'),
+    array('name'=>'career',         'index'=>'career',      'width'=>'100',  'align'=>'left'),
+    array('name'=>'description',    'index'=>'description', 'width'=>'500',  'align'=>'left','sortable'=>'false'),
+    array('name'=>'actions',        'index'=>'actions',     'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false'),
+);
 $extra_params['autowidth'] = 'true'; //use the width of the parent
 //$extra_params['editurl'] = $url; //use the width of the parent
 
 $extra_params['height'] = 'auto'; //use the width of the parent
 //With this function we can add actions to the jgrid
 $action_links = 'function action_formatter (cellvalue, options, rowObject) {
-                    return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'">'.Display::return_icon('session_to_promotion.png',get_lang('SubscribeSessionsToPromotions'),'',ICON_SIZE_SMALL).'</a>'.
-                    '&nbsp;<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(get_lang("ConfirmYourChoice"))."\'".')) return false;"  href="?sec_token='.$token.'&action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
-                    '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a> \';
-                 }';
+    return \'<a href="add_sessions_to_promotion.php?id=\'+options.rowId+\'">'.Display::return_icon('session_to_promotion.png',get_lang('SubscribeSessionsToPromotions'),'',ICON_SIZE_SMALL).'</a>'.
+    '&nbsp;<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(get_lang("ConfirmYourChoice"))."\'".')) return false;"  href="?sec_token='.$token.'&action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
+    '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;"  href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a> \';
+}';
 
 ?>
 <script>

+ 1 - 0
main/admin/session_category_add.php

@@ -222,3 +222,4 @@ function setDisable(select) {
 }
 </script>
 <?php
+Display::display_footer();

+ 9 - 11
main/admin/session_user_import.php

@@ -8,13 +8,13 @@
 $language_file = array('admin', 'registration');
 $cidReset = true;
 
-require '../inc/global.inc.php';
+//require '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script(true);
 
 $form_sent = 0;
-$error_message = '';
+$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']);
 }
@@ -32,9 +32,9 @@ $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$session_id
 
 set_time_limit(0);
 
-if ($_POST['formSent']) {    
-    if (isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) {        
-        $form_sent = $_POST['formSent'];        
+if (isset($_POST['formSent']) && $_POST['formSent']) {
+    if (isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) {
+        $form_sent = $_POST['formSent'];
         $send_mail = $_POST['sendMail'] ? 1 : 0;
         
         // CSV
@@ -48,14 +48,14 @@ if ($_POST['formSent']) {
             }
         }
         
-        if (!empty($user_list)) {            
+        if (!empty($user_list)) {
             SessionManager::suscribe_users_to_session($session_id, $user_list, null, false, $send_mail);
             foreach ($user_list as & $user_id) {
                 $user_info = api_get_user_info($user_id);
                 $user_id = $user_info['complete_name'];
             }
             $error_message  = get_lang('UsersAdded').' : '.implode(', ', $user_list);
-        }  
+        }
     } else {
         $error_message = get_lang('NoInputFile');
     }
@@ -84,7 +84,6 @@ if (!empty($error_message)) {
 $form = new FormValidator('import_sessions', 'post', api_get_self().'?id_session='.$session_id, null, array('enctype' => 'multipart/form-data'));
 $form->addElement('hidden', 'formSent', 1);
 $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
-
 $form->addElement('checkbox', 'sendMail', null, get_lang('SendMailToUsers'));
 $form->addElement('button', 'submit', get_lang('Import'));
 
@@ -100,12 +99,11 @@ $form->display();
 <blockquote>
 <pre>
 username;
-jdoe;
+admin;
+teacher;
 jmontoya;
 </pre>
 </blockquote>
-
 <?php
 
-/* FOOTER */
 Display::display_footer();

+ 17 - 10
main/admin/settings.lib.php

@@ -446,7 +446,7 @@ function upload_stylesheet($values, $picture)
 }
 
 /**
- *
+ * Store plugin regions.
  */
 function store_regions()
 {
@@ -464,6 +464,7 @@ function store_regions()
         }
     }
     $shortlist_installed = array_flip(array_flip($shortlist_installed));
+
     $plugin_list = $plugin_obj->read_plugins_from_path();
 
     foreach ($plugin_list as $plugin) {
@@ -487,16 +488,16 @@ function store_regions()
 */
 function store_plugins()
 {
-    $plugin_obj = new AppPlugin();
+    $appPlugin = new AppPlugin();
 
     // Get a list of all current 'Plugins' settings
-    $plugin_list = $plugin_obj->read_plugins_from_path();
+    $plugin_list = $appPlugin->read_plugins_from_path();
 
     $installed_plugins = array();
 
     foreach ($plugin_list as $plugin) {
         if (isset($_POST['plugin_'.$plugin])) {
-            $plugin_obj->install($plugin);
+            $appPlugin->install($plugin);
             $installed_plugins[] = $plugin;
         }
     }
@@ -506,8 +507,9 @@ function store_plugins()
     } else {
         $remove_plugins = $plugin_list;
     }
+
     foreach ($remove_plugins as $plugin) {
-        $plugin_obj->uninstall($plugin);
+        $appPlugin->uninstall($plugin);
     }
 }
 
@@ -709,9 +711,11 @@ function handle_search()
  * @version August 2008
  * @since Dokeos 1.8.6
  */
-function handle_templates()
-{
-    $action = isset($_GET['action']) ? $_GET['action'] : null;
+function handle_templates() {
+    /* Drive-by fix to avoid undefined var warnings, without repeating
+     * isset() combos all over the place. */
+    $action = isset($_GET['action']) ? $_GET['action'] : "invalid";
+
     if ($action != 'add') {
         echo '<div class="actions" style="margin-left: 1px;">';
         echo '<a href="settings.php?category=Templates&amp;action=add">'.Display::return_icon('new_template.png', get_lang('AddTemplate'),'',ICON_SIZE_MEDIUM).'</a>';
@@ -853,7 +857,8 @@ function image_filter($image) {
  */
 function add_edit_template() {
     // Initialize the object.
-    $form = new FormValidator('template', 'post', 'settings.php?category=Templates&action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
+    $id = isset($_GET['id']) ? '&id='.Security::remove_XSS($_GET['id']) : '';
+    $form = new FormValidator('template', 'post', 'settings.php?category=Templates&action='.Security::remove_XSS($_GET['action']).$id);
 
     // Settting the form elements: the header.
     if ($_GET['action'] == 'add') {
@@ -1007,6 +1012,7 @@ function delete_template($id) {
     // Display a feedback message.
     Display::display_confirmation_message(get_lang('TemplateDeleted'));
 }
+
 /**
  * Returns the list of timezone identifiers used to populate the select
  * This function is called through a call_user_func() in the generate_settings_form function.
@@ -1029,6 +1035,7 @@ function select_timezone_value() {
 function select_gradebook_number_decimals() {
     return array('0', '1', '2');
 }
+
 function select_gradebook_default_grade_model_id() {
     $grade_model = new GradeModel();
     $models = $grade_model->get_all();
@@ -1287,7 +1294,7 @@ function generate_settings_form($settings, $settings_by_access_list, $settings_t
                 }
 
                 $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark'));
-                $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
+                $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
                 $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
 
                 break;

+ 1 - 1
main/admin/settings.php

@@ -152,7 +152,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
         $mark_all = false;
         $un_mark_all = false;
 
-        if (!empty($_configuration['multiple_access_urls'])) {
+        if (api_is_multiple_url_enabled()) {
             if (isset($values['buttons_in_action_right']) && isset($values['buttons_in_action_right']['mark_all'])) {
                 $mark_all = true;
             }

+ 1 - 1
main/admin/skills_import.php

@@ -11,7 +11,7 @@
 $language_file = array ('admin', 'registration');
 
 $cidReset = true;
-require '../inc/global.inc.php';
+//require '../inc/global.inc.php';
 
 function validate_data($skills) {
     $errors = array();

+ 1 - 1
main/admin/specific_fields_add.php

@@ -11,7 +11,7 @@ $language_file[] = 'admin';
 $cidReset = true;
 
 // including necessary libraries
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 $libpath = api_get_path(LIBRARY_PATH);
 include_once $libpath.'specific_fields_manager.lib.php';
 

+ 0 - 1
main/admin/statistics/index.php

@@ -48,7 +48,6 @@ $tools[$strSocial]['report=messagesent'] = get_lang('MessagesSent');
 $tools[$strSocial]['report=messagereceived'] = get_lang('MessagesReceived');
 $tools[$strSocial]['report=friends'] = get_lang('CountFriends');
 
-
 echo '<table><tr>';
 foreach ($tools as $section => $items) {
     echo '<td style="vertical-align:top;">';

+ 57 - 13
main/admin/system_announcements.php

@@ -18,6 +18,8 @@ $cidReset = true;
 $this_section = SECTION_PLATFORM_ADMIN;
 $_SESSION['this_section']=$this_section;
 
+$action = isset($_GET['action']) ? $_GET['action'] : null;
+
 // Access restrictions
 api_protect_admin_script(true);
 
@@ -32,12 +34,12 @@ if (empty($_GET['lang'])) {
 
 $usergroup = new UserGroup();
 
-if (isset($_GET['action'])) {
+if (!empty($action)) {
     $interbreadcrumb[] = array ("url" => "system_announcements.php", "name" => get_lang('SystemAnnouncements'));
-    if ($_GET['action'] == 'add') {
+    if ($action == 'add') {
         $interbreadcrumb[] = array ("url" => '#', "name" => get_lang('AddAnnouncement'));
     }
-    if ($_GET['action'] == 'edit') {
+    if ($action == 'edit') {
         $interbreadcrumb[] = array ("url" => '#', "name" => get_lang('Edit'));
     }
 } else {
@@ -47,7 +49,7 @@ if (isset($_GET['action'])) {
 // Displaying the header.
 Display :: display_header($tool_name);
 
-if ($_GET['action'] != 'add' && $_GET['action'] != 'edit') {
+if ($action != 'add' && $action != 'edit') {
     echo '<div class="actions">';
     echo '<a href="?action=add">'.Display::return_icon('add.png', get_lang('AddAnnouncement'), array(), 32).'</a>';
     echo '</div>';
@@ -59,7 +61,6 @@ $show_announcement_list = true;
 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
 
 // Form was posted?
-$action_todo = false;
 if (isset($_POST['action'])) {
     $action_todo = true;
 }
@@ -93,6 +94,10 @@ switch($action) {
         // Set default time window: NOW -> NEXT WEEK
         $values['start'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()));
         $values['end']   = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()) + (7 * 24 * 60 * 60));
+
+        $values['range'] =
+            substr(api_get_local_time(api_get_local_time()), 0, 16).' / '.
+            substr(api_get_local_time(api_get_local_time()) + (7 * 24 * 60 * 60), 0, 16);
         $action_todo = true;
         break;
     case 'edit':
@@ -103,6 +108,11 @@ switch($action) {
         $values['content']			= $announcement->content;
         $values['start'] 			= api_get_local_time($announcement->date_start);
         $values['end'] 				= api_get_local_time($announcement->date_end);
+
+        $values['range'] =
+            substr(api_get_local_time($announcement->date_start), 0, 16).' / '.
+            substr(api_get_local_time($announcement->date_end), 0, 16);
+
         $values['visible_teacher'] 	= $announcement->visible_teacher;
         $values['visible_student'] 	= $announcement->visible_student ;
         $values['visible_guest'] 	= $announcement->visible_guest ;
@@ -136,7 +146,8 @@ if ($action_todo) {
     } else {
         $form->add_html_editor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'PortalNews', 'Width' => '100%', 'Height' => '300'));
     }
-    $form->add_timewindow('start','end',get_lang('StartTimeWindow'),get_lang('EndTimeWindow'));
+    $form->addDateRangePicker('range', get_lang('StartTimeWindow'), true, array('id' => 'date_range'));
+
     $group = array();
 
     $group[]= $form->createElement('checkbox', 'visible_teacher', null, get_lang('Teacher'));
@@ -158,16 +169,20 @@ if ($action_todo) {
         $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
         $text=get_lang('AddNews');
         $class='add';
-        $form->addElement('hidden', 'action','add');
+        $form->addElement('hidden', 'action', 'add');
 
-    } elseif (isset($_REQUEST['action']) && $_REQUEST['action']=='edit') {
+    } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
         $text=get_lang('EditNews');
         $class='save';
-        $form->addElement('hidden', 'action','edit');
+        $form->addElement('hidden', 'action', 'edit');
     }
 
-    $form->addElement('style_submit_button', 'submit', $text,'class="'.$class.'"');
+    $form->addElement('checkbox', 'send_email_test', null, get_lang('SendOnlyAnEmailToMySelfToTest'));
+
+    $form->addElement('style_submit_button', 'submit', $text, 'class="'.$class.'"');
+
     $form->setDefaults($values);
+
     if ($form->validate()) {
         $values = $form->exportValues();
         if ( !isset($values['visible_teacher'])) {
@@ -182,10 +197,26 @@ if ($action_todo) {
         if ($values['lang'] == 'all') {
             $values['lang'] = null;
         }
+
+        $sendMail = isset($values['send_mail']) ? $values['send_mail'] : null;
+
         switch ($values['action']) {
             case 'add':
-                $announcement_id = SystemAnnouncementManager::add_announcement($values['title'],$values['content'],$values['start'],$values['end'],$values['visible_teacher'],$values['visible_student'],$values['visible_guest'], $values['lang'],$values['send_mail'],  $values['add_to_calendar']);
-                if ($announcement_id !== false )  {
+                $announcement_id = SystemAnnouncementManager::add_announcement(
+                    $values['title'],
+                    $values['content'],
+                    $values['range_start'],
+                    $values['range_end'],
+                    $values['visible_teacher'],
+                    $values['visible_student'],
+                    $values['visible_guest'],
+                    $values['lang'],
+                    $sendMail,
+                    $values['add_to_calendar'],
+                    $values['send_email_test']
+                );
+
+                if ($announcement_id !== false)  {
                     SystemAnnouncementManager::announcement_for_groups($announcement_id, array($values['group']));
                     Display :: display_confirmation_message(get_lang('AnnouncementAdded'));
                 } else {
@@ -194,7 +225,20 @@ if ($action_todo) {
                 }
                 break;
             case 'edit':
-                if (SystemAnnouncementManager::update_announcement($values['id'], $values['title'], $values['content'], $values['start'], $values['end'], $values['visible_teacher'], $values['visible_student'], $values['visible_guest'], $values['lang'], $values['send_mail'])) {
+                if (SystemAnnouncementManager::update_announcement(
+                    $values['id'],
+                    $values['title'],
+                    $values['content'],
+                    $values['range_start'],
+                    $values['range_end'],
+                    $values['visible_teacher'],
+                    $values['visible_student'],
+                    $values['visible_guest'],
+                    $values['lang'],
+                    $sendMail,
+                    $values['send_email_test']
+                )
+                ) {
                     SystemAnnouncementManager::announcement_for_groups($values['id'], array($values['group']));
                     Display :: display_confirmation_message(get_lang('AnnouncementUpdated'));
                 } else {

+ 1 - 1
main/admin/system_status.php

@@ -9,7 +9,7 @@
 $language_file = array('admin', 'registration');
 $cidReset = true;
 
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 
 $this_section = SECTION_PLATFORM_ADMIN;
 // User permissions

+ 20 - 2
main/admin/user_add.php

@@ -164,9 +164,11 @@ if (isset($extAuthSource) && count($extAuthSource) > 0) {
     	$group[] = $form->createElement('static', '', '', '<br />');
     }
 }
+
 $group[] = $form->createElement('radio', 'password_auto', get_lang('Password'), get_lang('AutoGeneratePassword').'<br />', 1);
 $group[] = $form->createElement('radio', 'password_auto', 'id="radio_user_password"', null, 0);
-$group[] = $form->createElement('password', 'password', null, array('id'=> 'password', 'onkeydown' => 'javascript: password_switch_radio_button();'));
+$group[] = $form->createElement('password', 'password', null, array('id'=> 'password', 'autocomplete' => 'off', 'onkeydown' => 'javascript: password_switch_radio_button();'));
+
 $form->addGroup($group, 'password', get_lang('Password'), '');
 
 if (isset($_configuration['allow_strength_pass_checker']) && $_configuration['allow_strength_pass_checker']) {
@@ -198,6 +200,17 @@ if (isset($drh_list) && is_array($drh_list)) {
 }
 $form->addElement('html', '</div>');
 
+if (api_is_platform_admin()) {
+    // Platform admin
+    $group = array();
+    $group[] = $form->createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('Yes'), 1);
+    $group[] = $form->createElement('radio', 'platform_admin', 'id="id_platform_admin"', get_lang('No'), 0);
+    //$display = ($_POST['status'] == STUDENT || !isset($_POST['status'])) ? 'none' : 'block';
+    $form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.';">');
+    $form->addGroup($group, 'admin', get_lang('PlatformAdmin'), '&nbsp;');
+    $form->addElement('html', '</div>');
+}
+
 $form->addElement('select_language', 'language', get_lang('Language'), null);
 
 // Send email
@@ -234,7 +247,8 @@ $(document).ready(function(){
 </script>';
 
 // Set default values
-$defaults['mail']['send_mail'] = 0;
+$defaults['admin']['platform_admin'] = 0;
+$defaults['mail']['send_mail'] = 1;
 $defaults['password']['password_auto'] = 1;
 $defaults['active'] = 1;
 $defaults['expiration_date'] = array();
@@ -267,6 +281,7 @@ if( $form->validate()) {
 		$status         = intval($user['status']);
 		$language       = $user['language'];
 		$picture        = $_FILES['picture'];
+		$platform_admin = intval($user['admin']['platform_admin']);
 		$send_mail      = intval($user['mail']['send_mail']);
 		$hr_dept_id     = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : 0;
 
@@ -353,6 +368,9 @@ if( $form->validate()) {
 					UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
 				}
 			}
+			if ($platform_admin) {
+                UserManager::add_user_as_admin($user_id);
+			}
 			$message = get_lang('UserAdded');
 		}
 		if (isset($user['submit_plus'])) {

+ 29 - 14
main/admin/user_edit.php

@@ -66,6 +66,7 @@ if (Database::num_rows($res) != 1) {
 }
 
 $user_data = Database::fetch_array($res, 'ASSOC');
+$user_data['platform_admin'] = is_null($user_data['is_admin']) ? 0 : 1;
 $user_data['send_mail'] = 0;
 $user_data['old_password'] = $user_data['password'];
 //Convert the registration date of the user
@@ -235,6 +236,19 @@ foreach($drh_list as $drh) {
 $form->addElement('html', '</div>');
 */
 
+//Language
+if (api_is_platform_admin()) {
+	$group = array();
+	$group[] =$form->createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
+	$group[] =$form->createElement('radio', 'platform_admin', null, get_lang('No'), 0);
+
+	$user_data['status'] == 1 ? $display = 'block':$display = 'none';
+
+	$form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.'">');
+	$form->addGroup($group, 'admin', get_lang('PlatformAdmin'), null, false);
+	$form->addElement('html', '</div>');
+}
+
 //Language
 $form->addElement('select_language', 'language', get_lang('Language'));
 
@@ -245,23 +259,24 @@ $group[] = $form->createElement('radio', 'send_mail', null, get_lang('No'), 0);
 $form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;', false);
 
 // Registration Date
-$form->addElement('static', 'registration_date', get_lang('RegistrationDate'), $user_data['registration_date']);
+$creatorInfo = api_get_user_info($user_data['creator_id']);
+$date = sprintf(get_lang('CreatedByXYOnZ'), 'user_information.php?user_id='.$user_data['creator_id'], $creatorInfo['username'], $user_data['registration_date']);
+$form->addElement('html', '<div class="control-group"><label class="control-label">'.get_lang('RegistrationDate').'</label><div class="controls">'.$date.'</div></div>');
 
 // Expiration Date
-$form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
-$group = array();
-$group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('On'), 1);
-$group[] = $form->createElement(
-    'datepicker',
-    'expiration_date',
-    null,
-    array('form_name' => $form->getAttribute('name'), 'onchange' => 'javascript: enable_expiration_date();')
-);
-$form->addGroup($group, 'max_member_group', null, '', false);
-
+if (!$user_data['platform_admin']) {
+	// Expiration Date
+	$form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
+	$group = array ();
+	$group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('On'), 1);
+	$group[] = $form->createElement('datepicker', 'expiration_date', null, array('form_name' => $form->getAttribute('name'), 'onchange' => 'javascript: enable_expiration_date();'));
+	$form->addGroup($group, 'max_member_group', null, '', false);
+
+	// Active account or inactive account
+	$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
+	$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
+}
 // Active account or inactive account
-$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
-$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
 
 // EXTRA FIELDS
 $extraField = new ExtraField('user');

+ 1 - 1
main/admin/user_export.php

@@ -11,7 +11,7 @@ $language_file = 'admin';
 
 $cidReset = true;
 
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();

+ 8 - 1
main/admin/user_import.php

@@ -13,7 +13,7 @@
 $language_file = array('admin', 'registration');
 
 $cidReset = true;
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 
 // Set this option to true to enforce strict purification for usenames.
 $purification_option_for_usernames = false;
@@ -183,6 +183,8 @@ function parse_csv_data($file) {
 }
 /**
  * XML-parser: handle start of element
+ * @param   string  $parser Deprecated?
+ * @param   string  $data The data to be parsed
  */
 function element_start($parser, $data) {
 	$data = api_utf8_decode($data);
@@ -199,6 +201,8 @@ function element_start($parser, $data) {
 
 /**
  * XML-parser: handle end of element
+ * @param   string  $parser Deprecated?
+ * @param   string  $data   The data to be parsed
  */
 function element_end($parser, $data) {
 	$data = api_utf8_decode($data);
@@ -223,6 +227,9 @@ function element_end($parser, $data) {
 
 /**
  * XML-parser: handle character data
+ * @param   string  $parser Parser (deprecated?)
+ * @param   string  $data The data to be parsed
+ * @return  void
  */
 function character_data($parser, $data) {
 	$data = trim(api_utf8_decode($data));

+ 3 - 3
main/admin/user_information.php

@@ -8,7 +8,7 @@
 // name of the language file that needs to be included
 $language_file = 'admin';
 $cidReset = true;
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 $this_section=SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
@@ -24,8 +24,8 @@ Display::display_header($tool_name);
 
 $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
-if ( isset($_GET['action']) ) {
-    switch($_GET['action']) {
+if (isset($_GET['action'])) {
+    switch ($_GET['action']) {
         case 'unsubscribe':
             if ( CourseManager::get_user_in_course_status($_GET['user_id'],$_GET['courseId']) == STUDENT) {
                 CourseManager::unsubscribe_user($_GET['user_id'], $_GET['courseId']);

+ 1 - 2
main/admin/user_move_stats.php

@@ -14,6 +14,7 @@ require_once '../inc/global.inc.php';
 $this_section=SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();
+//require_once '../newscorm/learnpathList.class.php';
 
 $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
 $debug = 0;
@@ -188,7 +189,6 @@ if (isset($_REQUEST['load_ajax'])) {
                     }
                 }
 
-
                 //2.track_e_attempt, track_e_attempt_recording, track_e_downloads
                 //Nothing to do because there are not relationship with a session
 
@@ -236,7 +236,6 @@ if (isset($_REQUEST['load_ajax'])) {
                 }
 
                 //5. lp_item_view
-
                //CHECK ORIGIN
 
                 $sql = "SELECT * FROM $TBL_LP_VIEW WHERE user_id = $user_id AND session_id = $origin_session_id AND c_id = $course_id ";

+ 1 - 2
main/admin/usergroup_export.php

@@ -8,10 +8,9 @@
  */
 // name of the language file that needs to be included
 $language_file = 'admin';
-
 $cidReset = true;
 
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 $this_section = SECTION_PLATFORM_ADMIN;
 
 api_protect_admin_script();

+ 2 - 6
main/admin/usergroup_import.php

@@ -55,9 +55,6 @@ $language_file = array ('admin', 'registration');
 // Resetting the course id.
 $cidReset = true;
 
-// Including some necessary dokeos files
-require_once '../inc/global.inc.php';
-
 // Setting the section (for the tabs).
 $this_section = SECTION_PLATFORM_ADMIN;
 
@@ -65,9 +62,8 @@ $this_section = SECTION_PLATFORM_ADMIN;
 api_protect_admin_script();
 
 // setting breadcrumbs
-$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
-$interbreadcrumb[] = array ('url' => 'usergroups.php', 'name' => get_lang('Classes'));
-
+$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array('url' => 'usergroups.php', 'name' => get_lang('Classes'));
 // Database Table Definitions
 
 // Setting the name of the tool.

+ 9 - 6
main/admin/usergroup_user_import.php

@@ -6,7 +6,7 @@
 /**
  * Code
  * This tool allows platform admins to update class-user relations by uploading
- * a CSVfile
+ * a CSV file
  */
 
 /**
@@ -67,7 +67,7 @@ function validate_data($user_classes) {
 /**
  * Saves imported data.
  */
-function save_data($users_classes) {
+function save_data($users_classes, $deleteUsersNotInList = false) {
 
     global $purification_option_for_usernames;
 
@@ -81,7 +81,8 @@ function save_data($users_classes) {
     if (!empty($users_classes)) {
 
         foreach ($users_classes as $user_class) {
-            $sql1 = "SELECT user_id FROM $user_table WHERE username = '" . Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames)) . "'";
+            $sql1 = "SELECT user_id FROM $user_table
+                     WHERE username = '".Database::escape_string(UserManager::purify_username($user_class['UserName'], $purification_option_for_usernames))."'";
             $res1 = Database::query($sql1);
             $obj1 = Database::fetch_object($res1);
 
@@ -103,7 +104,7 @@ function save_data($users_classes) {
             $user_list = $user_data['user_list'];
             $class_name = $user_data['class_name'];
             $user_list_name = $user_data['user_list_name'];
-            $usergroup->subscribe_users_to_usergroup($class_id, $user_list, false);
+            $usergroup->subscribe_users_to_usergroup($class_id, $user_list, $deleteUsersNotInList);
             $message .= Display::return_message(get_lang('Class') . ': ' . $class_name . '<br />', 'normal', false);
             $message .= Display::return_message(get_lang('Users') . ': ' . implode(', ', $user_list_name));
         }
@@ -143,14 +144,16 @@ $form = new FormValidator('class_user_import');
 $form->addElement('header', $tool_name);
 $form->addElement('file', 'import_file', get_lang('ImportCSVFileLocation'));
 //$form->addElement('checkbox', 'subscribe', get_lang('Action'), get_lang('SubscribeUserIfNotAllreadySubscribed'));
-//$form->addElement('checkbox', 'unsubscribe', '', get_lang('UnsubscribeUserIfSubscriptionIsNotInFile'));
+$form->addElement('checkbox', 'unsubscribe', '', get_lang('UnsubscribeUserIfSubscriptionIsNotInFile'));
 $form->addElement('style_submit_button', 'submit', get_lang('Import'), 'class="save"');
 
+$errors = array();
 if ($form->validate()) {
     $users_classes = parse_csv_data($_FILES['import_file']['tmp_name']);
     $errors = validate_data($users_classes);
     if (count($errors) == 0) {
-        $return = save_data($users_classes);
+        $deleteUsersNotInList = isset($_REQUEST['unsubscribe']) && !empty($_REQUEST['unsubscribe']) ? true : false;
+        $return = save_data($users_classes, $deleteUsersNotInList);
     }
 }
 

+ 5 - 3
main/admin/usergroups.php

@@ -61,6 +61,7 @@ $column_model   = array(
     array('name'=>'group_type',    	'index'=>'group_type', 	    'width'=>'15',  'align'=>'left'),
     array('name'=>'actions',        'index'=>'actions',     'width'=>'20',  'align'=>'left','sortable'=>'false','formatter'=>'action_formatter'),
 );
+
 //Autowidth
 $extra_params['autowidth'] = 'true';
 //height auto
@@ -138,6 +139,9 @@ elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET[
     $form->setDefaults($defaults);
 
     // The validation or display
+    $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
+
+    // The validation or display.
     if ($form->validate()) {
         $check = Security::check_token('post');
         if ($check) {
@@ -158,9 +162,7 @@ elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET[
         $form->setConstants(array('sec_token' => $token));
         $form->display();
     }
-}
-// Action handling: deleting a note
-elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
+} elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
     $res = $usergroup->delete(Security::remove_XSS($_GET['id']));
     if ($res) {
         Display::display_confirmation_message(get_lang('Deleted'));

+ 0 - 1
main/course_info/infocours.php

@@ -17,7 +17,6 @@ use \ChamiloSession as Session;
 
 // Language files that need to be included
 $language_file = array('create_course', 'course_info', 'admin', 'gradebook', 'document');
-require_once '../inc/global.inc.php';
 $current_course_tool  = TOOL_COURSE_SETTING;
 $this_section = SECTION_COURSES;
 

+ 1 - 1
main/course_progress/index.php

@@ -13,7 +13,7 @@
 $language_file = array ('course_description', 'userInfo', 'admin');
 
 // including files
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'app_view.php';
 require_once 'thematic_controller.php';
 

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

@@ -348,4 +348,4 @@ class Course
             return unserialize($course);
         }
     }
-}
+}

+ 0 - 1
main/coursecopy/classes/CourseArchiver.class.php

@@ -14,7 +14,6 @@ require_once 'Course.class.php';
  */
 class CourseArchiver
 {
-
     /**
      * Delete old temp-dirs
      */

+ 0 - 1
main/coursecopy/classes/CourseRecycler.class.php

@@ -402,7 +402,6 @@ class CourseRecycler
             // Identifying again and deletion of the orphan questions, if it was desired.
             if ($delete_orphan_questions) {
 
-
                 //@todo fix query in order to use iid
                 $sql = " (
                     SELECT q.iid FROM $table_qui_que q

+ 40 - 44
main/coursecopy/classes/Document.class.php

@@ -1,58 +1,54 @@
 <?php
 /* For licensing terms, see /license.txt */
-/**
- * Document class file
- * @package chamilo.backup
- */
-/**
- * Code
- */
+
 require_once 'Resource.class.php';
 
 define('DOCUMENT','file');
 define('FOLDER','folder');
 
 /**
- * An document
+ * Class Document
  * @author Bart Mollet <bart.mollet@hogent.be>
  * @package chamilo.backup
  */
 class Document extends Resource
 {
-	public $path;
-	public $comment;
-	public $file_type;
-	public $size;
-	public $title;
-	/**
-	 * Create a new Document
-	 * @param int $id
-	 * @param string $path
-	 * @param string $comment
-	 * @param string $title
-	 * @param string $file_type (DOCUMENT or FOLDER);
-	 * @param int $size
-	 */
-	function Document($id,$path,$comment,$title,$file_type,$size)
-	{
-		parent::Resource($id, RESOURCE_DOCUMENT);
-		$this->path = 'document'.$path;
-		$this->comment = $comment;
-		$this->title = $title;
-		$this->file_type = $file_type;
-		$this->size = $size;
-	}
-	/**
-	 * Show this document
-	 */
-	function show()
-	{
-		parent::show();
-		echo preg_replace('@^document@', '', $this->path);
-		if (!empty($this->title)) {
-			if (strpos($this->path, $this->title) === false) {
-				echo " - ".$this->title;
-			}
-		}
-	}
+    public $path;
+    public $comment;
+    public $file_type;
+    public $size;
+    public $title;
+
+    /**
+     * Create a new Document
+     * @param int $id
+     * @param string $path
+     * @param string $comment
+     * @param string $title
+     * @param string $file_type (DOCUMENT or FOLDER);
+     * @param int $size
+     */
+    public function Document($id, $path, $comment, $title, $file_type, $size)
+    {
+        parent::Resource($id, RESOURCE_DOCUMENT);
+        $this->path = 'document' . $path;
+        $this->comment = $comment;
+        $this->title = $title;
+        $this->file_type = $file_type;
+        $this->size = $size;
+    }
+
+    /**
+     * Show this document
+     */
+    public function show()
+    {
+        parent::show();
+        echo preg_replace('@^document@', '', $this->path);
+        if (!empty($this->title)) {
+            if (strpos($this->path, $this->title) === false) {
+                echo " - " . $this->title;
+            }
+        }
+    }
 }

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

@@ -63,4 +63,4 @@ class Link extends Resource
 		parent::show();
 		echo $this->title.' ('.$this->url.')';
 	}
-}
+}

+ 3 - 10
main/coursecopy/classes/QuizQuestion.class.php

@@ -1,23 +1,16 @@
 <?php
-
 /* For licensing terms, see /license.txt */
-/**
- * Exercises questions backup script
- * @package chamilo.backup
- */
-/**
- * Code
- */
+
 require_once 'Resource.class.php';
 
 /**
- * An QuizQuestion
+ * Exercises questions backup script
+ * Class QuizQuestion
  * @author Bart Mollet <bart.mollet@hogent.be>
  * @package chamilo.backup
  */
 class QuizQuestion extends Resource
 {
-
     /**
      * The question
      */

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

@@ -25,4 +25,4 @@ class QuizQuestionOption extends Resource
         parent::Resource($obj->iid, RESOURCE_QUIZQUESTION);
         $this->obj = $obj;
     }
-}
+}

+ 15 - 19
main/coursecopy/classes/Resource.class.php

@@ -1,13 +1,6 @@
 <?php
-
 /* For licensing terms, see /license.txt */
-/**
- * General resources backup script
- * @package chamilo.backup
- */
-/**
- * Definition of all possible resource-types
- */
+
 define('RESOURCE_DOCUMENT', 'document');
 define('RESOURCE_GLOSSARY', 'glossary');
 define('RESOURCE_EVENT', 'calendar_event');
@@ -19,6 +12,7 @@ define('RESOURCE_FORUM', 'forum');
 define('RESOURCE_FORUMTOPIC', 'thread');
 define('RESOURCE_FORUMPOST', 'post');
 define('RESOURCE_QUIZ', 'quiz');
+define('RESOURCE_TEST_CATEGORY', 'test_category');
 define('RESOURCE_QUIZQUESTION', 'Exercise_Question');
 define('RESOURCE_TOOL_INTRO', 'Tool introduction');
 define('RESOURCE_LINKCATEGORY', 'Link_Category');
@@ -33,6 +27,7 @@ define('RESOURCE_ATTENDANCE', 'attendance');
 define('RESOURCE_WORK', 'work');
 
 /**
+ * Class Resource
  * Representation of a resource in a Chamilo-course.
  * This is a base class of which real resource-classes (for Links,
  * Documents,...) should be derived.
@@ -43,7 +38,6 @@ define('RESOURCE_WORK', 'work');
  */
 class Resource
 {
-
     /**
      * The id from this resource in the source course
      */
@@ -88,29 +82,29 @@ class Resource
     /**
      * Add linked resource
      */
-    function add_linked_resource($type, $id)
-    {
+    function add_linked_resource($type, $id) {
         $this->linked_resources[$type][] = $id;
     }
 
     /**
      * Get linked resources
      */
-    function get_linked_resources()
-    {
+    function get_linked_resources() {
         return $this->linked_resources;
     }
 
     /**
      * Checks if this resource links to a given resource
      */
-    function links_to(& $resource)
-    {
-        if (isset($this->linked_resources[$resource->get_type()]) && is_array(
-                $this->linked_resources[$resource->get_type()]
-            )
+    function links_to(& $resource) {
+        $type = $resource->get_type();
+        if (isset($this->linked_resources[$type]) &&
+            is_array($this->linked_resources[$type])
         ) {
-            return in_array($resource->get_id(), $this->linked_resources[$resource->get_type()]);
+            return in_array(
+                $resource->get_id(),
+                $this->linked_resources[$type]
+            );
         }
         return false;
     }
@@ -169,6 +163,8 @@ class Resource
                 return TOOL_POST;
             case RESOURCE_QUIZ:
                 return TOOL_QUIZ;
+            case RESOURCE_TEST_CATEGORY:
+                return TOOL_TEST_CATEGORY;
             //case RESOURCE_QUIZQUESTION: //no corresponding global constant
             //	return TOOL_QUIZ_QUESTION;
             //case RESOURCE_TOOL_INTRO:

+ 2 - 2
main/coursecopy/copy_course.php

@@ -10,7 +10,7 @@
 $language_file = array('exercice', 'coursebackup', 'admin');
 
 // Setting the global file that gets the general configuration, the databases, the languages, ...
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 
 // Including additional libraries
 require_once 'classes/CourseBuilder.class.php';
@@ -128,4 +128,4 @@ if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (is
     }
 }
 
-Display::display_footer();
+Display::display_footer();

+ 1 - 1
main/coursecopy/import_backup.php

@@ -15,7 +15,7 @@
 $language_file = array('exercice', 'coursebackup', 'admin');
 
 // Including the global initialization file
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 $current_course_tool = TOOL_COURSE_MAINTENANCE;
 api_protect_course_script(true);
 

+ 2 - 2
main/coursecopy/recycle_course.php

@@ -79,9 +79,9 @@ if ((isset($_POST['action']) &&
 	} else {
 		Display::display_warning_message(get_lang('RecycleWarning'), false);
         $form = new FormValidator('recycle_course', 'post', api_get_self().'?'.api_get_cidreq());
-		$form->addElement('header', get_lang('SelectOptionForBackup'));		
+		$form->addElement('header', get_lang('SelectOptionForBackup'));
 		$form->addElement('radio', 'recycle_option', null, get_lang('FullRecycle'), 'full_backup');
-        $form->addElement('radio', 'recycle_option', null, get_lang('LetMeSelectItems'), 'select_items');        
+        $form->addElement('radio', 'recycle_option', null, get_lang('LetMeSelectItems'), 'select_items');
         $form->addElement('style_submit_button', 'submit', get_lang('RecycleCourse'), 'class="save"');
         $form->setDefaults(array('recycle_option' => 'select_items'));
         $form->display();

+ 1 - 0
main/create_course/add_course.php

@@ -287,3 +287,4 @@ if ($form->validate()) {
 
 $tpl->assign('message', $message);
 $tpl->assign('content', $content);
+

+ 238 - 56
main/cron/import_csv.php

@@ -1,14 +1,16 @@
 <?php
+/* For licensing terms, see /license.txt */
 
 if (PHP_SAPI !='cli') {
     die('Run this script through the command line or comment this line in the code');
 }
 
-//$_SERVER['SERVER_NAME'] = '';
-//$_SERVER['HTTP_HOST'] = '';
+if (file_exists('multiple_url_fix.php')) {
+    require 'multiple_url_fix.php';
+}
 
-require_once __DIR__.'/../inc/global.inc.php';
-require_once api_get_path(LIBRARY_PATH).'log.class.php';
+//require_once __DIR__.'/../inc/global.inc.php';
+//require_once api_get_path(LIBRARY_PATH).'log.class.php';
 
 /**
  * Class ImportCsv
@@ -44,6 +46,7 @@ class ImportCsv
 
     /**
      * @param Logger $logger
+     * @param array
      */
     public function __construct($logger, $conditions)
     {
@@ -54,7 +57,7 @@ class ImportCsv
     /**
      * @param bool $dump
      */
-    function setDumpValues($dump)
+    public function setDumpValues($dump)
     {
         $this->dumpValues = $dump;
     }
@@ -62,7 +65,7 @@ class ImportCsv
     /**
      * @return mixed
      */
-    function getDumpValues()
+    public function getDumpValues()
     {
         return $this->dumpValues;
     }
@@ -75,34 +78,47 @@ class ImportCsv
         $path = api_get_path(SYS_CODE_PATH).'cron/incoming/';
         if (!is_dir($path)) {
             echo "The folder! $path does not exits";
-            exit;
+            return 0;
         }
 
         if ($this->getDumpValues()) {
             $this->dumpDatabaseTables();
         }
 
-        echo "Starting with reading the files: ".PHP_EOL.PHP_EOL;
+        echo "Reading files: ".PHP_EOL.PHP_EOL;
 
         $files = scandir($path);
         $fileToProcess = array();
+        $fileToProcessStatic = array();
 
         if (!empty($files)) {
             foreach ($files as $file) {
                 $fileInfo = pathinfo($file);
                 if ($fileInfo['extension'] == 'csv') {
-                    // teachers_yyyymmdd.csv, courses_yyyymmdd.csv, students_yyyymmdd.csv and sessions_yyyymmdd.csv
+                    // Checking teachers_yyyymmdd.csv, courses_yyyymmdd.csv, students_yyyymmdd.csv and sessions_yyyymmdd.csv
                     $parts = explode('_', $fileInfo['filename']);
-                    $method = 'import'.ucwords($parts[1]);
+                    $preMethod = ucwords($parts[1]);
+                    $preMethod = str_replace('-static', 'Static', $preMethod);
+                    $method = 'import'.$preMethod;
+
+                    $isStatic = strpos($method, 'Static');
 
                     if (method_exists($this, $method)) {
-                         $fileToProcess[$parts[1]][] = array(
-                            'method' => $method,
-                            'file' => $path.$fileInfo['basename']
-                        );
-                        //$this->$method($path.$fileInfo['basename']);
+                        if ($method == 'importUnsubscribeStatic' || empty($isStatic)) {
+                            $fileToProcess[$parts[1]][] = array(
+                                'method' => $method,
+                                'file' => $path.$fileInfo['basename']
+                            );
+                        } else {
+                            $fileToProcessStatic[$parts[1]][] = array(
+                                'method' => $method,
+                                'file' => $path.$fileInfo['basename']
+                            );
+                        }
                     } else {
                         echo "Error - This file '$file' can't be processed.".PHP_EOL;
+                        echo "Trying to call $method".PHP_EOL;
+
                         echo "The file have to has this format:".PHP_EOL;
                         echo "prefix_students_ddmmyyyy.csv, prefix_teachers_ddmmyyyy.csv, prefix_courses_ddmmyyyy.csv, prefix_sessions_ddmmyyyy.csv ".PHP_EOL;
                         exit;
@@ -112,13 +128,12 @@ class ImportCsv
 
             if (empty($fileToProcess)) {
                 echo 'Error - no files to process.';
-                exit;
+                return 0;
             }
 
-            $sections = array('students', 'teachers', 'courses', 'sessions');
-
             $this->prepareImport();
 
+            $sections = array('students', 'teachers', 'courses', 'sessions', 'unsubscribe-static');
             foreach ($sections as $section) {
                 $this->logger->addInfo("-- Import $section --");
 
@@ -128,22 +143,38 @@ class ImportCsv
                         $method = $fileInfo['method'];
                         $file = $fileInfo['file'];
 
-                        echo 'Reading file: '.$file.PHP_EOL;
+                        echo 'File: '.$file.PHP_EOL;
                         $this->logger->addInfo("Reading file: $file");
-
-                        $this->$method($file);
+                        $this->$method($file, true);
                     }
+                }
+            }
+
+            $sections = array('students-static', 'teachers-static', 'courses-static', 'sessions-static');
+            foreach ($sections as $section) {
+                $this->logger->addInfo("-- Import static files $section --");
 
+                if (isset($fileToProcessStatic[$section]) && !empty($fileToProcessStatic[$section])) {
+                    $files = $fileToProcessStatic[$section];
+                    foreach ($files as $fileInfo) {
+                        $method = $fileInfo['method'];
+                        $file = $fileInfo['file'];
+                        echo 'Static file: '.$file.PHP_EOL;
+                        $this->logger->addInfo("Reading static file: $file");
+                        $this->$method($file, true);
+                    }
                 }
             }
         }
     }
 
+    /**
+     * Prepares extra fields before the import
+     */
     private function prepareImport()
     {
         // Create user extra field: extra_external_user_id
         UserManager::create_extra_field($this->extraFieldIdNameList['user'], 1, 'External user id', null);
-
         // Create course extra field: extra_external_course_id
         CourseManager::create_course_extra_field($this->extraFieldIdNameList['course'], 1, 'External course id');
         // Create session extra field extra_external_session_id
@@ -153,7 +184,7 @@ class ImportCsv
     /**
      * @param string $file
      */
-    function moveFile($file)
+    private function moveFile($file)
     {
         $moved = str_replace('incoming', 'treated', $file);
 
@@ -194,7 +225,6 @@ class ImportCsv
             $row['extra_'.$this->extraFieldIdNameList['user']] = $row['TeacherID'];
         }
 
-        //$row['lastname'] =  Status
         return $row;
     }
 
@@ -212,9 +242,15 @@ class ImportCsv
 
         $row['teachers'] = array();
         if (isset($row['Teacher']) && !empty($row['Teacher'])) {
-            $userInfo = api_get_user_info_from_username($row['Teacher']);
-            if (!empty($userInfo)) {
-                $row['teachers'] = $userInfo['user_id'];
+            $teachers = explode(',', $row['Teacher']);
+            if (!empty($teachers)) {
+                foreach ($teachers as $teacherUserName) {
+                    $teacherUserName = trim($teacherUserName);
+                    $userInfo = api_get_user_info_from_username($teacherUserName);
+                    if (!empty($userInfo)) {
+                        $row['teachers'][] = $userInfo['user_id'];
+                    }
+                }
             }
         }
 
@@ -228,7 +264,17 @@ class ImportCsv
      * File to import
      * @param string $file
      */
-    private function importTeachers($file)
+    private function importTeachersStatic($file)
+    {
+        $this->importTeachers($file, false);
+    }
+
+    /**
+     * File to import
+     * @param string $file
+     * @param bool $moveFile
+     */
+    private function importTeachers($file, $moveFile = true)
     {
         $data = Import::csv_to_array($file);
 
@@ -306,7 +352,7 @@ class ImportCsv
                         $row['lastname'],  // <<-- changed
                         $userInfo['username'],
                         null, //$password = null,
-                        $auth_source = null,
+                        PLATFORM_AUTH_SOURCE,
                         $userInfo['email'],
                         COURSEMANAGER,
                         $userInfo['official_code'],
@@ -336,13 +382,26 @@ class ImportCsv
                 }
             }
         }
-        $this->moveFile($file);
+
+        if ($moveFile) {
+            $this->moveFile($file);
+        }
     }
 
+
     /**
      * @param string $file
      */
-    private function importStudents($file)
+    private function importStudentsStatic($file)
+    {
+        $this->importStudents($file, false);
+    }
+
+    /**
+     * @param string $file
+     * @param bool $moveFile
+     */
+    private function importStudents($file, $moveFile = true)
     {
         $data = Import::csv_to_array($file);
 
@@ -361,8 +420,10 @@ class ImportCsv
             $this->logger->addInfo(count($data)." records found.");
             foreach ($data as $row) {
                 $row = $this->cleanUserRow($row);
-                //$userInfo = api_get_user_info_from_username($row['username']);
-                $user_id = UserManager::get_user_id_from_original_id($row['extra_'.$this->extraFieldIdNameList['user']], $this->extraFieldIdNameList['user']);
+                $user_id = UserManager::get_user_id_from_original_id(
+                    $row['extra_'.$this->extraFieldIdNameList['user']],
+                    $this->extraFieldIdNameList['user']
+                );
 
                 $userInfo = array();
                 $userInfoByOfficialCode = null;
@@ -406,29 +467,51 @@ class ImportCsv
                         $this->logger->addError("Students - User NOT created: ".$row['username']." ".$row['firstname']." ".$row['lastname']);
                     }
                 } else {
+
                     if (empty($userInfo)) {
                         $this->logger->addError("Students - Can't update user :".$row['username']);
                         continue;
                     }
 
                     if ($row['action'] == 'delete') {
-                        // INactive one year later
+                        // Inactive one year later
                         $userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + 365*24*60*60));
                     }
 
+                    $password = $row['password']; // change password
+                    $email = $row['email']; // change email
+                    $resetPassword = 2; // allow password change
+
+                    // Conditions that disables the update of password and email:
+
                     if (isset($this->conditions['importStudents'])) {
                         if (isset($this->conditions['importStudents']['update']) && isset($this->conditions['importStudents']['update']['avoid'])) {
+                            // Blocking email update -
+                            // 1. Condition
                             $avoidUsersWithEmail = $this->conditions['importStudents']['update']['avoid']['email'];
                             if ($userInfo['email'] != $row['email'] && in_array($row['email'], $avoidUsersWithEmail)) {
-                                $this->logger->addInfo("Students - User skipped: ".$row['username']." because the avoid conditions (email).");
-                                continue;
+                                $this->logger->addInfo("Students - User email is not updated : ".$row['username']." because the avoid conditions (email).");
+                                // Do not change email keep the old email.
+                                $email = $userInfo['email'];
                             }
 
+                            // 2. Condition
+                            if (!in_array($userInfo['email'], $avoidUsersWithEmail) && !in_array($row['email'], $avoidUsersWithEmail)) {
+                                $email = $userInfo['email'];
+                            }
+
+                            // 3. Condition
+                            if (in_array($userInfo['email'], $avoidUsersWithEmail) && !in_array($row['email'], $avoidUsersWithEmail)) {
+                                $email = $row['email'];
+                            }
+
+                            // Blocking password update
                             $avoidUsersWithPassword = $this->conditions['importStudents']['update']['avoid']['password'];
 
                             if ($userInfo['password'] != api_get_encrypted_password($row['password']) && in_array($row['password'], $avoidUsersWithPassword)) {
-                                $this->logger->addInfo("Students - User skipped: ".$row['username']." because the avoid conditions (password).");
-                                continue;
+                                $this->logger->addInfo("Students - User password is not updated: ".$row['username']." because the avoid conditions (password).");
+                                $password = null;
+                                $resetPassword = 0; // disallow password change
                             }
                         }
                     }
@@ -441,9 +524,9 @@ class ImportCsv
                         $row['firstname'], // <<-- changed
                         $row['lastname'],  // <<-- changed
                         $row['username'],  // <<-- changed
-                        null, //$password = null,
-                        $auth_source = null,
-                        $userInfo['email'],
+                        $password, //$password = null,
+                        PLATFORM_AUTH_SOURCE,
+                        $email,
                         STUDENT,
                         $userInfo['official_code'],
                         $userInfo['phone'],
@@ -456,7 +539,7 @@ class ImportCsv
                         null, //$language = 'english',
                         null, //$encrypt_method = '',
                         false, //$send_email = false,
-                        0 //$reset_password = 0
+                        $resetPassword //$reset_password = 0
                     );
 
                     if ($result) {
@@ -477,13 +560,24 @@ class ImportCsv
             }
         }
 
-        $this->moveFile($file);
+        if ($moveFile) {
+            $this->moveFile($file);
+        }
+    }
+
+    /**
+     * @param string $file
+     */
+    private function importCoursesStatic($file)
+    {
+        $this->importCourses($file, false);
     }
 
     /**
      * @param string $file
+     * @param bool $moveFile
      */
-    private function importCourses($file)
+    private function importCourses($file, $moveFile = true)
     {
         $data = Import::csv_to_array($file);
 
@@ -495,8 +589,6 @@ class ImportCsv
             foreach ($data as $row) {
                 $row = $this->cleanCourseRow($row);
                 $courseCode = CourseManager::get_course_id_from_original_id($row['extra_'.$this->extraFieldIdNameList['course']], $this->extraFieldIdNameList['course']);
-
-                //$courseInfo = api_get_course_info($row['course_code']);
                 $courseInfo = api_get_course_info($courseCode);
                 if (empty($courseInfo)) {
                     // Create
@@ -521,9 +613,15 @@ class ImportCsv
                     $params = array(
                         'title' => $row['title'],
                     );
+
                     $result = CourseManager::update_attributes($courseInfo['real_id'], $params);
 
-                    //CourseManager::updateTeachers($courseInfo['id'], $row['teachers']);
+                    $addTeacherToSession = isset($courseInfo['add_teachers_to_sessions_courses']) && !empty($courseInfo['add_teachers_to_sessions_courses']) ? true : false;
+                    if ($addTeacherToSession) {
+                        CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, true, false);
+                    } else {
+                        CourseManager::updateTeachers($courseInfo['id'], $row['teachers'], false, false);
+                    }
 
                     if ($result) {
                         $this->logger->addInfo("Courses - Course updated ".$courseInfo['code']);
@@ -533,13 +631,26 @@ class ImportCsv
                 }
             }
         }
-        $this->moveFile($file);
+
+        if ($moveFile) {
+            $this->moveFile($file);
+        }
+    }
+
+
+    /**
+     * @param string $file
+     */
+    private function importSessionsStatic($file)
+    {
+        $this->importSessions($file, false);
     }
 
     /**
      * @param string $file
+     * @param bool $moveFile
      */
-    private function importSessions($file)
+    private function importSessions($file, $moveFile = true)
     {
         $avoid =  null;
         if (isset($this->conditions['importSessions']) && isset($this->conditions['importSessions']['update'])) {
@@ -555,16 +666,65 @@ class ImportCsv
             $this->daysCoachAccessBeforeBeginning,
             $this->daysCoachAccessAfterBeginning,
             $this->defaultSessionVisibility,
-            $avoid
+            $avoid,
+            false,
+            false,
+            true
         );
 
         if (!empty($result['error_message'])) {
             $this->logger->addError($result['error_message']);
         }
         $this->logger->addInfo("Sessions - Sessions parsed: ".$result['session_counter']);
-        $this->moveFile($file);
+
+        if ($moveFile) {
+            $this->moveFile($file);
+        }
     }
 
+    /**
+     * @param string $file
+     */
+    private function importUnsubscribeStatic($file)
+    {
+        $data = Import::csv_reader($file);
+
+        if (!empty($data)) {
+            $this->logger->addInfo(count($data)." records found.");
+            foreach ($data as $row) {
+                $chamiloUserName = $row['UserName'];
+                $chamiloCourseCode = $row['CourseCode'];
+                $chamiloSessionId = $row['SessionID'];
+
+                $sessionInfo = api_get_session_info($chamiloSessionId);
+
+                if (empty($sessionInfo)) {
+                    $this->logger->addError('Session does not exists: '.$chamiloSessionId);
+                    continue;
+                }
+
+                $courseInfo = api_get_course_info($chamiloCourseCode);
+                if (empty($courseInfo)) {
+                    $this->logger->addError('Course does not exists: '.$courseInfo);
+                    continue;
+                }
+
+                $userId = Usermanager::get_user_id_from_username($chamiloUserName);
+
+                if (empty($userId)) {
+                    $this->logger->addError('User does not exists: '.$chamiloUserName);
+                    continue;
+                }
+
+                CourseManager::unsubscribe_user($userId, $courseInfo['code'], $chamiloSessionId);
+                $this->logger->addError("User '$chamiloUserName' was removed from session: #$chamiloSessionId, Course: ".$courseInfo['code']);
+            }
+        }
+    }
+
+    /**
+     *  Dump database tables
+     */
     private function dumpDatabaseTables()
     {
         echo 'Dumping tables'.PHP_EOL;
@@ -658,19 +818,21 @@ if (!is_array($emails)) {
 }
 $subject = "Cron main/cron/import_csv.php ".date('Y-m-d h:i:s');
 $from = api_get_setting('emailAdministrator');
-
+/*
 if (!empty($emails)) {
     foreach ($emails as $email) {
         $stream = new NativeMailerHandler($email, $subject, $from, $minLevel);
         $logger->pushHandler(new BufferHandler($stream, 0, $minLevel));
     }
-}
+}*/
 
 $stream = new StreamHandler(api_get_path(SYS_ARCHIVE_PATH).'import_csv.log', $minLevel);
 $logger->pushHandler(new BufferHandler($stream, 0, $minLevel));
 $logger->pushHandler(new RotatingFileHandler('import_csv', 5, $minLevel));
 
-$import = new ImportCsv($logger, $_configuration['cron_import_csv_conditions']);
+$cronImportCSVConditions = isset($_configuration['cron_import_csv_conditions']) ? $_configuration['cron_import_csv_conditions'] : null;
+
+$import = new ImportCsv($logger, $cronImportCSVConditions);
 
 if (isset($_configuration['default_admin_user_id_for_cron'])) {
     $import->defaultAdminId = $_configuration['default_admin_user_id_for_cron'];
@@ -682,7 +844,27 @@ if (isset($argv[1]) && $argv[1] = '--dump') {
     $dump = true;
 }
 
-$import->setDumpValues($dump);
+if (isset($_configuration['import_csv_disable_dump']) && $_configuration['import_csv_disable_dump'] == true) {
+    $import->setDumpValues(false);
+} else {
+    $import->setDumpValues($dump);
+}
+
 // Do not moves the files to treated
-$import->test = true;
+if (isset($_configuration['import_csv_test'])) {
+    $import->test = $_configuration['import_csv_test'];
+} else {
+    $import->test = true;
+}
+
 $import->run();
+
+if (isset($_configuration['import_csv_fix_permissions']) && $_configuration['import_csv_fix_permissions'] == true) {
+    $command = "sudo find ".api_get_path(SYS_COURSE_PATH)." -type d -exec chmod 777 {} \; ";
+    echo "Executing: ".$command.PHP_EOL;
+    system($command);
+
+    $command = "sudo find ".api_get_path(SYS_CODE_PATH)."upload/users  -type d -exec chmod 777 {} \;";
+    echo "Executing: ".$command.PHP_EOL;
+    system($command);
+}

+ 2 - 2
main/dashboard/index.php

@@ -1,7 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-* Template (front controller in MVC pattern) used for distpaching to the controllers depend on the current action
+* Template (front controller in MVC pattern) used for distpaching to the controllers depend on the current action  
 * @author Christian Fasanando <christian1827@gmail.com>
 * @package chamilo.dashboard
 */
@@ -13,7 +13,7 @@ $language_file = array ('index', 'tracking', 'userInfo', 'admin', 'gradebook');
 $cidReset = true;
 
 // including files
-require_once '../inc/global.inc.php';
+//require_once '../inc/global.inc.php';
 require_once 'dashboard_controller.php';
 require_once 'block.class.php';
 

+ 68 - 72
main/document/create_audio.php

@@ -86,6 +86,10 @@ $interbreadcrumb[] = array(
     "name" => get_lang('Documents')
 );
 
+if (!$is_allowed_in_course) {
+	api_not_allowed(true);
+}
+
 if (!($is_allowed_to_edit || GroupManager::groupMemberWithUploadRights() || is_my_shared_folder(
     api_get_user_id(),
     Security::remove_XSS($dir),
@@ -185,7 +189,7 @@ $(document).ready(function(){
 </style>
 <div id="textareaCallBack"></div>
 <?php
-	if(Security::remove_XSS($_POST['text2voice_mode'])=='google'){
+	if (Security::remove_XSS($_POST['text2voice_mode'])=='google') {
     	downloadMP3_google($filepath, $dir);
     } elseif (Security::remove_XSS($_POST['text2voice_mode']) == 'pediaphon') {
     	downloadMP3_pediaphon($filepath, $dir);
@@ -333,8 +337,7 @@ $(document).ready(function(){
 
 				if (api_get_setting('platformLanguage')==$row['english_name']){
 					echo '<option value="'.$row['isocode'].'" selected="selected">'.$row['original_name'].' ('.$row['english_name'].')</option>';
-				}
-				else{
+				} else {
 					echo '<option value="'.$row['isocode'].'">'.$row['original_name'].' ('.$row['english_name'].')</option>';
 				}
 			}
@@ -413,8 +416,6 @@ function downloadMP3_google($filepath, $dir)
 	}
 
 	$documentPath = $filepath.'/'.$audio_filename;
-
-
 	//prev for a fine unicode, borrowed from main api TODO:clean
 	// Safe replacements for some non-letter characters (whitout blank spaces)
     $search = array(
@@ -567,7 +568,6 @@ function downloadMP3_pediaphon($filepath, $dir)
 	$extension='mp3';
 	$audio_filename=$clean_title.'.'.$extension;
 	$audio_title = str_replace('_',' ',$clean_title);
-
 	//prevent duplicates
 	if (file_exists($filepath.'/'.$clean_title.'.'.$extension)){
 		$i = 1;
@@ -581,9 +581,6 @@ function downloadMP3_pediaphon($filepath, $dir)
 
 	$documentPath = $filepath.'/'.$audio_filename;
 
-
-
-
 	//prev for a fine unicode, borrowed from main api TODO:clean
 	// Safe replacements for some non-letter characters (whitout blank spaces)
     $search = array(
@@ -652,74 +649,73 @@ function downloadMP3_pediaphon($filepath, $dir)
 
 	//adding the file
 
-
-		if($clean_lang=='de'){
-			$url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
-			$find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/(.*)\.mp3\"/';
+	if ($clean_lang=='de') {
+	    $url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
+	    $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/(.*)\.mp3\"/';
     } else {
-			$url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi';//en, es, fr
-			$find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/'.$clean_lang.'\/(.*)\.mp3\"/';
-		}
+	    $url_pediaphon='http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_'.$clean_lang.'.cgi';//en, es, fr
+	    $find_t2v = '/http\:\/\/www\.pediaphon\.org\/\~bischoff\/radiopedia\/mp3\/'.$clean_lang.'\/(.*)\.mp3\"/';
+    }
 
-		$data="stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=go";
-        $opts = array(
-            'http' =>
-			    array(
-			         'method'  => 'POST',
-			         'header'  =>"Content-Type: application/x-www-form-urlencoded\r\n",
-			         "Content-Length: " . strlen($data) . "\r\n",
-			         'content' => $data
-			    )
-		);
-		$context  = stream_context_create($opts);
-		$previous_returntext2voice = file_get_contents($url_pediaphon,false,$context);
-
-		//clean file contents
-
-		$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
+	$data="stimme=".$clean_voices."&inputtext=".$clean_text."&speed=".$clean_speed."&go=go";
+    $opts = array(
+        'http' =>
+		    array(
+		         'method'  => 'POST',
+		         'header'  =>"Content-Type: application/x-www-form-urlencoded\r\n",
+		         "Content-Length: " . strlen($data) . "\r\n",
+		         'content' => $data
+		    )
+	);
+	$context  = stream_context_create($opts);
+	$previous_returntext2voice = file_get_contents($url_pediaphon,false,$context);
+
+	//clean file contents
+
+	$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);
+	//save file
+	file_put_contents($documentPath, $returntext2voice);
 
-		//add document to database
-		$current_session_id = api_get_session_id();
-		$groupId=$_SESSION['_gid'];
-		$file_size = filesize($documentPath);
-		$relativeUrlPath=$dir;
-        $doc_id = FileManager::add_document(
-            $_course,
-            $relativeUrlPath.$audio_filename,
-            'file',
-            filesize($documentPath),
-            $audio_title
-        );
-        api_item_property_update(
-            $_course,
-            TOOL_DOCUMENT,
-            $doc_id,
-            'DocumentAdded',
-            $_user['user_id'],
-            $groupId,
-            null,
-            null,
-            null,
-            $current_session_id
-        );
-        Display::display_confirmation_message(get_lang('DocumentCreated'));
+	//add document to database
+	$current_session_id = api_get_session_id();
+	$groupId=$_SESSION['_gid'];
+	$file_size = filesize($documentPath);
+	$relativeUrlPath=$dir;
+    $doc_id = FileManager::add_document(
+        $_course,
+        $relativeUrlPath.$audio_filename,
+        'file',
+        filesize($documentPath),
+        $audio_title
+    );
+    api_item_property_update(
+        $_course,
+        TOOL_DOCUMENT,
+        $doc_id,
+        'DocumentAdded',
+        $_user['user_id'],
+        $groupId,
+        null,
+        null,
+        null,
+        $current_session_id
+    );
+    Display::display_confirmation_message(get_lang('DocumentCreated'));
 	//return to location
 	echo '<script>window.location.href="'.$location.'"</script>';
 }

+ 15 - 13
main/document/create_draw.php

@@ -92,6 +92,10 @@ if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
 
 $interbreadcrumb[] = array ("url" => "./document.php?id=".$parent_id.$req_gid, "name" => get_lang('Documents'));
 
+if (!$is_allowed_in_course) {
+	api_not_allowed(true);
+}
+
 if (!($is_allowed_to_edit || GroupManager::groupMemberWithUploadRights() || is_my_shared_folder(api_get_user_id(), Security::remove_XSS($dir), api_get_session_id()))) {
 	api_not_allowed(true);
 }
@@ -137,27 +141,25 @@ echo '<div class="actions">';
 		echo '<a href="document.php?id='.$document_id.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
 echo '</div>';
 
-if (api_browser_support('svg')){
+if (api_browser_support('svg')) {
 
 	//automatic loading the course language
 	$svgedit_code_translation_table = array('' => 'en', 'pt' => 'pt-Pt', 'sr' => 'sr_latn');
 	$langsvgedit  = api_get_language_isocode();
 	$langsvgedit = isset($svgedit_code_translation_table[$langsvgedit]) ? $svgedit_code_translation_table[$langsvgedit] : $langsvgedit;
 	$langsvgedit = file_exists(api_get_path(LIBRARY_PATH).'svg-edit/locale/lang.'.$langsvgedit.'.js') ? $langsvgedit : 'en';
-	$svg_url= api_get_path(WEB_LIBRARY_PATH).'svg-edit/svg-editor.php?lang='.$langsvgedit ;
+	$svg_url= api_get_path(WEB_LIBRARY_PATH).'svg-edit/svg-editor.php?lang='.$langsvgedit;
 	?>
-
-	<script type="text/javascript">
-
+	<script>
 		document.write ('<iframe id="frame" frameborder="0" scrolling="no" src="<?php echo  $svg_url; ?>" width="100%" height="100%"><noframes><p>Sorry, your browser does not handle frames</p></noframes></iframe>');
-	function resizeIframe() {
-    	var height = window.innerHeight -50;
-		//max lower size
-		if (height<550) {
-			height=550;
-		}
-    	document.getElementById('frame').style.height = height +"px";
-	};
+        function resizeIframe() {
+            var height = window.innerHeight -50;
+            //max lower size
+            if (height<550) {
+                height=550;
+            }
+            document.getElementById('frame').style.height = height +"px";
+        }
 	document.getElementById('frame').onload = resizeIframe;
 	window.onresize = resizeIframe;
 

+ 6 - 2
main/document/create_paint.php

@@ -33,7 +33,7 @@ if (api_get_setting('enabled_support_paint') == 'false') {
 $document_data = DocumentManager::get_document_data_by_id($_GET['id'], api_get_course_id(), true);
 if (empty($document_data)) {
     if (api_is_in_group()) {
-        $group_properties   = GroupManager::get_group_properties(api_get_group_id());
+        $group_properties   = GroupManager::get_group_properties(api_get_group_id());        
         $document_id        = DocumentManager::get_document_id(api_get_course_info(), $group_properties['directory']);
         $document_data      = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
     }
@@ -92,6 +92,10 @@ if (isset ($_SESSION['_gid']) && $_SESSION['_gid'] != 0) {
 
 $interbreadcrumb[] = array ("url" => "./document.php?curdirpath=".urlencode($dir).$req_gid, "name" => get_lang('Documents'));
 
+if (!$is_allowed_in_course) {
+	api_not_allowed(true);
+}
+
 if (!($is_allowed_to_edit || GroupManager::groupMemberWithUploadRights() || is_my_shared_folder($_user['user_id'], Security::remove_XSS($dir),api_get_session_id()))) {
 	api_not_allowed(true);
 }
@@ -158,7 +162,7 @@ else {
 	$credentials="false";
 }
 
-$pixlr_url = 'http://pixlr.com/editor/?title='.$title.'&amp;image='.$image.'&amp;loc='.$loc.'&amp;referrer='.$referrer.'&amp;target='.$target.'&amp;exit='.$exit_path.'&amp;locktarget='.$locktarget.'&amp;locktitle='.$locktitle.'&amp;credentials='.$credentials;
+$pixlr_url = api_get_protocol().'://pixlr.com/editor/?title='.$title.'&amp;image='.$image.'&amp;loc='.$loc.'&amp;referrer='.$referrer.'&amp;target='.$target.'&amp;exit='.$exit_path.'&amp;locktarget='.$locktarget.'&amp;locktitle='.$locktitle.'&amp;credentials='.$credentials;
 
 
 ?>