Browse Source

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

Yannick Warnier 11 years ago
parent
commit
f8c530b388
50 changed files with 3530 additions and 1406 deletions
  1. 1 4
      index.php
  2. 337 0
      main/admin/access_url_edit_course_category_to_url.php
  3. 0 5
      main/admin/access_url_edit_usergroup_to_url.php
  4. 14 1
      main/admin/access_urls.php
  5. 17 6
      main/admin/course_category.php
  6. 39 41
      main/admin/dashboard_add_sessions_to_user.php
  7. 2 1
      main/auth/profile.php
  8. 7 12
      main/cron/import_csv.php
  9. 1 0
      main/exercice/answer.class.php
  10. 119 109
      main/group/group.php
  11. 34 29
      main/group/group_category.php
  12. 91 93
      main/group/group_creation.php
  13. 104 93
      main/group/group_edit.php
  14. 97 78
      main/group/group_overview.php
  15. 50 43
      main/group/group_space.php
  16. 71 0
      main/group/import.php
  17. 222 0
      main/group/member_settings.php
  18. 194 0
      main/group/settings.php
  19. 185 0
      main/group/tutor_settings.php
  20. BIN
      main/img/icons/22/export_excel.png
  21. 53 19
      main/inc/ajax/model.ajax.php
  22. 65 11
      main/inc/lib/course_category.lib.php
  23. 0 1
      main/inc/lib/database.lib.php
  24. 18 15
      main/inc/lib/exercise_show_functions.lib.php
  25. 78 72
      main/inc/lib/export.lib.inc.php
  26. 325 131
      main/inc/lib/groupmanager.lib.php
  27. 2 0
      main/inc/lib/internationalization.lib.php
  28. 92 49
      main/inc/lib/pdf.lib.php
  29. 27 12
      main/inc/lib/sessionmanager.lib.php
  30. 3 1
      main/inc/lib/social.lib.php
  31. 23 19
      main/inc/lib/tracking.lib.php
  32. 158 17
      main/inc/lib/urlmanager.lib.php
  33. 7 1
      main/inc/lib/userportal.lib.php
  34. 17 10
      main/newscorm/lp_upload.php
  35. 26 18
      main/newscorm/openoffice_document.class.php
  36. 59 19
      main/newscorm/openoffice_presentation.class.php
  37. 132 101
      main/survey/survey.lib.php
  38. 77 70
      main/survey/survey_list.php
  39. 15 7
      main/tracking/courseLog.php
  40. 48 50
      main/upload/upload_ppt.php
  41. 16 9
      main/work/add_document.php
  42. 7 9
      main/work/edit_work.php
  43. 4 1
      main/work/upload_from_template.php
  44. 592 131
      main/work/work.lib.php
  45. 0 35
      main/work/work.php
  46. 28 20
      main/work/work_list.php
  47. 62 11
      main/work/work_list_all.php
  48. 10 3
      main/work/work_list_others.php
  49. 0 48
      tests/main/work/work.lib.test.php
  50. 1 1
      user_portal.php

+ 1 - 4
index.php

@@ -9,7 +9,7 @@ use \ChamiloSession as Session;
 
 define('CHAMILO_HOMEPAGE', true);
 
-$language_file = array('courses', 'index');
+$language_file = array('courses', 'index', 'userInfo');
 
 /* Flag forcing the 'current course' reset, as we're not inside a course anymore. */
 // Maybe we should change this into an api function? an example: CourseManager::unset();
@@ -151,7 +151,6 @@ if (api_is_anonymous()) {
     }
 }
 
-
 $controller->set_login_form($showLoginForm);
 
 //@todo move this inside the IndexManager
@@ -181,9 +180,7 @@ if (!isset($_REQUEST['include'])) {
 $controller->tpl->assign('hot_courses', $hot_courses);
 $controller->tpl->assign('announcements_block', $announcements_block);
 $controller->tpl->assign('home_page_block', $controller->return_home_page());
-
 $controller->tpl->assign('navigation_course_links', $controller->return_navigation_links());
-
 $controller->tpl->assign('notice_block', $controller->return_notice());
 $controller->tpl->assign('main_navigation_block', $controller->return_navigation_links());
 $controller->tpl->assign('help_block', $controller->return_help());

+ 337 - 0
main/admin/access_url_edit_course_category_to_url.php

@@ -0,0 +1,337 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+*	@package chamilo.admin
+*	@author Julio Montoya <gugli100@gmail.com>
+*/
+
+// name of the language file that needs to be included
+$language_file = 'admin';
+
+// resetting the course id
+$cidReset = true;
+
+require_once '../inc/global.inc.php';
+require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
+require_once api_get_path(LIBRARY_PATH).'course_category.lib.php';
+require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php';
+
+$xajax = new xajax();
+$xajax->registerFunction(array('searchCourseCategoryAjax', 'UrlManager', 'searchCourseCategoryAjax'));
+
+// Setting the section (for the tabs)
+$this_section = SECTION_PLATFORM_ADMIN;
+
+// Access restrictions
+api_protect_global_admin_script();
+if (!api_get_multiple_access_url()) {
+    header('Location: index.php');
+    exit;
+}
+
+// Setting breadcrumbs
+$tool_name = get_lang('EditUserGroupToURL');
+$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
+$interbreadcrumb[] = array ('url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs'));
+
+$add_type = 'multiple';
+if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
+    $add_type = Security::remove_XSS($_REQUEST['add_type']);
+}
+
+$access_url_id = 1;
+if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id'] != '') {
+    $access_url_id = Security::remove_XSS($_REQUEST['access_url_id']);
+}
+
+$xajax->processRequests();
+$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
+$htmlHeadXtra[] = '
+<script>
+function add_user_to_url(code, content) {
+
+	document.getElementById("course_to_add").value = "";
+	document.getElementById("ajax_list_courses").innerHTML = "";
+
+	destination = document.getElementById("destination_users");
+	destination.options[destination.length] = new Option(content,code);
+
+	destination.selectedIndex = -1;
+	sortOptions(destination.options);
+}
+
+function send() {
+
+	if (document.formulaire.access_url_id.value!=0) {
+		document.formulaire.form_sent.value=0;
+		document.formulaire.add_type.value=\''.$add_type.'\';
+		document.formulaire.submit();
+	}
+}
+
+function remove_item(origin) {
+	for(var i = 0 ; i<origin.options.length ; i++) {
+		if(origin.options[i].selected) {
+			origin.options[i]=null;
+			i = i-1;
+		}
+	}
+}
+</script>';
+
+$form_sent=0;
+$errorMsg='';
+$UserList=$SessionList = array();
+$users=$sessions = array();
+
+if (isset($_POST['form_sent']) && $_POST['form_sent']) {
+    $form_sent = $_POST['form_sent'];
+    $list = $_POST['course_list'];
+
+    if (!is_array($list)) {
+        $list = array();
+    }
+
+    if ($form_sent == 1) {
+        if ($access_url_id == 0) {
+            header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
+        } elseif (is_array($list)) {
+            UrlManager::updateUrlRelCourseCategory($list, $access_url_id);
+            header('Location: access_urls.php?action=show_message&message='.get_lang('Updated'));
+        }
+        exit;
+    }
+}
+
+Display::display_header($tool_name);
+
+api_display_tool_title($tool_name);
+
+if ($_GET['action'] == 'show_message') {
+    Display :: display_normal_message(Security::remove_XSS(stripslashes($_GET['message'])));
+}
+
+$noUserGroupList = $userGroupList = array();
+$ajax_search = $add_type == 'unique' ? true : false;
+
+if ($ajax_search) {
+    $userGroups = UrlManager::getUrlRelCourseCategory($access_url_id);
+    foreach ($userGroups as $item) {
+        $userGroupList[$item['id']] = $item;
+    }
+} else {
+    $userGroups = UrlManager::getUrlRelCourseCategory();
+
+    foreach ($userGroups as $item) {
+        if ($item['access_url_id'] == $access_url_id) {
+            $userGroupList[$item['id']] = $item ;
+        }
+    }
+    $noUserGroupList = getCourseCategoryNotInList(array_keys($userGroupList));
+}
+
+if ($add_type == 'multiple') {
+	$link_add_type_unique = '<a href="'.api_get_self().'?add_type=unique&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeUnique').'</a>';
+	$link_add_type_multiple = get_lang('SessionAddTypeMultiple');
+} else {
+	$link_add_type_unique = get_lang('SessionAddTypeUnique');
+	$link_add_type_multiple = '<a href="'.api_get_self().'?add_type=multiple&access_url_id='.$access_url_id.'">'.get_lang('SessionAddTypeMultiple').'</a>';
+}
+
+$url_list = UrlManager::get_url_data();
+?>
+<div style="text-align: left;">
+	<?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>
+</div>
+<br /><br />
+<form
+    name="formulaire"
+    method="post"
+    action="<?php echo api_get_self(); ?>"
+    style="margin:0px;" <?php if ($ajax_search) { echo ' onsubmit="valide();"'; } ?>
+>
+<?php echo get_lang('SelectUrl').' : '; ?>
+<select name="access_url_id" onchange="javascript:send();">
+<option value="0">-- <?php echo get_lang('SelectUrl')?> -- </option>
+	<?php
+    $url_selected = '';
+    foreach ($url_list as $url_obj) {
+        $checked = '';
+        if (!empty($access_url_id)) {
+            if ($url_obj[0] == $access_url_id) {
+                $checked = 'selected=true';
+                $url_selected=$url_obj[1];
+            }
+        }
+        if ($url_obj['active']==1) { ?>
+            <option <?php echo $checked;?> value="<?php echo $url_obj[0]; ?>"> <?php echo $url_obj[1]; ?>
+            </option>
+        <?php
+        }
+    }
+?>
+</select>
+<br /><br />
+<input type="hidden" name="form_sent" value="1" />
+<input type="hidden" name="add_type" value = "<?php echo $add_type ?>" />
+
+<?php
+if (!empty($errorMsg)) {
+    Display::display_normal_message($errorMsg); //main API
+}
+?>
+
+<table border="0" cellpadding="5" cellspacing="0" width="100%">
+<!-- Users -->
+<tr>
+  <td align="center"><b><?php echo get_lang('CourseCategoryInPlatform') ?> :</b>
+  </td>
+  <td></td>
+  <td align="center"><b><?php echo get_lang('CourseCategoryListIn').' '.$url_selected; ?></b></td>
+</tr>
+
+<tr>
+  <td align="center">
+  <div id="content_source">
+    <?php if ($ajax_search) { ?>
+		<input type="text" id="course_to_add" onkeyup="xajax_searchCourseCategoryAjax(this.value,document.formulaire.access_url_id.options[document.formulaire.access_url_id.selectedIndex].value)" />
+		<div id="ajax_list_courses"></div>
+    <?php } else { ?>
+	  <select id="origin_users" name="no_course_list[]" multiple="multiple" size="15" style="width:380px;">
+		<?php
+		foreach ($noUserGroupList as $noItem) {
+		?>
+			<option value="<?php echo $noItem['id']; ?>">
+                <?php echo $noItem['name']; ?>
+            </option>
+		<?php
+		}
+		?>
+	  </select>
+	<?php
+  	  }
+  	 ?>
+  </div>
+  </td>
+  <td width="10%" valign="middle" align="center">
+  <?php
+  if ($ajax_search) {
+	?>
+	<button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination_users'))" ></button>
+  	<?php
+  } else {
+  	?>
+	<button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))" ></button>
+	<br /><br />
+	<button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))" ></button>
+	<?php
+  }
+  ?>
+	<br /><br /><br /><br /><br /><br />
+  </td>
+  <td align="center">
+  <select id="destination_users" name="course_list[]" multiple="multiple" size="15" style="width:380px;">
+<?php
+foreach($userGroupList as $item) {
+?>
+	<option value="<?php echo $item['id']; ?>">
+        <?php echo $item['name']; ?>
+    </option>
+<?php
+}
+?>
+  </select>
+  </td>
+</tr>
+<tr>
+	<td colspan="3" align="center">
+		<br />
+		<?php
+		if(isset($_GET['add']))
+			echo '<button class="save" onclick="valide()" >'.get_lang('Add').'</button>';
+		else
+			echo '<button class="save" onclick="valide()" >'.get_lang('Edit').'</button>';
+		?>
+	</td>
+</tr>
+</table>
+</form>
+<script>
+
+function moveItem(origin , destination) {
+	for(var i = 0 ; i<origin.options.length ; i++) {
+		if(origin.options[i].selected) {
+			destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
+			origin.options[i]=null;
+			i = i-1;
+		}
+	}
+	destination.selectedIndex = -1;
+	sortOptions(destination.options);
+}
+
+function sortOptions(options) {
+	newOptions = new Array();
+	for (i = 0 ; i<options.length ; i++)
+		newOptions[i] = options[i];
+
+	newOptions = newOptions.sort(mysort);
+	options.length = 0;
+	for(i = 0 ; i < newOptions.length ; i++)
+		options[i] = newOptions[i];
+
+}
+
+function mysort(a, b) {
+	if(a.text.toLowerCase() > b.text.toLowerCase()){
+		return 1;
+	}
+	if(a.text.toLowerCase() < b.text.toLowerCase()){
+		return -1;
+	}
+	return 0;
+}
+
+function valide(){
+	var options = document.getElementById('destination_users').options;
+	for (i = 0 ; i<options.length ; i++)
+		options[i].selected = true;
+	document.forms.formulaire.submit();
+}
+
+function loadUsersInSelect(select){
+
+	var xhr_object = null;
+
+	if(window.XMLHttpRequest) // Firefox
+		xhr_object = new XMLHttpRequest();
+	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...");
+
+	xhr_object.open("POST", "loadUsersInSelect.ajax.php");
+	xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+	nosessionUsers = makepost(document.getElementById('origin_users'));
+	sessionUsers = makepost(document.getElementById('destination_users'));
+	nosessionClasses = makepost(document.getElementById('origin_classes'));
+	sessionClasses = makepost(document.getElementById('destination_classes'));
+	xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
+
+	xhr_object.onreadystatechange = function() {
+		if(xhr_object.readyState == 4) {
+			document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
+		}
+	}
+}
+
+function makepost(select){
+	var options = select.options;
+	var ret = "";
+	for (i = 0 ; i<options.length ; i++)
+		ret = ret + options[i].value +'::'+options[i].text+";;";
+	return ret;
+}
+</script>
+<?php
+Display::display_footer();

+ 0 - 5
main/admin/access_url_edit_usergroup_to_url.php

@@ -30,11 +30,6 @@ if (!api_get_multiple_access_url()) {
     exit;
 }
 
-// Database Table Definitions
-$tbl_access_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
-$tbl_course 			 = Database::get_main_table(TABLE_MAIN_COURSE);
-$tbl_access_url 		 = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
-
 // setting breadcrumbs
 $tool_name = get_lang('EditUserGroupToURL');
 $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));

+ 14 - 1
main/admin/access_urls.php

@@ -25,6 +25,7 @@ Display :: display_header($tool_name);
 
 require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
 require_once api_get_path(LIBRARY_PATH).'usergroup.lib.php';
+require_once api_get_path(LIBRARY_PATH).'course_category.lib.php';
 
 $my_user_url_list = api_get_access_url_from_user(api_get_user_id());
 $current_access_url_id = api_get_current_access_url_id();
@@ -108,10 +109,22 @@ echo Display::url(Display::return_icon('new_link.png',  get_lang('AddUrl'), arra
 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');
+    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 '</div>';
 
 //$table = new SortableTable('urls', 'url_count_mask', 'get_url_data_mask',2);

+ 17 - 6
main/admin/course_category.php

@@ -29,7 +29,10 @@ $errorMsg = '';
 if (!empty($action)) {
     if ($action == 'delete') {
         if (api_get_multiple_access_url()) {
-            if (api_get_current_access_url_id() == 1) {
+            if (api_get_current_access_url_id() == 1 ||
+                (isset($_configuration['enable_multiple_url_support_for_course_category']) &&
+                $_configuration['enable_multiple_url_support_for_course_category'])
+            ) {
                 deleteNode($_GET['id']);
                 header('Location: ' . api_get_self() . '?category=' . Security::remove_XSS($category));
                 exit();
@@ -63,7 +66,11 @@ $interbreadcrumb[] = array('url' => 'index.php', "name" => get_lang('PlatformAdm
 Display::display_header($tool_name);
 
 if ($action == 'add' || $action == 'edit') {
-    if ((api_get_multiple_access_url() && api_get_current_access_url_id() == 1) || !api_get_multiple_access_url()) {
+    if ((api_get_multiple_access_url() && api_get_current_access_url_id() == 1) ||
+        !api_get_multiple_access_url() ||
+        (isset($_configuration['enable_multiple_url_support_for_course_category']) &&
+         $_configuration['enable_multiple_url_support_for_course_category'])
+    ) {
         echo '<div class="actions">';
         echo Display::url(
             Display::return_icon('folder_up.png', get_lang("Back"), '', ICON_SIZE_MEDIUM),
@@ -83,8 +90,12 @@ if ($action == 'add' || $action == 'edit') {
         $form->addElement('text', 'name', get_lang("CategoryName"));
         $form->addRule('name', get_lang('PleaseEnterCategoryInfo'), 'required');
         $form->addRule('code', get_lang('PleaseEnterCategoryInfo'), 'required');
-        $form->addElement('radio', 'auth_course_child', get_lang("AllowCoursesInCategory"), get_lang('Yes'), 'TRUE');
-        $form->addElement('radio', 'auth_course_child', null, get_lang('No'), 'FALSE');
+        $group = array(
+            $form->createElement('radio', 'auth_course_child', get_lang("AllowCoursesInCategory"), get_lang('Yes'), 'TRUE'),
+            $form->createElement('radio', 'auth_course_child', null, get_lang('No'), 'FALSE')
+        );
+        $form->addGroup($group, null, get_lang("AllowCoursesInCategory"));
+
         if (!empty($categoryInfo)) {
             $class = "save";
             $text = get_lang('CategoryMod');
@@ -110,7 +121,7 @@ if ($action == 'add' || $action == 'edit') {
         );
     }
 
-    if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'FALSE') {
+    if (empty($parentInfo) || $parentInfo['auth_cat_child'] == 'TRUE') {
         echo Display::url(
             Display::return_icon('new_folder.png', get_lang("AddACategory"), '', ICON_SIZE_MEDIUM),
             api_get_path(WEB_CODE_PATH).'admin/course_category.php?action=add&category='.$category
@@ -119,7 +130,7 @@ if ($action == 'add' || $action == 'edit') {
 
     echo '</div>';
     if (!empty($parentInfo)) {
-        echo Display::page_subheader($parentInfo['name']);
+        echo Display::page_subheader($parentInfo['name'].' ('.$parentInfo['code'].')');
     }
     echo listCategories($category);
 }

+ 39 - 41
main/admin/dashboard_add_sessions_to_user.php

@@ -11,7 +11,6 @@ $language_file='admin';
 // resetting the course id
 $cidReset = true;
 
-// including some necessary dokeos files
 require_once '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php';
 global $_configuration;
@@ -52,8 +51,8 @@ if (UserManager::is_admin($user_id)) {
 }
 
 $add_type = 'multiple';
-if(isset($_GET['add_type']) && $_GET['add_type']!=''){
-	$add_type = Security::remove_XSS($_REQUEST['add_type']);
+if (isset($_GET['add_type']) && $_GET['add_type']!=''){
+    $add_type = Security::remove_XSS($_REQUEST['add_type']);
 }
 
 if (!api_is_platform_admin() && !api_is_session_admin()) {
@@ -61,40 +60,40 @@ if (!api_is_platform_admin() && !api_is_session_admin()) {
 }
 
 function search_sessions($needle,$type) {
-	global $_configuration, $tbl_session_rel_access_url, $tbl_session, $user_id;
-
-	$xajax_response = new XajaxResponse();
-	$return = '';
-	if(!empty($needle) && !empty($type)) {
-		// xajax send utf8 datas... datas in db can be non-utf8 datas
-		$charset = api_get_system_encoding();
-		$needle = api_convert_encoding($needle, $charset, 'utf-8');
-		$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).")";
-		}
-
-		if ($_configuration['multiple_access_urls']) {
-			$sql 	= " SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
-						WHERE  s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()."";
-		} else {
-			$sql = "SELECT s.id, s.name FROM $tbl_session s
-				WHERE  s.name LIKE '$needle%' $without_assigned_sessions ";
-		}
-
-		$rs	= Database::query($sql);
-
-		$return .= '<select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">';
-		while($session = Database :: fetch_array($rs)) {
-			$return .= '<option value="'.$session['id'].'" title="'.htmlspecialchars($session['name'],ENT_QUOTES).'">'.$session['name'].'</option>';
-		}
-		$return .= '</select>';
-		$xajax_response->addAssign('ajax_list_sessions_multiple','innerHTML',api_utf8_encode($return));
-	}
-	return $xajax_response;
+    global $_configuration, $tbl_session_rel_access_url, $tbl_session, $user_id;
+
+    $xajax_response = new XajaxResponse();
+    $return = '';
+    if(!empty($needle) && !empty($type)) {
+        // xajax send utf8 datas... datas in db can be non-utf8 datas
+        $charset = api_get_system_encoding();
+        $needle = api_convert_encoding($needle, $charset, 'utf-8');
+        $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).")";
+        }
+
+        if ($_configuration['multiple_access_urls']) {
+            $sql 	= " SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
+                        WHERE  s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()."";
+        } else {
+            $sql = "SELECT s.id, s.name FROM $tbl_session s
+                    WHERE  s.name LIKE '$needle%' $without_assigned_sessions ";
+        }
+
+        $rs	= Database::query($sql);
+
+        $return .= '<select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">';
+        while($session = Database :: fetch_array($rs)) {
+            $return .= '<option value="'.$session['id'].'" title="'.htmlspecialchars($session['name'],ENT_QUOTES).'">'.$session['name'].'</option>';
+        }
+        $return .= '</select>';
+        $xajax_response->addAssign('ajax_list_sessions_multiple','innerHTML',api_utf8_encode($return));
+    }
+    return $xajax_response;
 }
 
 $xajax->processRequests();
@@ -157,7 +156,7 @@ $UserList = array();
 $msg = '';
 if (intval($_POST['formSent']) == 1) {
 	$sessions_list = $_POST['SessionsList'];
-	$affected_rows = SessionManager::suscribe_sessions_to_hr_manager($user_id,$sessions_list);
+	$affected_rows = SessionManager::suscribe_sessions_to_hr_manager($user_id, $sessions_list);
 	if ($affected_rows)	{
 		$msg = get_lang('AssignedSessionsHaveBeenUpdatedSuccessfully');
 	}
@@ -192,11 +191,11 @@ if (isset($_POST['firstLetterSession'])) {
 
 if ($_configuration['multiple_access_urls']) {
 	$sql 	= " SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
-				WHERE  s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()." 
+				WHERE  s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()."
                 ORDER BY s.name";
 } else {
 	$sql 	= " SELECT s.id, s.name FROM $tbl_session s
-				WHERE  s.name LIKE '$needle%' $without_assigned_sessions 
+				WHERE  s.name LIKE '$needle%' $without_assigned_sessions
                 ORDER BY s.name
                 ";
 }
@@ -289,7 +288,6 @@ if(!empty($msg)) {
   </select></td>
 </tr>
 </table>
-
 </form>
 
 <?php

+ 2 - 1
main/auth/profile.php

@@ -358,12 +358,13 @@ function upload_user_production($user_id) {
  * @return    bool true o false
  * @uses Gets user ID from global variable
  */
-function check_user_password($password){
+function check_user_password($password) {
     global $_user;
     $user_id = api_get_user_id();
     if ($user_id != strval(intval($user_id)) || empty($password)) { return false; }
     $table_user = Database :: get_main_table(TABLE_MAIN_USER);
     $password = api_get_encrypted_password($password);
+    $password = Database::escape_string($password);
     $sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND password='".$password."'";
     $result = Database::query($sql_password);
     return Database::num_rows($result) != 0;

+ 7 - 12
main/cron/import_csv.php

@@ -139,11 +139,8 @@ class ImportCsv
 
                         $this->$method($file);
                     }
-
                 }
             }
-
-
         }
     }
 
@@ -154,7 +151,6 @@ class ImportCsv
     {
         // 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
@@ -205,7 +201,6 @@ class ImportCsv
             $row['extra_'.$this->extraFieldIdNameList['user']] = $row['TeacherID'];
         }
 
-        //$row['lastname'] =  Status
         return $row;
     }
 
@@ -323,7 +318,7 @@ class ImportCsv
                         $row['lastname'],  // <<-- changed
                         $userInfo['username'],
                         null, //$password = null,
-                        $auth_source = null,
+                        PLATFORM_AUTH_SOURCE,
                         $userInfo['email'],
                         COURSEMANAGER,
                         $userInfo['official_code'],
@@ -378,8 +373,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;
@@ -481,7 +478,7 @@ class ImportCsv
                         $row['lastname'],  // <<-- changed
                         $row['username'],  // <<-- changed
                         $password, //$password = null,
-                        $auth_source = null,
+                        PLATFORM_AUTH_SOURCE,
                         $email,
                         STUDENT,
                         $userInfo['official_code'],
@@ -543,7 +540,7 @@ class ImportCsv
                     $params['wanted_code']          = $row['course_code'];
                     $params['course_category']      = $row['course_category'];
                     $params['course_language']      = $row['language'];
-                    $params['teachers'] = $row['teachers'];
+                    $params['teachers']             = $row['teachers'];
 
                     $courseInfo = CourseManager::create_course($params);
 
@@ -620,10 +617,8 @@ class ImportCsv
             foreach ($data as $row) {
                 $chamiloUserName = $row['UserName'];
                 $chamiloCourseCode = $row['CourseCode'];
-                //$systemSessionId= $row['SessionID'];
                 $chamiloSessionId = $row['SessionID'];
 
-                //$sessionId = SessionManager::get_session_id_from_original_id($systemSessionId, $this->extraFieldIdNameList['session']);
                 $sessionInfo = api_get_session_info($chamiloSessionId);
 
                 if (empty($sessionInfo)) {

+ 1 - 0
main/exercice/answer.class.php

@@ -545,6 +545,7 @@ class Answer
 
 		$this->cancel();
 	}
+
 	/**
 	 * Duplicates answers by copying them into another question
 	 *

+ 119 - 109
main/group/group.php

@@ -39,25 +39,25 @@ $course_id = api_get_course_int_id();
 
 // Create default category if it doesn't exist when group categories aren't allowed
 if (api_get_setting('allow_group_categories') == 'false') {
-	$cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY);
-	$sql = "SELECT * FROM $cat_table WHERE c_id = $course_id AND id = '".GroupManager::DEFAULT_GROUP_CATEGORY."'";
-	$res = Database::query($sql);
-	$num = Database::num_rows($res);
-	if ($num == 0) {
-		$sql = "INSERT INTO ".$cat_table." ( c_id, id , title , description , forum_state, wiki_state, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)
-		VALUES ($course_id, '2', '".lang2db(get_lang('DefaultGroupCategory'))."', '', '1', '1', '8', '0', '0', '0', '0');";
-		Database::query ($sql);
-	}
+    $cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY);
+    $sql = "SELECT * FROM $cat_table WHERE c_id = $course_id AND id = '".GroupManager::DEFAULT_GROUP_CATEGORY."'";
+    $res = Database::query($sql);
+    $num = Database::num_rows($res);
+    if ($num == 0) {
+        $sql = "INSERT INTO ".$cat_table." ( c_id, id , title , description , forum_state, wiki_state, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)
+        VALUES ($course_id, '2', '".lang2db(get_lang('DefaultGroupCategory'))."', '', '1', '1', '8', '0', '0', '0', '0');";
+        Database::query($sql);
+    }
 }
 
 /*	Header */
 
 if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
-	// So we are not in learnpath tool
-	event_access_tool(TOOL_GROUP);
-	if (!$is_allowed_in_course) {
-		api_not_allowed(true);
-	}
+    // So we are not in learnpath tool
+    event_access_tool(TOOL_GROUP);
+    if (!$is_allowed_in_course) {
+        api_not_allowed(true);
+    }
 }
 
 Display::display_header(get_lang('Groups'));
@@ -66,7 +66,7 @@ Display::display_header(get_lang('Groups'));
 Display::display_introduction_section(TOOL_GROUP);
 
 /*
- * Self-registration and unregistration
+ * Self-registration and un-registration
  */
  $my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
  $my_msg	  = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : null;
@@ -76,29 +76,29 @@ Display::display_introduction_section(TOOL_GROUP);
  $my_get_id   = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
 
 if (isset($_GET['action'])) {
-	switch ($_GET['action']) {
-		case 'self_reg':
-			if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
-				GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $my_group_id);
-				Display :: display_confirmation_message(get_lang('GroupNowMember'));
-			}
-			break;
-		case 'self_unreg':
-			if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
-				GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $my_group_id);
-				Display :: display_confirmation_message(get_lang('StudentDeletesHimself'));
-			}
-			break;
-		case 'show_msg':
-			Display :: display_confirmation_message($my_msg);
-			break;
+    switch ($_GET['action']) {
+        case 'self_reg':
+            if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
+                GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $my_group_id);
+                Display :: display_confirmation_message(get_lang('GroupNowMember'));
+            }
+            break;
+        case 'self_unreg':
+            if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
+                GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $my_group_id);
+                Display :: display_confirmation_message(get_lang('StudentDeletesHimself'));
+            }
+            break;
+        case 'show_msg':
+            Display :: display_confirmation_message($my_msg);
+            break;
         case 'warning_message':
-			Display :: display_warning_message($my_msg);
-			break;
+            Display :: display_warning_message($my_msg);
+            break;
         case 'success_message':
-			Display :: display_confirmation_message($my_msg);
-			break;
-	}
+            Display :: display_confirmation_message($my_msg);
+            break;
+    }
 }
 
 /*
@@ -107,82 +107,92 @@ if (isset($_GET['action'])) {
 
 if (api_is_allowed_to_edit(false, true)) {
 
-	// Post-actions
-	if (isset($_POST['action'])) {
-		switch ($_POST['action']) {
-			case 'delete_selected' :
-				if (is_array($_POST['group'])) {
-					GroupManager :: delete_groups($my_group);
-					Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
-				}
-				break;
-			case 'empty_selected' :
-				if (is_array($_POST['group'])) {
+    // Post-actions
+    if (isset($_POST['action'])) {
+        switch ($_POST['action']) {
+            case 'delete_selected':
+                if (is_array($_POST['group'])) {
+                    GroupManager :: delete_groups($my_group);
+                    Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
+                }
+                break;
+            case 'empty_selected':
+                if (is_array($_POST['group'])) {
                     GroupManager :: unsubscribe_all_users($my_group);
                     Display :: display_confirmation_message(get_lang('SelectedGroupsEmptied'));
-				}
-				break;
-			case 'fill_selected' :
-				if (is_array($_POST['group'])) {
+                }
+                break;
+            case 'fill_selected':
+                if (is_array($_POST['group'])) {
                     GroupManager :: fill_groups($my_group);
                     Display :: display_confirmation_message(get_lang('SelectedGroupsFilled'));
-				}
-				break;
-		}
-	}
+                }
+                break;
+        }
+    }
 
-	// Get-actions
-	if (isset($_GET['action'])) {
-		switch ($_GET['action']) {
-			case 'swap_cat_order':
-				GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
-				Display :: display_confirmation_message(get_lang('CategoryOrderChanged'));
-				break;
-			case 'delete_one':
-				GroupManager :: delete_groups($my_get_id);
-				Display :: display_confirmation_message(get_lang('GroupDel'));
-				break;
-			case 'empty_one':
-				GroupManager :: unsubscribe_all_users($my_get_id);
-				Display :: display_confirmation_message(get_lang('GroupEmptied'));
-				break;
-			case 'fill_one':
-				GroupManager :: fill_groups($my_get_id);
-				Display :: display_confirmation_message(get_lang('GroupFilledGroups'));
-				break;
-			case 'delete_category':
-				GroupManager :: delete_category($my_get_id);
-				Display :: display_confirmation_message(get_lang('CategoryDeleted'));
-				break;
-		}
-	}
+    // Get-actions
+    if (isset($_GET['action'])) {
+        switch ($_GET['action']) {
+            case 'swap_cat_order':
+                GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
+                Display :: display_confirmation_message(get_lang('CategoryOrderChanged'));
+                break;
+            case 'delete_one':
+                GroupManager :: delete_groups($my_get_id);
+                Display :: display_confirmation_message(get_lang('GroupDel'));
+                break;
+
+            case 'fill_one':
+                GroupManager :: fill_groups($my_get_id);
+                Display :: display_confirmation_message(get_lang('GroupFilledGroups'));
+                break;
+            case 'delete_category':
+                GroupManager :: delete_category($my_get_id);
+                Display :: display_confirmation_message(get_lang('CategoryDeleted'));
+                break;
+        }
+    }
 }
 
 echo '<div class="actions">';
 if (api_is_allowed_to_edit(false, true)) {
-	echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).'</a>';
-	if (CourseManager::count_rows_course_table(Database::get_course_table(TABLE_GROUP),api_get_session_id(), api_get_course_int_id()) > 0) {
-		echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_summary.png', get_lang('GroupOverview'),'',ICON_SIZE_MEDIUM).'</a>';
-	}
-	if (api_get_setting('allow_group_categories') == 'true') {
-		echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.Display::return_icon('new_folder.png', get_lang('AddCategory'),'',ICON_SIZE_MEDIUM).'</a>';
-	} else {
-        echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).'</a>';
-	}
-	echo  '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a>';
-	echo '<a href="../user/user.php?'.api_get_cidreq().'">'.Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'),'',ICON_SIZE_MEDIUM).'</a>';
-}
+    echo '<a href="group_creation.php?'.api_get_cidreq().'">'.
+        Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
+
+    if (api_get_setting('allow_group_categories') == 'true') {
+        echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
+            Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
+    } else {
+        echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
+            Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
+    }
+
+    echo  '<a href="import.php?'.api_get_cidreq().'&action=import">'.
+        Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
+
+    echo  '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
+        Display::return_icon('export_csv.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
+
+    echo  '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.
+        Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
+
+    echo  '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
+        Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
 
-$group_cats = GroupManager :: get_categories(api_get_course_id());
+    echo '<a href="group_overview.php?'.api_get_cidreq().'">'.
+        Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';
 
-if (api_get_setting('allow_group_categories') == 'true' && count($group_cats) > 1) {
-	echo ' <a href="?'.api_get_cidreq().'&show_all=1">'.Display::return_icon('group.png',get_lang('ShowAll'),'',ICON_SIZE_MEDIUM).'</a>';
+    echo '<a href="../user/user.php?'.api_get_cidreq().'">'.
+        Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>';
+
+    echo GroupManager::getSearchForm();
 }
+
+$group_cats = GroupManager::get_categories(api_get_course_id());
 echo '</div>';
 
-/*
- * List all categories
- */
+/*  List all categories */
 
 if (api_get_setting('allow_group_categories') == 'true') {
     foreach ($group_cats as $index => $category) {
@@ -191,30 +201,30 @@ if (api_get_setting('allow_group_categories') == 'true') {
 
         $actions = null;
         if (api_is_allowed_to_edit(false, true)) {
-            $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'"  title="'.get_lang('Edit').'">'.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
-            $actions .= '<a href="group.php?'.api_get_cidreq().'&action=delete_category&amp;id='.$category['id'].'"  onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
+            $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'">'.
+                Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
+            $actions .= '<a href="group.php?'.api_get_cidreq().'&action=delete_category&amp;id='.$category['id'].'"  onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'">'.
+                Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
             if ($index != 0) {
-                $actions .=  ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'">'.Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
+                $actions .=  ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'">'.
+                    Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
             }
             if ($index != count($group_cats) - 1) {
-                $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'">'.Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
+                $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'">'.
+                    Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
             }
         }
 
         echo Display::page_header($category['title'].' '. $label.' '.$actions);
-
         echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p><p/>';
-
         GroupManager ::process_groups($group_list, $category['id']);
     }
 } else {
-    $group_list = GroupManager :: get_group_list();
-    GroupManager ::process_groups($group_list);
+    $group_list = GroupManager::get_group_list();
+    GroupManager::process_groups($group_list);
 }
 
-/*	FOOTER */
-
 if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
-	Display::display_footer();
+    Display::display_footer();
 }
 $_SESSION['_gid'] = 0;

+ 34 - 29
main/group/group_category.php

@@ -22,34 +22,38 @@ if (!api_is_allowed_to_edit(false,true) || !(isset ($_GET['id']) || isset ($_POS
 /**
  * Function to check the given max number of members per group
  */
-function check_max_number_of_members($value) {
-	$max_member_no_limit = $value['max_member_no_limit'];
-	if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
-		return true;
-	}
-	$max_member = $value['max_member'];
-	return is_numeric($max_member);
+function check_max_number_of_members($value)
+{
+    $max_member_no_limit = $value['max_member_no_limit'];
+    if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        return true;
+    }
+    $max_member = $value['max_member'];
+    return is_numeric($max_member);
 }
 
 /**
  * Function to check the number of groups per user
  */
-function check_groups_per_user($value) {
-	$groups_per_user = $value['groups_per_user'];
-	if (isset ($_POST['id']) && intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT && GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) {
-		return false;
-	}
-	return true;
+function check_groups_per_user($value)
+{
+    $groups_per_user = $value['groups_per_user'];
+    if (isset($_POST['id']) &&
+        intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT &&
+        GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) {
+        return false;
+    }
+    return true;
 }
 
 if (api_get_setting('allow_group_categories') == 'true') {
-	if (isset ($_GET['id'])) {
-		$category = GroupManager :: get_category($_GET['id']);
-		$nameTools = get_lang('EditGroupCategory').': '.$category['title'];
-	} else {
-		$nameTools = get_lang('AddCategory');
-		// Default values for new category
-		$category = array(
+    if (isset ($_GET['id'])) {
+        $category = GroupManager::get_category($_GET['id']);
+        $nameTools = get_lang('EditGroupCategory').': '.$category['title'];
+    } else {
+        $nameTools = get_lang('AddCategory');
+        // Default values for new category
+        $category = array(
             'groups_per_user' => 1,
             'doc_state' => GroupManager::TOOL_PRIVATE,
             'work_state' => GroupManager::TOOL_PRIVATE,
@@ -58,11 +62,12 @@ if (api_get_setting('allow_group_categories') == 'true') {
             'calendar_state' => GroupManager::TOOL_PRIVATE,
             'announcements_state'=> GroupManager::TOOL_PRIVATE,
             'forum_state' => GroupManager::TOOL_PRIVATE,
-            'max_student' => 0);
-	}
+            'max_student' => 0
+        );
+    }
 } else {
-	$category = GroupManager :: get_category($_GET['id']);
-	$nameTools = get_lang('PropModify');
+    $category = GroupManager::get_category($_GET['id']);
+    $nameTools = get_lang('PropModify');
 }
 
 $htmlHeadXtra[] = '<script>
@@ -87,8 +92,8 @@ if (isset ($_GET['id'])) {
 } else {
     // Checks if the field was created in the table Category. It creates it if is neccesary
     $table_category = Database :: get_course_table(TABLE_GROUP_CATEGORY);
-	if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) {
-    	Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id");
+    if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) {
+        Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id");
     }
 	// Create a new category
 	$action = 'add_category';
@@ -115,7 +120,7 @@ $group = array ();
 $group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'));
 $possible_values = array ();
 for ($i = 1; $i <= 10; $i ++) {
-	$possible_values[$i] = $i;
+    $possible_values[$i] = $i;
 }
 $possible_values[GroupManager::GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
 $group[] = $form->createElement('select', 'groups_per_user', null, $possible_values);
@@ -187,8 +192,8 @@ $form->addElement('style_submit_button', 'submit', get_lang('PropModify'), 'clas
 
 // If form validates -> save data
 if ($form->validate()) {
-	$values = $form->exportValues();
-	if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+    $values = $form->exportValues();
+    if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
 		$max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
 	} else {
 		$max_member = $values['max_member'];

+ 91 - 93
main/group/group_creation.php

@@ -21,51 +21,55 @@ api_protect_course_script(true);
 /*	Create the groups */
 
 if (isset ($_POST['action'])) {
-	switch ($_POST['action']) {
-		case 'create_groups':
-			$groups = array();
+    switch ($_POST['action']) {
+        case 'create_groups':
+            $groups = array();
 
-			for ($i = 0; $i < $_POST['number_of_groups']; $i ++) {
-				$group1['name'] = empty($_POST['group_'.$i.'_name']) ? get_lang('Group').' '.$i : $_POST['group_'.$i.'_name'];
-				$group1['category'] = isset($_POST['group_'.$i.'_category']) ? $_POST['group_'.$i.'_category'] : null;
-				$group1['tutor'] = isset($_POST['group_'.$i.'_tutor']) ? $_POST['group_'.$i.'_tutor'] : null;
-				$group1['places'] = isset($_POST['group_'.$i.'_places']) ? $_POST['group_'.$i.'_places'] : null;
-				$groups[] = $group1;
-			}
+            for ($i = 0; $i < $_POST['number_of_groups']; $i ++) {
+                $group1['name'] = empty($_POST['group_'.$i.'_name']) ? get_lang('Group').' '.$i : $_POST['group_'.$i.'_name'];
+                $group1['category'] = isset($_POST['group_'.$i.'_category']) ? $_POST['group_'.$i.'_category'] : null;
+                $group1['tutor'] = isset($_POST['group_'.$i.'_tutor']) ? $_POST['group_'.$i.'_tutor'] : null;
+                $group1['places'] = isset($_POST['group_'.$i.'_places']) ? $_POST['group_'.$i.'_places'] : null;
+                $groups[] = $group1;
+            }
 
-			foreach ($groups as $index => $group) {
-				if (!empty($_POST['same_tutor'])) {
-					$group['tutor'] = $_POST['group_0_tutor'];
-				}
-				if (!empty($_POST['same_places'])) {
-					$group['places'] = $_POST['group_0_places'];
-				}
-				if (api_get_setting('allow_group_categories') == 'false') {
-					$group['category'] = GroupManager::DEFAULT_GROUP_CATEGORY;
-				} elseif ($_POST['same_category']) {
-					$group['category'] = $_POST['group_0_category'];
-				}
-				GroupManager :: create_group($group['name'], $group['category'], $group['tutor'], $group['places']);
-			}
-			$msg = urlencode(count($groups).' '.get_lang('GroupsAdded'));
-			header('Location: group.php?action=show_msg&msg='.$msg);
-			break;
-		case 'create_virtual_groups':
-			$ids = GroupManager :: create_groups_from_virtual_courses();
-			$msg = urlencode(count($ids).' '.get_lang('GroupsAdded'));
-			header('Location: group.php?action=show_msg&msg='.$msg);
-			break;
-		case 'create_subgroups':
-			GroupManager :: create_subgroups($_POST['base_group'], $_POST['number_of_groups']);
-			$msg = urlencode($_POST['number_of_groups'].' '.get_lang('GroupsAdded'));
-			header('Location: group.php?action=show_msg&msg='.$msg);
-			break;
-		case 'create_class_groups':
-			$ids = GroupManager :: create_class_groups($_POST['group_category']);
-			$msg = urlencode(count($ids).' '.get_lang('GroupsAdded'));
-			header('Location: group.php?action=show_msg&msg='.$msg);
-			break;
-	}
+            foreach ($groups as $index => $group) {
+                if (!empty($_POST['same_tutor'])) {
+                    $group['tutor'] = $_POST['group_0_tutor'];
+                }
+                if (!empty($_POST['same_places'])) {
+                    $group['places'] = $_POST['group_0_places'];
+                }
+                if (api_get_setting('allow_group_categories') == 'false') {
+                    $group['category'] = GroupManager::DEFAULT_GROUP_CATEGORY;
+                } elseif ($_POST['same_category']) {
+                    $group['category'] = $_POST['group_0_category'];
+                }
+                GroupManager :: create_group($group['name'], $group['category'], $group['tutor'], $group['places']);
+            }
+            $msg = urlencode(count($groups).' '.get_lang('GroupsAdded'));
+            header('Location: group.php?action=show_msg&msg='.$msg);
+            exit;
+            break;
+        case 'create_virtual_groups':
+            $ids = GroupManager :: create_groups_from_virtual_courses();
+            $msg = urlencode(count($ids).' '.get_lang('GroupsAdded'));
+            header('Location: group.php?action=show_msg&msg='.$msg);
+            exit;
+            break;
+        case 'create_subgroups':
+            GroupManager :: create_subgroups($_POST['base_group'], $_POST['number_of_groups']);
+            $msg = urlencode($_POST['number_of_groups'].' '.get_lang('GroupsAdded'));
+            header('Location: group.php?action=show_msg&msg='.$msg);
+            exit;
+            break;
+        case 'create_class_groups':
+            $ids = GroupManager :: create_class_groups($_POST['group_category']);
+            $msg = urlencode(count($ids).' '.get_lang('GroupsAdded'));
+            header('Location: group.php?action=show_msg&msg='.$msg);
+            exit;
+            break;
+    }
 }
 
 $nameTools = get_lang('GroupCreation');
@@ -73,7 +77,7 @@ $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
 Display :: display_header($nameTools, 'Group');
 
 if (!api_is_allowed_to_edit(false, true)) {
-	api_not_allowed();
+    api_not_allowed();
 }
 
 /*	MAIN TOOL CODE */
@@ -81,53 +85,48 @@ if (!api_is_allowed_to_edit(false, true)) {
 /*	Show group-settings-form */
 
 elseif (isset($_POST['number_of_groups'])) {
-	if (!is_numeric($_POST['number_of_groups']) || intval($_POST['number_of_groups']) < 1) {
-		Display :: display_error_message(get_lang('PleaseEnterValidNumber').'<br /><br /><a href="group_creation.php?'.api_get_cidreq().'">&laquo; '.get_lang('Back').'</a>', false);
-	} else {
-		$number_of_groups = intval($_POST['number_of_groups']);
-		if ($number_of_groups > 1) {
-?>
-	<script type="text/javascript">
-	<!--
-	var number_of_groups = <?php echo $number_of_groups; ?>;
-	function switch_state(key)
-	{
-		for( i=1; i<number_of_groups; i++)
-		{
-			element = document.getElementById(key+'_'+i);
-			element.disabled = !element.disabled;
-			disabled = element.disabled;
-		}
-		ref = document.getElementById(key+'_0');
-		if( disabled )
-		{
-			ref.addEventListener("change", copy, false);
-		}
-		else
-		{
-			ref.removeEventListener("change", copy, false);
-		}
-		copy_value(key);
-	}
-	function copy(e)
-	{
-		key = e.currentTarget.id;
-		var re = new RegExp ('_0', '') ;
-		var key = key.replace(re, '') ;
-		copy_value(key);
-	}
-	function copy_value(key)
-	{
-		ref = document.getElementById(key+'_0');
-		for( i=1; i<number_of_groups; i++)
-		{
-			element = document.getElementById(key+'_'+i);
-			element.value = ref.value;
-		}
-	}
-	-->
-	</script>
-<?php
+    if (!is_numeric($_POST['number_of_groups']) || intval($_POST['number_of_groups']) < 1) {
+        Display :: display_error_message(get_lang('PleaseEnterValidNumber').'<br /><br /><a href="group_creation.php?'.api_get_cidreq().'">&laquo; '.get_lang('Back').'</a>', false);
+    } else {
+        $number_of_groups = intval($_POST['number_of_groups']);
+        if ($number_of_groups > 1) {
+    ?>
+    <script type="text/javascript">
+    <!--
+    var number_of_groups = <?php echo $number_of_groups; ?>;
+    function switch_state(key) {
+        for( i=1; i<number_of_groups; i++) {
+            element = document.getElementById(key+'_'+i);
+            element.disabled = !element.disabled;
+            disabled = element.disabled;
+        }
+        ref = document.getElementById(key+'_0');
+        if( disabled ) {
+            ref.addEventListener("change", copy, false);
+        } else {
+            ref.removeEventListener("change", copy, false);
+        }
+        copy_value(key);
+    }
+
+    function copy(e) {
+        key = e.currentTarget.id;
+        var re = new RegExp ('_0', '') ;
+        var key = key.replace(re, '') ;
+        copy_value(key);
+    }
+
+    function copy_value(key) {
+        ref = document.getElementById(key+'_0');
+        for( i=1; i<number_of_groups; i++)
+        {
+            element = document.getElementById(key+'_'+i);
+            element.value = ref.value;
+        }
+    }
+    -->
+    </script>
+    <?php
 		}
 		$group_categories = GroupManager :: get_categories();
 		$group_id = GroupManager :: get_number_of_groups() + 1;
@@ -323,8 +322,7 @@ EOT;
 		$create_class_groups_form->display();
 		echo '</blockquote>';
 	}
-
 }
 
 /*	FOOTER */
-Display :: display_footer();
+Display :: display_footer();

+ 104 - 93
main/group/group_edit.php

@@ -32,8 +32,8 @@ $interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidReq(), 'name'
 
 $is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), $group_id);
 
-if (!api_is_allowed_to_edit(false,true) && !$is_group_member) {
-	api_not_allowed(true);
+if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
+    api_not_allowed(true);
 }
 
 /*	FUNCTIONS */
@@ -41,69 +41,77 @@ if (!api_is_allowed_to_edit(false,true) && !$is_group_member) {
 /**
  *  List all users registered to the course
  */
-function search_members_keyword($firstname, $lastname, $username, $official_code, $keyword) {
-	if (api_strripos($firstname, $keyword) !== false || api_strripos($lastname, $keyword) !== false || api_strripos($username, $keyword) !== false || api_strripos($official_code, $keyword) !== false) {
-		return true;
-	} else {
-		return false;
-	}
+function search_members_keyword($firstname, $lastname, $username, $official_code, $keyword)
+{
+    if (api_strripos($firstname, $keyword) !== false ||
+        api_strripos($lastname, $keyword) !== false ||
+        api_strripos($username, $keyword) !== false ||
+        api_strripos($official_code, $keyword) !== false
+    ) {
+        return true;
+    } else {
+        return false;
+    }
 }
 
-
 /**
- * function to sort users after getting the list in the db. Necessary because there are 2 or 3 queries. Called by usort()
+ * Function to sort users after getting the list in the DB.
+ * Necessary because there are 2 or 3 queries. Called by usort()
  */
-function sort_users($user_a, $user_b) {
-	if (api_sort_by_first_name()) {
-		$cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
-		if ($cmp !== 0) {
-			return $cmp;
-		} else {
-			$cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
-			if ($cmp !== 0) {
-				return $cmp;
-			} else {
-				return api_strcmp($user_a['username'], $user_b['username']);
-			}
-		}
-	} else {
-		$cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
-		if ($cmp !== 0) {
-			return $cmp;
-		} else {
-			$cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
-			if ($cmp !== 0) {
-				return $cmp;
-			} else {
-				return api_strcmp($user_a['username'], $user_b['username']);
-			}
-		}
-	}
+function sort_users($user_a, $user_b)
+{
+    if (api_sort_by_first_name()) {
+        $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
+        if ($cmp !== 0) {
+            return $cmp;
+        } else {
+            $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
+            if ($cmp !== 0) {
+                return $cmp;
+            } else {
+                return api_strcmp($user_a['username'], $user_b['username']);
+            }
+        }
+    } else {
+        $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
+        if ($cmp !== 0) {
+            return $cmp;
+        } else {
+            $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
+            if ($cmp !== 0) {
+                return $cmp;
+            } else {
+                return api_strcmp($user_a['username'], $user_b['username']);
+            }
+        }
+    }
 }
 
 /**
  * Function to check the given max number of members per group
  */
-function check_max_number_of_members($value) {
-	$max_member_no_limit = $value['max_member_no_limit'];
-	if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
-		return true;
-	}
-	$max_member = $value['max_member'];
-	return is_numeric($max_member);
+function check_max_number_of_members($value)
+{
+    $max_member_no_limit = $value['max_member_no_limit'];
+    if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        return true;
+    }
+    $max_member = $value['max_member'];
+    return is_numeric($max_member);
 }
 
 /**
  * Function to check if the number of selected group members is valid
  */
-function check_group_members($value) {
-	if ($value['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
-		return true;
-	}
-	if (isset($value['max_member']) && isset($value['group_members']) && $value['max_member'] < count($value['group_members'])) {
-		return array ('group_members' => get_lang('GroupTooMuchMembers'));
-	}
-	return true;
+function check_group_members($value)
+{
+    if ($value['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        return true;
+    }
+    if (isset($value['max_member']) && isset($value['group_members']) && $value['max_member'] < count($value['group_members'])) {
+        return array ('group_members' => get_lang('GroupTooMuchMembers'));
+    }
+    return true;
 }
 
 /*	MAIN CODE */
@@ -130,8 +138,8 @@ $form->add_textfield('name', get_lang('GroupName'));
 $form->addElement('textarea', 'description', get_lang('Description'), array ('class' => 'span6', 'rows' => 6));
 
 $complete_user_list = GroupManager :: fill_groups_list($current_group['id']);
-
 usort($complete_user_list, 'sort_users');
+
 $possible_users = array();
 foreach ($complete_user_list as $index => $user) {
     $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
@@ -173,7 +181,7 @@ foreach ($group_member_list as $index => $user) {
 // possible : number_groups_left > 0 and is group member
 $possible_users = array();
 foreach ($complete_user_list as $index => $user) {
-     if ($user['number_groups_left'] > 0 || in_array($user['user_id'], $selected_users) )  {
+     if ($user['number_groups_left'] > 0 || in_array($user['user_id'], $selected_users)) {
         $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
      }
 }
@@ -206,9 +214,10 @@ $form->addGroup($group, 'max_member_group', null, '', false);
 $form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
 
 // Self registration
-$group = array();
-$group[] = $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1);
-$group[] = $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1);
+$group = array(
+    $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
+    $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1)
+);
 $form->addGroup($group, '', Display::return_icon('user.png', get_lang('GroupSelfRegistration') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupSelfRegistration'), '', false);
 
 // Documents settings
@@ -247,33 +256,35 @@ $group[] = $form->createElement('radio', 'forum_state', null, get_lang('Private'
 $form->addGroup($group, '', Display::return_icon('forum.png', get_lang('GroupForum') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupForum'), '', false);
 
 // Wiki settings
-$group = array();
-$group[] = $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
-$group[] = $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
-$group[] = $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
+$group = array(
+    $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
+    $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
+    $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
+);
 $form->addGroup($group, '', Display::return_icon('wiki.png', get_lang('GroupWiki') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupWiki'), '', false);
 
 // Chat settings
-$group = array();
-$group[] = $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
-$group[] = $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
-$group[] = $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
-$form->addGroup($group, '', Display::return_icon('chat.png', get_lang('Chat') , array(), ICON_SIZE_SMALL).' '.get_lang('Chat'), '', false);
+$group = array(
+    $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
+    $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
+    $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
+);
+$form->addGroup($group, '', Display::return_icon('chat.png', get_lang('Chat'), array(), ICON_SIZE_SMALL).' '.get_lang('Chat'), '', false);
 
 // submit button
 $form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"');
 
 if ($form->validate()) {
-	$values = $form->exportValues();
-	if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
-		$max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
-	} else {
-		$max_member = $values['max_member'];
-	}
-	$self_registration_allowed   = isset($values['self_registration_allowed']) ? 1 : 0;
-	$self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
-
-	GroupManager::set_group_properties(
+    $values = $form->exportValues();
+    if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
+    } else {
+        $max_member = $values['max_member'];
+    }
+    $self_registration_allowed   = isset($values['self_registration_allowed']) ? 1 : 0;
+    $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
+
+    GroupManager::set_group_properties(
         $current_group['id'],
         strip_tags($values['name']),
         strip_tags($values['description']),
@@ -289,20 +300,20 @@ if ($form->validate()) {
         $self_unregistration_allowed
     );
 
-	// Storing the tutors (we first remove all the tutors and then add only those who were selected)
-	GroupManager :: unsubscribe_all_tutors($current_group['id']);
-	if (isset ($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
-		GroupManager :: subscribe_tutors($values['group_tutors'], $current_group['id']);
-	}
+    // Storing the tutors (we first remove all the tutors and then add only those who were selected)
+    GroupManager :: unsubscribe_all_tutors($current_group['id']);
+    if (isset ($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
+        GroupManager :: subscribe_tutors($values['group_tutors'], $current_group['id']);
+    }
 
-	// Storing the users (we first remove all users and then add only those who were selected)
-	GroupManager :: unsubscribe_all_users($current_group['id']);
-	if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) {
-		GroupManager :: subscribe_users($values['group_members'], $current_group['id']);
-	}
+    // Storing the users (we first remove all users and then add only those who were selected)
+    GroupManager :: unsubscribe_all_users($current_group['id']);
+    if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) {
+        GroupManager :: subscribe_users($values['group_members'], $current_group['id']);
+    }
 
-	// Returning to the group area (note: this is inconsistent with the rest of chamilo)
-	$cat = GroupManager :: get_category_from_group($current_group['id']);
+    // Returning to the group area (note: this is inconsistent with the rest of chamilo)
+    $cat = GroupManager :: get_category_from_group($current_group['id']);
     if (isset($_POST['group_members']) && count($_POST['group_members']) > $max_member && $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
         header('Location: group.php?'.api_get_cidreq(true, false).'&action=warning_message&msg='.get_lang('GroupTooMuchMembers'));
     } else {
@@ -317,22 +328,22 @@ $defaults['group_tutors'] = $selected_tutors;
 $action = isset($_GET['action']) ? $_GET['action'] : '';
 $defaults['action'] = $action;
 if ($defaults['maximum_number_of_students'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
-	$defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
+    $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
 } else {
-	$defaults['max_member_no_limit'] = 1;
-	$defaults['max_member'] = $defaults['maximum_number_of_students'];
+    $defaults['max_member_no_limit'] = 1;
+    $defaults['max_member'] = $defaults['maximum_number_of_students'];
 }
 
 if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
-	$keyword_name = Security::remove_XSS($_GET['keyword']);
-	echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
+    $keyword_name = Security::remove_XSS($_GET['keyword']);
+    echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
 }
 
 Display :: display_header($nameTools, 'Group');
 
 //@todo fix this
 if (isset($_GET['show_message_warning'])) {
-	echo Display::display_warning_message($_GET['show_message_warning']);
+    echo Display::display_warning_message($_GET['show_message_warning']);
 }
 
 if (isset($_GET['show_message_sucess'])) {

+ 97 - 78
main/group/group_overview.php

@@ -17,9 +17,9 @@
  */
 
 // Name of the language file that needs to be included
-$language_file = 'group';
+$language_file = array('group', 'admin');
 
-require '../inc/global.inc.php';
+require_once '../inc/global.inc.php';
 $this_section = SECTION_COURSES;
 $current_course_tool  = TOOL_GROUP;
 
@@ -27,106 +27,125 @@ $current_course_tool  = TOOL_GROUP;
 api_protect_course_script(true);
 
 $nameTools = get_lang('GroupOverview');
+$courseId = api_get_course_int_id();
+$courseInfo = api_get_course_info();
 
 /*	Libraries */
-
 include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
 include_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
 
+$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : null;
+
 if (isset($_GET['action'])) {
-	switch ($_GET['action']) {
-		case 'export':
-			$groups = GroupManager::get_group_list();
-			$data = array();
-			foreach ($groups as $index => $group) {
-				$users = GroupManager::get_users($group['id']);
-				foreach ($users as $index => $user) {
-					$row = array();
-					$user = api_get_user_info($user);
-					$row[] = $group['name'];
-					$row[] = $user['official_code'];
-					$row[] = $user['lastName'];
-					$row[] = $user['firstName'];
-					$data[] = $row;
-				}
-			}
-			switch ($_GET['type']) {
-				case 'csv':
-					Export::export_table_csv($data);
-					exit;
-				case 'xls':
-					Export::export_table_xls($data);
-					exit;
-			}
-			break;
+    switch ($_GET['action']) {
+        case 'export_all':
+            $data = GroupManager::exportCategoriesAndGroupsToArray();
+            Export::export_table_csv($data);
+            exit;
+            break;
+        case 'export_pdf':
+            $content = GroupManager::getOverview($courseId, $keyword);
+            $pdf = new PDF();
+            $extra = '<div style="text-align:center"><h2>'.get_lang('GroupList').'</h2></div>';
+            $extra .= '<strong>'.get_lang('Course').': </strong>'.$courseInfo['title'].' ('.$courseInfo['code'].')';
+
+            $content = $extra.$content;
+            $pdf->content_to_pdf($content, null, null, api_get_course_id());
+            break;
+        case 'export':
+            $groupId = isset($_GET['id']) ? intval($_GET['id']) : null;
+            $groups = GroupManager::get_group_list();
+
+            $data = array();
+            foreach ($groups as $index => $group) {
+                if (!empty($groupId)) {
+                    if ($group['id'] != $groupId) {
+                        continue;
+                    }
+                }
+                $users = GroupManager::get_users($group['id']);
+                foreach ($users as $index => $user) {
+                    $row = array();
+                    $user = api_get_user_info($user);
+                    $row[] = $group['name'];
+                    $row[] = $user['official_code'];
+                    $row[] = $user['lastName'];
+                    $row[] = $user['firstName'];
+                    $data[] = $row;
+                }
+            }
+            switch ($_GET['type']) {
+                case 'csv':
+                    Export::export_table_csv($data);
+                    exit;
+                    break;
+                case 'xls':
+                    if (!empty($data)) {
+                        Export::export_table_xls($data);
+                        exit;
+                    }
+                    break;
+            }
+            break;
 	}
 }
 
 /*	Header */
 
+
 $interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups'));
 if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
-	// So we are not in learnpath tool
-	if (!$is_allowed_in_course) {
-		api_not_allowed(true);
-	}
-	if (!api_is_allowed_to_edit(false, true)) {
-		api_not_allowed(true);
-	} else {
-		Display::display_header($nameTools, 'Group');
-	}
+    // So we are not in learnpath tool
+    if (!$is_allowed_in_course) {
+        api_not_allowed(true);
+    }
+    if (!api_is_allowed_to_edit(false, true)) {
+        api_not_allowed(true);
+    } else {
+        Display::display_header($nameTools, 'Group');
+        // Tool introduction
+        Display::display_introduction_section(TOOL_GROUP);
+    }
 } else {
 ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CSS_PATH); ?>default.css" /> <?php
 }
 
 // Action links
 echo '<div class="actions">';
-    echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).'</a>';
-    echo '<a href="group.php?'.api_get_cidreq().'">'.Display::return_icon('group.png', get_lang('Groups'),'',ICON_SIZE_MEDIUM).'</a>';
+    echo '<a href="group_creation.php?'.api_get_cidreq().'">'.
+        Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
+
     if (api_get_setting('allow_group_categories') == 'true') {
-    	echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.Display::return_icon('new_folder.png', get_lang('AddCategory'),'',ICON_SIZE_MEDIUM).'</a>';
+        echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
+            Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
     } else {
-    	//echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('edit_group.gif').'&nbsp;'.get_lang('PropModify').'</a>&nbsp;';
-    	echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).'</a>';
+        echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
+            Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
     }
-    //echo Display::return_icon('csv.gif', get_lang('ExportAsCSV')).'<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=csv">'.get_lang('ExportAsCSV').'</a> ';
-    echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a>';
-echo '</div>';
+    echo  '<a href="import.php?'.api_get_cidreq().'&action=import">'.
+        Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
 
-$categories = GroupManager::get_categories();
+    echo  '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
+        Display::return_icon('export_csv.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
 
-foreach ($categories as $index => $category) {
-	if (api_get_setting('allow_group_categories') == 'true') {
-		echo '<h2>'.$category['title'].'</h2>';
-	}
-	$groups = GroupManager::get_group_list($category['id']);
-    echo '<ul>';
-	if (!empty($groups)) {    	
-    	foreach ($groups as $index => $group) {
-    		echo '<li>';
-        		echo Display::tag('h3', Security::remove_XSS($group['name']));
-        		echo '<ul>';
-        		$users = GroupManager::get_users($group['id']);
-                if (!empty($users)) {
-            		foreach ($users as $index => $user) {
-            			$user_info = api_get_user_info($user);
-            			$username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
-            			echo '<li title="'.$username.'">'.api_get_person_name($user_info['firstName'], $user_info['lastName']).'</li>';
-            		}            	
-                } else {
-                    //echo Display::tag('li', get_lang('NoStudents'));            
-                }
-                echo '</ul>';
-    		echo '</li>';
-    	}    	
-    } else {        
-        //echo Display::tag('li', get_lang('NoData'));   
-    }    
-    echo '</ul>';
-}
+    echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.
+    Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
+
+   echo  '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
+        Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
 
-/*	FOOTER */
+    echo '<a href="group.php?'.api_get_cidreq().'">'.
+        Display::return_icon('group.png', get_lang('Groups'),'',ICON_SIZE_MEDIUM).'</a>';
+
+
+    echo '<a href="../user/user.php?'.api_get_cidreq().'">'.
+    Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>';
+
+    echo GroupManager::getSearchForm();
+echo '</div>';
+
+echo GroupManager::getOverview($courseId, $keyword);
 
 if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
-	Display::display_footer();
-}
+    Display::display_footer();
+}

+ 50 - 43
main/group/group_space.php

@@ -74,16 +74,16 @@ Display::display_introduction_section(TOOL_GROUP);
  * User wants to register in this group
  */
 if (!empty($_GET['selfReg']) && GroupManager :: is_self_registration_allowed($user_id, $current_group['id'])) {
-	GroupManager :: subscribe_users($user_id, $current_group['id']);
-	Display :: display_normal_message(get_lang('GroupNowMember'));
+    GroupManager :: subscribe_users($user_id, $current_group['id']);
+    Display :: display_normal_message(get_lang('GroupNowMember'));
 }
 
 /*
  * User wants to unregister from this group
  */
 if (!empty($_GET['selfUnReg']) && GroupManager :: is_self_unregistration_allowed($user_id, $current_group['id'])) {
-	GroupManager :: unsubscribe_users($user_id, $current_group['id']);
-	Display::display_normal_message(get_lang('StudentDeletesHimself'));
+    GroupManager :: unsubscribe_users($user_id, $current_group['id']);
+    Display::display_normal_message(get_lang('StudentDeletesHimself'));
 }
 echo '<div class="actions">';
 echo '<a href="group.php">'.Display::return_icon('back.png',get_lang('BackToGroupList'),'',ICON_SIZE_MEDIUM).'</a>';
@@ -124,10 +124,13 @@ $is_course_member = CourseManager :: is_user_subscribed_in_real_or_linked_course
 $edit_url = '';
 if (api_is_allowed_to_edit(false, true) or GroupManager :: is_tutor_of_group(api_get_user_id(), api_get_group_id())) {
     $my_origin = isset($origin) ? $origin : '';
-    $edit_url =  '<a href="group_edit.php?cidReq='.  api_get_course_id().'&origin='.$my_origin.'&gidReq='.api_get_group_id().'">'.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
+    $edit_url =  '<a href="'.api_get_path(WEB_CODE_PATH).'group/settings.php?cidReq='.api_get_course_id().'&origin='.$my_origin.'&gidReq='.api_get_group_id().'">'.
+        Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
 }
 
-echo Display::page_header(Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group);
+echo Display::page_header(
+    Security::remove_XSS($current_group['name']).' '.$edit_url.' '.$subscribe_group.' '.$unsubscribe_group
+);
 
 if (!empty($current_group['description'])) {
 	echo '<p>'.Security::remove_XSS($current_group['description']).'</p>';
@@ -138,9 +141,9 @@ if (!empty($current_group['description'])) {
  */
 // If the user is subscribed to the group or the user is a tutor of the group then
 if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group(api_get_user_id(), $current_group['id'])) {
-	$actions_array = array();
-	// Link to the forum of this group
-	$forums_of_groups = get_forums_of_group($current_group['id']);
+    $actions_array = array();
+    // Link to the forum of this group
+    $forums_of_groups = get_forums_of_group($current_group['id']);
 
 	if (is_array($forums_of_groups)) {
 		if ($current_group['forum_state'] != GroupManager::TOOL_NOT_AVAILABLE ) {
@@ -157,51 +160,51 @@ if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group(api_
 	if ($current_group['doc_state'] != GroupManager::TOOL_NOT_AVAILABLE ) {
 		// Link to the documents area of this group
         $actions_array[] = array(
-                        'url' => '../document/document.php?'.api_get_cidreq(),
-                        'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32)
-                     );
+            'url' => '../document/document.php?'.api_get_cidreq(),
+            'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), 32)
+        );
 	}
 	if ($current_group['calendar_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
 		// Link to a group-specific part of agenda
         $actions_array[] = array(
-                        'url' => '../calendar/agenda.php?'.api_get_cidreq(),
-                        'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32)
+            'url' => '../calendar/agenda.php?'.api_get_cidreq(),
+            'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), 32)
         );
 	}
 	if ($current_group['work_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
 		// Link to the works area of this group
 		 $actions_array[] = array(
-                        'url' => '../work/work.php?'.api_get_cidreq(),
-                        'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), 32)
+            'url' => '../work/work.php?'.api_get_cidreq(),
+            'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), 32)
          );
 
 	}
 	if ($current_group['announcements_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
 		// Link to a group-specific part of announcements
         $actions_array[] = array(
-                        'url' => '../announcements/announcements.php?'.api_get_cidreq(),
-                        'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32)
+            'url' => '../announcements/announcements.php?'.api_get_cidreq(),
+            'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), 32)
         );
 	}
 
 	if ($current_group['wiki_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
 		// Link to the wiki area of this group
         $actions_array[] = array(
-                        'url' => '../wiki/index.php?'.api_get_cidreq().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'],
-                        'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
+            'url' => '../wiki/index.php?'.api_get_cidreq().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'],
+            'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
         );
 	}
 	if ($current_group['chat_state'] != GroupManager::TOOL_NOT_AVAILABLE) {
 		// Link to the chat area of this group
 		if (api_get_course_setting('allow_open_chat_window')) {
             $actions_array[] = array(
-                        'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"",
-                        'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
+                'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"",
+                'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
             );
 		} else {
             $actions_array[] = array(
-                        'url' => "../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id'],
-                        'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
+                'url' => "../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id'],
+                'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
             );
 		}
 	}
@@ -230,50 +233,50 @@ if (api_is_allowed_to_edit(false, true) OR GroupManager :: is_user_in_group(api_
 	if ($current_group['doc_state'] == GroupManager::TOOL_PUBLIC) {
 		// Link to the documents area of this group
         $actions_array[] = array(
-                        'url' => '../document/document.php?cidReq='.api_get_course_id().'&amp;origin='.$origin,
-                        'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_MEDIUM)
+            'url' => '../document/document.php?cidReq='.api_get_course_id().'&amp;origin='.$origin,
+            'content' => Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_MEDIUM)
         );
 	}
 	if ($current_group['calendar_state'] == GroupManager::TOOL_PUBLIC) {
 		// Link to a group-specific part of agenda
         $actions_array[] = array(
-                        'url' => '../calendar/agenda.php?'.api_get_cidreq(),
-                        'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_MEDIUM)
+            'url' => '../calendar/agenda.php?'.api_get_cidreq(),
+            'content' => Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_MEDIUM)
         );
 
 	}
 	if ($current_group['work_state'] == GroupManager::TOOL_PUBLIC) {
 		// Link to the works area of this group
 		$actions_array[] = array(
-                        'url' => '../work/work.php?'.api_get_cidreq(),
-                        'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_MEDIUM)
+            'url' => '../work/work.php?'.api_get_cidreq(),
+            'content' => Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_MEDIUM)
          );
 	}
 	if ($current_group['announcements_state'] == GroupManager::TOOL_PUBLIC) {
 		// Link to a group-specific part of announcements
 		$actions_array[] = array(
-                        'url' => '../announcements/announcements.php?'.api_get_cidreq(),
-                        'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_MEDIUM)
+            'url' => '../announcements/announcements.php?'.api_get_cidreq(),
+            'content' => Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_MEDIUM)
         );
 	}
 	if ($current_group['wiki_state'] == GroupManager::TOOL_PUBLIC) {
 		// Link to the wiki area of this group
 		$actions_array[] = array(
-                        'url' => '../wiki/index.php?'.api_get_cidreq().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'],
-                        'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
+            'url' => '../wiki/index.php?'.api_get_cidreq().'&amp;action=show&amp;title=index&amp;session_id='.api_get_session_id().'&amp;group_id='.$current_group['id'],
+            'content' => Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), 32)
         );
 	}
 	if ($current_group['chat_state'] == GroupManager::TOOL_PUBLIC ) {
 		// Link to the chat area of this group
 		if (api_get_course_setting('allow_open_chat_window')) {
             $actions_array[] = array(
-                        'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"",
-                        'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
+                'url' => "javascript: void(0);\" onclick=\"window.open('../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id']."','window_chat_group_".$_SESSION['_cid']."_".$_SESSION['_gid']."','height=380, width=625, left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no') \"",
+                'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
             );
 		} else {
             $actions_array[] = array(
-                        'url' => "../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id'],
-                        'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
+                'url' => "../chat/chat.php?".api_get_cidreq()."&amp;toolgroup=".$current_group['id'],
+                'content' => Display::return_icon('chat.png', get_lang('Chat'), array(), 32)
             );
 		}
 	}
@@ -291,16 +294,20 @@ $tutor_info = '';
 if (count($tutors) == 0) {
 	$tutor_info = get_lang('GroupNoneMasc');
 } else {
-	isset($origin)?$my_origin = $origin:$my_origin='';
-	foreach($tutors as $index => $tutor) {
+	isset($origin) ? $my_origin = $origin:$my_origin='';
+    $tutor_info .= '<ul class="thumbnails">';
+	foreach ($tutors as $index => $tutor) {
 	    $tab_user_info = Database::get_user_info_from_id($tutor['user_id']);
 	    $username = api_htmlentities(sprintf(get_lang('LoginX'), $tab_user_info['username']), ENT_QUOTES);
 		$image_path = UserManager::get_user_picture_path_by_id($tutor['user_id'], 'web', false, true);
 		$image_repository = $image_path['dir'];
 		$existing_image = $image_path['file'];
-		$photo= '<img src="'.$image_repository.$existing_image.'" align="absbottom" alt="'.api_get_person_name($tutor['firstname'], $tutor['lastname']).'" width="32" height="32" title="'.api_get_person_name($tutor['firstname'], $tutor['lastname']).'" />';
-		$tutor_info .= '<a href="../user/userInfo.php?origin='.$my_origin.'&amp;uInfo='.$tutor['user_id'].'">'.$photo.'&nbsp;'.Display::tag('span', api_get_person_name($tutor['firstname'], $tutor['lastname']), array('title'=>$username)).'</a>';
+        $completeName = api_get_person_name($tutor['firstname'], $tutor['lastname']);
+		$photo = '<img src="'.$image_repository.$existing_image.'" alt="'.$completeName.'" width="32" height="32" title="'.$completeName.'" />';
+		$tutor_info .= '<li><a href="'.api_get_path(WEB_CODE_PATH).'user/userInfo.php?origin='.$my_origin.'&amp;uInfo='.$tutor['user_id'].'">'.
+            $photo.'&nbsp;'.$completeName.'</a></li>';
 	}
+    $tutor_info .= '</ul>';
 }
 
 echo Display::page_subheader(get_lang('GroupTutors'));
@@ -473,6 +480,7 @@ function user_icon_filter($user_id) {
 	$photo = '<center><img src="'.$image_repository.$existing_image.'" alt="'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'"  width="22" height="22" title="'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'" /></center>';
 	return '<a href="../user/userInfo.php?origin='.$origin.'&amp;uInfo='.$user_id.'">'.$photo;
 }
+
 /**
  * Return user profile link around the given user name.
  *
@@ -484,7 +492,6 @@ function user_icon_filter($user_id) {
  * @return  string  HTML link
  */
 function user_name_filter($name, $url_params, $row) {
-    global $origin;
     $tab_user_info = Database::get_user_info_from_id($row[0]);
     $username = api_htmlentities(sprintf(get_lang('LoginX'), $tab_user_info['username']), ENT_QUOTES);
     return '<a href="../user/userInfo.php?uInfo='.$row[0].'&amp;'.$url_params.'" title="'.$username.'">'.$name.'</a>';

+ 71 - 0
main/group/import.php

@@ -0,0 +1,71 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+// Name of the language file that needs to be included
+$language_file = 'group';
+
+require_once '../inc/global.inc.php';
+$this_section = SECTION_COURSES;
+$current_course_tool  = TOOL_GROUP;
+
+// Notice for unauthorized people.
+api_protect_course_script(true);
+
+if (!api_is_allowed_to_edit(false, true)) {
+    api_not_allowed(true);
+}
+
+$nameTools = get_lang('Import');
+
+/*	Libraries */
+
+include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
+include_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
+
+$interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups'));
+
+Display::display_header($nameTools, 'Group');
+
+$form = new FormValidator('import', 'post', api_get_self().'?'.api_get_cidreq());
+$form->addElement('header', get_lang('ImportGroups'));
+$form->addElement('file', 'file', get_lang('File'));
+$form->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
+$form->addElement('checkbox', 'delete_not_in_file', null, get_lang('DeleteItemsNotInFile'));
+$form->addElement('button', 'submit', get_lang('Import'));
+
+if ($form->validate()) {
+    if (isset($_FILES['file']['tmp_name']) && !empty($_FILES['file']['tmp_name'])) {
+        $groupData = Import::csv_reader($_FILES['file']['tmp_name']);
+        $deleteNotInArray = $form->getSubmitValue('delete_not_in_file') == 1 ? true : false;
+
+        $result = GroupManager::importCategoriesAndGroupsFromArray($groupData, $deleteNotInArray);
+        if (!empty($result)) {
+            $html = null;
+            foreach ($result as $status => $data) {
+
+                if (empty($data['category']) && empty($data['group'])) {
+                    continue;
+                }
+
+                $html .= " <h3>".get_lang(ucfirst($status)).' </h3>';
+                if (!empty($data['category'])) {
+                    $html .= "<h4> ".get_lang('Categories').':</h4>';
+                    foreach ($data['category'] as $category) {
+                        $html .= "<div>".$category['category']."</div>";
+                    }
+                }
+
+                if (!empty($data['group'])) {
+                    $html .= "<h4> ".get_lang('Groups').':</h4>';
+                    foreach ($data['group'] as $group) {
+                        $html .= "<div>".$group['group']."</div>";
+                    }
+                }
+            }
+            echo $html;
+        }
+    }
+}
+$form->display();
+
+Display::display_footer();

+ 222 - 0
main/group/member_settings.php

@@ -0,0 +1,222 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ *	This script displays an area where teachers can edit the group properties and member list.
+ *	Groups are also often called "teams" in the Dokeos code.
+ *
+ *	@author various contributors
+ *	@author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
+ *	@package chamilo.group
+ *	@todo course admin functionality to create groups based on who is in which course (or class).
+ */
+
+/*	INIT SECTION */
+
+// Name of the language file that needs to be included
+$language_file = 'group';
+
+require_once '../inc/global.inc.php';
+$this_section = SECTION_COURSES;
+$current_course_tool  = TOOL_GROUP;
+
+// Notice for unauthorized people.
+api_protect_course_script(true);
+
+$group_id = api_get_group_id();
+$current_group = GroupManager::get_group_properties($group_id);
+
+$nameTools = get_lang('EditGroup');
+$interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
+$interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidReq(), 'name' => $current_group['name']);
+
+$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
+
+if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
+    api_not_allowed(true);
+}
+
+/*	FUNCTIONS */
+
+/**
+ *  List all users registered to the course
+ */
+function search_members_keyword($firstname, $lastname, $username, $official_code, $keyword)
+{
+    if (api_strripos($firstname, $keyword) !== false ||
+        api_strripos($lastname, $keyword) !== false ||
+        api_strripos($username, $keyword) !== false ||
+        api_strripos($official_code, $keyword) !== false
+    ) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
+/**
+ * Function to sort users after getting the list in the DB.
+ * Necessary because there are 2 or 3 queries. Called by usort()
+ */
+function sort_users($user_a, $user_b)
+{
+    if (api_sort_by_first_name()) {
+        $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
+        if ($cmp !== 0) {
+            return $cmp;
+        } else {
+            $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
+            if ($cmp !== 0) {
+                return $cmp;
+            } else {
+                return api_strcmp($user_a['username'], $user_b['username']);
+            }
+        }
+    } else {
+        $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
+        if ($cmp !== 0) {
+            return $cmp;
+        } else {
+            $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
+            if ($cmp !== 0) {
+                return $cmp;
+            } else {
+                return api_strcmp($user_a['username'], $user_b['username']);
+            }
+        }
+    }
+}
+
+/**
+ * Function to check if the number of selected group members is valid
+ */
+function check_group_members($value)
+{
+    if ($value['max_student'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        return true;
+    }
+    if (isset($value['max_student']) && isset($value['group_members']) && $value['max_student'] < count($value['group_members'])) {
+        return array('group_members' => get_lang('GroupTooMuchMembers'));
+    }
+    return true;
+}
+
+/*	MAIN CODE */
+
+$htmlHeadXtra[] = '<script>
+$(document).ready( function() {
+    $("#max_member").on("focus", function() {
+        $("#max_member_selected").attr("checked", true);
+    });
+});
+ </script>';
+
+// Build form
+$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
+$form->addElement('hidden', 'action');
+$form->addElement('hidden', 'max_student', $current_group['max_student']);
+$complete_user_list = GroupManager::fill_groups_list($current_group['id']);
+usort($complete_user_list, 'sort_users');
+$possible_users = array();
+foreach ($complete_user_list as $index => $user) {
+    $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
+}
+
+// Group members
+$group_member_list = GroupManager :: get_subscribed_users($current_group['id']);
+
+$selected_users = array ();
+foreach ($group_member_list as $index => $user) {
+    $selected_users[] = $user['user_id'];
+}
+
+// possible : number_groups_left > 0 and is group member
+$possible_users = array();
+foreach ($complete_user_list as $index => $user) {
+    if ($user['number_groups_left'] > 0 || in_array($user['user_id'], $selected_users)) {
+        $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
+    }
+}
+
+$group_members_element = $form->addElement('advmultiselect', 'group_members', get_lang('GroupMembers'), $possible_users, 'style="width: 280px;"');
+
+$group_members_element->setElementTemplate('
+{javascript}
+<table{class}>
+<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
+<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
+<tr>
+  <td valign="top">{unselected}</td>
+  <td align="center">{add}<br /><br />{remove}</td>
+  <td valign="top">{selected}</td>
+</tr>
+</table>');
+
+$group_members_element->setButtonAttributes('add', array('class' => 'btn arrowr'));
+$group_members_element->setButtonAttributes('remove', array('class' => 'btn arrowl'));
+$form->addFormRule('check_group_members');
+
+/*$url = '<a class="btn btn-danger" href="'.api_get_self().'?'.api_get_cidreq(true, false).'&action=empty&amp;id='.$group_id.'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('EmptyGroup').'">'.
+    get_lang('EmptyGroup').'</a>&nbsp;';
+$form->addElement('label', null, $url);*/
+// submit button
+$form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"');
+
+if ($form->validate()) {
+    $values = $form->exportValues();
+
+    // Storing the users (we first remove all users and then add only those who were selected)
+    GroupManager :: unsubscribe_all_users($current_group['id']);
+    if (isset ($_POST['group_members']) && count($_POST['group_members']) > 0) {
+        GroupManager :: subscribe_users($values['group_members'], $current_group['id']);
+    }
+
+    // Returning to the group area (note: this is inconsistent with the rest of chamilo)
+    $cat = GroupManager :: get_category_from_group($current_group['id']);
+    if (isset($_POST['group_members']) && count($_POST['group_members']) > $max_member && $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        header('Location: group.php?'.api_get_cidreq(true, false).'&action=warning_message&msg='.get_lang('GroupTooMuchMembers'));
+    } else {
+        header('Location: group.php?'.api_get_cidreq(true, false).'&action=success_message&msg='.get_lang('GroupSettingsModified').'&category='.$cat['id']);
+    }
+    exit;
+}
+
+$action = isset($_GET['action']) ? $_GET['action'] : null;
+switch ($action) {
+    case 'empty':
+        if (api_is_allowed_to_edit(false, true)) {
+            GroupManager :: unsubscribe_all_users($group_id);
+            Display :: display_confirmation_message(get_lang('GroupEmptied'));
+        }
+        break;
+
+}
+
+
+$defaults = $current_group;
+$defaults['group_members'] = $selected_users;
+$action = isset($_GET['action']) ? $_GET['action'] : '';
+$defaults['action'] = $action;
+
+if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
+    $keyword_name = Security::remove_XSS($_GET['keyword']);
+    echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
+}
+
+Display :: display_header($nameTools, 'Group');
+
+//@todo fix this
+if (isset($_GET['show_message_warning'])) {
+    echo Display::display_warning_message($_GET['show_message_warning']);
+}
+
+if (isset($_GET['show_message_sucess'])) {
+    echo Display::display_normal_message($_GET['show_message_sucess']);
+}
+
+$form->setDefaults($defaults);
+echo GroupManager::getSettingBar('member');
+
+$form->display();
+
+Display :: display_footer();

+ 194 - 0
main/group/settings.php

@@ -0,0 +1,194 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ *	This script displays an area where teachers can edit the group properties and member list.
+ *	Groups are also often called "teams" in the Dokeos code.
+ *
+ *	@author various contributors
+ *	@author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
+ *	@package chamilo.group
+ *	@todo course admin functionality to create groups based on who is in which course (or class).
+ */
+
+/*	INIT SECTION */
+
+// Name of the language file that needs to be included
+$language_file = 'group';
+
+require_once '../inc/global.inc.php';
+$this_section = SECTION_COURSES;
+$current_course_tool  = TOOL_GROUP;
+
+// Notice for unauthorized people.
+api_protect_course_script(true);
+
+$group_id = api_get_group_id();
+$current_group = GroupManager :: get_group_properties($group_id);
+
+$nameTools = get_lang('EditGroup');
+$interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
+$interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidReq(), 'name' => $current_group['name']);
+
+$is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), $group_id);
+
+if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
+    api_not_allowed(true);
+}
+
+// Build form
+$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
+$form->addElement('hidden', 'action');
+
+// Group name
+$form->addElement('text', 'name', get_lang('GroupName'));
+
+// Description
+$form->addElement('textarea', 'description', get_lang('Description'), array ('class' => 'span6', 'rows' => 6));
+
+// Members per group
+$group = array(
+    $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT),
+    $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, array('id' => 'max_member_selected')),
+    $form->createElement('text', 'max_member', null, array('class' => 'span1', 'id' => 'max_member')),
+    $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis'))
+);
+$form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), '', false);
+$form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
+
+$form->addElement('html', '<div class="span6">');
+
+// Self registration
+$group = array(
+    $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
+    $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1)
+);
+$form->addGroup($group, '', Display::return_icon('user.png', get_lang('GroupSelfRegistration') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupSelfRegistration'), '', false);
+
+// Documents settings
+$group = array();
+$group[] = $form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
+$group[] = $form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
+$group[] = $form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
+$form->addGroup($group, '', Display::return_icon('folder.png', get_lang('GroupDocument') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupDocument'), '', false);
+
+// Work settings
+$group = array();
+$group[] = $form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
+$group[] = $form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
+$group[] = $form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
+$form->addGroup($group, '', Display::return_icon('work.png', get_lang('GroupWork') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupWork'), '', false);
+
+// Calendar settings
+$group = array();
+$group[] = $form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
+$group[] = $form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
+$group[] = $form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
+$form->addGroup($group, '', Display::return_icon('agenda.png', get_lang('GroupCalendar') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupCalendar'), '', false);
+
+$form->addElement('html', '</div>');
+$form->addElement('html', '<div class="span6">');
+
+// Announcements settings
+$group = array();
+$group[] = $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
+$group[] = $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
+$group[] = $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
+$form->addGroup($group, '', Display::return_icon('announce.png', get_lang('GroupAnnouncements') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupAnnouncements'), '', false);
+
+//Forum settings
+$group = array();
+$group[] = $form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
+$group[] = $form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
+$group[] = $form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
+$form->addGroup($group, '', Display::return_icon('forum.png', get_lang('GroupForum') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupForum'), '', false);
+
+// Wiki settings
+$group = array(
+    $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
+    $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
+    $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
+);
+$form->addGroup($group, '', Display::return_icon('wiki.png', get_lang('GroupWiki') , array(), ICON_SIZE_SMALL).' '.get_lang('GroupWiki'), '', false);
+
+// Chat settings
+$group = array(
+    $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
+    $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
+    $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
+);
+$form->addGroup($group, '', Display::return_icon('chat.png', get_lang('Chat'), array(), ICON_SIZE_SMALL).' '.get_lang('Chat'), '', false);
+
+$form->addElement('html', '</div>');
+
+$form->addElement('html', '<div class="span12">');
+// Submit button
+$form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"');
+$form->addElement('html', '</div>');
+
+if ($form->validate()) {
+    $values = $form->exportValues();
+    if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
+    } else {
+        $max_member = $values['max_member'];
+    }
+    $self_registration_allowed   = isset($values['self_registration_allowed']) ? 1 : 0;
+    $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
+
+    GroupManager::set_group_properties(
+        $current_group['id'],
+        strip_tags($values['name']),
+        strip_tags($values['description']),
+        $max_member,
+        $values['doc_state'],
+        $values['work_state'],
+        $values['calendar_state'],
+        $values['announcements_state'],
+        $values['forum_state'],
+        $values['wiki_state'],
+        $values['chat_state'],
+        $self_registration_allowed,
+        $self_unregistration_allowed
+    );
+    if (isset($_POST['group_members']) && count($_POST['group_members']) > $max_member && $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        header('Location: group.php?'.api_get_cidreq(true, false).'&action=warning_message&msg='.get_lang('GroupTooMuchMembers'));
+    } else {
+        header('Location: group.php?'.api_get_cidreq(true, false).'&action=success_message&msg='.get_lang('GroupSettingsModified').'&category='.$cat['id']);
+    }
+    exit;
+}
+
+$defaults = $current_group;
+$action = isset($_GET['action']) ? $_GET['action'] : '';
+$defaults['action'] = $action;
+if ($defaults['maximum_number_of_students'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+    $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
+} else {
+    $defaults['max_member_no_limit'] = 1;
+    $defaults['max_member'] = $defaults['maximum_number_of_students'];
+}
+
+if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
+    $keyword_name = Security::remove_XSS($_GET['keyword']);
+    echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
+}
+
+Display :: display_header($nameTools, 'Group');
+
+//@todo fix this
+if (isset($_GET['show_message_warning'])) {
+    echo Display::display_warning_message($_GET['show_message_warning']);
+}
+
+if (isset($_GET['show_message_sucess'])) {
+    echo Display::display_normal_message($_GET['show_message_sucess']);
+}
+
+$form->setDefaults($defaults);
+echo GroupManager::getSettingBar('settings');
+echo '<div class="row">';
+$form->display();
+echo '</div>';
+
+Display :: display_footer();

+ 185 - 0
main/group/tutor_settings.php

@@ -0,0 +1,185 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ *	This script displays an area where teachers can edit the group properties and member list.
+ *	Groups are also often called "teams" in the Dokeos code.
+ *
+ *	@author various contributors
+ *	@author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
+ *	@package chamilo.group
+ *	@todo course admin functionality to create groups based on who is in which course (or class).
+ */
+
+/*	INIT SECTION */
+
+// Name of the language file that needs to be included
+$language_file = 'group';
+
+require_once '../inc/global.inc.php';
+$this_section = SECTION_COURSES;
+$current_course_tool  = TOOL_GROUP;
+
+// Notice for unauthorized people.
+api_protect_course_script(true);
+
+$group_id = api_get_group_id();
+$current_group = GroupManager :: get_group_properties($group_id);
+
+$nameTools = get_lang('EditGroup');
+$interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
+$interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidReq(), 'name' => $current_group['name']);
+
+$is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), $group_id);
+
+if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
+    api_not_allowed(true);
+}
+
+/*	FUNCTIONS */
+
+/**
+ *  List all users registered to the course
+ */
+function search_members_keyword($firstname, $lastname, $username, $official_code, $keyword)
+{
+    if (api_strripos($firstname, $keyword) !== false ||
+        api_strripos($lastname, $keyword) !== false ||
+        api_strripos($username, $keyword) !== false ||
+        api_strripos($official_code, $keyword) !== false
+    ) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
+/**
+ * Function to sort users after getting the list in the DB.
+ * Necessary because there are 2 or 3 queries. Called by usort()
+ */
+function sort_users($user_a, $user_b)
+{
+    if (api_sort_by_first_name()) {
+        $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
+        if ($cmp !== 0) {
+            return $cmp;
+        } else {
+            $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
+            if ($cmp !== 0) {
+                return $cmp;
+            } else {
+                return api_strcmp($user_a['username'], $user_b['username']);
+            }
+        }
+    } else {
+        $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
+        if ($cmp !== 0) {
+            return $cmp;
+        } else {
+            $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
+            if ($cmp !== 0) {
+                return $cmp;
+            } else {
+                return api_strcmp($user_a['username'], $user_b['username']);
+            }
+        }
+    }
+}
+
+
+/*	MAIN CODE */
+
+$htmlHeadXtra[] = '<script>
+$(document).ready( function() {
+    $("#max_member").on("focus", function() {
+        $("#max_member_selected").attr("checked", true);
+    });
+});
+ </script>';
+
+// Build form
+$form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
+$form->addElement('hidden', 'action');
+
+// Group tutors
+$group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['id']);
+$selected_users = array();
+$selected_tutors = array();
+foreach ($group_tutor_list as $index => $user) {
+    $selected_tutors[] = $user['user_id'];
+}
+
+$complete_user_list = GroupManager :: fill_groups_list($current_group['id']);
+usort($complete_user_list, 'sort_users');
+
+$possible_users = array();
+foreach ($complete_user_list as $index => $user) {
+    $possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
+}
+
+$group_tutors_element = $form->addElement('advmultiselect', 'group_tutors', get_lang('GroupTutors'), $possible_users, 'style="width: 280px;"');
+$group_tutors_element->setElementTemplate('
+{javascript}
+<table{class}>
+<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
+<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
+<tr>
+  <td valign="top">{unselected}</td>
+  <td align="center">{add}<br /><br />{remove}</td>
+  <td valign="top">{selected}</td>
+</tr>
+</table>
+');
+
+$group_tutors_element->setButtonAttributes('add', array('class' => 'btn arrowr'));
+$group_tutors_element->setButtonAttributes('remove', array('class' => 'btn arrowl'));
+
+// submit button
+$form->addElement('style_submit_button', 'submit', get_lang('SaveSettings'), 'class="save"');
+
+if ($form->validate()) {
+    $values = $form->exportValues();
+
+    // Storing the tutors (we first remove all the tutors and then add only those who were selected)
+    GroupManager :: unsubscribe_all_tutors($current_group['id']);
+    if (isset ($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
+        GroupManager :: subscribe_tutors($values['group_tutors'], $current_group['id']);
+    }
+
+    // Returning to the group area (note: this is inconsistent with the rest of chamilo)
+    $cat = GroupManager::get_category_from_group($current_group['id']);
+    if (isset($_POST['group_members']) && count($_POST['group_members']) > $max_member && $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
+        header('Location: group.php?'.api_get_cidreq(true, false).'&action=warning_message&msg='.get_lang('GroupTooMuchMembers'));
+    } else {
+        header('Location: group.php?'.api_get_cidreq(true, false).'&action=success_message&msg='.get_lang('GroupSettingsModified').'&category='.$cat['id']);
+    }
+    exit;
+}
+
+$defaults = $current_group;
+$defaults['group_tutors'] = $selected_tutors;
+$action = isset($_GET['action']) ? $_GET['action'] : '';
+$defaults['action'] = $action;
+
+if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
+    $keyword_name = Security::remove_XSS($_GET['keyword']);
+    echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
+}
+
+Display :: display_header($nameTools, 'Group');
+
+//@todo fix this
+if (isset($_GET['show_message_warning'])) {
+    echo Display::display_warning_message($_GET['show_message_warning']);
+}
+
+if (isset($_GET['show_message_sucess'])) {
+    echo Display::display_normal_message($_GET['show_message_sucess']);
+}
+
+$form->setDefaults($defaults);
+echo GroupManager::getSettingBar('tutor');
+$form->display();
+
+Display :: display_footer();

BIN
main/img/icons/22/export_excel.png


+ 53 - 19
main/inc/ajax/model.ajax.php

@@ -167,6 +167,7 @@ switch ($action) {
         if ($courseInfo['show_score'] == '0') {
             $count = get_count_work($work_id, null, api_get_user_id());
         } else {
+            // Only my stuff
             $count = get_count_work($work_id, api_get_user_id());
         }
         break;
@@ -338,15 +339,20 @@ switch ($action) {
         break;
     case 'get_work_user_list_all':
         if (isset($_GET['type'])  && $_GET['type'] == 'simple') {
-            $columns = array('type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
+            $columns = array(
+                'type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
+            );
         } else {
             $columns = array('type', 'firstname', 'lastname', 'title', 'sent_date', 'actions');
         }
         $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
+
         break;
     case 'get_work_user_list_others':
         if (isset($_GET['type'])  && $_GET['type'] == 'simple') {
-            $columns = array('type', 'firstname', 'lastname',  'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
+            $columns = array(
+                'type', 'firstname', 'lastname',  'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
+            );
         } else {
             $columns = array('type', 'firstname', 'lastname',  'title', 'sent_date', 'actions');
         }
@@ -355,21 +361,41 @@ switch ($action) {
         break;
     case 'get_work_user_list':
         if (isset($_GET['type'])  && $_GET['type'] == 'simple') {
-            $columns = array('type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
+            $columns = array(
+                'type', 'firstname', 'lastname', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions'
+            );
         } else {
             $columns = array('type', 'firstname', 'lastname', 'title', 'sent_date', 'actions');
         }
-        $where_condition .= " AND u.user_id = ".api_get_user_id();
+
         $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
+        $documents = getAllDocumentToWork($work_id, api_get_course_int_id());
+
+        if (empty($documents)) {
+            $where_condition .= " AND u.user_id = ".api_get_user_id();
+            $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
+        } else {
+            $result = get_work_user_list_from_documents(
+                $start,
+                $limit,
+                $sidx,
+                $sord,
+                $work_id,
+                api_get_user_id(),
+                $where_condition
+            );
+        }
         break;
 	case 'get_exercise_results':
         $course = api_get_course_info();
-        //used inside get_exam_results_data()
-		$documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
-		if ($is_allowedToEdit) {
-			$columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions');
-		}
-		$result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
+        // Used inside get_exam_results_data()
+        $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
+        if ($is_allowedToEdit) {
+            $columns = array(
+                'firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions'
+            );
+        }
+        $result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
 		break;
 	case 'get_hotpotatoes_exercise_results':
 		$course = api_get_course_info();
@@ -378,17 +404,29 @@ switch ($action) {
 		$result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
 		break;
     case 'get_sessions':
-        $columns = array('name', 'nbr_courses', 'nbr_users', 'category_name', 'date_start','date_end', 'coach_name', 'session_active', 'visibility');
-        $result = SessionManager::get_sessions_admin(array('where'=> $where_condition, 'order'=>"$sidx $sord", 'limit'=> "$start , $limit"));
+        $columns = array(
+            'name', 'nbr_courses', 'nbr_users', 'category_name', 'date_start','date_end', 'coach_name', 'session_active', 'visibility'
+        );
+        $result = SessionManager::get_sessions_admin(
+            array(
+                'where' => $where_condition,
+                'order' => "$sidx $sord",
+                'limit'=> "$start , $limit"
+            )
+        );
         break;
      case 'get_timelines':
         $columns = array('headline', 'actions');
 
-        if(!in_array($sidx, $columns)) {
+        if (!in_array($sidx, $columns)) {
         	$sidx = 'headline';
         }
         $course_id = api_get_course_int_id();
-        $result     = Database::select('*', $obj->table, array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
+        $result = Database::select(
+            '*',
+            $obj->table,
+            array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit")
+        );
         $new_result = array();
         foreach ($result as $item) {
             if (!$item['status']) {
@@ -451,10 +489,6 @@ switch ($action) {
             $item['language_id'] = $language_info['english_name'];
             $item['actions'] = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH).'admin/event_type.php?action=edit&event_type_name='.$item['event_type_name']);
             $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH).'admin/event_controller.php?action=delete&id='.$item['id']);
-
-            /*if (!$item['status']) {
-                $item['name'] = '<font style="color:#AAA">'.$item['subject'].'</font>';
-            }*/
             $new_result[] = $item;
         }
         $result = $new_result;
@@ -476,7 +510,7 @@ switch ($action) {
         break;
     case 'get_promotions':
         $columns = array('name', 'career', 'description', 'actions');
-        if(!in_array($sidx, $columns)) {
+        if (!in_array($sidx, $columns)) {
             $sidx = 'name';
         }
 

+ 65 - 11
main/inc/lib/course_category.lib.php

@@ -10,6 +10,22 @@ function isMultipleUrlSupport()
     return false;
 }
 
+/**
+ * @param int $categoryId
+ * @return array
+ */
+function getCategoryById($categoryId)
+{
+    $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
+    $categoryId = Database::escape_string($categoryId);
+    $sql = "SELECT * FROM $tbl_category WHERE id = '$categoryId'";
+    $result = Database::query($sql);
+    if (Database::num_rows($result)) {
+        return Database::fetch_array($result, 'ASSOC');
+    }
+    return array();
+}
+
 /**
  * @param string $category
  * @return array
@@ -94,7 +110,7 @@ function addNode($code, $name, $canHaveCourses, $parent_id)
     $row = Database::fetch_array($result);
     $tree_pos = $row['maxTreePos'] + 1;
 
-    $sql = "INSERT INTO $tbl_category(name,code,parent_id,tree_pos,children_count,auth_course_child)
+    $sql = "INSERT INTO $tbl_category(name, code, parent_id, tree_pos, children_count, auth_course_child)
             VALUES('$name','$code'," .(empty($parent_id) ? "NULL" : "'$parent_id'") . ",'$tree_pos','0','$canHaveCourses')";
     Database::query($sql);
     $categoryId = Database::insert_id();
@@ -134,7 +150,7 @@ function deleteNode($node)
 
     $node = Database::escape_string($node);
 
-    $result = Database::query("SELECT parent_id,tree_pos FROM $tbl_category WHERE code='$node'");
+    $result = Database::query("SELECT parent_id, tree_pos FROM $tbl_category WHERE code='$node'");
 
     if ($row = Database::fetch_array($result)) {
         if (!empty($row['parent_id'])) {
@@ -171,19 +187,18 @@ function editNode($code, $name, $canHaveCourses, $old_code)
     $old_code = Database::escape_string($old_code);
     $canHaveCourses = Database::escape_string($canHaveCourses);
 
-    if ($code != $old_code) {
-        $sql = "SELECT 1 FROM $tbl_category WHERE code='$code'";
-        $result = Database::query($sql);
-        if (Database::num_rows($result)) {
-            return false;
-        }
-    }
-
     $code = generate_course_code($code);
+    // Updating category
     $sql = "UPDATE $tbl_category SET name='$name', code='$code', auth_course_child = '$canHaveCourses'
-            WHERE code='$old_code'";
+            WHERE code = '$old_code'";
     Database::query($sql);
 
+    // Updating children
+    $sql = "UPDATE $tbl_category SET parent_id = '$code'
+            WHERE parent_id = '$old_code'";
+    Database::query($sql);
+
+    // Updating course category
     $sql = "UPDATE $tbl_course SET category_code = '$code' WHERE category_code = '$old_code' ";
     Database::query($sql);
     return true;
@@ -238,6 +253,24 @@ function compterFils($pere, $cpt)
     return ($cpt + 1);
 }
 
+/**
+ * @param string $categoryCode
+ * @return array
+ */
+function getChildren($categoryCode)
+{
+    $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
+    $categoryCode = Database::escape_string($categoryCode);
+    $result = Database::query("SELECT code, id FROM $tbl_category WHERE parent_id = '$categoryCode'");
+    $children = array();
+    while ($row = Database::fetch_array($result, 'ASSOC')) {
+        $children[] = $row;
+        $subChildren = getChildren($row['code']);
+        $children = array_merge($children, $subChildren);
+    }
+    return $children;
+}
+
 /**
  * @param string $categorySource
  * @return string
@@ -583,6 +616,27 @@ function setCategoriesInForm($form, $defaultCode = null, $parentCode = null , $p
     }
 }
 
+/**
+ * @param array $list
+ * @return array
+ */
+function getCourseCategoryNotInList($list)
+{
+    $table = Database::get_main_table(TABLE_MAIN_CATEGORY);
+    if (empty($list)) {
+        return array();
+    }
+
+    $list = array_map('intval', $list);
+    $listToString = implode("','", $list);
+
+    $sql = "SELECT * FROM $table WHERE id NOT IN ('$listToString') AND (parent_id IS NULL) ";
+    $result = Database::query($sql);
+    return Database::store_result($result, 'ASSOC');
+}
+
+
+
 /**
  CREATE TABLE IF NOT EXISTS access_url_rel_course_category (access_url_id int unsigned NOT NULL, course_category_id int unsigned NOT NULL, PRIMARY KEY (access_url_id, course_category_id));
  */

+ 0 - 1
main/inc/lib/database.lib.php

@@ -1174,7 +1174,6 @@ class Database {
         }
 
         $sql    = "SELECT $clean_columns FROM $table_name $conditions";
-
         $result = self::query($sql);
         $array = array();
         //if (self::num_rows($result) > 0 ) {

+ 18 - 15
main/inc/lib/exercise_show_functions.lib.php

@@ -15,7 +15,8 @@
  * Class
  * @package chamilo.library
  */
-class ExerciseShowFunctions {
+class ExerciseShowFunctions
+{
 
 	/**
 	 * Shows the answer to a fill-in-the-blanks question, as HTML
@@ -57,7 +58,8 @@ class ExerciseShowFunctions {
 	 * @param int       Question ID
 	 * @return void
 	 */
-	static function display_free_answer($feedback_type, $answer, $exe_id, $questionId, $questionScore = null) {
+	static function display_free_answer($feedback_type, $answer, $exe_id, $questionId, $questionScore = null)
+    {
         $comments = get_comments($exe_id, $questionId);
 
         if (!empty($answer)) {
@@ -76,7 +78,8 @@ class ExerciseShowFunctions {
         }
 	}
 
-	static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $nano = null) {
+	static function display_oral_expression_answer($feedback_type, $answer, $id, $questionId, $nano = null)
+    {
 		if (isset($nano)) {
 			echo $nano->show_audio_file();
 		}
@@ -162,9 +165,9 @@ class ExerciseShowFunctions {
 			<td valign="top" align="left" >
 				<?php
                 if ($studentChoice) {
-                    echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
+                    echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
                 } else {
-                    //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
+                    //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
                 }
 
 				?>
@@ -221,18 +224,18 @@ class ExerciseShowFunctions {
             if ($studentChoice) {
 				if ($answerCorrect) {
                     $color = 'green';
-					//echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
+					//echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
 				} else {
                     $color = 'black';
-                    //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
+                    //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
 				}
-                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(make_clickable($answerComment)).'</span>';
+                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
 
 			} else {
 				if ($answerCorrect) {
-					//echo '<span style="font-weight: bold; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
+					//echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
 				} else {
-                    //echo '<span style="font-weight: normal; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
+                    //echo '<span style="font-weight: normal; color: #000;">'.nl2br($answerComment).'</span>';
 				}
 			}
 			?>
@@ -311,7 +314,7 @@ class ExerciseShowFunctions {
                 if ($studentChoice == $answerCorrect) {
                     $color = "green";
                 }
-                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(make_clickable($answerComment)).'</span>';
+                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
             }
             ?>
         </td>
@@ -389,15 +392,15 @@ class ExerciseShowFunctions {
                 if ($studentChoice == $answerCorrect) {
                     $color = "green";
                 }
-                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br(make_clickable($answerComment)).'</span>';
+                echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>';
             }
             if ($studentChoice == 2 || $studentChoice == '') {
-            	//echo '<span style="font-weight: bold; color: #000;">'.nl2br(make_clickable($answerComment)).'</span>';
+            	//echo '<span style="font-weight: bold; color: #000;">'.nl2br($answerComment).'</span>';
             } else {
 				if ($studentChoice == $answerCorrect) {
-	            	//echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
+	            	//echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>';
 				} else {
-                    //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
+                    //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>';
 				}
             }
             ?>

+ 78 - 72
main/inc/lib/export.lib.inc.php

@@ -18,42 +18,46 @@ require_once api_get_path(LIBRARY_PATH).'pdf.lib.php';
  *
  * @package chamilo.library
  */
-class Export {
+class Export
+{
 
-	private function __construct() {
+	private function __construct()
+    {
 	}
 
-	/**
-     * 
-     * @deprecated use export_table_csv_utf8 instead
-	 */
-	public static function export_table_csv ($data, $filename = 'export') {
-		$file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.csv';
-		$handle = @fopen($file, 'a+');
-
-		if(is_array($data)) {
-			foreach ($data as $index => $row) {
-				$line = '';
-				if(is_array($row)) {
-					foreach($row as $value) {
-						$line .= '"'.str_replace('"', '""', $value).'";';
-					}
-				}
-				@fwrite($handle, $line."\n");
-			}
-		}
-		@fclose($handle);
-		DocumentManager :: file_send_for_download($file, true, $filename.'.csv');
-		return false;
-	}
-    
+    /**
+    *
+    * @deprecated use export_table_csv_utf8 instead
+    */
+    public static function export_table_csv ($data, $filename = 'export')
+    {
+        $file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.csv';
+        $handle = @fopen($file, 'a+');
+
+        if (is_array($data)) {
+            foreach ($data as $index => $row) {
+                $line = '';
+                if (is_array($row)) {
+                    foreach($row as $value) {
+                        $line .= '"'.str_replace('"', '""', $value).'";';
+                    }
+                }
+                @fwrite($handle, $line."\n");
+            }
+        }
+        @fclose($handle);
+        DocumentManager :: file_send_for_download($file, true, $filename.'.csv');
+        return false;
+    }
+
 	/**
 	 * Export tabular data to CSV-file
 	 * @param array $data
 	 * @param string $filename
 	 */
-	public static function export_table_csv_utf8 ($data, $filename = 'export') {
-        if(empty($data)){
+	public static function export_table_csv_utf8($data, $filename = 'export')
+    {
+        if(empty($data)) {
             return false;
         }
         $path = Chamilo::temp_file();
@@ -64,37 +68,37 @@ class Export {
             $file->put($row);
         }
 		$file->close();
-		DocumentManager :: file_send_for_download($path, true, $filename.'.csv');
+		DocumentManager::file_send_for_download($path, true, $filename.'.csv');
         unlink($path);
         exit;
-		return false;
 	}
 
-	/**
-	 * Export tabular data to XLS-file
-	 * @param array $data
-	 * @param string $filename
-	 */
-	public static function export_table_xls ($data, $filename = 'export') {
-		$file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.xls';
-		$handle = @fopen($file, 'a+');
-		foreach ($data as $index => $row) {
-			@fwrite($handle, implode("\t", $row)."\n");
-		}
-		@fclose($handle);
-		DocumentManager :: file_send_for_download($file, true, $filename.'.xls');
-		return false;
+    /**
+     * Export tabular data to XLS-file
+     * @param array $data
+     * @param string $filename
+     */
+    public static function export_table_xls($data, $filename = 'export')
+    {
+        $file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.xls';
+        $handle = fopen($file, 'a+');
+        foreach ($data as $row) {
+            fwrite($handle, implode("\t", $row)."\n");
+        }
+        fclose($handle);
+        DocumentManager::file_send_for_download($file, true, $filename.'.xls');
 	}
 
-	/**
-	 * Export tabular data to XML-file
-	 * @param array  Simple array of data to put in XML
-	 * @param string Name of file to be given to the user
-     * @param string Name of common tag to place each line in
-     * @param string Name of the root element. A root element should always be given.
-     * @param string Encoding in which the data is provided
-	 */
-	public static function export_table_xml ($data, $filename = 'export', $item_tagname = 'item', $wrapper_tagname = null, $encoding = null) {
+    /**
+    * Export tabular data to XML-file
+    * @param array  Simple array of data to put in XML
+    * @param string Name of file to be given to the user
+    * @param string Name of common tag to place each line in
+    * @param string Name of the root element. A root element should always be given.
+    * @param string Encoding in which the data is provided
+    */
+	public static function export_table_xml ($data, $filename = 'export', $item_tagname = 'item', $wrapper_tagname = null, $encoding = null)
+    {
 		if (empty($encoding)) {
 			$encoding = api_get_system_encoding();
 		}
@@ -104,7 +108,7 @@ class Export {
 		if (!is_null($wrapper_tagname)) {
 			fwrite($handle, "\t".'<'.$wrapper_tagname.'>'."\n");
 		}
-		foreach ($data as $index => $row) {
+		foreach ($data as $row) {
 			fwrite($handle, '<'.$item_tagname.'>'."\n");
 			foreach ($row as $key => $value) {
 				fwrite($handle, "\t\t".'<'.$key.'>'.$value.'</'.$key.'>'."\n");
@@ -128,7 +132,8 @@ class Export {
      * @param string Encoding in which the data is provided
      * @return void  Prompts the user for a file download
      */
-    public static function export_complex_table_xml ($data, $filename = 'export', $wrapper_tagname, $encoding = 'ISO-8859-1') {
+    public static function export_complex_table_xml ($data, $filename = 'export', $wrapper_tagname, $encoding = 'ISO-8859-1')
+    {
         $file = api_get_path(SYS_ARCHIVE_PATH).'/'.uniqid('').'.xml';
         $handle = fopen($file, 'a+');
         fwrite($handle, '<?xml version="1.0" encoding="'.$encoding.'"?>'."\n");
@@ -152,10 +157,11 @@ class Export {
      * @param   int     Level of recursivity. Allows the XML to be finely presented
      * @return string   The XML string to be inserted into the root element
      */
-    public static function _export_complex_table_xml_helper ($data, $level = 1) {
+    public static function _export_complex_table_xml_helper ($data, $level = 1)
+    {
     	if (count($data)<1) { return '';}
         $string = '';
-        foreach ($data as $index => $row) {
+        foreach ($data as $row) {
             $string .= "\n".str_repeat("\t",$level).'<'.$row['name'].'>';
             if (is_array($row['value'])) {
             	$string .= self::_export_complex_table_xml_helper($row['value'],$level+1)."\n";
@@ -167,18 +173,18 @@ class Export {
         }
         return $string;
     }
-    
-    /** 
-     * 
-     * @param array table in array format to be read with the HTML_table class 
+
+    /**
+     *
+     * @param array table in array format to be read with the HTML_table class
      */
     public static function export_table_pdf($data, $params = array())
     {
-        $table_html = self::convert_array_to_html($data, $params);          
+        $table_html = self::convert_array_to_html($data, $params);
         $params['format'] = isset($params['format']) ? $params['format'] : 'A4';
         $params['orientation'] = isset($params['orientation']) ? $params['orientation'] : 'P';
-        
-        $pdf = new PDF($params['format'], $params['orientation'], $params); 
+
+        $pdf = new PDF($params['format'], $params['orientation'], $params);
         $pdf->html_to_pdf_with_template($table_html);
     }
 
@@ -190,9 +196,9 @@ class Export {
     {
         $params['format'] = isset($params['format']) ? $params['format'] : 'A4';
         $params['orientation'] = isset($params['orientation']) ? $params['orientation'] : 'P';
-        
-        $pdf = new PDF($params['format'], $params['orientation'], $params); 
-        $pdf->html_to_pdf_with_template($html);        
+
+        $pdf = new PDF($params['format'], $params['orientation'], $params);
+        $pdf->html_to_pdf_with_template($html);
     }
 
     /**
@@ -203,9 +209,9 @@ class Export {
     public static function convert_array_to_html($data, $params = array())
     {
         $headers = $data[0];
-        unset($data[0]); 
-       
-        $header_attributes = isset($params['header_attributes']) ? $params['header_attributes'] : array();                
+        unset($data[0]);
+
+        $header_attributes = isset($params['header_attributes']) ? $params['header_attributes'] : array();
         $table = new HTML_Table(array('class' => 'data_table', 'repeat_header' => '1'));
         $row = 0;
         $column = 0;
@@ -213,14 +219,14 @@ class Export {
             $table->setHeaderContents($row, $column, $header);
             $attributes = array();
             if (isset($header_attributes) && isset($header_attributes[$column])) {
-                $attributes = $header_attributes[$column];            
+                $attributes = $header_attributes[$column];
             }
             if (!empty($attributes)) {
                 $table->updateCellAttributes($row, $column, $attributes);
             }
             $column++;
         }
-        $row++; 
+        $row++;
         foreach ($data as &$printable_data_row) {
             $column = 0;
             foreach ($printable_data_row as &$printable_data_cell) {

File diff suppressed because it is too large
+ 325 - 131
main/inc/lib/groupmanager.lib.php


+ 2 - 0
main/inc/lib/internationalization.lib.php

@@ -1111,10 +1111,12 @@ function api_is_western_name_order($format = null, $language = null) {
     }
 
     $language_is_supported = api_is_language_supported($language);
+
     if (!$language_is_supported || empty($language)) {
         $language = api_get_interface_language(false, true);
     }
     if (!isset($order[$format][$language])) {
+
         $test_name = api_get_person_name('%f', '%l', '%t', $format, $language);
         $order[$format][$language] = stripos($test_name, '%f') <= stripos($test_name, '%l');
     }

+ 92 - 49
main/inc/lib/pdf.lib.php

@@ -8,7 +8,9 @@
  */
 define('_MPDF_PATH', api_get_path(LIBRARY_PATH).'mpdf/');
 require_once _MPDF_PATH.'mpdf.php';
-
+/**
+ * Class PDF
+ */
 class PDF
 {
     public $pdf;
@@ -121,13 +123,13 @@ class PDF
 
         if (is_array($html_file_array)) {
             if (count($html_file_array) == 0) {
-            return false;
+                return false;
             }
         } else {
             if (!file_exists($html_file_array)) {
                 return false;
             }
-            //Converting the string into an array
+            // Converting the string into an array
             $html_file_array = array($html_file_array);
         }
 
@@ -137,13 +139,13 @@ class PDF
             $course_data = api_get_course_info();
         }
 
-        //clean styles and javascript document
+        // Clean styles and javascript document
         $clean_search = array (
             '@<script[^>]*?>.*?</script>@si',
             '@<style[^>]*?>.*?</style>@si'
             );
 
-        //Formatting the pdf
+        // Formatting the pdf
         self::format_pdf($course_data, $complete_style);
 
         $counter = 1;
@@ -168,7 +170,7 @@ class PDF
             }
 
             if (empty($file) && !empty($html_title)) {
-            	//this is a chapter, print title & skip the rest
+                //this is a chapter, print title & skip the rest
                 if ($print_title) {
                     $this->pdf->WriteHTML('<html><body><h3>'.$html_title.'</h3></body></html>'.$page_break, 2);
                 }
@@ -177,7 +179,7 @@ class PDF
 
             if (!file_exists($file)) {
                 //the file doesn't exist, skip
-            	continue;
+                continue;
             }
 
             //it's not a chapter but the file exists, print its title
@@ -243,9 +245,10 @@ class PDF
                 }
 
                 api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data.
-                $title = api_get_title_html($document_html, 'UTF-8', 'UTF-8');  // TODO: Maybe it is better idea the title to be passed through
-                                                                                // $_GET[] too, as it is done with file name.
-                                                                         // At the moment the title is retrieved from the html document itself.
+                // TODO: Maybe it is better idea the title to be passed through
+                $title = api_get_title_html($document_html, 'UTF-8', 'UTF-8');
+                // $_GET[] too, as it is done with file name.
+                // At the moment the title is retrieved from the html document itself.
                 //echo $document_html;exit;
                 if (empty($title)) {
                     $title = $filename; // Here file name is expected to contain ASCII symbols only.
@@ -264,9 +267,9 @@ class PDF
             $output_file = 'pdf_'.date('Y-m-d-his').'.pdf';
         } else {
             $pdf_name = replace_dangerous_char($pdf_name);
-        	$output_file = $pdf_name.'.pdf';
+            $output_file = $pdf_name.'.pdf';
         }
-        $result = $this->pdf->Output($output_file, 'D');       /// F to save the pdf in a file
+        $this->pdf->Output($output_file, 'D');       /// F to save the pdf in a file
         exit;
     }
 
@@ -280,7 +283,6 @@ class PDF
      */
     public function content_to_pdf($document_html, $css = '', $pdf_name = '', $course_code = null)
     {
-
         if (empty($document_html)) {
             return false;
         }
@@ -291,7 +293,7 @@ class PDF
             '@<style[^>]*?>.*?</style>@siU'
             );
 
-        //Formatting the pdf
+        // Formatting the pdf
        	$course_data = api_get_course_info($course_code);
 
         self::format_pdf($course_data);
@@ -347,8 +349,8 @@ class PDF
 
         api_set_encoding_html($document_html, 'UTF-8'); // The library mPDF expects UTF-8 encoded input data.
         $title = api_get_title_html($document_html, 'UTF-8', 'UTF-8');  // TODO: Maybe it is better idea the title to be passed through
-                                                                        // $_GET[] too, as it is done with file name.
-                                                                        // At the moment the title is retrieved from the html document itself.
+        // $_GET[] too, as it is done with file name.
+        // At the moment the title is retrieved from the html document itself.
 
         if (!empty($css)) {
             $this->pdf->WriteHTML($css, 1);
@@ -361,7 +363,7 @@ class PDF
             $pdf_name = replace_dangerous_char($pdf_name);
             $output_file = $pdf_name.'.pdf';
         }
-        $result = $this->pdf->Output($output_file, 'D'); // F to save the pdf in a file
+        $this->pdf->Output($output_file, 'D'); // F to save the pdf in a file
         exit;
     }
 
@@ -396,15 +398,18 @@ class PDF
     {
         if (!empty($course_code) && api_get_setting('pdf_export_watermark_by_course') == 'true') {
             $course_info = api_get_course_info($course_code);
-            $store_path  = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.api_get_current_access_url_id().'_pdf_watermark.png';   // course path
+            // course path
+            $store_path  = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/'.api_get_current_access_url_id().'_pdf_watermark.png';
+
         } else {
-            $store_path = api_get_path(SYS_CODE_PATH).'default_course_document/images/'.api_get_current_access_url_id().'_pdf_watermark.png';   // course path
+            // course path
+            $store_path = api_get_path(SYS_CODE_PATH).'default_course_document/images/'.api_get_current_access_url_id().'_pdf_watermark.png';
         }
         if (file_exists($store_path)) {
-            @unlink($store_path);
+            unlink($store_path);
             return true;
         }
-    	return false;
+        return false;
     }
 
     /**
@@ -454,7 +459,8 @@ class PDF
     /**
      *
      */
-    public function set_footer() {
+    public function set_footer()
+    {
         $this->pdf->defaultfooterfontsize = 12;   // in pts
         $this->pdf->defaultfooterfontstyle = B;   // blank, B, I, or BI
         $this->pdf->defaultfooterline = 1;        // 1 to include line below header/above footer
@@ -489,11 +495,10 @@ class PDF
     }
 
     /**
-     * @param $course_data
+     * @param array $course_data
      */
     public function set_header($course_data)
     {
-
         $this->pdf->defaultheaderfontsize   = 10;   // in pts
         $this->pdf->defaultheaderfontstyle  = BI;   // blank, B, I, or BI
         $this->pdf->defaultheaderline       = 1;    // 1 to include line below header/above footer
@@ -503,7 +508,6 @@ class PDF
             $teachers = '';
             if (!empty($teacher_list)) {
                 foreach ($teacher_list as $teacher) {
-                    //$teachers[]= api_get_person_name($teacher['firstname'], $teacher['lastname']);
                     $teachers[]= $teacher['firstname'].' '.$teacher['lastname'];
                 }
                 if (count($teachers) > 1) {
@@ -512,7 +516,7 @@ class PDF
                     $teachers = get_lang('Teacher').': '.implode('', $teachers);
                 }
 
-                //do not show the teacher list see BT#4080 only the current teacher name
+                // Do not show the teacher list see BT#4080 only the current teacher name
                 $user_info = api_get_user_info();
                 $teachers = $user_info['complete_name'];
             }
@@ -521,35 +525,73 @@ class PDF
             $center_content  = '';
             $right_content   = $teachers;
 
-            $header = array (
-              'odd' => array (
-                'L' => array (
-                  'content' => $left_content,  'font-size' => 10,'font-style' => 'B','font-family' => 'serif','color'=>'#000000'),
-                'C' => array (
-                  'content' => $center_content,'font-size' => 10,'font-style' => 'B','font-family' => 'serif','color'=>'#000000'),
-                'R' => array (
-                  'content' => $right_content, 'font-size' => 10,'font-style' => 'B','font-family' => 'serif','color'=>'#000000'),
-                'line' => 1,
-              ),
-             'even' => array (
-                'L' => array (
-                  'content' => $left_content,  'font-size' => 10,'font-style' => 'B','font-family' => 'serif','color'=>'#000000'),
-                'C' => array (
-                  'content' => $center_content,'font-size' => 10,'font-style' => 'B','font-family' => 'serif','color'=>'#000000'),
-                'R' => array (
-                  'content' => $right_content, 'font-size' => 10,'font-style' => 'B','font-family' => 'serif','color'=>'#000000'),
-                'line' => 1,
-              ),
+            $header = array(
+                'odd' => array(
+                    'L' => array(
+                        'content' => $left_content,
+                        'font-size' => 10,
+                        'font-style' => 'B',
+                        'font-family' => 'serif',
+                        'color'=>'#000000'
+                    ),
+                    'C' => array(
+                        'content' => $center_content,
+                        'font-size' => 10,
+                        'font-style' => 'B',
+                        'font-family' => 'serif',
+                        'color'=>'#000000'
+                    ),
+                    'R' => array(
+                        'content' => $right_content,
+                        'font-size' => 10,
+                        'font-style' => 'B',
+                        'font-family' => 'serif',
+                        'color'=>'#000000'
+                    ),
+                    'line' => 1,
+                ),
+                'even' => array(
+                    'L' => array(
+                        'content' => $left_content,
+                        'font-size' => 10,
+                        'font-style' => 'B',
+                        'font-family' => 'serif',
+                        'color'=>'#000000'
+                    ),
+                    'C' => array(
+                        'content' => $center_content,
+                        'font-size' => 10,
+                        'font-style' => 'B',
+                        'font-family' => 'serif',
+                        'color'=>'#000000'
+                    ),
+                    'R' => array(
+                        'content' => $right_content,
+                        'font-size' => 10,
+                        'font-style' => 'B',
+                        'font-family' => 'serif',
+                        'color'=>'#000000'
+                    ),
+                    'line' => 1,
+                ),
             );
             $this->pdf->SetHeader($header);// ('{DATE j-m-Y}|{PAGENO}/{nb}|'.$title);
         }
     }
 
-    public function set_custom_header($header) {
+    /**
+     * @param string $header html content
+     */
+    public function set_custom_header($header)
+    {
         $this->custom_header = $header;
     }
 
-    public function set_custom_footer($footer) {
+    /**
+     * @param string $footer html content
+     */
+    public function set_custom_footer($footer)
+    {
         $this->custom_footer = $footer;
     }
 
@@ -565,7 +607,7 @@ class PDF
             error_log('Asked with no decoration');
         }
         $course_code = null;
-        if (!empty( $course_data)) {
+        if (!empty($course_data)) {
             $course_code = $course_data['code'];
         }
 
@@ -576,7 +618,8 @@ class PDF
         */
         $this->pdf->directionality      = api_get_text_direction(); // TODO: To be read from the html document.
         $this->pdf->useOnlyCoreFonts    = true;
-        $this->pdf->mirrorMargins       = 1;            // Use different Odd/Even headers and footers and mirror margins
+        // Use different Odd/Even headers and footers and mirror margins
+        $this->pdf->mirrorMargins       = 1;
 
         // Add decoration only if not stated otherwise
         if ($complete) {

+ 27 - 12
main/inc/lib/sessionmanager.lib.php

@@ -1540,9 +1540,8 @@ class SessionManager
     * Subscribes sessions to human resource manager (Dashboard feature)
     * @param	int 		Human Resource Manager id
     * @param	array 		Sessions id
-    * @param	int			Relation type
     **/
-	public static function suscribe_sessions_to_hr_manager($hr_manager_id,$sessions_list)
+	public static function suscribe_sessions_to_hr_manager($hr_manager_id, $sessions_list)
     {
         // Database Table Definitions
         $tbl_session_rel_user           =   Database::get_main_table(TABLE_MAIN_SESSION_USER);
@@ -1553,24 +1552,36 @@ class SessionManager
 
         // Deleting assigned sessions to hrm_id
         if (api_is_multiple_url_enabled()) {
-            $sql = "SELECT id_session FROM $tbl_session_rel_user s INNER JOIN $tbl_session_rel_access_url a ON (a.session_id = s.id_session) WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH." AND access_url_id = ".api_get_current_access_url_id()."";
+            $sql = "SELECT id_session
+                    FROM $tbl_session_rel_user s
+                    INNER JOIN $tbl_session_rel_access_url a ON (a.session_id = s.id_session)
+                    WHERE
+                        id_user = $hr_manager_id AND
+                        relation_type=".SESSION_RELATION_TYPE_RRHH." AND
+                        access_url_id = ".api_get_current_access_url_id()."";
         } else {
-            $sql = "SELECT id_session FROM $tbl_session_rel_user s WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH."";
+            $sql = "SELECT id_session FROM $tbl_session_rel_user s
+                    WHERE id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH."";
         }
         $result = Database::query($sql);
 
         if (Database::num_rows($result) > 0) {
             while ($row = Database::fetch_array($result))   {
-                 $sql = "DELETE FROM $tbl_session_rel_user WHERE id_session = {$row['id_session']} AND id_user = $hr_manager_id AND relation_type=".SESSION_RELATION_TYPE_RRHH." ";
+                 $sql = "DELETE FROM $tbl_session_rel_user
+                        WHERE
+                            id_session = {$row['id_session']} AND
+                            id_user = $hr_manager_id AND
+                            relation_type=".SESSION_RELATION_TYPE_RRHH." ";
                  Database::query($sql);
             }
         }
 
-		// inserting new sessions list
+		// Inserting new sessions list
 		if (is_array($sessions_list)) {
 			foreach ($sessions_list as $session_id) {
 				$session_id = intval($session_id);
-				$insert_sql = "INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user, relation_type) VALUES($session_id, $hr_manager_id, '".SESSION_RELATION_TYPE_RRHH."')";
+				$insert_sql = "INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user, relation_type) VALUES
+				               ($session_id, $hr_manager_id, '".SESSION_RELATION_TYPE_RRHH."')";
 				Database::query($insert_sql);
 				$affected_rows = Database::affected_rows();
 			}
@@ -2060,8 +2071,7 @@ class SessionManager
         $daysCoachAccessAfterBeginning = null,
         $sessionVisibility = 1,
         $fieldsToAvoidUpdate = array()
-    )
-    {
+    ) {
         $content = file($file);
 
         $error_message = null;
@@ -2280,11 +2290,16 @@ class SessionManager
                             }
                         }
 
-                        Database::query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'");
-                        Database::query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'");
+                        $sql = "DELETE FROM $tbl_session_user
+                                WHERE id_session = '$session_id' AND relation_type <> ".SESSION_RELATION_TYPE_RRHH;
+                        Database::query($sql);
+
+                        $sql = "DELETE FROM $tbl_session_course WHERE id_session = '$session_id'";
+                        Database::query($sql);
 
                         // Delete session course user relation ships *only* for students
-                        Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id' AND status <> 2");
+                        $sql = "DELETE FROM $tbl_session_course_user WHERE id_session = '$session_id' AND status <> 2";
+                        Database::query($sql);
                     }
                     $session_counter++;
                 }

+ 3 - 1
main/inc/lib/social.lib.php

@@ -594,7 +594,9 @@ class SocialManager extends UserManager
             $html .= '<div class="well social-background-content">';
             $html .= Display::url('<img src='.$big['file'].' class="social-groups-image" /> </a><br /><br />', api_get_path(WEB_PATH).'main/social/groups.php?id='.$group_id);
             if (GroupPortalManager::is_group_admin($group_id, api_get_user_id())) {
-                $html .= '<div id="edit_image" class="hidden_message" style="display:none"><a href="'.api_get_path(WEB_PATH).'main/social/group_edit.php?id='.$group_id.'">'.get_lang('EditGroup').'</a></div>';
+                $html .= '<div id="edit_image" class="hidden_message" style="display:none">
+                            <a href="'.api_get_path(WEB_PATH).'main/social/group_edit.php?id='.$group_id.'">'.
+                    get_lang('EditGroup').'</a></div>';
             }
             $html .= '</div>';
             $html .= '</div>';

+ 23 - 19
main/inc/lib/tracking.lib.php

@@ -3106,12 +3106,16 @@ class Tracking {
         return $html;
     }
 }
+
 /**
+ * @todo move into a proper file
  * @package chamilo.tracking
  */
-class TrackingCourseLog {
+class TrackingCourseLog
+{
 
-    function count_item_resources() {
+    function count_item_resources()
+    {
     	global $session_id;
         $course_id = api_get_course_int_id();
 
@@ -3132,7 +3136,8 @@ class TrackingCourseLog {
     	return $obj->total_number_of_items;
     }
 
-    function get_item_resources_data($from, $number_of_items, $column, $direction) {
+    function get_item_resources_data($from, $number_of_items, $column, $direction)
+    {
     	global $dateTimeFormatLong, $session_id;
         $course_id = api_get_course_int_id();
 
@@ -3541,9 +3546,14 @@ class TrackingCourseLog {
 
     /**
      * Get data for users list in sortable with pagination
+     * @param $from
+     * @param $number_of_items
+     * @param $column
+     * @param $direction
      * @return array
      */
-    static function get_user_data($from, $number_of_items, $column, $direction) {
+    static function get_user_data($from, $number_of_items, $column, $direction)
+    {
     	global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content, $session_id, $_configuration;
 
     	$course_code        = Database::escape_string($course_code);
@@ -3564,7 +3574,7 @@ class TrackingCourseLog {
 
     	if (!empty($_GET['user_keyword'])) {
     		$keyword = trim(Database::escape_string($_GET['user_keyword']));
-    		$condition_user .=  " AND  (user.firstname LIKE '%".$keyword."%' OR user.lastname LIKE '%".$keyword."%'  OR user.username LIKE '%".$keyword."%'  OR user.email LIKE '%".$keyword."%' ) ";
+    		$condition_user .=  " AND (user.firstname LIKE '%".$keyword."%' OR user.lastname LIKE '%".$keyword."%'  OR user.username LIKE '%".$keyword."%'  OR user.email LIKE '%".$keyword."%' ) ";
     	}
 
     	if (api_is_multiple_url_enabled()) {
@@ -3626,19 +3636,14 @@ class TrackingCourseLog {
 
     	while ($user = Database::fetch_array($res, 'ASSOC')) {
     		$user['official_code']  = $user['col0'];
-    		if ($is_western_name_order) {
-    			$user['lastname']       = $user['col2'];
-    			$user['firstname']      = $user['col1'];
-    		} else {
-    			$user['lastname']       = $user['col1'];
-    			$user['firstname']      = $user['col2'];
-    		}
-    		$user['username']           = $user['col3'];
-    		$user['time']                = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $course_code, $session_id));
+            $user['lastname']       = $user['col1'];
+            $user['firstname']      = $user['col2'];
+    		$user['username']       = $user['col3'];
+    		$user['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $course_code, $session_id));
 
-    		$avg_student_score           = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), $session_id);
+    		$avg_student_score = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), $session_id);
 
-    		$avg_student_progress        = Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $session_id);
+    		$avg_student_progress = Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $session_id);
     		if (empty($avg_student_progress)) {
     			$avg_student_progress=0;
     		}
@@ -3650,7 +3655,6 @@ class TrackingCourseLog {
             $total_user_exercise = Tracking::get_exercise_student_average_best_attempt($total_exercises, $user['user_id'], $course_code, $session_id);
             $user['exercise_average_best_attempt']  = $total_user_exercise;
 
-
     		if (is_numeric($avg_student_score)) {
     			$user['student_score']  = $avg_student_score.'%';
     		} else {
@@ -3684,11 +3688,11 @@ class TrackingCourseLog {
 
             $user_row[]= $user['official_code']; //0
             if ($is_western_name_order) {
-                $user_row[]= $user['lastname'];
                 $user_row[]= $user['firstname'];
+                $user_row[]= $user['lastname'];
             } else {
-                $user_row[]= $user['firstname'];
                 $user_row[]= $user['lastname'];
+                $user_row[]= $user['firstname'];
             }
             $user_row[]= $user['username'];
             $user_row[]= $user['time'];

+ 158 - 17
main/inc/lib/urlmanager.lib.php

@@ -264,6 +264,37 @@ class UrlManager
         return $courses;
     }
 
+    /**
+     * Gets the inner join of access_url and the usergroup table
+     *
+     * @author Julio Montoya
+     * @param int  access url id
+     * @return array   Database::store_result of the result
+     **/
+
+    public static function getUrlRelCourseCategory($access_url_id = null)
+    {
+
+        $table_url_rel = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
+        $table = Database::get_main_table(TABLE_MAIN_CATEGORY);
+        $where = " WHERE 1=1 ";
+        if (!empty($access_url_id)) {
+            $where .= " AND $table_url_rel.access_url_id = ".intval($access_url_id);
+        }
+        $where .= " AND (parent_id IS NULL) ";
+
+        $sql = "SELECT id, name, access_url_id
+            FROM $table u
+            INNER JOIN $table_url_rel
+            ON $table_url_rel.course_category_id = u.id
+            $where
+            ORDER BY name";
+
+        $result = Database::query($sql);
+        $courses = Database::store_result($result, 'ASSOC');
+        return $courses;
+    }
+
     /**
      * Sets the status of an URL 1 or 0
      * @author Julio Montoya
@@ -500,22 +531,6 @@ class UrlManager
         return $num;
     }
 
-    /**
-     * @param int $categoryCourseId
-     * @param int $urlId
-     * @return int
-     */
-    public static function addCourseCategoryToUrl($categoryCourseId, $urlId)
-    {
-        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
-        $sql = "INSERT INTO $table SET
-                course_category_id = '".intval($categoryCourseId)."',
-                access_url_id = ".intval($urlId);
-        Database::query($sql);
-        return Database::insert_id();
-    }
-
-
     /**
      * @param int $userGroupId
      * @param int $urlId
@@ -532,6 +547,27 @@ class UrlManager
         return Database::insert_id();
     }
 
+    /**
+     * @param int $categoryId
+     * @param int $urlId
+     * @return int
+     */
+    public static function addCourseCategoryToUrl($categoryId, $urlId)
+    {
+        $exists = self::relationUrlCourseCategoryExist($categoryId, $urlId);
+        if (empty($exists)) {
+            $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
+
+            $sql = "INSERT INTO $table
+                    SET
+                    course_category_id = '".intval($categoryId)."',
+                    access_url_id = ".intval($urlId);
+            Database::query($sql);
+
+            return Database::insert_id();
+        }
+        return 0;
+    }
 
     /**
      * Add a group of sessions into a group of URLs
@@ -618,7 +654,7 @@ class UrlManager
             $url_id=1;
         }
         $result = false;
-        $count = UrlManager::relation_url_session_exist($session_id,$url_id);
+        $count = UrlManager::relation_url_session_exist($session_id, $url_id);
         $session_id	= intval($session_id);
         if (empty($count) && !empty($session_id)) {
             $url_id = intval($url_id);
@@ -680,6 +716,24 @@ class UrlManager
         return $result;
     }
 
+    /**
+     * Deletes an url and $userGroup relationship
+     * @author Julio Montoya
+     * @param  int $userGroupId
+     * @param  int $urlId
+     * @return boolean true if success
+     * */
+    public static function deleteUrlRelCourseCategory($userGroupId, $urlId)
+    {
+        $table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
+        $sql= "DELETE FROM $table
+               WHERE course_category_id = '".intval($userGroupId)."' AND
+                     access_url_id=".intval($urlId)."  ";
+        $result = Database::query($sql);
+        return $result;
+    }
+
+
 
     /**
     * Deletes an url and session relationship
@@ -813,6 +867,55 @@ class UrlManager
         }
     }
 
+    /**
+     * Updates the access_url_rel_course_category table with a given list
+     * @author Julio Montoya
+     * @param array course category list
+     * @param int access_url_id
+     **/
+    public static function updateUrlRelCourseCategory($list, $urlId)
+    {
+        $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
+
+        $sql = "SELECT course_category_id FROM $table WHERE access_url_id = ".intval($urlId);
+        $result = Database::query($sql);
+        $existingItems = array();
+
+        while ($row = Database::fetch_array($result)){
+            $existingItems[] = $row['course_category_id'];
+        }
+
+        // Adding
+
+        foreach ($list as $id) {
+            UrlManager::addCourseCategoryToUrl($id, $urlId);
+            $categoryInfo = getCategoryById($id);
+            $children = getChildren($categoryInfo['code']);
+            if (!empty($children)) {
+                foreach ($children as $category) {
+                    UrlManager::addCourseCategoryToUrl($category['id'], $urlId);
+                }
+            }
+        }
+
+        // Deleting old items
+        foreach ($existingItems as $id) {
+            if (!in_array($id, $list)) {
+                UrlManager::deleteUrlRelCourseCategory($id, $urlId);
+                $categoryInfo = getCategoryById($id);
+
+                $children = getChildren($categoryInfo['code']);
+                if (!empty($children)) {
+                    foreach ($children as $category) {
+                        UrlManager::deleteUrlRelCourseCategory($category['id'], $urlId);
+                    }
+                }
+            }
+        }
+    }
+
+
+
     /**
      * Updates the access_url_rel_session table with a given user list
      * @author Julio Montoya
@@ -894,4 +997,42 @@ class UrlManager
         $access_url_id = Database::result($result, 0, 0);
         return $access_url_id;
     }
+
+    /**
+     *
+     * @param string $needle
+     * @return XajaxResponse
+     */
+    public static function searchCourseCategoryAjax($needle)
+    {
+        $response = new XajaxResponse();
+        $return = '';
+
+        if (!empty($needle)) {
+            // xajax send utf8 datas... datas in db can be non-utf8 datas
+            $charset = api_get_system_encoding();
+            $needle = api_convert_encoding($needle, $charset, 'utf-8');
+            $needle = Database::escape_string($needle);
+            // search courses where username or firstname or lastname begins likes $needle
+            $sql = 'SELECT id, name FROM '.Database::get_main_table(TABLE_MAIN_CATEGORY).' u
+                    WHERE name LIKE "'.$needle.'%" AND (parent_id IS NULL or parent_id = 0)
+                    ORDER BY name
+                    LIMIT 11';
+            $result = Database::query($sql);
+            $i = 0;
+            while ($data = Database::fetch_array($result)) {
+                $i++;
+                if ($i <= 10) {
+                    $return .= '<a
+                    href="javascript: void(0);"
+                    onclick="javascript: add_user_to_url(\''.addslashes($data['id']).'\',\''.addslashes($data['name']).' \')">'.$data['name'].' </a><br />';
+                } else {
+                    $return .= '...<br />';
+                }
+            }
+        }
+        $response->addAssign('ajax_list_courses', 'innerHTML', api_utf8_encode($return));
+        return $response;
+    }
+
 }

+ 7 - 1
main/inc/lib/userportal.lib.php

@@ -782,7 +782,9 @@ class IndexManager {
         return $html;
     }
 
-	function return_profile_block() {
+	function return_profile_block()
+    {
+        global $_configuration;
 		$user_id = api_get_user_id();
 
 		if (empty($user_id)) {
@@ -818,6 +820,10 @@ class IndexManager {
 				$total_invitations = Display::badge($total_invitations);
 				$profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/invitations.php">'.get_lang('PendingInvitations').$total_invitations.'</a></li>';
 			}
+
+            if (isset($_configuration['allow_my_files_link_in_homepage']) && $_configuration['allow_my_files_link_in_homepage']) {
+                $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/social/myfiles.php">'.get_lang('MyFiles').'</a></li>';
+            }
         }
         $profile_content .= '<li><a href="'.api_get_path(WEB_PATH).'main/auth/profile.php">'.get_lang('EditProfile').'</a></li>';
         $profile_content .= '</ul>';

+ 17 - 10
main/newscorm/lp_upload.php

@@ -20,7 +20,6 @@ if (empty($_POST['current_dir'])) {
 }
 $uncompress = 1;
 
-//error_log('New LP - lp_upload.php', 0);
 /*
  * Check the request method in place of a variable from POST
  * because if the file size exceed the maximum file upload
@@ -30,7 +29,7 @@ $uncompress = 1;
 $user_file = Request::is_post() ? Request::file('user_file') : array();
 $user_file = $user_file ? $user_file : array();
 $is_error = isset($user_file['error']) ? $user_file['error'] : false;
-if( Request::is_post() && $is_error){
+if (Request::is_post() && $is_error) {
     return api_failure::set_failure('upload_file_too_big');
     unset($_FILEs['user_file']);
 } else if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && !empty($_FILES['user_file']['name'])) {
@@ -55,11 +54,11 @@ if( Request::is_post() && $is_error){
 
     $proximity = 'local';
     if (!empty($_REQUEST['content_proximity'])) {
-    	$proximity = Database::escape_string($_REQUEST['content_proximity']);
+        $proximity = Database::escape_string($_REQUEST['content_proximity']);
     }
     $maker = 'Scorm';
     if (!empty($_REQUEST['content_maker'])) {
-    	$maker = Database::escape_string($_REQUEST['content_maker']);
+        $maker = Database::escape_string($_REQUEST['content_maker']);
     }
 
     switch ($type) {
@@ -108,7 +107,7 @@ if( Request::is_post() && $is_error){
         default:
             return api_failure::set_failure('not_a_learning_path');
     }
-} elseif($_SERVER['REQUEST_METHOD'] == 'POST') {
+} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
     // end if is_uploaded_file
 
     // If file name given to get in claroline/upload/, try importing this way.
@@ -142,7 +141,7 @@ if( Request::is_post() && $is_error){
             require_once 'scorm.class.php';
             $oScorm = new scorm();
             $manifest = $oScorm->import_local_package($s, $current_dir);
-            if ($manifest === false ) { //if ap i_set_failure
+            if ($manifest === false) { //if ap i_set_failure
                 return api_failure::set_failure(api_failure::get_last_failure());
             }
             if (!empty($manifest)) {
@@ -151,9 +150,13 @@ if( Request::is_post() && $is_error){
             }
 
             $proximity = '';
-            if (!empty($_REQUEST['content_proximity'])) { $proximity = Database::escape_string($_REQUEST['content_proximity']); }
+            if (!empty($_REQUEST['content_proximity'])) {
+                $proximity = Database::escape_string($_REQUEST['content_proximity']);
+            }
             $maker = '';
-            if (!empty($_REQUEST['content_maker'])) {$maker = Database::escape_string($_REQUEST['content_maker']); }
+            if (!empty($_REQUEST['content_maker'])) {
+                $maker = Database::escape_string($_REQUEST['content_maker']);
+            }
             $oScorm->set_proximity($proximity);
             $oScorm->set_maker($maker);
             $oScorm->set_jslib('scorm_api.php');
@@ -167,9 +170,13 @@ if( Request::is_post() && $is_error){
                 $oAICC->import_aicc(api_get_course_id());
             }
             $proximity = '';
-            if (!empty($_REQUEST['content_proximity'])) { $proximity = Database::escape_string($_REQUEST['content_proximity']); }
+            if (!empty($_REQUEST['content_proximity'])) {
+                $proximity = Database::escape_string($_REQUEST['content_proximity']);
+            }
             $maker = '';
-            if (!empty($_REQUEST['content_maker'])) { $maker = Database::escape_string($_REQUEST['content_maker']); }
+            if (!empty($_REQUEST['content_maker'])) {
+                $maker = Database::escape_string($_REQUEST['content_maker']);
+            }
             $oAICC->set_proximity($proximity);
             $oAICC->set_maker($maker);
             $oAICC->set_jslib('aicc_api.php');

+ 26 - 18
main/newscorm/openoffice_document.class.php

@@ -7,13 +7,15 @@
  * to help in the conversion of Office documents to learning paths
  * @package chamilo.learnpath
  * @author	Eric Marguin <eric.marguin@dokeos.com>
+ * @author Julio Montoya
  * @license	GNU/GPL
  */
 
 /**
  * Defines the "OpenofficeDocument" child of class "learnpath"
  */
-abstract class OpenofficeDocument extends learnpath {
+abstract class OpenofficeDocument extends learnpath
+{
 
     public $first_item = 0;
     public $original_charset = 'utf-8';
@@ -25,31 +27,36 @@ abstract class OpenofficeDocument extends learnpath {
      * @param	integer	Learnpath ID in DB
      * @param	integer	User ID
      */
-    public function __construct($course_code = null, $resource_id = null, $user_id = null) {
+    public function __construct($course_code = null, $resource_id = null, $user_id = null)
+    {
         if ($this->debug > 0) {
             error_log('In OpenofficeDocument::OpenofficeDocument()', 0);
         }
         if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) {
             parent::__construct($course_code, $resource_id, $user_id);
-        } else {
-            // Do nothing but still build the presentation object.
         }
     }
 
-    public function convert_document($file, $action_after_conversion = 'make_lp') {
-        global $_course, $_user, $_configuration;
-        $this->file_name = pathinfo($file['name'], PATHINFO_FILENAME);        
+    /**
+     * @param string $file
+     * @param string $action_after_conversion
+     * @return bool|int
+     */
+    public function convert_document($file, $action_after_conversion = 'make_lp')
+    {
+        global $_course;
+        $this->file_name = pathinfo($file['name'], PATHINFO_FILENAME);
         // Create the directory
-        $result = $this->generate_lp_folder($_course, $this->file_name);                        
-                
+        $result = $this->generate_lp_folder($_course, $this->file_name);
+
          // Create the directory
         $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
         ///learning_path/ppt_dirname directory
-        $this->created_dir = substr($result['dir'], 0, strlen($result['dir']) -1);        
+        $this->created_dir = substr($result['dir'], 0, strlen($result['dir']) -1);
         $this->file_path = $this->created_dir.'/'.replace_dangerous_char($file['name'], 'strict');
-        
+
         //var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir);
-    
+
         /*
          * Original code
         global $_course, $_user, $_configuration;
@@ -69,9 +76,9 @@ abstract class OpenofficeDocument extends learnpath {
         $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 
         $this->created_dir = create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), 0, 0, $this->base_work_dir, $dir_name);
-       
+
             var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir);
-        
+
         */
 
         $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');
@@ -96,7 +103,7 @@ abstract class OpenofficeDocument extends learnpath {
             $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
             // Call to the function implemented by child.
             $cmd .= $this->add_command_parameters();
-            // To allow openoffice to manipulate docs.            
+            // To allow openoffice to manipulate docs.
             @chmod($this->base_work_dir, 0777);
             @chmod($this->base_work_dir.$this->created_dir, 0777);
             @chmod($this->base_work_dir.$this->file_path, 0777);
@@ -107,7 +114,7 @@ abstract class OpenofficeDocument extends learnpath {
             $files = array();
             $return = 0;
             $shell = exec($cmd, $files, $return);
-            
+
             if ($return != 0) { // If the java application returns an error code.
                 switch ($return) {
                     // Can't connect to openoffice.
@@ -141,7 +148,7 @@ abstract class OpenofficeDocument extends learnpath {
             // files info
             $files = $result['files'];
         }
-        
+
         if (!empty($files)) {
             // Create lp
             $this->lp_id = learnpath::add_lp($_course['id'], $this->file_name, '', 'guess', 'manual');
@@ -165,7 +172,8 @@ abstract class OpenofficeDocument extends learnpath {
      * @param   array current ppt file
      * @return  array images files
      */
-    private function _get_remote_ppt2lp_files($file) {
+    private function _get_remote_ppt2lp_files($file)
+    {
         require_once api_get_path(LIBRARY_PATH) . 'nusoap/nusoap.php';
         // host
         $ppt2lp_host = api_get_setting('service_ppt2lp', 'host');

+ 59 - 19
main/newscorm/openoffice_presentation.class.php

@@ -20,17 +20,19 @@ if (api_get_setting('search_enabled') == 'true') {
     require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
 }
 
-class OpenofficePresentation extends OpenofficeDocument {
+class OpenofficePresentation extends OpenofficeDocument
+{
 
     public $take_slide_name;
 
-    public function __construct($take_slide_name = false, $course_code = null, $resource_id = null, $user_id = null) {
+    public function __construct($take_slide_name = false, $course_code = null, $resource_id = null, $user_id = null)
+    {
         $this->take_slide_name = $take_slide_name;
         parent::__construct($course_code, $resource_id, $user_id);
     }
 
-
-    public function make_lp($files = array()) {
+    public function make_lp($files = array())
+    {
         global $_course;
         $previous = 0;
         $i = 0;
@@ -39,8 +41,10 @@ class OpenofficePresentation extends OpenofficeDocument {
             return false;
 
         foreach ($files as $file) {
-
-            list($slide_name, $file_name, $slide_body) = explode('||', $file); // '||' is used as separator between fields: slide name (with accents) || file name (without accents) || all slide text (to be indexed).
+            /* '||' is used as separator between fields:
+                slide name (with accents) || file name (without accents) || all slide text (to be indexed).
+            */
+            list($slide_name, $file_name, $slide_body) = explode('||', $file);
 
             // Filename is utf8 encoded, but when we decode, some chars are not translated (like quote &rsquo;).
             // so we remove these chars by translating it in htmlentities and the reconvert it in want charset.
@@ -58,8 +62,26 @@ class OpenofficePresentation extends OpenofficeDocument {
 
             $i++;
             // Add the png to documents.
-            $document_id = add_document($_course, $this->created_dir.'/'.urlencode($file_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$file_name), $slide_name);
-            api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id(), 0, 0, null, null, api_get_session_id());
+            $document_id = add_document(
+                $_course,
+                $this->created_dir.'/'.urlencode($file_name),
+                'file',
+                filesize($this->base_work_dir.$this->created_dir.'/'.$file_name),
+                $slide_name
+            );
+
+            api_item_property_update(
+                $_course,
+                TOOL_DOCUMENT,
+                $document_id,
+                'DocumentAdded',
+                api_get_user_id(),
+                0,
+                0,
+                null,
+                null,
+                api_get_session_id()
+            );
 
             // Generating the thumbnail.
             $image = $this->base_work_dir.$this->created_dir .'/'. $file_name;
@@ -67,21 +89,28 @@ class OpenofficePresentation extends OpenofficeDocument {
             $pattern = '/(\w+)\.png$/';
             $replacement = '${1}_thumb.png';
             $thumb_name = preg_replace($pattern, $replacement, $file_name);
-            
+
             // Calculate thumbnail size.
             $image_size = api_getimagesize($image);
             $width  = $image_size['width'];
             $height = $image_size['height'];
-            
+
             $thumb_width = 300;
             $thumb_height = floor($height * ($thumb_width / $width));
-  
+
             $my_new_image = new Image($image);
             $my_new_image->resize($thumb_width, $thumb_height);
             $my_new_image->send_image($this->base_work_dir.$this->created_dir .'/'. $thumb_name, -1, 'png');
-  
+
             // Adding the thumbnail to documents.
-            $document_id_thumb = add_document($_course, $this->created_dir.'/'.urlencode($thumb_name), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$thumb_name), $slide_name);
+            $document_id_thumb = add_document(
+                $_course,
+                $this->created_dir.'/'.urlencode($thumb_name),
+                'file',
+                filesize($this->base_work_dir.$this->created_dir.'/'.$thumb_name),
+                $slide_name
+            );
+
             api_item_property_update($_course, TOOL_THUMBNAIL, $document_id_thumb, 'DocumentAdded', api_get_user_id(), 0, 0);
 
             // Create an html file.
@@ -100,7 +129,14 @@ class OpenofficePresentation extends OpenofficeDocument {
 </html>');  // This indentation is to make the generated html files to look well.
 
             fclose($fp);
-            $document_id = add_document($_course,$this->created_dir.'/'.urlencode($html_file), 'file', filesize($this->base_work_dir.$this->created_dir.'/'.$html_file), $slide_name);
+            $document_id = add_document(
+                $_course,
+                $this->created_dir.'/'.urlencode($html_file),
+                'file',
+                filesize($this->base_work_dir.$this->created_dir.'/'.$html_file),
+                $slide_name
+            );
+
             if ($document_id) {
 
                 // Put the document in item_property update.
@@ -114,7 +150,7 @@ class OpenofficePresentation extends OpenofficeDocument {
             // Code for text indexing.
             if (api_get_setting('search_enabled') == 'true') {
 
-                if (isset($_POST['index_document']) && $_POST['index_document']) {                    
+                if (isset($_POST['index_document']) && $_POST['index_document']) {
                     $di = new ChamiloIndexer();
                     isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english';
                     $di->connectDb(NULL, NULL, $lang);
@@ -165,18 +201,22 @@ class OpenofficePresentation extends OpenofficeDocument {
         }
     }
 
-    function add_command_parameters() {
-        if (empty($this->slide_width) || empty($this->slide_height))
+    function add_command_parameters()
+    {
+        if (empty($this->slide_width) || empty($this->slide_height)) {
             list($this->slide_width, $this->slide_height) = explode('x', api_get_setting('service_ppt2lp', 'size'));
+        }
         return ' -w '.$this->slide_width.' -h '.$this->slide_height.' -d oogie "'.$this->base_work_dir.'/'.$this->file_path.'"  "'.$this->base_work_dir.$this->created_dir.'.html"';
     }
 
-    function set_slide_size($width, $height) {
+    function set_slide_size($width, $height)
+    {
         $this->slide_width = $width;
         $this->slide_height = $height;
     }
 
-    function add_docs_to_visio($files = array()) {
+    function add_docs_to_visio($files = array())
+    {
         global $_course;
         foreach ($files as $file) {
             list($slide_name,$file_name) = explode('||',$file); // '||' is used as separator between slide name (with accents) and file name (without accents).

+ 132 - 101
main/survey/survey.lib.php

@@ -24,7 +24,8 @@ $htmlHeadXtra[] = '<script>
 		});
 </script>';
 
-class survey_manager {
+class survey_manager
+{
 
     /**
      * Deletes all survey invitations of a user
@@ -32,15 +33,16 @@ class survey_manager {
      * @return boolean
      * @assert ('') === false
      */
-    public static function delete_all_survey_invitations_by_user($user_id) {
+    public static function delete_all_survey_invitations_by_user($user_id)
+    {
         $user_id = intval($user_id);
-       
+
         if (empty($user_id)) {
             return false;
         }
         $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION);
         $table_survey = Database :: get_course_table(TABLE_SURVEY);
-        
+
         $sql = "SELECT survey_invitation_id, survey_code FROM $table_survey_invitation WHERE user = '$user_id' AND c_id <> 0 ";
         $result = Database::query($sql);
         $deleted = array();
@@ -55,6 +57,7 @@ class survey_manager {
             }
         }
     }
+
     /**
      *
      * @param type $course_code
@@ -62,7 +65,8 @@ class survey_manager {
      * @return type
      * @assert ('') === false
      */
-    public static function get_surveys($course_code, $session_id = 0) {
+    public static function get_surveys($course_code, $session_id = 0)
+    {
         $table_survey = Database :: get_course_table(TABLE_SURVEY);
         if (empty($course_code)) {
             return false;
@@ -90,7 +94,8 @@ class survey_manager {
 	 *
 	 * @todo this is the same function as in create_new_survey.php
 	 */
-	static function get_survey($survey_id, $shared = 0, $course_code = '') {
+    public static function get_survey($survey_id, $shared = 0, $course_code = '')
+    {
 		global $_course;
 
 		// Table definition
@@ -147,7 +152,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version February 2007
 	 */
-	static function store_survey($values) {
+    public static function store_survey($values) {
 		global $_user;
 
 		// Table defnitions
@@ -343,7 +348,7 @@ class survey_manager {
 							surveythanks	= '".Database::escape_string($values['survey_thanks'])."',
 							anonymous       = '".Database::escape_string($values['anonymous'])."'".$additionalsets."
 					WHERE c_id = $course_id AND survey_id = '".Database::escape_string($values['survey_id'])."'";
-			$result = Database::query($sql);
+			Database::query($sql);
 
 			// Update into item_property (update)
 			api_item_property_update(api_get_course_info(), TOOL_SURVEY, $values['survey_id'], 'SurveyUpdated', api_get_user_id());
@@ -364,7 +369,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version February 2007
 	 */
-	function store_shared_survey($values) {
+    public function store_shared_survey($values) {
 		global $_user, $_course;
 
 		// Table defnitions
@@ -410,7 +415,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	static function delete_survey($survey_id, $shared = false, $course_id = '') {
+    public static function delete_survey($survey_id, $shared = false, $course_id = '') {
 		// Database table definitions
         if (empty($course_id)) {
             $course_id = api_get_course_int_id();
@@ -450,7 +455,8 @@ class survey_manager {
 		return true;
 	}
 
-	function copy_survey($parent_survey, $new_survey_id) {
+    public function copy_survey($parent_survey, $new_survey_id)
+    {
 	    $course_id = api_get_course_int_id();
 
 		// Database table definitions
@@ -504,7 +510,7 @@ class survey_manager {
 	 * @author Eric Marguin <e.marguin@elixir-interactive.com>, Elixir Interactive
 	 * @version October 2007
 	 */
-	function empty_survey($survey_id) {
+    public function empty_survey($survey_id) {
 		// Database table definitions
 		$table_survey_invitation      = Database :: get_course_table(TABLE_SURVEY_INVITATION);
 		$table_survey_answer          = Database :: get_course_table(TABLE_SURVEY_ANSWER);
@@ -539,7 +545,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version February 2007
 	 */
-	static function update_survey_answered($survey_data, $user, $survey_code) {
+    public static function update_survey_answered($survey_data, $user, $survey_code) {
 		// Database table definitions
 		$table_survey 				= Database :: get_course_table(TABLE_SURVEY);
 		$table_survey_invitation 	= Database :: get_course_table(TABLE_SURVEY_INVITATION);
@@ -574,13 +580,13 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version February 2007
 	 */
-	static function get_complete_survey_structure($survey_id, $shared = 0) {
+    public static function get_complete_survey_structure($survey_id, $shared = 0) {
 		$structure = survey_manager::get_survey($survey_id, $shared);
 		$structure['questions'] = survey_manager::get_questions($survey_id);
 	}
 
 	/***
-	 * SYRVEY QUESTION FUNCTIONS
+	 * SURVEY QUESTION FUNCTIONS
 	 */
 
 	/**
@@ -589,7 +595,8 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version February 2007
 	 */
-	static function icon_question($type) {
+    public static function icon_question($type)
+    {
 		// the possible question types
 		$possible_types = array('personality', 'yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak', 'percentage', 'score');
 
@@ -625,7 +632,7 @@ class survey_manager {
 	 *
 	 * @todo one sql call should do the trick
 	 */
-	static function get_question($question_id, $shared = false) {
+    public static function get_question($question_id, $shared = false) {
 		// Table definitions
 		$tbl_survey_question 			= Database :: get_course_table(TABLE_SURVEY_QUESTION);
 		$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
@@ -687,7 +694,7 @@ class survey_manager {
 	 *
 	 * @todo one sql call should do the trick
 	 */
-	static function get_questions($survey_id) {
+    public static function get_questions($survey_id) {
 		// Table definitions
 		$tbl_survey_question 			= Database :: get_course_table(TABLE_SURVEY_QUESTION);
 		$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
@@ -728,7 +735,8 @@ class survey_manager {
 	 * @version January 2007
 	 */
 
-	function save_question($form_content) {
+    public function save_question($form_content)
+    {
 		global $survey_data;
 
 		if (strlen($form_content['question']) > 1) { // Checks lenght of the question
@@ -868,7 +876,8 @@ class survey_manager {
 	 *
 	 * @todo editing of a shared question
 	 */
-	function save_shared_question($form_content, $survey_data) {
+    public function save_shared_question($form_content, $survey_data)
+    {
 		global $_course;
 
 			// Table definitions
@@ -922,7 +931,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	static function move_survey_question($direction, $survey_question_id, $survey_id) {
+    public static function move_survey_question($direction, $survey_question_id, $survey_id) {
 		// Table definition
 		$table_survey_question 	= Database :: get_course_table(TABLE_SURVEY_QUESTION);
 
@@ -953,12 +962,11 @@ class survey_manager {
 		}
 
 		$sql1 = "UPDATE $table_survey_question SET sort = '".Database::escape_string($question_sort_two)."' WHERE c_id = $course_id AND  question_id='".Database::escape_string($question_id_one)."'";
-		$result = Database::query($sql1);
+		Database::query($sql1);
 		$sql2 = "UPDATE $table_survey_question SET sort = '".Database::escape_string($question_sort_one)."' WHERE c_id = $course_id AND question_id='".Database::escape_string($question_id_two)."'";
-		$result = Database::query($sql2);
+		Database::query($sql2);
 	}
 
-
 	/**
 	 * This function deletes all the questions of a given survey
 	 * This function is normally only called when a survey is deleted
@@ -969,7 +977,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	static function delete_all_survey_questions($survey_id, $shared = false) {
+    public static function delete_all_survey_questions($survey_id, $shared = false) {
 	    $course_id = api_get_course_int_id();
 
 		// Table definitions
@@ -1005,7 +1013,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version March 2007
 	 */
-	static function delete_survey_question($survey_id, $question_id, $shared = false) {
+    public static function delete_survey_question($survey_id, $question_id, $shared = false) {
         $course_id = api_get_course_int_id();
 		// Table definitions
 		$table_survey_question 	= Database :: get_course_table(TABLE_SURVEY_QUESTION);
@@ -1032,7 +1040,7 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version March 2007
 	 */
-	static function delete_shared_survey_question($survey_id, $question_id) {
+    public static function delete_shared_survey_question($survey_id, $question_id) {
 		// Table definitions
 		$table_survey_question 	      = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION);
 		$table_survey_question_option = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
@@ -1062,7 +1070,8 @@ class survey_manager {
 	 *
 	 * @todo writing the update statement when editing a question
 	 */
-	function save_question_options($form_content, $survey_data) {
+    public function save_question_options($form_content, $survey_data)
+    {
 	    $course_id = api_get_course_int_id();
 		// A percentage question type has options 1 -> 100
 		if ($form_content['type'] == 'percentage') {
@@ -1081,7 +1090,7 @@ class survey_manager {
 		// We are editing a question so we first have to remove all the existing options from the database
 		if (is_numeric($form_content['question_id'])) {
 			$sql = "DELETE FROM $table_survey_question_option WHERE c_id = $course_id AND question_id = '".Database::escape_string($form_content['question_id'])."'";
-			$result = Database::query($sql);
+			Database::query($sql);
 		}
 
 		$counter = 1;
@@ -1095,7 +1104,7 @@ class survey_manager {
 								'".Database::escape_string($form_content['answers'][$i])."',
 								'".Database::escape_string($form_content['values'][$i])."',
 								'".Database::escape_string($counter)."')";
-				$result = Database::query($sql);
+				Database::query($sql);
 				$counter++;
 			}
 		}
@@ -1111,7 +1120,8 @@ class survey_manager {
 	 *
 	 * @todo writing the update statement when editing a question
 	 */
-	function save_shared_question_options($form_content, $survey_data) {
+    public function save_shared_question_options($form_content, $survey_data)
+    {
 		if (is_array($form_content) && is_array($form_content['answers'])) {
 			// Table defintion
 			$table_survey_question_option 	= Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION);
@@ -1134,13 +1144,6 @@ class survey_manager {
 		}
 	}
 
-	/*
-		if (is_numeric($survey_data['survey_share']) AND $survey_data['survey_share'] != 0) {
-			$form_content = survey_manager::save_shared_question($form_content, $survey_data);
-		}
-	*/
-
-
 	/**
 	 * This function deletes all the options of the questions of a given survey
 	 * This function is normally only called when a survey is deleted
@@ -1151,7 +1154,8 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	static function delete_all_survey_questions_options($survey_id, $shared = false) {
+	static function delete_all_survey_questions_options($survey_id, $shared = false)
+    {
 
 		// Table definitions
 		$table_survey_question_option 	= Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
@@ -1173,15 +1177,17 @@ class survey_manager {
 	/**
 	 * This function deletes the options of a given question
 	 *
-	 * @param unknown_type $survey_id
-	 * @param unknown_type $question_id
-	 * @param unknown_type $shared
-	 * @return unknown
+	 * @param int $survey_id
+	 * @param int $question_id
+	 * @param int $shared
+	 * @return bool
 	 *
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+     * @author Julio Montoya
 	 * @version March 2007
 	 */
-	static function delete_survey_question_option($survey_id, $question_id, $shared = false) {
+    public static function delete_survey_question_option($survey_id, $question_id, $shared = false)
+    {
 	    $course_id = api_get_course_int_id();
         $course_condition = " c_id = $course_id AND ";
 
@@ -1194,7 +1200,7 @@ class survey_manager {
 
 		// Deleting the options of the survey questions
 		$sql = "DELETE from $table_survey_question_option WHERE $course_condition survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'";
-		$res = Database::query($sql);
+		Database::query($sql);
 		return true;
 	}
 
@@ -1214,7 +1220,8 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007,december 2008
 	 */
-	static function delete_all_survey_answers($survey_id) {
+    public static function delete_all_survey_answers($survey_id)
+    {
         $course_id = api_get_course_int_id();
 		$table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER);
 		$survey_id = intval($survey_id);
@@ -1222,7 +1229,14 @@ class survey_manager {
 		return true;
 	}
 
-	static function is_user_filled_survey($user_id, $survey_id, $course_id) {
+    /**
+     * @param int $user_id
+     * @param int $survey_id
+     * @param int $course_id
+     * @return bool
+     */
+    public static function is_user_filled_survey($user_id, $survey_id, $course_id)
+    {
 		$table_survey_answer 		= Database :: get_course_table(TABLE_SURVEY_ANSWER);
 
 		$user_id	= intval($user_id);
@@ -1238,7 +1252,6 @@ class survey_manager {
 			return true;
 		}
 		return false;
-
 	}
 
 	/**
@@ -1250,7 +1263,8 @@ class survey_manager {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version February 2007
 	 */
-	static function get_people_who_filled_survey($survey_id, $all_user_info = false, $course_id = null) {
+	static function get_people_who_filled_survey($survey_id, $all_user_info = false, $course_id = null)
+    {
 
 		// Database table definition
 		$table_survey_answer 		= Database :: get_course_table(TABLE_SURVEY_ANSWER);
@@ -1292,19 +1306,22 @@ class survey_manager {
 		return $return;
 	}
 
-    static function survey_generation_hash_available() {
+    static function survey_generation_hash_available()
+    {
         if (extension_loaded('mcrypt')) {
             return true;
         }
         return false;
     }
 
-    static function generate_survey_hash($survey_id, $course_id, $session_id, $group_id) {
+    static function generate_survey_hash($survey_id, $course_id, $session_id, $group_id)
+    {
         $hash = hash('sha512', api_get_security_key().'_'.$course_id.'_'.$session_id.'_'.$group_id.'_'.$survey_id);
         return $hash;
     }
 
-    static function validate_survey_hash($survey_id, $course_id, $session_id, $group_id, $hash) {
+    static function validate_survey_hash($survey_id, $course_id, $session_id, $group_id, $hash)
+    {
         $survey_generated_hash = self::generate_survey_hash($survey_id, $course_id, $session_id, $group_id);
         if ($survey_generated_hash == $hash) {
             return true;
@@ -1312,14 +1329,16 @@ class survey_manager {
         return false;
     }
 
-    static function generate_survey_link($survey_id, $course_id, $session_id, $group_id) {
+    static function generate_survey_link($survey_id, $course_id, $session_id, $group_id)
+    {
         $code = self::generate_survey_hash($survey_id, $course_id, $session_id, $group_id);
         return api_get_path(WEB_CODE_PATH).'survey/link.php?h='.$code.'&i='.$survey_id.'&c='.intval($course_id).'&s='.intval($session_id).'&g='.$group_id;
     }
 }
 
 
-class survey_question {
+class survey_question
+{
 
 	// The html code of the form
 	public $html;
@@ -1333,7 +1352,8 @@ class survey_question {
 	 * @todo the form_text has to become a wysiwyg editor or adding a question_comment field
 	 * @todo consider adding a question_comment form element
 	 */
-	function create_form($form_content) {
+	function create_form($form_content)
+    {
 
 		global $survey_data;
 
@@ -1371,15 +1391,6 @@ class survey_question {
 		$this->html .= '		</div>';
 		$this->html .= '	</div>';
 
-		/*
-		$this->html .= '	<tr>';
-		$this->html .= '		<td><label for="question_comment">'.get_lang('QuestionComment').'</label></td>';
-		$this->html .= '		<td><input type="text" name="question_comment" id="question_comment" value="'.$form_content['question_comment'].'"/></td>';
-		$this->html .= '		<td>&nbsp;</td>';
-		$this->html .= '	</tr>';
-		*/
-
-
 		if ($survey_data['survey_type'] == 1) {
 			$table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
 			$sql = 'SELECT id,name FROM '.$table_survey_question_group.' WHERE survey_id = '.(int)$_GET['survey_id'].' ORDER BY name';
@@ -1429,7 +1440,8 @@ class survey_question {
 	 * @version January 2007
 	 *
 	 */
-	function render_form() {
+	function render_form()
+    {
 		if (isset($_GET['question_id']) and !empty($_GET['question_id'])) {
 			$class = 'save';
 			$text = get_lang('ModifyQuestionSurvey');
@@ -1460,7 +1472,8 @@ class survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function handle_action($form_content) {
+	function handle_action($form_content)
+    {
 	    $course_id = api_get_course_int_id();
 		global $config;
 
@@ -1551,14 +1564,16 @@ class survey_question {
 	 * @return html code
 	 *
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+     * @author Julio Montoya - 2013
 	 * @version January 2007
 	 */
-	function add_remove_buttons($form_content) {
+	function add_remove_buttons($form_content)
+    {
 		if (count($form_content['answers']) <= 2) {
 			$remove_answer_attribute = 'disabled="disabled"';
 		}
 
-		$return .= '	<div class="row">';
+		$return = '	<div class="row">';
 		$return .= '		<div class="formw">';
 		$return .= '		<input type="hidden" name="is_executable" id="is_executable" value="-" />';
 		$return .= '			<button class="minus" type="submit" name="remove_answer" "'.$remove_answer_attribute.'">'.get_lang('RemoveAnswer').' </button>';
@@ -1576,13 +1591,15 @@ class survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function render_question($form_content) {
+	function render_question($form_content)
+    {
 		$this->html = '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.intval($_GET['survey_id']).'">';
 		echo $this->html;
 	}
 }
 
-class ch_yesno extends survey_question {
+class ch_yesno extends survey_question
+{
 
 	/**
 	 * This function creates the form elements for the yesno questions
@@ -1590,7 +1607,8 @@ class ch_yesno extends survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function create_form($form_content) {
+	function create_form($form_content)
+    {
 		$this->html = parent::create_form($form_content);
 		// Horizontal or vertical
 		$this->html .= '	<div class="control-group">';
@@ -1643,7 +1661,8 @@ class ch_yesno extends survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function render_question($form_content, $answers = array()) {
+	function render_question($form_content, $answers = array())
+    {
 
 		if (is_array($form_content['options'])) { // Check if data is correct
 			foreach ($form_content['options'] as $key => & $value) {
@@ -1677,7 +1696,8 @@ class ch_yesno extends survey_question {
 	}
 }
 
-class ch_multiplechoice extends survey_question {
+class ch_multiplechoice extends survey_question
+{
 
 	/**
 	 * This function creates the form elements for the multiple choice questions
@@ -1685,7 +1705,8 @@ class ch_multiplechoice extends survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function create_form($form_content) {
+	function create_form($form_content)
+    {
 
 		$this->html = parent::create_form($form_content);
 		// Horizontal or vertical
@@ -1753,13 +1774,15 @@ class ch_multiplechoice extends survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function render_question($form_content, $answers = array()) {
+	function render_question($form_content, $answers = array())
+    {
 		$question = new ch_yesno();
 		$question->render_question($form_content, $answers);
 	}
 }
 
-class ch_personality extends survey_question {
+class ch_personality extends survey_question
+{
 
 	/**
 	 * This function creates the form elements for the multiple response questions
@@ -1767,7 +1790,8 @@ class ch_personality extends survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function create_form($form_content) {
+	function create_form($form_content)
+    {
 		$this->html = parent::create_form($form_content);
 		$this->html .= '	<tr>';
 		$this->html .= '		<td colspan="2"><strong>'.get_lang('DisplayAnswersHorVert').'</strong></td>';
@@ -1854,7 +1878,8 @@ class ch_personality extends survey_question {
 	}
 }
 
-class ch_multipleresponse extends survey_question {
+class ch_multipleresponse extends survey_question
+{
 
 	/**
 	 * This function creates the form elements for the multiple response questions
@@ -1959,7 +1984,8 @@ class ch_multipleresponse extends survey_question {
 	}
 }
 
-class ch_dropdown extends survey_question {
+class ch_dropdown extends survey_question
+{
 
 	/**
 	 * This function creates the form elements for the dropdown questions
@@ -1967,7 +1993,8 @@ class ch_dropdown extends survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function create_form($form_content) {
+	function create_form($form_content)
+    {
 
 		$this->html = parent::create_form($form_content);
 		// The answers
@@ -2010,7 +2037,8 @@ class ch_dropdown extends survey_question {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	function render_question($form_content, $answers = array()) {
+	function render_question($form_content, $answers = array())
+    {
 		foreach ($form_content['options'] as $key => & $value) {
 			$this->html .= '<option value="'.$key.'" ';
 			if (is_array($answers)) {
@@ -2036,7 +2064,8 @@ class ch_dropdown extends survey_question {
 }
 
 
-class ch_open extends survey_question {
+class ch_open extends survey_question
+{
 
 	/**
 	 * This function creates the form elements for the open questions
@@ -4173,7 +4202,8 @@ class SurveyUtil {
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version January 2007
 	 */
-	static function display_survey_list() {
+	static function display_survey_list()
+    {
 		$parameters = array();
 		$parameters['cidReq'] = api_get_course_id();
 		if (isset($_GET['do_search']) && $_GET['do_search']) {
@@ -4366,17 +4396,18 @@ class SurveyUtil {
 	/**
 	 * This function gets all the survey data that is to be displayed in the sortable table
 	 *
-	 * @param unknown_type $from
-	 * @param unknown_type $number_of_items
-	 * @param unknown_type $column
-	 * @param unknown_type $direction
+	 * @param int $from
+	 * @param int $number_of_items
+	 * @param int $column
+	 * @param string $direction
 	 * @return unknown
 	 *
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @author Julio Montoya <gugli100@gmail.com>, Beeznest - Adding intvals
 	 * @version January 2007
 	 */
-	static function get_survey_data($from, $number_of_items, $column, $direction) {
+	static function get_survey_data($from, $number_of_items, $column, $direction)
+    {
 		global $table_survey, $table_user, $table_survey_question;
 		global $_user;
 
@@ -4395,25 +4426,25 @@ class SurveyUtil {
 		// Condition for the session
 		$session_id = api_get_session_id();
 		$condition_session = api_get_session_condition($session_id);
-
 		$course_id = api_get_course_int_id();
 
-
 		$sql = "SELECT
-					survey.survey_id							AS col0,
-					CONCAT('<a href=\"survey.php?survey_id=',survey.survey_id,'\">',survey.title,'</a>')		AS col1,
-					survey.code									AS col2,
-					count(survey_question.question_id)			AS col3,
+					survey.survey_id AS col0,
+					CONCAT('<a href=\"survey.php?survey_id=',survey.survey_id,'\">',survey.title,'</a>') AS col1,
+					survey.code AS col2,
+					count(survey_question.question_id) AS col3,
 					".(api_is_western_name_order() ? "CONCAT(user.firstname, ' ', user.lastname)" : "CONCAT(user.lastname, ' ', user.firstname)")."	AS col4,
-					survey.avail_from							AS col5,
-					survey.avail_till							AS col6,
+					survey.avail_from AS col5,
+					survey.avail_till AS col6,
 					CONCAT('<a href=\"survey_invitation.php?view=answered&amp;survey_id=',survey.survey_id,'\">',survey.answered,'</a> / <a href=\"survey_invitation.php?view=invited&amp;survey_id=',survey.survey_id,'\">',survey.invited, '</a>')	AS col7,
-					survey.anonymous							AS col8,
-					survey.survey_id							AS col9,
-					survey.session_id							AS session_id
+					survey.anonymous AS col8,
+					survey.survey_id AS col9,
+					survey.session_id AS session_id
 				 FROM $table_survey survey
-                    LEFT JOIN $table_survey_question survey_question ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = $course_id)
-                    INNER JOIN $table_user user ON (survey.author = user.user_id)
+                    LEFT JOIN $table_survey_question survey_question
+                    ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = $course_id)
+                    LEFT JOIN $table_user user
+                    ON (survey.author = user.user_id)
 				 WHERE survey.c_id = $course_id
 				 $search_restriction
 				 $condition_session ";

+ 77 - 70
main/survey/survey_list.php

@@ -33,10 +33,10 @@ event_access_tool(TOOL_SURVEY);
 
 /** @todo This has to be moved to a more appropriate place (after the display_header of the code)*/
 if (!api_is_allowed_to_edit(false, true)) { // Coach can see this
-	Display :: display_header(get_lang('SurveyList'));
-	SurveyUtil::survey_list_user($_user['user_id']);
-	Display :: display_footer();
-	exit;
+    Display::display_header(get_lang('SurveyList'));
+    SurveyUtil::survey_list_user($_user['user_id']);
+    Display::display_footer();
+    exit;
 }
 
 $extend_rights_for_coachs = api_get_setting('extend_rights_for_coach_on_survey');
@@ -49,83 +49,83 @@ $table_user 			= Database :: get_main_table(TABLE_MAIN_USER);
 
 // Language variables
 if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
-	$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
-	$tool_name = get_lang('SearchASurvey');
+    $interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList'));
+    $tool_name = get_lang('SearchASurvey');
 } else {
-	$tool_name = get_lang('SurveyList');
+    $tool_name = get_lang('SurveyList');
 }
 
 // Header
-Display :: display_header($tool_name, 'Survey');
+Display::display_header($tool_name, 'Survey');
 
 // Tool introduction
 Display::display_introduction_section('survey', 'left');
 
 // Action handling: searching
 if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
-	SurveyUtil::display_survey_search_form();
+    SurveyUtil::display_survey_search_form();
 }
 // Action handling: deleting a survey
 if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['survey_id'])) {
-	// Getting the information of the survey (used for when the survey is shared)
-	$survey_data = survey_manager::get_survey($_GET['survey_id']);
-	if (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
-		// The coach can't delete a survey not belonging to his session
-		api_not_allowed();
-		exit;
-	}
-	// If the survey is shared => also delete the shared content
-	if (is_numeric($survey_data['survey_share'])) {
-		survey_manager::delete_survey($survey_data['survey_share'], true);
-	}
-
-	$return = survey_manager :: delete_survey($_GET['survey_id']);
-	if ($return) {
-		Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
-	} else {
-		Display :: display_error_message(get_lang('ErrorOccurred'), false);
-	}
+    // Getting the information of the survey (used for when the survey is shared)
+    $survey_data = survey_manager::get_survey($_GET['survey_id']);
+    if (api_is_course_coach() && intval($_SESSION['id_session']) != $survey_data['session_id']) {
+        // The coach can't delete a survey not belonging to his session
+        api_not_allowed();
+        exit;
+    }
+    // If the survey is shared => also delete the shared content
+    if (is_numeric($survey_data['survey_share'])) {
+        survey_manager::delete_survey($survey_data['survey_share'], true);
+    }
+
+    $return = survey_manager :: delete_survey($_GET['survey_id']);
+    if ($return) {
+        Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
+    } else {
+        Display :: display_error_message(get_lang('ErrorOccurred'), false);
+    }
 }
 
 if (isset($_GET['action']) && $_GET['action'] == 'empty') {
-	$mysession = api_get_session_id();
-	if ( $mysession != 0 ) {
-		if (!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id'])))) {
-			// The coach can't empty a survey not belonging to his session
-			api_not_allowed();
-			exit;
-		}
-	} else {
-		if (!(api_is_course_admin() || api_is_platform_admin())) {
-			api_not_allowed();
-			exit;
-		}
-	}
-	$return = survey_manager::empty_survey(intval($_GET['survey_id']));
-	if ($return) {
-		Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
-	} else {
-		Display :: display_error_message(get_lang('ErrorOccurred'), false);
-	}
+    $mysession = api_get_session_id();
+    if ( $mysession != 0 ) {
+        if (!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id'])))) {
+            // The coach can't empty a survey not belonging to his session
+            api_not_allowed();
+            exit;
+        }
+    } else {
+        if (!(api_is_course_admin() || api_is_platform_admin())) {
+            api_not_allowed();
+            exit;
+        }
+    }
+    $return = survey_manager::empty_survey(intval($_GET['survey_id']));
+    if ($return) {
+        Display :: display_confirmation_message(get_lang('SurveyEmptied'), false);
+    } else {
+        Display :: display_error_message(get_lang('ErrorOccurred'), false);
+    }
 }
 
 // Action handling: performing the same action on multiple surveys
 if (isset($_POST['action']) && $_POST['action']) {
-	if (is_array($_POST['id'])) {
-		foreach ($_POST['id'] as $key => & $value) {
-			// getting the information of the survey (used for when the survey is shared)
-			$survey_data = survey_manager::get_survey($value);
-			// if the survey is shared => also delete the shared content
-			if (is_numeric($survey_data['survey_share'])) {
-				survey_manager::delete_survey($survey_data['survey_share'], true);
-			}
-			// delete the actual survey
-			survey_manager::delete_survey($value);
-		}
-		Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
-	} else {
-		Display :: display_error_message(get_lang('NoSurveysSelected'), false);
-	}
+    if (is_array($_POST['id'])) {
+        foreach ($_POST['id'] as $key => & $value) {
+            // getting the information of the survey (used for when the survey is shared)
+            $survey_data = survey_manager::get_survey($value);
+            // if the survey is shared => also delete the shared content
+            if (is_numeric($survey_data['survey_share'])) {
+                survey_manager::delete_survey($survey_data['survey_share'], true);
+            }
+            // delete the actual survey
+            survey_manager::delete_survey($value);
+        }
+        Display :: display_confirmation_message(get_lang('SurveysDeleted'), false);
+    } else {
+        Display :: display_error_message(get_lang('NoSurveysSelected'), false);
+    }
 }
 
 echo '<div class="actions">';
@@ -139,9 +139,9 @@ echo '</div>';
 
 // Load main content
 if (api_is_course_coach() && $extend_rights_for_coachs == 'false') {
-	SurveyUtil::display_survey_list_for_coach();
+    SurveyUtil::display_survey_list_for_coach();
 } else {
-	SurveyUtil::display_survey_list();
+    SurveyUtil::display_survey_list();
 }
 
 // Footer
@@ -149,29 +149,36 @@ Display :: display_footer();
 
 /* Bypass functions to make direct use from SortableTable possible */
 
-function get_number_of_surveys() {
+function get_number_of_surveys()
+{
 	return SurveyUtil::get_number_of_surveys();
 }
 
-function get_survey_data($from, $number_of_items, $column, $direction) {
+function get_survey_data($from, $number_of_items, $column, $direction)
+{
 	return SurveyUtil::get_survey_data($from, $number_of_items, $column, $direction);
 }
 
-function modify_filter($survey_id) {
+function modify_filter($survey_id)
+{
 	return SurveyUtil::modify_filter($survey_id);
 }
 
-function get_number_of_surveys_for_coach() {
+function get_number_of_surveys_for_coach()
+{
 	return SurveyUtil::get_number_of_surveys_for_coach();
 }
-function get_survey_data_for_coach($from, $number_of_items, $column, $direction) {
+function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
+{
 	return SurveyUtil::get_survey_data_for_coach($from, $number_of_items, $column, $direction);
 }
 
-function modify_filter_for_coach($survey_id) {
+function modify_filter_for_coach($survey_id)
+{
 	return SurveyUtil::modify_filter_for_coach($survey_id);
 }
 
-function anonymous_filter($anonymous) {
+function anonymous_filter($anonymous)
+{
 	return SurveyUtil::anonymous_filter($anonymous);
 }

+ 15 - 7
main/tracking/courseLog.php

@@ -250,10 +250,14 @@ if (count($a_students) > 0) {
     $course_name = get_lang('Course').' '.$course_info['name'];
 
     if ($session_id) {
-        echo Display::page_subheader(Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL).' '.api_get_session_name($session_id).' '.
-             Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_name);
+        echo Display::page_subheader(
+            Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL).' '.api_get_session_name($session_id).' '.
+            Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_name
+        );
     } else {
-        echo Display::page_subheader(Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_info['name']);
+        echo Display::page_subheader(
+            Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_info['name']
+        );
     }
 
     $extra_field_select = TrackingCourseLog::display_additional_profile_fields();
@@ -263,7 +267,7 @@ if (count($a_students) > 0) {
     }
     $form->display();
 
-    //PERSON_NAME_DATA_EXPORT is buggy
+    // PERSON_NAME_DATA_EXPORT is buggy
     $is_western_name_order = api_is_western_name_order();
 
     if ($export_csv) {
@@ -277,7 +281,11 @@ if (count($a_students) > 0) {
 
     $user_ids = array_keys($a_students);
 
-    $table = new SortableTable('users_tracking', array('TrackingCourseLog', 'get_number_of_users'), array('TrackingCourseLog', 'get_user_data'), (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
+    $table = new SortableTable(
+        'users_tracking',
+        array('TrackingCourseLog', 'get_number_of_users'),
+        array('TrackingCourseLog', 'get_user_data'),
+        (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
 
     $parameters['cidReq'] 		= Security::remove_XSS($_GET['cidReq']);
     $parameters['id_session'] 	= $session_id;
@@ -324,7 +332,7 @@ if (count($a_students) > 0) {
         $tab_table_header[] = get_lang('FirstLogin');
         $table->set_header(13, get_lang('LatestLogin'), false);
         $tab_table_header[] = get_lang('LatestLogin');
-        if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
+        if (isset($_GET['additional_profile_field']) and is_numeric($_GET['additional_profile_field'])) {
             $table->set_header(14, $extra_info['field_display_text'], false);
             $tab_table_header[] = $extra_info['field_display_text'];
             $table->set_header(15, get_lang('Details'), false);
@@ -340,7 +348,7 @@ if (count($a_students) > 0) {
         $table->set_header(12, get_lang('LatestLogin'), false);
         $tab_table_header[] = get_lang('LatestLogin');
 
-        if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
+        if (isset($_GET['additional_profile_field']) and is_numeric($_GET['additional_profile_field'])) {
             $table->set_header(13, $extra_info['field_display_text'], false);
             $tab_table_header[] = $extra_info['field_display_text'];
             $table->set_header(14, get_lang('Details'), false);

+ 48 - 50
main/upload/upload_ppt.php

@@ -11,7 +11,7 @@
  */
 
 //the document file is loaded because most of the upload vocab relates to the document tool
-$language_file[] = "document"; 
+$language_file[] = "document";
 $language_file[] = "learnpath";
 $language_file[] = "scormdocument";
 
@@ -26,39 +26,41 @@ $htmlHeadXtra[] = '<script type="text/javascript">
 	var myUpload = new upload(0);
 </script>';
 
-if (isset($_POST['convert'])){
-	$cwdir = getcwd();
-	if(isset($_FILES['user_file'])) {
-		$allowed_extensions = array('odp','sxi','ppt','pps','sxd','pptx');
-		if(in_array(strtolower(pathinfo($_FILES['user_file']['name'],PATHINFO_EXTENSION)),$allowed_extensions)) {
-			require('../newscorm/lp_upload.php');
-			if(isset($o_ppt) && $first_item_id != 0){
-				if (api_get_setting('search_enabled')=='true') {
-                    require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
+if (isset($_POST['convert'])) {
+    $cwdir = getcwd();
+    if (isset($_FILES['user_file'])) {
+        $allowed_extensions = array('odp', 'sxi', 'ppt', 'pps', 'sxd', 'pptx');
+        if (in_array(strtolower(pathinfo($_FILES['user_file']['name'], PATHINFO_EXTENSION)), $allowed_extensions)) {
+            require_once api_get_path(SYS_CODE_PATH).'newscorm/lp_upload.php';
+            if (isset($o_ppt) && $first_item_id != 0) {
+                if (api_get_setting('search_enabled')=='true') {
+                    require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
                     $specific_fields = get_specific_field_list();
                     foreach ($specific_fields as $specific_field) {
-    					$values = explode(',', trim($_POST[$specific_field['code']]));
-    					if ( !empty($values) ) {
-    						foreach ($values as $value) {
-    							$value = trim($value);
-    							if ( !empty($value) ) {
-    								add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $o_ppt->lp_id, $value);
-    							}
-    						}
-    					}
-    				}
+                        $values = explode(',', trim($_POST[$specific_field['code']]));
+                        if (!empty($values)) {
+                            foreach ($values as $value) {
+                                $value = trim($value);
+                                if (!empty($value)) {
+                                    add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $o_ppt->lp_id, $value);
+                                }
+                            }
+                        }
+                    }
                 }
-				header('Location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_ppt->lp_id.'&action=view_item&id='.$first_item_id);
-			} else {
-				if(!empty($o_ppt->error))
-					$errorMessage = $o_ppt->error;
-				else
-					$errorMessage = get_lang('OogieUnknownError');
-			}
-		} else {
-			$errorMessage = get_lang('OogieBadExtension');
-		}
-	}
+                header('Location: ../newscorm/lp_controller.php?'.api_get_cidreq().'&lp_id='.$o_ppt->lp_id.'&action=view_item&id='.$first_item_id);
+                exit;
+            } else {
+                if (!empty($o_ppt->error)) {
+                    $errorMessage = $o_ppt->error;
+                } else {
+                    $errorMessage = get_lang('OogieUnknownError');
+                }
+            }
+        } else {
+            $errorMessage = get_lang('OogieBadExtension');
+        }
+    }
 }
 
 event_access_tool(TOOL_UPLOAD);
@@ -66,8 +68,8 @@ event_access_tool(TOOL_UPLOAD);
 // check access permissions (edit permission is needed to add a document or a LP)
 $is_allowed_to_edit = api_is_allowed_to_edit();
 
-if(!$is_allowed_to_edit){
-	api_not_allowed(true);
+if (!$is_allowed_to_edit) {
+    api_not_allowed(true);
 }
 
 $interbreadcrumb[]= array ("url"=>"../newscorm/lp_controller.php?action=list", "name"=> get_lang("Doc"));
@@ -76,38 +78,34 @@ $nameTools = get_lang("OogieConversionPowerPoint");
 Display :: display_header($nameTools);
 $message = get_lang("WelcomeOogieConverter");
 
-
-
-if (!empty($errorMessage)) {	
+if (!empty($errorMessage)) {
     echo Display::return_message($errorMessage, 'warning', false);
 }
 
+$div_upload_limit = get_lang('UploadMaxSize').' : '.ini_get('post_max_size');
+
 $form = new FormValidator('upload_ppt', 'POST', '', '');
 $form->addElement('header', get_lang("WelcomeOogieSubtitle"));
-
 $form->addElement('html', Display::return_message($message, 'info', false));
-
-// build the form
-$div_upload_limit = get_lang('UploadMaxSize').' : '.ini_get('post_max_size');
-$form->addElement ('file', 'user_file', array('<img src="../img/powerpoint_big.gif" />', $div_upload_limit));
-$form->addElement ('checkbox', 'take_slide_name','', get_lang('TakeSlideName'));
-if (api_get_setting('search_enabled')=='true') {
+$form->addElement('file', 'user_file', array('<img src="../img/powerpoint_big.gif" />', $div_upload_limit));
+$form->addElement('checkbox', 'take_slide_name', '', get_lang('TakeSlideName'));
+if (api_get_setting('search_enabled') == 'true') {
     require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
     $specific_fields = get_specific_field_list();
-    $form->addElement ('checkbox', 'index_document','', get_lang('SearchFeatureDoIndexDocument'));        
-    $form->addElement ('select_language', 'language', get_lang('SearchFeatureDocumentLanguage'));    
+    $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument'));
+    $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage'));
     foreach ($specific_fields as $specific_field) {
-        $form->addElement ('text', $specific_field['code'], $specific_field['name'].' : ');
+        $form->addElement('text', $specific_field['code'], $specific_field['name'].' : ');
     }
 }
 
-$form->addElement ('style_submit_button', 'convert', get_lang('ConvertToLP'));
-$form->addElement ('hidden', 'ppt2lp', 'true');
+$form->addElement('style_submit_button', 'convert', get_lang('ConvertToLP'));
+$form->addElement('hidden', 'ppt2lp', 'true');
 
-$form->add_real_progress_bar(md5(rand(0,10000)), 'user_file', 1, true);
+$form->add_real_progress_bar(md5(rand(0, 10000)), 'user_file', 1, true);
 $defaults = array('take_slide_name'=>'checked="checked"','index_document'=>'checked="checked"');
 $form->setDefaults($defaults);
 
 // display the form
 $form->display();
-Display::display_footer();
+Display::display_footer();

+ 16 - 9
main/work/add_document.php

@@ -6,7 +6,6 @@ use ChamiloSession as Session;
 $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
 
 require_once '../inc/global.inc.php';
-// Including necessary files
 require_once 'work.lib.php';
 
 if (ADD_DOCUMENT_TO_WORK == false) {
@@ -18,6 +17,7 @@ $current_course_tool  = TOOL_STUDENTPUBLICATION;
 $workId = isset($_GET['id']) ? intval($_GET['id']) : null;
 $docId = isset($_GET['document_id']) ? intval($_GET['document_id']) : null;
 $action = isset($_GET['action']) ? $_GET['action'] : null;
+$message = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
 
 if (empty($workId)) {
     api_not_allowed(true);
@@ -46,7 +46,7 @@ switch ($action) {
     case 'delete':
         if (!empty($workId) && !empty($docId)) {
             deleteDocumentToWork($docId, $workId, api_get_course_int_id());
-            $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId;
+            $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq();
             header('Location: '.$url);
             exit;
         }
@@ -56,6 +56,7 @@ switch ($action) {
 if (empty($docId)) {
 
     Display :: display_header(null);
+    echo $message;
     $documents = getAllDocumentToWork($workId, api_get_course_int_id());
     if (!empty($documents)) {
         echo Display::page_subheader(get_lang('DocumentsAdded'));
@@ -64,7 +65,7 @@ if (empty($docId)) {
             $documentId = $doc['document_id'];
             $docData = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
             if ($docData) {
-                $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?action=delete&id='.$workId.'&document_id='.$documentId;
+                $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?action=delete&id='.$workId.'&document_id='.$documentId.'&'.api_get_cidreq();
                 $link = Display::url(get_lang('Delete'), $url);
                 echo $docData['title'].' '.$link.'<br />';
             }
@@ -86,10 +87,10 @@ if (empty($docId)) {
     echo $document_tree;
     echo '<hr /><div class="clear"></div>';
 } else {
-    $message = null;
 
     $documentInfo = DocumentManager::get_document_data_by_id($docId, $courseInfo['code']);
-    $form = new FormValidator('add_doc', 'post', api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId);
+    $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&document_id='.$docId.'&'.api_get_cidreq();
+    $form = new FormValidator('add_doc', 'post', $url);
     $form->addElement('header', get_lang('AddDocument'));
     $form->addElement('hidden', 'add_doc', '1');
     $form->addElement('hidden', 'id', $workId);
@@ -104,15 +105,17 @@ if (empty($docId)) {
 
         if (empty($data)) {
             addDocumentToWork($docId, $workId, api_get_course_int_id());
-            $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId;
-            header('Location: '.$url);
-            exit;
+            $message = Display::return_message(get_lang('Added'), 'success');
         } else {
             $message = Display::return_message(get_lang('DocumentAlreadyAdded'), 'warning');
         }
+
+        $url = api_get_path(WEB_CODE_PATH).'work/add_document.php?id='.$workId.'&'.api_get_cidreq().'&message='.$message;
+        header('Location: '.$url);
+        exit;
     }
 
-    Display :: display_header(null);
+    Display::display_header(null);
     echo $message;
     $form->display();
 }
@@ -122,6 +125,7 @@ if (empty($docId)) {
  *
  *
  * 1. Create tables
+ *
 CREATE TABLE IF NOT EXISTS c_student_publication_rel_document (
     id  INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
     work_id INT NOT NULL,
@@ -138,9 +142,12 @@ CREATE TABLE IF NOT EXISTS c_student_publication_rel_user (
 
 CREATE TABLE IF NOT EXISTS c_student_publication_comment (id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,  work_id INT NOT NULL,  c_id INT NOT NULL,  comment text,  user_id int NOT NULL,  sent_at datetime NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+ALTER TABLE c_student_publication ADD COLUMN document_id int DEFAULT 0;
+ *
  * Update configuration.php:
  *  $_configuration['add_document_to_work'] = true;
 
+ *
 */
 
 

+ 7 - 9
main/work/edit_work.php

@@ -4,8 +4,13 @@
 $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
 
 require_once '../inc/global.inc.php';
+$lib_path = api_get_path(LIBRARY_PATH);
+
+/* Libraries */
+require_once $lib_path.'fileManage.lib.php';
 require_once 'work.lib.php';
 
+
 // Section (for the tabs)
 $this_section = SECTION_COURSES;
 
@@ -93,12 +98,7 @@ $display_edit_form = true;
 if ($form->validate()) {
     $params = $form->exportValues();
     $workId = $params['work_id'];
-
-    $dir_name = replace_dangerous_char($params['dir_name']);
-    $dir_name = disable_dangerous_file($dir_name);
-
     $edit_check = false;
-
     $workData = get_work_data_by_id($workId);
 
     if (!empty($workData)) {
@@ -108,11 +108,9 @@ if ($form->validate()) {
     }
 
     if ($edit_check) {
-
+        updateWork($workId, $params, $courseInfo);
         updatePublicationAssignment($workId, $params, $courseInfo, $group_id);
-        updateDirName($workData, $dir_name, $params['dir_name'], $courseInfo);
-
-        $dir = $dir_name;
+        updateDirName($workData, $params['new_dir']);
 
         Display::display_confirmation_message(get_lang('FolderEdited'));
     } else {

+ 4 - 1
main/work/upload_from_template.php

@@ -19,6 +19,7 @@ require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
 $this_section = SECTION_COURSES;
 
 $work_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
+$documentId = isset($_REQUEST['document_id']) ? intval($_REQUEST['document_id']) : null;
 
 $is_allowed_to_edit = api_is_allowed_to_edit();
 $course_id = api_get_course_int_id();
@@ -62,10 +63,12 @@ $interbreadcrumb[] = array('url' => '#', 'name'  => get_lang('UploadFromTemplate
 
 $form = new FormValidator('form', 'POST', api_get_self()."?".api_get_cidreq()."&id=".$work_id, '', array('enctype' => "multipart/form-data"));
 setWorkUploadForm($form, false);
+$form->addElement('hidden', 'document_id', $documentId);
 $form->addElement('hidden', 'id', $work_id);
 $form->addElement('hidden', 'sec_token', $token);
 
-$documentTemplateData = getDocumentTemplateFromWork($work_id, $course_info);
+$documentTemplateData = getDocumentTemplateFromWork($work_id, $course_info, $documentId);
+
 if (!empty($documentTemplateData)) {
     $defaults['title'] = $userInfo['complete_name'].'_'.$documentTemplateData['title'].'_'.substr(api_get_utc_datetime(), 0, 10);
     $defaults['description'] = $documentTemplateData['file_content'];

File diff suppressed because it is too large
+ 592 - 131
main/work/work.lib.php


+ 0 - 35
main/work/work.php

@@ -210,10 +210,7 @@ switch ($action) {
                 $form->display();
             }
         }
-    case 'make_visible':
-    case 'delete':
     case 'delete_dir':
-    case 'make_invisible':
     case 'move':
     case 'move_to':
     case 'list':
@@ -251,28 +248,6 @@ switch ($action) {
             }
         }
 
-        /*	Visible */
-        if ($is_allowed_to_edit && $action == 'make_visible') {
-            if (!empty($item_id)) {
-                if (isset($item_id) && $item_id == 'all') {
-                } else {
-                    makeVisible($item_id, $course_info);
-                    Display::display_confirmation_message(get_lang('FileVisible'));
-                }
-            }
-        }
-
-        if ($is_allowed_to_edit && $action == 'make_invisible') {
-
-            /*	Invisible */
-            if (!empty($item_id)) {
-                if (isset($item_id) && $item_id == 'all') {
-                } else {
-                    makeInvisible($item_id, $course_info);
-                    Display::display_confirmation_message(get_lang('FileInvisible'));
-                }
-            }
-        }
 
         /*	Delete dir */
 
@@ -285,16 +260,6 @@ switch ($action) {
             }
         }
 
-        /*	Delete document */
-        if ($action == 'delete' && $item_id) {
-            $file_deleted = deleteWorkItem($item_id, $_course);
-            if (!$file_deleted) {
-                Display::display_error_message(get_lang('YouAreNotAllowedToDeleteThisDocument'));
-            } else {
-                Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
-            }
-        }
-
         /*	Display list of student publications */
         if (!empty($my_folder_data['description'])) {
             echo '<p><div><strong>'.

+ 28 - 20
main/work/work_list.php

@@ -55,19 +55,15 @@ if (!empty($group_id)) {
 $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(), 'name' => get_lang('StudentPublications'));
 $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId, 'name' =>  $my_folder_data['title']);
 
-Display :: display_header(null);
-
 $documentsAddedInWork = getAllDocumentsFromWorkToString($workId, $courseInfo);
 
+Display :: display_header(null);
+
 echo '<div class="actions">';
 echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).'</a>';
 if (api_is_allowed_to_session_edit(false, true) && !empty($workId)) {
     echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
     echo Display::return_icon('upload_file.png', get_lang('UploadADocument'), '', ICON_SIZE_MEDIUM).'</a>';
-    if (!empty($documentsAddedInWork)) {
-        echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload_from_template.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
-    }
-    echo Display::return_icon('import_html.png', get_lang('UploadFromTemplate'), '', ICON_SIZE_MEDIUM).'</a>';
 }
 echo '</div>';
 
@@ -80,11 +76,23 @@ if (!empty($my_folder_data['description'])) {
     echo '<p><div><strong>'.get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description']).'</p></div></p>';
 }
 
-echo $documentsAddedInWork;
+$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
+$item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
+
+switch ($action) {
+    case 'delete':
+        $file_deleted = deleteWorkItem($item_id, $courseInfo);
+
+        if (!$file_deleted) {
+            Display::display_error_message(get_lang('YouAreNotAllowedToDeleteThisDocument'));
+        } else {
+            Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
+        }
+        break;
+}
 
 $result = getWorkDateValidationStatus($work_data);
 echo $result['message'];
-
 $check_qualification = intval($my_folder_data['qualification']);
 
 if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
@@ -102,14 +110,14 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification))
     );
 
     $column_model   = array (
-        array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
-        array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
-        array('name'=>'lastname',		'index'=>'lastname',        'width'=>'35',   'align'=>'left', 'search' => 'true'),
-        array('name'=>'title',          'index'=>'title',           'width'=>'40',   'align'=>'left', 'search' => 'false', 'wrap_cell' => 'true'),
-        array('name'=>'qualification',	'index'=>'qualification',	'width'=>'20',   'align'=>'left', 'search' => 'true'),
-        array('name'=>'sent_date',           'index'=>'sent_date',            'width'=>'50',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
-        array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30',   'align'=>'left', 'search' => 'true'),
-        array('name'=>'actions',        'index'=>'actions',         'width'=>'40',   'align'=>'left', 'search' => 'false', 'sortable'=>'false')
+        array('name'=>'type', 'index'=>'file', 'width'=>'5',   'align'=>'left', 'search' => 'false'),
+        array('name'=>'firstname', 'index'=>'firstname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
+        array('name'=>'lastname', 'index'=>'lastname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
+        array('name'=>'title', 'index'=>'title', 'width'=>'40',   'align'=>'left', 'search' => 'false', 'wrap_cell' => 'true'),
+        array('name'=>'qualification',	'index'=>'qualification', 'width'=>'10',   'align'=>'left', 'search' => 'true'),
+        array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'30',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
+        array('name'=>'qualificator_id', 'index'=>'qualificator_id', 'width'=>'20', 'align'=>'left', 'search' => 'true'),
+        array('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'left', 'search' => 'false', 'sortable'=>'false')
     );
 } else {
     $type = 'complex';
@@ -124,12 +132,12 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification))
     );
 
     $column_model   = array (
-        array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
+        array('name'=>'type',           'index'=>'file',            'width'=>'5',   'align'=>'left', 'search' => 'false'),
         array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
         array('name'=>'lastname',		'index'=>'lastname',        'width'=>'35',   'align'=>'left', 'search' => 'true'),
-        array('name'=>'title',          'index'=>'title',           'width'=>'40',   'align'=>'left', 'search' => 'false', 'wrap_cell' => "true"),
-        array('name'=>'sent_date',       'index'=>'sent_date',            'width'=>'50',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
-        array('name'=>'actions',        'index'=>'actions',         'width'=>'40',   'align'=>'left', 'search' => 'false', 'sortable'=>'false')
+        array('name'=>'title',          'index'=>'title',           'width'=>'60',   'align'=>'left', 'search' => 'false', 'wrap_cell' => "true"),
+        array('name'=>'sent_date',       'index'=>'sent_date',      'width'=>'30',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true', 'sortable'=>'false'),
+        array('name'=>'actions',        'index'=>'actions',         'width'=>'20',   'align'=>'left', 'search' => 'false', 'sortable'=>'false')
     );
 }
 

+ 62 - 11
main/work/work_list_all.php

@@ -15,6 +15,7 @@ require_once 'work.lib.php';
 $this_section = SECTION_COURSES;
 
 $workId = isset($_GET['id']) ? intval($_GET['id']) : null;
+$is_allowed_to_edit = api_is_allowed_to_edit();
 
 if (empty($workId)) {
     api_not_allowed(true);
@@ -61,6 +62,43 @@ $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work_list
 $error_message = null;
 
 Display :: display_header(null);
+
+$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
+$item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null;
+
+/*	Delete document */
+if ($action == 'delete' && $item_id) {
+    $file_deleted = deleteWorkItem($item_id, $_course);
+    if (!$file_deleted) {
+        Display::display_error_message(get_lang('YouAreNotAllowedToDeleteThisDocument'));
+    } else {
+        Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
+    }
+}
+
+/*	Visible */
+if ($is_allowed_to_edit && $action == 'make_visible') {
+    if (!empty($item_id)) {
+        if (isset($item_id) && $item_id == 'all') {
+        } else {
+            makeVisible($item_id, $courseInfo);
+            Display::display_confirmation_message(get_lang('FileVisible'));
+        }
+    }
+}
+
+if ($is_allowed_to_edit && $action == 'make_invisible') {
+
+    /*	Invisible */
+    if (!empty($item_id)) {
+        if (isset($item_id) && $item_id == 'all') {
+        } else {
+            makeInvisible($item_id, $courseInfo);
+            Display::display_confirmation_message(get_lang('FileInvisible'));
+        }
+    }
+}
+
 $documentsAddedInWork = getAllDocumentsFromWorkToString($workId, $courseInfo);
 
 echo '<div class="actions">';
@@ -68,12 +106,6 @@ echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'
 if (api_is_allowed_to_session_edit(false, true) && !empty($workId)) {
     echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
     echo Display::return_icon('upload_file.png', get_lang('UploadADocument'), '', ICON_SIZE_MEDIUM).'</a>';
-
-    if (!empty($documentsAddedInWork)) {
-        echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload_from_template.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
-        echo Display::return_icon('import_html.png', get_lang('UploadFromTemplate'), '', ICON_SIZE_MEDIUM).'</a>';
-    }
-
     if (ADD_DOCUMENT_TO_WORK) {
         echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/add_document.php?'.api_get_cidreq().'&id='.$workId.'">';
         echo Display::return_icon('new_document.png', get_lang('AddDocument'), '', ICON_SIZE_MEDIUM).'</a>';
@@ -107,7 +139,17 @@ $check_qualification = intval($my_folder_data['qualification']);
 
 if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
     $type = 'simple';
-    $columns        = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'),  get_lang('Status'), get_lang('Actions'));
+
+    $columns = array(
+        get_lang('Type'),
+        get_lang('FirstName'),
+        get_lang('LastName'),
+        get_lang('Title'),
+        get_lang('Qualification'),
+        get_lang('Date'),
+        get_lang('Status'),
+        get_lang('Actions')
+    );
     $column_model   = array (
         array('name'=>'type',           'index'=>'file',            'width'=>'10',   'align'=>'left', 'search' => 'false'),
         array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
@@ -120,23 +162,32 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification))
     );
 } else {
     $type = 'complex';
-    $columns  = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'),  get_lang('Actions'));
+
+    $columns = array(
+        get_lang('Type'),
+        get_lang('FirstName'),
+        get_lang('LastName'),
+        get_lang('Title'),
+        get_lang('Date'),
+        get_lang('Actions')
+    );
+
     $column_model   = array (
         array('name'=>'type',           'index'=>'file',            'width'=>'10',   'align'=>'left', 'search' => 'false'),
         array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
         array('name'=>'lastname',		'index'=>'lastname',        'width'=>'35',   'align'=>'left', 'search' => 'true'),
         array('name'=>'title',          'index'=>'title',           'width'=>'40',   'align'=>'left', 'search' => 'false', 'wrap_cell' => "true"),
-        array('name'=>'sent_date',       'index'=>'sent_date',      'width'=>'45',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
+        array('name'=>'sent_date',      'index'=>'sent_date',      'width'=>'45',   'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
         array('name'=>'actions',        'index'=>'actions',         'width'=>'50',   'align'=>'left', 'search' => 'false', 'sortable'=>'false', 'wrap_cell' => 'true')
     );
 }
 
 $extra_params = array();
 
-//Auto-width
+// Auto-width
 $extra_params['autowidth'] = 'true';
 
-//height auto
+// height auto
 $extra_params['height'] = 'auto';
 $extra_params['sortname'] = 'firstname';
 

+ 10 - 3
main/work/work_list_others.php

@@ -75,9 +75,16 @@ $check_qualification = intval($my_folder_data['qualification']);
 if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
     $type = 'simple';
     $columns = array(
-        get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'),  get_lang('Status'), get_lang('Actions')
+        get_lang('Type'),
+        get_lang('FirstName'),
+        get_lang('LastName'),
+        get_lang('Title'),
+        get_lang('Qualification'),
+        get_lang('Date'),
+        get_lang('Status'),
+        get_lang('Actions')
     );
-    $column_model   = array(
+    $column_model = array(
         array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
         array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
         array('name'=>'lastname',		'index'=>'lastname',        'width'=>'35',   'align'=>'left', 'search' => 'true'),
@@ -92,7 +99,7 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification))
     $columns  = array(
         get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'),  get_lang('Actions')
     );
-    $column_model   = array (
+    $column_model = array (
         array('name'=>'type',           'index'=>'file',            'width'=>'12',   'align'=>'left', 'search' => 'false'),
         array('name'=>'firstname',      'index'=>'firstname',       'width'=>'35',   'align'=>'left', 'search' => 'true'),
         array('name'=>'lastname',		'index'=>'lastname',        'width'=>'35',   'align'=>'left', 'search' => 'true'),

+ 0 - 48
tests/main/work/work.lib.test.php

@@ -151,30 +151,6 @@ class TestWork extends UnitTestCase {
 		//var_dump($res);
 	}
 
-	/**
-	* Display the list of student publications, taking into account the user status
-	*
-	* @param $currentCourseRepositoryWeb, the web location of the course folder
-	* @param $link_target_parameter - should there be a target parameter for the links
-	* @param $dateFormatLong - date format
-	* @param $origin - typically empty or 'learnpath'
-	*/
-
-	function testdisplay_student_publications_list() {
-		global $charset,$timeNoSecFormat,$dateFormatShort,$gradebook,$dateFormatLong;
-		$work_dir='';
-		$sub_course_dir='';
-		$currentCourseRepositoryWeb='';
-		$link_target_parameter='';
-		$origin='learnpath';
-		$add_in_where_query='';
-		ob_start();
-		$res=display_student_publications_list($work_dir,$sub_course_dir,$currentCourseRepositoryWeb, $link_target_parameter, $dateFormatLong, $origin);
-		$this->assertTrue(is_null($res));
-		ob_end_clean();
-		//var_dump($res);
-	}
-
 	/**
 	* Displays all options for this tool.
 	* These are
@@ -238,30 +214,6 @@ class TestWork extends UnitTestCase {
 		//var_dump($res);
 	}
 
-	/**
-	 * Returns a list of subdirectories found in the given directory.
-	 *
-	 * The list return starts from the given base directory.
-	 * If you require the subdirs of /var/www/ (or /var/www), you will get 'abc/', 'def/', but not '/var/www/abc/'...
-	 * @param	string	Base dir
-	 * @param	integer	0 if we only want dirs from this level, 1 if we want to recurse into subdirs
-	 * @return	strings_array	The list of subdirs in 'abc/' form, -1 on error, and 0 if none found
-	 * @todo	Add a session check to see if subdirs_list doesn't exist yet (cached copy)
-	 */
-
-	function testget_subdirs_list() {
-		$path_name = api_get_path(SYS_PATH);
-		$basedir = $path_name.'/';
-		$dh = opendir($basedir);
-		$entry = readdir($dh);
-		$dirs_list[] = $entry;
-		$res=get_subdirs_list($basedir='',$recurse=0);
-		$this->assertTrue(is_numeric($res));
-		$this->assertTrue(is_array($dirs_list));
-		//var_dump($res);
-		//var_dump($dirs_list);
-	}
-
 	/**
 	 * Gets the id of a student publication with a given path
 	 * @param string $path

+ 1 - 1
user_portal.php

@@ -23,7 +23,7 @@
 
 use \ChamiloSession as Session;
 
-$language_file = array('courses', 'index','admin');
+$language_file = array('courses', 'index', 'admin', 'userInfo');
 
 $cidReset = true; /* Flag forcing the 'current course' reset,
                     as we're not inside a course anymore  */

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