Adding session id + group id as suffix

1.9.x
Julio Montoya 11 years ago
parent 00440abad4
commit c352fba06a
  1. 15
      main/document/document.inc.php
  2. 20
      main/document/document.php
  3. 2
      main/inc/lib/document.lib.php
  4. 2
      main/inc/lib/fckeditor/editor/plugins/ImageManager/Classes/ImageManager.php
  5. 56
      main/inc/lib/fileUpload.lib.php
  6. 4
      main/inc/lib/groupmanager.lib.php
  7. 31
      main/newscorm/learnpath.class.php

@ -600,23 +600,28 @@ function build_edit_icons($document_data, $id, $is_template, $is_read_only = 0,
if (in_array($path, DocumentManager::get_system_folders())) { if (in_array($path, DocumentManager::get_system_folders())) {
$modify_icons .= ' ' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL); $modify_icons .= ' ' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL);
} else { } else {
if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && DocumentManager::get_default_certificate_id(api_get_course_id()) == $id) { $titleToShow = addslashes(basename($document_data['title']));
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid='.$document_id.$req_gid.'&amp;' . $sort_params . 'delete_certificate_id=' . $id . '" onclick="return confirmation(\'' . basename($path) . '\');">' .
if (isset($_GET['curdirpath']) &&
$_GET['curdirpath'] == '/certificates' &&
DocumentManager::get_default_certificate_id(api_get_course_id()) == $id
) {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid='.$document_id.$req_gid.'&amp;' . $sort_params . 'delete_certificate_id=' . $id . '" onclick="return confirmation(\'' . $titleToShow . '\');">' .
Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
} else { } else {
if ($is_certificate_mode) { if ($is_certificate_mode) {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid=' . $document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . $titleToShow . '\');">' .
Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
} else { } else {
if (api_get_session_id()) { if (api_get_session_id()) {
if ($document_data['session_id'] == api_get_session_id()) { if ($document_data['session_id'] == api_get_session_id()) {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid='.$document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">'. $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid='.$document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . $titleToShow . '\');">'.
Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
} else { } else {
$modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL); $modify_icons .= '&nbsp;' . Display::return_icon('delete_na.png', get_lang('ThisFolderCannotBeDeleted'), array(), ICON_SIZE_SMALL);
} }
} else { } else {
$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid='.$document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . basename($path) . '\');">' . $modify_icons .= '&nbsp;<a href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;curdirpath=' . $curdirpath . '&action=delete_item&id='.$parent_id.'&deleteid='.$document_id . $req_gid . '&amp;' . $sort_params . '" onclick="return confirmation(\'' . $titleToShow. '\');">' .
Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>'; Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . '</a>';
} }
} }

@ -232,7 +232,10 @@ switch ($action) {
if ($deleteDocument) { if ($deleteDocument) {
$certificateId = isset($_GET['delete_certificate_id']) ? $_GET['delete_certificate_id'] : null; $certificateId = isset($_GET['delete_certificate_id']) ? $_GET['delete_certificate_id'] : null;
DocumentManager::remove_attach_certificate(api_get_course_id(), $certificateId); DocumentManager::remove_attach_certificate(api_get_course_id(), $certificateId);
$message = Display::return_message(get_lang('DocDeleted').': '.$documentInfo['path'], 'success'); $message = Display::return_message(
get_lang('DocDeleted') . ': ' . $documentInfo['title'],
'success'
);
} else { } else {
$message = Display::return_message(get_lang('DocDeleteError'), 'warning'); $message = Display::return_message(get_lang('DocDeleteError'), 'warning');
} }
@ -1205,6 +1208,7 @@ if ($is_allowed_to_edit ||
if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') { if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
$message = Display::return_message(get_lang('CannotCreateDir'), 'error'); $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
} else { } else {
// dir_id is the parent folder id.
if (!empty($_POST['dir_id'])) { if (!empty($_POST['dir_id'])) {
// Get the document data from the ID // Get the document data from the ID
$document_data = DocumentManager::get_document_data_by_id( $document_data = DocumentManager::get_document_data_by_id(
@ -1232,7 +1236,7 @@ if ($is_allowed_to_edit ||
$dir_check = $base_work_dir.$dir_name; $dir_check = $base_work_dir.$dir_name;
$visibility = empty($groupId) ? null : 1; $visibility = empty($groupId) ? null : 1;
$created_dir = create_unexisting_directory( $newFolderData = create_unexisting_directory(
$courseInfo, $courseInfo,
api_get_user_id(), api_get_user_id(),
$sessionId, $sessionId,
@ -1244,10 +1248,16 @@ if ($is_allowed_to_edit ||
$visibility $visibility
); );
if ($created_dir) { if (!empty($newFolderData)) {
$message = Display::return_message(get_lang('DirCr').' '.$created_dir, 'confirmation'); $message = Display::return_message(
get_lang('DirCr') . ' ' . $newFolderData['title'],
'confirmation'
);
} else { } else {
$message = Display::return_message(get_lang('CannotCreateDir'), 'error'); $message = Display::return_message(
get_lang('CannotCreateDir'),
'error'
);
} }
} }

@ -1890,7 +1890,7 @@ class DocumentManager
$visibility_command = 'invisible'; $visibility_command = 'invisible';
if (!is_dir($base_work_dir_test)) { if (!is_dir($base_work_dir_test)) {
$created_dir = create_unexisting_directory( create_unexisting_directory(
$course_info, $course_info,
api_get_user_id(), api_get_user_id(),
api_get_session_id(), api_get_session_id(),

@ -804,7 +804,7 @@ class ImageManager
//@todo make this str to functions //@todo make this str to functions
$base_dir = substr($path, 0, strpos($path,'/document/')+9); // $base_dir = substr($path, 0, strpos($path,'/document/')+9); //
$new_dir = substr($fullpath, strlen($base_dir),-1); // $new_dir = substr($fullpath, strlen($base_dir),-1); //
$created_dir = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0,0, $base_dir, $new_dir,$newDir); create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), 0,0, $base_dir, $new_dir,$newDir);
$doc_id = DocumentManager::get_document_id($_course, $new_dir); $doc_id = DocumentManager::get_document_id($_course, $new_dir);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(),null,null,null,null, api_get_session_id()); api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(),null,null,null,null, api_get_session_id());
} else { } else {

@ -1334,6 +1334,11 @@ function search_img_from_html($html_file) {
return $img_path_list; return $img_path_list;
} }
function get_folder_suffix($courseInfo, $sessionId, $groupId)
{
return '_'.intval($sessionId).'_'.intval($groupId);
}
/** /**
* Creates a new directory trying to find a directory name * Creates a new directory trying to find a directory name
* that doesn't already exist * that doesn't already exist
@ -1364,29 +1369,46 @@ function create_unexisting_directory(
$title = null, $title = null,
$visibility = null $visibility = null
) { ) {
$nb = ''; $systemFolderName = $desired_dir_name;
// Adding prefix folder prefix
$prefix = get_folder_suffix($_course, $session_id, $to_group_id);
$systemFolderName .= $prefix;
/*$nb = '';
// add numerical suffix to directory if another one of the same number already exists // add numerical suffix to directory if another one of the same number already exists
while (file_exists($base_work_dir.$desired_dir_name.$nb)) { while (file_exists($base_work_dir.$systemFolderName.$nb)) {
$nb += 1; $nb += 1;
} }*/
if ($title == null) { if ($title == null) {
$title = basename($desired_dir_name); $title = basename($desired_dir_name);
} }
$course_id = $_course['real_id']; $course_id = $_course['real_id'];
if (!is_dir($base_work_dir.$systemFolderName)) {
mkdir(
$base_work_dir.$systemFolderName,
api_get_permissions_for_new_directories(),
true
);
if (mkdir($base_work_dir.$desired_dir_name.$nb, api_get_permissions_for_new_directories(), true)) {
// Check if pathname already exists inside document table // Check if pathname already exists inside document table
$tbl_document = Database::get_course_table(TABLE_DOCUMENT); $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$sql = "SELECT path FROM $tbl_document $sql = "SELECT id, path FROM $tbl_document
WHERE c_id = $course_id AND path='".$desired_dir_name.$nb."'"; WHERE
c_id = $course_id AND
(
path = '".$systemFolderName."'
)
";
$rs = Database::query($sql); $rs = Database::query($sql);
if (Database::num_rows($rs) == 0) { if (Database::num_rows($rs) == 0) {
$document_id = add_document( $document_id = add_document(
$_course, $_course,
$desired_dir_name . $nb, $systemFolderName,
'folder', 'folder',
0, 0,
$title, $title,
@ -1431,12 +1453,28 @@ function create_unexisting_directory(
$session_id $session_id
); );
} }
return $desired_dir_name.$nb; $documentData = DocumentManager::get_document_data_by_id(
$document_id,
$_course['code'],
false,
$session_id
);
return $documentData;
} else {
return false;
} }
} else { } else {
$document = Database::fetch_array($rs);
$documentData = DocumentManager::get_document_data_by_id(
$document['id'],
$_course['code'],
false,
$session_id
);
/* This means the folder NOT exist in the filesystem /* This means the folder NOT exist in the filesystem
(now this was created) but there is a record in the Database*/ (now this was created) but there is a record in the Database*/
return $desired_dir_name.$nb; return $documentData;
} }
} else { } else {
return false; return false;

@ -201,7 +201,7 @@ class GroupManager
$desired_dir_name= '/'.replace_dangerous_char($name,'strict').'_groupdocs'; $desired_dir_name= '/'.replace_dangerous_char($name,'strict').'_groupdocs';
$my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document'; $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document';
$unique_name = create_unexisting_directory( $newFolderData = create_unexisting_directory(
$_course, $_course,
api_get_user_id(), api_get_user_id(),
$session_id, $session_id,
@ -213,6 +213,8 @@ class GroupManager
1 1
); );
$unique_name = $newFolderData['path'];
/* Stores the directory path into the group table */ /* Stores the directory path into the group table */
$sql = "UPDATE ".$table_group." SET $sql = "UPDATE ".$table_group." SET
name = '".Database::escape_string($name)."', name = '".Database::escape_string($name)."',

@ -5679,14 +5679,15 @@ class learnpath
/** /**
* Creates the default learning path folder * Creates the default learning path folder
* @param array $course * @param array $course
* @return bool|string * @return bool
*/ */
public static function generate_learning_path_folder($course) { public static function generate_learning_path_folder($course) {
//Creating learning_path folder //Creating learning_path folder
$dir = '/learning_path'; $dir = '/learning_path';
$filepath = api_get_path(SYS_COURSE_PATH).$course['path'] . '/document'; $filepath = api_get_path(SYS_COURSE_PATH).$course['path'] . '/document';
$folder = false;
if (!is_dir($filepath.'/'.$dir)) { if (!is_dir($filepath.'/'.$dir)) {
$folder = create_unexisting_directory( $folderData = create_unexisting_directory(
$course, $course,
api_get_user_id(), api_get_user_id(),
api_get_session_id(), api_get_session_id(),
@ -5697,6 +5698,9 @@ class learnpath
get_lang('LearningPaths'), get_lang('LearningPaths'),
0 0
); );
if (!empty($folderData)) {
$folder = true;
}
} else { } else {
$folder = true; $folder = true;
} }
@ -5708,7 +5712,8 @@ class learnpath
* @param string $lp_name * @param string $lp_name
* @return array * @return array
*/ */
public function generate_lp_folder($course, $lp_name = null) { public function generate_lp_folder($course, $lp_name = null)
{
$filepath = ''; $filepath = '';
$dir = '/learning_path/'; $dir = '/learning_path/';
@ -5724,7 +5729,19 @@ class learnpath
$dir = $dir.$title; $dir = $dir.$title;
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'; $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
if (!is_dir($filepath.'/'.$dir)) { if (!is_dir($filepath.'/'.$dir)) {
$folder = create_unexisting_directory($course, api_get_user_id(), 0, 0, 0, $filepath, $dir , $lp_name); $folderData = create_unexisting_directory(
$course,
api_get_user_id(),
0,
0,
0,
$filepath,
$dir,
$lp_name
);
if (!empty($folderData)) {
$folder = true;
}
} else { } else {
$folder = true; $folder = true;
} }
@ -5733,7 +5750,11 @@ class learnpath
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'.$dir; $filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document'.$dir;
} }
} }
$array = array('dir' => $dir, 'filepath' => $filepath, 'folder' => $folder); $array = array(
'dir' => $dir,
'filepath' => $filepath,
'folder' => $folder
);
return $array; return $array;
} }

Loading…
Cancel
Save