Browse Source

fix bad merge caused by bad commit by me and fixed by Yannick
fixing functionality for filtering on user profiling fields (broken after bad bad commit by me and an attempt to fix it by Yannick)

Patrick Cool 15 years ago
parent
commit
4360a93d72
1 changed files with 43 additions and 11 deletions
  1. 43 11
      main/user/subscribe_user.php

+ 43 - 11
main/user/subscribe_user.php

@@ -35,7 +35,10 @@
 */
 // name of the language file that needs to be included
 $language_file = array('registration','admin');
-require '../inc/global.inc.php';
+
+// including the global Dokeos file
+include ('../inc/global.inc.php');
+
 // the section (for the tabs)
 $this_section = SECTION_COURSES;
 // access restriction
@@ -43,11 +46,10 @@ if (!api_is_allowed_to_edit()) {
 	 api_not_allowed(true);
 }
 // including additional libraries
-$libpath = api_get_path(LIBRARY_PATH);
-require_once $libpath.'course.lib.php';
-require_once $libpath.'sortabletable.class.php';
-require_once $libpath.'formvalidator/FormValidator.class.php';
-require_once $libpath.'usermanager.lib.php';
+require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
+require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
+require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
+require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
 
 /*
 ==============================================================================
@@ -197,6 +199,7 @@ function get_number_of_users() {
 	$user_table = Database :: get_main_table(TABLE_MAIN_USER);
 	$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 	$table_user_field_values 	= Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
+	
 	if (isset($_REQUEST['type']) && $_REQUEST['type']=='teacher') {
 		$sql = "SELECT 	u.user_id
 						FROM $user_table u
@@ -338,6 +341,8 @@ function get_user_data($from, $number_of_items, $column, $direction) {
 					WHERE cu.user_id IS NULL
 						AND field_values.field_id = '".Database::escape_string($field_identification[0])."' 
 						AND field_values.field_value = '".Database::escape_string($field_identification[1])."'";
+			} else {	
+				$sql .=	"WHERE cu.user_id IS NULL";
 			}
 		} else {
 		// adding a teacher NOT through a session
@@ -369,6 +374,8 @@ function get_user_data($from, $number_of_items, $column, $direction) {
 				}
 				//showing only the courses of the current Dokeos access_url_id
 				global $_configuration;
+				
+				// adding a teacher NOT trough a session on a portal with multiple URLs
 				if ($_configuration['multiple_access_urls']==true) {
 					$url_access_id = api_get_current_access_url_id();
 					if ($url_access_id !=-1) {
@@ -407,6 +414,7 @@ function get_user_data($from, $number_of_items, $column, $direction) {
 			}
 		}
 	} else {
+		// adding a student
 		if (!empty($_SESSION["id_session"])) {
 			$sql = "SELECT
 					u.user_id AS col0,
@@ -420,9 +428,20 @@ function get_user_data($from, $number_of_items, $column, $direction) {
 					u.active 	AS col5,
 					u.user_id   AS col6
 				FROM $user_table u
-				LEFT JOIN $tbl_session_rel_course_user cu on u.user_id = cu.id_user and course_code='".$_SESSION['_course']['id']."'
-				WHERE cu.id_user IS NULL
-				";
+				LEFT JOIN $tbl_session_rel_course_user cu on u.user_id = cu.id_user and course_code='".$_SESSION['_course']['id']."'";
+				
+			// applying the filter of the additional user profile fields 	
+			if (isset($_GET['subscribe_user_filter_value'])){
+				$field_identification = explode('*',$_GET['subscribe_user_filter_value']);
+				$sql .=	"
+					LEFT JOIN $table_user_field_values field_values 
+						ON field_values.user_id = u.user_id 
+					WHERE cu.user_id IS NULL
+						AND field_values.field_id = '".Database::escape_string($field_identification[0])."' 
+						AND field_values.field_value = '".Database::escape_string($field_identification[1])."'";
+			} else	{
+				$sql .=	"WHERE cu.user_id IS NULL";
+			}
 		} else {
 		$sql = "SELECT
 					u.user_id AS col0,
@@ -436,8 +455,21 @@ function get_user_data($from, $number_of_items, $column, $direction) {
 					u.active 	AS col5,
 					u.user_id   AS col6
 				FROM $user_table u
-				LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'
-				WHERE cu.user_id IS NULL";
+				LEFT JOIN $course_user_table cu on u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'";
+				
+			// applying the filter of the additional user profile fields 	
+			if (isset($_GET['subscribe_user_filter_value'])){
+				$field_identification = explode('*',$_GET['subscribe_user_filter_value']);
+				$sql .=	"
+					LEFT JOIN $table_user_field_values field_values 
+						ON field_values.user_id = u.user_id 
+					WHERE cu.user_id IS NULL
+						AND field_values.field_id = '".Database::escape_string($field_identification[0])."' 
+						AND field_values.field_value = '".Database::escape_string($field_identification[1])."'";
+			} else	{
+				$sql .=	"WHERE cu.user_id IS NULL";
+			}
+
 			//showing only the courses of the current Dokeos access_url_id
 			global $_configuration;
 			if ($_configuration['multiple_access_urls']==true) {