本文整理汇总了PHP中api_get_permissions_for_new_files函数的典型用法代码示例。如果您正苦于以下问题:PHP api_get_permissions_for_new_files函数的具体用法?PHP api_get_permissions_for_new_files怎么用?PHP api_get_permissions_for_new_files使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_get_permissions_for_new_files函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export_csv
/**
* This function serves exporting data in CSV format.
* @param array $header The header labels.
* @param array $data The data array.
* @param string $file_name The name of the file which contains exported data.
* @return string mixed Returns a message (string) if an error occurred.
*/
function export_csv($header, $data, $file_name = 'export.csv')
{
$archive_path = api_get_path(SYS_ARCHIVE_PATH);
$archive_url = api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=';
if (!($open = fopen($archive_path . $file_name, 'w+'))) {
$message = get_lang('noOpen');
} else {
$info = '';
foreach ($header as $value) {
$info .= $value . ';';
}
$info .= "\r\n";
foreach ($data as $row) {
foreach ($row as $value) {
$info .= $value . ';';
}
$info .= "\r\n";
}
fwrite($open, $info);
fclose($open);
@chmod($file_name, api_get_permissions_for_new_files());
header("Location:" . $archive_url . $file_name);
}
return $message;
}
示例2: wsConvertPpt
/**
* Function to convert from ppt to png
* This function is used from Chamilo Rapid Lesson
*
* @param array $pptData
* @return string
*/
function wsConvertPpt($pptData)
{
$fileData = $pptData['file_data'];
$dataInfo = pathinfo($pptData['file_name']);
$fileName = basename($pptData['file_name'], '.' . $dataInfo['extension']);
$fullFileName = $pptData['file_name'];
$tempArchivePath = api_get_path(SYS_ARCHIVE_PATH);
$tempPath = $tempArchivePath . 'wsConvert/' . $fileName . '/';
$tempPathNewFiles = $tempArchivePath . 'wsConvert/' . $fileName . '-n/';
$perms = api_get_permissions_for_new_directories();
if (!is_dir($tempPath)) {
mkdir($tempPath, $perms, true);
}
if (!is_dir($tempPathNewFiles)) {
mkdir($tempPathNewFiles, $perms, true);
}
if (!is_dir($tempPathNewFiles . $fileName)) {
mkdir($tempPathNewFiles . $fileName, $perms, true);
}
$file = base64_decode($fileData);
file_put_contents($tempPath . $fullFileName, $file);
if (IS_WINDOWS_OS) {
// IS_WINDOWS_OS has been defined in main_api.lib.php
$converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
$classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
$cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $classPath . '" DokeosConverter';
} else {
$converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
$classPath = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
$cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' DokeosConverter';
}
$cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
$cmd .= ' -w 720 -h 540 -d oogie "' . $tempPath . $fullFileName . '" "' . $tempPathNewFiles . $fileName . '.html"';
$perms = api_get_permissions_for_new_files();
chmod($tempPathNewFiles . $fileName, $perms, true);
$files = array();
$return = 0;
$shell = exec($cmd, $files, $return);
if ($return === 0) {
$images = array();
foreach ($files as $file) {
$imageData = explode('||', $file);
$images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles . $fileName . '/' . $imageData[1]));
}
$data = array('files' => $files, 'images' => $images);
deleteDirectory($tempPath);
deleteDirectory($tempPathNewFiles);
return serialize($data);
} else {
deleteDirectory($tempPath);
deleteDirectory($tempPathNewFiles);
return false;
}
}
示例3: str_replace
$content = Security::remove_XSS($values['content'], COURSEMANAGERLOWSECURITY);
if (strpos($content, '/css/frames.css') === false) {
$content = str_replace('</head>', '<style> body{margin:10px;}</style><link rel="stylesheet" href="./css/frames.css" type="text/css" /></head>', $content);
}
if ($fp = @fopen($filepath . $filename . '.' . $extension, 'w')) {
$content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
// change the path of mp3 to absolute
// first regexp deals with ../../../ urls
// Disabled by Ivan Tcholakov.
//$content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
//second regexp deals with audio/ urls
// Disabled by Ivan Tcholakov.
//$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
fputs($fp, $content);
fclose($fp);
chmod($filepath . $filename . '.' . $extension, api_get_permissions_for_new_files());
if (!is_dir($filepath . 'css')) {
mkdir($filepath . 'css', api_get_permissions_for_new_directories());
$doc_id = FileManager::add_document($_course, $dir . 'css', 'folder', 0, 'css');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], 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_CSS_PATH) . 'themes/' . api_get_setting('stylesheets') . '/frames.css', $filepath . 'css/frames.css');
$doc_id = FileManager::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', $_user['user_id'], null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
}
$file_size = filesize($filepath . $filename . '.' . $extension);
$save_file_path = $dir . $filename . '.' . $extension;
示例4: convertCopyDocument
/**
* Used to convert copied from document
* @param string $originalPath
* @param string $convertedPath
* @param string $convertedTitle
* @return bool
*/
function convertCopyDocument($originalPath, $convertedPath, $convertedTitle)
{
$_course = api_get_course_info();
$ids = array();
$originalPathInfo = pathinfo($originalPath);
$convertedPathInfo = pathinfo($convertedPath);
$this->base_work_dir = $originalPathInfo['dirname'];
$this->file_path = $originalPathInfo['basename'];
$this->created_dir = $convertedPathInfo['basename'];
$ppt2lpHost = api_get_setting('ppt_to_lp.host');
$permissionFile = api_get_permissions_for_new_files();
$permissionFolder = api_get_permissions_for_new_directories();
if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
return $ids;
}
if ($ppt2lpHost == 'localhost') {
if (IS_WINDOWS_OS) {
// IS_WINDOWS_OS has been defined in main_api.lib.php
$converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
$classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
$cmd = 'java -Dfile.encoding=UTF-8 -jar "' . $classPath . '/jodconverter-2.2.2.jar"';
} else {
$converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
$classPath = ' -Dfile.encoding=UTF-8 -jar jodconverter-cli-2.2.2.jar';
$cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' ';
}
$cmd .= ' -p ' . api_get_setting('ppt_to_lp.port');
// Call to the function implemented by child.
$cmd .= ' "' . $this->base_work_dir . '/' . $this->file_path . '" "' . $this->base_work_dir . '/' . $this->created_dir . '"';
// To allow openoffice to manipulate docs.
@chmod($this->base_work_dir, $permissionFolder);
@chmod($this->base_work_dir . '/' . $this->file_path, $permissionFile);
$locale = $this->original_locale;
// TODO: Improve it because we're not sure this locale is present everywhere.
putenv('LC_ALL=' . $locale);
$files = array();
$return = 0;
$shell = exec($cmd, $files, $return);
// TODO: Chown is not working, root keep user privileges, should be www-data
@chown($this->base_work_dir . '/' . $this->created_dir, 'www-data');
@chmod($this->base_work_dir . '/' . $this->created_dir, $permissionFile);
if ($return != 0) {
// If the java application returns an error code.
switch ($return) {
// Can't connect to openoffice.
case 1:
$this->error = get_lang('CannotConnectToOpenOffice');
break;
// Conversion failed in openoffice.
// Conversion failed in openoffice.
case 2:
$this->error = get_lang('OogieConversionFailed');
break;
// Conversion can't be launch because command failed.
// Conversion can't be launch because command failed.
case 255:
$this->error = get_lang('OogieUnknownError');
break;
}
DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir);
return false;
}
} else {
/*
* @TODO Create method to use webservice
// get result from webservices
$result = $this->_get_remote_ppt2lp_files($file);
$result = unserialize(base64_decode($result));
// Save remote images to server
chmod($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
if (!empty($result['images'])) {
foreach ($result['images'] as $image => $img_data) {
$image_path = $this->base_work_dir.$this->created_dir;
@file_put_contents($image_path . '/' . $image, base64_decode($img_data));
@chmod($image_path . '/' . $image, 0777);
}
}
// files info
$files = $result['files'];
*/
}
if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
// Register Files to Document tool
$ids[] = add_document($_course, '/' . $this->created_dir, 'file', filesize($this->base_work_dir . '/' . $this->created_dir), $convertedTitle, sprintf(get_lang('FileConvertedFromXToY'), strtoupper($originalPathInfo['extension']), strtoupper($convertedPathInfo['extension'])), 0, true, null, api_get_session_id());
chmod($this->base_work_dir, $permissionFolder);
}
return $ids;
}
示例5: generateDefaultCertificate
/**
* Generate a default certificate for a courses
*
* @global string $css CSS directory
* @global string $img_dir image directory
* @global string $default_course_dir Course directory
* @global string $js JS directory
* @param array $courseData The course info
* @param bool $fromBaseCourse
* @param int $sessionId
*/
public static function generateDefaultCertificate($courseData, $fromBaseCourse = false, $sessionId = 0)
{
global $css, $img_dir, $default_course_dir, $js;
$codePath = api_get_path(REL_CODE_PATH);
$dir = '/certificates';
$title = get_lang('DefaultCertificate');
$comment = null;
$fileName = api_replace_dangerous_char($title);
$filePath = api_get_path(SYS_COURSE_PATH) . "{$courseData['path']}/document{$dir}";
$fileFullPath = "{$filePath}/{$fileName}.html";
$fileSize = 0;
$fileType = 'file';
$templateContent = file_get_contents(api_get_path(SYS_CODE_PATH) . 'gradebook/certificate_template/template.html');
$search = array('{CSS}', '{IMG_DIR}', '{REL_CODE_PATH}', '{COURSE_DIR}');
$replace = array($css . $js, $img_dir, $codePath, $default_course_dir);
$fileContent = str_replace($search, $replace, $templateContent);
$saveFilePath = "{$dir}/{$fileName}.html";
if (!is_dir($filePath)) {
mkdir($filePath, api_get_permissions_for_new_directories());
}
if ($fromBaseCourse) {
$defaultCertificateId = self::get_default_certificate_id($courseData['code'], 0);
if (!empty($defaultCertificateId)) {
// We have a certificate from the course base
$documentData = DocumentManager::get_document_data_by_id($defaultCertificateId, $courseData['code'], false, 0);
if ($documentData) {
$fileContent = file_get_contents($documentData['absolute_path']);
}
}
}
$defaultCertificateFile = $fp = @fopen($fileFullPath, 'w');
if ($defaultCertificateFile != false) {
@fputs($defaultCertificateFile, $fileContent);
fclose($defaultCertificateFile);
chmod($fileFullPath, api_get_permissions_for_new_files());
$fileSize = filesize($fileFullPath);
}
$documentId = add_document($courseData, $saveFilePath, $fileType, $fileSize, $title, $comment, 0, true, null, $sessionId);
api_item_property_update($courseData, TOOL_DOCUMENT, $documentId, 'DocumentAdded', api_get_user_id(), null, null, null, null, $sessionId);
$defaultCertificateId = self::get_default_certificate_id($courseData['code'], $sessionId);
if (!isset($defaultCertificateId)) {
self::attach_gradebook_certificate($courseData['code'], $documentId, $sessionId);
}
}
示例6: display_requirements
//.........这里部分代码省略.........
" />
</p>
<p>
<button type="submit" class="btn btn-default" name="step1" value="<?php
echo get_lang('Back');
?>
" >
<i class="fa fa-backward"> <?php
echo get_lang('Back');
?>
</i>
</button>
<input type="hidden" name="is_executable" id="is_executable" value="-" />
<button type="submit" class="btn btn-success" name="<?php
echo isset($_POST['step2_update_6']) ? 'step2_update_6' : 'step2_update_8';
?>
" value="<?php
echo get_lang('Next');
?>
>" >
<i class="fa fa-forward"> </i> <?php
echo get_lang('Next');
?>
</button>
</p>
</div>
</div>
<?php
} else {
$error = false;
// First, attempt to set writing permissions if we don't have them yet
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
$notWritable = array();
$checked_writable = api_get_path(SYS_APP_PATH);
if (!is_writable($checked_writable)) {
$notWritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
$checked_writable = api_get_path(SYS_PUBLIC_PATH);
if (!is_writable($checked_writable)) {
$notWritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
$checked_writable = api_get_path(SYS_CODE_PATH) . 'default_course_document/images/';
if (!is_writable($checked_writable)) {
$notWritable[] = $checked_writable;
@chmod($checked_writable, $perm);
}
if ($course_test_was_created == false) {
$error = true;
}
$checked_writable = api_get_path(CONFIGURATION_PATH) . 'configuration.php';
if (file_exists($checked_writable) && !is_writable($checked_writable)) {
$notWritable[] = $checked_writable;
@chmod($checked_writable, $perm_file);
}
// Second, if this fails, report an error
//--> The user would have to adjust the permissions manually
if (count($notWritable) > 0) {
$error = true;
echo '<div class="error-message">';
echo '<center><h3>' . get_lang('Warning') . '</h3></center>';
printf(get_lang('NoWritePermissionPleaseReadInstallGuide'), '</font>
<a href="../../documentation/installation_guide.html" target="blank">', '</a> <font color="red">');
示例7: fill_db_course
/**
* Fills the course database with some required content and example content.
* @param int Course (int) ID
* @param string Course directory name (e.g. 'ABC')
* @param string Language used for content (e.g. 'spanish')
* @param bool Whether to fill the course with example content
* @return bool False on error, true otherwise
* @version 1.2
* @assert (null, '', '', null) === false
* @assert (1, 'ABC', null, null) === false
* @assert (1, 'TEST', 'spanish', true) === true
*/
public static function fill_db_course($course_id, $course_repository, $language, $fill_with_exemplary_content = null)
{
if (is_null($fill_with_exemplary_content)) {
$fill_with_exemplary_content = api_get_setting('course.example_material_course_creation') != 'false';
}
$course_id = intval($course_id);
if (empty($course_id)) {
return false;
}
$entityManager = Database::getManager();
$course = $entityManager->getRepository('ChamiloCoreBundle:Course')->find($course_id);
$tools = array();
$settingsManager = CourseManager::getCourseSettingsManager();
$settingsManager->setCourse($course);
$toolList = CourseManager::getToolList();
$toolList = $toolList->getTools();
/** @var Chamilo\CourseBundle\Tool\BaseTool $tool */
foreach ($toolList as $tool) {
$visibility = self::string2binary(api_get_setting_in_list('course.active_tools_on_create', $tool->getName()));
$toolObject = new CTool();
$toolObject->setName($tool->getName())->setCategory($tool->getCategory())->setLink($tool->getLink())->setImage($tool->getImage())->setVisibility($visibility)->setAdmin(0)->setTarget($tool->getTarget());
$tools[] = $toolObject;
$settings = $settingsManager->loadSettings($tool->getName());
$settingsManager->saveSettings($tool->getName(), $settings);
}
$course->setTools($tools);
$entityManager->persist($course);
$entityManager->flush($course);
$courseInfo = api_get_course_info_by_id($course_id);
$now = api_get_utc_datetime(time());
$tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST);
$TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO);
$TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY);
$TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA);
$TABLETOOLANNOUNCEMENTS = Database::get_course_table(TABLE_ANNOUNCEMENT);
$TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
$TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
$TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING);
$TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY);
$TABLEFORUMS = Database::get_course_table(TABLE_FORUM);
$TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD);
$TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST);
$TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$TABLEGRADEBOOKCERT = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$visible_for_all = 1;
$visible_for_course_admin = 0;
$visible_for_platform_admin = 2;
/* Course tools */
$alert = api_get_setting('exercise.email_alert_manager_on_new_quiz');
if ($alert === 'true') {
$defaultEmailExerciseAlert = 1;
} else {
$defaultEmailExerciseAlert = 0;
}
/* course_setting table (courseinfo tool) */
$settings = ['email_alert_manager_on_new_doc' => ['default' => 0, 'category' => 'work'], 'email_alert_on_new_doc_dropbox' => ['default' => 0, 'category' => 'dropbox'], 'allow_user_edit_agenda' => ['default' => 0, 'category' => 'agenda'], 'allow_user_edit_announcement' => ['default' => 0, 'category' => 'announcement'], 'email_alert_manager_on_new_quiz' => ['default' => $defaultEmailExerciseAlert, 'category' => 'quiz'], 'allow_user_image_forum' => ['default' => 1, 'category' => 'forum'], 'course_theme' => ['default' => '', 'category' => 'theme'], 'allow_learning_path_theme' => ['default' => 1, 'category' => 'theme'], 'allow_open_chat_window' => ['default' => 1, 'category' => 'chat'], 'email_alert_to_teacher_on_new_user_in_course' => ['default' => 0, 'category' => 'registration'], 'allow_user_view_user_list' => ['default' => 1, 'category' => 'user'], 'display_info_advance_inside_homecourse' => ['default' => 1, 'category' => 'thematic_advance'], 'email_alert_students_on_new_homework' => ['default' => 0, 'category' => 'work'], 'enable_lp_auto_launch' => ['default' => 0, 'category' => 'learning_path'], 'pdf_export_watermark_text' => ['default' => '', 'category' => 'learning_path'], 'allow_public_certificates' => ['default' => api_get_setting('course.allow_public_certificates') === 'true' ? 1 : '', 'category' => 'certificates'], 'documents_default_visibility' => ['default' => 'visible', 'category' => 'document']];
/*$counter = 1;
foreach ($settings as $variable => $setting) {
Database::query(
"INSERT INTO $TABLESETTING (id, c_id, variable, value, category)
VALUES ($counter, $course_id, '".$variable."', '".$setting['default']."', '".$setting['category']."')"
);
$counter++;
}*/
/* Course homepage tools for platform admin only */
/* Group tool */
Database::query("INSERT INTO {$TABLEGROUPCATEGORIES} (c_id, id, title , description, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)\n VALUES ({$course_id}, '2', '" . self::lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');");
/* Example Material */
$language_interface = !empty($language_interface) ? $language_interface : api_get_setting('language.platform_language');
// Example material should be in the same language as the course is.
$language_interface_original = $language_interface;
$now = api_get_utc_datetime();
$files = [['path' => '/shared_folder', 'title' => get_lang('UserFolders'), 'filetype' => 'folder', 'size' => 0], ['path' => '/chat_files', 'title' => get_lang('ChatFiles'), 'filetype' => 'folder', 'size' => 0]];
$counter = 1;
foreach ($files as $file) {
self::insertDocument($course_id, $counter, $file);
$counter++;
}
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
$chat_path = $sys_course_path . $course_repository . '/document/chat_files';
//.........这里部分代码省略.........
示例8: generateDefaultCertificate
/**
* Generate a default certificate for a courses
*
* @global string $css CSS directory
* @global string $img_dir image directory
* @global string $default_course_dir Course directory
* @global string $js JS directory
* @param array $courseData The course info
*/
public static function generateDefaultCertificate($courseData)
{
global $css, $img_dir, $default_course_dir, $js;
$codePath = api_get_path(REL_CODE_PATH);
$dir = '/certificates';
$title = get_lang('DefaultCertificate');
$comment = null;
$fileName = replace_dangerous_char($title);
$filePath = api_get_path(SYS_COURSE_PATH) . "{$courseData['path']}/document{$dir}";
$fileFullPath = "{$filePath}/{$fileName}.html";
$fileSize = 0;
$fileType = 'file';
$templateContent = file_get_contents(api_get_path(SYS_CODE_PATH) . 'gradebook/certificate_template/template.html');
$search = array('{CSS}', '{IMG_DIR}', '{REL_CODE_PATH}', '{COURSE_DIR}');
$replace = array($css . $js, $img_dir, $codePath, $default_course_dir);
$fileContent = str_replace($search, $replace, $templateContent);
$saveFilePath = "{$dir}/{$fileName}.html";
if (!is_dir($filePath)) {
mkdir($filePath, api_get_permissions_for_new_directories());
}
$defaultCertificateFile = $fp = @fopen($fileFullPath, 'w');
if ($defaultCertificateFile != false) {
@fputs($defaultCertificateFile, $fileContent);
fclose($defaultCertificateFile);
chmod($fileFullPath, api_get_permissions_for_new_files());
$fileSize = filesize($fileFullPath);
}
$documentId = add_document($courseData, $saveFilePath, $fileType, $fileSize, $title, $comment);
$defaultCertificateId = self::get_default_certificate_id($courseData['code']);
if (!isset($defaultCertificateId)) {
self::attach_gradebook_certificate($courseData['code'], $documentId);
}
}
示例9: handle_uploaded_document
//.........这里部分代码省略.........
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)) {
示例10: flush
</div>
</div>
</div>';
// Push the web server to send these strings before we start the real
// installation process
flush();
$f = ob_get_contents();
if (!empty($f)) {
ob_flush();
//#5565
}
if ($installType == 'update') {
remove_memory_and_time_limits();
$manager = connectToDatabase($dbHostForm, $dbUsernameForm, $dbPassForm, $dbNameForm, $dbPortForm);
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
error_log('Starting migration process from ' . $my_old_version . ' (' . time() . ')');
switch ($my_old_version) {
case '1.9.0':
case '1.9.2':
case '1.9.4':
case '1.9.6':
case '1.9.6.1':
case '1.9.8':
case '1.9.8.1':
case '1.9.8.2':
case '1.9.10':
case '1.9.10.2':
// Fix type "enum" before running the migration with Doctrine
Database::query("ALTER TABLE course_category MODIFY COLUMN auth_course_child VARCHAR(40) DEFAULT 'TRUE'");
Database::query("ALTER TABLE course_category MODIFY COLUMN auth_cat_child VARCHAR(40) DEFAULT 'TRUE'");
示例11: fill_db_course
//.........这里部分代码省略.........
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_edit_announcement',0,'announcement')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_manager_on_new_quiz',1,'quiz')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_image_forum',1,'forum')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'course_theme','','theme')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_learning_path_theme','1','theme')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_open_chat_window',1,'chat')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_to_teacher_on_new_user_in_course',0,'registration')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_user_view_user_list',1,'user')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'display_info_advance_inside_homecourse',1,'thematic_advance')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'email_alert_students_on_new_homework',0,'work')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'enable_lp_auto_launch',0,'learning_path')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'pdf_export_watermark_text','','learning_path')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_public_certificates','','certificates')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'allow_fast_exercise_edition', 0 ,'exercise')");
Database::query("INSERT INTO $TABLESETTING (c_id, variable,value,category) VALUES ($course_id, 'enable_exercise_auto_launch', 0 ,'exercise')");*/
/* Course homepage tools for platform admin only */
/* Group tool */
Database::query("INSERT INTO {$TABLEGROUPCATEGORIES} (c_id, id , title , description , max_student , self_reg_allowed , self_unreg_allowed , groups_per_user , display_order )\n VALUES ({$course_id}, '2', '" . Database::escape_string(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');");
/* Example Material */
$language_interface = Container::getTranslator()->getLocale();
// Example material should be in the same language as the course is.
$language_interface_original = $language_interface;
$language_interface = $language;
//Share folder
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/shared_folder','" . get_lang('UserFolders') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)\n VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
//Chat folder
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/chat_files','" . get_lang('ChatFiles') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
$chat_path = $sys_course_path . $course_repository . '/document/chat_files';
if (!is_dir($chat_path)) {
@mkdir($chat_path, api_get_permissions_for_new_directories());
}
/* Documents */
if ($fill_with_exemplary_content) {
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id,path,title,filetype,size) VALUES ({$course_id},'/images','" . get_lang('Images') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/images/gallery','" . get_lang('DefaultCourseImages') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/audio','" . get_lang('Audio') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/flash','" . get_lang('Flash') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/video','" . get_lang('Video') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
Database::query("INSERT INTO {$TABLETOOLDOCUMENT} (c_id, path,title,filetype,size) VALUES ({$course_id},'/certificates','" . get_lang('Certificates') . "','folder','0')");
$example_doc_id = Database::insert_id();
Database::query("INSERT INTO {$TABLEITEMPROPERTY} (c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ({$course_id},'document',1,NOW(),NOW(),{$example_doc_id},'DocumentAdded',1,0,NULL,0)");
// FILL THE COURSE DOCUMENT WITH DEFAULT COURSE PICTURES
$folders_to_copy_from_default_course = array('images', 'audio', 'flash', 'video', 'certificates');
$default_course_path = api_get_path(SYS_DEFAULT_COURSE_DOCUMENT_PATH);
$default_document_array = array();
foreach ($folders_to_copy_from_default_course as $folder) {
$default_course_folder_path = $default_course_path . $folder . '/';
$files = self::browse_folders($default_course_folder_path, array(), $folder);
$sorted_array = self::sort_pictures($files, 'dir');
示例12: handle_uploaded_document
/**
* 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 $_course
* @param array $uploaded_file ($_FILES)
* @param string $base_work_dir
* @param string $upload_path
* @param int $user_id
* @param int $to_group_id, 0 for everybody
* @param int $to_user_id, NULL for everybody
* @param int $unzip 1/0
* @param string $what_if_file_exists overwrite, rename or warn if exists (default)
* @param boolean Optional output parameter. So far only use for unzip_uploaded_document function. If no output wanted on success, set to false.
* @return path of the saved file
*/
static function handle_uploaded_document($_course, $uploaded_file, $base_work_dir, $upload_path, $user_id, $to_group_id = 0, $to_user_id = null, $unzip = 0, $what_if_file_exists = '', $output = true)
{
if (!$user_id) {
die('Not a valid user.');
}
// Strip slashes
$uploaded_file['name'] = stripslashes($uploaded_file['name']);
// Add extension to files without one (if possible)
$uploaded_file['name'] = self::add_ext_on_mime($uploaded_file['name'], $uploaded_file['type']);
$current_session_id = api_get_session_id();
//Just in case process_uploaded_file is not called
$max_filled_space = DocumentManager::get_course_quota();
// Check if there is enough space to save the file
if (!DocumentManager::enough_space($uploaded_file['size'], $max_filled_space)) {
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($uploaded_file['name']))) {
return self::unzip_uploaded_document($uploaded_file, $upload_path, $base_work_dir, $max_filled_space, $output, $to_group_id);
//display_message('Unzipping file');
} elseif ($unzip == 1 && !preg_match('/.zip$/', strtolower($uploaded_file['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)
$clean_name = api_replace_dangerous_char($uploaded_file['name'], 'strict');
// No "dangerous" files
$clean_name = self::disable_dangerous_file($clean_name);
if (!self::filter_extension($clean_name)) {
if ($output) {
Display::display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
}
return false;
} else {
// Extension is good
//echo '<br />clean name = '.$clean_name;
//echo '<br />upload_path = '.$upload_path;
// If the upload path differs from / (= root) it will need a slash at the end
if ($upload_path != '/') {
$upload_path = $upload_path . '/';
}
//echo '<br />upload_path = '.$upload_path;
$file_path = $upload_path . $clean_name;
//echo '<br />file path = '.$file_path;
// Full path to where we want to store the file with trailing slash
$where_to_save = $base_work_dir . $upload_path;
// At least if the directory doesn't exist, tell so
if (!is_dir($where_to_save)) {
if ($output) {
Display::display_error_message(get_lang('DestDirectoryDoesntExist') . ' (' . $upload_path . ')');
}
return false;
}
//echo '<br />where to save = '.$where_to_save;
// Full path of the destination
$store_path = $where_to_save . $clean_name;
//echo '<br />store path = '.$store_path;
// Name of the document without the extension (for the title)
$document_name = self::get_document_title($uploaded_file['name']);
// Size of the uploaded file (in bytes)
$file_size = $uploaded_file['size'];
$files_perm = api_get_permissions_for_new_files();
// What to do if the target file exists
switch ($what_if_file_exists) {
// Overwrite the file if it exists
case 'overwrite':
// Check if the target file exists, so we can give another message
$file_exists = file_exists($store_path);
if (self::moveUploadedFile($uploaded_file, $store_path)) {
chmod($store_path, $files_perm);
if ($file_exists) {
// UPDATE DATABASE
$document_id = DocumentManager::get_document_id($_course, $file_path);
if (is_numeric($document_id)) {
// Update filesize
//.........这里部分代码省略.........