Minor - format code.

1.9.x
Julio Montoya 10 years ago
parent 4b9be66ff5
commit f65a75ee6a
  1. 143
      main/document/document.php
  2. 10
      main/inc/lib/document.lib.php

@ -65,6 +65,7 @@ $document_path = $base_work_dir;
unset($_SESSION['draw_dir']);
unset($_SESSION['paint_dir']);
unset($_SESSION['temp_audio_nanogong']);
$plugin = new AppPlugin();
$pluginList = $plugin->get_installed_plugins();
$capturePluginInstalled = in_array('jcapture', $pluginList);
@ -82,7 +83,7 @@ if ($capturePluginInstalled) {
</script>';
}
// Create directory certificates
// Create directory certificates.
DocumentManager::create_directory_certificate_in_course(api_get_course_id());
if (empty($courseInfo)) {
@ -91,17 +92,17 @@ if (empty($courseInfo)) {
// Used for avoiding double-click.
$dbl_click_id = 0;
$selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']) : null;
$moveTo = isset($_POST['move_to']) ? Security::remove_XSS($_POST['move_to']) : null;
/* Constants and variables */
$session_id = api_get_session_id();
$userId = api_get_user_id();
$userInfo = api_get_user_info();
$sessionId = api_get_session_id();
$course_code = api_get_course_id();
$groupId = api_get_group_id();
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$group_member_with_upload_rights = false;
$userId = api_get_user_id();
// If the group id is set, we show them group documents
$group_properties = array();
@ -112,7 +113,7 @@ if (api_get_session_id() != 0) {
$group_member_with_upload_rights = $group_member_with_upload_rights && api_is_allowed_to_session_edit(false, true);
}
//Setting group variables
// Setting group variables.
if (!empty($groupId)) {
// Get group info
$group_properties = GroupManager::get_group_properties($groupId);
@ -172,8 +173,8 @@ switch ($action) {
case 'delete_item':
if ($is_allowed_to_edit ||
$group_member_with_upload_rights ||
is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) ||
is_my_shared_folder(api_get_user_id(), $moveTo, $session_id)
is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ||
is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId)
) {
if (isset($_GET['deleteid'])) {
if (!$is_allowed_to_edit) {
@ -181,7 +182,7 @@ switch ($action) {
if (!DocumentManager::is_visible_by_id(
$_GET['deleteid'],
$courseInfo,
$session_id,
$sessionId,
api_get_user_id())
) {
api_not_allowed();
@ -203,7 +204,7 @@ switch ($action) {
$_GET['deleteid'],
$courseInfo['code'],
false,
$session_id
$sessionId
);
// Check whether the document is in the database.
@ -212,7 +213,7 @@ switch ($action) {
$courseInfo,
null,
$base_work_dir,
api_get_session_id(),
$sessionId,
$_GET['deleteid'],
$groupId
);
@ -232,15 +233,16 @@ switch ($action) {
exit;
}
}
break;
case 'download':
// Get the document data from the ID
$document_data = DocumentManager::get_document_data_by_id(
$document_id,
api_get_course_id(),
false,
$session_id
$sessionId
);
if ($session_id != 0 && !$document_data) {
if ($sessionId != 0 && !$document_data) {
// If there is a session defined and asking for the document *from
// the session* didn't work, try it from the course (out of a
// session context)
@ -259,7 +261,7 @@ switch ($action) {
event_download($document_data['url']);
// Check visibility of document and paths
if (!($is_allowed_to_edit || $group_member_with_upload_rights)
&& !DocumentManager::is_visible_by_id($document_id, $courseInfo, $session_id, api_get_user_id())) {
&& !DocumentManager::is_visible_by_id($document_id, $courseInfo, $sessionId, api_get_user_id())) {
api_not_allowed(true);
}
$full_file_name = $base_work_dir.$document_data['path'];
@ -277,9 +279,9 @@ switch ($action) {
$document_id,
api_get_course_id(),
false,
$session_id
$sessionId
);
if ($session_id != 0 && !$document_data) {
if ($sessionId != 0 && !$document_data) {
// If there is a session defined and asking for the
// document * from the session* didn't work, try it from the
// course (out of a session context)
@ -292,8 +294,8 @@ switch ($action) {
}
//filter when I am into shared folder, I can download only my shared folder
if (is_any_user_shared_folder($document_data['path'], $session_id)) {
if (is_my_shared_folder(api_get_user_id(), $document_data['path'], $session_id)
if (is_any_user_shared_folder($document_data['path'], $sessionId)) {
if (is_my_shared_folder(api_get_user_id(), $document_data['path'], $sessionId)
|| api_is_allowed_to_edit()
|| api_is_platform_admin()) {
require 'downloadfolder.inc.php';
@ -323,9 +325,9 @@ switch ($action) {
$document_id,
api_get_course_id(),
true,
$session_id
$sessionId
);
if ($session_id != 0 && !$document_info) {
if ($sessionId != 0 && !$document_info) {
/* If there is a session defined and asking for the document
from the session didn't work, try it from the course
(out of a session context)*/
@ -419,9 +421,9 @@ if (isset($document_id) && empty($action)) {
$document_id,
api_get_course_id(),
true,
$session_id
$sessionId
);
if ($session_id != 0 && !$document_data) {
if ($sessionId != 0 && !$document_data) {
// If there is a session defined and asking for the
// document * from the session* didn't work, try it from the course
// (out of a session context)
@ -438,7 +440,7 @@ if (isset($document_id) && empty($action)) {
$visibility = DocumentManager::check_visibility_tree(
$document_id,
api_get_course_id(),
$session_id,
$sessionId,
api_get_user_id(),
$groupId
);
@ -606,13 +608,13 @@ if ($groupId != 0 && $curdirpath == '/') {
//if (!$is_allowed_to_edit || api_is_coach()) { before
if (!$is_allowed_to_edit && api_is_coach()) {
if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $courseInfo, $session_id, 'folder'))) {
if ($curdirpath != '/' && !(DocumentManager::is_visible($curdirpath, $courseInfo, $sessionId, 'folder'))) {
api_not_allowed(true);
}
}
/* Create shared folders */
if ($session_id == 0) {
if ($sessionId == 0) {
//Create shared folder. Necessary for recycled courses.
// session_id should always be zero and should always be created from a
// base course, never from a session.
@ -624,7 +626,7 @@ if ($session_id == 0) {
create_unexisting_directory(
$courseInfo,
api_get_user_id(),
$session_id,
$sessionId,
$groupId,
$to_user_id,
$base_work_dir,
@ -634,18 +636,15 @@ if ($session_id == 0) {
);
}
// Create dynamic user shared folder
if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.api_get_user_id())) {
$usf_dir_title = api_get_person_name(
$_user['firstName'],
$_user['lastName']
);
$usf_dir_name = '/shared_folder/sf_user_'.api_get_user_id();
if (!file_exists($base_work_dir.'/shared_folder/sf_user_'.$userId)) {
$usf_dir_title = $userInfo['complete_name'];
$usf_dir_name = '/shared_folder/sf_user_'.$userId;
$groupId = 0;
$visibility = 1;
create_unexisting_directory(
$courseInfo,
api_get_user_id(),
$session_id,
$sessionId,
$groupId,
$to_user_id,
$base_work_dir,
@ -655,16 +654,16 @@ if ($session_id == 0) {
);
}
} else {
//Create shared folder session
if (!file_exists($base_work_dir.'/shared_folder_session_'.$session_id)) {
$usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($session_id).')';
$usf_dir_name = '/shared_folder_session_'.$session_id;
// Create shared folder session.
if (!file_exists($base_work_dir.'/shared_folder_session_'.$sessionId)) {
$usf_dir_title = get_lang('UserFolders').' ('.api_get_session_name($sessionId).')';
$usf_dir_name = '/shared_folder_session_'.$sessionId;
$groupId = 0;
$visibility = 0;
create_unexisting_directory(
$courseInfo,
api_get_user_id(),
$session_id,
$sessionId,
$groupId,
$to_user_id,
$base_work_dir,
@ -674,17 +673,15 @@ if ($session_id == 0) {
);
}
//Create dynamic user shared folder into a shared folder session
if (!file_exists($base_work_dir.'/shared_folder_session_'.$session_id.'/sf_user_'.api_get_user_id())) {
$usf_dir_title = api_get_person_name(
$_user['firstName'],
$_user['lastName']).'('.api_get_session_name($session_id).')';
$usf_dir_name = '/shared_folder_session_'.$session_id.'/sf_user_'.api_get_user_id();
if (!file_exists($base_work_dir.'/shared_folder_session_'.$sessionId.'/sf_user_'.$userId)) {
$usf_dir_title = $userInfo['complete_name'].'('.api_get_session_name($sessionId).')';
$usf_dir_name = '/shared_folder_session_'.$sessionId.'/sf_user_'.$userId;
$groupId = 0;
$visibility = 1;
create_unexisting_directory(
$courseInfo,
api_get_user_id(),
$session_id,
$userId,
$sessionId,
$groupId,
$to_user_id,
$base_work_dir,
@ -771,9 +768,9 @@ if (!empty($documentAndFolders)) {
$file['id'],
api_get_course_id(),
false,
$session_id
$sessionId
);
if ($session_id != 0 && !$document_data) {
if ($sessionId != 0 && !$document_data) {
/* If there is a session defined and asking for the document
* from the session* didn't work, try it from the
course (out of a session context) */
@ -821,14 +818,14 @@ $moveForm = null;
//Only teacher and all users into their group and each user into his/her shared folder
if ($is_allowed_to_edit ||
$group_member_with_upload_rights ||
is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) ||
is_my_shared_folder(api_get_user_id(), $moveTo, $session_id)
is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) ||
is_my_shared_folder(api_get_user_id(), $moveTo, $sessionId)
) {
if (isset($_GET['move']) && $_GET['move'] != '') {
$my_get_move = intval($_REQUEST['move']);
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($my_get_move, $courseInfo, $session_id, api_get_user_id())) {
if (!DocumentManager::is_visible_by_id($my_get_move, $courseInfo, $sessionId, api_get_user_id())) {
api_not_allowed(true);
}
}
@ -843,7 +840,7 @@ if ($is_allowed_to_edit ||
$my_get_move,
api_get_course_id(),
false,
$session_id
$sessionId
);
$move_path = $document_to_move['path'];
@ -855,7 +852,7 @@ if ($is_allowed_to_edit ||
);
// filter if is my shared folder. TODO: move this code to build_move_to_selector function
if (is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id) && !$is_allowed_to_edit) {
if (is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId) && !$is_allowed_to_edit) {
//only main user shared folder
$main_user_shared_folder_main = '/shared_folder/sf_user_'.api_get_user_id();
$main_user_shared_folder_sub = '/shared_folder\/sf_user_'.api_get_user_id().'\//'; //all subfolders
@ -890,7 +887,7 @@ if ($is_allowed_to_edit ||
}
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($_POST['move_file'], $courseInfo, $session_id, api_get_user_id())) {
if (!DocumentManager::is_visible_by_id($_POST['move_file'], $courseInfo, $sessionId, api_get_user_id())) {
api_not_allowed(true);
}
}
@ -900,7 +897,7 @@ if ($is_allowed_to_edit ||
$_POST['move_file'],
api_get_course_id(),
false,
$session_id
$sessionId
);
// Security fix: make sure they can't move files that are not in the document table
@ -928,7 +925,7 @@ if ($is_allowed_to_edit ||
null,
null,
null,
$session_id
$sessionId
);
$message = Display::return_message(get_lang('DirMv'), 'confirmation');
} elseif (is_file($real_path_target)) {
@ -942,7 +939,7 @@ if ($is_allowed_to_edit ||
null,
null,
null,
$session_id
$sessionId
);
$message = Display::return_message(get_lang('DocMv'), 'confirmation');
}
@ -972,7 +969,7 @@ if ($is_allowed_to_edit ||
//Only teacher and all users into their group
if ($is_allowed_to_edit ||
$group_member_with_upload_rights ||
is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)
is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
) {
if (isset($_POST['action']) && isset($_POST['ids'])) {
$files = $_POST['ids'];
@ -998,7 +995,7 @@ if ($is_allowed_to_edit ||
null,
null,
null,
$session_id
$sessionId
)) {
$messages .= Display::return_message(get_lang('VisibilityChanged').': '.$data['path'], 'confirmation');
} else {
@ -1017,7 +1014,7 @@ if ($is_allowed_to_edit ||
null,
null,
null,
$session_id
$sessionId
)) {
$messages .= Display::return_message(get_lang('VisibilityChanged').': '.$data['path'], 'confirmation');
} else {
@ -1037,7 +1034,7 @@ if ($is_allowed_to_edit ||
null,
$id,
false,
$session_id
$sessionId
)
) {
$messages .= Display::return_message(get_lang('CantDeleteReadonlyFiles'), 'error');
@ -1052,7 +1049,7 @@ if ($is_allowed_to_edit ||
$courseInfo,
null,
$base_work_dir,
$session_id,
$sessionId,
$documentId,
$groupId
);
@ -1075,7 +1072,7 @@ $dirForm = null;
//Only teacher and all users into their group and any user into his/her shared folder
if ($is_allowed_to_edit ||
$group_member_with_upload_rights ||
is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)
is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
) {
// Create directory with $_POST data
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
@ -1091,9 +1088,9 @@ if ($is_allowed_to_edit ||
$_POST['dir_id'],
api_get_course_id(),
false,
$session_id
$sessionId
);
if ($session_id != 0 && !$document_data) {
if ($sessionId != 0 && !$document_data) {
// If there is a session defined and asking for the
// document * from the session* didn't work, try it from
// the course (out of a session context)
@ -1117,7 +1114,7 @@ if ($is_allowed_to_edit ||
$created_dir = create_unexisting_directory(
$courseInfo,
api_get_user_id(),
$session_id,
$sessionId,
$groupId,
$to_user_id,
$base_work_dir,
@ -1161,7 +1158,7 @@ if ($is_allowed_to_edit) {
if (!$is_allowed_to_edit) {
if (api_is_coach()) {
if (!DocumentManager::is_visible_by_id($update_id, $courseInfo, $session_id, api_get_user_id())) {
if (!DocumentManager::is_visible_by_id($update_id, $courseInfo, $sessionId, api_get_user_id())) {
api_not_allowed(true);
}
}
@ -1181,7 +1178,7 @@ if ($is_allowed_to_edit) {
null,
null,
null,
$session_id)
$sessionId)
) {
//don't use ViMod because firt is load ViMdod (Gradebook). VisibilityChanged (trad4all)
$message = Display::return_message(get_lang('VisibilityChanged'), 'confirmation');
@ -1197,7 +1194,7 @@ $templateForm = null;
//Only teacher and all users into their group
if ($is_allowed_to_edit ||
$group_member_with_upload_rights ||
is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)
is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
) {
if (isset($_GET['add_as_template']) && !isset($_POST['create_template'])) {
@ -1387,7 +1384,7 @@ $column_show = array();
if ($is_allowed_to_edit ||
$group_member_with_upload_rights ||
is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)
is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
) {
// TODO:check enable more options for shared folders
/* CREATE NEW DOCUMENT OR NEW DIRECTORY / GO TO UPLOAD / DOWNLOAD ZIPPED FOLDER */
@ -1515,7 +1512,7 @@ if (isset($documentAndFolders) && is_array($documentAndFolders)) {
$is_visible = DocumentManager::is_visible_by_id(
$document_data['id'],
$courseInfo,
$session_id,
$sessionId,
api_get_user_id(),
false
);
@ -1591,7 +1588,7 @@ if (isset($documentAndFolders) && is_array($documentAndFolders)) {
$row[] = $invisibility_span_open.$display_date.$invisibility_span_close;
// Admins get an edit column
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)) {
$is_template = isset($document_data['is_template']) ? $document_data['is_template'] : false;
// If readonly, check if it the owner of the file or if the user is an admin
if ($document_data['insert_user_id'] == api_get_user_id() || api_is_platform_admin()) {
@ -1634,7 +1631,7 @@ if (!is_null($documentAndFolders)) {
)
) {
//for student does not show icon into other shared folder, and does not show into main path (root)
if (is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)
if (is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
&& $curdirpath != '/'
|| api_is_allowed_to_edit()
|| api_is_platform_admin()
@ -1693,7 +1690,7 @@ $column_show[] = 1;
if ($is_allowed_to_edit
|| $group_member_with_upload_rights
|| is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)
|| is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)
) {
$column_show[] = 1;
}
@ -1752,7 +1749,7 @@ $table->set_header($column++, get_lang('Date'), true, array('style' => 'width:15
// Admins get an edit column
if ($is_allowed_to_edit
|| $group_member_with_upload_rights
|| is_my_shared_folder(api_get_user_id(), $curdirpath, $session_id)) {
|| is_my_shared_folder(api_get_user_id(), $curdirpath, $sessionId)) {
$table->set_header($column++, get_lang('Actions'), false, array('class' => 'td_actions'));
}

@ -469,8 +469,10 @@ class DocumentManager
/**
* Session folder filters
*
* @param string $path
* @param int $sessionId
* @param int $sessionId
*
* @return null|string
*/
public static function getSessionFolderFilters($path, $sessionId)
@ -486,6 +488,7 @@ class DocumentManager
// share_folder filter
$condition .= " AND docs.path != '/shared_folder' ";
}
return $condition;
}
@ -563,7 +566,8 @@ class DocumentManager
FROM $TABLE_ITEMPROPERTY AS last
INNER JOIN $TABLE_DOCUMENT AS docs
ON (
docs.id = last.ref AND last.tool = '".TOOL_DOCUMENT."' AND
docs.id = last.ref AND
last.tool = '".TOOL_DOCUMENT."' AND
docs.c_id = {$_course['real_id']} AND
last.c_id = {$_course['real_id']}
)
@ -1045,6 +1049,7 @@ class DocumentManager
* @param string $base_work_dir, path to the documents folder (if not defined, $documentId must be used)
* @param int $sessionId The ID of the session, if any
* @param int $documentId The document id, if available
* @param int $groupId
* @return boolean true/false
* @todo now only files/folders in a folder get visibility 2, we should rename them too.
* @todo We should be able to get rid of this later when using only documentId (check further usage)
@ -1058,6 +1063,7 @@ class DocumentManager
$groupId = null
) {
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
if (empty($groupId)) {
$groupId = api_get_group_id();
} else {

Loading…
Cancel
Save