本文整理汇总了PHP中my_delete函数的典型用法代码示例。如果您正苦于以下问题:PHP my_delete函数的具体用法?PHP my_delete怎么用?PHP my_delete使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了my_delete函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: HotPotGCt
/**
* Garbage collector
*/
function HotPotGCt($folder, $flag, $userID)
{
// Garbage Collector
$filelist = array();
if ($dir = @opendir($folder)) {
while (($file = readdir($dir)) !== false) {
if ($file != ".") {
if ($file != "..") {
$full_name = $folder . "/" . $file;
if (is_dir($full_name)) {
HotPotGCt($folder . "/" . $file, $flag);
} else {
$filelist[] = $file;
}
}
}
}
closedir($dir);
}
while (list($key, $val) = each($filelist)) {
if (stristr($val, $userID . ".t.html")) {
if ($flag == 1) {
my_delete($folder . "/" . $val);
} else {
echo $folder . "/" . $val . "<br />";
}
}
}
}
示例2: api_get_course_info
require_once '../newscorm/learnpath.class.php';
require_once '../newscorm/learnpathItem.class.php';
require_once '../newscorm/scorm.class.php';
require_once '../newscorm/scormItem.class.php';
require_once '../newscorm/aicc.class.php';
require_once '../newscorm/aiccItem.class.php';
}
require_once '../inc/global.inc.php';
$courseInfo = api_get_course_info();
$_user = api_get_user_info();
$this_section = SECTION_COURSES;
require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
$documentPath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . "/document";
$test = $_REQUEST['test'];
$full_file_path = $documentPath . $test;
my_delete($full_file_path . $_user['user_id'] . ".t.html");
$TABLETRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$score = $_REQUEST['score'];
$origin = $_REQUEST['origin'];
$learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
$lpViewId = isset($_REQUEST['lp_view_id']) ? intval($_REQUEST['lp_view_id']) : null;
$course_id = $courseInfo['real_id'];
$_cid = api_get_course_id();
$jscript2run = '';
/**
* Save the score for a HP quiz. Can be used by the learnpath tool as well
* for HotPotatoes quizzes. When coming from the learning path, we
* use the session variables telling us which item of the learning path has to
* be updated (score-wise)
* @param string File is the exercise name (the file name for a HP)
示例3: delete_document
/**
* This deletes a document by changing visibility to 2, renaming it to filename_DELETED_#id
* Files/folders that are inside a deleted folder get visibility 2
*
* @param array|\Entity\Course $_course
* @param string $path, path stored in the database
* @param string $base_work_dir, path to the documents folder
* @return boolean true/false
* @todo now only files/folders in a folder get visibility 2, we should rename them too.
*/
public static function delete_document($_course, $path, $base_work_dir, $sessionId = null)
{
$TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
if (empty($path) || empty($base_work_dir)) {
return false;
}
if (is_array($_course)) {
$course_id = $_course['real_id'];
} else {
if ($_course instanceof Course) {
$course_id = $_course->getId();
$_course = api_get_course_info_by_id($course_id);
}
}
if (empty($course_id)) {
return false;
}
if (empty($sessionId)) {
$sessionId = api_get_session_id();
} else {
$sessionId = intval($sessionId);
}
// First, delete the actual document.
$document_id = self::get_document_id($_course, $path, $sessionId);
if (empty($document_id)) {
return false;
}
$document_exists_in_disk = file_exists($base_work_dir . $path);
$new_path = $path . '_DELETED_' . $document_id;
$file_deleted_from_db = false;
$file_deleted_from_disk = false;
$file_renamed_from_disk = false;
if ($document_id) {
self::delete_document_from_db($document_id, $_course, $sessionId);
// Checking
// $file_exists_in_db = self::get_document_data_by_id($document_id, $_course['code']);
$file_deleted_from_db = true;
}
if ($document_exists_in_disk) {
if (api_get_setting('permanently_remove_deleted_files') == 'true') {
// Deleted files are *really* deleted.
$sql = "SELECT id FROM {$TABLE_DOCUMENT}\n WHERE\n c_id = {$course_id} AND\n session_id = {$sessionId} AND\n (path = '" . $path . "' OR path LIKE BINARY '" . $path . "/%') ";
// Get all id's of documents that are deleted.
$result = Database::query($sql);
if ($result && Database::num_rows($result) != 0) {
// Delete all item_property entries
while ($row = Database::fetch_array($result)) {
// Query to delete from item_property table (hard way)
self::delete_document_from_db($row['id'], $_course, $sessionId, true);
}
}
// Delete documents, do it like this so metadata gets deleted too
my_delete($base_work_dir . $path);
$file_deleted_from_disk = true;
} else {
// Set visibility to 2 and rename file/folder to xxx_DELETED_#id (soft delete)
if (is_file($base_work_dir . $path) || is_dir($base_work_dir . $path)) {
if (rename($base_work_dir . $path, $base_work_dir . $new_path)) {
$sql = "UPDATE {$TABLE_DOCUMENT} SET path='" . $new_path . "'\n WHERE c_id = {$course_id} AND session_id = {$sessionId} AND id = '" . $document_id . "'";
Database::query($sql);
$sql = "SELECT id, path FROM {$TABLE_DOCUMENT}\n WHERE\n c_id = {$course_id} AND\n session_id = {$sessionId} AND\n (path = '" . $path . "' OR path LIKE BINARY '" . $path . "/%') ";
$result = Database::query($sql);
if ($result && Database::num_rows($result) > 0) {
while ($deleted_items = Database::fetch_array($result, 'ASSOC')) {
self::delete_document_from_db($deleted_items['id'], $_course, $sessionId);
// Change path of sub folders and documents in database.
$old_item_path = $deleted_items['path'];
$new_item_path = $new_path . substr($old_item_path, strlen($path));
$sql = "UPDATE {$TABLE_DOCUMENT}\n SET path = '" . $new_item_path . "'\n WHERE c_id = {$course_id} AND session_id = {$sessionId} AND id = " . $deleted_items['id'];
Database::query($sql);
}
}
$file_renamed_from_disk = true;
} else {
// Couldn't rename - file permissions problem?
error_log(__FILE__ . ' ' . __LINE__ . ': Error renaming ' . $base_work_dir . $path . ' to ' . $base_work_dir . $new_path . '. This is probably due to file permissions', 0);
}
}
}
}
// Checking inconsistency
if ($file_deleted_from_db && $file_deleted_from_disk || $file_deleted_from_db && $file_renamed_from_disk) {
return true;
} else {
//Something went wrong
//The file or directory isn't there anymore (on the filesystem)
// This means it has been removed externally. To prevent a
// blocking error from happening, we drop the related items from the
// item_property and the document table.
error_log(__FILE__ . ' ' . __LINE__ . ': System inconsistency detected. The file or directory ' . $base_work_dir . $path . ' seems to have been removed from the filesystem independently from the web platform. To restore consistency, the elements using the same path will be removed from the database', 0);
//.........这里部分代码省略.........
示例4: api_item_property_update
if ($is_allowed_to_edit && $locked == false || ($locked == false and $is_author && api_get_course_setting('student_delete_own_publication') == 1 && $work_data['qualificator_id'] == 0)) {
//we found the current user is the author
$queryString1 = "SELECT url, contains_file FROM " . $work_table . " WHERE c_id = {$course_id} AND id = {$item_id}";
$result1 = Database::query($queryString1);
$row = Database::fetch_array($result1);
if (Database::num_rows($result1) > 0) {
$queryString2 = "UPDATE " . $work_table . " SET active = 2 WHERE c_id = {$course_id} AND id = {$item_id}";
$queryString3 = "DELETE FROM " . $TSTDPUBASG . " WHERE c_id = {$course_id} AND publication_id = {$item_id}";
Database::query($queryString2);
Database::query($queryString3);
api_item_property_update($_course, 'work', $item_id, 'DocumentDeleted', $user_id);
$work = $row['url'];
if ($row['contains_file'] == 1) {
if (!empty($work)) {
if (api_get_setting('permanently_remove_deleted_files') == 'true') {
my_delete($currentCourseRepositorySys . '/' . $work);
Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
$file_deleted = true;
} else {
$extension = pathinfo($work, PATHINFO_EXTENSION);
$new_dir = $work . '_DELETED_' . $item_id . '.' . $extension;
if (file_exists($currentCourseRepositorySys . '/' . $work)) {
rename($currentCourseRepositorySys . '/' . $work, $currentCourseRepositorySys . '/' . $new_dir);
Display::display_confirmation_message(get_lang('TheDocumentHasBeenDeleted'));
$file_deleted = true;
}
}
}
} else {
$file_deleted = true;
}
示例5: unset_document_as_template
/**
* Unset a document as template
*
* @param int $document_id
* @param string $course_code
* @param int $user_id
*/
public static function unset_document_as_template($document_id, $course_code, $user_id)
{
$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
$course_code = Database::escape_string($course_code);
$user_id = intval($user_id);
$document_id = intval($document_id);
$sql = 'SELECT id FROM ' . $table_template . '
WHERE
course_code="' . $course_code . '" AND
user_id="' . $user_id . '" AND
ref_doc="' . $document_id . '"';
$result = Database::query($sql);
$template_id = Database::result($result, 0, 0);
include_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
my_delete(api_get_path(SYS_CODE_PATH) . 'upload/template_thumbnails/' . $template_id . '.jpg');
$sql = 'DELETE FROM ' . $table_template . '
WHERE
course_code="' . $course_code . '" AND
user_id="' . $user_id . '" AND
ref_doc="' . $document_id . '"';
Database::query($sql);
}
示例6: action_bar
if (isset($_GET['create'])) {
$pageName = $langCreate;
$tool_content .= action_bar(array(array('title' => $langBack, 'url' => "{$_SERVER['SCRIPT_NAME']}?course={$course_code}", 'icon' => 'fa-reply', 'level' => 'primary-label')));
} else {
$tool_content .= action_bar(array(array('title' => $langCreate, 'url' => "index.php?course={$course_code}&create=1", 'icon' => 'fa-plus-circle', 'button-class' => 'btn-success', 'level' => 'primary-label')));
}
if (isset($_REQUEST['delete']) or isset($_POST['delete_x'])) {
$id = $_REQUEST['delete'];
$r = Database::get()->querySingle("SELECT title FROM ebook WHERE course_id = ?d AND id = ?d", $course_id, $id);
if ($r) {
$title = $r->title;
Database::get()->query("DELETE FROM ebook_subsection WHERE section_id IN\n (SELECT id FROM ebook_section WHERE ebook_id = ?d)", $id);
Database::get()->query("DELETE FROM ebook_section WHERE ebook_id = ?d", $id);
Database::get()->query("DELETE FROM ebook WHERE id = ?d", $id);
$basedir = $webDir . 'courses/' . $course_code . '/ebook/' . $id;
my_delete($basedir);
Database::get()->query("DELETE FROM document WHERE\n subsystem = " . EBOOK . " AND\n subsystem_id = ?d AND\n course_id = ?d", $id, $course_id);
$tool_content .= "<div class='alert-success'>" . q(sprintf($langEBookDeleted, $title)) . "</div>";
}
} elseif (isset($_GET['create'])) {
$navigation[] = array('url' => "{$_SERVER['SCRIPT_NAME']}?course={$course_code}", 'name' => $langEBook);
$tool_content .= "\n <div class='form-wrapper'>\n <form class='form-horizontal' role='form' method='post' action='create.php?course={$course_code}' enctype='multipart/form-data'> \n <div class='form-group'>\n <label for='ebook_title' class='col-sm-2 control-label'>{$langTitle}: </label>\n <div class='col-sm-10'>\n <input type='text' class='form-control' id='ebook_title' name='title' placeholder='{$langTitle}'> \n </div>\n </div>\n <div class='form-group'>\n <label for='fileUpload' class='col-sm-2 control-label'>{$langZipFile}:</label>\n <div class='col-sm-10'> \n <input type='file' name='file' id='fileUpload'> \n </div>\n </div>\n <div class='row'>\n <div class='col-sm-10 col-sm-offset-2 '>\n <input type='submit' class='btn btn-primary' name='submit' value='{$langSend}' />\n <a href='index.php?course={$course_code}' class='btn btn-default'>{$langCancel}</a> \n </div>\n </div> \n </form>\n </div>";
} elseif (isset($_GET['down'])) {
move_order('ebook', 'id', intval($_GET['down']), 'order', 'down', "course_id = {$course_id}");
} elseif (isset($_GET['up'])) {
move_order('ebook', 'id', intval($_GET['up']), 'order', 'up', "course_id = {$course_id}");
} elseif (isset($_GET['vis'])) {
Database::get()->query("UPDATE ebook SET visible = NOT visible\n WHERE course_id = ?d AND\n id = ?d", $course_id, $_GET['vis']);
}
}
if ($is_editor) {
示例7: delete_groups
/**
* deletes groups and their data.
* @author Christophe Gesche <christophe.gesche@claroline.net>
* @author Hugues Peeters <hugues.peeters@claroline.net>
* @author Bart Mollet
* @param mixed $groupIdList - group(s) to delete. It can be a single id
* (int) or a list of id (array).
* @param string $course_code Default is current course
* @return integer - number of groups deleted.
*/
public static function delete_groups($group_ids, $course_code = null)
{
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
// Database table definitions
$group_table = Database::get_course_table(TABLE_GROUP);
$forum_table = Database::get_course_table(TABLE_FORUM);
$group_ids = is_array($group_ids) ? $group_ids : array($group_ids);
$group_ids = array_map('intval', $group_ids);
if (!api_is_platform_admin() && api_is_course_coach()) {
// A coach can only delete courses from his session
for ($i = 0; $i < count($group_ids); $i++) {
if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) {
array_splice($group_ids, $i, 1);
$i--;
}
}
if (count($group_ids) == 0) {
return 0;
}
}
// Unsubscribe all users
self::unsubscribe_all_users($group_ids);
$sql = "SELECT iid, secret_directory, session_id\n FROM {$group_table}\n WHERE c_id = {$course_id} AND iid IN (" . implode(' , ', $group_ids) . ")";
$db_result = Database::query($sql);
while ($group = Database::fetch_object($db_result)) {
// move group-documents to garbage
$source_directory = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . "/document" . $group->secret_directory;
//File to renamed
$destination_dir = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . "/document" . $group->secret_directory . '_DELETED_' . $group->iid;
if (!empty($group->secret_directory)) {
//Deleting from document tool
DocumentManager::delete_document($course_info, $group->secret_directory, $source_directory);
if (file_exists($source_directory)) {
if (api_get_setting('permanently_remove_deleted_files') == 'true') {
// Delete
my_delete($source_directory);
} else {
// Rename
rename($source_directory, $destination_dir);
}
}
}
}
// delete the groups
$sql = "DELETE FROM " . $group_table . " WHERE c_id = {$course_id} AND iid IN ('" . implode("' , '", $group_ids) . "')";
Database::query($sql);
$sql = "DELETE FROM " . $forum_table . " WHERE c_id = {$course_id} AND forum_of_group IN ('" . implode("' , '", $group_ids) . "')";
Database::query($sql);
return Database::affected_rows($result);
}
示例8: purgeDocument
/**
* @param int $id
* @param array $courseInfo
* @param int $sessionId
* @return bool
*/
public static function purgeDocument($id, $courseInfo, $sessionId = 0)
{
$document = self::getDeletedDocument($id, $courseInfo, $sessionId);
if (!empty($document)) {
$path = $document['path'];
$coursePath = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document/';
my_delete($coursePath . $path);
// Hard delete.
self::deleteDocumentFromDb($id, $courseInfo, $sessionId, true);
return true;
}
return false;
}
示例9: import_exercise
//.........这里部分代码省略.........
$element_pile = array();
// create parser and array to retrieve info from manifest
$element_pile = array();
//pile to known the depth in which we are
//$module_info = array (); //array to store the info we need
// if file is not a .zip, then we cancel all
if (!preg_match('/.zip$/i', $file)) {
return 'UplZipCorrupt';
}
// unzip the uploaded file in a tmp directory
if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) {
return 'UplZipCorrupt';
}
// find the different manifests for each question and parse them.
$exerciseHandle = opendir($baseWorkDir);
//$question_number = 0;
$file_found = false;
$operation = false;
$result = false;
$filePath = null;
// parse every subdirectory to search xml question files
while (false !== ($file = readdir($exerciseHandle))) {
if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") {
// Find each manifest for each question repository found
$questionHandle = opendir($baseWorkDir . '/' . $file);
while (false !== ($questionFile = readdir($questionHandle))) {
if (preg_match('/.xml$/i', $questionFile)) {
$result = parse_file($baseWorkDir, $file, $questionFile);
$filePath = $baseWorkDir . $file;
$file_found = true;
}
}
} elseif (preg_match('/.xml$/i', $file)) {
// Else ignore file
$result = parse_file($baseWorkDir, '', $file);
$filePath = $baseWorkDir . '/' . $file;
$file_found = true;
}
}
if (!$file_found) {
return 'NoXMLFileFoundInTheZip';
}
if ($result == false) {
return false;
}
$doc = new DOMDocument();
$doc->load($filePath);
$encoding = $doc->encoding;
// 1. Create exercise.
$exercise = new Exercise();
$exercise->exercise = $exercise_info['name'];
$exercise->save();
$last_exercise_id = $exercise->selectId();
if (!empty($last_exercise_id)) {
// For each question found...
foreach ($exercise_info['question'] as $question_array) {
//2. Create question
$question = new Ims2Question();
$question->type = $question_array['type'];
$question->setAnswer();
$question->updateTitle(formatText($question_array['title']));
//$question->updateDescription($question_array['title']);
$type = $question->selectType();
$question->type = constant($type);
$question->save($last_exercise_id);
$last_question_id = $question->selectId();
//3. Create answer
$answer = new Answer($last_question_id);
$answer->new_nbrAnswers = count($question_array['answer']);
$totalCorrectWeight = 0;
foreach ($question_array['answer'] as $key => $answers) {
$split = explode('_', $key);
$i = $split[1];
// Answer
$answer->new_answer[$i] = formatText($answers['value']);
// Comment
$answer->new_comment[$i] = isset($answers['feedback']) ? formatText($answers['feedback']) : null;
// Position
$answer->new_position[$i] = $i;
// Correct answers
if (in_array($key, $question_array['correct_answers'])) {
$answer->new_correct[$i] = 1;
} else {
$answer->new_correct[$i] = 0;
}
$answer->new_weighting[$i] = $question_array['weighting'][$key];
if ($answer->new_correct[$i]) {
$totalCorrectWeight = $answer->new_weighting[$i];
}
}
$question->updateWeighting($totalCorrectWeight);
$question->save($last_exercise_id);
$answer->save();
}
// delete the temp dir where the exercise was unzipped
my_delete($baseWorkDir . $uploadPath);
return $last_exercise_id;
}
return false;
}
示例10: update_db_info
update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
}
if (!is_dir($documentPath . $uploadPath . "/" . $fld . "/")) {
my_delete($documentPath . $file);
update_db_info("delete", $file);
} else {
if (my_delete($documentPath . $file)) {
update_db_info("delete", $file);
}
}
/* hotpotatoes folder may contains several tests so
don't delete folder if not empty :
http://support.chamilo.org/issues/2165
*/
if (!(strstr($uploadPath, DIR_HOTPOTATOES) && !folder_is_empty($documentPath . $uploadPath . "/" . $fld . "/"))) {
my_delete($documentPath . $uploadPath . "/" . $fld . "/");
}
break;
case 'enable':
// enables an exercise
$newVisibilityStatus = "1";
//"visible"
$query = "SELECT id FROM {$TBL_DOCUMENT}\n WHERE c_id = {$courseId} AND path='" . Database::escape_string($file) . "'";
$res = Database::query($query);
$row = Database::fetch_array($res, 'ASSOC');
api_item_property_update($courseInfo, TOOL_DOCUMENT, $row['id'], 'visible', $userId);
//$dialogBox = get_lang('ViMod');
break;
case 'disable':
// disables an exercise
$newVisibilityStatus = "0";
示例11: add_document
$doc_id = add_document($_course, '/HotPotatoes_files/' . $fld, 'folder', 0, $fld);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id());
} else {
// It is not the first step... get the filename directly from the system params.
$filename = $_FILES['userFile']['name'];
}
$allow_output_on_success = false;
if (handle_uploaded_document($_course, $_FILES['userFile'], $document_sys_path, $uploadPath . '/' . $fld, api_get_user_id(), null, null, $unzip, '', $allow_output_on_success)) {
if ($finish == 2) {
$imgparams = $_POST['imgparams'];
$checked = CheckImageName($imgparams, $filename);
if ($checked) {
$imgcount = $imgcount - 1;
} else {
$dialogBox .= $filename . ' ' . get_lang('NameNotEqual');
my_delete($document_sys_path . $uploadPath . '/' . $fld . '/' . $filename);
update_db_info('delete', $uploadPath . '/' . $fld . '/' . $filename);
}
if ($imgcount == 0) {
// all image uploaded
$finish = 1;
}
} else {
// If we are (still) on the first step of the upload process.
if ($finish == 0) {
$finish = 2;
// Get number and name of images from the files contents.
GetImgParams('/' . $filename, $document_sys_path . $uploadPath . '/' . $fld, $imgparams, $imgcount);
if ($imgcount == 0) {
// There is no img link, so finish the upload process.
$finish = 1;
示例12: aiken_import_exercise
//.........这里部分代码省略.........
$baseWorkDir = $archive_path;
if (!is_dir($baseWorkDir)) {
mkdir($baseWorkDir, api_get_permissions_for_new_directories(), true);
}
$uploadPath = '/';
// set some default values for the new exercise
$exercise_info = array();
$exercise_info['name'] = preg_replace('/.(zip|txt)$/i', '', $file);
$exercise_info['question'] = array();
$element_pile = array();
// create parser and array to retrieve info from manifest
$element_pile = array();
//pile to known the depth in which we are
// if file is not a .zip, then we cancel all
if (!preg_match('/.(zip|txt)$/i', $file)) {
//Display :: display_error_message(get_lang('YouMustUploadAZipOrTxtFile'));
return 'YouMustUploadAZipOrTxtFile';
}
// unzip the uploaded file in a tmp directory
if (preg_match('/.(zip|txt)$/i', $file)) {
if (!get_and_unzip_uploaded_exercise($baseWorkDir, $uploadPath)) {
return 'ThereWasAProblemWithYourFile';
}
}
// find the different manifests for each question and parse them
$exerciseHandle = opendir($baseWorkDir);
$file_found = false;
$operation = false;
$result = false;
// Parse every subdirectory to search txt question files
while (false !== ($file = readdir($exerciseHandle))) {
if (is_dir($baseWorkDir . '/' . $file) && $file != "." && $file != "..") {
//find each manifest for each question repository found
$questionHandle = opendir($baseWorkDir . '/' . $file);
while (false !== ($questionFile = readdir($questionHandle))) {
if (preg_match('/.txt$/i', $questionFile)) {
$result = aiken_parse_file($exercise_info, $baseWorkDir, $file, $questionFile);
$file_found = true;
}
}
} elseif (preg_match('/.txt$/i', $file)) {
$result = aiken_parse_file($exercise_info, $baseWorkDir, '', $file);
$file_found = true;
}
// else ignore file
}
if (!$file_found) {
$result = 'NoTxtFileFoundInTheZip';
}
if ($result !== true) {
return $result;
}
// Add exercise in tool
// 1.create exercise
$exercise = new Exercise();
$exercise->exercise = $exercise_info['name'];
$exercise->save();
$last_exercise_id = $exercise->selectId();
if (!empty($last_exercise_id)) {
// For each question found...
foreach ($exercise_info['question'] as $key => $question_array) {
//2.create question
$question = new Aiken2Question();
$question->type = $question_array['type'];
$question->setAnswer();
$question->updateTitle($question_array['title']);
$question->updateDescription($question_array['description']);
$type = $question->selectType();
$question->type = constant($type);
$question->save($last_exercise_id);
$last_question_id = $question->selectId();
//3.create answer
$answer = new Answer($last_question_id);
$answer->new_nbrAnswers = count($question_array['answer']);
$max_score = 0;
foreach ($question_array['answer'] as $key => $answers) {
$key++;
$answer->new_answer[$key] = $answers['value'];
$answer->new_position[$key] = $key;
// Correct answers ...
if (in_array($key, $question_array['correct_answers'])) {
$answer->new_correct[$key] = 1;
$answer->new_comment[$key] = $question_array['feedback'];
} else {
$answer->new_correct[$key] = 0;
}
$answer->new_weighting[$key] = $question_array['weighting'][$key - 1];
$max_score += $question_array['weighting'][$key - 1];
}
$answer->save();
// Now that we know the question score, set it!
$question->updateWeighting($max_score);
$question->save();
}
// delete the temp dir where the exercise was unzipped
my_delete($baseWorkDir . $uploadPath);
$operation = $last_exercise_id;
}
return $operation;
}
示例13: HotPotGCt
/**
* Hotpotato Garbage Collector
* @param string Path
* @param integer Flag
* @param integer User id
* @return void No return value, but echoes results
*/
function HotPotGCt($folder, $flag, $user_id)
{
// Garbage Collector
$filelist = array();
if ($dir = @opendir($folder)) {
while (($file = readdir($dir)) !== false) {
if ($file != '.') {
if ($file != '..') {
$full_name = $folder . '/' . $file;
if (is_dir($full_name)) {
HotPotGCt($folder . '/' . $file, $flag, $user_id);
} else {
$filelist[] = $file;
}
}
}
}
closedir($dir);
}
while (list($key, $val) = each($filelist)) {
if (stristr($val, $user_id . '.t.html')) {
if ($flag == 1) {
my_delete($folder . '/' . $val);
} else {
echo $folder . '/' . $val . '<br />';
}
}
}
}
示例14: del_dir
/**
* Delete a work-tool directory
* @param string Base "work" directory for this course as /var/www/chamilo/courses/ABCD/work/
* @param string The directory name as the bit after "work/", without trailing slash
* @return integer -1 on error
*/
function del_dir($id)
{
global $_course;
$id = intval($id);
$work_data = get_work_data_by_id($id);
if (empty($work_data)) {
return false;
}
$base_work_dir = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/work';
$work_data_url = $base_work_dir . $work_data['url'];
$check = Security::check_abs_path($work_data_url . '/', $base_work_dir . '/');
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$course_id = api_get_course_int_id();
if (!empty($work_data['url'])) {
//Deleting all contents inside the folder
//@todo replace to parent_id
$sql = "UPDATE {$table} SET active = 2 WHERE c_id = {$course_id} AND filetype = 'folder' AND id = {$id}";
$res = Database::query($sql);
$sql = "UPDATE {$table} SET active = 2 WHERE c_id = {$course_id} AND parent_id = {$id}";
$res = Database::query($sql);
if ($check) {
require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
$new_dir = $work_data_url . '_DELETED_' . $id;
if (api_get_setting('permanently_remove_deleted_files') == 'true') {
my_delete($work_data_url);
} else {
if (file_exists($work_data_url)) {
rename($work_data_url, $new_dir);
}
}
}
}
}
示例15: export_zip
/**
* Exports the current SCORM object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath()
* @param integer Learnpath ID (optional, taken from object context if not defined)
*/
public function export_zip($lp_id = null)
{
if ($this->debug > 0) {
error_log('In scorm::export_zip method(' . $lp_id . ')', 0);
}
if (empty($lp_id)) {
if (!is_object($this)) {
return false;
} else {
$id = $this->get_id();
if (empty($id)) {
return false;
} else {
$lp_id = $this->get_id();
}
}
}
//error_log('New LP - in export_zip()',0);
//zip everything that is in the corresponding scorm dir
//write the zip file somewhere (might be too big to return)
require_once 'learnpath_functions.inc.php';
$courseId = api_get_course_int_id();
$_course = api_get_course_info();
$tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql = "SELECT * FROM {$tbl_lp} WHERE c_id = " . $courseId . " AND id=" . $lp_id;
$result = Database::query($sql);
$row = Database::fetch_array($result);
$LPname = $row['path'];
$list = explode('/', $LPname);
$LPnamesafe = $list[0];
$zipfoldername = api_get_path(SYS_COURSE_PATH) . $_course['directory'] . '/temp/' . $LPnamesafe;
$scormfoldername = api_get_path(SYS_COURSE_PATH) . $_course['directory'] . '/scorm/' . $LPnamesafe;
$zipfilename = $zipfoldername . '/' . $LPnamesafe . '.zip';
// Get a temporary dir for creating the zip file.
//error_log('New LP - cleaning dir '.$zipfoldername, 0);
deldir($zipfoldername);
// Make sure the temp dir is cleared.
$res = mkdir($zipfoldername, api_get_permissions_for_new_directories());
//error_log('New LP - made dir '.$zipfoldername, 0);
// Create zipfile of given directory.
$zip_folder = new PclZip($zipfilename);
$zip_folder->create($scormfoldername . '/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername . '/');
//This file sending implies removing the default mime-type from php.ini
//DocumentManager :: file_send_for_download($zipfilename, true, $LPnamesafe.'.zip');
DocumentManager::file_send_for_download($zipfilename, true);
// Delete the temporary zip file and directory in fileManage.lib.php
my_delete($zipfilename);
my_delete($zipfoldername);
return true;
}