/** * Responses to AJAX calls */ //require_once '../global.inc.php'; require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php'; $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $isAllowedToEdit = api_is_allowed_to_edit(); switch ($action) { case 'delete_work': if ($isAllowedToEdit) { if (empty($_REQUEST['id'])) { return false; } $workList = explode(',', $_REQUEST['id']); foreach ($workList as $workId) { deleteDirWork($workId); } } break; case 'upload_correction_file': api_protect_course_script(true); // User access same as upload.php $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $itemId = isset($_GET['item_id']) ? intval($_GET['item_id']) : ''; $result = array(); if (!empty($_FILES) && !empty($itemId)) { $file = $_FILES['file']; $courseInfo = api_get_course_info(); $workInfo = get_work_data_by_id($itemId); $workInfoParent = get_work_data_by_id($workInfo['parent_id']); $resultUpload = uploadWork($workInfoParent, $courseInfo, true, $workInfo);
if ($result) { $message = Display::return_message(get_lang('DirectoryCreated'), 'success'); } else { $message = Display::return_message(get_lang('CannotCreateDir'), 'error'); } Session::write('message', $message); header('Location: ' . $currentUrl); exit; } else { $content = $form->return_form(); } break; case 'delete_dir': if ($is_allowed_to_edit) { $work_to_delete = get_work_data_by_id($_REQUEST['id']); $result = deleteDirWork($_REQUEST['id']); if ($result) { $message = Display::return_message(get_lang('DirDeleted') . ': ' . $work_to_delete['title'], 'success'); Session::write('message', $message); } header('Location: ' . $currentUrl); exit; } break; case 'move': /* Move file form request */ if ($is_allowed_to_edit) { if (!empty($item_id)) { $content = generateMoveForm($item_id, $curdirpath, $course_info, $group_id, $session_id); } }