From a004e1c9e2cd218bdff3be390dccd831b0b3f645 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 15 Feb 2017 08:19:37 +0100 Subject: [PATCH] Student publication UI improvements see BT#12100 --- main/inc/ajax/work.ajax.php | 2 +- main/template/default/work/view.tpl | 2 + main/work/edit.php | 19 +++--- main/work/edit_work.php | 2 +- main/work/student_work.php | 2 +- main/work/view.php | 91 ++++++++++++++++++++++++++++- main/work/work.lib.php | 36 +++++++----- main/work/work_list_all.php | 1 - 8 files changed, 126 insertions(+), 29 deletions(-) diff --git a/main/inc/ajax/work.ajax.php b/main/inc/ajax/work.ajax.php index 847eb8519a..15d4be3d1e 100755 --- a/main/inc/ajax/work.ajax.php +++ b/main/inc/ajax/work.ajax.php @@ -138,8 +138,8 @@ switch ($action) { $json['type'] = api_htmlentities($file['type']); $json['size'] = format_file_size($file['size']); - } + if (isset($result['url'])) { $json['result'] = Display::return_icon( 'accept.png', diff --git a/main/template/default/work/view.tpl b/main/template/default/work/view.tpl index cbfc4ce41a..906477fc7a 100755 --- a/main/template/default/work/view.tpl +++ b/main/template/default/work/view.tpl @@ -13,6 +13,8 @@

{% endif %} +{{ score_form }} + {% if work.contains_file and work.show_content %}

{{ 'Content' | get_lang }} diff --git a/main/work/edit.php b/main/work/edit.php index c827ae56b5..8d523fc63a 100755 --- a/main/work/edit.php +++ b/main/work/edit.php @@ -177,7 +177,7 @@ $defaults['qualification'] = $work_item['qualification']; if ($is_allowed_to_edit && !empty($item_id)) { // Get qualification from parent_id that will allow the validation qualification over - $sql = "SELECT qualification FROM $work_table + /*$sql = "SELECT qualification FROM $work_table WHERE c_id = $course_id AND id ='$work_id' "; $result = Database::query($sql); $row = Database::fetch_array($result); @@ -185,7 +185,7 @@ if ($is_allowed_to_edit && !empty($item_id)) { if (!empty($qualification_over) && intval($qualification_over) > 0) { $form->addText('qualification', array(get_lang('Qualification'), " / ".$qualification_over), false, 'size="10"'); $form->addElement('hidden', 'qualification_over', $qualification_over); - } + }*/ $form->addCheckBox( 'send_email', @@ -239,9 +239,9 @@ if ($form->validate()) { $add_to_update = null; if ($is_allowed_to_edit && ($_POST['qualification'] !='' )) { - $add_to_update = ', qualificator_id ='."'".api_get_user_id()."', "; + /*$add_to_update = ', qualificator_id ='."'".api_get_user_id()."', "; $add_to_update .= ' qualification = '."'".api_float_val($_POST['qualification'])."',"; - $add_to_update .= ' date_of_qualification = '."'".api_get_utc_datetime()."'"; + $add_to_update .= ' date_of_qualification = '."'".api_get_utc_datetime()."'";*/ if (isset($_POST['send_email'])) { $url = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$item_to_edit_id; @@ -306,19 +306,20 @@ if (!empty($work_id)) { if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) { echo Display::display_warning_message(get_lang('ResourceLockedByGradebook')); } else { - $comments = getWorkComments($work_item); + /*$comments = getWorkComments($work_item); $template = $tpl->get_template('work/comments.tpl'); $tpl->assign('comments', $comments); $commentForm = getWorkCommentForm($work_item, 'edit'); - + */ if (api_is_allowed_to_session_edit()) { - $tpl->assign('form', $commentForm); + //$tpl->assign('form', $commentForm); } - $content .= $form->returnForm(); - $content .= $tpl->fetch($template); + + /*$content .= $form->returnForm(); + $content .= $tpl->fetch($template);*/ } } elseif ($is_author) { if (empty($work_item['qualificator_id']) || $work_item['qualificator_id'] == 0) { diff --git a/main/work/edit_work.php b/main/work/edit_work.php index 932872a54b..5ca5f1f28f 100755 --- a/main/work/edit_work.php +++ b/main/work/edit_work.php @@ -104,7 +104,7 @@ if ($form->validate()) { updateDirName($workData, $params['new_dir']); $currentUrl = api_get_path(WEB_CODE_PATH).'work/edit_work.php?id='.$workId.'&'.api_get_cidreq(); - Display::addFlash(Display::return_message(get_lang('FolderEdited'), 'success')); + Display::addFlash(Display::return_message(get_lang('Updated'), 'success')); header('Location: '.$currentUrl); exit; diff --git a/main/work/student_work.php b/main/work/student_work.php index 09ab2c59ae..8327cabd11 100755 --- a/main/work/student_work.php +++ b/main/work/student_work.php @@ -177,7 +177,7 @@ foreach ($workPerUser as $work) { if (api_is_allowed_to_edit()) { $url = api_get_path(WEB_CODE_PATH).'work/edit.php?'.api_get_cidreq().'&item_id='.$itemId.'&id='.$workId.'&parent_id='.$workId; $links .= Display::url( - Display::return_icon('rate_work.png', get_lang('Comment')), + Display::return_icon('edit.png', get_lang('Comment')), $url ); } diff --git a/main/work/view.php b/main/work/view.php index 8829375195..3dbc922f90 100755 --- a/main/work/view.php +++ b/main/work/view.php @@ -72,11 +72,66 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i } switch ($action) { + case 'update_score': + if (api_is_allowed_to_edit()) { + $work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION); + $sql = "UPDATE $work_table + SET + qualificator_id = '".api_get_user_id()."', + qualification = '".api_float_val($_POST['qualification'])."', + date_of_qualification = '".api_get_utc_datetime()."' + WHERE c_id = ".$courseInfo['real_id']." AND id = $id"; + Database::query($sql); + $resultUpload = uploadWork($my_folder_data, $courseInfo, true, $work); + if ($resultUpload) { + $work_table = Database:: get_course_table( + TABLE_STUDENT_PUBLICATION + ); + + if (isset($resultUpload['url']) && !empty($resultUpload['url'])) { + $title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang('Untitled'); + $urlToSave = Database::escape_string($resultUpload['url']); + $title = Database::escape_string($title); + $sql = "UPDATE $work_table SET + url_correction = '".$urlToSave."', + title_correction = '".$title."' + WHERE iid = ".$work['iid']; + Database::query($sql); + Display::addFlash( + Display::return_message(get_lang('FileUploadSucces')) + ); + } + } + + if (isset($_POST['send_email'])) { + $urlToSave = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$id; + $subject = sprintf(get_lang('ThereIsANewWorkFeedback'), $work['title']); + $message = sprintf(get_lang('ThereIsANewWorkFeedbackInWorkXHere'), $work['title'], $urlToSave); + + MessageManager::send_message_simple( + $work['user_id'], + $subject, + $message, + api_get_user_id(), + isset($_POST['send_to_drh_users']) + ); + + Display::addFlash( + Display::return_message(get_lang('MessageSent')) + ); + } + Display::addFlash( + Display::return_message(get_lang('Updated')) + ); + } + header('Location: '.$url); + exit; + + break; case 'send_comment': if (isset($_FILES["file"])) { $_POST['file'] = $_FILES["file"]; } - addWorkComment( api_get_course_info(), api_get_user_id(), @@ -161,6 +216,40 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i } } + $qualification = $my_folder_data['qualification']; + if (api_is_allowed_to_edit() && !empty($qualification) && intval($qualification) > 0) { + $form = new FormValidator( + 'form', + 'POST', + api_get_self()."?action=update_score&".api_get_cidreq()."&id=".$id, + '', + array('enctype' => "multipart/form-data") + ); + $form->addElement('hidden', 'id', $id); + $form->addFloat( + 'qualification', + array(get_lang('Qualification'), " / ".$qualification), + false, + [], + false, + 0, + $qualification + ); + + $form->addFile('file', get_lang('Correction')); + $form->addCheckBox( + 'send_email', + null, + get_lang('SendMailToStudent') + ); + $form->setDefaults(['qualification' => $work['qualification']]); + + $form->addButtonUpdate(get_lang('Update')); + $tpl->assign('score_form', $form->returnForm()); + } else { + $tpl->assign('score_form', $actions); + } + $tpl->assign('actions', $actions); if (api_is_allowed_to_session_edit()) { $tpl->assign('form', $commentForm); diff --git a/main/work/work.lib.php b/main/work/work.lib.php index d9c4a88287..6aa1978650 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -1745,7 +1745,7 @@ function get_work_user_list_from_documents( $editIcon = Display::return_icon('edit.png', get_lang('Edit')); $addIcon = Display::return_icon('add.png', get_lang('Add')); $deleteIcon = Display::return_icon('delete.png', get_lang('Delete')); - $viewIcon = Display::return_icon('default.png', get_lang('View')); + $viewIcon = Display::return_icon('rate_work.png', get_lang('CorrectAndRate')); $allowEdition = api_get_course_setting('student_delete_own_publication'); $workList = array(); @@ -1957,6 +1957,11 @@ function get_work_user_list( $url = api_get_path(WEB_CODE_PATH).'work/'; $unoconv = api_get_configuration_value('unoconv.binaries'); + $loadingText = addslashes(get_lang('Loading')); + $uploadedText = addslashes(get_lang('Uploaded')); + $failsUploadText = addslashes(get_lang('UplNoFileUploaded')); + $failsUploadIcon = Display::return_icon('closed-circle.png', '', [], ICON_SIZE_TINY); + while ($work = Database::fetch_array($result, 'ASSOC')) { $item_id = $work['id']; @@ -2009,7 +2014,6 @@ function get_work_user_list( } $work['qualification_score'] = $work['qualification']; - $add_string = ''; $time_expires = ''; if (!empty($work_assignment['expires_on'])) { @@ -2021,7 +2025,7 @@ function get_work_user_list( if (!empty($work_assignment['expires_on']) && !empty($time_expires) && ($time_expires < api_strtotime($work['sent_date'], 'UTC'))) { - $add_string = Display::label(get_lang('Expired'), 'important'); + $add_string = Display::label(get_lang('Expired'), 'important').' - '; } if (($can_read && $work['accepted'] == '1') || @@ -2044,7 +2048,6 @@ function get_work_user_list( // File name. $link_to_download = null; - // If URL is present then there's a file to download keep BC. if ($work['contains_file'] || !empty($work['url'])) { $link_to_download = ''. @@ -2069,14 +2072,13 @@ function get_work_user_list( // Date. $work_date = api_convert_and_format_date($work['sent_date']); $date = date_to_str_ago($work['sent_date']). ' ' . $work_date; - $work['formatted_date'] = $work_date . ' - ' . $add_string; + $work['formatted_date'] = $work_date . ' ' . $add_string; $work['sent_date_from_db'] = $work['sent_date']; - $work['sent_date'] = '
' . $add_string . ' - ' . $work['sent_date'] . '
'; + $work['sent_date'] = '
' . $add_string . ' ' . $work['sent_date'] . '
'; // Actions. $correction = ''; - $action = ''; if (api_is_allowed_to_edit()) { if (!empty($work['url_correction'])) { @@ -2087,16 +2089,13 @@ function get_work_user_list( } $action .= '
'. - Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL).' '; + Display::return_icon('rate_work.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL).' '; if ($unoconv && empty($work['contains_file'])) { $action .= ''. Display::return_icon('export_doc.png', get_lang('ExportToDoc'),array(), ICON_SIZE_SMALL).' '; } - $loadingText = addslashes(get_lang('Loading')); - $uploadedText = addslashes(get_lang('Uploaded')); - $failsUploadText = addslashes(get_lang('UplNoFileUploaded')); - $failsUploadIcon = Display::return_icon('closed-circle.png', '', [], ICON_SIZE_TINY); + $correction = '
'. - Display::return_icon('rate_work.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL).''; + Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).''; } else { $action .= ''. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).''; @@ -2154,7 +2153,12 @@ function get_work_user_list( if ($work['contains_file']) { if ($locked) { - $action .= Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL); + $action .= Display::return_icon( + 'move_na.png', + get_lang('Move'), + array(), + ICON_SIZE_SMALL + ); } else { $action .= ''. Display::return_icon('move.png', get_lang('Move'),array(), ICON_SIZE_SMALL).''; @@ -3458,12 +3462,14 @@ function uploadWork($my_folder_data, $_course, $isCorrection = false, $workInfo } $curdirpath = basename($my_folder_data['url']); + // If we come from the group tools the groupid will be saved in $work_table if (is_dir($updir.$curdirpath) || empty($curdirpath)) { $result = move_uploaded_file( $file['tmp_name'], $updir.$curdirpath.'/'.$new_file_name ); + } else { return array( 'error' => Display :: return_message( diff --git a/main/work/work_list_all.php b/main/work/work_list_all.php index 62a605f2de..4c5ef0999f 100755 --- a/main/work/work_list_all.php +++ b/main/work/work_list_all.php @@ -169,7 +169,6 @@ $actionsLeft = ''; $actionsLeft .= Display::return_icon('new_document.png', get_lang('AddDocument'), '', ICON_SIZE_MEDIUM).'';