error_log("upload" . $_FILES['Filedata']); } /*==== PERMISSION ====*/ $permissions = CourseManager::get_user_in_course_status($user_id, $cidReq); if ($permissions != COURSEMANAGER) { if ($debug > 0) { error_log("Upload from videoconf not allowed !!!", 0); } die('Not allowed'); // this user is not allowed to add upload documents } /*==== UPLOAD ====*/ $destPath = $coursePath . VIDEOCONF_UPLOAD_PATH; /*==== creation of /videoconf ====*/ if (!is_dir($destPath)) { $result = FileManager::create_unexisting_directory($_course, $user_id, api_get_session_id(), 0, null, $coursePath, VIDEOCONF_UPLOAD_PATH); if (!$result) { if ($debug > 0) { error_log("Can't create " . $destPath . " folder", 0); } } } /*==== file upload ====*/ $newPath = $_FILES['Filedata']['name']; if ($debug > 0) { error_log($newPath); } /*==== extension extraction ====*/ $file_name = strrpos($newPath, '.') > 0 ? substr($newPath, 0, strrpos($newPath, '.')) : $newPath; $file_extension = strrpos($newPath, '.') > 0 ? substr($newPath, strrpos($newPath, '.'), 10) : ''; if ($debug > 0) {
/** * Create a group * @param string $name The name for this group * @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) { $_course = api_get_course_info(); $table_group = Database::get_course_table(TABLE_GROUP); $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $currentCourseRepository = $_course['path']; $category = self::get_category($category_id); $places = intval($places); 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']; } } $sql = "INSERT INTO " . $table_group . " SET\n c_id = {$course_id} ,\n category_id='" . Database::escape_string($category_id) . "',\n max_student = '" . $places . "',\n doc_state = '" . $category['doc_state'] . "',\n calendar_state = '" . $category['calendar_state'] . "',\n work_state = '" . $category['work_state'] . "',\n announcements_state = '" . $category['announcements_state'] . "',\n forum_state = '" . $category['forum_state'] . "',\n wiki_state = '" . $category['wiki_state'] . "',\n chat_state = '" . $category['chat_state'] . "',\n self_registration_allowed = '" . $category['self_reg_allowed'] . "',\n self_unregistration_allowed = '" . $category['self_unreg_allowed'] . "',\n session_id='" . Database::escape_string($session_id) . "'"; Database::query($sql); $lastId = Database::insert_id(); if ($lastId) { $desired_dir_name = '/' . api_replace_dangerous_char($name, 'strict') . '_groupdocs'; $my_path = api_get_path(SYS_COURSE_PATH) . $currentCourseRepository . '/document'; $unique_name = FileManager::create_unexisting_directory($_course, api_get_user_id(), $session_id, $lastId, NULL, $my_path, $desired_dir_name); /* Stores the directory path into the group table */ $sql = "UPDATE " . $table_group . " SET name = '" . Database::escape_string($name) . "', secret_directory = '" . $unique_name . "'\n WHERE c_id = {$course_id} AND iid ='" . $lastId . "'"; Database::query($sql); // create a forum if needed if ($category['forum_state'] >= 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(); $values = array(); $values['forum_title'] = $name; $values['group_id'] = $lastId; $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['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('default_forum_view'); $values['group_forum'] = $lastId; if ($category['forum_state'] == '1') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'public'; } elseif ($category['forum_state'] == '2') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'private'; } elseif ($category['forum_state'] == '0') { $values['public_private_group_forum_group']['public_private_group_forum'] = 'unavailable'; } store_forum($values); } } return $lastId; }
/** * Restore documents * @param int session id * */ function restore_documents($session_id = 0, $respect_base_content = false, $destination_course_code = '') { $perm = api_get_permissions_for_new_directories(); $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; foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) { $path = api_get_path(SYS_COURSE_PATH) . $this->course->destination_path . '/'; //$dirs = explode('/', dirname($document->path)); 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']; if (!empty($document->title)) { $title = $document->title; } else { $title = basename($document->path); } $new = substr($document->path, 8); if (!is_dir($path . 'document' . $new)) { $created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0, $path . 'document', $new, $title, $visibility); } } 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 . " WHERE c_id = " . $this->destination_course_id . " AND 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 = FileManager::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); } } else { //$created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), $my_session_id, 0, 0 , $path.'document', $new, $title, $visibility, true); } } 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 . " WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'"; $res = Database::query($sql); $count = Database::num_rows($res); if ($count == 0) { $sql = "INSERT INTO {$table} SET\n \t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "',\n \t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n \t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n \t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n \t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n \t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n \t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $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); $sql = "UPDATE " . $table . " SET\n path \t\t= '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "',\n\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'\n WHERE c_id = " . $this->destination_course_id . " AND path = '/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'"; Database::query($sql); 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']); $result = file_put_contents($path . $document->path, $content); } $sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path='/" . substr($document->path, 9) . "'"; $res = Database::query($sql); $obj = Database::fetch_object($res); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; $sql = "UPDATE " . $table . " SET comment = '" . self::DBUTF8escapestring($document->comment) . "', title='" . self::DBUTF8escapestring($document->title) . "', size='" . $document->size . "'\n\t\t\t\t\t\t\t\t\t\tWHERE c_id = " . $this->destination_course_id . " AND id = '" . $obj->id . "'"; Database::query($sql); break; case FILE_SKIP: $sql = "SELECT id FROM " . $table . " WHERE c_id = " . $this->destination_course_id . " AND path='/" . self::DBUTF8escapestring(substr($document->path, 9)) . "'"; $res = Database::query($sql); $obj = Database::fetch_object($res); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; break; case FILE_RENAME: $i = 1; $ext = explode('.', basename($document->path)); if (count($ext) > 1) { $ext = array_pop($ext); $file_name_no_ext = substr($document->path, 0, -(strlen($ext) + 1)); $ext = '.' . $ext; } else { $ext = ''; $file_name_no_ext = $document->path; } $new_file_name = $file_name_no_ext . '_' . $i . $ext; $file_exists = file_exists($path . $new_file_name); while ($file_exists) { $i++; $new_file_name = $file_name_no_ext . '_' . $i . $ext; $file_exists = file_exists($path . $new_file_name); } if (!empty($session_id)) { $document_path = explode('/', $document->path, 3); $course_path = $path; // "/var/www/wiener/courses/" $orig_base_folder = $document_path[1]; $orig_base_path = $course_path . $document_path[0] . '/' . $document_path[1]; if (is_dir($orig_base_path)) { $new_base_foldername = $orig_base_folder; // e.g: "carpeta1" $new_base_path = $orig_base_path; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1" if ($_SESSION['orig_base_foldername'] != $new_base_foldername) { unset($_SESSION['new_base_foldername']); unset($_SESSION['orig_base_foldername']); unset($_SESSION['new_base_path']); } $folder_exists = file_exists($new_base_path); if ($folder_exists) { $_SESSION['orig_base_foldername'] = $new_base_foldername; // e.g: carpeta1 in session $x = ''; while ($folder_exists) { $x = $x + 1; $new_base_foldername = $document_path[1] . '_' . $x; $new_base_path = $orig_base_path . '_' . $x; if ($_SESSION['new_base_foldername'] == $new_base_foldername) { break; } $folder_exists = file_exists($new_base_path); } $_SESSION['new_base_foldername'] = $new_base_foldername; $_SESSION['new_base_path'] = $new_base_path; } if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) { $new_base_foldername = $_SESSION['new_base_foldername']; $new_base_path = $_SESSION['new_base_path']; } $dest_document_path = $new_base_path . '/' . $document_path[2]; // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" $basedir_dest_path = dirname($dest_document_path); // e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1" //$dest_filename = basename($dest_document_path); // e.g: "collaborative.png" $base_path_document = $course_path . $document_path[0]; // e.g: "/var/www/wiener/courses/CURSO4/document" $path_title = '/' . $new_base_foldername . '/' . $document_path[2]; api_copy_folder_course_session($basedir_dest_path, $base_path_document, $session_id, $course_info, $document, $this->course_origin_id); if (file_exists($course_path . $document->path)) { copy($course_path . $document->path, $dest_document_path); } //Replace old course code with the new destination code see BT#1985 if (file_exists($dest_document_path)) { $file_info = pathinfo($dest_document_path); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($dest_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']); $result = file_put_contents($dest_document_path, $content); } } $sql = "INSERT INTO {$table} SET\n\t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '{$path_title}',\n\t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring(basename($path_title)) . "' ,\n\t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $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 { if (file_exists($path . $document->path)) { copy($path . $document->path, $path . $new_file_name); } //Replace old course code with the new destination code see BT#1985 if (file_exists($path . $new_file_name)) { $file_info = pathinfo($path . $new_file_name); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($path . $new_file_name); 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']); $result = file_put_contents($path . $new_file_name, $content); } } $sql = "INSERT INTO " . $table . " SET\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '/" . self::DBUTF8escapestring(substr($new_file_name, 9)) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $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 { copy($this->course->backup_path . '/' . $document->path, $path . $new_file_name); //Replace old course code with the new destination code see BT#1985 if (file_exists($path . $new_file_name)) { $file_info = pathinfo($path . $new_file_name); if (in_array($file_info['extension'], array('html', 'htm'))) { $content = file_get_contents($path . $new_file_name); 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']); $result = file_put_contents($path . $new_file_name, $content); } } $sql = "INSERT INTO " . $table . " SET\n\t\t\t\t\t\t\t\t\t\t\t\tc_id \t\t= " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t\t\t\t\t\tpath \t\t= '/" . self::DBUTF8escapestring(substr($new_file_name, 9)) . "',\n\t\t\t\t\t\t\t\t\t\t\t\tcomment \t= '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t\t\t\t\t\ttitle \t\t= '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t\t\t\t\t\tfiletype\t='" . $document->file_type . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsize\t\t= '" . $document->size . "',\n\t\t\t\t\t\t\t\t\t\t\t\tsession_id \t= '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $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); } break; } // end switch } else { // end if file exists //make sure the source file actually exists if (is_file($this->course->backup_path . '/' . $document->path) && is_readable($this->course->backup_path . '/' . $document->path) && is_dir(dirname($path . $document->path)) && is_writeable(dirname($path . $document->path))) { //echo 'Copying'; copy($this->course->backup_path . '/' . $document->path, $path . $document->path); //Replace old course code with the new destination code see BT#1985 if (file_exists($path . $document->path)) { $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']); $result = file_put_contents($path . $document->path, $content); } } $sql = "INSERT INTO " . $table . " SET\n\t\t\t\t\t\t\t c_id = " . $this->destination_course_id . ",\n\t\t\t\t\t\t\t path = '/" . substr($document->path, 9) . "',\n\t\t\t\t\t\t\t comment = '" . self::DBUTF8escapestring($document->comment) . "',\n\t\t\t\t\t\t\t title = '" . self::DBUTF8escapestring($document->title) . "' ,\n\t\t\t\t\t\t\t filetype='" . $document->file_type . "',\n\t\t\t\t\t\t\t size= '" . $document->size . "',\n\t\t\t\t\t\t\t session_id = '{$my_session_id}'"; Database::query($sql); $document_id = Database::insert_id(); $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 { //echo 'not Copying'; if (is_file($this->course->backup_path . '/' . $document->path) && is_readable($this->course->backup_path . '/' . $document->path)) { error_log('Course copy generated an ignoreable error while trying to copy ' . $this->course->backup_path . '/' . $document->path . ': file not found'); } if (!is_dir(dirname($path . $document->path))) { error_log('Course copy generated an ignoreable error while trying to copy to ' . dirname($path . $document->path) . ': directory not found'); } if (!is_writeable(dirname($path . $document->path))) { error_log('Course copy generated an ignoreable error while trying to copy to ' . dirname($path . $document->path) . ': directory not writeable'); } } } // end file doesn't exist } else { /*$sql = "SELECT id FROM ".$table." WHERE path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'"; $res = Database::query($sql); if( Database::num_rows($res)> 0) { $obj = Database::fetch_object($res); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; } else { $sql = "INSERT INTO ".$table." SET path = '/".self::DBUTF8escapestring(substr($document->path, 9))."', comment = '".self::DBUTF8escapestring($document->comment)."', title = '".self::DBUTF8escapestring($document->title)."' ,filetype='".$document->file_type."', size= '".$document->size."'"; Database::query($sql); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id(); }*/ } // end folder } // end for each // Delete sessions for the copy the new folder in session unset($_SESSION['new_base_foldername']); unset($_SESSION['orig_base_foldername']); unset($_SESSION['new_base_path']); } }
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)) { $folder = FileManager::create_unexisting_directory($course, api_get_user_id(), 0, 0, 0, $filepath, $dir, $lp_name); } 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; }
/** * Create directory certificate * @param string The course id * @return void() */ static function create_directory_certificate_in_course($course_id) { $course_info = api_get_course_info($course_id); if (!empty($course_info)) { $to_group_id = 0; $to_user_id = null; $course_dir = $course_info['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'; if (!is_dir($base_work_dir_test)) { $created_dir = FileManager::create_unexisting_directory($course_info, api_get_user_id(), api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $dir_name, $post_dir_name); $update_id = self::get_document_id_of_directory_certificate(); api_item_property_update($course_info, TOOL_DOCUMENT, $update_id, $visibility_command, api_get_user_id()); } } }
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') { // Needed for directory creation $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 . api_replace_dangerous_char($post_dir_name); $dir_name = FileManager::disable_dangerous_file($dir_name); $dir_check = $base_work_dir . $dir_name; if (!is_dir($dir_check)) { $created_dir = FileManager::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'])) {
//create a directory for the missing files $img_directory = str_replace('.', '_', $_POST['related_file'] . "_files"); $missing_files_dir = FileManager::create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), $to_group_id, $to_user_id, $base_work_dir, $img_directory); //put the uploaded files in the new directory and get the paths $paths_to_replace_in_file = FileManager::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 FileManager::replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir . $_POST['related_file']); //update parent folders FileManager::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 = FileManager::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("<strong>".$created_dir."</strong> was created!"); 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') . '"/>';