Adding upload_from_template.php new work file in order to upload documents based in templates see BT#6616

1.9.x
Julio Montoya 11 years ago
parent dfa28bafb0
commit e247d53ddd
  1. 1
      main/template/default/work/view.tpl
  2. 2
      main/work/edit.php
  3. 24
      main/work/upload.php
  4. 116
      main/work/upload_from_template.php
  5. 3
      main/work/view.php
  6. 56
      main/work/work.lib.php
  7. 11
      main/work/work_list.php
  8. 18
      main/work/work_list_all.php

@ -7,6 +7,7 @@
{# "UpdatedBy"|get_lang|format(comment.username) #}
{% if work_comment_enabled %}
<hr>
<h4>
{{ 'Comments' | get_lang }}
</h4>

@ -8,8 +8,6 @@ $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
/* Configuration settings */
api_protect_course_script(true);
// Including necessary files

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
@ -7,8 +8,6 @@ $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
/* Configuration settings */
api_protect_course_script(true);
// Including necessary files
@ -34,14 +33,14 @@ if (empty($work_id)) {
api_not_allowed(true);
}
allowOnlySubscribedUser($user_id, $work_id, $course_id);
$workInfo = get_work_data_by_id($work_id);
if (empty($workInfo)) {
api_not_allowed(true);
}
allowOnlySubscribedUser($user_id, $work_id, $course_id);
$is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code, $session_id);
$is_course_member = $is_course_member || api_is_platform_admin();
@ -53,7 +52,6 @@ $check = Security::check_token('post');
$token = Security::get_token();
$student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
$workInfo['qualification'] = intval($workInfo['qualification']);
// @todo add an option to allow/block multiple attempts.
/*
@ -71,10 +69,8 @@ if (!empty($workInfo) && !empty($workInfo['qualification'])) {
}
}*/
$has_expired = false;
$has_ended = false;
$homework = get_work_assignment_by_id($workInfo['id']);
$message = getWorkWarningMessage($homework);
$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']);
@ -85,14 +81,6 @@ setWorkUploadForm($form);
$form->addElement('hidden', 'id', $work_id);
$form->addElement('hidden', 'sec_token', $token);
$documentTemplateData = getDocumentTemplateFromWork($work_id, $course_info);
if (!empty($documentTemplateData)) {
$defaults['title'] = $userInfo['complete_name'].'_'.$documentTemplateData['title'].'_'.substr(api_get_utc_datetime(), 0, 10);
$defaults['description'] = $documentTemplateData['file_content'];
}
$form->setDefaults($defaults);
$error_message = null;
$succeed = false;
@ -117,14 +105,14 @@ $htmlHeadXtra[] = to_javascript_work();
Display :: display_header(null);
if (!empty($work_id)) {
echo $message;
echo $validationStatus['message'];
if ($is_allowed_to_edit) {
if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) {
echo Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
} else {
$form->display();
}
} elseif ($student_can_edit_in_session && $has_ended == false) {
} elseif ($student_can_edit_in_session && $validationStatus['has_ended'] == false) {
$form->display();
} else {
Display::display_error_message(get_lang('ActionNotAllowed'));

@ -0,0 +1,116 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
$language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
api_protect_course_script(true);
// Including necessary files
require_once 'work.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';
$this_section = SECTION_COURSES;
$work_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
$is_allowed_to_edit = api_is_allowed_to_edit();
$course_id = api_get_course_int_id();
$user_id = api_get_user_id();
$userInfo = api_get_user_info();
$session_id = api_get_session_id();
$course_code = api_get_course_id();
$course_info = api_get_course_info();
$group_id = api_get_group_id();
if (empty($work_id)) {
api_not_allowed(true);
}
$workInfo = get_work_data_by_id($work_id);
if (empty($workInfo)) {
api_not_allowed(true);
}
allowOnlySubscribedUser($user_id, $work_id, $course_id);
$is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code, $session_id);
$is_course_member = $is_course_member || api_is_platform_admin();
if ($is_course_member == false) {
api_not_allowed(true);
}
$check = Security::check_token('post');
$token = Security::get_token();
$student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
$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('UploadFromTemplate'));
$form = new FormValidator('form', 'POST', api_get_self()."?".api_get_cidreq()."&id=".$work_id, '', array('enctype' => "multipart/form-data"));
setWorkUploadForm($form, false);
$form->addElement('hidden', 'id', $work_id);
$form->addElement('hidden', 'sec_token', $token);
$documentTemplateData = getDocumentTemplateFromWork($work_id, $course_info);
if (!empty($documentTemplateData)) {
$defaults['title'] = $userInfo['complete_name'].'_'.$documentTemplateData['title'].'_'.substr(api_get_utc_datetime(), 0, 10);
$defaults['description'] = $documentTemplateData['file_content'];
}
$form->setDefaults($defaults);
$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, $id_session, $group_id, $user_id);
$script = 'work_list.php';
if ($is_allowed_to_edit) {
$script = 'work_list_all.php';
}
header('Location: '.api_get_path(WEB_CODE_PATH).'work/'.$script.'?'.api_get_cidreq().'&id='.$work_id.'&error_message='.$error_message);
exit;
} else {
// Bad token or can't add works
$error_message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error');
}
}
$htmlHeadXtra[] = to_javascript_work();
Display :: display_header(null);
if (!empty($work_id)) {
echo $validationStatus['message'];
if ($is_allowed_to_edit) {
if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) {
echo Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
} else {
$form->display();
}
} elseif ($student_can_edit_in_session && $validationStatus['has_ended'] == false) {
$form->display();
} else {
Display::display_error_message(get_lang('ActionNotAllowed'));
}
} else {
Display::display_error_message(get_lang('ActionNotAllowed'));
}
Display :: display_footer();

@ -29,8 +29,7 @@ if (user_is_author($id) || $course_info['show_score'] == 0 && $work['active'] ==
}
$interbreadcrumb[] = array('url' => $url_dir, 'name' => $my_folder_data['title']);
$interbreadcrumb[] = array('url' => '#','name' => $work['title']);
if (
($course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) ||
if (($course_info['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) ||
api_is_allowed_to_edit() || user_is_author($id)
) {

@ -2376,24 +2376,25 @@ function getDocumentTemplateFromWork($workId, $courseInfo)
}
/**
* @param $workId
* @param $courseInfo
* @param int $workId
* @param array $courseInfo
*/
function getAllDocumentsFromWorkToString($workId, $courseInfo)
{
$documents = getAllDocumentToWork($workId, $courseInfo['real_id']);
$content = null;
if (!empty($documents)) {
$docContent = '<ul class="nav nav-list well">';
$docContent .= '<li class="nav-header">'.get_lang('Documents').'</li>';
$content .= '<ul class="nav nav-list well">';
$content .= '<li class="nav-header">'.get_lang('Documents').'</li>';
foreach ($documents as $doc) {
$docData = DocumentManager::get_document_data_by_id($doc['document_id'], $courseInfo['code']);
if ($docData) {
$docContent .= '<li><a target="_blank" href="'.$docData['url'].'">'.$docData['title'].'</a></li>';
$content .= '<li><a target="_blank" href="'.$docData['url'].'">'.$docData['title'].'</a></li>';
}
}
$docContent .= '</ul><br />';
echo $docContent;
$content .= '</ul><br />';
}
return $content;
}
/**
@ -2488,8 +2489,11 @@ function getWorkCommentForm($work)
* @param array $homework result of get_work_assignment_by_id()
* @return string
*/
function getWorkWarningMessage($homework) {
function getWorkDateValidationStatus($homework) {
$message = null;
$has_expired = false;
$has_ended = false;
if (!empty($homework)) {
if ($homework['expires_on'] != '0000-00-00 00:00:00' || $homework['ends_on'] != '0000-00-00 00:00:00') {
@ -2529,25 +2533,32 @@ function getWorkWarningMessage($homework) {
}
}
}
return $message;
return array(
'message' => $message,
'has_ended' => $has_ended,
'has_expired' => $has_expired
);
}
/**
* @param FormValidator $form
* @param bool $uploadFile
*/
function setWorkUploadForm($form)
function setWorkUploadForm($form, $uploadFile = true)
{
$form->addElement('header', get_lang('UploadADocument'));
$form->addElement('hidden', 'contains_file', 0, array('id'=>'contains_file_id'));
$form->addElement('hidden', 'active', 1);
$form->addElement('hidden', 'accepted', 1);
$form->addElement('file', 'file', get_lang('UploadADocument'), 'size="40" onchange="updateDocumentTitle(this.value)"');
if ($uploadFile) {
$form->addElement('file', 'file', get_lang('UploadADocument'), 'size="40" onchange="updateDocumentTitle(this.value)"');
$form->add_real_progress_bar('uploadWork', 'file');
}
$form->addElement('text', 'title', get_lang('Title'), array('id' => 'file_upload', 'class' => 'span4'));
$form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
$form->addElement('style_submit_button', 'submitWork', get_lang('Send'), array('class'=> 'upload', 'value' => "submitWork"));
$form->add_real_progress_bar('uploadWork', 'file');
}
/**
@ -2681,21 +2692,14 @@ function event_upload($docId, $userId, $courseCode, $sessionId) {
return 1;
}
/**
* @param array $my_folder_data
* @param array $values
* @param array $course_info
* @param int $session_id
* @return null|string
*/
/**
* @param array $workInfo
* @param array $values
* @param array $course_info
* @param int $session_id
* @param int $group_id
* @param int $user_id
* @return string
* @param array $courseInfo
* @param int $sessionId
* @param int $groupId
* @param int $userId
* @return null|string
*/
function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId, $userId)
{

@ -8,8 +8,6 @@ $language_file = array('exercice', 'work', 'document', 'admin', 'gradebook');
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_STUDENTPUBLICATION;
/* Configuration settings */
api_protect_course_script(true);
// Including necessary files
@ -60,12 +58,17 @@ $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work.php?
$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work_list.php?'.api_get_cidreq().'&id='.$workId, 'name' => $my_folder_data['title']);
Display :: display_header(null);
$documentsAddedInWork = getAllDocumentsFromWorkToString($workId, $courseInfo);
echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).'</a>';
if (api_is_allowed_to_session_edit(false, true) && !empty($workId)) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
echo Display::return_icon('upload_file.png', get_lang('UploadADocument'),'',ICON_SIZE_MEDIUM).'</a>';
echo Display::return_icon('upload_file.png', get_lang('UploadADocument'), '', ICON_SIZE_MEDIUM).'</a>';
if (!empty($documentsAddedInWork)) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload_from_template.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
}
echo Display::return_icon('import_html.png', get_lang('UploadFromTemplate'), '', ICON_SIZE_MEDIUM).'</a>';
}
echo '</div>';
@ -78,7 +81,7 @@ if (!empty($my_folder_data['description'])) {
echo '<p><div><strong>'.get_lang('Description').':</strong><p>'.Security::remove_XSS($my_folder_data['description']).'</p></div></p>';
}
echo getAllDocumentsFromWorkToString($workId, $courseInfo);
echo $documentsAddedInWork;
$check_qualification = intval($my_folder_data['qualification']);

@ -61,6 +61,7 @@ $interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'work/work_list
$error_message = null;
Display :: display_header(null);
$documentsAddedInWork = getAllDocumentsFromWorkToString($workId, $courseInfo);
echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq().'&origin='.$origin.'&gradebook='.$gradebook.'">'.Display::return_icon('back.png', get_lang('BackToWorksList'),'',ICON_SIZE_MEDIUM).'</a>';
@ -68,6 +69,11 @@ if (api_is_allowed_to_session_edit(false, true) && !empty($workId)) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
echo Display::return_icon('upload_file.png', get_lang('UploadADocument'), '', ICON_SIZE_MEDIUM).'</a>';
if (!empty($documentsAddedInWork)) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/upload_from_template.php?'.api_get_cidreq().'&id='.$workId.'&origin='.$origin.'&gradebook='.$gradebook.'">';
}
echo Display::return_icon('import_html.png', get_lang('UploadFromTemplate'), '', ICON_SIZE_MEDIUM).'</a>';
if (ADD_DOCUMENT_TO_WORK) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'work/add_document.php?'.api_get_cidreq().'&id='.$workId.'">';
echo Display::return_icon('new_document.png', get_lang('AddDocument'), '', ICON_SIZE_MEDIUM).'</a>';
@ -101,15 +107,12 @@ $check_qualification = intval($my_folder_data['qualification']);
if (!empty($work_data['enable_qualification']) && !empty($check_qualification)) {
$type = 'simple';
//$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions'));
$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Qualification'), get_lang('Date'), get_lang('Status'), get_lang('Actions'));
$column_model = array (
array('name'=>'type', 'index'=>'file', 'width'=>'10', 'align'=>'left', 'search' => 'false'),
array('name'=>'firstname', 'index'=>'firstname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
array('name'=>'lastname', 'index'=>'lastname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
//array('name'=>'username', 'index'=>'username', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
array('name'=>'title', 'index'=>'title', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'wrap_cell' => 'true'),
// array('name'=>'file', 'index'=>'file', 'width'=>'20', 'align'=>'left', 'search' => 'false'),
array('name'=>'qualification', 'index'=>'qualification', 'width'=>'20', 'align'=>'left', 'search' => 'true'),
array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
@ -117,18 +120,13 @@ if (!empty($work_data['enable_qualification']) && !empty($check_qualification))
);
} else {
$type = 'complex';
//$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Title'), get_lang('Date'), get_lang('Actions'));
$columns = array(get_lang('Type'), get_lang('FirstName'), get_lang('LastName'), get_lang('Title'), get_lang('Date'), get_lang('Actions'));
$column_model = array (
array('name'=>'type', 'index'=>'file', 'width'=>'10', 'align'=>'left', 'search' => 'false'),
array('name'=>'firstname', 'index'=>'firstname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
array('name'=>'lastname', 'index'=>'lastname', 'width'=>'35', 'align'=>'left', 'search' => 'true'),
//array('name'=>'username', 'index'=>'username', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
array('name'=>'title', 'index'=>'title', 'width'=>'40', 'align'=>'left', 'search' => 'false', 'wrap_cell' => "true"),
// array('name'=>'file', 'index'=>'file', 'width'=>'20', 'align'=>'left', 'search' => 'false'),
//array('name'=>'qualification', 'index'=>'qualification', 'width'=>'20', 'align'=>'left', 'search' => 'true'),
array('name'=>'sent_date', 'index'=>'sent_date', 'width'=>'45', 'align'=>'left', 'search' => 'true', 'wrap_cell' => 'true'),
//array('name'=>'qualificator_id','index'=>'qualificator_id', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'50', 'align'=>'left', 'search' => 'false', 'sortable'=>'false', 'wrap_cell' => 'true')
);
}
@ -153,8 +151,6 @@ $(function() {
</script>
<?php
echo getAllDocumentsFromWorkToString($workId, $courseInfo);
echo $documentsAddedInWork;
echo Display::grid_html('results');
Display :: display_footer();

Loading…
Cancel
Save