if (empty($workId)) { api_not_allowed(true); } $my_folder_data = get_work_data_by_id($workId); if (empty($my_folder_data)) { api_not_allowed(true); } if ($my_folder_data['active'] != 1) { api_not_allowed(true); } $work_data = get_work_assignment_by_id($workId); $tool_name = get_lang('StudentPublications'); $group_id = api_get_group_id(); $courseInfo = api_get_course_info(); $htmlHeadXtra[] = api_get_jqgrid_js(); $url_dir = api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(); allowOnlySubscribedUser(api_get_user_id(), $workId, $courseInfo['real_id']); if (!empty($group_id)) { $group_properties = GroupManager :: get_group_properties($group_id); $show_work = false; if (api_is_allowed_to_edit(false, true)) { $show_work = true;
$workPerUser = getWorkPerUser($studentId); $table = new HTML_Table(array('class' => 'data_table')); $column = 0; $row = 0; $headers = array(get_lang('Title'), get_lang('HandedOutDate'), get_lang('HandOutDateLimit'), get_lang('Score'), get_lang('Actions')); foreach ($headers as $header) { $table->setHeaderContents($row, $column, $header); $column++; } $row++; $column = 0; foreach ($workPerUser as $work) { $work = $work['work']; $scoreWeight = intval($work->qualification) == 0 ? null : $work->qualification; $workId = $work->id; $workExtraData = get_work_assignment_by_id($workId); foreach ($work->user_results as $userResult) { $table->setCellContents($row, $column, $work->title . ' [' . strip_tags($userResult['title']) . ']'); $table->setCellAttributes($row, $column, array('width' => '300px')); $column++; $table->setCellContents($row, $column, $userResult['sent_date']); $column++; $dateQualification = !empty($workExtraData['expires_on']) && $workExtraData['expires_on'] != '0000-00-00 00:00:00' ? api_get_local_time($workExtraData['expires_on']) : '-'; $table->setCellContents($row, $column, $dateQualification); $column++; $score = '-'; if (!empty($scoreWeight)) { $score = strip_tags($userResult['qualification']) . "/" . $scoreWeight; } $table->setCellContents($row, $column, $score); $column++;
// @todo add an option to allow/block multiple attempts. /* if (!empty($workInfo) && !empty($workInfo['qualification'])) { $count = get_work_count_by_student($user_id, $work_id); if ($count >= 1) { Display::display_header(); if (api_get_course_setting('student_delete_own_publication') == '1') { Display::display_warning_message(get_lang('CantUploadDeleteYourPaperFirst')); } else { Display::display_warning_message(get_lang('YouAlreadySentAPaperYouCantUpload')); } Display::display_footer(); exit; } }*/ $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);
/** * @param int $workId * @param array $courseInfo * @param int $sessionId * @param string $format * @return bool */ function exportAllStudentWorkFromPublication( $workId, $courseInfo, $sessionId, $format = 'pdf' ) { if (empty($courseInfo)) { return false; } $workData = get_work_data_by_id($workId); if (empty($workData)) { return false; } $assignment = get_work_assignment_by_id($workId); $courseCode = $courseInfo['code']; $header = get_lang('Course').': '.$courseInfo['title']; $teachers = CourseManager::get_teacher_list_from_course_code_to_string( $courseCode ); if (!empty($sessionId)) { $sessionInfo = api_get_session_info($sessionId); if (!empty($sessionInfo)) { $header .= ' - ' . $sessionInfo['name']; $header .= '<br />' . $sessionInfo['description']; $teachers = SessionManager::getCoachesByCourseSessionToString( $sessionId, $courseCode ); } } $header .= '<br />'.get_lang('Teachers').': '.$teachers.'<br />'; $header .= '<br />'.get_lang('Date').': '.api_get_local_time().'<br />'; $header .= '<br />'.get_lang('StudentPublication').': '.$workData['title'].'<br />'; $content = null; $expiresOn = null; if (!empty($assignment) && isset($assignment['expires_on'])) { $content .= '<br /><strong>' . get_lang('ExpiryDate') . '</strong>: ' . api_get_local_time($assignment['expires_on']); $expiresOn = api_get_local_time($assignment['expires_on']); } if (!empty($workData['description'])) { $content .= '<br /><strong>' . get_lang('Description') . '</strong>: ' . $workData['description']; } $workList = get_work_user_list(null, null, null, null, $workId); switch ($format) { case 'pdf': if (!empty($workList)) { require_once api_get_path(LIBRARY_PATH).'pdf.lib.php'; $table = new HTML_Table(array('class' => 'data_table')); $headers = array( get_lang('Name'), get_lang('User'), get_lang('HandOutDateLimit'), get_lang('SentDate'), get_lang('Filename'), get_lang('Score'), get_lang('Feedback') ); $column = 0; foreach($headers as $header) { $table->setHeaderContents(0, $column, $header); $column++; } $row = 1; //$pdf->set_custom_header($header); foreach ($workList as $work) { $content .= '<hr />'; // getWorkComments need c_id $work['c_id'] = $courseInfo['real_id']; //$content .= get_lang('Date').': '.api_get_local_time($work['sent_date_from_db']).'<br />'; $score = null; if (!empty($work['qualification_only'])) { $score = $work['qualification_only']; } //$content .= get_lang('Description').': '.$work['description'].'<br />'; $comments = getWorkComments($work); $feedback = null; if (!empty($comments)) { $content .= '<h4>'.get_lang('Feedback').': </h4>'; foreach ($comments as $comment) { $feedback .= get_lang('User').': '.api_get_person_name( $comment['firstname'], $comment['lastname'] ).'<br />'; $feedback .= $comment['comment'].'<br />'; } } $table->setCellContents($row, 0, strip_tags($workData['title'])); $table->setCellContents($row, 1, api_get_person_name(strip_tags($work['firstname']), strip_tags($work['lastname']))); $table->setCellContents($row, 2, $expiresOn); $table->setCellContents($row, 3, api_get_local_time($work['sent_date_from_db'])); $table->setCellContents($row, 4, strip_tags($work['title'])); $table->setCellContents($row, 5, $score); $table->setCellContents($row, 6, $feedback); $row++; } $content = $table->toHtml(); if (!empty($content)) { $params = array( 'filename' => $workData['title'] . '_' . api_get_local_time(), 'pdf_title' => replace_dangerous_char($workData['title']), 'course_code' => $courseInfo['code'], 'add_signatures' => false ); $pdf = new PDF('A4', null, $params); $pdf->html_to_pdf_with_template($content); } exit; } break; } }
require_once $lib_path.'fileManage.lib.php'; require_once 'work.lib.php'; // Section (for the tabs) $this_section = SECTION_COURSES; if (!api_is_allowed_to_edit()) { api_not_allowed(true); } $courseInfo = api_get_course_info(); $sessionId = api_get_session_id(); $groupId = api_get_group_id(); $workId = isset($_GET['id']) ? intval($_GET['id']) : null; $workData = get_work_data_by_id($workId); $homework = get_work_assignment_by_id($workId); $locked = api_resource_is_locked_by_gradebook($workId, LINK_STUDENTPUBLICATION); if (api_is_platform_admin() == false && $locked == true) { api_not_allowed(true); } $htmlHeadXtra[] = to_javascript_work(); $interbreadcrumb[] = array( 'url' => api_get_path(WEB_CODE_PATH) . 'work/work.php?' . api_get_cidreq(), 'name' => get_lang('StudentPublications') ); $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit')); $form = new FormValidator( 'edit_dir',
$has_ended = false; $is_author = false; $work_item = get_work_data_by_id($item_id); // Get the author ID for that document from the item_property table $is_author = user_is_author($item_id); if (!$is_author) { api_not_allowed(true); } // Student's can't edit work only if he can delete his docs. if (!api_is_allowed_to_edit()) { if (api_get_course_setting('student_delete_own_publication') != 1) { api_not_allowed(true); } } if (!empty($my_folder_data)) { $homework = get_work_assignment_by_id($my_folder_data['id']); if (!empty($homework['expires_on']) || !empty($homework['ends_on'])) { $time_now = time(); if (!empty($homework['expires_on']) && !empty($homework['expires_on'])) { $time_expires = api_strtotime($homework['expires_on'], 'UTC'); $difference = $time_expires - $time_now; if ($difference < 0) { $has_expired = true; } } if (empty($homework['expires_on'])) { $has_expired = false; } if (!empty($homework['ends_on'])) { $time_ends = api_strtotime($homework['ends_on'], 'UTC'); $difference2 = $time_ends - $time_now;
/** * @param int $start * @param int $limit * @param int $column * @param string $direction * @param int $work_id * @param array $where_condition * @param int $studentId * @return array */ function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition, $studentId = null) { $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $user_table = Database::get_main_table(TABLE_MAIN_USER); $session_id = api_get_session_id(); $course_id = api_get_course_int_id(); $group_id = api_get_group_id(); $course_info = api_get_course_info(api_get_course_id()); $work_id = intval($work_id); $column = empty($column) ?: Database::escape_string($column); $start = intval($start); $limit = intval($limit); if (!in_array($direction, array('asc', 'desc'))) { $direction = 'desc'; } $work_data = get_work_data_by_id($work_id); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $condition_session = api_get_session_condition($session_id); $locked = api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION); if (!empty($work_data)) { if (!empty($group_id)) { $extra_conditions = " work.post_group_id = '" . intval($group_id) . "' "; // set to select only messages posted by the user's group } else { $extra_conditions = " work.post_group_id = '0' "; } if ($is_allowed_to_edit) { $extra_conditions .= ' AND work.active IN (0, 1) '; } else { if (isset($course_info['show_score']) && $course_info['show_score'] == 1) { $extra_conditions .= " AND (u.user_id = " . api_get_user_id() . " AND work.active IN (0, 1) OR work.active = 1) "; } else { $extra_conditions .= ' AND work.active = 1 '; } } $extra_conditions .= " AND parent_id = " . $work_id . " "; $select = 'DISTINCT u.user_id, work.id as id, title as title, description, url, sent_date, contains_file, has_properties, view_properties, qualification, weight, allow_text_assignment, u.firstname, u.lastname, u.username, parent_id, accepted, qualificator_id'; $user_condition = "INNER JOIN {$user_table} u ON (work.user_id = u.user_id) "; $work_condition = "{$iprop_table} prop INNER JOIN {$work_table} work ON (prop.ref = work.id AND prop.c_id = {$course_id} AND work.c_id = {$course_id} ) "; $work_assignment = get_work_assignment_by_id($work_id); if (!empty($studentId)) { $where_condition .= " AND u.user_id = " . intval($studentId); } $sql = "SELECT {$select}\n FROM {$work_condition} {$user_condition}\n WHERE {$extra_conditions} {$where_condition} {$condition_session} "; $sql .= " ORDER BY {$column} {$direction} "; $sql .= " LIMIT {$start}, {$limit}"; $result = Database::query($sql); $works = array(); while ($work = Database::fetch_array($result, 'ASSOC')) { $item_id = $work['id']; // Get the author ID for that document from the item_property table $is_author = false; $can_read = false; $owner_id = $work['user_id']; /* Because a bug found when saving items using the api_item_property_update() the field $item_property_data['insert_user_id'] is not reliable. */ // $item_property_data = api_get_item_property_info(api_get_course_int_id(), 'work', $item_id, api_get_session_id()); //if (!$is_allowed_to_edit && $item_property_data['insert_user_id'] == api_get_user_id()) { if (!$is_allowed_to_edit && $owner_id == api_get_user_id()) { $is_author = true; } if ($course_info['show_score'] == 0) { $can_read = true; } if ($work['accepted'] == '0') { $class = 'invisible'; } else { $class = ''; } $qualification_exists = false; if (!empty($work_data['qualification']) && intval($work_data['qualification']) > 0) { $qualification_exists = true; } $qualification_string = ''; if ($qualification_exists) { if ($work['qualification'] == '') { $qualification_string = Display::label('-'); } else { $qualification_string = Display::label($work['qualification'], 'info'); } } $add_string = ''; $time_expires = api_strtotime($work_assignment['expires_on'], 'UTC'); if (!empty($work_assignment['expires_on']) && $work_assignment['expires_on'] != '0000-00-00 00:00:00' && $time_expires && $time_expires < api_strtotime($work['sent_date'], 'UTC')) { $add_string = Display::label(get_lang('Expired'), 'important'); } if ($can_read && $work['accepted'] == '1' || $is_author && in_array($work['accepted'], array('1', '0')) || $is_allowed_to_edit) { // Firstname, lastname, username $work['firstname'] = Display::div($work['firstname'], array('class' => $class)); $work['lastname'] = Display::div($work['lastname'], array('class' => $class)); if (strlen($work['title']) > 30) { $short_title = substr($work['title'], 0, 27) . '...'; $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title'])); } else { $work['title'] = Display::div($work['title'], array('class' => $class)); } // Type. $work['type'] = build_document_icon_tag('file', $work['file']); // File name. $link_to_download = null; if ($work['contains_file']) { $link_to_download = '<a href="download.php?id=' . $item_id . '">' . Display::return_icon('save.png', get_lang('Save'), array(), ICON_SIZE_SMALL) . '</a> '; } else { //$link_to_download = '<a href="view.php?id='.$item_id.'">'.Display::return_icon('save_na.png', get_lang('Save'),array(), ICON_SIZE_SMALL).'</a> '; } $send_to = Portfolio::share('work', $work['id'], array('style' => 'white-space:nowrap;')); $work['qualification'] = $qualification_string; // Date. $work_date = api_convert_and_format_date($work['sent_date']); $work['sent_date'] = date_to_str_ago(api_get_local_time($work['sent_date'])) . ' ' . $add_string . '<br />' . $work_date; // Actions. $url = api_get_path(WEB_CODE_PATH) . 'work/'; $action = ''; if ($is_allowed_to_edit) { $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a> '; if ($locked) { if ($qualification_exists) { $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL); } else { $action .= Display::return_icon('edit_na.png', get_lang('Comment'), array(), ICON_SIZE_SMALL); } } else { if ($qualification_exists) { $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Modify') . '" >' . Display::return_icon('rate_work.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL) . '</a>'; } else { $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '&gradebook=' . Security::remove_XSS($_GET['gradebook']) . '" title="' . get_lang('Modify') . '">' . Display::return_icon('edit.png', get_lang('Comment'), array(), ICON_SIZE_SMALL) . '</a>'; } } if ($work['contains_file']) { if ($locked) { $action .= Display::return_icon('move_na.png', get_lang('Move'), array(), ICON_SIZE_SMALL); } else { $action .= '<a href="' . $url . 'work.php?' . api_get_cidreq() . '&action=move&item_id=' . $item_id . '" title="' . get_lang('Move') . '">' . Display::return_icon('move.png', get_lang('Move'), array(), ICON_SIZE_SMALL) . '</a>'; } } if ($work['accepted'] == '1') { $action .= '<a href="' . $url . 'work.php?' . api_get_cidreq() . '&action=make_invisible&item_id=' . $item_id . '&' . $sort_params . '" title="' . get_lang('Invisible') . '" >' . Display::return_icon('visible.png', get_lang('Invisible'), array(), ICON_SIZE_SMALL) . '</a>'; } else { $action .= '<a href="' . $url . 'work.php?' . api_get_cidreq() . '&action=make_visible&item_id=' . $item_id . '&' . $sort_params . '" title="' . get_lang('Visible') . '" >' . Display::return_icon('invisible.png', get_lang('Visible'), array(), ICON_SIZE_SMALL) . '</a> '; } if ($locked) { $action .= Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL); } else { $action .= '<a href="' . $url . 'work.php?' . api_get_cidreq() . '&action=delete&item_id=' . $item_id . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('Delete') . '" >' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>'; } } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) { $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a>'; if (api_get_course_setting('student_delete_own_publication') == 1) { if (api_is_allowed_to_session_edit(false, true)) { $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '&gradebook=' . Security::remove_XSS($_GET['gradebook']) . '" title="' . get_lang('Modify') . '">' . Display::return_icon('edit.png', get_lang('Comment'), array(), ICON_SIZE_SMALL) . '</a>'; } $action .= ' <a href="' . $url . 'work.php?' . api_get_cidreq() . '&action=delete&item_id=' . $item_id . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('Delete') . '" >' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>'; } else { $action .= Display::return_icon('edit_na.png', get_lang('Modify'), array(), ICON_SIZE_SMALL); } } else { $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a>'; $action .= Display::return_icon('edit_na.png', get_lang('Modify'), array(), ICON_SIZE_SMALL); } // Status. if (empty($work['qualificator_id'])) { $qualificator_id = Display::label(get_lang('NotRevised'), 'warning'); } else { $qualificator_id = Display::label(get_lang('Revised'), 'success'); } $work['qualificator_id'] = $qualificator_id; $work['actions'] = $send_to . $link_to_download . $action; $works[] = $work; } } return $works; } }