Use group.iid when saving into c_item_property, fixing queries

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 88c3c2c32c
commit 1e8eeafd1d
  1. 33
      main/document/create_document.php
  2. 2
      main/document/document_quota.php
  3. 9
      main/document/edit_odf.php
  4. 2
      main/document/remote.php
  5. 9
      main/document/upload.php
  6. 30
      main/inc/lib/api.lib.php
  7. 26
      main/inc/lib/document.lib.php
  8. 51
      main/inc/lib/fileUpload.lib.php
  9. 15
      main/inc/lib/javascript/svgedit/extensions/imagelib/index.php
  10. 10
      main/inc/lib/svg-edit/extensions/imagelib/groups.php
  11. 9
      main/inc/lib/svg-edit/extensions/imagelib/index.php
  12. 12
      main/inc/lib/webservices/Rest.php

@ -98,10 +98,15 @@ if (!empty($sessionId) && empty($document_data)) {
$sessionId
);
}
$groupIid = 0;
if (!empty($groupId)) {
$group_properties = GroupManager::get_group_properties($groupId);
$groupIid = $group_properties['iid'];
}
if (empty($document_data)) {
if (api_is_in_group()) {
$group_properties = GroupManager::get_group_properties($groupId);
$document_id = DocumentManager::get_document_id($_course, $group_properties['directory']);
$document_data = DocumentManager::get_document_data_by_id($document_id, api_get_course_id());
$dir = $document_data['path'];
@ -191,7 +196,6 @@ if (!is_dir($filepath)) {
}
$to_group_id = 0;
if (!$is_certificate_mode) {
if (api_is_in_group()) {
$interbreadcrumb[] = array(
@ -199,7 +203,7 @@ if (!$is_certificate_mode) {
"name" => get_lang('GroupSpace'),
);
$noPHP_SELF = true;
$to_group_id = api_get_group_id();
$to_group_id = $group_properties['iid'];
$path = explode('/', $dir);
if ('/'.$path[1] != $group_properties['directory']) {
api_not_allowed(true);
@ -300,7 +304,11 @@ $current_session_id = api_get_session_id();
$form->addHtmlEditor('content', get_lang('Content'), true, true, $editorConfig, true);
// Comment-field
$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
$folders = DocumentManager::get_all_document_folders(
$_course,
$groupIid,
$is_allowed_to_edit
);
// If we are not in the certificates creation, display a folder chooser for the
// new document created
@ -308,13 +316,20 @@ $folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is
if (!$is_certificate_mode &&
!DocumentManager::is_my_shared_folder($userId, $dir, $current_session_id)
) {
$folders = DocumentManager::get_all_document_folders($_course, $to_group_id, $is_allowed_to_edit);
$folders = DocumentManager::get_all_document_folders(
$_course,
$groupIid,
$is_allowed_to_edit
);
//$parent_select = $form->addElement('select', 'curdirpath', array(null, get_lang('DestinationDirectory')));
$parent_select = $form->addSelect('curdirpath', get_lang('DestinationDirectory'),null, array('cols-size' => [2, 10, 0]) );
// Following two conditions copied from document.inc.php::build_directory_selector()
$folder_titles = array();
$parent_select = $form->addSelect(
'curdirpath',
get_lang('DestinationDirectory'),
null,
array('cols-size' => [2, 10, 0])
);
$folder_titles = array();
if (is_array($folders)) {
$escaped_folders = array();
foreach ($folders as $key => & $val) {

@ -76,7 +76,7 @@ if (!empty($group_list)) {
$session[] = array(addslashes(get_lang('Group').': '.$group_data['name']).' ('.format_file_size($quota_bytes).')', $quota_percentage);
}
}
//Showing weight of documents uploaded by user
// Showing weight of documents uploaded by user
$document_list = DocumentManager::get_all_document_data($_course);
if (is_array($document_list)) {
foreach ($document_list as $document_data) {

@ -20,8 +20,13 @@ if ($document_id) {
}
//Check user visibility
//$is_visible = DocumentManager::is_visible_by_id($document_id, $course_info, api_get_session_id(), api_get_user_id());
$is_visible = DocumentManager::check_visibility_tree($document_id, api_get_course_id(), api_get_session_id(), api_get_user_id(), api_get_group_id());
$is_visible = DocumentManager::check_visibility_tree(
$document_id,
api_get_course_id(),
api_get_session_id(),
api_get_user_id(),
api_get_group_id()
);
if (!api_is_allowed_to_edit() && !$is_visible) {
api_not_allowed(true);

@ -58,7 +58,7 @@ if ($action == 'list') {
if ($debug>0) { error_log("sending file list",0); }
// get files list
$files = DocumentManager::get_all_document_data($_course, $cwd, 0, NULL, false);
$files = DocumentManager::get_all_document_data($_course, $cwd, 0, null, false);
// adding download link to files
foreach ($files as $k => $f) {

@ -103,12 +103,13 @@ function setFocus(){
}
</script>';
$groupIid = 0;
// This needs cleaning!
if (!empty($groupId)) {
// If the group id is set, check if the user has the right to be here
// Get group info
$group_properties = GroupManager::get_group_properties($groupId);
$groupIid = $group_properties['iid'];
// Only courseadmin or group members allowed
if ($is_allowed_to_edit || GroupManager::is_user_in_group(api_get_user_id(), $group_properties['iid'])) {
@ -217,7 +218,11 @@ if ($is_certificate_mode) {
// Link to create a folder
echo $toolbar = Display::toolbarAction('toolbar-upload', array($actions), 1);
// Form to select directory
$folders = DocumentManager::get_all_document_folders($_course, $groupId, $is_allowed_to_edit);
$folders = DocumentManager::get_all_document_folders(
$_course,
$groupIid,
$is_allowed_to_edit
);
if (!$is_certificate_mode) {
echo DocumentManager::build_directory_selector(
$folders,

@ -3528,7 +3528,7 @@ function api_item_property_delete(
* (3) "visible"
* (4) "invisible"
* @param int $user_id id of the editing/adding user
* @param int $to_group_id id of the intended group (0 = for everybody), only relevant for $type (1)
* @param int $to_group_id group.iid
* @param int $to_user_id id of the intended user (always has priority over $to_group_id !), only relevant for $type (1)
* @param string $start_visible 0000-00-00 00:00:00 format
* @param string $end_visible 0000-00-00 00:00:00 format
@ -6810,17 +6810,33 @@ function api_is_global_chat_enabled()
*
* @param int $item_id
* @param int $tool_id
* @param int $group_id
* @param int $group_id iid
* @param array $courseInfo
*/
function api_set_default_visibility($item_id, $tool_id, $group_id = 0, $courseInfo = array(), $sessionId = 0, $userId = 0)
{
function api_set_default_visibility(
$item_id,
$tool_id,
$group_id = 0,
$courseInfo = array(),
$sessionId = 0,
$userId = 0
) {
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
$courseId = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
$sessionId = empty($sessionId) ? api_get_session_id() : $sessionId;
$userId = empty($userId) ? api_get_user_id() : $userId;
if (empty($group_id)) {
$group_id = api_get_group_id();
}
$groupInfo = GroupManager::get_group_properties($group_id);
$groupIid = 0;
if ($groupInfo) {
$groupIid = $groupInfo['iid'];
}
$original_tool_id = $tool_id;
switch ($tool_id) {
@ -6854,10 +6870,6 @@ function api_set_default_visibility($item_id, $tool_id, $group_id = 0, $courseIn
$visibility = 'visible';
}
if (empty($group_id)) {
$group_id = api_get_group_id();
}
// Read the portal and course default visibility
if ($tool_id == 'documents') {
$visibility = DocumentManager::getDocumentDefaultVisibility($courseCode);
@ -6869,7 +6881,7 @@ function api_set_default_visibility($item_id, $tool_id, $group_id = 0, $courseIn
$item_id,
$visibility,
$userId,
$group_id,
$groupIid,
null,
null,
null,

@ -531,7 +531,7 @@ class DocumentManager
*
* @param array $_course
* @param string $path
* @param int $to_group_id
* @param int $to_group_id iid
* @param int $to_user_id
* @param boolean $can_see_invisible
* @param boolean $search
@ -741,7 +741,7 @@ class DocumentManager
* can show all folders (except for the deleted ones) or only visible ones
*
* @param array $_course
* @param int $to_group_id iid
* @param int $groupIid iid
* @param boolean $can_see_invisible
* @param boolean $getInvisibleList
*
@ -749,13 +749,13 @@ class DocumentManager
*/
public static function get_all_document_folders(
$_course,
$to_group_id = 0,
$groupIid = 0,
$can_see_invisible = false,
$getInvisibleList = false
) {
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$to_group_id = intval($to_group_id);
$groupIid = intval($groupIid);
$document_folders = array();
$students = CourseManager::get_user_list_from_course_code(
@ -770,8 +770,8 @@ class DocumentManager
}
}
$groupCondition = " last.to_group_id = $to_group_id";
if (empty($to_group_id)) {
$groupCondition = " last.to_group_id = $groupIid";
if (empty($groupIid)) {
$groupCondition = " (last.to_group_id = 0 OR last.to_group_id IS NULL)";
}
@ -785,7 +785,7 @@ class DocumentManager
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id');
if ($to_group_id <> 0) {
if ($groupIid <> 0) {
$sql = "SELECT DISTINCT docs.id, path
FROM $TABLE_ITEMPROPERTY AS last
INNER JOIN $TABLE_DOCUMENT AS docs
@ -890,9 +890,9 @@ class DocumentManager
$condition_session = api_get_session_condition($session_id, true, false, 'docs.session_id');
//get invisible folders
$sql = "SELECT DISTINCT docs.id, path
FROM $TABLE_ITEMPROPERTY AS last, $TABLE_DOCUMENT AS docs
WHERE
docs.id = last.ref AND
FROM $TABLE_ITEMPROPERTY AS last INNER JOIN $TABLE_DOCUMENT AS docs
ON (docs.id = last.ref AND last.c_id = docs.c_id)
WHERE
docs.filetype = 'folder' AND
last.tool = '" . TOOL_DOCUMENT . "' AND
$groupCondition AND
@ -2037,7 +2037,6 @@ class DocumentManager
$id = self::get_document_id_of_directory_certificate();
if (empty($id)) {
create_unexisting_directory(
$courseInfo,
api_get_user_id(),
@ -2054,7 +2053,6 @@ class DocumentManager
$id = self::get_document_id_of_directory_certificate();
if (empty($id)) {
$id = add_document(
$courseInfo,
$dir_name,
@ -3861,7 +3859,7 @@ class DocumentManager
* @param string $course_code
* @param int $session_id
* @param int $user_id
* @param int $groupId
* @param int $groupId iid
* @return bool
*/
public static function check_visibility_tree(
@ -4912,7 +4910,7 @@ class DocumentManager
* @param string $folder Example: /folder/folder2
* @param array $courseInfo
* @param int $sessionId
* @param int $groupId
* @param int $groupId group.id
*
* @return bool
*/

@ -165,7 +165,7 @@ function process_uploaded_file($uploaded_file, $show_output = true)
* @param string $documentDir Example: /var/www/chamilo/courses/ABC/document
* @param string $uploadPath Example: /folder1/folder2/
* @param int $userId
* @param int $groupId, 0 for everybody
* @param int $groupId group.id
* @param int $toUserId, NULL for everybody
* @param int $unzip 1/0
* @param string $whatIfFileExists overwrite, rename or warn if exists (default)
@ -212,6 +212,12 @@ function handle_uploaded_document(
$sessionId = intval($sessionId);
}
$groupIid = 0;
if (!empty($groupId)) {
$groupInfo = GroupManager::get_group_properties($groupId);
$groupIid = $groupInfo['iid'];
}
// Just in case process_uploaded_file is not called
$maxSpace = DocumentManager::get_course_quota();
@ -302,13 +308,6 @@ function handle_uploaded_document(
Using the session_id and group_id if values are not empty
*/
/*$fileExists = DocumentManager::documentExists(
$uploadPath.$cleanName,
$courseInfo,
$sessionId,
$groupId
);*/
$fileSystemName = DocumentManager::fixDocumentName(
$cleanName,
'file',
@ -390,7 +389,7 @@ function handle_uploaded_document(
$documentId,
'DocumentUpdated',
$userId,
$groupId,
$groupIid,
$toUserId,
null,
null,
@ -429,7 +428,7 @@ function handle_uploaded_document(
$documentId,
'DocumentAdded',
$userId,
$groupId,
$groupIid,
$toUserId,
null,
null,
@ -479,7 +478,7 @@ function handle_uploaded_document(
$documentId,
'DocumentAdded',
$userId,
$groupId,
$groupIid,
$toUserId,
null,
null,
@ -489,6 +488,7 @@ function handle_uploaded_document(
// Redo visibility
api_set_default_visibility($documentId, TOOL_DOCUMENT, null, $courseInfo);
}
// If the file is in a folder, we need to update all parent folders
item_property_update_on_folder($courseInfo, $uploadPath, $userId);
// Display success message to user
@ -1031,7 +1031,7 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
* @param int $maxFilledSpace - amount of bytes to not exceed in the base
* working directory
* @param int $sessionId
* @param int $groupId
* @param int $groupId group.id
* @param boolean $output Optional. If no output not wanted on success, set to false.
*
* @return boolean true if it succeeds false otherwise
@ -1208,7 +1208,7 @@ function filter_extension(&$filename)
* @param string $comment
* @param int $readonly
* @param bool $save_visibility
* @param int $group_id
* @param int $group_id group.id
* @param int $session_id Session ID, if any
* @param int $userId creator id
*
@ -1250,7 +1250,14 @@ function add_document(
Database::query($sql);
if ($save_visibility) {
api_set_default_visibility($documentId, TOOL_DOCUMENT, $group_id, $_course, $session_id, $userId);
api_set_default_visibility(
$documentId,
TOOL_DOCUMENT,
$group_id,
$_course,
$session_id,
$userId
);
}
return $documentId;
@ -1464,7 +1471,7 @@ function search_img_from_html($html_file) {
* @param array $_course current course information
* @param int $user_id current user id
* @param int $session_id
* @param int $to_group_id
* @param int $to_group_id group.id
* @param int $to_user_id
* @param string $base_work_dir /var/www/chamilo/courses/ABC/document
* @param string $desired_dir_name complete path of the desired name
@ -1554,6 +1561,12 @@ function create_unexisting_directory(
)
";
$groupIid = 0;
if (!empty($to_group_id)) {
$groupInfo = GroupManager::get_group_properties($to_group_id);
$groupIid = $groupInfo['iid'];
}
$rs = Database::query($sql);
if (Database::num_rows($rs) == 0) {
$document_id = add_document(
@ -1584,7 +1597,7 @@ function create_unexisting_directory(
$document_id,
$visibilities[$visibility],
$user_id,
$to_group_id,
$groupIid,
$to_user_id,
null,
null,
@ -1597,7 +1610,7 @@ function create_unexisting_directory(
$document_id,
'FolderCreated',
$user_id,
$to_group_id,
$groupIid,
$to_user_id,
null,
null,
@ -1644,7 +1657,7 @@ function create_unexisting_directory(
* @param string $base_work_dir
* @param string $missing_files_dir
* @param int $user_id
* @param int $max_filled_space
* @param int $to_group_id group.id
*/
function move_uploaded_file_collection_into_directory(
$_course,
@ -1815,7 +1828,7 @@ function build_missing_files_form($missing_files, $upload_path, $file_name)
* @param string $base_work_dir
* @param string $folderPath
* @param int $sessionId
* @param int $groupId
* @param int $groupId group.id
* @param bool $output
* @param array $parent
* @param string $uploadPath

@ -6,18 +6,23 @@
//Chamilo load libraries
require_once '../../../../../../inc/global.inc.php';
//Add security from Chamilo
// Add security from Chamilo
api_protect_course_script();
api_block_anonymous_users();
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$curdirpath='/images/gallery'; //path of library directory
$course_info = api_get_course_info();
//get all files and folders
$docs_and_folders = DocumentManager::get_all_document_data($course_info, $curdirpath, 0, null, $is_allowed_to_edit, false);
// Get all files and folders
$docs_and_folders = DocumentManager::get_all_document_data(
$course_info,
$curdirpath,
0,
null,
$is_allowed_to_edit,
false
);
//get all filenames
$array_to_search = is_array($docs_and_folders) ? $docs_and_folders : array();

@ -16,7 +16,11 @@ $course_info = api_get_course_info();
$groupId = api_get_group_id();
$group_properties = GroupManager::get_group_properties($groupId);
$groupdirpath = $group_properties['directory'];
$groupIid = 0;
if ($group_properties) {
$groupdirpath = $group_properties['directory'];
$groupIid = $group_properties['iid'];
}
$group_disk_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
$group_web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'.$groupdirpath.'/';
@ -24,13 +28,13 @@ $group_web_path = api_get_path(WEB_COURSE_PATH).$course_info['path'].'/document'
$docs_and_folders = DocumentManager::get_all_document_data(
$course_info,
$groupdirpath,
api_get_group_id(),
$groupIid,
null,
$is_allowed_to_edit,
false
);
//get all group filenames
// get all group filenames
$array_to_search = is_array($docs_and_folders) ? $docs_and_folders : array();
if (count($array_to_search) > 0) {

@ -16,7 +16,14 @@ $curdirpath='/images/gallery'; //path of library directory
$course_info = api_get_course_info();
//get all files and folders
$docs_and_folders = DocumentManager::get_all_document_data($course_info, $curdirpath, 0, null, $is_allowed_to_edit, false);
$docs_and_folders = DocumentManager::get_all_document_data(
$course_info,
$curdirpath,
0,
null,
$is_allowed_to_edit,
false
);
//get all filenames
$array_to_search = is_array($docs_and_folders) ? $docs_and_folders : array();

@ -283,12 +283,18 @@ class Rest extends WebService
$path = $directory['path'];
}
require_once api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php';
$courseInfo = api_get_course_info_by_id($this->course->getId());
$documents = DocumentManager::get_all_document_data($courseInfo, $path, 0, null, false, false, $sessionId);
$documents = DocumentManager::get_all_document_data(
$courseInfo,
$path,
0,
null,
false,
false,
$sessionId
);
$results = [];
if (is_array($documents)) {

Loading…
Cancel
Save