Fixing file doc creation

1.9.x
Julio Montoya 11 years ago
parent 1dedd78fbe
commit 8b11aea7ce
  1. 10
      main/document/create_document.php
  2. 13
      main/inc/lib/document.lib.php

@ -351,8 +351,14 @@ $form->addElement('hidden', 'title_edited', 'false', 'id="title_edited"');
*/
function document_exists($filename) {
global $dir;
return DocumentManager::documentExists(
$dir.$filename.'.html',
// Clean up the name, only ASCII characters should stay. (and strict)
$cleanName = replace_dangerous_char($filename, 'strict');
// No "dangerous" files
$cleanName = disable_dangerous_file($cleanName);
return !DocumentManager::documentExists(
$dir.$cleanName.'.html',
api_get_course_info(),
api_get_session_id(),
api_get_group_id()

@ -4615,7 +4615,7 @@ class DocumentManager
$dir = null;
}
if (!empty($dir)) {
if (!empty($dir) && $dir != '/') {
$dir = $dir.'/';
}
@ -4709,14 +4709,14 @@ class DocumentManager
$fileNameWithSuffix = Database::escape_string($fileNameWithSuffix);
// Check if pathname already exists inside document table
$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$sql = "SELECT id, path FROM $tbl_document
$table = Database::get_course_table(TABLE_DOCUMENT);
$sql = "SELECT id, path FROM $table
WHERE
filetype = 'file' AND
c_id = $courseId AND
(
path = '".$fileNameEscape."' OR
path ='$fileNameWithSuffix'
path = '$fileNameWithSuffix'
) AND
(session_id = 0 OR session_id = $sessionId)
";
@ -4772,8 +4772,6 @@ class DocumentManager
{
$counter = 1;
$filePath = $path.$name;
error_log('getUniqueFileName');
error_log($filePath);
$uniqueName = $name;
while($documentExists = self::documentExists(
$filePath,
@ -4783,10 +4781,9 @@ class DocumentManager
)) {
$uniqueName = self::addSuffixToFileName($name, '_'.$counter);
$filePath = $path.$uniqueName;
error_log($filePath);
$counter++;
}
error_log($uniqueName);
return $uniqueName;
}

Loading…
Cancel
Save