Эх сурвалжийг харах

Adding new setting session_tutor_reports_visibility see BT#4984

Julio Montoya 12 жил өмнө
parent
commit
7f88e3655b

+ 14 - 7
main/admin/user_information.php

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

+ 10 - 4
main/exercice/exercise_show.php

@@ -62,18 +62,24 @@ if ( empty ( $action ) ) {              $action         = $_REQUEST['action']; }
 $id = intval($_REQUEST['id']); //exe id
 
 if (empty($id)) {
-	api_not_allowed();
+	api_not_allowed(true);
 }
-
 $is_allowedToEdit    = api_is_allowed_to_edit(null,true) || $is_courseTutor || api_is_session_admin() || api_is_drh();
 
+//if (api_is_coach(api_get_session_id(), api_get_course_id())) {    
+if (api_is_course_session_coach(api_get_user_id(), api_get_course_id(), api_get_session_id())) {    
+    if (!api_coach_can_edit_view_results(api_get_course_id(), api_get_session_id())) {
+        api_not_allowed(true);
+    }
+}
+
 //Getting results from the exe_id. This variable also contain all the information about the exercise
 $track_exercise_info = get_exercise_track_exercise_info($id);
 
 
 //No track info
 if (empty($track_exercise_info)) {
-    api_not_allowed();
+    api_not_allowed(true);
 }
 
 $exercise_id        = $track_exercise_info['id'];
@@ -102,7 +108,7 @@ if (isset($session_control_key) && !exercise_time_control_is_valid($exercise_id,
 //Only users can see their own results 
 if (!$is_allowedToEdit) {
     if ($student_id != $current_user_id) {
-    	api_not_allowed();
+    	api_not_allowed(true);
     }
 }
 

+ 150 - 0
main/inc/lib/main_api.lib.php

@@ -38,6 +38,15 @@ define('ANONYMOUS', 6);
  * the teacher through HTMLPurifier */
 define('COURSEMANAGERLOWSECURITY', 10);
 
+//Soft user status
+define('PLATFORM_ADMIN', 11);
+define('SESSION_COURSE_COACH', 12);
+define('SESSION_GENERAL_COACH', 13);
+define('COURSE_STUDENT', 14);   //student subscribed in a course
+define('SESSION_STUDENT', 15);  //student subscribed in a session course
+define('COURSE_TUTOR', 16); // student is tutor of a course (NOT in session)
+
+
 // Table of status
 $_status_list[COURSEMANAGER]    = 'teacher';        // 1
 $_status_list[SESSIONADMIN]     = 'session_admin';  // 3
@@ -1648,6 +1657,19 @@ function get_status_from_code($status_code) {
             return get_lang('SessionsAdmin', '');
         case DRH:
             return get_lang('Drh', '');
+        // "New" roles            
+        case PLATFORM_ADMIN:
+            return get_lang('Admin');
+        case SESSION_COURSE_COACH:
+            return get_lang('SessionCourseCoach');
+        case SESSION_GENERAL_COACH:
+            return get_lang('SessionGeneralCoach');    
+        case COURSE_STUDENT:
+            return get_lang('StudentInCourse');    
+        case SESSION_STUDENT:
+            return get_lang('StudentInSession');    
+        case COURSE_TUTOR:
+            return get_lang('CourseTutor');
     }
 }
 
@@ -2261,6 +2283,25 @@ function api_get_user_platform_status($user_id = false) {
     return $status;
 }
 
+function api_is_course_session_coach($user_id, $course_code, $session_id) {    
+    $session_table 						= Database::get_main_table(TABLE_MAIN_SESSION);
+    $session_rel_course_rel_user_table  = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
+    
+    $user_id = intval($user_id);
+    $session_id = intval($session_id);
+    $course_code = Database::escape_string($course_code);
+    
+    $sql = "SELECT DISTINCT id
+				FROM $session_table INNER JOIN $session_rel_course_rel_user_table session_rc_ru
+	            ON session.id = session_rc_ru.id_session
+	            WHERE   session_rc_ru.id_user = '".$user_id."'  AND 
+                        session_rc_ru.course_code = '$course_code' AND 
+                        session_rc_ru.status = 2 AND 
+                        session_rc_ru.id_session = '$session_id'";
+    $result = Database::query($sql);
+    return Database::num_rows($result) > 0;    
+}
+
 /**
  * Checks whether the current user is a course or session coach
  * @param int - optional, session id
@@ -6161,3 +6202,112 @@ function api_get_datetime_picker_js($htmlHeadXtra) {
     }
     return $htmlHeadXtra;
 }
+
+
+function api_detect_user_roles($user_id, $course_code, $session_id = 0) {
+    $user_roles = array();    
+    /*$user_info = api_get_user_info($user_id);
+    $user_roles[] = $user_info['status'];*/
+    
+    $url_id = api_get_current_access_url_id();    
+    if (api_is_platform_admin_by_id($user_id, $url_id)) {
+        $user_roles[] = PLATFORM_ADMIN;
+    }   
+        
+    /*if (api_is_drh()) {    
+        $user_roles[] = DRH;    
+    }*/
+     
+    if (!empty($session_id)) {
+        if (SessionManager::user_is_general_coach($user_id, $session_id)) {
+            $user_roles[] = SESSION_GENERAL_COACH;
+        }
+    }
+    
+    if (!empty($course_code)) {
+        if (empty($session_id)) {
+            if (CourseManager::is_course_teacher($user_id, $course_code)) {
+                $user_roles[] = COURSEMANAGER;
+            }        
+            if (CourseManager::get_tutor_in_course_status($user_id, $course_code)) {
+                $user_roles[] = COURSE_TUTOR;
+            }
+
+            if (CourseManager::is_user_subscribed_in_course($user_id, $course_code)) {
+                $user_roles[] = COURSE_STUDENT;
+            }
+        } else {
+            $user_status_in_session = SessionManager::get_user_status_in_course_session($user_id, $course_code, $session_id);
+            
+            if (!empty($user_status_in_session)) {
+                if ($user_status_in_session == 0) {
+                    $user_roles[] = SESSION_STUDENT;
+                }
+                if ($user_status_in_session == 2) {
+                    $user_roles[] = SESSION_COURSE_COACH;      
+                }
+            }      
+            
+            /*if (api_is_course_session_coach($user_id, $course_code, $session_id)) {
+               $user_roles[] = SESSION_COURSE_COACH; 
+            }*/
+        }
+    }    
+    return $user_roles;
+}
+function api_get_roles_to_string($roles) {
+    $role_names = array();
+    if (!empty($roles)) {
+        foreach ($roles as $role) {
+            $role_names[] = get_status_from_code($role);
+        }
+    }
+    if (!empty($role_names)) {
+        return implode(', ', $role_names);
+    }
+    return null;
+}
+
+function role_actions() {
+    return array(
+        'course' => array(
+            'create',
+            'read',
+            'edit',
+            'delete'
+        ),
+        'admin' => array(
+            'create',
+            'read',
+            'edit',
+            'delete'
+        )
+    );    
+}
+
+function api_coach_can_edit_view_results($course_code = null, $session_id = null) {
+    $user_id = api_get_user_id();
+    
+    if (empty($course_code)) {
+        $course_code = api_get_course_id();
+    }
+    
+    if (empty($session_id)) {
+        $session_id = api_get_session_id();
+    }
+    
+    if (api_is_platform_admin()) {
+        return true;
+    }
+       
+    $roles = api_detect_user_roles($user_id, $course_code, $session_id);
+                
+    if (in_array(SESSION_COURSE_COACH, $roles)) {     
+        return api_get_setting('session_tutor_reports_visibility') == 'true';
+    } else {
+        if (in_array(COURSEMANAGER, $roles)) {
+            return true;
+        }
+        return false;
+    }
+}

+ 3 - 2
main/inc/lib/sessionmanager.lib.php

@@ -1756,7 +1756,8 @@ class SessionManager {
                 WHERE session_rcru.id_user = user.user_id AND 
                 session_rcru.id_session = '".intval($session_id)."' AND 
                 session_rcru.course_code ='".Database::escape_string($course_code)."' AND 
-                user.user_id = ".intval($user_id);        
+                user.user_id = ".intval($user_id);    
+        
         $result = Database::query($sql);
         $status = false;
         if (Database::num_rows($result)) {
@@ -1911,7 +1912,7 @@ class SessionManager {
     	return $sid;
     }
     
-    function user_is_general_coach($user_id, $session_id) {
+    static function user_is_general_coach($user_id, $session_id) {
     	$session_id = intval($session_id);
     	$user_id = intval($user_id);
     	$session_table = Database::get_main_table(TABLE_MAIN_SESSION);    	

+ 3 - 3
main/inc/lib/tracking.lib.php

@@ -3346,7 +3346,7 @@ class TrackingCourseLog {
 		return array('table_name' => $table_name,'link_tool' => $link_tool,'id_tool' => $id_tool);
 	}
 
-	function display_additional_profile_fields() {
+	static function display_additional_profile_fields() {
 		// getting all the extra profile fields that are defined by the platform administrator
 		$extra_fields = UserManager :: get_extra_fields(0,50,5,'ASC');
 
@@ -3492,7 +3492,7 @@ class TrackingCourseLog {
 	 * Get number of users for sortable with pagination
 	 * @return int
 	 */
-	function get_number_of_users() {
+	static function get_number_of_users() {
 		global $user_ids;
 		return count($user_ids);
 	}
@@ -3501,7 +3501,7 @@ class TrackingCourseLog {
 	 * Get data for users list in sortable with pagination
 	 * @return array
 	 */
-	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);

+ 5 - 2
main/install/db_main.sql

@@ -894,7 +894,8 @@ VALUES
 ('tool_visible_by_default_at_creation','forums','checkbox','Tools','true','ToolVisibleByDefaultAtCreationTitle','ToolVisibleByDefaultAtCreationComment',NULL,'Forums', 1),
 ('tool_visible_by_default_at_creation','quiz','checkbox','Tools','true','ToolVisibleByDefaultAtCreationTitle','ToolVisibleByDefaultAtCreationComment',NULL,'Quiz', 1),
 ('tool_visible_by_default_at_creation','gradebook','checkbox','Tools','true','ToolVisibleByDefaultAtCreationTitle','ToolVisibleByDefaultAtCreationComment',NULL,'Gradebook', 1),
-('chamilo_database_version', NULL, 'textfield',NULL, '1.10.0.19570','DatabaseVersion','', NULL, NULL, 0);
+('session_tutor_reports_visibility', NULL, 'radio', 'Session', 'true', 'SessionTutorsCanSeeExpiredSessionsResultsTitle', 'SessionTutorsCanSeeExpiredSessionsResultsComment', NULL, NULL, 1),
+('chamilo_database_version', NULL, 'textfield',NULL, '1.10.0.19730','DatabaseVersion','', NULL, NULL, 0);
 UNLOCK TABLES;
 /*!40000 ALTER TABLE settings_current ENABLE KEYS */;
 
@@ -1236,7 +1237,9 @@ VALUES
 ('show_hot_courses', 'true', 'Yes'),
 ('show_hot_courses', 'false', 'No'),
 ('enable_webcam_clip', 'true', 'Yes'),
-('enable_webcam_clip', 'false', 'No');
+('enable_webcam_clip', 'false', 'No'),
+('session_tutor_reports_visibility', 'true', 'Yes'),
+('session_tutor_reports_visibility', 'false', 'No');
 
 UNLOCK TABLES;
 

+ 10 - 13
main/install/migrate-db-1.9.0-1.10.0-pre.sql

@@ -18,17 +18,9 @@
 ALTER TABLE track_e_online ADD INDEX idx_trackonline_uat (login_user_id, access_url_id, login_date);
 ALTER TABLE track_e_default ADD COLUMN session_id INT NOT NULL DEFAULT 0;
 
-
--- Do not move this query
-
--- Main changes
-
--- Courses changes c_XXX
-
-ALTER TABLE c_lp_item ADD INDEX idx_c_lp_item_cid_lp_id (c_id, lp_id);
-ALTER TABLE c_lp_item_view ADD INDEX idx_c_lp_item_view_cid_lp_view_id_lp_item_id(c_id, lp_view_id, lp_item_id);
-ALTER TABLE c_tool_intro MODIFY COLUMN intro_text MEDIUMTEXT NOT NULL;
-
+INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('session_tutor_reports_visibility', NULL, 'radio', 'Session', 'true', 'SessionTutorsCanSeeExpiredSessionsResultsTitle', 'SessionTutorsCanSeeExpiredSessionsResultsComment', NULL, NULL, 1);
+INSERT INTO settings_options (variable, value, display_text) VALUES ('session_tutor_reports_visibility', 'true', 'Yes');
+INSERT INTO settings_options (variable, value, display_text) VALUES ('session_tutor_reports_visibility', 'false', 'No');
 
 ALTER TABLE notification ADD COLUMN sender_id INT NOT NULL DEFAULT 0;
 
@@ -52,9 +44,14 @@ ALTER TABLE grade_components ADD COLUMN count_elements INT DEFAULT 0;
 
 CREATE TABLE IF NOT EXISTS session_field_options (id int NOT NULL auto_increment, field_id int NOT NULL, option_value text, option_display_text varchar(255), option_order int, tms DATETIME NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (id));
 
--- Normal tables
+-- Courses changes c_XXX
+
+ALTER TABLE c_lp_item ADD INDEX idx_c_lp_item_cid_lp_id (c_id, lp_id);
+ALTER TABLE c_lp_item_view ADD INDEX idx_c_lp_item_view_cid_lp_view_id_lp_item_id(c_id, lp_view_id, lp_item_id);
+ALTER TABLE c_tool_intro MODIFY COLUMN intro_text MEDIUMTEXT NOT NULL;
 
-UPDATE settings_current SET selected_value = '1.10.0.19570' WHERE variable = 'chamilo_database_version';
+-- Do not move this 
+UPDATE settings_current SET selected_value = '1.10.0.19730' WHERE variable = 'chamilo_database_version';
 
 -- xxSTATSxx
 -- All stats DB changes will be added in the "main zone"

+ 18 - 8
main/mySpace/myStudents.php

@@ -754,8 +754,10 @@ if (empty($_GET['details'])) {
     		// Latest exercise results in a LP                
             $score_latest = Tracking :: get_avg_student_score($student_id, $course_code, array($lp_id),$session_id, false, true);
     
-    		if ($i % 2 == 0) $css_class = "row_even";
-    		else $css_class = "row_odd";
+    		if ($i % 2 == 0) 
+                $css_class = "row_even";
+    		else 
+                $css_class = "row_odd";
     
     		$i++;
     		
@@ -838,8 +840,8 @@ if (empty($_GET['details'])) {
 			</tr>
 		<?php
 
-		$csv_content[] = array ();
-		$csv_content[] = array (
+		$csv_content[] = array();
+		$csv_content[] = array(
 			get_lang('Exercices'),
 			get_lang('Score'),
 			get_lang('Attempts')
@@ -867,8 +869,10 @@ if (empty($_GET['details'])) {
 					$count_attempts
 				);
 
-				if ($i % 2) $css_class = 'row_odd';
-				else $css_class = 'row_even';
+				if ($i % 2) 
+                    $css_class = 'row_odd';
+				else 
+                    $css_class = 'row_even';
 
 				echo '<tr class="'.$css_class.'"><td>'.$exercices['title'].'</td>';
 				
@@ -897,8 +901,14 @@ if (empty($_GET['details'])) {
 				$result_last_attempt = Database::query($sql_last_attempt);
 				if (Database :: num_rows($result_last_attempt) > 0) {
 					$id_last_attempt = Database :: result($result_last_attempt, 0, 0);
-					if ($count_attempts > 0)
-						echo '<a href="../exercice/exercise_show.php?id=' . $id_last_attempt . '&cidReq='.$course_code.'&session_id='.$session_id.'&student='.$student_id.'&origin='.(empty($_GET['origin'])?'tracking':Security::remove_XSS($_GET['origin'])).'"> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" border="0" /> </a>';
+					if ($count_attempts > 0) {
+                        if (api_coach_can_edit_view_results($course_code, $session_id)) {
+                            echo '<a href="../exercice/exercise_show.php?id=' . $id_last_attempt . '&cidReq='.$course_code.'&session_id='.$session_id.'&student='.$student_id.'&origin='.(empty($_GET['origin'])?'tracking':Security::remove_XSS($_GET['origin'])).'"> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" border="0" /> </a>';
+                        } else {
+                            echo Display::return_icon('quiz_na.png', get_lang('Exercise'));                            
+                            //echo '<a href="../exercice/exercise_show.php?id=' . $id_last_attempt . '&cidReq='.$course_code.'&session_id='.$session_id.'&student='.$student_id.'&origin='.(empty($_GET['origin'])?'tracking':Security::remove_XSS($_GET['origin'])).'"> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" border="0" /> </a>';
+                        }
+                    }
 				}
 				echo '</td>';