Actualización
This commit is contained in:
597
main/dropbox/dropbox_class.inc.php
Normal file
597
main/dropbox/dropbox_class.inc.php
Normal file
@@ -0,0 +1,597 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
/**
|
||||
* Dropbox module for Chamilo
|
||||
* Classes for the dropbox module.
|
||||
*
|
||||
* 3 classes have been defined:
|
||||
* - Dropbox_Work:
|
||||
* . id
|
||||
* . uploader_id => who sent it
|
||||
* . filename => name of file stored on the server
|
||||
* . filesize
|
||||
* . title => name of file returned to user. This is the original name of the file
|
||||
* except when the original name contained spaces. In that case the spaces
|
||||
* will be replaced by _
|
||||
* . description
|
||||
* . author
|
||||
* . upload_date => date when file was first sent
|
||||
* . last_upload_date => date when file was last sent
|
||||
* . isOldWork => has the work already been uploaded before
|
||||
*
|
||||
* . feedback_date => date of most recent feedback
|
||||
* . feedback => feedback text (or HTML?)
|
||||
*
|
||||
* - Dropbox_SentWork extends Dropbox_Work
|
||||
* . recipients => array of ["id"]["name"] lists the recipients of the work
|
||||
*
|
||||
* - Dropbox_Person:
|
||||
* . userId
|
||||
* . receivedWork => array of Dropbox_Work objects
|
||||
* . sentWork => array of Dropbox_SentWork objects
|
||||
* . isCourseTutor
|
||||
* . isCourseAdmin
|
||||
* . _orderBy => private property used for determining the field by which the works have to be ordered
|
||||
*
|
||||
* @version 1.30
|
||||
*
|
||||
* @copyright 2004
|
||||
* @author Jan Bols <jan@ivpv.UGent.be>
|
||||
* with contributions by René Haentjens <rene.haentjens@UGent.be>
|
||||
*/
|
||||
class Dropbox_Work
|
||||
{
|
||||
public $id;
|
||||
public $uploader_id;
|
||||
public $filename;
|
||||
public $filesize;
|
||||
public $title;
|
||||
public $description;
|
||||
public $author;
|
||||
public $upload_date;
|
||||
public $last_upload_date;
|
||||
public $isOldWork;
|
||||
public $feedback_date;
|
||||
public $feedback;
|
||||
|
||||
/**
|
||||
* Constructor calls private functions to create a new work or retrieve an existing work from DB
|
||||
* depending on the number of parameters.
|
||||
*
|
||||
* @param int $arg1
|
||||
* @param string $arg2
|
||||
* @param string $arg3
|
||||
* @param string $arg4
|
||||
* @param string $arg5
|
||||
* @param int $arg6
|
||||
*/
|
||||
public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null)
|
||||
{
|
||||
if (func_num_args() > 1) {
|
||||
$this->createNewWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
|
||||
} else {
|
||||
$this->createExistingWork($arg1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* private function creating a new work object.
|
||||
*
|
||||
* @param int $uploader_id
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @param string $author
|
||||
* @param string $filename
|
||||
* @param int $filesize
|
||||
*
|
||||
* @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
|
||||
* As a consequence this parameter can be removed
|
||||
*/
|
||||
public function createNewWork($uploader_id, $title, $description, $author, $filename, $filesize)
|
||||
{
|
||||
// Fill in the properties
|
||||
$this->uploader_id = (int) $uploader_id;
|
||||
$this->filename = $filename;
|
||||
$this->filesize = $filesize;
|
||||
$this->title = $title;
|
||||
$this->description = $description;
|
||||
$this->author = $author;
|
||||
$this->last_upload_date = api_get_utc_datetime();
|
||||
$course_id = api_get_course_int_id();
|
||||
|
||||
// Check if object exists already. If it does, the old object is used
|
||||
// with updated information (authors, description, upload_date)
|
||||
$this->isOldWork = false;
|
||||
$sql = 'SELECT id, upload_date
|
||||
FROM '.Database::get_course_table(TABLE_DROPBOX_FILE)."
|
||||
WHERE
|
||||
c_id = $course_id AND
|
||||
filename = '".Database::escape_string($this->filename)."'";
|
||||
$result = Database::query($sql);
|
||||
$res = Database::fetch_array($result);
|
||||
if ($res) {
|
||||
$this->isOldWork = true;
|
||||
}
|
||||
// Insert or update the dropbox_file table and set the id property
|
||||
if ($this->isOldWork) {
|
||||
$this->id = $res['id'];
|
||||
$this->upload_date = $res['upload_date'];
|
||||
|
||||
$params = [
|
||||
'filesize' => $this->filesize,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'author' => $this->author,
|
||||
'last_upload_date' => $this->last_upload_date,
|
||||
'session_id' => api_get_session_id(),
|
||||
];
|
||||
|
||||
Database::update(
|
||||
Database::get_course_table(TABLE_DROPBOX_FILE),
|
||||
$params,
|
||||
['c_id = ? AND id = ?' => [$course_id, $this->id]]
|
||||
);
|
||||
} else {
|
||||
$this->upload_date = $this->last_upload_date;
|
||||
$params = [
|
||||
'c_id' => $course_id,
|
||||
'uploader_id' => $this->uploader_id,
|
||||
'filename' => $this->filename,
|
||||
'filesize' => $this->filesize,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'author' => $this->author,
|
||||
'upload_date' => $this->upload_date,
|
||||
'last_upload_date' => $this->last_upload_date,
|
||||
'session_id' => api_get_session_id(),
|
||||
'cat_id' => 0,
|
||||
];
|
||||
|
||||
$this->id = Database::insert(Database::get_course_table(TABLE_DROPBOX_FILE), $params);
|
||||
if ($this->id) {
|
||||
$sql = 'UPDATE '.Database::get_course_table(TABLE_DROPBOX_FILE)." SET id = iid
|
||||
WHERE iid = {$this->id}";
|
||||
Database::query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT count(file_id) as count
|
||||
FROM '.Database::get_course_table(TABLE_DROPBOX_PERSON)."
|
||||
WHERE c_id = $course_id AND file_id = ".intval($this->id).' AND user_id = '.$this->uploader_id;
|
||||
$result = Database::query($sql);
|
||||
$row = Database::fetch_array($result);
|
||||
if (0 == $row['count']) {
|
||||
// Insert entries into person table
|
||||
$sql = 'INSERT INTO '.Database::get_course_table(TABLE_DROPBOX_PERSON)." (c_id, file_id, user_id)
|
||||
VALUES ($course_id, ".intval($this->id).' , '.intval($this->uploader_id).')';
|
||||
Database::query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* private function creating existing object by retrieving info from db.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function createExistingWork($id)
|
||||
{
|
||||
$course_id = api_get_course_int_id();
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
|
||||
// Do some sanity checks
|
||||
$id = intval($id);
|
||||
|
||||
// Get the data from DB
|
||||
$sql = 'SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id
|
||||
FROM '.Database::get_course_table(TABLE_DROPBOX_FILE)."
|
||||
WHERE c_id = $course_id AND id = ".$id.'';
|
||||
$result = Database::query($sql);
|
||||
$res = Database::fetch_array($result, 'ASSOC');
|
||||
|
||||
// Check if uploader is still in Chamilo system
|
||||
$uploader_id = stripslashes($res['uploader_id']);
|
||||
$userInfo = api_get_user_info($uploader_id);
|
||||
if (!$userInfo) {
|
||||
//deleted user
|
||||
$this->uploader_id = -1;
|
||||
} else {
|
||||
$this->uploader_id = $uploader_id;
|
||||
}
|
||||
|
||||
// Fill in properties
|
||||
$this->id = $id;
|
||||
$this->filename = stripslashes($res['filename']);
|
||||
$this->filesize = stripslashes($res['filesize']);
|
||||
$this->title = stripslashes($res['title']);
|
||||
$this->description = stripslashes($res['description']);
|
||||
$this->author = stripslashes($res['author']);
|
||||
$this->upload_date = stripslashes($res['upload_date']);
|
||||
$this->last_upload_date = stripslashes($res['last_upload_date']);
|
||||
$this->category = $res['cat_id'];
|
||||
|
||||
// Getting the feedback on the work.
|
||||
if ('viewfeedback' == $action && $this->id == $_GET['id']) {
|
||||
$feedback2 = [];
|
||||
$sql = 'SELECT * FROM '.Database::get_course_table(TABLE_DROPBOX_FEEDBACK)."
|
||||
WHERE c_id = $course_id AND file_id='".$id."'
|
||||
ORDER BY feedback_id ASC";
|
||||
$result = Database::query($sql);
|
||||
while ($row_feedback = Database::fetch_array($result)) {
|
||||
$row_feedback['feedback'] = Security::remove_XSS($row_feedback['feedback']);
|
||||
$feedback2[] = $row_feedback;
|
||||
}
|
||||
$this->feedback2 = $feedback2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function updateFile()
|
||||
{
|
||||
$course_id = api_get_course_int_id();
|
||||
if (empty($this->id) || empty($course_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = [
|
||||
'uploader_id' => $this->uploader_id,
|
||||
'filename' => $this->filename,
|
||||
'filesize' => $this->filesize,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'author' => $this->author,
|
||||
'upload_date' => $this->upload_date,
|
||||
'last_upload_date' => $this->last_upload_date,
|
||||
'session_id' => api_get_session_id(),
|
||||
];
|
||||
|
||||
Database::update(
|
||||
Database::get_course_table(TABLE_DROPBOX_FILE),
|
||||
$params,
|
||||
['c_id = ? AND id = ?' => [$course_id, $this->id]]
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Dropbox_SentWork extends Dropbox_Work
|
||||
{
|
||||
public $recipients; //array of ['id']['name'] arrays
|
||||
|
||||
/**
|
||||
* Constructor calls private functions to create a new work or retrieve an existing work from DB
|
||||
* depending on the number of parameters.
|
||||
*
|
||||
* @param int $arg1
|
||||
* @param string $arg2
|
||||
* @param string $arg3
|
||||
* @param string $arg4
|
||||
* @param string $arg5
|
||||
* @param int $arg6
|
||||
* @param array $arg7
|
||||
*/
|
||||
public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null)
|
||||
{
|
||||
if (func_num_args() > 1) {
|
||||
$this->createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
|
||||
} else {
|
||||
$this->createExistingSentWork($arg1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* private function creating a new SentWork object.
|
||||
*
|
||||
* @param int $uploader_id
|
||||
* @param string $title
|
||||
* @param string $description
|
||||
* @param string $author
|
||||
* @param string $filename
|
||||
* @param int $filesize
|
||||
* @param array $recipient_ids
|
||||
*/
|
||||
public function createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
|
||||
{
|
||||
$_course = api_get_course_info();
|
||||
|
||||
// Call constructor of Dropbox_Work object
|
||||
parent::__construct(
|
||||
$uploader_id,
|
||||
$title,
|
||||
$description,
|
||||
$author,
|
||||
$filename,
|
||||
$filesize
|
||||
);
|
||||
|
||||
$course_id = api_get_course_int_id();
|
||||
|
||||
// Do sanity checks on recipient_ids array & property filling
|
||||
// The sanity check for ex-course members is already done in base constructor
|
||||
$uploader_id = (int) $uploader_id;
|
||||
|
||||
$justSubmit = false;
|
||||
if (is_int($recipient_ids)) {
|
||||
$justSubmit = true;
|
||||
$recipient_ids = [$recipient_ids + $this->id];
|
||||
} elseif (0 == count($recipient_ids)) {
|
||||
$justSubmit = true;
|
||||
$recipient_ids = [$uploader_id];
|
||||
}
|
||||
|
||||
if (!is_array($recipient_ids) || 0 == count($recipient_ids)) {
|
||||
exit(get_lang('GeneralError').' (code 209)');
|
||||
}
|
||||
|
||||
foreach ($recipient_ids as $rec) {
|
||||
if (empty($rec)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//this check is done when validating submitted data
|
||||
$this->recipients[] = ['id' => $rec];
|
||||
}
|
||||
|
||||
$table_post = Database::get_course_table(TABLE_DROPBOX_POST);
|
||||
$table_person = Database::get_course_table(TABLE_DROPBOX_PERSON);
|
||||
$session_id = api_get_session_id();
|
||||
$user = api_get_user_id();
|
||||
$now = api_get_utc_datetime();
|
||||
$mailId = get_mail_id_base();
|
||||
|
||||
// Insert data in dropbox_post and dropbox_person table for each recipient
|
||||
foreach ($this->recipients as $rec) {
|
||||
$file_id = (int) $this->id;
|
||||
$user_id = (int) $rec['id'];
|
||||
$sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id)
|
||||
VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)";
|
||||
Database::query($sql);
|
||||
// If work already exists no error is generated
|
||||
|
||||
/*
|
||||
* Poster is already added when work is created - not so good to split logic.
|
||||
*/
|
||||
if ($user_id != $user) {
|
||||
// Insert entries into person table
|
||||
$sql = "INSERT INTO $table_person (c_id, file_id, user_id)
|
||||
VALUES ($course_id, $file_id, $user_id)";
|
||||
|
||||
// Do not add recipient in person table if mailing zip or just upload.
|
||||
if (!$justSubmit) {
|
||||
Database::query($sql); // If work already exists no error is generated
|
||||
}
|
||||
}
|
||||
|
||||
// Update item_property table for each recipient
|
||||
if (($ownerid = $this->uploader_id) > $mailId) {
|
||||
$ownerid = getUserOwningThisMailing($ownerid);
|
||||
}
|
||||
if (($recipid = $rec['id']) > $mailId) {
|
||||
$recipid = $ownerid; // mailing file recipient = mailing id, not a person
|
||||
}
|
||||
api_item_property_update(
|
||||
$_course,
|
||||
TOOL_DROPBOX,
|
||||
$this->id,
|
||||
'DropboxFileAdded',
|
||||
$ownerid,
|
||||
null,
|
||||
$recipid
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* private function creating existing object by retrieving info from db.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function createExistingSentWork($id)
|
||||
{
|
||||
$id = (int) $id;
|
||||
$course_id = api_get_course_int_id();
|
||||
|
||||
// Call constructor of Dropbox_Work object
|
||||
parent::__construct($id);
|
||||
|
||||
// Fill in recipients array
|
||||
$this->recipients = [];
|
||||
$sql = 'SELECT dest_user_id, feedback_date, feedback
|
||||
FROM '.Database::get_course_table(TABLE_DROPBOX_POST)."
|
||||
WHERE c_id = $course_id AND file_id = ".intval($id);
|
||||
$result = Database::query($sql);
|
||||
while ($res = Database::fetch_array($result, 'ASSOC')) {
|
||||
// Check for deleted users
|
||||
$dest_user_id = $res['dest_user_id'];
|
||||
$user_info = api_get_user_info($dest_user_id);
|
||||
if (!$user_info) {
|
||||
$this->recipients[] = ['id' => -1, 'name' => get_lang('Unknown', '')];
|
||||
} else {
|
||||
$this->recipients[] = [
|
||||
'id' => $dest_user_id,
|
||||
'name' => $user_info['complete_name'],
|
||||
'user_id' => $dest_user_id,
|
||||
'feedback_date' => $res['feedback_date'],
|
||||
'feedback' => $res['feedback'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Dropbox_Person
|
||||
{
|
||||
// The receivedWork and the sentWork arrays are sorted.
|
||||
public $receivedWork; // an array of Dropbox_Work objects
|
||||
public $sentWork; // an array of Dropbox_SentWork objects
|
||||
|
||||
public $userId = 0;
|
||||
public $isCourseAdmin = false;
|
||||
public $isCourseTutor = false;
|
||||
public $_orderBy = ''; // private property that determines by which field
|
||||
|
||||
/**
|
||||
* Constructor for recreating the Dropbox_Person object.
|
||||
*/
|
||||
public function __construct(
|
||||
int $userId,
|
||||
bool $isCourseAdmin,
|
||||
bool $isCourseTutor,
|
||||
int $courseId = 0,
|
||||
int $sessionId = 0
|
||||
) {
|
||||
if (empty($courseId)) {
|
||||
$courseId = api_get_course_int_id();
|
||||
}
|
||||
if (empty($sessionId)) {
|
||||
$sessionId = api_get_session_id();
|
||||
}
|
||||
|
||||
// Fill in properties
|
||||
$this->userId = $userId;
|
||||
$this->isCourseAdmin = $isCourseAdmin;
|
||||
$this->isCourseTutor = $isCourseTutor;
|
||||
$this->receivedWork = [];
|
||||
$this->sentWork = [];
|
||||
|
||||
// Note: perhaps include an ex course member check to delete old files
|
||||
|
||||
$condition_session = api_get_session_condition($sessionId);
|
||||
|
||||
$post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
|
||||
$person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
|
||||
$file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
|
||||
|
||||
// Find all entries where this person is the recipient
|
||||
$sql = "SELECT DISTINCT r.file_id, r.cat_id
|
||||
FROM $post_tbl r
|
||||
INNER JOIN $person_tbl p
|
||||
ON (r.file_id = p.file_id AND r.c_id = p.c_id)
|
||||
WHERE
|
||||
r.c_id = $courseId AND
|
||||
p.user_id = ".intval($this->userId).' AND
|
||||
r.dest_user_id = '.intval($this->userId)." $condition_session ";
|
||||
|
||||
$result = Database::query($sql);
|
||||
while ($res = Database::fetch_array($result)) {
|
||||
$temp = new Dropbox_Work($res['file_id']);
|
||||
$temp->category = $res['cat_id'];
|
||||
$this->receivedWork[] = $temp;
|
||||
}
|
||||
// Find all entries where this person is the sender/uploader
|
||||
$sql = "SELECT DISTINCT f.id
|
||||
FROM $file_tbl f
|
||||
INNER JOIN $person_tbl p
|
||||
ON (f.id = p.file_id AND f.c_id = p.c_id)
|
||||
WHERE
|
||||
f.c_id = $courseId AND
|
||||
f.uploader_id = ".intval($this->userId).' AND
|
||||
p.user_id = '.intval($this->userId)."
|
||||
$condition_session
|
||||
";
|
||||
$result = Database::query($sql);
|
||||
while ($res = Database::fetch_array($result)) {
|
||||
$this->sentWork[] = new Dropbox_SentWork($res['id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all the received categories and work of this person.
|
||||
*/
|
||||
public function deleteReceivedWorkFolder(int $id, int $courseId = 0, int $sessionId = 0): bool
|
||||
{
|
||||
if (empty($courseId)) {
|
||||
$courseId = api_get_course_int_id();
|
||||
}
|
||||
if (empty($sessionId)) {
|
||||
$sessionId = api_get_session_id();
|
||||
}
|
||||
|
||||
$condition_session = api_get_session_condition($sessionId);
|
||||
|
||||
$sql = 'DELETE FROM '.Database::get_course_table(TABLE_DROPBOX_FILE)."
|
||||
WHERE c_id = $courseId $condition_session AND cat_id = $id";
|
||||
Database::query($sql);
|
||||
|
||||
$sql = 'DELETE FROM '.Database::get_course_table(TABLE_DROPBOX_CATEGORY)."
|
||||
WHERE c_id = $courseId $condition_session AND cat_id = $id";
|
||||
Database::query($sql);
|
||||
|
||||
$sql = 'DELETE FROM '.Database::get_course_table(TABLE_DROPBOX_POST)."
|
||||
WHERE c_id = $courseId $condition_session AND cat_id = $id";
|
||||
Database::query($sql);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a received dropbox file of this person with id=$id.
|
||||
*/
|
||||
public function deleteReceivedWork(int $id, int $courseId = 0, int $sessionId = 0): void
|
||||
{
|
||||
if (empty($courseId)) {
|
||||
$courseId = api_get_course_int_id();
|
||||
}
|
||||
if (empty($sessionId)) {
|
||||
$sessionId = api_get_session_id();
|
||||
}
|
||||
|
||||
// index check
|
||||
$found = false;
|
||||
foreach ($this->receivedWork as $w) {
|
||||
if ($w->id == $id) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
if (!$this->deleteReceivedWorkFolder($id, $courseId, $sessionId)) {
|
||||
exit(get_lang('GeneralError').' (code 216)');
|
||||
}
|
||||
}
|
||||
// Delete entries in person table concerning received works
|
||||
$sql = 'DELETE FROM '.Database::get_course_table(TABLE_DROPBOX_PERSON)."
|
||||
WHERE c_id = $courseId AND user_id = ".$this->userId." AND file_id = $id";
|
||||
Database::query($sql);
|
||||
removeUnusedFiles(); // Check for unused files
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a sent dropbox file of this person with id=$id.
|
||||
*/
|
||||
public function deleteSentWork(int $id, int $courseId = 0, int $sessionId = 0): void
|
||||
{
|
||||
if (empty($courseId)) {
|
||||
$courseId = api_get_course_int_id();
|
||||
}
|
||||
if (empty($sessionId)) {
|
||||
$sessionId = api_get_session_id();
|
||||
}
|
||||
|
||||
// index check
|
||||
$found = false;
|
||||
foreach ($this->sentWork as $w) {
|
||||
if ($w->id == $id) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
if (!$this->deleteReceivedWorkFolder($id, $courseId, $sessionId)) {
|
||||
exit(get_lang('GeneralError').' (code 219)');
|
||||
}
|
||||
}
|
||||
//$file_id = $this->sentWork[$index]->id;
|
||||
// Delete entries in person table concerning sent works
|
||||
$sql = 'DELETE FROM '.Database::get_course_table(TABLE_DROPBOX_PERSON)."
|
||||
WHERE c_id = $courseId AND user_id = ".$this->userId." AND file_id = $id";
|
||||
Database::query($sql);
|
||||
removeMoreIfMailing($id);
|
||||
removeUnusedFiles(); // Check for unused files
|
||||
}
|
||||
}
|
||||
107
main/dropbox/dropbox_download.php
Normal file
107
main/dropbox/dropbox_download.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
|
||||
$_course = api_get_course_info();
|
||||
|
||||
// the dropbox file that contains additional functions
|
||||
require_once 'dropbox_functions.inc.php';
|
||||
|
||||
/* DOWNLOAD A FOLDER */
|
||||
$course_id = api_get_course_int_id();
|
||||
$user_id = api_get_user_id();
|
||||
|
||||
if (isset($_GET['cat_id']) &&
|
||||
is_numeric($_GET['cat_id']) &&
|
||||
$_GET['action'] == 'downloadcategory' &&
|
||||
isset($_GET['sent_received'])
|
||||
) {
|
||||
/** step 1: constructing the sql statement.
|
||||
Therefore we have to create to separate sql statements to find which files are in the category
|
||||
(depending if we zip-download a sent category or a received category)*/
|
||||
if ($_GET['sent_received'] == 'sent') {
|
||||
// here we also incorporate the person table to make sure that deleted sent documents are not included.
|
||||
$sql = "SELECT DISTINCT file.id, file.filename, file.title
|
||||
FROM ".Database::get_course_table(TABLE_DROPBOX_FILE)." file
|
||||
INNER JOIN ".Database::get_course_table(TABLE_DROPBOX_PERSON)." person
|
||||
ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
|
||||
WHERE
|
||||
file.uploader_id = $user_id AND
|
||||
file.cat_id='".intval($_GET['cat_id'])."' AND
|
||||
person.user_id = $user_id";
|
||||
}
|
||||
|
||||
if ($_GET['sent_received'] == 'received') {
|
||||
$sql = "SELECT DISTINCT file.id, file.filename, file.title
|
||||
FROM ".Database::get_course_table(TABLE_DROPBOX_FILE)." file
|
||||
INNER JOIN ".Database::get_course_table(TABLE_DROPBOX_PERSON)." person
|
||||
ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
|
||||
INNER JOIN ".Database::get_course_table(TABLE_DROPBOX_POST)." post
|
||||
ON (post.file_id = file.id AND post.c_id = $course_id AND file.c_id = $course_id)
|
||||
WHERE
|
||||
post.cat_id = ".intval($_GET['cat_id'])." AND
|
||||
post.dest_user_id = $user_id";
|
||||
}
|
||||
$files_to_download = [];
|
||||
$result = Database::query($sql);
|
||||
while ($row = Database::fetch_array($result)) {
|
||||
$files_to_download[] = $row['id'];
|
||||
}
|
||||
if (!is_array($files_to_download) || empty($files_to_download)) {
|
||||
header('Location: index.php?'.api_get_cidreq().'&view='.Security::remove_XSS($_GET['sent_received']).'&error=ErrorNoFilesInFolder');
|
||||
exit;
|
||||
}
|
||||
zip_download($files_to_download);
|
||||
exit;
|
||||
}
|
||||
/* DOWNLOAD A FILE */
|
||||
/* AUTHORIZATION */
|
||||
|
||||
// Check if the id makes sense
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
api_not_allowed(true);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check if the user is allowed to download the file
|
||||
$allowed_to_download = false;
|
||||
if (user_can_download_file($_GET['id'], api_get_user_id())) {
|
||||
$allowed_to_download = true;
|
||||
}
|
||||
|
||||
/* ERROR IF NOT ALLOWED TO DOWNLOAD */
|
||||
if (!$allowed_to_download) {
|
||||
api_not_allowed(
|
||||
true,
|
||||
Display::return_message(
|
||||
get_lang('YouAreNotAllowedToDownloadThisFile'),
|
||||
'error'
|
||||
)
|
||||
);
|
||||
exit;
|
||||
} else {
|
||||
/* DOWNLOAD THE FILE */
|
||||
// the user is allowed to download the file
|
||||
$_SESSION['_seen'][$_course['id']][TOOL_DROPBOX][] = intval($_GET['id']);
|
||||
|
||||
$work = new Dropbox_Work($_GET['id']);
|
||||
//path to file as stored on server
|
||||
$path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$work->filename;
|
||||
if (!Security::check_abs_path(
|
||||
$path,
|
||||
api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'
|
||||
)
|
||||
) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
$file = $work->title;
|
||||
$result = DocumentManager::file_send_for_download($path, true, $file);
|
||||
if ($result === false) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
//@todo clean this file the code below is useless there are 2 exits in previous conditions ... maybe a bad copy/paste/merge?
|
||||
exit;
|
||||
1735
main/dropbox/dropbox_functions.inc.php
Normal file
1735
main/dropbox/dropbox_functions.inc.php
Normal file
File diff suppressed because it is too large
Load Diff
368
main/dropbox/dropbox_init.inc.php
Normal file
368
main/dropbox/dropbox_init.inc.php
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use ChamiloSession as Session;
|
||||
|
||||
/**
|
||||
* @desc The dropbox is a personal (peer to peer) file exchange module that allows
|
||||
* you to send documents to a certain (group of) users.
|
||||
*
|
||||
* @version 1.3
|
||||
*
|
||||
* @author Jan Bols <jan@ivpv.UGent.be>, main programmer, initial version
|
||||
* @author René Haentjens <rene.haentjens@UGent.be>, several contributions
|
||||
* @author Roan Embrechts, virtual course support
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University (see history version 1.3)
|
||||
*
|
||||
* @todo complete refactoring. Currently there are about at least 3 sql queries needed for every individual dropbox document.
|
||||
* first we find all the documents that were sent (resp. received) by the user
|
||||
* then for every individual document the user(s)information who received (resp. sent) the document is searched
|
||||
* then for every individual document the feedback is retrieved
|
||||
* @todo
|
||||
* the implementation of the dropbox categories could (on the database level) have been done more elegantly by storing the category
|
||||
* in the dropbox_person table because this table stores the relationship between the files (sent OR received) and the users
|
||||
*/
|
||||
|
||||
/**
|
||||
HISTORY
|
||||
Version 1.1
|
||||
------------
|
||||
- dropbox_init1.inc.php: changed include statements to require statements.
|
||||
This way if a file is not found, it stops the execution of a script instead of continuing with warnings.
|
||||
- dropbox_init1.inc.php: the include files "claro_init_global.inc.php" & "debug.lib.inc.php" are first checked for
|
||||
their existence before including them. If they don't exist, in the .../include dir,
|
||||
they get loaded from the .../inc dir. This change is necessary because the UCL changed the include dir to inc.
|
||||
- dropbox_init1.inc.php: the databasetable name in the variable $dropbox_cnf["introTbl"]
|
||||
is changed from "introduction" to "tool_intro"
|
||||
- install.php: after submit, checks if the database uses accueil or tool_list as a tablename
|
||||
- index.php: removed the behaviour of only the teachers that are allowed to delete entries
|
||||
- index.php: added field "lastUploadDate" in table dropbox_file to store information
|
||||
about last update when resubmiting a file
|
||||
- dropbox.inc.php: added $lang["lastUpdated"]
|
||||
- index.php: entries in received list show when file was last updated if it is updated
|
||||
- index.php: entries in sent list show when file was last resent if it was resent
|
||||
- index.php: add POST-variable to the upload form with overwrite data when
|
||||
user decides to overwrite the previous sent file with new file
|
||||
- dropbox_submit.php: add sanity checks on POST['overwrite'] data
|
||||
- index.php: remove title field in upload form
|
||||
- dropbox_init1.inc.php: added $dropbox_cnf["version"] variable
|
||||
- dropbox_class.inc.php: add $this->lastUploadDate to Dropbox_work class
|
||||
- dropbox.inc.php: added $lang['emptyTable']
|
||||
- index.php: if the received or sent list is empty, a message is displayed
|
||||
- dropbox_download.php: the $file var is set equal to the title-field of the filetable.
|
||||
So not constructed anymore by substracting the username from the filename
|
||||
- index.php: add check to see if column lastUploadDate exists in filetable
|
||||
- index.php: moved javascripts from dropbox_init2.inc.php to index.php
|
||||
- index.php: when specifying an uploadfile in the form, a checkbox allowing the user to overwrite a
|
||||
previously sent file is shown when the specified file has the same name as a previously uploaded file of that user.
|
||||
- index.php: assign all the metadata (author, description, date, recipient, sender) of an
|
||||
entry in a list to the class="dropbox_detail" and add css to html-header
|
||||
- index.php: assign all dates of entries in list to the class="dropbox_date" and add CSS
|
||||
- index.php: assign all persons in entries of list to the class="dropbox_person" and add CSS
|
||||
- dropbox.inc.php: added $lang['dropbox_version'] to indicate the lates version.
|
||||
This must be equal to the $dropbox_cnf['version'] variable.
|
||||
- dropbox_init1.inc.php: if the newest lang file isn't loaded by claro_init_global.inc.php
|
||||
from the .../lang dir it will be loaded locally from the .../plugin/dropbox/ dir.
|
||||
This way an administrator must not install the dropbox.inc.php in the .../lang/english dir,
|
||||
but he can leave it in the local .../plugin/dropbox/ dir.
|
||||
However if you want to present multiple language translations of the file you must still
|
||||
put the file in the /lang/ dir, because there is no language management system inside the .../plugin/dropbox dir.
|
||||
- mime.inc.php: created this file. It contains an array $mimetype with all the mimetypes
|
||||
that are used by dropbox_download.php to give hinst to the browser during download about content
|
||||
- dropbox_download.php: remove https specific headers because they're not necessary
|
||||
- dropbox_download.php: use application/octet-stream as the default mime and inline as the default Content-Disposition
|
||||
- dropbox.inc.php: add lang vars for "order by" action
|
||||
- dropbox_class.inc.php: add methods orderSentWork, orderReceivedWork en _cmpWork and
|
||||
propery _orderBy to class Dropbox_person to take care of sorting
|
||||
- index.php: add selectionlist to headers of sent/received lists to select "order by"
|
||||
and add code to keep selected value in sessionvar.
|
||||
- index.php: moved part of a <a> hyperlink to previous line to remove the underlined space between
|
||||
symbol and title of a work entry in the sent/received list
|
||||
- index.php: add filesize info in sent/received lists
|
||||
- dropbox_submit.php: resubmit prevention only for GET action, because it gives some annoying behaviour in POST
|
||||
* situation: white screen in IE6.
|
||||
- removed all self-built database tables names
|
||||
*/
|
||||
|
||||
/**
|
||||
* First initialisation file with initialisation of variables and
|
||||
* without outputting anything to browser.
|
||||
* 1. Calls global.inc.php and lang file
|
||||
* 2. Initialises $dropbox_cnf array with all relevant vars
|
||||
* 3. Often used functions.
|
||||
*
|
||||
* @version 1.31
|
||||
*
|
||||
* @copyright 2004-2005
|
||||
* @author Jan Bols <jan@ivpv.UGent.be>, main programmer
|
||||
* @author René Haentjens, severalcontributions <rene.haentjens@UGent.be>
|
||||
* @author Roan Embrechts, virtual course support
|
||||
* @author Patrick Cool <patrick.cool@UGent.be>
|
||||
* Chamilo Config Settings (AWACS)
|
||||
* Refactoring
|
||||
* tool introduction
|
||||
* folders
|
||||
* download file / folder (download icon)
|
||||
* same action on multiple documents
|
||||
* extended feedback
|
||||
*/
|
||||
require_once __DIR__.'/../inc/global.inc.php';
|
||||
$is_allowed_in_course = api_is_allowed_in_course();
|
||||
$is_courseTutor = api_is_course_tutor();
|
||||
$is_courseAdmin = api_is_course_admin();
|
||||
|
||||
$current_course_tool = TOOL_DROPBOX;
|
||||
|
||||
// the dropbox file that contains additional functions
|
||||
require_once 'dropbox_functions.inc.php';
|
||||
|
||||
// protecting the script
|
||||
api_protect_course_script();
|
||||
|
||||
$user_id = api_get_user_id();
|
||||
$course_code = api_get_course_id();
|
||||
$course_info = api_get_course_info($course_code);
|
||||
$session_id = api_get_session_id();
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||
$view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
|
||||
$postAction = isset($_POST['action']) ? $_POST['action'] : null;
|
||||
|
||||
if (api_is_excluded_user_type()) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (empty($session_id)) {
|
||||
$is_course_member = CourseManager::is_user_subscribed_in_course(
|
||||
$user_id,
|
||||
$course_code,
|
||||
false
|
||||
);
|
||||
} else {
|
||||
$is_course_member = CourseManager::is_user_subscribed_in_course(
|
||||
$user_id,
|
||||
$course_code,
|
||||
true,
|
||||
$session_id
|
||||
);
|
||||
}
|
||||
|
||||
// we need this here because the javascript to re-upload the file needs an array
|
||||
// off all the documents that have already been sent.
|
||||
// @todo consider moving the javascripts in a function that displays the javascripts
|
||||
// only when it is needed.
|
||||
if ('add' == $action) {
|
||||
$dropbox_person = new Dropbox_Person(
|
||||
$user_id,
|
||||
$is_courseAdmin,
|
||||
$is_courseTutor
|
||||
);
|
||||
}
|
||||
|
||||
/* Create javascript and htmlHeaders */
|
||||
$javascript = "<script>
|
||||
function confirmsend()
|
||||
{
|
||||
if (confirm(\"".get_lang('MailingConfirmSend', '')."\")){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function confirmation (name)
|
||||
{
|
||||
if (confirm(\"".get_lang('ConfirmDelete', '')." : \"+ name )){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkForm (frm)
|
||||
{
|
||||
if (frm.elements['recipients[]'].selectedIndex < 0){
|
||||
alert(\"".get_lang('NoUserSelected', '')."\");
|
||||
return false;
|
||||
} else if (frm.file.value == '') {
|
||||
alert(\"".get_lang('NoFileSpecified', '')."\");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
$allowOverwrite = api_get_setting('dropbox_allow_overwrite');
|
||||
if ($allowOverwrite == 'true') {
|
||||
//sentArray keeps list of all files still available in the sent files list
|
||||
//of the user.
|
||||
//This is used to show or hide the overwrite file-radio button of the upload form
|
||||
$javascript .= " var sentArray = new Array(";
|
||||
if (isset($dropbox_person)) {
|
||||
for ($i = 0; $i < count($dropbox_person->sentWork); $i++) {
|
||||
if ($i > 0) {
|
||||
$javascript .= ", ";
|
||||
}
|
||||
$javascript .= "'".$dropbox_person->sentWork[$i]->title."'";
|
||||
}
|
||||
}
|
||||
$javascript .= ");
|
||||
|
||||
function checkfile(str)
|
||||
{
|
||||
ind = str.lastIndexOf('/'); //unix separator
|
||||
if (ind == -1) ind = str.lastIndexOf('\\\'); //windows separator
|
||||
filename = str.substring(ind+1, str.length);
|
||||
|
||||
found = 0;
|
||||
for (i=0; i<sentArray.length; i++) {
|
||||
if (sentArray[i] == filename) found=1;
|
||||
}
|
||||
|
||||
//always start with unchecked box
|
||||
el = getElement('cb_overwrite');
|
||||
el.checked = false;
|
||||
|
||||
//show/hide checkbox
|
||||
if (found == 1) {
|
||||
displayEl('overwrite');
|
||||
} else {
|
||||
undisplayEl('overwrite');
|
||||
}
|
||||
}
|
||||
|
||||
function getElement(id)
|
||||
{
|
||||
return document.getElementById ? document.getElementById(id) :
|
||||
document.all ? document.all(id) : null;
|
||||
}
|
||||
|
||||
function displayEl(id)
|
||||
{
|
||||
var el = getElement(id);
|
||||
if (el && el.style) el.style.display = '';
|
||||
}
|
||||
|
||||
function undisplayEl(id)
|
||||
{
|
||||
var el = getElement(id);
|
||||
if (el && el.style) el.style.display = 'none';
|
||||
}";
|
||||
}
|
||||
|
||||
$javascript .= "
|
||||
</script>";
|
||||
$htmlHeadXtra[] = $javascript;
|
||||
$htmlHeadXtra[] = "<script>
|
||||
function confirmation (name)
|
||||
{
|
||||
if (confirm(\" ".get_lang("AreYouSureToDeleteJS")." \"+ name + \" ?\"))
|
||||
{return true;}
|
||||
else
|
||||
{return false;}
|
||||
}
|
||||
</script>";
|
||||
|
||||
Session::write('javascript', $javascript);
|
||||
|
||||
$htmlHeadXtra[] = '<meta http-equiv="cache-control" content="no-cache">
|
||||
<meta http-equiv="pragma" content="no-cache">
|
||||
<meta http-equiv="expires" content="-1">';
|
||||
$htmlHeadXtra[] = api_get_jquery_libraries_js(['jquery-ui', 'jquery-upload']);
|
||||
$htmlHeadXtra[] = "<script>
|
||||
$(function () {
|
||||
$('#recipient_form').on('change', function() {
|
||||
$('#multiple_form').show();
|
||||
});
|
||||
});
|
||||
</script>";
|
||||
$checked_files = false;
|
||||
if (!$view || $view == 'received') {
|
||||
$part = 'received';
|
||||
} elseif ($view == 'sent') {
|
||||
$part = 'sent';
|
||||
} else {
|
||||
header('location: index.php?'.api_get_cidreq().'&view=received&error=Error');
|
||||
exit;
|
||||
}
|
||||
|
||||
if (($postAction == 'download_received' || $postAction == 'download_sent') and !$_POST['store_feedback']) {
|
||||
$checked_file_ids = $_POST['id'];
|
||||
if (!is_array($checked_file_ids) || count($checked_file_ids) == 0) {
|
||||
header('Location: index.php?'.api_get_cidreq().'&view='.$view.'&error=CheckAtLeastOneFile');
|
||||
} else {
|
||||
handle_multiple_actions();
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* AUTHORISATION SECTION
|
||||
* Prevents access of all users that are not course members
|
||||
*/
|
||||
if ((!$is_allowed_in_course || !$is_course_member) &&
|
||||
!api_is_allowed_to_edit(null, true)
|
||||
) {
|
||||
if ($origin != 'learnpath') {
|
||||
api_not_allowed(true); //print headers/footers
|
||||
} else {
|
||||
api_not_allowed();
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
/* BREADCRUMBS */
|
||||
if ($view == 'received') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('Dropbox', ''),
|
||||
];
|
||||
$nameTools = get_lang('ReceivedFiles');
|
||||
|
||||
if ($action == 'addreceivedcategory') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?view=received&'.api_get_cidreq(),
|
||||
'name' => get_lang('ReceivedFiles'),
|
||||
];
|
||||
$nameTools = get_lang('AddNewCategory');
|
||||
}
|
||||
}
|
||||
|
||||
if ($view == 'sent' || empty($view)) {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq(),
|
||||
'name' => get_lang('Dropbox'),
|
||||
];
|
||||
$nameTools = get_lang('SentFiles');
|
||||
|
||||
if ($action == 'addsentcategory') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?view=sent&'.api_get_cidreq(),
|
||||
'name' => get_lang('SentFiles'),
|
||||
];
|
||||
$nameTools = get_lang('AddNewCategory');
|
||||
}
|
||||
if ($action == 'add') {
|
||||
$nameTools = get_lang('UploadNewFile');
|
||||
}
|
||||
|
||||
if ($action == 'update') {
|
||||
$interbreadcrumb[] = [
|
||||
'url' => api_get_path(WEB_CODE_PATH).'dropbox/index.php?view=sent&'.api_get_cidreq(),
|
||||
'name' => get_lang('SentFiles'),
|
||||
];
|
||||
$nameTools = get_lang('UpdateFile');
|
||||
}
|
||||
}
|
||||
|
||||
/* HEADER & TITLE */
|
||||
if (isset($origin) && $origin == 'learnpath') {
|
||||
$htmlHeadXtra[] = $javascript;
|
||||
Display::display_reduced_header($nameTools, 'Dropbox');
|
||||
} else {
|
||||
Display::display_header($nameTools, 'Dropbox');
|
||||
}
|
||||
732
main/dropbox/index.php
Normal file
732
main/dropbox/index.php
Normal file
@@ -0,0 +1,732 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
// The file that contains all the initialisation stuff (and includes all the configuration stuff)
|
||||
require_once 'dropbox_init.inc.php';
|
||||
|
||||
$_course = api_get_course_info();
|
||||
|
||||
$last_access = '';
|
||||
// get the last time the user accessed the tool
|
||||
if (isset($_SESSION[$_course['id']]) &&
|
||||
$_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] == ''
|
||||
) {
|
||||
$last_access = get_last_tool_access(TOOL_DROPBOX);
|
||||
$_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access;
|
||||
} else {
|
||||
if (isset($_SESSION[$_course['id']])) {
|
||||
$last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX];
|
||||
}
|
||||
}
|
||||
|
||||
$postAction = isset($_POST['action']) ? $_POST['action'] : null;
|
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
|
||||
$view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
|
||||
$viewReceivedCategory = isset($_GET['view_received_category']) ? Security::remove_XSS($_GET['view_received_category']) : null;
|
||||
$viewSentCategory = isset($_GET['view_sent_category']) ? Security::remove_XSS($_GET['view_sent_category']) : null;
|
||||
$showSentReceivedTabs = true;
|
||||
|
||||
// Do the tracking
|
||||
Event::event_access_tool(TOOL_DROPBOX);
|
||||
|
||||
$logInfo = [
|
||||
'tool' => TOOL_DROPBOX,
|
||||
'tool_id' => 0,
|
||||
'tool_id_detail' => 0,
|
||||
'action' => $action,
|
||||
];
|
||||
Event::registerLog($logInfo);
|
||||
|
||||
/* DISPLAY SECTION */
|
||||
Display::display_introduction_section(TOOL_DROPBOX);
|
||||
|
||||
// Build URL-parameters for table-sorting
|
||||
$sort_params = [];
|
||||
if (isset($_GET['dropbox_column'])) {
|
||||
$sort_params[] = 'dropbox_column='.intval($_GET['dropbox_column']);
|
||||
}
|
||||
if (isset($_GET['dropbox_page_nr'])) {
|
||||
$sort_params[] = 'page_nr='.intval($_GET['dropbox_page_nr']);
|
||||
}
|
||||
if (isset($_GET['dropbox_per_page'])) {
|
||||
$sort_params[] = 'dropbox_per_page='.intval($_GET['dropbox_per_page']);
|
||||
}
|
||||
if (isset($_GET['dropbox_direction']) && in_array($_GET['dropbox_direction'], ['ASC', 'DESC'])) {
|
||||
$sort_params[] = 'dropbox_direction='.$_GET['dropbox_direction'];
|
||||
}
|
||||
|
||||
$sort_params = Security::remove_XSS(implode('&', $sort_params));
|
||||
|
||||
// Display the form for adding a new dropbox item.
|
||||
if (in_array($action, ['add', 'send_other_users'])) {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$dropboxId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
display_add_form(
|
||||
$viewReceivedCategory,
|
||||
$viewSentCategory,
|
||||
$view,
|
||||
$dropboxId,
|
||||
$action
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($_POST['submitWork'])) {
|
||||
$check = Security::check_token();
|
||||
if ($check) {
|
||||
store_add_dropbox();
|
||||
|
||||
echo Display::getFlashToString();
|
||||
}
|
||||
}
|
||||
|
||||
// Display the form for adding a category
|
||||
if ($action == 'addreceivedcategory' || $action == 'addsentcategory') {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : '';
|
||||
display_addcategory_form($categoryName, '', $_GET['action']);
|
||||
}
|
||||
|
||||
// Editing a category: displaying the form
|
||||
if ($action == 'editcategory' && isset($_GET['id'])) {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
if (!$_POST) {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
display_addcategory_form('', $_GET['id'], 'editcategory');
|
||||
}
|
||||
}
|
||||
|
||||
// Storing a new or edited category
|
||||
if (isset($_POST['StoreCategory'])) {
|
||||
if (api_get_session_id() != 0 &&
|
||||
!api_is_allowed_to_session_edit(false, true)
|
||||
) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$return_information = store_addcategory();
|
||||
if ($return_information['type'] == 'confirmation') {
|
||||
echo Display::return_message($return_information['message'], 'confirmation');
|
||||
}
|
||||
if ($return_information['type'] == 'error') {
|
||||
echo Display::return_message(
|
||||
get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message'],
|
||||
'error'
|
||||
);
|
||||
display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction);
|
||||
}
|
||||
}
|
||||
|
||||
// Move a File
|
||||
if (($action == 'movesent' || $action == 'movereceived') && isset($_GET['move_id'])) {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
display_move_form(
|
||||
str_replace('move', '', $action),
|
||||
$_GET['move_id'],
|
||||
get_dropbox_categories(str_replace('move', '', $action)),
|
||||
$sort_params,
|
||||
$viewReceivedCategory,
|
||||
$viewSentCategory,
|
||||
$view
|
||||
);
|
||||
}
|
||||
if (isset($_POST['do_move'])) {
|
||||
$result = store_move(
|
||||
$_POST['id'],
|
||||
$_POST['move_target'],
|
||||
$_POST['part']
|
||||
);
|
||||
echo Display::return_message(
|
||||
$result,
|
||||
'confirm'
|
||||
);
|
||||
}
|
||||
|
||||
// Delete a file
|
||||
if (($action == 'deletereceivedfile' || $action == 'deletesentfile') && isset($_GET['id']) && is_numeric($_GET['id'])) {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$dropboxfile = new Dropbox_Person(
|
||||
api_get_user_id(),
|
||||
$is_courseAdmin,
|
||||
$is_courseTutor
|
||||
);
|
||||
if ($action == 'deletereceivedfile') {
|
||||
$dropboxfile->deleteReceivedWork($_GET['id']);
|
||||
$message = get_lang('ReceivedFileDeleted');
|
||||
}
|
||||
if ($action == 'deletesentfile') {
|
||||
$dropboxfile->deleteSentWork($_GET['id']);
|
||||
$message = get_lang('SentFileDeleted');
|
||||
}
|
||||
echo Display::return_message($message, 'confirmation');
|
||||
}
|
||||
|
||||
// Delete a category
|
||||
if (($action == 'deletereceivedcategory' || $action == 'deletesentcategory') &&
|
||||
isset($_GET['id']) && is_numeric($_GET['id'])
|
||||
) {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$message = delete_category($action, $_GET['id']);
|
||||
echo Display::return_message($message, 'confirmation');
|
||||
}
|
||||
|
||||
// Do an action on multiple files
|
||||
// only the download has is handled separately in
|
||||
// dropbox_init_inc.php because this has to be done before the headers are sent
|
||||
// (which also happens in dropbox_init.inc.php
|
||||
if (!isset($_POST['feedback']) && (
|
||||
strstr($postAction, 'move_received') ||
|
||||
strstr($postAction, 'move_sent') ||
|
||||
$postAction == 'delete_received' ||
|
||||
$postAction == 'download_received' ||
|
||||
$postAction == 'delete_sent' ||
|
||||
$postAction == 'download_sent'
|
||||
)
|
||||
) {
|
||||
$display_message = handle_multiple_actions();
|
||||
echo Display::return_message($display_message, 'normal');
|
||||
}
|
||||
|
||||
// Store Feedback
|
||||
if (isset($_POST['feedback'])) {
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
$check = Security::check_token();
|
||||
if ($check) {
|
||||
$display_message = store_feedback();
|
||||
echo Display::return_message($display_message, 'normal');
|
||||
Security::check_token();
|
||||
}
|
||||
}
|
||||
|
||||
// Error Message
|
||||
if (isset($_GET['error']) && !empty($_GET['error'])) {
|
||||
echo Display::return_message(get_lang($_GET['error']), 'normal');
|
||||
}
|
||||
|
||||
$dropbox_data_sent = [];
|
||||
$movelist = [];
|
||||
$dropbox_data_recieved = [];
|
||||
|
||||
if (!in_array($action, ['add', 'send_other_users'])) {
|
||||
// Getting all the categories in the dropbox for the given user
|
||||
$dropbox_categories = get_dropbox_categories();
|
||||
// Greating the arrays with the categories for the received files and for the sent files
|
||||
foreach ($dropbox_categories as $category) {
|
||||
if ($category['received'] == '1') {
|
||||
$dropbox_received_category[] = $category;
|
||||
}
|
||||
if ($category['sent'] == '1') {
|
||||
$dropbox_sent_category[] = $category;
|
||||
}
|
||||
}
|
||||
|
||||
// ACTIONS
|
||||
if ($view == 'received' || !$showSentReceivedTabs) {
|
||||
// This is for the categories
|
||||
if (isset($viewReceivedCategory) && $viewReceivedCategory != '') {
|
||||
$view_dropbox_category_received = $viewReceivedCategory;
|
||||
} else {
|
||||
$view_dropbox_category_received = 0;
|
||||
}
|
||||
/* Menu Received */
|
||||
|
||||
if (api_get_session_id() == 0) {
|
||||
echo '<div class="actions">';
|
||||
if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
|
||||
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.
|
||||
Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'), '', ICON_SIZE_MEDIUM).
|
||||
"</a>";
|
||||
echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
|
||||
$movelist[0] = 'Root'; // move_received selectbox content
|
||||
} else {
|
||||
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.
|
||||
Display::return_icon('new_folder.png', get_lang('AddNewCategory'), '', ICON_SIZE_MEDIUM).'</a>';
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
if (api_is_allowed_to_session_edit(false, true)) {
|
||||
echo '<div class="actions">';
|
||||
if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) {
|
||||
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.
|
||||
Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'), '', ICON_SIZE_MEDIUM)."</a>";
|
||||
echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> ';
|
||||
$movelist[0] = 'Root'; // move_received selectbox content
|
||||
} else {
|
||||
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.
|
||||
Display::return_icon('new_folder.png', get_lang('AddNewCategory'), '', ICON_SIZE_MEDIUM).
|
||||
'</a>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
echo Display::return_message(get_lang('DropboxVulnerabilityWarning'), 'w', false);
|
||||
}
|
||||
|
||||
if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
|
||||
// This is for the categories
|
||||
if (isset($viewSentCategory) && $viewSentCategory != '') {
|
||||
$view_dropbox_category_sent = $viewSentCategory;
|
||||
} else {
|
||||
$view_dropbox_category_sent = 0;
|
||||
}
|
||||
|
||||
/* Menu Sent */
|
||||
if (api_get_session_id() == 0) {
|
||||
echo '<div class="actions">';
|
||||
if (empty($viewSentCategory)) {
|
||||
echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".
|
||||
Display::return_icon('upload_file.png', get_lang('UploadNewFile'), '', ICON_SIZE_MEDIUM).
|
||||
"</a>";
|
||||
}
|
||||
if ($view_dropbox_category_sent != 0) {
|
||||
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.
|
||||
Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'), '', ICON_SIZE_MEDIUM).
|
||||
"</a>";
|
||||
echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
|
||||
} else {
|
||||
echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".
|
||||
Display::return_icon('new_folder.png', get_lang('AddNewCategory'), '', ICON_SIZE_MEDIUM)."</a>\n";
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
if (api_is_allowed_to_session_edit(false, true)) {
|
||||
echo '<div class="actions">';
|
||||
if (empty($viewSentCategory)) {
|
||||
echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".
|
||||
Display::return_icon('upload_file.png', get_lang('UploadNewFile'), '', ICON_SIZE_MEDIUM).
|
||||
"</a>";
|
||||
}
|
||||
if ($view_dropbox_category_sent != 0) {
|
||||
echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> ';
|
||||
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.
|
||||
Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'), '', ICON_SIZE_MEDIUM).
|
||||
"</a>";
|
||||
} else {
|
||||
echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".
|
||||
Display::return_icon('new_folder.png', get_lang('AddNewCategory'), '', ICON_SIZE_MEDIUM)."</a>\n";
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
/* THE MENU TABS */
|
||||
if ($showSentReceivedTabs) {
|
||||
?>
|
||||
<ul class="nav nav-tabs">
|
||||
<li <?php if (!$view || $view == 'sent') {
|
||||
echo 'class="active"';
|
||||
} ?> >
|
||||
<a href="<?php echo api_get_path(WEB_CODE_PATH).'dropbox/'; ?>index.php?<?php echo api_get_cidreq(); ?>&view=sent" >
|
||||
<?php echo get_lang('SentFiles'); ?>
|
||||
</a>
|
||||
</li>
|
||||
<li <?php if ($view == 'received') {
|
||||
echo 'class="active"';
|
||||
} ?> >
|
||||
<a href="<?php echo api_get_path(WEB_CODE_PATH).'dropbox/'; ?>index.php?<?php echo api_get_cidreq(); ?>&view=received" >
|
||||
<?php echo get_lang('ReceivedFiles'); ?></a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
/* RECEIVED FILES */
|
||||
if ($view == 'received' || !$showSentReceivedTabs) {
|
||||
// This is for the categories
|
||||
if (isset($viewReceivedCategory) && $viewReceivedCategory != '') {
|
||||
$view_dropbox_category_received = $viewReceivedCategory;
|
||||
} else {
|
||||
$view_dropbox_category_received = 0;
|
||||
}
|
||||
|
||||
// Object initialisation
|
||||
$dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
|
||||
// note: are the $is_courseAdmin and $is_courseTutor parameters needed????
|
||||
|
||||
// Constructing the array that contains the total number of feedback messages per document.
|
||||
$number_feedback = get_total_number_feedback();
|
||||
|
||||
// Sorting and paging options
|
||||
$sorting_options = [];
|
||||
$paging_options = [];
|
||||
|
||||
// The headers of the sortable tables
|
||||
$column_header = [];
|
||||
$column_header[] = ['', false, ''];
|
||||
$column_header[] = [get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'];
|
||||
$column_header[] = [get_lang('ReceivedTitle'), true, ''];
|
||||
$column_header[] = [get_lang('Size'), true, ''];
|
||||
$column_header[] = [get_lang('Authors'), true, ''];
|
||||
$column_header[] = [get_lang('LastResent'), true];
|
||||
|
||||
if (api_get_session_id() == 0) {
|
||||
$column_header[] = [get_lang('Modify'), false, '', 'nowrap style="text-align: right"'];
|
||||
} elseif (api_is_allowed_to_session_edit(false, true)) {
|
||||
$column_header[] = [get_lang('Modify'), false, '', 'nowrap style="text-align: right"'];
|
||||
}
|
||||
|
||||
$column_header[] = ['RealDate', true];
|
||||
$column_header[] = ['RealSize', true];
|
||||
|
||||
// An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
|
||||
if (api_get_session_id() == 0) {
|
||||
$column_show[] = 1;
|
||||
} elseif (api_is_allowed_to_session_edit(false, true)) {
|
||||
$column_show[] = 1;
|
||||
}
|
||||
$column_show[] = 0;
|
||||
|
||||
// Here we change the way how the columns are going to be sort
|
||||
// in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
|
||||
// because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
|
||||
$column_order[3] = 8;
|
||||
$column_order[5] = 7;
|
||||
// The content of the sortable table = the received files
|
||||
foreach ($dropbox_person->receivedWork as $dropbox_file) {
|
||||
$dropbox_file_data = [];
|
||||
if ($view_dropbox_category_received == $dropbox_file->category) {
|
||||
// we only display the files that are in the category that we are in.
|
||||
$dropbox_file_data[] = $dropbox_file->id;
|
||||
|
||||
if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) {
|
||||
$_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = [];
|
||||
}
|
||||
|
||||
// New icon
|
||||
$new_icon = '';
|
||||
if (isset($_SESSION['_seen'])) {
|
||||
if ($dropbox_file->last_upload_date > $last_access &&
|
||||
!in_array(
|
||||
$dropbox_file->id,
|
||||
$_SESSION['_seen'][$_course['id']][TOOL_DROPBOX]
|
||||
)
|
||||
) {
|
||||
$new_icon = ' '.Display::return_icon(
|
||||
'new_dropbox_message.png',
|
||||
get_lang('New'),
|
||||
'',
|
||||
ICON_SIZE_SMALL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
|
||||
$dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
|
||||
$dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
|
||||
Display::return_icon('save.png', get_lang('Download'), ['style' => 'float:right;'], ICON_SIZE_SMALL).
|
||||
'</a>'.$link_open.$dropbox_file->title.'</a>'.$new_icon.'<br />'.$dropbox_file->description;
|
||||
$file_size = $dropbox_file->filesize;
|
||||
$dropbox_file_data[] = format_file_size($file_size);
|
||||
$authorInfo = api_get_user_info($dropbox_file->uploader_id);
|
||||
if ($authorInfo) {
|
||||
$dropbox_file_data[] = $authorInfo['complete_name'];
|
||||
} else {
|
||||
$dropbox_file_data[] = '';
|
||||
}
|
||||
|
||||
$lastUploadDate = Display::dateToStringAgoAndLongDate($dropbox_file->last_upload_date);
|
||||
$dropbox_file_data[] = $lastUploadDate;
|
||||
|
||||
$action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.
|
||||
Display::return_icon('discuss.png', get_lang('Comment'), '', ICON_SIZE_SMALL).'</a>
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movereceived&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.
|
||||
Display::return_icon('move.png', get_lang('Move'), '', ICON_SIZE_SMALL).'</a>
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
|
||||
'</a>';
|
||||
|
||||
// This is a hack to have an additional row in a sortable table
|
||||
if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
|
||||
$action_icons .= "</td></tr>"; // Ending the normal row of the sortable table
|
||||
$url = api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params;
|
||||
$action_icons .= "
|
||||
<tr>
|
||||
<td colspan=\"9\">".
|
||||
feedback($dropbox_file->feedback2, $url).
|
||||
"</td></tr>";
|
||||
}
|
||||
if (api_get_session_id() == 0) {
|
||||
$dropbox_file_data[] = $action_icons;
|
||||
} elseif (api_is_allowed_to_session_edit(false, true)) {
|
||||
$dropbox_file_data[] = $action_icons;
|
||||
}
|
||||
$action_icons = '';
|
||||
$dropbox_file_data[] = $lastUploadDate;
|
||||
$dropbox_file_data[] = $file_size;
|
||||
$dropbox_data_recieved[] = $dropbox_file_data;
|
||||
}
|
||||
}
|
||||
|
||||
// The content of the sortable table = the categories (if we are not in the root)
|
||||
if ($view_dropbox_category_received == 0) {
|
||||
foreach ($dropbox_categories as $category) {
|
||||
/* Note: This can probably be shortened since the categories
|
||||
for the received files are already in the
|
||||
$dropbox_received_category array;*/
|
||||
$dropbox_category_data = [];
|
||||
if ($category['received'] == '1') {
|
||||
$movelist[$category['cat_id']] = $category['cat_name'];
|
||||
// This is where the checkbox icon for the files appear
|
||||
$dropbox_category_data[] = $category['cat_id'];
|
||||
// The icon of the category
|
||||
$link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">';
|
||||
$dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>';
|
||||
$dropbox_category_data[] =
|
||||
'<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.
|
||||
Display::return_icon('save_pack.png', get_lang('Save'), ['style' => 'float:right;'], ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>';
|
||||
$dropbox_category_data[] = '';
|
||||
$dropbox_category_data[] = '';
|
||||
$dropbox_category_data[] = '';
|
||||
$dropbox_category_data[] =
|
||||
'<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
|
||||
}
|
||||
if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
|
||||
$dropbox_data_recieved[] = $dropbox_category_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Displaying the table
|
||||
$additional_get_parameters = [
|
||||
'view' => $view,
|
||||
'view_received_category' => $viewReceivedCategory,
|
||||
'view_sent_category' => $viewSentCategory,
|
||||
];
|
||||
$selectlist = [
|
||||
'delete_received' => get_lang('Delete'),
|
||||
'download_received' => get_lang('Download'),
|
||||
];
|
||||
|
||||
if (is_array($movelist)) {
|
||||
foreach ($movelist as $catid => $catname) {
|
||||
$selectlist['move_received_'.$catid] = get_lang('Move').'->'.Security::remove_XSS($catname);
|
||||
}
|
||||
}
|
||||
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
$selectlist = [];
|
||||
}
|
||||
echo '<div class="files-table">';
|
||||
Display::display_sortable_config_table(
|
||||
'dropbox',
|
||||
$column_header,
|
||||
$dropbox_data_recieved,
|
||||
$sorting_options,
|
||||
$paging_options,
|
||||
$additional_get_parameters,
|
||||
$column_show,
|
||||
$column_order,
|
||||
$selectlist
|
||||
);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/* SENT FILES */
|
||||
if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
|
||||
// This is for the categories
|
||||
if (isset($viewSentCategory) && $viewSentCategory != '') {
|
||||
$view_dropbox_category_sent = $viewSentCategory;
|
||||
} else {
|
||||
$view_dropbox_category_sent = 0;
|
||||
}
|
||||
|
||||
// Object initialisation
|
||||
$dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
|
||||
// Constructing the array that contains the total number of feedback messages per document.
|
||||
$number_feedback = get_total_number_feedback();
|
||||
// Sorting and paging options
|
||||
$sorting_options = [];
|
||||
$paging_options = [];
|
||||
// The headers of the sortable tables
|
||||
$column_header = [];
|
||||
$column_header[] = ['', false, ''];
|
||||
$column_header[] = [get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'];
|
||||
$column_header[] = [get_lang('SentTitle'), true, ''];
|
||||
$column_header[] = [get_lang('Size'), true, ''];
|
||||
$column_header[] = [get_lang('SentTo'), true, ''];
|
||||
$column_header[] = [get_lang('LastResent'), true, ''];
|
||||
|
||||
if (api_get_session_id() == 0) {
|
||||
$column_header[] = [get_lang('Modify'), false, '', 'nowrap style="text-align: right"'];
|
||||
} elseif (api_is_allowed_to_session_edit(false, true)) {
|
||||
$column_header[] = [get_lang('Modify'), false, '', 'nowrap style="text-align: right"'];
|
||||
}
|
||||
|
||||
$column_header[] = ['RealDate', true];
|
||||
$column_header[] = ['RealSize', true];
|
||||
|
||||
$column_show = [];
|
||||
$column_order = [];
|
||||
|
||||
// An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
$column_show[] = 1;
|
||||
if (api_get_session_id() == 0) {
|
||||
$column_show[] = 1;
|
||||
} elseif (api_is_allowed_to_session_edit(false, true)) {
|
||||
$column_show[] = 1;
|
||||
}
|
||||
$column_show[] = 0;
|
||||
|
||||
// Here we change the way how the colums are going to be sort
|
||||
// in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate
|
||||
// because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48"
|
||||
$column_order[3] = 8;
|
||||
$column_order[5] = 7;
|
||||
// The content of the sortable table = the received files
|
||||
foreach ($dropbox_person->sentWork as $dropbox_file) {
|
||||
$dropbox_file_data = [];
|
||||
if ($view_dropbox_category_sent == $dropbox_file->category) {
|
||||
$dropbox_file_data[] = $dropbox_file->id;
|
||||
$link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">';
|
||||
$dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>';
|
||||
$dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'.
|
||||
Display::return_icon('save.png', get_lang('Save'), ['style' => 'float:right;'], ICON_SIZE_SMALL).
|
||||
'</a>'.
|
||||
$link_open.
|
||||
$dropbox_file->title.
|
||||
'</a><br />'.$dropbox_file->description;
|
||||
$file_size = $dropbox_file->filesize;
|
||||
$dropbox_file_data[] = format_file_size($file_size);
|
||||
$receivers_celldata = '';
|
||||
foreach ($dropbox_file->recipients as $recipient) {
|
||||
if (isset($recipient['user_id'])) {
|
||||
$userInfo = api_get_user_info($recipient['user_id']);
|
||||
$receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata;
|
||||
}
|
||||
}
|
||||
$receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma.
|
||||
$dropbox_file_data[] = $receivers_celldata;
|
||||
|
||||
$lastUploadDate = Display::dateToStringAgoAndLongDate($dropbox_file->last_upload_date);
|
||||
$dropbox_file_data[] = $lastUploadDate;
|
||||
$receivers_celldata = '';
|
||||
|
||||
$action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').'
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.
|
||||
Display::return_icon('discuss.png', get_lang('Comment'), '', ICON_SIZE_SMALL).
|
||||
'</a>
|
||||
<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/update.php?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=update&id='.$dropbox_file->id.'&'.$sort_params.'">'.
|
||||
Display::return_icon('upload_file.png', get_lang('Update'), '', ICON_SIZE_SMALL).
|
||||
'</a>
|
||||
<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=send_other_users&id='.$dropbox_file->id.'&'.$sort_params.'">'.
|
||||
Display::return_icon('addworkuser.png', get_lang('SendOtherUsers'), '', ICON_SIZE_SMALL).
|
||||
'</a>
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movesent&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.
|
||||
Display::return_icon('move.png', get_lang('Move'), '', ICON_SIZE_SMALL).'
|
||||
</a>
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
|
||||
'</a>';
|
||||
// This is a hack to have an additional row in a sortable table
|
||||
if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) {
|
||||
$action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table
|
||||
$action_icons .= "<tr><td colspan=\"9\">";
|
||||
$url = api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params;
|
||||
$action_icons .= feedback($dropbox_file->feedback2, $url);
|
||||
//$action_icons .= "<a class=\"btn btn-default\" href=\""><i class=\"fa fa-times\" aria-hidden=\"true\"></i></a>";
|
||||
$action_icons .= "</tr>";
|
||||
}
|
||||
$dropbox_file_data[] = $action_icons;
|
||||
$dropbox_file_data[] = $lastUploadDate;
|
||||
$dropbox_file_data[] = $file_size;
|
||||
$action_icons = '';
|
||||
$dropbox_data_sent[] = $dropbox_file_data;
|
||||
}
|
||||
}
|
||||
|
||||
$moveList = [];
|
||||
// The content of the sortable table = the categories (if we are not in the root)
|
||||
if ($view_dropbox_category_sent == 0) {
|
||||
foreach ($dropbox_categories as $category) {
|
||||
$dropbox_category_data = [];
|
||||
if ($category['sent'] == '1') {
|
||||
$moveList[$category['cat_id']] = $category['cat_name'];
|
||||
$dropbox_category_data[] = $category['cat_id'];
|
||||
// This is where the checkbox icon for the files appear.
|
||||
$link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">';
|
||||
$dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>';
|
||||
$dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.
|
||||
Display::return_icon('save_pack.png', get_lang('Save'), ['style' => 'float:right;'], ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>';
|
||||
$dropbox_category_data[] = '';
|
||||
$dropbox_category_data[] = '';
|
||||
$dropbox_category_data[] = '';
|
||||
$dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.
|
||||
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>
|
||||
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.
|
||||
Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>';
|
||||
}
|
||||
if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) {
|
||||
$dropbox_data_sent[] = $dropbox_category_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Displaying the table
|
||||
$additional_get_parameters = [
|
||||
'view' => $view,
|
||||
'view_received_category' => $viewReceivedCategory,
|
||||
'view_sent_category' => $viewSentCategory,
|
||||
];
|
||||
|
||||
$selectlist = [
|
||||
'delete_received' => get_lang('Delete'),
|
||||
'download_received' => get_lang('Download'),
|
||||
];
|
||||
|
||||
if (!empty($moveList)) {
|
||||
foreach ($moveList as $catid => $catname) {
|
||||
$selectlist['move_sent_'.$catid] = get_lang('Move').'->'.Security::remove_XSS($catname);
|
||||
}
|
||||
}
|
||||
|
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
|
||||
$selectlist = ['download_received' => get_lang('Download')];
|
||||
}
|
||||
|
||||
echo '<div class="files-table">';
|
||||
Display::display_sortable_config_table(
|
||||
'dropbox',
|
||||
$column_header,
|
||||
$dropbox_data_sent,
|
||||
$sorting_options,
|
||||
$paging_options,
|
||||
$additional_get_parameters,
|
||||
$column_show,
|
||||
$column_order,
|
||||
$selectlist
|
||||
);
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
Display::display_footer();
|
||||
63
main/dropbox/recover_dropbox_files.php
Normal file
63
main/dropbox/recover_dropbox_files.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once 'dropbox_init.inc.php';
|
||||
|
||||
$file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
|
||||
$person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
|
||||
$course_id = api_get_course_int_id();
|
||||
$user_id = api_get_user_id();
|
||||
$session_id = api_get_session_id();
|
||||
|
||||
if (empty($course_id)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
if (!api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed();
|
||||
}
|
||||
|
||||
echo Display::page_subheader(get_lang('RecoverDropboxFiles'));
|
||||
if (isset($_GET['recover_id']) && !empty($_GET['recover_id'])) {
|
||||
$recover_id = (int) $_GET['recover_id'];
|
||||
|
||||
$sql = "INSERT INTO $person_tbl VALUES('$course_id', $recover_id, $user_id)";
|
||||
$result = Database::query($sql);
|
||||
if ($result) {
|
||||
echo Display::return_message(get_lang('Recovered'), 'confirm');
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM $file_tbl
|
||||
WHERE c_id = $course_id AND session_id = $session_id";
|
||||
$result = Database::query($sql);
|
||||
|
||||
if (Database::num_rows($result)) {
|
||||
$files = Database::store_result($result);
|
||||
$rows = [];
|
||||
foreach ($files as $file) {
|
||||
//Check if I have this file:
|
||||
$sql = "SELECT * FROM $person_tbl
|
||||
WHERE c_id = $course_id AND user_id = $user_id AND file_id = {$file['id']}";
|
||||
$result_person = Database::query($sql);
|
||||
if (Database::num_rows($result_person) == 0) {
|
||||
$rows[] = [
|
||||
$file['filename'],
|
||||
api_convert_and_format_date($file['upload_date']),
|
||||
Display::url(
|
||||
get_lang('Recover'),
|
||||
api_get_self().'?recover_id='.$file['id'],
|
||||
['class' => 'btn btn-default']
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
$headers = [
|
||||
get_lang('FileName'),
|
||||
get_lang('UploadedDate'),
|
||||
get_lang('Action'),
|
||||
];
|
||||
echo Display::table($headers, $rows);
|
||||
}
|
||||
Display::display_footer();
|
||||
40
main/dropbox/update.php
Normal file
40
main/dropbox/update.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
require_once 'dropbox_init.inc.php';
|
||||
|
||||
api_protect_course_script();
|
||||
|
||||
if (0 != api_get_session_id() && !api_is_allowed_to_session_edit(false, true)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
|
||||
if (empty($id)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
$work = new Dropbox_SentWork($id);
|
||||
if (empty($work)) {
|
||||
api_not_allowed(true);
|
||||
}
|
||||
|
||||
if (isset($_POST['submitWork'])) {
|
||||
store_add_dropbox(null, $work);
|
||||
}
|
||||
|
||||
$viewReceivedCategory = isset($_GET['view_received_category']) ? Security::remove_XSS($_GET['view_received_category']) : '';
|
||||
$viewSentCategory = isset($_GET['view_sent_category']) ? Security::remove_XSS($_GET['view_sent_category']) : '';
|
||||
$view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : '';
|
||||
|
||||
echo Display::page_header($work->title);
|
||||
|
||||
display_add_form(
|
||||
$viewReceivedCategory,
|
||||
$viewSentCategory,
|
||||
$view,
|
||||
$id
|
||||
);
|
||||
|
||||
Display::display_footer();
|
||||
Reference in New Issue
Block a user