コード例 #1
0
 /**
  * changes the exercise sound file
  *
  * @author Olivier Brouckaert
  * @param string $sound - exercise sound file
  * @param string $delete - ask to delete the file
  */
 public function updateSound($sound, $delete)
 {
     global $audioPath, $documentPath;
     $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
     if ($sound['size'] && (strstr($sound['type'], 'audio') || strstr($sound['type'], 'video'))) {
         $this->sound = $sound['name'];
         if (@move_uploaded_file($sound['tmp_name'], $audioPath . '/' . $this->sound)) {
             $query = "SELECT 1 FROM {$TBL_DOCUMENT}\n                        WHERE c_id = " . $this->course_id . " AND path='" . str_replace($documentPath, '', $audioPath) . '/' . $this->sound . "'";
             $result = Database::query($query);
             if (!Database::num_rows($result)) {
                 $id = add_document($this->course, str_replace($documentPath, '', $audioPath) . '/' . $this->sound, 'file', $sound['size'], $sound['name']);
                 api_item_property_update($this->course, TOOL_DOCUMENT, $id, 'DocumentAdded', api_get_user_id());
                 item_property_update_on_folder($this->course, str_replace($documentPath, '', $audioPath), api_get_user_id());
             }
         }
     } elseif ($delete && is_file($audioPath . '/' . $this->sound)) {
         $this->sound = '';
     }
 }
コード例 #2
0
     api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $userId, null, null, null, null, $current_session_id);
 }
 if (!is_file($filepath . 'css/frames.css')) {
     // Make a copy of the current css for the new document
     copy(api_get_path(SYS_CODE_PATH) . 'css/' . api_get_setting('stylesheets') . '/frames.css', $filepath . 'css/frames.css');
     $doc_id = add_document($_course, $dir . 'css/frames.css', 'file', filesize($filepath . 'css/frames.css'), 'frames.css');
     api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $userId, null, null, null, null, $current_session_id);
     api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $userId, null, null, null, null, $current_session_id);
 }
 $file_size = filesize($filepath . $filename . '.' . $extension);
 $save_file_path = $dir . $filename . '.' . $extension;
 $document_id = add_document($_course, $save_file_path, 'file', $file_size, $title, null, $readonly);
 if ($document_id) {
     api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $userId, $to_group_id, null, null, null, $current_session_id);
     // Update parent folders
     item_property_update_on_folder($_course, $dir, $userId);
     $new_comment = isset($_POST['comment']) ? trim($_POST['comment']) : '';
     $new_comment = Database::escape_string($new_comment);
     $new_title = isset($_POST['title']) ? trim($_POST['title']) : '';
     $new_title = htmlspecialchars($new_title);
     $new_title = Database::escape_string($new_title);
     if ($new_comment || $new_title) {
         $ct = '';
         if ($new_comment) {
             $ct .= ", comment='{$new_comment}'";
         }
         if ($new_title) {
             $ct .= ", title='{$new_title}'";
         }
         Database::query("UPDATE {$doc_table} SET" . substr($ct, 1) . " WHERE c_id = {$course_id} AND id = '{$document_id}'");
     }
コード例 #3
0
//missing images are submitted
if (isset($_POST['submit_image'])) {
    $number_of_uploaded_images = count($_FILES['img_file']['name']);
    //if images are uploaded
    if ($number_of_uploaded_images > 0) {
        //we could also create a function for this, I'm not sure...
        //create a directory for the missing files
        $img_directory = str_replace('.', '_', $_POST['related_file'] . "_files");
        $folderData = create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $img_directory);
        $missing_files_dir = $folderData['path'];
        //put the uploaded files in the new directory and get the paths
        $paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'], $base_work_dir, $missing_files_dir, $_user['user_id'], $to_group_id, $to_user_id, $max_filled_space);
        //open the html file and replace the paths
        replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir . $_POST['related_file']);
        //update parent folders
        item_property_update_on_folder($_course, $_POST['curdirpath'], $_user['user_id']);
    }
}
//they want to create a directory
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
    $added_slash = $path == '/' ? '' : '/';
    $dir_name = $path . $added_slash . api_replace_dangerous_char($_POST['dirname']);
    $created_dir = create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $_POST['dirname']);
    if ($created_dir) {
        Display::display_normal_message(get_lang('DirCr'));
        $path = $created_dir;
    } else {
        display_error(get_lang('CannotCreateDir'));
    }
}
if (isset($_GET['createdir'])) {
コード例 #4
0
/**
 * @param string $message
 * @param array $_course
 * @param int $group_id
 * @param int $session_id
 * @param bool $preview
 */
function saveMessage($message, $userId, $_course, $session_id, $group_id, $preview = true)
{
    $userInfo = api_get_user_info($userId);
    $fullName = $userInfo['complete_name'];
    $isMaster = (bool) api_is_course_admin();
    $document_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
    if (!empty($group_id)) {
        $group_info = GroupManager::get_group_properties($group_id);
        $basepath_chat = $group_info['directory'] . '/chat_files';
    } else {
        $basepath_chat = '/chat_files';
    }
    $chat_path = $document_path . $basepath_chat . '/';
    if (!is_dir($chat_path)) {
        if (is_file($chat_path)) {
            @unlink($chat_path);
        }
    }
    $date_now = date('Y-m-d');
    $message = trim($message);
    $timeNow = date('d/m/y H:i:s');
    if (!empty($group_id)) {
        $basename_chat = 'messages-' . $date_now . '_gid-' . $group_id;
    } elseif (!empty($session_id)) {
        $basename_chat = 'messages-' . $date_now . '_sid-' . $session_id;
    } else {
        $basename_chat = 'messages-' . $date_now;
    }
    if (!api_is_anonymous()) {
        if (!empty($message)) {
            Emojione\Emojione::$imagePathPNG = api_get_path(WEB_LIBRARY_PATH) . 'javascript/emojione/png/';
            Emojione\Emojione::$ascii = true;
            // Parsing emojis
            $message = Emojione\Emojione::toImage($message);
            // Parsing text to understand markdown (code highlight)
            $message = MarkdownExtra::defaultTransform($message);
            // Security XSS
            $message = Security::remove_XSS($message);
            if ($preview == true) {
                return $message;
            }
            if (!file_exists($chat_path . $basename_chat . '.log.html')) {
                $doc_id = add_document($_course, $basepath_chat . '/' . $basename_chat . '.log.html', 'file', 0, $basename_chat . '.log.html');
                api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $userId, $group_id, null, null, null, $session_id);
                api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $userId, $group_id, null, null, null, $session_id);
                item_property_update_on_folder($_course, $basepath_chat, $userId);
            } else {
                $doc_id = DocumentManager::get_document_id($_course, $basepath_chat . '/' . $basename_chat . '.log.html');
            }
            $fp = fopen($chat_path . $basename_chat . '.log.html', 'a');
            $userPhoto = Usermanager::getUserPicture($userId, USER_IMAGE_SIZE_MEDIUM);
            $filePhoto = '<img class="chat-image" src="' . $userPhoto . '"/>';
            if ($isMaster) {
                fputs($fp, '<div class="message-teacher"><div class="content-message"><div class="chat-message-block-name">' . $fullName . '</div><div class="chat-message-block-content">' . $message . '</div><div class="message-date">' . $timeNow . '</div></div><div class="icon-message"></div>' . $filePhoto . '</div>' . "\n");
            } else {
                fputs($fp, '<div class="message-student">' . $filePhoto . '<div class="icon-message"></div><div class="content-message"><div class="chat-message-block-name">' . $fullName . '</div><div class="chat-message-block-content">' . $message . '</div><div class="message-date">' . $timeNow . '</div></div></div>' . "\n");
            }
            fclose($fp);
            $chat_size = filesize($chat_path . $basename_chat . '.log.html');
            update_existing_document($_course, $doc_id, $chat_size);
            item_property_update_on_folder($_course, $basepath_chat, $userId);
        }
    }
}
コード例 #5
0
ファイル: fileUpload.lib.php プロジェクト: daffef/chamilo-lms
/**
 * This function does the save-work for the documents.
 * It handles the uploaded file and adds the properties to the database
 * If unzip=1 and the file is a zipfile, it is extracted
 * If we decide to save ALL kinds of documents in one database,
 * we could extend this with a $type='document', 'scormdocument',...
 *
 * @param array $courseInfo
 * @param array $uploadedFile ($_FILES)
 * array(
 *  'name' => 'picture.jpg',
 *  'tmp_name' => '...', // absolute path
 * );
 * @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 $toUserId, NULL for everybody
 * @param int $unzip 1/0
 * @param string $whatIfFileExists overwrite, rename or warn if exists (default)
 * @param boolean $output Optional output parameter.
 * @param bool $onlyUploadFile
 * @param string $comment
 * @param int $sessionId
 *
 * So far only use for unzip_uploaded_document function.
 * If no output wanted on success, set to false.
 * @param string $comment
 * @return string path of the saved file
 */
function handle_uploaded_document($courseInfo, $uploadedFile, $documentDir, $uploadPath, $userId, $groupId = 0, $toUserId = null, $unzip = 0, $whatIfFileExists = '', $output = true, $onlyUploadFile = false, $comment = null, $sessionId = null)
{
    if (!$userId) {
        return false;
    }
    $userInfo = api_get_user_info();
    $uploadedFile['name'] = stripslashes($uploadedFile['name']);
    // Add extension to files without one (if possible)
    $uploadedFile['name'] = add_ext_on_mime($uploadedFile['name'], $uploadedFile['type']);
    if (empty($sessionId)) {
        $sessionId = api_get_session_id();
    } else {
        $sessionId = intval($sessionId);
    }
    // Just in case process_uploaded_file is not called
    $maxSpace = DocumentManager::get_course_quota();
    // Check if there is enough space to save the file
    if (!DocumentManager::enough_space($uploadedFile['size'], $maxSpace)) {
        if ($output) {
            Display::display_error_message(get_lang('UplNotEnoughSpace'));
        }
        return false;
    }
    // If the want to unzip, check if the file has a .zip (or ZIP,Zip,ZiP,...) extension
    if ($unzip == 1 && preg_match('/.zip$/', strtolower($uploadedFile['name']))) {
        return unzip_uploaded_document($courseInfo, $userInfo, $uploadedFile, $uploadPath, $documentDir, $maxSpace, $sessionId, $groupId, $output);
    } elseif ($unzip == 1 && !preg_match('/.zip$/', strtolower($uploadedFile['name']))) {
        // We can only unzip ZIP files (no gz, tar,...)
        if ($output) {
            Display::display_error_message(get_lang('UplNotAZip') . " " . get_lang('PleaseTryAgain'));
        }
        return false;
    } else {
        // Clean up the name, only ASCII characters should stay. (and strict)
        $cleanName = api_replace_dangerous_char($uploadedFile['name'], 'strict');
        // No "dangerous" files
        $cleanName = disable_dangerous_file($cleanName);
        // Checking file extension
        if (!filter_extension($cleanName)) {
            if ($output) {
                Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
            }
            return false;
        } else {
            // If the upload path differs from / (= root) it will need a slash at the end
            if ($uploadPath != '/') {
                $uploadPath = $uploadPath . '/';
            }
            // Full path to where we want to store the file with trailing slash
            $whereToSave = $documentDir . $uploadPath;
            // At least if the directory doesn't exist, tell so
            if (!is_dir($whereToSave)) {
                if (!mkdir($whereToSave, api_get_permissions_for_new_directories())) {
                    if ($output) {
                        Display::display_error_message(get_lang('DestDirectoryDoesntExist') . ' (' . $uploadPath . ')');
                    }
                    return false;
                }
            }
            // Just upload the file "as is"
            if ($onlyUploadFile) {
                $errorResult = moveUploadedFile($uploadedFile, $whereToSave . $cleanName);
                if ($errorResult) {
                    return $whereToSave . $cleanName;
                } else {
                    return $errorResult;
                }
            }
            /*
                Based in the clean name we generate a new filesystem name
                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', $courseInfo, $sessionId, $groupId);
            // Name of the document without the extension (for the title)
            $documentTitle = get_document_title($uploadedFile['name']);
            // Size of the uploaded file (in bytes)
            $fileSize = $uploadedFile['size'];
            // File permissions
            $filePermissions = api_get_permissions_for_new_files();
            // Example: /var/www/chamilo/courses/xxx/document/folder/picture.jpg
            $fullPath = $whereToSave . $fileSystemName;
            // Example: /folder/picture.jpg
            $filePath = $uploadPath . $fileSystemName;
            $docId = DocumentManager::get_document_id($courseInfo, $filePath, $sessionId);
            $documentList = DocumentManager::getDocumentByPathInCourse($courseInfo, $filePath);
            // This means that the path already exists in this course.
            if (!empty($documentList) && $whatIfFileExists != 'overwrite') {
                //$found = false;
                // Checking if we are talking about the same course + session
                /*foreach ($documentList as $document) {
                      if ($document['session_id'] == $sessionId) {
                          $found = true;
                          break;
                      }
                  }*/
                //if ($found == false) {
                $whatIfFileExists = 'rename';
                //}
            }
            // What to do if the target file exists
            switch ($whatIfFileExists) {
                // Overwrite the file if it exists
                case 'overwrite':
                    // Check if the target file exists, so we can give another message
                    $fileExists = file_exists($fullPath);
                    if (moveUploadedFile($uploadedFile, $fullPath)) {
                        chmod($fullPath, $filePermissions);
                        if ($fileExists && $docId) {
                            // UPDATE DATABASE
                            $documentId = DocumentManager::get_document_id($courseInfo, $filePath);
                            if (is_numeric($documentId)) {
                                // Update file size
                                update_existing_document($courseInfo, $documentId, $uploadedFile['size']);
                                // Update document item_property
                                api_item_property_update($courseInfo, TOOL_DOCUMENT, $documentId, 'DocumentUpdated', $userId, $groupId, $toUserId, null, null, $sessionId);
                                // Redo visibility
                                api_set_default_visibility($documentId, TOOL_DOCUMENT, null, $courseInfo);
                            } else {
                                // There might be cases where the file exists on disk but there is no registration of that in the database
                                // In this case, and if we are in overwrite mode, overwrite and create the db record
                                $documentId = add_document($courseInfo, $filePath, 'file', $fileSize, $documentTitle, $comment, 0, true, $groupId, $sessionId);
                                if ($documentId) {
                                    // Put the document in item_property update
                                    api_item_property_update($courseInfo, TOOL_DOCUMENT, $documentId, 'DocumentAdded', $userId, $groupId, $toUserId, null, null, $sessionId);
                                    // 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 with extra info to user
                            if ($output) {
                                Display::display_confirmation_message(get_lang('UplUploadSucceeded') . '<br /> ' . $documentTitle . ' ' . get_lang('UplFileOverwritten'), false);
                            }
                            return $filePath;
                        } else {
                            // Put the document data in the database
                            $documentId = add_document($courseInfo, $filePath, 'file', $fileSize, $documentTitle, $comment, 0, true, $groupId, $sessionId);
                            if ($documentId) {
                                // Put the document in item_property update
                                api_item_property_update($courseInfo, TOOL_DOCUMENT, $documentId, 'DocumentAdded', $userId, $groupId, $toUserId, null, null, $sessionId);
                                // 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
                            if ($output) {
                                Display::display_confirmation_message(get_lang('UplUploadSucceeded') . '<br /> ' . $documentTitle, false);
                            }
                            return $filePath;
                        }
                    } else {
                        if ($output) {
                            Display::display_error_message(get_lang('UplUnableToSaveFile'));
                        }
                        return false;
                    }
                    break;
                    // Rename the file if it exists
                // Rename the file if it exists
                case 'rename':
                    // Always rename.
                    $cleanName = DocumentManager::getUniqueFileName($uploadPath, $cleanName, $courseInfo, $sessionId, $groupId);
                    $fileSystemName = DocumentManager::fixDocumentName($cleanName, 'file', $courseInfo, $sessionId, $groupId);
                    $documentTitle = get_document_title($cleanName);
                    $fullPath = $whereToSave . $fileSystemName;
                    $filePath = $uploadPath . $fileSystemName;
                    if (moveUploadedFile($uploadedFile, $fullPath)) {
                        chmod($fullPath, $filePermissions);
                        // Put the document data in the database
                        $documentId = add_document($courseInfo, $filePath, 'file', $fileSize, $documentTitle, $comment, 0, true, $groupId, $sessionId);
                        if ($documentId) {
                            // Update document item_property
                            api_item_property_update($courseInfo, TOOL_DOCUMENT, $documentId, 'DocumentAdded', $userId, $groupId, $toUserId, null, null, $sessionId);
                            // 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
                        if ($output) {
                            Display::display_confirmation_message(get_lang('UplUploadSucceeded') . '<br />' . get_lang('UplFileSavedAs') . ' ' . $documentTitle, false);
                        }
                        return $filePath;
                    } else {
                        if ($output) {
                            Display::display_error_message(get_lang('UplUnableToSaveFile'));
                        }
                        return false;
                    }
                    break;
                default:
                    // Only save the file if it doesn't exist or warn user if it does exist
                    if (file_exists($fullPath) && $docId) {
                        if ($output) {
                            Display::display_error_message($cleanName . ' ' . get_lang('UplAlreadyExists'));
                        }
                    } else {
                        if (moveUploadedFile($uploadedFile, $fullPath)) {
                            chmod($fullPath, $filePermissions);
                            // Put the document data in the database
                            $documentId = add_document($courseInfo, $filePath, 'file', $fileSize, $documentTitle, $comment, 0, true, $groupId, $sessionId);
                            if ($documentId) {
                                // Update document item_property
                                api_item_property_update($courseInfo, TOOL_DOCUMENT, $documentId, 'DocumentAdded', $userId, $groupId, $toUserId, null, null, $sessionId);
                                // 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
                            if ($output) {
                                Display::display_confirmation_message(get_lang('UplUploadSucceeded') . '<br /> ' . $documentTitle, false);
                            }
                            return $filePath;
                        } else {
                            if ($output) {
                                Display::display_error_message(get_lang('UplUnableToSaveFile'));
                            }
                            return false;
                        }
                    }
                    break;
            }
        }
    }
}
コード例 #6
0
ファイル: chat_chat.php プロジェクト: annickvdp/Chamilo1.9.10
         $basename_chat = 'messages-' . $date_now . '_sid-' . $session_id;
     } else {
         $basename_chat = 'messages-' . $date_now;
     }
 }
 if ($reset && $isMaster) {
     $i = 1;
     while (file_exists($chat_path . $basename_chat . '-' . $i . '.log.html')) {
         $i++;
     }
     @rename($chat_path . $basename_chat . '.log.html', $chat_path . $basename_chat . '-' . $i . '.log.html');
     @fclose(fopen($chat_path . $basename_chat . '.log.html', 'w'));
     $doc_id = add_document($_course, $basepath_chat . '/' . $basename_chat . '-' . $i . '.log.html', 'file', filesize($chat_path . $basename_chat . '-' . $i . '.log.html'), $basename_chat . '-' . $i . '.log.html');
     api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $userId, $group_id, null, null, null, $session_id);
     api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $userId, $group_id, null, null, null, $session_id);
     item_property_update_on_folder($_course, $basepath_chat, $userId);
     $doc_id = DocumentManager::get_document_id($_course, $basepath_chat . '/' . $basename_chat . '.log.html');
     update_existing_document($_course, $doc_id, 0);
 }
 $remove = 0;
 $content = array();
 if (file_exists($chat_path . $basename_chat . '.log.html')) {
     $content = file($chat_path . $basename_chat . '.log.html');
     $nbr_lines = sizeof($content);
     $remove = $nbr_lines - 100;
 }
 if ($remove < 0) {
     $remove = 0;
 }
 array_splice($content, 0, $remove);
 require 'header_frame.inc.php';
コード例 #7
0
ファイル: commands.php プロジェクト: annickvdp/Chamilo1.9.10
function FileUpload($resourceType, $currentFolder, $sCommand)
{
    if (!isset($_FILES)) {
        global $_FILES;
    }
    $sErrorNumber = '0';
    $sFileName = '';
    if (isset($_FILES['NewFile']) && !is_null($_FILES['NewFile']['tmp_name'])) {
        global $Config;
        $oFile = $_FILES['NewFile'];
        // Map the virtual path to the local server path.
        $sServerDir = ServerMapFolder($resourceType, $currentFolder, $sCommand);
        // Get the uploaded file name.
        $sFileName = $oFile['name'];
        $sFileName = SanitizeFileName($sFileName, $oFile['type']);
        $sOriginalFileName = $sFileName;
        // Get the extension.
        $sExtension = substr($sFileName, strrpos($sFileName, '.') + 1);
        $sExtension = strtolower($sExtension);
        if (isset($Config['SecureImageUploads'])) {
            if (($isImageValid = IsImageValid($oFile['tmp_name'], $sExtension)) === false) {
                $sErrorNumber = '202';
            }
        }
        if (isset($Config['HtmlExtensions'])) {
            if (!IsHtmlExtension($sExtension, $Config['HtmlExtensions']) && ($detectHtml = DetectHtml($oFile['tmp_name'])) === true) {
                $sErrorNumber = '202';
            }
        }
        // Check if it is an allowed extension.
        if (!$sErrorNumber && IsAllowedExt($sExtension, $resourceType)) {
            $iCounter = 0;
            while (true) {
                $sFilePath = $sServerDir . $sFileName;
                if (is_file($sFilePath)) {
                    $iCounter++;
                    $sFileName = RemoveExtension($sOriginalFileName) . '(' . $iCounter . ').' . $sExtension;
                    $sErrorNumber = '0';
                    // Change $sErrorNumber '201' to '0' to allow create record files renamed
                } else {
                    move_uploaded_file($oFile['tmp_name'], $sFilePath);
                    if (is_file($sFilePath)) {
                        if (isset($Config['ChmodOnUpload']) && !$Config['ChmodOnUpload']) {
                            break;
                        }
                        $permissions = 0777;
                        if (isset($Config['ChmodOnUpload']) && $Config['ChmodOnUpload']) {
                            $permissions = $Config['ChmodOnUpload'];
                        }
                        //$oldumask = umask(0) ;
                        chmod($sFilePath, $permissions);
                        //umask( $oldumask ) ;
                    }
                    break;
                }
            }
            if (file_exists($sFilePath)) {
                //previous checks failed, try once again
                if (isset($isImageValid) && $isImageValid === -1 && IsImageValid($sFilePath, $sExtension) === false) {
                    @unlink($sFilePath);
                    $sErrorNumber = '202';
                } else {
                    if (isset($detectHtml) && $detectHtml === -1 && DetectHtml($sFilePath) === true) {
                        @unlink($sFilePath);
                        $sErrorNumber = '202';
                    }
                }
            }
        } else {
            $sErrorNumber = '202';
        }
    } else {
        $sErrorNumber = '202';
    }
    if ($sErrorNumber == '0') {
        // While we are in a course: Registering the newly uploaded file in the course's database.
        if (api_is_in_course()) {
            global $_course, $_user;
            $repository_path = api_get_path(REL_COURSE_PATH) . api_get_course_path() . '/document/';
            $to_group_id = 0;
            if (api_is_in_group()) {
                global $group_properties;
                $to_group_id = $group_properties['id'];
            }
            if (file_exists($sFilePath)) {
                $file_path = substr($sFilePath, strpos($sFilePath, $repository_path) + strlen($repository_path) - 1);
                $path = explode('/', $file_path);
                $file_name = $path[count($path) - 1];
                $path[count($path) - 1] = '';
                $folder_path = '/' + implode('/', $path);
                $file_size = @filesize($sFilePath);
                $doc_id = add_document($_course, $file_path, 'file', $file_size, $file_name);
                api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $to_group_id);
                item_property_update_on_folder($_course, $folder_path, $_user['user_id']);
            }
        }
    }
    $sFileUrl = CombinePaths(GetResourceTypePath($resourceType, $sCommand), $currentFolder);
    $sFileUrl = CombinePaths($sFileUrl, $sFileName);
    SendUploadResults($sErrorNumber, $sFileUrl, $sFileName);
    exit;
}
コード例 #8
0
             					api_get_user_id(),
             					null,
             					null,
             					null,
             					null,
             					$sessionId
             				);
             			}
             		}*/
             // "WHAT'S NEW" notification: update table item_property
             $document_id = DocumentManager::get_document_id($_course, $file);
             if ($document_id) {
                 update_existing_document($_course, $document_id, $file_size, $read_only_flag);
                 api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentUpdated', api_get_user_id(), null, null, null, null, $sessionId);
                 // Update parent folders
                 item_property_update_on_folder($_course, $dir, api_get_user_id());
                 header('Location: document.php?id=' . $document_data['parent_id'] . '&' . api_get_cidreq() . ($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''));
                 exit;
             } else {
                 Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning'));
             }
         } else {
             Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning'));
         }
     } else {
         if ($document_id) {
             update_existing_document($_course, $document_id, $file_size, $read_only_flag);
         }
     }
 } else {
     if ($document_id) {
コード例 #9
0
ファイル: chat_message.php プロジェクト: ragebat/chamilo-lms
                $userImage = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
                if (substr($userImage['file'], 0, 7) != 'unknown') {
                    $userPhoto = $userImage['dir'] . 'medium_' . $userImage['file'];
                } else {
                    $userPhoto = $userImage['dir'] . $userImage['file'];
                }
                $filePhoto = '<img class="chat-image" src="' . $userPhoto . '"/>';
                if ($isMaster) {
                    fputs($fp, '<div class="message-teacher"><div class="content-message"><div>' . $message . '</div><div class="message-date">' . $timeNow . '</div></div><div class="icon-message"></div>' . $filePhoto . '</div>' . "\n");
                } else {
                    fputs($fp, '<div class="message-student">' . $filePhoto . '<div class="icon-message"></div><div class="content-message"><div>' . $message . '</div><div class="message-date">' . $timeNow . '</div></div></div>' . "\n");
                }
                fclose($fp);
                $chat_size = filesize($chat_path . $basename_chat . '.log.html');
                update_existing_document($_course, $doc_id, $chat_size);
                item_property_update_on_folder($_course, $basepath_chat, $_user['user_id']);
            }
        }
    }
    ?>
	<form name="formMessage" method="post" action="<?php 
    echo api_get_self() . '?' . api_get_cidreq();
    ?>
" onsubmit="javascript: if(document.formMessage.message.value == '') { alert('<?php 
    echo addslashes(api_htmlentities(get_lang('TypeMessage'), ENT_QUOTES));
    ?>
'); document.formMessage.message.focus(); return false; }" autocomplete="off">
	<input type="hidden" name="sent" value="1">
	<div class="message-form-chat">
	<table border="0" cellpadding="5" cellspacing="0" width="100%">
	<tr>