Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

1.10.x
Yannick Warnier 8 years ago
commit 2fbd07e31c
  1. 4
      main/inc/ajax/work.ajax.php
  2. 9
      main/inc/lib/formvalidator/FormValidator.class.php
  3. 1
      main/inc/lib/system/session.class.php
  4. 39
      main/work/work.lib.php

@ -41,7 +41,7 @@ switch ($action) {
'title' => $file['name'],
'description' => ''
];
$result = processWorkForm($workInfo, $values, $courseInfo, $sessionId, 0, $userId, $file);
$result = processWorkForm($workInfo, $values, $courseInfo, $sessionId, 0, $userId, $file, true);
$json = array();
if (!empty($result) && is_array($result) && empty($result['error'])) {
@ -60,7 +60,7 @@ switch ($action) {
);
} else {
$json['url'] = '';
$json['error'] = get_lang('Error');
$json['error'] = isset($result['error']) ? $result['error'] : get_lang('Error');
}
$resultList[] = $json;
}

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* Class FormValidator
* create/manipulate/validate user input.
@ -1384,6 +1386,9 @@ EOT;
node
.prepend('<br>')
.prepend(file.preview);
node
.append('<br>')
.append($('<span class=\"text-success\"/>').text('" . get_lang('UplUploadSucceeded') . "'));
}
if (file.error) {
node
@ -1402,7 +1407,6 @@ EOT;
progress + '%'
);
}).on('fileuploaddone', function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.url) {
var link = $('<a>')
@ -1419,7 +1423,8 @@ EOT;
});
}).on('fileuploadfail', function (e, data) {
$.each(data.files, function (index) {
var error = $('<span class=\"text-danger\"/>').text('".get_lang('Failed')."');
var failedMessage = '" . get_lang('UplUploadFailed') . "';
var error = $('<span class=\"text-danger\"/>').text(failedMessage);
$(data.context.children()[index])
.append('<br>')
.append(error);

@ -39,6 +39,7 @@ class Session implements \ArrayAccess
* Returns true if session has variable set up, false otherwise.
*
* @param string $variable
* @return mixed value
*/
static function has($variable)
{

@ -1423,7 +1423,7 @@ function getWorkListStudent(
$lastWork = getLastWorkStudentFromParentByUser($userId, $work['id'], $courseInfo);
if (!empty($lastWork)) {
$work['last_upload'] = Display::label($lastWork['qualification'], 'warning').' - ';
$work['last_upload'] = (!empty($lastWork['qualification'])) ? Display::label($lastWork['qualification'], 'warning').' - ' : '';
$work['last_upload'] .= api_get_local_time($lastWork['sent_date']);
}
@ -3638,6 +3638,23 @@ function sendAlertToUsers($workId, $courseInfo, $session_id)
}
}
/**
* Check if the current uploaded work filename already exists in the current assement
*
* @param $filename
* @param $workId
* @return mixed
*/
function checkExistingWorkFileName($filename, $workId)
{
$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$filename = Database::escape_string($filename);
$sql = "SELECT title FROM $work_table
WHERE parent_id = $workId AND title = '$filename'";
$result = Database::query($sql);
return Database::fetch_assoc($result);
}
/**
* @param array $workInfo
* @param array $values
@ -3646,10 +3663,11 @@ function sendAlertToUsers($workId, $courseInfo, $session_id)
* @param int $groupId
* @param int $userId
* @param array $file
* @param bool $checkDuplicated
*
* @return null|string
*/
function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId, $userId, $file = [])
function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId, $userId, $file = [], $checkDuplicated = false)
{
$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
@ -3667,9 +3685,20 @@ function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId,
$filename = null;
$url = null;
$filesize = null;
$workData = [];
if ($values['contains_file']) {
$result = uploadWork($workInfo, $courseInfo, false, [], $file);
if ($checkDuplicated) {
if (checkExistingWorkFileName($file['name'], $workInfo['id'])) {
$saveWork = false;
$workData['error'] = get_lang('YouAlreadySentThisFile');
} else {
$result = uploadWork($workInfo, $courseInfo, false, [], $file);
}
} else {
$result = uploadWork($workInfo, $courseInfo, false, [], $file);
}
if (isset($result['error'])) {
$message = $result['error'];
$saveWork = false;
@ -3680,15 +3709,13 @@ function processWorkForm($workInfo, $values, $courseInfo, $sessionId, $groupId,
}
$filesize = isset($result['filesize']) ? $result['filesize'] : null;
$url = $result['url'];
$url = isset($result['url']) ? $result['url'] : null;
}
if (empty($title)) {
$title = get_lang('Untitled');
}
$workData = [];
if ($saveWork) {
$active = '1';
$params = [

Loading…
Cancel
Save