Improving work upload page, moving code into functions.

1.9.x
Julio Montoya 12 years ago
parent 88ae9fb3db
commit d05fb11e42
  1. 36
      main/inc/lib/events.lib.inc.php
  2. 3
      main/inc/lib/main_api.lib.php
  3. 264
      main/work/upload.php
  4. 290
      main/work/work.lib.php
  5. 17
      main/work/work.php

@ -238,42 +238,6 @@ function event_download($doc_url) {
return 1;
}
/**
* @param doc_id id of document (id in mainDb.document table)
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @desc Record information for upload event
* used in the works tool to record informations when
* an user upload 1 work
*/
function event_upload($doc_id) {
global $_user;
global $_cid;
global $TABLETRACK_UPLOADS;
$reallyNow = api_get_utc_datetime();
if (isset($_user['user_id']) && $_user['user_id']!='') {
$user_id = "'".$_user['user_id']."'";
} else {
$user_id = "0"; // anonymous
}
$sql = "INSERT INTO ".$TABLETRACK_UPLOADS."
( upload_user_id,
upload_cours_id,
upload_work_id,
upload_date,
upload_session_id
)
VALUES (
".$user_id.",
'".$_cid."',
'".$doc_id."',
'".$reallyNow."',
'".api_get_session_id()."'
)";
$res = Database::query($sql);
return 1;
}
/**
* @param link_id (id in coursDb liens table)
* @author Sebastien Piraux <piraux_seb@hotmail.com>

@ -1921,7 +1921,8 @@ function api_get_session_visibility($session_id, $course_code = null, $ignore_vi
$session_id = intval($session_id);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "SELECT visibility, date_start, date_end, nb_days_access_after_end, nb_days_access_before_beginning FROM $tbl_session
$sql = "SELECT visibility, date_start, date_end, nb_days_access_after_end, nb_days_access_before_beginning
FROM $tbl_session
WHERE id = $session_id ";
$result = Database::query($sql);

@ -21,8 +21,6 @@ $this_section = SECTION_COURSES;
$work_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$is_allowed_to_edit = api_is_allowed_to_edit();
$course_id = api_get_course_int_id();
$user_id = api_get_user_id();
@ -38,9 +36,9 @@ if (empty($work_id)) {
allowOnlySubscribedUser($user_id, $work_id, $course_id);
$parent_data = $my_folder_data = get_work_data_by_id($work_id);
$workInfo = get_work_data_by_id($work_id);
if (empty($parent_data)) {
if (empty($workInfo)) {
api_not_allowed(true);
}
@ -55,15 +53,11 @@ $check = Security::check_token('post');
$token = Security::get_token();
$student_can_edit_in_session = api_is_allowed_to_session_edit(false, true);
$has_ended = false;
$is_author = false;
$parent_data['qualification'] = intval($parent_data['qualification']);
$workInfo['qualification'] = intval($workInfo['qualification']);
// @todo add an option to allow/block multiple attempts.
/*
if (!empty($parent_data) && !empty($parent_data['qualification'])) {
if (!empty($workInfo) && !empty($workInfo['qualification'])) {
$count = get_work_count_by_student($user_id, $work_id);
if ($count >= 1) {
Display::display_header();
@ -79,104 +73,18 @@ if (!empty($parent_data) && !empty($parent_data['qualification'])) {
$has_expired = false;
$has_ended = false;
$message = null;
if (!empty($my_folder_data)) {
$homework = get_work_assignment_by_id($my_folder_data['id']);
if ($homework['expires_on'] != '0000-00-00 00:00:00' || $homework['ends_on'] != '0000-00-00 00:00:00') {
$time_now = time();
if (!empty($homework['expires_on']) && $homework['expires_on'] != '0000-00-00 00:00:00') {
$time_expires = api_strtotime($homework['expires_on'], 'UTC');
$difference = $time_expires - $time_now;
if ($difference < 0) {
$has_expired = true;
}
}
if (empty($homework['expires_on']) || $homework['expires_on'] == '0000-00-00 00:00:00') {
$has_expired = false;
}
if (!empty($homework['ends_on']) && $homework['ends_on'] != '0000-00-00 00:00:00') {
$time_ends = api_strtotime($homework['ends_on'], 'UTC');
$difference2 = $time_ends - $time_now;
if ($difference2 < 0) {
$has_ended = true;
}
}
$ends_on = api_convert_and_format_date($homework['ends_on']);
$expires_on = api_convert_and_format_date($homework['expires_on']);
}
if ($has_ended) {
$message = Display::return_message(get_lang('EndDateAlreadyPassed').' '.$ends_on, 'error');
} elseif ($has_expired) {
$message = Display::return_message(get_lang('ExpiryDateAlreadyPassed').' '.$expires_on, 'warning');
} else {
if ($has_expired) {
$message = Display::return_message(get_lang('ExpiryDateToSendWorkIs').' '.$expires_on);
}
}
}
$homework = get_work_assignment_by_id($workInfo['id']);
$message = getWorkWarningMessage($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' => $parent_data['title']);
// form title
$form_title = get_lang('UploadADocument');
$interbreadcrumb[] = array('url' => '#', 'name' => $form_title);
$form = new FormValidator('form', 'POST', api_get_self()."?".api_get_cidreq()."&id=".$work_id."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&origin=$origin", '', array('enctype' => "multipart/form-data"));
$form->addElement('header', $form_title);
$show_progress_bar = false;
if ($submitGroupWorkUrl) {
// For user coming from group space to publish his work
$realUrl = str_replace($_configuration['root_sys'], api_get_path(WEB_PATH), str_replace("\\", '/', realpath($submitGroupWorkUrl)));
$form->addElement('hidden', 'newWorkUrl', $submitGroupWorkUrl);
$text_document = $form->addElement('text', 'document', get_lang('Document'));
$defaults['document'] = '<a href="' . format_url($submitGroupWorkUrl) . '">' . $realUrl . '</a>';
$text_document->freeze();
} else {
// else standard upload option
$form->addElement('file', 'file', get_lang('UploadADocument'), 'size="40" onchange="updateDocumentTitle(this.value)"');
$show_progress_bar = true;
}
$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);
$form->addElement('hidden', 'id', $work_id);
$form->addElement('hidden', 'contains_file', 0, array('id'=>'contains_file_id'));
$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('hidden', 'active', 1);
$form->addElement('hidden', 'accepted', 1);
$form->addElement('hidden', 'sec_token', $token);
$text = get_lang('Send');
$class = 'upload';
// fix the Ok button when we see the tool in the learn path
if ($origin == 'learnpath') {
$form->addElement('html', '<div style="margin-left:137px">');
$form->addElement('style_submit_button', 'submitWork', $text, array('class'=> $class, 'value' => "submitWork"));
$form->addElement('html', '</div>');
} else {
$form->addElement('style_submit_button', 'submitWork', $text, array('class'=> $class, 'value' => "submitWork"));
}
if (!empty($_POST['submitWork']) || $item_id) {
$form->addElement('style_submit_button', 'cancelForm', get_lang('Cancel'), 'class="cancel"');
}
if ($show_progress_bar) {
$form->add_real_progress_bar('uploadWork', 'file');
}
$documentTemplateData = getDocumentTemplateFromWork($work_id, $course_info);
if (!empty($documentTemplateData)) {
$defaults['title'] = $userInfo['complete_name'].'_'.$documentTemplateData['title'].'_'.substr(api_get_utc_datetime(), 0, 10);
@ -184,153 +92,24 @@ if (!empty($documentTemplateData)) {
}
$form->setDefaults($defaults);
$error_message = null;
$_course = api_get_course_info();
$currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH).$_course['path'] . '/';
$succeed = false;
if ($form->validate()) {
if ($student_can_edit_in_session && $check) {
// Check the token inserted into the form
$filename = null;
if (isset($_POST['submitWork'])) {
$url = null;
$contains_file = 0;
$title = isset($_POST['title']) ? $_POST['title'] : null;
$description = isset($_POST['description']) ? $_POST['description'] : null;
if ($_POST['contains_file'] && !empty($_FILES['file']['size'])) {
$updir = $currentCourseRepositorySys.'work/'; //directory path to upload
// Try to add an extension to the file if it has'nt one
$filename = add_ext_on_mime(stripslashes($_FILES['file']['name']), $_FILES['file']['type']);
// Replace dangerous characters
$filename = replace_dangerous_char($filename, 'strict');
// Transform any .php file in .phps fo security
$filename = php2phps($filename);
$filesize = filesize($_FILES['file']['tmp_name']);
if (empty($filesize)) {
$error_message .= Display :: return_message(get_lang('UplUploadFailedSizeIsZero'), 'error');
$succeed = false;
} elseif (!filter_extension($new_file_name)) {
//filter extension
$error_message .= Display :: return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'error');
$succeed = false;
}
if (!$title) {
$title = $_FILES['file']['name'];
}
// Compose a unique file name to avoid any conflict
$new_file_name = api_get_unique_id();
$curdirpath = basename($my_folder_data['url']);
// If we come from the group tools the groupid will be saved in $work_table
$result = move_uploaded_file($_FILES['file']['tmp_name'], $updir.$curdirpath.'/'.$new_file_name);
if ($result) {
$url = 'work/'.$curdirpath.'/'.$new_file_name;
$contains_file = 1;
}
}
if (empty($title)) {
$title = get_lang('Untitled');
}
$documents_total_space = DocumentManager::documents_total_space();
$course_max_space = DocumentManager::get_course_quota();
$total_size = $filesize + $documents_total_space;
if ($total_size > $course_max_space) {
$error_message .= Display::return_message(get_lang('NoSpace'), 'warning');
} else {
$active = '1';
$sql_add_publication = "INSERT INTO ".$work_table." SET
c_id = $course_id ,
url = '".$url . "',
title = '".Database::escape_string($title)."',
description = '".Database::escape_string($description)."',
contains_file = '".$contains_file."',
active = '" . $active."',
accepted = '1',
post_group_id = '".$group_id."',
sent_date = '".api_get_utc_datetime()."',
parent_id = '".$work_id."' ,
session_id = '".intval($id_session)."' ,
user_id = '".$user_id."'";
Database::query($sql_add_publication);
$id = Database::insert_id();
if ($id && array_key_exists('filename', $my_folder_data) && !empty($filename)) {
$sql = "UPDATE $work_table SET filename = '$filename' WHERE c_id = $course_id AND id = $id";
Database::query($sql);
}
}
if ($id) {
api_item_property_update($course_info, 'work', $id, 'DocumentAdded', $user_id, api_get_group_id());
$succeed = true;
}
} else {
$error_message .= Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error');
}
Security::clear_token();
} else {
//Bad token or can't add works
$error_message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error');
}
if (!empty($succeed) && !empty($id)) {
//last value is to check this is not "just" an edit
//YW Tis part serve to send a e-mail to the tutors when a new file is sent
$send = api_get_course_setting('email_alert_manager_on_new_doc');
if ($send > 0) {
// Lets predefine some variables. Be sure to change the from address!
if (empty($id_session)) {
//Teachers
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), null, null, null, COURSEMANAGER);
} else {
//Coaches
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id, null, null, 2);
}
$subject = "[" . api_get_setting('siteName') . "] ".get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$_course['name']." ";
foreach ($user_list as $user_data) {
$to_user_id = $user_data['user_id'];
$emailbody = get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$_course['name']."\n";
$user_info = api_get_user_info($user_id);
$emailbody .= get_lang('UserName')." : ".api_get_person_name($user_info['firstname'], $user_info['lastname'])."\n";
$emailbody .= get_lang('DateSent')." : ".api_format_date(api_get_local_time())."\n";
$emailbody .= get_lang('WorkName')." : ".$title."\n\n".get_lang('DownloadLink')."\n";
$url = api_get_path(WEB_CODE_PATH)."work/work.php?".api_get_cidreq()."&amp;id=".$work_id;
$emailbody .= $url;
MessageManager::send_message_simple($to_user_id, $subject, $emailbody);
}
}
$message = get_lang('DocAdd');
event_upload($id);
$error_message .= Display::return_message(get_lang('DocAdd'));
$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');
}
}
@ -338,23 +117,14 @@ $htmlHeadXtra[] = to_javascript_work();
Display :: display_header(null);
if (!empty($work_id)) {
echo $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 ($is_author) {
if (empty($work_item['qualificator_id']) || $work_item['qualificator_id'] == 0) {
$form->display();
} else {
Display::display_error_message(get_lang('ActionNotAllowed'));
}
} elseif ($student_can_edit_in_session && $has_ended == false) {
$form->display();
} else {
Display::display_error_message(get_lang('ActionNotAllowed'));

@ -285,11 +285,18 @@ function get_work_count_by_student($user_id, $work_id) {
/**
* @param int $id
* @param int $course_id
* @return array
*/
function get_work_assignment_by_id($id) {
function get_work_assignment_by_id($id, $course_id = null)
{
if (empty($courseId)) {
$course_id = api_get_course_int_id();
} else {
$course_id = intval($course_id);
}
$id = intval($id);
$course_id = api_get_course_int_id();
$table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$sql = "SELECT * FROM $table WHERE c_id = $course_id AND publication_id = $id";
$result = Database::query($sql);
@ -2475,5 +2482,284 @@ function getWorkCommentForm($work)
$form->addElement('hidden', 'id', $work['id']);
$form->addElement('button', 'button', get_lang('Send'));
return $form->return_form();
}
/**
* @param array $homework result of get_work_assignment_by_id()
* @return string
*/
function getWorkWarningMessage($homework) {
$message = null;
if (!empty($homework)) {
if ($homework['expires_on'] != '0000-00-00 00:00:00' || $homework['ends_on'] != '0000-00-00 00:00:00') {
$time_now = time();
if (!empty($homework['expires_on']) && $homework['expires_on'] != '0000-00-00 00:00:00') {
$time_expires = api_strtotime($homework['expires_on'], 'UTC');
$difference = $time_expires - $time_now;
if ($difference < 0) {
$has_expired = true;
}
}
if (empty($homework['expires_on']) || $homework['expires_on'] == '0000-00-00 00:00:00') {
$has_expired = false;
}
if (!empty($homework['ends_on']) && $homework['ends_on'] != '0000-00-00 00:00:00') {
$time_ends = api_strtotime($homework['ends_on'], 'UTC');
$difference2 = $time_ends - $time_now;
if ($difference2 < 0) {
$has_ended = true;
}
}
$ends_on = api_convert_and_format_date($homework['ends_on']);
$expires_on = api_convert_and_format_date($homework['expires_on']);
}
if ($has_ended) {
$message = Display::return_message(get_lang('EndDateAlreadyPassed').' '.$ends_on, 'error');
} elseif ($has_expired) {
$message = Display::return_message(get_lang('ExpiryDateAlreadyPassed').' '.$expires_on, 'warning');
} else {
if ($has_expired) {
$message = Display::return_message(get_lang('ExpiryDateToSendWorkIs').' '.$expires_on);
}
}
}
return $message;
}
/**
* @param FormValidator $form
*/
function setWorkUploadForm($form)
{
$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)"');
$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');
}
/**
* @param array $my_folder_data
* @param array $_course
* @return array
*/
function uploadWork($my_folder_data, $_course) {
if (empty($_FILES['file']['size'])) {
return array('error' => Display :: return_message(get_lang('UplUploadFailedSizeIsZero'), 'error'));
}
$currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH).$_course['path'] . '/';
$updir = $currentCourseRepositorySys.'work/'; //directory path to upload
// Try to add an extension to the file if it has'nt one
$filename = add_ext_on_mime(stripslashes($_FILES['file']['name']), $_FILES['file']['type']);
// Replace dangerous characters
$filename = replace_dangerous_char($filename, 'strict');
// Transform any .php file in .phps fo security
$filename = php2phps($filename);
$filesize = filesize($_FILES['file']['tmp_name']);
if (empty($filesize)) {
return array('error' => Display :: return_message(get_lang('UplUploadFailedSizeIsZero'), 'error'));
} elseif (!filter_extension($new_file_name)) {
return array('error' => Display :: return_message(get_lang('UplUnableToSaveFileFilteredExtension'), 'error'));
}
$documents_total_space = DocumentManager::documents_total_space($_course['real_id']);
$course_max_space = DocumentManager::get_course_quota($_course['code']);
$total_size = $filesize + $documents_total_space;
if ($total_size > $course_max_space) {
return array('error' => Display :: return_message(get_lang('NoSpace'), 'error'));
}
// Compose a unique file name to avoid any conflict
$new_file_name = api_get_unique_id();
$curdirpath = basename($my_folder_data['url']);
// If we come from the group tools the groupid will be saved in $work_table
$result = move_uploaded_file($_FILES['file']['tmp_name'], $updir.$curdirpath.'/'.$new_file_name);
$url = null;
if ($result) {
$url = 'work/'.$curdirpath.'/'.$new_file_name;
}
return array(
'url' => $url,
'filename' => $filename,
'error' => null
);
}
/**
* @param int $workId
* @param array $courseInfo
* @param int $session_id
*/
function sendAlertToTeacher($workId, $courseInfo, $session_id) {
$workData = get_work_assignment_by_id($workId, $courseInfo['real_id']);
//last value is to check this is not "just" an edit
//YW Tis part serve to send a e-mail to the tutors when a new file is sent
$send = api_get_course_setting('email_alert_manager_on_new_doc');
if ($send > 0) {
// Lets predefine some variables. Be sure to change the from address!
if (empty($id_session)) {
//Teachers
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), null, null, null, COURSEMANAGER);
} else {
//Coaches
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id, null, null, 2);
}
$subject = "[" . api_get_setting('siteName') . "] ".get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$courseInfo['name']." ";
foreach ($user_list as $user_data) {
$to_user_id = $user_data['user_id'];
$user_info = api_get_user_info($to_user_id);
$message = get_lang('SendMailBody')."\n".get_lang('CourseName')." : ".$courseInfo['name']."\n";
$message .= get_lang('UserName')." : ".api_get_person_name($user_info['firstname'], $user_info['lastname'])."\n";
$message .= get_lang('DateSent')." : ".api_format_date(api_get_local_time())."\n";
$message .= get_lang('WorkName')." : ".$workData['title']."\n\n".get_lang('DownloadLink')."\n";
$url = api_get_path(WEB_CODE_PATH)."work/work.php?cidReq=".$courseInfo['code']."&id_session=".$session_id."&id=".$workData['id'];
$message .= $url;
MessageManager::send_message_simple($to_user_id, $subject, $message);
}
}
}
/**
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @author Julio Montoya
* @desc Record information for upload event
* @param int $docId
* @param int $userId
* @param string $courseCode
* @param int $sessionId
* @return int
*/
function event_upload($docId, $userId, $courseCode, $sessionId) {
$TABLETRACK_UPLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_UPLOADS);
$reallyNow = api_get_utc_datetime();
$userId = intval($userId);
$docId = intval($docId);
$sessionId = intval($sessionId);
$courseCode = Database::escape_string($courseCode);
$sql = "INSERT INTO ".$TABLETRACK_UPLOADS."
( upload_user_id,
upload_cours_id,
upload_work_id,
upload_date,
upload_session_id
)
VALUES (
".$userId.",
'".$courseCode."',
'".$docId."',
'".$reallyNow."',
'".$sessionId."'
)";
Database::query($sql);
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
*/
function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId, $userId)
{
$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$courseId = $courseInfo['real_id'];
$groupId = intval($groupId);
$sessionId = intval($sessionId);
$title = $values['title'];
$description = $values['description'];
$contains_file = isset($values['contains_file']) && !empty($values['contains_file']) ? $values['contains_file']: 0;
$saveWork = true;
$message = null;
$filename = null;
if ($values['contains_file']) {
$result = uploadWork($workInfo, $courseInfo);
if (isset($result['error'])) {
$message = $result['error'];
$saveWork = false;
}
$filename = isset($result['filename']) ? $result['filename'] : null;
if (empty($title)) {
$title = isset($result['title']) && !empty($result['title']) ? $result['title'] : get_lang('Untitled');
}
$url = $result['url'];
}
if (empty($title)) {
$title = get_lang('Untitled');
}
if ($saveWork) {
$active = '1';
$sql = "INSERT INTO ".$work_table." SET
c_id = $courseId ,
url = '".$url . "',
title = '".Database::escape_string($title)."',
description = '".Database::escape_string($description)."',
contains_file = '".$contains_file."',
active = '" . $active."',
accepted = '1',
post_group_id = '".$groupId."',
sent_date = '".api_get_utc_datetime()."',
parent_id = '".$workInfo['id']."' ,
session_id = '".$sessionId."',
user_id = '".$userId."'";
Database::query($sql);
$id = Database::insert_id();
if ($id) {
if (array_key_exists('filename', $workInfo) && !empty($filename)) {
$sql = "UPDATE $work_table SET filename = '$filename' WHERE c_id = $courseId AND id = $id";
Database::query($sql);
}
api_item_property_update($courseInfo, 'work', $id, 'DocumentAdded', $userId, $groupId);
sendAlertToTeacher($id, $courseInfo, $sessionId);
event_upload($id, $userId, $courseInfo['code'], $sessionId) ;
$message = Display::return_message(get_lang('DocAdd'));
}
} else {
$message = Display::return_message(get_lang('IsNotPosibleSaveTheDocument'), 'error');
}
return $message;
}

@ -249,7 +249,7 @@ if ($origin == 'learnpath') {
/* Display links to upload form and tool options */
if (!in_array($action, array('add','create_dir'))) {
if (!in_array($action, array('add', 'create_dir'))) {
$token = Security::get_token();
}
@ -314,25 +314,20 @@ switch ($action) {
$form->addElement('header', get_lang('CreateAssignment').$token);
$form->addElement('hidden', 'action', 'add');
$form->addElement('hidden', 'curdirpath', Security :: remove_XSS($curdirpath));
// $form->addElement('hidden', 'sec_token', $token);
$form->addElement('text', 'new_dir', get_lang('AssignmentName'));
$form->addRule('new_dir', get_lang('ThisFieldIsRequired'), 'required');
$form->add_html_editor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
$form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: return plus();"><span id="plus">'.Display::return_icon('div_show.gif',get_lang('AdvancedParameters'), array('style' => 'vertical-align:center')).' '.get_lang('AdvancedParameters').'</span></a>');
$form->addElement('advanced_settings', '<a href="javascript: void(0);" onclick="javascript: return plus();">
<span id="plus">'.Display::return_icon('div_show.gif',get_lang('AdvancedParameters'), array('style' => 'vertical-align:center')).' '.get_lang('AdvancedParameters').'</span></a>');
$form->addElement('html', '<div id="options" style="display: none;">');
//QualificationOfAssignment
// QualificationOfAssignment
$form->addElement('text', 'qualification_value', get_lang('QualificationNumeric'));
if (Gradebook::is_active()) {
$form->addElement('checkbox', 'make_calification', null, get_lang('MakeQualifiable'), array('id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option1').style.display='block';}else{document.getElementById('option1').style.display='none';}"));
} else {
//QualificationOfAssignment
//$form->addElement('hidden', 'qualification_value',0);
// QualificationOfAssignment
$form->addElement('hidden', 'make_calification', false);
}
@ -347,7 +342,7 @@ switch ($action) {
$form->addElement('checkbox', 'type1', null, get_lang('EnableExpiryDate'), array('id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option2').style.display='block';}else{document.getElementById('option2').style.display='none';}"));
$form->addElement('html', '<div id="option2" style="display: none;">');
$form->addElement('advanced_settings',draw_date_picker('expires'));
$form->addElement('advanced_settings', draw_date_picker('expires'));
$form->addElement('html', '</div>');
$form->addElement('checkbox', 'type2', null, get_lang('EnableEndDate'), array('id' =>'make_calification_id', 'onclick' => "javascript: if(this.checked){document.getElementById('option3').style.display='block';}else{document.getElementById('option3').style.display='none';}"));

Loading…
Cancel
Save