Prechádzať zdrojové kódy

Adding document preview now students can see the feature see #2773

Julio Montoya 13 rokov pred
rodič
commit
98815c7873

+ 5 - 0
main/css/base.css

@@ -2272,4 +2272,9 @@ div.admin_section h4 {
 
 #course_settings h3 img {
     margin-left: 25px;	
+}
+
+.document_preview_container {
+    font-size: 12px !important;
+    color: #111 ! important;	
 }

+ 5 - 3
main/document/document.php

@@ -60,7 +60,6 @@ unset($_SESSION['paint_dir']);
 // Create directory certificates
 DocumentManager::create_directory_certificate_in_course(api_get_course_id());
 
-
 $course_info = api_get_course_info();
 
 //Hack in order to use document.php?id=X 
@@ -69,8 +68,11 @@ if (isset($_REQUEST['id'])) {
     
     //Redirect to the file path
     if (!empty($document_data['filetype']) && $document_data['filetype'] == 'file') {
-    	$url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq();    	    	
-    	header("Location: $url");
+    	$visibility = DocumentManager::is_visible_by_id($_REQUEST['id'], $course_info, api_get_session_id(), 'file');
+    	if ($visibility && api_is_allowed_to_session_edit()) {    		
+    		$url = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$document_data['path'].'?'.api_get_cidreq();    	    	
+    		header("Location: $url");
+    	}
     	exit;
     }  
     //@todo replace all 

+ 4 - 2
main/inc/ajax/document.ajax.php

@@ -43,8 +43,10 @@ switch($action) {
 		}
 		break;
 	case 'document_preview':
-		$course_info = api_get_course_info_by_id($_REQUEST['course_id']);
-		echo DocumentManager::get_document_preview($course_info, false, '_blank');
+		$course_info = api_get_course_info_by_id($_REQUEST['course_id']);		
+		if (!empty($course_info) && is_array($course_info)) {
+			echo DocumentManager::get_document_preview($course_info, false, '_blank', $_REQUEST['session_id']);
+		}
 		break;		
 }
 exit;

+ 22 - 4
main/inc/lib/course.lib.php

@@ -2718,15 +2718,23 @@ class CourseManager {
                 echo '<div style="float:right;">';
                 
                 if ($load_dirs) {
-                	echo '<a id="document_preview_'.$course['id'].'" class="document_preview" href="#">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),22).'</a>';
+                	echo '<a id="document_preview_'.$course['id'].'_0" class="document_preview" href="#">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),22).'</a>';
                 	echo '<a href="'.api_get_path(WEB_CODE_PATH).'course_info/infocours.php?cidReq='.$course['code'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'),22).'</a>';                
-                	echo Display::div('', array('id' => 'document_result_'.$course['id'], 'class'=>'document_preview_container not_active'));
+                	echo Display::div('', array('id' => 'document_result_'.$course['id'].'_0', 'class'=>'document_preview_container'));
                 }
                 
                 if ($course['status'] == COURSEMANAGER) {
                     //echo Display::return_icon('teachers.gif', get_lang('Status').': '.get_lang('Teacher'), array('style'=>'width: 11px; height: 11px;'));
                 }
                 echo '</div>';
+            } else {
+            	echo '<div style="float:right;">';            	
+            	if ($load_dirs) {
+            		echo '<a id="document_preview_'.$course['id'].'_0" class="document_preview" href="#">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),22).'</a>';
+            		echo Display::div('', array('id' => 'document_result_'.$course['id'].'_0', 'class'=>'document_preview_container'));
+            	}
+            	echo '</div>';
+            	
             }
     
             // Function logic - act on the data (check if the course is virtual, if yes change the link).
@@ -2844,7 +2852,7 @@ class CourseManager {
      * @todo move code for what's new icons to a separate function to clear things up
      * @todo add a parameter user_id so that it is possible to show the courselist of other users (=generalisation). This will prevent having to write a new function for this.
      */
-    function get_logged_user_course_html($course, $session_id = 0, $class = 'courses', $session_accessible = true) {
+    function get_logged_user_course_html($course, $session_id = 0, $class = 'courses', $session_accessible = true, $load_dirs = false) {
         global $nosession, $nbDigestEntries, $digest, $thisCourseSysCode, $orderKey;
         $charset = api_get_system_encoding();
     
@@ -2918,7 +2926,7 @@ class CourseManager {
         }
     
         $s_course_status = $my_course['status'];
-        $is_coach = api_is_coach($my_course['id_session'],$course['code']);
+        $is_coach = api_is_coach($my_course['id_session'], $course['code']);
             
         $s_htlm_status_icon = Display::return_icon('blackboard_blue.png', get_lang('Course'), array('width' => '48px'));
         /*
@@ -2965,6 +2973,15 @@ class CourseManager {
         $result .= '<li class="'.$class.'"><div class="coursestatusicons">'.$s_htlm_status_icon.'</div>';
         $result .= $session_title;
         
+        
+        if ($load_dirs) {        	
+        	$result .= '<div style="float:right;">';
+            $result .= '<a id="document_preview_'.$info['real_id'].'_'.$my_course['id_session'].'" class="document_preview" href="#">'.Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'),22).'</a>';
+            $result .= Display::div('', array('id' => 'document_result_'.$info['real_id'].'_'.$my_course['id_session'], 'class'=>'document_preview_container not_active'));
+			$result .= '</div>';
+        }
+        
+        
         // Show the course_code and teacher if chosen to display this.
         if (api_get_setting('display_coursecode_in_courselist') == 'true' || api_get_setting('display_teacher_in_courselist') == 'true') {
             $result .= '<br />';
@@ -3007,6 +3024,7 @@ class CourseManager {
         }
     
         $result .= isset($course['special_course']) ? ' '.Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : '';
+
     
         $current_course_settings = CourseManager :: get_access_settings($my_course['k']);
     

+ 78 - 22
main/inc/lib/document.lib.php

@@ -1146,7 +1146,7 @@ return 'application/octet-stream';
         $is_visible = false;
         if (Database::num_rows($result) > 0) {
             $row = Database::fetch_array($result,'ASSOC');
-            if ($row['visibility'] == 1) {
+            if ($row['visibility'] == 1) {            	
                 $is_visible = $_SESSION['is_allowed_in_course'] || api_is_platform_admin();
             }
         }
@@ -2473,11 +2473,49 @@ return 'application/octet-stream';
         return $html;
     }
     
-    function get_document_preview($course_info, $lp_id = false, $target = '') {    	
+    function get_document_preview($course_info, $lp_id = false, $target = '', $session_id = 0) {
+    	
     	if (!isset($course_info['dbName'])) {
     		$course_info = api_get_course_info($course_info['code']);
+    	}  
+    	
+    	if (empty($course_info) || !is_array($course_info)) {
+    		return '';
+    	}    		
+    	$user_id = api_get_user_id();
+    	
+    	$user_in_course = false;
+    	
+    	if (api_is_platform_admin()) {
+    		$user_in_course = true;
     	}
     	
+    	if (!$user_in_course) {
+    		if (CourseManager::is_course_teacher($user_id, $course_info['code'])) {
+    			$user_in_course = true;
+    		}
+    	}
+    	
+    	//condition for the session
+    	if (isset($session_id) && !empty($session_id)) {
+    		$current_session_id  = intval($session_id);
+    	} else {
+    		$current_session_id = api_get_session_id();
+    	}
+    	
+    	if (!$user_in_course) 
+    	if (empty($current_session_id)) {    		
+    		if (CourseManager::is_user_subscribed_in_course($user_id, $course_info['code'])) {
+    			$user_in_course = true;
+    		}    		
+    	} else {
+    		require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
+    		$user_status = SessionManager::get_user_status_in_session($user_id, $course_info['code'], $current_session_id);
+    		if (in_array($user_status, array('0', '6'))) { //user and coach 
+    			$user_in_course = true;
+    		}    		 		
+    	}    	
+    	
     	$tbl_course 	= Database::get_main_table(TABLE_MAIN_COURSE);
     	$tbl_doc 		= Database::get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
     	$tbl_item_prop 	= Database::get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']);
@@ -2486,19 +2524,21 @@ return 'application/octet-stream';
     	$path = Database::escape_string(str_replace('_', '\_', $path));
     	$added_slash = ($path == '/') ? '' : '/';
     	
-    	//condition for the session
-    	$current_session_id = api_get_session_id();
-    	$condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '".$course_info['code']."' )))";
+
+    	//$condition_session = " AND (id_session = '$current_session_id' OR (id_session = '0' AND insert_date <= (SELECT creation_date FROM $tbl_course WHERE code = '".$course_info['code']."' )))";
+    	$condition_session = " AND (id_session = '$current_session_id' OR  id_session = '0' )";
     	
-		$sql_doc = "SELECT docs.*
+		$sql_doc = "SELECT last.visibility, docs.*
     				FROM  $tbl_item_prop AS last, $tbl_doc AS docs
     	            WHERE docs.id = last.ref
     	            	AND docs.path LIKE '".$path.$added_slash."%'
     	            	AND docs.path NOT LIKE '%_DELETED_%'
-    	                AND last.tool = '".TOOL_DOCUMENT."' $condition_session ORDER BY docs.path ASC";
+    	                AND last.tool = '".TOOL_DOCUMENT."' $condition_session 
+    	                AND last.visibility = '1'
+					ORDER BY docs.path ASC";
     	
-		$res_doc = Database::query($sql_doc);
-    	$resources = Database::store_result($res_doc);
+		$res_doc 	= Database::query($sql_doc);
+    	$resources  = Database::store_result($res_doc);
     	
     	$return = '';
     	
@@ -2510,12 +2550,18 @@ return 'application/octet-stream';
 	    	$return .= Display::url(get_lang('NewDocument'), api_get_self().'?'.api_get_cidreq().'&action=add_item&type='.TOOL_DOCUMENT.'&lp_id='.$_SESSION['oLP']->lp_id);
 	    	$return .= '</div>';
     	} else {
-    		$return .= Display::div(Display::url(Display::return_icon('delete.png', get_lang('Close'), array(), 22), '#', array('id'=>'close_div_'.$course_info['real_id'],'class' =>'close_div')), array('style' => 'position:absolute;right:10px'));
+    		$return .= Display::div(Display::url(Display::return_icon('delete.png', get_lang('Close'), array(), 22), '#', array('id'=>'close_div_'.$course_info['real_id'].'_'.$session_id,'class' =>'close_div')), array('style' => 'position:absolute;right:10px'));
     	}
     	
     	// If you want to debug it, I advise you to do "echo" on the eval statements.
-    	if (!empty($resources)) {
+    	if (!empty($resources) && $user_in_course) {
 	    	foreach ($resources as $resource) {
+	    		$item_info = api_get_item_property_info($course_info['real_id'], 'document', $resource['id'], $session_id);
+	    		
+	    		if (empty($item_info)) {
+	    			continue;
+	    		}
+	    		
 		    	$resource_paths = explode('/', $resource['path']);
 		    	array_shift($resource_paths);
 		    	$path_to_eval = $last_path = '';
@@ -2545,7 +2591,9 @@ return 'application/octet-stream';
     	$label = get_lang('Documents');
     	$new_array[$label] = array('id' => 0, 'files' => $resources_sorted);
     	
-    	$return .= self::write_resources_tree($course_info, $new_array, 0, $lp_id, $target);    	
+    	$write_result = self::write_resources_tree($course_info, $current_session_id, $new_array, 0, $lp_id, $target);
+    	    	
+    	$return .= $write_result ;
     	
     	$return = Display::div($return, array('class'=>'lp_resource'));    	
     	$img_path = api_get_path(WEB_IMG_PATH);
@@ -2555,8 +2603,8 @@ return 'application/octet-stream';
     		
     		    	$('.doc_folder').mouseover(function() {	
     					var my_id = this.id.split('_')[2];    						
-    					$('#'+my_id).show();    								
-    					$('#img_'+my_id).attr('src', '".$img_path."nolines_minus.gif' );			
+    					$('#'+my_id).show();    					    								
+    					//$('#img_'+my_id).attr('src', '".$img_path."nolines_minus.gif' );			
     				});
     				
     				/*$('.doc_folder').click(function() {
@@ -2565,8 +2613,9 @@ return 'application/octet-stream';
     				});*/
     				
     				$('.close_div').click(function() {
-    					var my_id = this.id.split('_')[2];			
-    					$('#document_result_'+my_id).hide();
+    					var course_id = this.id.split('_')[2];
+    					var session_id = this.id.split('_')[3];			
+    					$('#document_result_'+course_id+'_'+session_id).hide();
     					$('.lp_resource').remove();
     				});
     				</script>";
@@ -2584,7 +2633,9 @@ return 'application/octet-stream';
     		}
     		</script>"; 
     	}
-    		  	
+    	if(!$user_in_course) {
+    		$return = '';
+    	}    		  	
     	return $return;    	
     }
     
@@ -2596,13 +2647,14 @@ return 'application/octet-stream';
     * @param	integer Enables the tree display by shifting the new elements a certain distance to the right
     * @return	string	The HTML list
     */
-    public function write_resources_tree($course_info, $resources_sorted, $num = 0, $lp_id = false, $target = '') {
+    public function write_resources_tree($course_info, $session_id, $resources_sorted, $num = 0, $lp_id = false, $target = '') {
     	require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
     	
     	$img_path = api_get_path(WEB_IMG_PATH);
     	$web_code_path = api_get_path(WEB_CODE_PATH);
     	
     	$return = '';
+    	
     	if (count($resources_sorted) > 0) {
     		foreach ($resources_sorted as $key => $resource) {
     			if (isset($resource['id']) && is_int($resource['id'])) {
@@ -2637,15 +2689,19 @@ return 'application/octet-stream';
     				}    				
     
     				$return .= '<div class="doc_resource">';    				
-    				$return .= '<div class="doc_folder"  id="doc_id_'.$resource['id'].'"  style="margin-left:'.($num * 18).'px; margin-right:5px;">';    				    				
-    				$return .= '<img style="cursor: pointer;" src="'.$img_path.'nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '"  '.$onclick.' >';
+    				$return .= '<div class="doc_folder"  id="doc_id_'.$resource['id'].'"  style="margin-left:'.($num * 18).'px; margin-right:5px;">';
+    				if ($lp_id) {    				    				
+    					$return .= '<img style="cursor: pointer;" src="'.$img_path.'nolines_plus.gif" align="absmiddle" id="img_' . $resource['id'] . '"  '.$onclick.' >';
+    				} else {
+    					$return .= '<span style="margin-left:16px">&nbsp;</span>';
+    				}
     				$return .= '<img alt="" src="'.$img_path.'lp_folder.gif" title="" align="absmiddle" />&nbsp;';    				
     				$return .= '<span '.$onclick.' style="cursor: pointer;" >'.$key.'</span>';    				
     				$return .= '</div>
     							<div style="display: none;" id="'.$resource['id'].'">';
     				
     				if (isset($resource['files'])) {
-    					$return .= self::write_resources_tree($course_info, $resource['files'], $num +1, $lp_id, $target);
+    					$return .= self::write_resources_tree($course_info, $session_id, $resource['files'], $num +1, $lp_id, $target);
     				}
     				$return .= '</div></div>';
     			} else {
@@ -2666,7 +2722,7 @@ return 'application/octet-stream';
     						$url  = api_get_self() . '?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&amp;action=add_item&amp;type=' . TOOL_DOCUMENT . '&amp;file=' . $key . '&amp;lp_id=' .$lp_id;
     					} else {
     						//Direct document URL
-    						$url  = $web_code_path.'document/document.php?cidReq='.$course_info['code'].'&id='.$key;
+    						$url  = $web_code_path.'document/document.php?cidReq='.$course_info['code'].'&id_session='.$session_id.'&id='.$key;
     					}	
     					$img = $img_path.$icon;
     					$link = Display::url('<img alt="" src="'.$img.'" title="" />&nbsp;' . $my_file_title, $url, array('target' => $target));

+ 6 - 3
main/inc/lib/main_api.lib.php

@@ -1023,7 +1023,6 @@ function api_get_anonymous_id() {
 function api_get_cidreq() {
     return empty($GLOBALS['_cid']) ? '' : 'cidReq='.htmlspecialchars($GLOBALS['_cid']).(api_get_session_id() == 0 ? '' : '&id_session='.api_get_session_id());
 }
-
 /**
  * Returns the current course info array.
  * Note: this array is only defined if the user is inside a course.
@@ -2706,7 +2705,7 @@ function api_get_track_item_property_history($tool, $ref) {
  * @param string    tool name, linked to 'rubrique' of the course tool_list (Warning: language sensitive !!)
  * @param int       id of the item itself, linked to key of every tool ('id', ...), "*" = all items of the tool
  */
-function api_get_item_property_info($course_id, $tool, $ref) {
+function api_get_item_property_info($course_id, $tool, $ref, $session_id = 0) {
 
     $course_info    = api_get_course_info_by_id($course_id);
     $tool           = Database::escape_string($tool);
@@ -2714,7 +2713,11 @@ function api_get_item_property_info($course_id, $tool, $ref) {
 
     // Definition of tables.
     $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
-    $sql = "SELECT * FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $ref ";
+   	$sql = "SELECT * FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref = $ref ";
+   	if (!empty($session_id)) {
+   		$session_id = intval($session_id);
+   		$sql .= "AND id_session = $session_id ";
+   	}
     $rs  = Database::query($sql);    
     $row = array();
     if (Database::num_rows($rs) > 0) {