本文整理汇总了PHP中create_unexisting_directory函数的典型用法代码示例。如果您正苦于以下问题:PHP create_unexisting_directory函数的具体用法?PHP create_unexisting_directory怎么用?PHP create_unexisting_directory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_unexisting_directory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setup
/**
* Setups the folder
*/
public function setup()
{
$userId = api_get_user_id();
$sessionId = api_get_session_id();
$userInfo = $this->connector->user;
$courseInfo = $this->connector->course;
if (!empty($courseInfo)) {
$coursePath = api_get_path(SYS_COURSE_PATH);
$courseDir = $courseInfo['directory'] . '/document';
$baseDir = $coursePath . $courseDir;
// Creates shared folder
if (!file_exists($baseDir . '/shared_folder')) {
$title = get_lang('UserFolders');
$folderName = '/shared_folder';
//$groupId = 0;
$visibility = 0;
create_unexisting_directory($courseInfo, $userId, $sessionId, 0, null, $baseDir, $folderName, $title, $visibility);
}
// Creates user-course folder
if (!file_exists($baseDir . '/shared_folder/sf_user_' . $userId)) {
$title = $userInfo['complete_name'];
$folderName = '/shared_folder/sf_user_' . $userId;
$visibility = 1;
create_unexisting_directory($courseInfo, $userId, $sessionId, 0, null, $baseDir, $folderName, $title, $visibility);
}
}
}
示例2: create_group
/**
* Create a group
* @param string $name The name for this group
* @param int $category_id
* @param int $tutor The user-id of the group's tutor
* @param int $places How many people can subscribe to the new group
*/
public static function create_group($name, $category_id, $tutor, $places)
{
$courseObj = api_get_user_course_entity();
$_course = api_get_course_info();
$session_id = api_get_session_id();
$currentCourseRepository = $_course['path'];
$category = self::get_category($category_id);
$places = intval($places);
if ($category) {
if ($places == 0) {
//if the amount of users per group is not filled in, use the setting from the category
$places = $category['max_student'];
} else {
if ($places > $category['max_student'] && $category['max_student'] != 0) {
$places = $category['max_student'];
}
}
$docState = $category['doc_state'];
$calendarState = $category['calendar_state'];
$workState = $category['work_state'];
$anonuncementState = $category['announcements_state'];
$forumState = $category['forum_state'];
$wikiState = $category['wiki_state'];
$chatState = $category['chat_state'];
$selfRegAllowed = $category['self_reg_allowed'];
$selfUnregAllowed = $category['self_unreg_allowed'];
} else {
$docState = self::TOOL_PRIVATE;
$calendarState = self::TOOL_PRIVATE;
$workState = self::TOOL_PRIVATE;
$anonuncementState = self::TOOL_PRIVATE;
$forumState = self::TOOL_PRIVATE;
$wikiState = self::TOOL_PRIVATE;
$chatState = self::TOOL_PRIVATE;
$selfRegAllowed = 0;
$selfUnregAllowed = 0;
}
$group = new CGroupInfo();
$group->setName($name)->setStatus(1)->setDescription('')->setMaxStudent($places)->setAnnouncementsState($anonuncementState)->setDocState($docState)->setCalendarState($calendarState)->setChatState($chatState)->setForumState($forumState)->setWikiState($wikiState)->setWorkState($workState)->setSelfUnregistrationAllowed($selfUnregAllowed)->setSelfRegistrationAllowed($selfRegAllowed)->setSessionId($session_id)->setCourse($courseObj)->setCategoryId($category_id)->setDescription('');
$em = Database::getManager();
$em->persist($group);
$em->flush();
$lastId = $group->getIid();
if ($lastId) {
$desired_dir_name = '/' . api_replace_dangerous_char($name) . '_groupdocs';
$my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document';
$newFolderData = create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, null, $my_path, $desired_dir_name, null, 1);
$unique_name = $newFolderData['path'];
$group->setId($lastId);
$group->setSecretDirectory($unique_name);
$group->setName($name);
$em->merge($group);
$em->flush();
// create a forum if needed
if ($forumState >= 0) {
require_once api_get_path(SYS_CODE_PATH) . 'forum/forumconfig.inc.php';
require_once api_get_path(SYS_CODE_PATH) . 'forum/forumfunction.inc.php';
$forum_categories = get_forum_categories();
if (empty($forum_categories)) {
$categoryParam = array('forum_category_title' => get_lang('GroupForums'));
store_forumcategory($categoryParam);
$forum_categories = get_forum_categories();
}
$counter = 0;
foreach ($forum_categories as $key => $value) {
if ($counter == 0) {
$forum_category_id = $key;
}
$counter++;
}
// A sanity check.
if (empty($forum_category_id)) {
$forum_category_id = 0;
}
$values = array();
$values['forum_title'] = $name;
$values['group_id'] = $lastId;
$values['forum_category'] = $forum_category_id;
$values['allow_anonymous_group']['allow_anonymous'] = 0;
$values['students_can_edit_group']['students_can_edit'] = 0;
$values['approval_direct_group']['approval_direct'] = 0;
$values['allow_attachments_group']['allow_attachments'] = 1;
$values['allow_new_threads_group']['allow_new_threads'] = 1;
$values['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view');
$values['group_forum'] = $lastId;
if ($forumState == '1') {
$values['public_private_group_forum_group']['public_private_group_forum'] = 'public';
} elseif ($forumState == '2') {
$values['public_private_group_forum_group']['public_private_group_forum'] = 'private';
} elseif ($forumState == '0') {
$values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable';
}
store_forum($values);
//.........这里部分代码省略.........
示例3: api_get_course_info
exit;
}
$courseInfo = api_get_course_info();
$folderName = 'captures';
$documentId = DocumentManager::get_document_id($courseInfo, '/'.$folderName);
$path = null;
if (empty($documentId)) {
$course_dir = $courseInfo['path'] . '/document';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$dir = $sys_course_path . $course_dir;
$createdDir = create_unexisting_directory(
$courseInfo,
api_get_user_id(),
api_get_session_id(),
null,
null,
$dir,
'/'.$folderName,
$folderName
);
if ($createdDir) {
$path = '/'.$folderName;
}
} else {
$data = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code']);
$path = $data['path'];
}
if (empty($path)) {
exit;
}
示例4: api_get_course_id
// Get the document data from the ID
$document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id(), false, $sessionId);
if ($sessionId != 0 && !$document_data) {
// If there is a session defined and asking for the
// document * from the session* didn't work, try it from
// the course (out of a session context)
$document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id(), false, 0);
}
$curdirpath = $document_data['path'];
}
$added_slash = $curdirpath == '/' ? '' : '/';
$dir_name = $curdirpath . $added_slash . api_replace_dangerous_char($post_dir_name);
$dir_name = disable_dangerous_file($dir_name);
$dir_check = $base_work_dir . $dir_name;
$visibility = empty($groupId) ? null : 1;
$newFolderData = create_unexisting_directory($courseInfo, api_get_user_id(), $sessionId, $groupId, $to_user_id, $base_work_dir, $dir_name, $post_dir_name, $visibility);
if (!empty($newFolderData)) {
$message = Display::return_message(get_lang('DirCr') . ' ' . $newFolderData['title'], 'confirmation');
} else {
$message = Display::return_message(get_lang('CannotCreateDir'), 'error');
}
}
Display::addFlash($message);
}
// Show them the form for the directory name
if (isset($_GET['createdir'])) {
$dirForm = DocumentManager::create_dir_form($document_id);
}
}
/* VISIBILITY COMMANDS */
if ($is_allowed_to_edit) {
示例5: get_lang
$form .= '<dt>' . "\n" . '<label for="comment">' . get_lang('Comment') . '</label>' . '</dt>' . "\n" . '<dd>' . '<textarea rows=2 cols=50 id="comment" name="comment">' . claro_htmlspecialchars($oldComment) . '</textarea>' . "\n" . '</dd>' . "\n";
}
$form .= '</dl>' . '</fieldset>' . '<p><span class="required">*</span> ' . get_lang('Denotes required fields') . '</p>' . "\n" . '<input type="submit" value="' . get_lang('Ok') . '" /> ' . claro_html_button(claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?cmd=exChDir&file=' . base64_encode($cwd))), get_lang('Cancel')) . '</form>';
$dialogBox->form($form);
}
}
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
UPLOAD RELATED IMAGE FILES
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
if ('submitImage' == $cmd) {
$uploadImgFileNb = sizeof($_FILES['imgFile']);
if ($uploadImgFileNb > 0) {
// Try to create a directory to store the image files
$_REQUEST['relatedFile'] = secure_file_path($_REQUEST['relatedFile']);
$imgDirectory = $_REQUEST['relatedFile'] . '_files';
$imgDirectory = create_unexisting_directory($baseWorkDir . $imgDirectory);
// set the makeInvisible command param appearing later in the script
$mkInvisibl = str_replace($baseWorkDir, '', $imgDirectory);
// move the uploaded image files into the corresponding image directory
// Try to create a directory to store the image files
$newImgPathList = move_uploaded_file_collection_into_directory($_FILES['imgFile'], $imgDirectory);
if (!empty($newImgPathList)) {
$newImgPathList = array_map('rawurlencode', $newImgPathList);
// rawurlencode() does too much. We don't need to replace '/' by '%2F'
$newImgPathList = str_replace('%2F', '/', $newImgPathList);
replace_img_path_in_html_file($_REQUEST['imgFilePath'], $newImgPathList, $baseWorkDir . $_REQUEST['relatedFile']);
}
}
// end if ($uploadImgFileNb > 0)
}
// end if ($submitImage)
示例6: str_replace
$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'])) {
//create the form that asks for the directory name
$new_folder_text = '<form action="' . api_get_self() . '" method="POST">';
$new_folder_text .= '<input type="hidden" name="curdirpath" value="' . $path . '"/>';
$new_folder_text .= get_lang('NewDir') . ' ';
$new_folder_text .= '<input type="text" name="dirname"/>';
$new_folder_text .= '<input type="submit" name="create_dir" value="' . get_lang('Ok') . '"/>';
$new_folder_text .= '</form>';
示例7: add_all_documents_in_folder_to_database
/**
* This recursive function can be used during the upgrade process form older
* versions of Chamilo
* It crawls the given directory, checks if the file is in the DB and adds
* it if it's not
*
* @param array $courseInfo
* @param array $userInfo
* @param string $base_work_dir
* @param string $folderPath
* @param int $sessionId
* @param int $groupId
* @param bool $output
* @param array $parent
* @param string $uploadPath
*
*/
function add_all_documents_in_folder_to_database($courseInfo, $userInfo, $base_work_dir, $folderPath, $sessionId = 0, $groupId = 0, $output = false, $parent = array())
{
if (empty($userInfo) || empty($courseInfo)) {
return false;
}
$userId = $userInfo['user_id'];
// Open dir
$handle = opendir($folderPath);
$files = array();
if (is_dir($folderPath)) {
// Run trough
while ($file = readdir($handle)) {
if ($file == '.' || $file == '..') {
continue;
}
$parentPath = null;
if (!empty($parent) && isset($parent['path'])) {
$parentPath = $parent['path'];
if ($parentPath == '/') {
$parentPath = null;
}
}
$completePath = $parentPath . '/' . $file;
$sysFolderPath = $folderPath . '/' . $file;
// Is directory?
if (is_dir($sysFolderPath)) {
$newFolderData = create_unexisting_directory($courseInfo, $userId, $sessionId, $groupId, null, $base_work_dir, $completePath, null, null, true);
$files[$file] = $newFolderData;
// Recursive
add_all_documents_in_folder_to_database($courseInfo, $userInfo, $base_work_dir, $sysFolderPath, $sessionId, $groupId, $output, $newFolderData);
} else {
// Rename
$uploadedFile = array('name' => $file, 'tmp_name' => $sysFolderPath, 'size' => filesize($sysFolderPath), 'type' => null, 'from_file' => true, 'move_file' => true);
handle_uploaded_document($courseInfo, $uploadedFile, $base_work_dir, $parentPath, $userId, $groupId, null, 0, 'overwrite', $output, false, null, $sessionId);
}
}
}
}
示例8: get_lang
Always session_id should be zero. Always should be created from a base course, never from a session.*/
if (!file_exists($base_work_dir . '/shared_folder')) {
$usf_dir_title = get_lang('SharedFolder');
$usf_dir_name = '/shared_folder';
$visibility = 0;
create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
// Create dynamic user shared folder
if (!file_exists($base_work_dir . '/shared_folder/sf_user_' . $userId)) {
$usf_dir_title = $userInfo['complete_name'];
$usf_dir_name = '/shared_folder/sf_user_' . $userId;
$visibility = 1;
create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
} else {
// Create shared folder session
if (!file_exists($base_work_dir . '/shared_folder_session_' . $sessionId)) {
$usf_dir_title = get_lang('SharedFolder') . ' (' . $sessionName . ')';
$usf_dir_name = '/shared_folder_session_' . $sessionId;
$visibility = 0;
create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
// Create dynamic user shared folder into a shared folder session.
if (!file_exists($base_work_dir . '/shared_folder_session_' . $sessionId . '/sf_user_' . $userId)) {
$usf_dir_title = $userInfo['complete_name'] . ' (' . $sessionName . ')';
$usf_dir_name = '/shared_folder_session_' . $sessionId . '/sf_user_' . $userId;
$visibility = 1;
create_unexisting_directory($_course, $userId, $sessionId, 0, $to_user_id, $base_work_dir, $usf_dir_name, $usf_dir_title, $visibility);
}
}
}
示例9: generate_lp_folder
/**
* @param array $course
* @param string $lp_name
* @return array
*/
public function generate_lp_folder($course, $lp_name = null)
{
$filepath = '';
$dir = '/learning_path/';
if (empty($lp_name)) {
$lp_name = $this->name;
}
$folder = self::generate_learning_path_folder($course);
// Creating LP folder
if ($folder) {
//Limits title size
$title = api_substr(api_replace_dangerous_char($lp_name), 0, 80);
$dir = $dir . $title;
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
if (!is_dir($filepath . '/' . $dir)) {
$folderData = create_unexisting_directory($course, api_get_user_id(), 0, 0, 0, $filepath, $dir, $lp_name);
if (!empty($folderData)) {
$folder = true;
}
} else {
$folder = true;
}
$dir = $dir . '/';
if ($folder) {
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $dir;
}
}
$array = array('dir' => $dir, 'filepath' => $filepath, 'folder' => $folder);
return $array;
}
示例10: implode
$details = implode("<br />\n", claro_failure::get_last_failure());
$dialogBox->error(Backlog_Reporter::report($summary, $details));
}
}
} elseif (array_key_exists('packageCandidatePath', $_REQUEST)) {
// If the target is a zip file, it must be unpack
// If it's a unziped package, We copye the content
if (is_package_file($_REQUEST['packageCandidatePath'])) {
pushClaroMessage(__LINE__ . 'packageCandidatePath is a package', 'dbg');
$modulePath = unzip_package($_REQUEST['packageCandidatePath']);
pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg');
} elseif (file_exists($_REQUEST['packageCandidatePath'])) {
// COPY THE FILE TO WORK REPOSITORY
pushClaroMessage(__LINE__ . 'packageCandidatePath is a path', 'dbg');
claro_mkdir(get_package_path());
$modulePath = create_unexisting_directory(get_package_path() . basename($_REQUEST['packageCandidatePath']));
claro_mkdir($modulePath);
pushClaroMessage(__LINE__ . 'create target' . $modulePath, 'dbg');
if (claro_copy_file($_REQUEST['packageCandidatePath'], $modulePath . '/')) {
$modulePath .= '/' . basename($_REQUEST['packageCandidatePath']);
$moduleInstallable = true;
} else {
$dialogBox->error(get_lang('Module catching failed. Check your path'));
$moduleInstallable = false;
}
}
}
pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg');
// OK TO TRY TO INSTALL ?
if ($moduleInstallable) {
list($backlog, $module_id) = install_module($modulePath);
示例11: processNewDir
/**
* Create new directories.
* If in safe_mode, nothing happens.
* @return boolean true if created, false otherwise.
*/
function processNewDir()
{
if ($this->config['safe_mode']) {
return false;
}
if (isset($_GET['newDir']) && isset($_GET['dir'])) {
$newDir = rawurldecode($_GET['newDir']);
$dir = rawurldecode($_GET['dir']);
$path = Files::makePath($this->getBaseDir(), $dir);
$fullpath = Files::makePath($path, Files::escape($newDir));
if (is_dir($fullpath)) {
return false;
} else {
//adding to the DB
// now the create_unexisting_directory will create the folder
//$result = Files::createFolder($fullpath);
global $_course;
if (isset($_course) && !empty($_course) && isset($_course['code'])) {
//@todo make this str to functions
$base_dir = substr($path, 0, strpos($path, '/document/') + 9);
//
$new_dir = substr($fullpath, strlen($base_dir), -1);
//
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);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', api_get_user_id(), null, null, null, null, api_get_session_id());
} else {
return Files::createFolder($fullpath);
}
return true;
}
}
}
示例12: generate_lp_folder
/**
* @param array $course
* @param string $lp_name
* @param int $creatorId
*
* @return array
*/
public function generate_lp_folder($course, $lp_name = '', $creatorId = 0)
{
$filepath = '';
$dir = '/learning_path/';
if (empty($lp_name)) {
$lp_name = $this->name;
}
$creatorId = empty($creatorId) ? api_get_user_id() : $creatorId;
$folder = self::generate_learning_path_folder($course, $creatorId);
// Limits title size
$title = api_substr(api_replace_dangerous_char($lp_name), 0, 80);
$dir = $dir . $title;
// Creating LP folder
$documentId = null;
if ($folder) {
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document';
if (!is_dir($filepath . '/' . $dir)) {
$folderData = create_unexisting_directory($course, $creatorId, 0, 0, 0, $filepath, $dir, $lp_name);
if (!empty($folderData)) {
$folder = true;
}
$documentId = $folderData['id'];
} else {
$folder = true;
}
$dir = $dir . '/';
if ($folder) {
$filepath = api_get_path(SYS_COURSE_PATH) . $course['path'] . '/document' . $dir;
}
}
if (empty($documentId)) {
$dir = api_remove_trailing_slash($dir);
$documentId = DocumentManager::get_document_id($course, $dir, 0);
}
$array = array('dir' => $dir, 'filepath' => $filepath, 'folder' => $folder, 'id' => $documentId);
return $array;
}
示例13: api_get_path
// Needed for directory creation
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
$post_dir_name = $_POST['dirname'];
if ($post_dir_name == '../' || $post_dir_name == '.' || $post_dir_name == '..') {
Display::display_error_message(get_lang('CannotCreateDir'));
} else {
if (!empty($_POST['dir_id'])) {
$document_data = DocumentManager::get_document_data_by_id($_POST['dir_id'], api_get_course_id());
$curdirpath = $document_data['path'];
}
$added_slash = $curdirpath == '/' ? '' : '/';
$dir_name = $curdirpath . $added_slash . replace_dangerous_char($post_dir_name);
$dir_name = disable_dangerous_file($dir_name);
$dir_check = $base_work_dir . $dir_name;
if (!is_dir($dir_check)) {
$created_dir = create_unexisting_directory($_course, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name);
if ($created_dir) {
Display::display_confirmation_message('<span title="' . $created_dir . '">' . get_lang('DirCr') . '</span>', false);
// Uncomment if you want to enter the created dir
//$curdirpath = $created_dir;
//$curdirpathurl = urlencode($curdirpath);
} else {
Display::display_error_message(get_lang('CannotCreateDir'));
}
} else {
Display::display_error_message(get_lang('CannotCreateDir'));
}
}
}
// Show them the form for the directory name
if (isset($_GET['createdir'])) {
示例14: create_directory_certificate_in_course
/**
* Create directory certificate
* @param string $courseCode
* @return void()
*/
public static function create_directory_certificate_in_course($courseCode)
{
$courseInfo = api_get_course_info($courseCode);
if (!empty($courseInfo)) {
$to_group_id = 0;
$to_user_id = null;
$course_dir = $courseInfo['path'] . "/document/";
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$base_work_dir = $sys_course_path . $course_dir;
$base_work_dir_test = $base_work_dir . 'certificates';
$dir_name = '/certificates';
$post_dir_name = get_lang('CertificatesFiles');
$visibility_command = 'invisible';
$id = self::get_document_id_of_directory_certificate();
if (empty($id)) {
create_unexisting_directory($courseInfo, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name, null, false);
$id = self::get_document_id_of_directory_certificate();
if (empty($id)) {
$id = add_document($courseInfo, $dir_name, 'folder', 0, $post_dir_name, null, 0, true, $to_group_id);
}
if (!empty($id)) {
api_item_property_update($courseInfo, TOOL_DOCUMENT, $id, $visibility_command, api_get_user_id());
}
}
}
}
示例15: restore_documents
/**
* Restore documents
*
* @param int $session_id
* @param bool $respect_base_content
* @param string $destination_course_code
*/
public function restore_documents($session_id = 0, $respect_base_content = false, $destination_course_code = '')
{
$course_info = api_get_course_info($destination_course_code);
if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
$table = Database::get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources;
$path = api_get_path(SYS_COURSE_PATH) . $this->course->destination_path . '/';
foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
if (empty($document->item_properties[0]['id_session'])) {
$my_session_id = 0;
} else {
$my_session_id = $session_id;
}
if ($document->file_type == FOLDER) {
$visibility = $document->item_properties[0]['visibility'];
$new = substr($document->path, 8);
$folderList = explode('/', $new);
$tempFolder = '';
// Check if the parent path exists.
foreach ($folderList as $folder) {
$folderToCreate = $tempFolder . $folder;
$sysFolderPath = $path . 'document' . $folderToCreate;
$tempFolder .= $folder . '/';
if (empty($folderToCreate)) {
continue;
}
$title = basename($sysFolderPath);
// File doesn't exist in file system.
if (!is_dir($sysFolderPath)) {
// Creating directory
create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0, $path . 'document', $folderToCreate, $title, $visibility);
} else {
// File exist in file system.
$documentData = DocumentManager::get_document_id($course_info, $folderToCreate, $my_session_id);
if (empty($documentData)) {
/* This means the folder exists in the
filesystem but not in the DB, trying to fix it */
add_document($course_info, $folderToCreate, 'folder', 0, $title, null, null, false, null, $my_session_id);
}
}
}
} elseif ($document->file_type == DOCUMENT) {
//Checking if folder exists in the database otherwise we created it
$dir_to_create = dirname($document->path);
if (!empty($dir_to_create) && $dir_to_create != 'document' && $dir_to_create != '/') {
if (is_dir($path . dirname($document->path))) {
$sql = "SELECT id FROM {$table}\n WHERE\n c_id = " . $this->destination_course_id . " AND\n path = '/" . self::DBUTF8escapestring(substr(dirname($document->path), 9)) . "'";
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
//continue;
$visibility = $document->item_properties[0]['visibility'];
$new = '/' . substr(dirname($document->path), 9);
$title = str_replace('/', '', $new);
// This code fixes the possibility for a file without a directory entry to be
$document_id = add_document($course_info, $new, 'folder', 0, $title, null, null, false);
api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'FolderCreated', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
}
}
}
if (file_exists($path . $document->path)) {
switch ($this->file_option) {
case FILE_OVERWRITE:
$origin_path = $this->course->backup_path . '/' . $document->path;
if (file_exists($origin_path)) {
copy($origin_path, $path . $document->path);
$sql = "SELECT id FROM {$table}\n WHERE\n c_id = " . $this->destination_course_id . " AND\n path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'";
$res = Database::query($sql);
$count = Database::num_rows($res);
if ($count == 0) {
$params = ['path' => "/" . self::DBUTF8(substr($document->path, 9)), 'c_id' => $this->destination_course_id, 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
$document_id = Database::insert($table, $params);
if ($document_id) {
$sql = "UPDATE {$table} SET id = iid WHERE iid = {$document_id}";
Database::query($sql);
}
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
} else {
$obj = Database::fetch_object($res);
$document_id = $obj->id;
$params = ['path' => "/" . self::DBUTF8(substr($document->path, 9)), 'c_id' => $this->destination_course_id, 'comment' => self::DBUTF8($document->comment), 'title' => self::DBUTF8($document->title), 'filetype' => self::DBUTF8($document->file_type), 'size' => self::DBUTF8($document->size), 'session_id' => $my_session_id];
Database::update($table, $params, ['c_id = ? AND path = ?' => [$this->destination_course_id, "/" . self::DBUTF8escapestring(substr($document->path, 9))]]);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
api_item_property_update($course_info, TOOL_DOCUMENT, $obj->id, 'default', $document->item_properties[0]['insert_user_id'], $document->item_properties[0]['to_group_id'], $document->item_properties[0]['to_user_id'], null, null, $my_session_id);
}
// Replace old course code with the new destination code
$file_info = pathinfo($path . $document->path);
if (in_array($file_info['extension'], array('html', 'htm'))) {
$content = file_get_contents($path . $document->path);
if (UTF8_CONVERT) {
$content = utf8_encode($content);
}
$content = DocumentManager::replace_urls_inside_content_html_from_copy_course($content, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
//.........这里部分代码省略.........