|
|
|
|
@ -476,7 +476,7 @@ return 'application/octet-stream'; |
|
|
|
|
* @param boolean $can_see_invisible |
|
|
|
|
* @return array with all document data |
|
|
|
|
*/ |
|
|
|
|
public static function get_all_document_data($_course, $path = '/', $to_group_id = 0, $to_user_id = NULL, $can_see_invisible = false, $search =false) { |
|
|
|
|
public static function get_all_document_data($_course, $path = '/', $to_group_id = 0, $to_user_id = NULL, $can_see_invisible = false, $search = false) { |
|
|
|
|
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY, $_course['dbName']); |
|
|
|
|
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']); |
|
|
|
|
$TABLE_COURSE = Database::get_main_table(TABLE_MAIN_COURSE); |
|
|
|
|
@ -497,7 +497,7 @@ return 'application/octet-stream'; |
|
|
|
|
$to_value = Database::escape_string($to_value); |
|
|
|
|
|
|
|
|
|
//if they can't see invisible files, they can only see files with visibility 1 |
|
|
|
|
$visibility_bit = ' = 1'; |
|
|
|
|
//$visibility_bit = ' = 1'; |
|
|
|
|
//if they can see invisible files, only deleted files (visibility 2) are filtered out |
|
|
|
|
//if ($can_see_invisible) { |
|
|
|
|
$visibility_bit = ' <> 2'; |
|
|
|
|
@ -533,7 +533,7 @@ return 'application/octet-stream'; |
|
|
|
|
AND ".$to_field." = ".$to_value." |
|
|
|
|
AND last.visibility".$visibility_bit.$condition_session; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
|
|
|
|
|
$doc_list = array(); |
|
|
|
|
@ -587,7 +587,8 @@ return 'application/octet-stream'; |
|
|
|
|
} |
|
|
|
|
$temp[$row['id']] = $row; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//@todo use the DocumentManager::is_visible function |
|
|
|
|
|
|
|
|
|
//Checking disponibility in a session |
|
|
|
|
foreach($my_repeat_ids as $id) { |
|
|
|
|
foreach($doc_list as $row ) { |
|
|
|
|
@ -623,8 +624,19 @@ return 'application/octet-stream'; |
|
|
|
|
unset($document_data[$row['id']]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Checking parents visibility |
|
|
|
|
$final_document_data = array(); |
|
|
|
|
foreach($document_data as $row) { |
|
|
|
|
$is_visible = DocumentManager::check_visibility_tree($row['id'], $_course['code'], $current_session_id, api_get_user_id()); |
|
|
|
|
if ($is_visible) { |
|
|
|
|
$final_document_data[$row['id']]=$row; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$final_document_data = $document_data; |
|
|
|
|
} |
|
|
|
|
return $document_data; |
|
|
|
|
return $final_document_data; |
|
|
|
|
} else { |
|
|
|
|
//display_error("Error getting document info from database (".Database::error().")!"); |
|
|
|
|
return false; |
|
|
|
|
@ -1014,29 +1026,51 @@ return 'application/octet-stream'; |
|
|
|
|
$result = Database::query($sql); |
|
|
|
|
if ($result && Database::num_rows($result) == 1) { |
|
|
|
|
$row = Database::fetch_array($result,'ASSOC'); |
|
|
|
|
//Public document URL |
|
|
|
|
$row['url'] = api_get_path(WEB_CODE_PATH).'document/showinframes.php?cidReq='.$course_code.'&id='.$id; |
|
|
|
|
$row['document_url'] = api_get_path(WEB_CODE_PATH).'document/document.php?cidReq='.$course_code.'&id='.$id; |
|
|
|
|
|
|
|
|
|
//@todo need to clarify the name of the URLs not nice right now |
|
|
|
|
$url_path = urlencode($row['path']); |
|
|
|
|
$path = str_replace('%2F', '/',$url_path); |
|
|
|
|
$row['direct_url'] = $www.$path; |
|
|
|
|
$row['parent_id'] = self::get_document_id($course_info, dirname($row['path'])); |
|
|
|
|
$path = str_replace('%2F', '/',$url_path); |
|
|
|
|
|
|
|
|
|
$row['url'] = api_get_path(WEB_CODE_PATH).'document/showinframes.php?cidReq='.$course_code.'&id='.$id; |
|
|
|
|
$row['document_url'] = api_get_path(WEB_CODE_PATH).'document/document.php?cidReq='.$course_code.'&id='.$id; |
|
|
|
|
$row['direct_url'] = $www.$path; |
|
|
|
|
|
|
|
|
|
if (dirname($row['path']) == '.') { |
|
|
|
|
$row['parent_id'] = '0'; |
|
|
|
|
} else { |
|
|
|
|
$row['parent_id'] = self::get_document_id($course_info, dirname($row['path'])); |
|
|
|
|
} |
|
|
|
|
$parents = array(); |
|
|
|
|
//Use to generate the breadcrumb |
|
|
|
|
if ($load_parents) { |
|
|
|
|
|
|
|
|
|
//Use to generate parents (needed for the breadcrumb) |
|
|
|
|
//@todo sorry but this for is here because there's not a parent_id in the document table so we parsed the path!! |
|
|
|
|
|
|
|
|
|
$visibility = true; |
|
|
|
|
|
|
|
|
|
if ($load_parents) { |
|
|
|
|
$dir_array = explode('/', $row['path']); |
|
|
|
|
$dir_array = array_filter($dir_array); |
|
|
|
|
$array_len = count($dir_array) +1 ; |
|
|
|
|
$real_dir = ''; |
|
|
|
|
$real_dir = ''; |
|
|
|
|
|
|
|
|
|
for ($i = 1; $i < $array_len; $i++) { |
|
|
|
|
for ($i = 1; $i < $array_len; $i++) { |
|
|
|
|
$sub_visibility = true; |
|
|
|
|
$real_dir .= '/'.$dir_array[$i]; |
|
|
|
|
$parent_id = self::get_document_id($course_info, $real_dir); |
|
|
|
|
if (!empty($parent_id)) { |
|
|
|
|
$parents[] = self::get_document_data_by_id($parent_id, $course_code, false); |
|
|
|
|
$sub_document_data = self::get_document_data_by_id($parent_id, $course_code, false); |
|
|
|
|
//@todo add visibility here |
|
|
|
|
|
|
|
|
|
/*$sub_visibility = self::is_visible_by_id($parent_id, $course_info, api_get_session_id(), api_get_user_id()); |
|
|
|
|
if ($visibility && $sub_visibility == false) { |
|
|
|
|
$visibility = false; |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
$parents[] = $sub_document_data; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//$row['visibility_for_user'] = $visibility; |
|
|
|
|
$row['parents'] = $parents; |
|
|
|
|
return $row; |
|
|
|
|
} |
|
|
|
|
@ -2841,5 +2875,26 @@ return 'application/octet-stream'; |
|
|
|
|
return $return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function check_visibility_tree($doc_id, $course_code, $session_id, $user_id) { |
|
|
|
|
$document_data = self::get_document_data_by_id($doc_id, $course_code); |
|
|
|
|
|
|
|
|
|
if (!empty($document_data)) { |
|
|
|
|
if ($document_data['parent_id'] == false) { |
|
|
|
|
$visible = self::is_visible_by_id($doc_id, $course_info, $session_id, $user_id); |
|
|
|
|
return $visible; |
|
|
|
|
} else { |
|
|
|
|
$course_info = api_get_course_info($course_code); |
|
|
|
|
$visible = self::is_visible_by_id($doc_id, $course_info, $session_id, $user_id); |
|
|
|
|
|
|
|
|
|
if (!$visible) { |
|
|
|
|
return false; |
|
|
|
|
} else { |
|
|
|
|
return self::check_visibility_tree($document_data['parent_id'], $course_code, $session_id, $user_id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//end class DocumentManager |