$homework = get_work_assignment_by_id($workInfo['id']); $validationStatus = getWorkDateValidationStatus($homework); $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'work/work.php?' . api_get_cidreq(), 'name' => get_lang('StudentPublications')); $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'work/work_list.php?' . api_get_cidreq() . '&id=' . $work_id, 'name' => $workInfo['title']); $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('UploadADocument')); $form = new FormValidator('form', 'POST', api_get_self() . "?" . api_get_cidreq() . "&id=" . $work_id, '', array('enctype' => "multipart/form-data")); setWorkUploadForm($form, $workInfo['allow_text_assignment']); $form->addElement('hidden', 'id', $work_id); $form->addElement('hidden', 'sec_token', $token); $error_message = null; $succeed = false; if ($form->validate()) { if ($student_can_edit_in_session && $check) { $values = $form->getSubmitValues(); // Process work $error_message = processWorkForm($workInfo, $values, $course_info, $session_id, $group_id, $user_id); $script = 'work_list.php'; if ($is_allowed_to_edit) { $script = 'work_list_all.php'; } if (!empty($error_message)) { Session::write('error_message', $error_message); } header('Location: ' . api_get_path(WEB_CODE_PATH) . 'work/' . $script . '?' . api_get_cidreq() . '&id=' . $work_id); exit; } else { // Bad token or can't add works $error_message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error'); } } $htmlHeadXtra[] = to_javascript_work();
if (!empty($_FILES)) { $files = $_FILES['files']; $fileList = []; foreach ($files as $name => $array) { $counter = 0; foreach ($array as $data) { $fileList[$counter][$name] = $data; $counter++; } } $resultList = []; foreach ($fileList as $file) { $globalFile = []; $globalFile['files'] = $file; $values = ['contains_file' => 1, 'title' => $file['name'], 'description' => '']; $result = processWorkForm($workInfo, $values, $courseInfo, $sessionId, 0, $userId, $file); $json = array(); if (!empty($result) && is_array($result) && empty($result['error'])) { $json['name'] = Display::url(api_htmlentities($result['title']), api_htmlentities($result['view_url']), array('target' => '_blank')); $json['url'] = $result['view_url']; $json['size'] = ''; $json['type'] = api_htmlentities($result['filetype']); $json['result'] = Display::return_icon('accept.png', get_lang('Uploaded')); } else { $json['url'] = ''; $json['error'] = get_lang('Error'); } $resultList[] = $json; } echo json_encode(['files' => $resultList]); }