Minor - Format code, removing unused dropbox_zipdownload.inc.php file.

1.9.x
Julio Montoya 13 years ago
parent e959cab5a1
commit e1ca70eeb5
  1. 122
      main/dropbox/dropbox_class.inc.php
  2. 157
      main/dropbox/dropbox_submit.php
  3. 5
      main/dropbox/dropbox_zipdownload.inc.php
  4. 15
      main/dropbox/index.php
  5. 10
      main/dropbox/recover_dropbox_files.php

@ -41,19 +41,20 @@
* with contributions by René Haentjens <rene.haentjens@UGent.be>
* @package chamilo.dropbox
*/
class Dropbox_Work {
public $id;
public $uploader_id;
public $uploaderName;
public $filename;
public $filesize;
public $title;
public $description;
public $author;
public $upload_date;
public $last_upload_date;
public $isOldWork;
public $feedback_date, $feedback;
class Dropbox_Work
{
public $id;
public $uploader_id;
public $uploaderName;
public $filename;
public $filesize;
public $title;
public $description;
public $author;
public $upload_date;
public $last_upload_date;
public $isOldWork;
public $feedback_date, $feedback;
/**
* Constructor calls private functions to create a new work or retreive an existing work from DB
@ -67,7 +68,8 @@ class Dropbox_Work {
* @param unknown_type $arg6
* @return Dropbox_Work
*/
function Dropbox_Work($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null) {
function Dropbox_Work($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 {
@ -104,7 +106,7 @@ class Dropbox_Work {
$this->description = $description;
$this->author = api_get_person_name($_user['firstName'], $_user['lastName']);
$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
@ -121,10 +123,10 @@ class Dropbox_Work {
if ($this->isOldWork) {
$this->id = $res['id'];
$this->upload_date = $res['upload_date'];
$sql = "UPDATE ".$dropbox_cnf["tbl_file"]." SET
filesize = '".Database::escape_string($this->filesize)."' ,
title = '".Database::escape_string($this->title)."',
description = '".Database::escape_string($this->description)."',
$sql = "UPDATE ".$dropbox_cnf["tbl_file"]." SET
filesize = '".Database::escape_string($this->filesize)."' ,
title = '".Database::escape_string($this->title)."',
description = '".Database::escape_string($this->description)."',
author = '".Database::escape_string($this->author)."',
last_upload_date = '".Database::escape_string($this->last_upload_date)."'
WHERE c_id = $course_id AND id='".Database::escape_string($this->id)."'";
@ -132,7 +134,7 @@ class Dropbox_Work {
} else {
$this->upload_date = $this->last_upload_date;
$sql = "INSERT INTO ".$dropbox_cnf['tbl_file']." (c_id, uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, session_id)
VALUES ( $course_id,
VALUES ( $course_id,
'".Database::escape_string($this->uploader_id)."'
, '".Database::escape_string($this->filename)."'
, '".Database::escape_string($this->filesize)."'
@ -150,7 +152,7 @@ class Dropbox_Work {
// Insert entries into person table
$sql = "INSERT INTO ".$dropbox_cnf['tbl_person']." (c_id, file_id, user_id)
VALUES ($course_id,
VALUES ($course_id,
'".Database::escape_string($this->id)."'
, '".Database::escape_string($this->uploader_id)."'
)";
@ -163,8 +165,8 @@ class Dropbox_Work {
* @param unknown_type $id
*/
function _createExistingWork($id) {
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
global $_user, $dropbox_cnf;
// Do some sanity checks
@ -232,7 +234,8 @@ class Dropbox_SentWork extends Dropbox_Work
* @param unknown_type $arg7
* @return Dropbox_SentWork
*/
function Dropbox_SentWork($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) {
function Dropbox_SentWork($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 {
@ -251,11 +254,12 @@ class Dropbox_SentWork extends Dropbox_Work
* @param unknown_type $filesize
* @param unknown_type $recipient_ids
*/
function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) {
function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
{
global $dropbox_cnf;
// Call constructor of Dropbox_Work object
$this->Dropbox_Work($uploader_id, $title, $description, $author, $filename, $filesize);
$course_id = api_get_course_int_id();
// Do sanity checks on recipient_ids array & property fillin
@ -288,14 +292,14 @@ class Dropbox_SentWork extends Dropbox_Work
// 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)
$user_id = (int)$rec['id'];
$sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id)
VALUES ($course_id, $file_id, $user_id, $session_id)";
$result = Database::query($sql);
$result = 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
* Poster is already added when work is created - not so good to split logic
*/
if ($user_id != $user) {
// Insert entries into person table
@ -325,12 +329,13 @@ class Dropbox_SentWork extends Dropbox_Work
*
* @param unknown_type $id
*/
function _createExistingSentWork ($id) {
function _createExistingSentWork ($id)
{
global $dropbox_cnf;
$id = intval($id);
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
// Call constructor of Dropbox_Work object
$this->Dropbox_Work($id);
@ -342,7 +347,7 @@ class Dropbox_SentWork extends Dropbox_Work
WHERE c_id = $course_id AND file_id='".Database::escape_string($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);
@ -351,10 +356,10 @@ class Dropbox_SentWork extends Dropbox_Work
$this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', ''));
} else {
$this->recipients[] = array(
'id' => $dest_user_id,
'name' => $user_info['complete_name'],
'id' => $dest_user_id,
'name' => $user_info['complete_name'],
'user_id' => $dest_user_id,
'feedback_date' => $res['feedback_date'],
'feedback_date' => $res['feedback_date'],
'feedback' => $res['feedback']);
}
}
@ -381,8 +386,8 @@ class Dropbox_Person
* @return Dropbox_Person
*/
function Dropbox_Person($userId, $isCourseAdmin, $isCourseTutor) {
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
// Fill in properties
$this->userId = $userId;
$this->isCourseAdmin = $isCourseAdmin;
@ -394,32 +399,32 @@ class Dropbox_Person
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$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
$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 = $course_id AND p.c_id = $course_id )
WHERE
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 = $course_id AND p.c_id = $course_id)
WHERE
f.uploader_id = '".Database::escape_string($this->userId)."' AND
p.user_id = '".Database::escape_string($this->userId)."'
WHERE
f.uploader_id = '".Database::escape_string($this->userId)."' AND
p.user_id = '".Database::escape_string($this->userId)."'
$condition_session
";
$result = Database::query($sql);
@ -524,7 +529,7 @@ class Dropbox_Person
* Deletes all the received work of this person
*/
function deleteAllReceivedWork () {
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
global $dropbox_cnf;
// Delete entries in person table concerning received works
foreach ($this->receivedWork as $w) {
@ -536,10 +541,11 @@ class Dropbox_Person
/**
* Deletes all the received categories and work of this person
*/
function deleteReceivedWorkFolder($id) {
function deleteReceivedWorkFolder($id)
{
global $dropbox_cnf;
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
$id = intval($id);
$sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." WHERE c_id = $course_id AND cat_id = '".$id."' ";
if (!Database::query($sql)) return false;
@ -556,7 +562,7 @@ class Dropbox_Person
* @param integer $id
*/
function deleteReceivedWork($id) {
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
global $dropbox_cnf;
$id = intval($id);
@ -574,7 +580,7 @@ class Dropbox_Person
}
}
// Delete entries in person table concerning received works
$sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'";
$sql = "DELETE FROM ".$dropbox_cnf['tbl_person']." WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'";
Database::query($sql);
removeUnusedFiles(); // Check for unused files
}
@ -583,7 +589,7 @@ class Dropbox_Person
* Deletes all the sent dropbox files of this person
*/
function deleteAllSentWork() {
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
global $dropbox_cnf;
//delete entries in person table concerning sent works
foreach ($this->sentWork as $w) {
@ -600,7 +606,7 @@ class Dropbox_Person
*/
function deleteSentWork($id) {
$course_id = api_get_course_int_id();
global $dropbox_cnf;
$id = intval($id);
@ -632,7 +638,7 @@ class Dropbox_Person
*/
function updateFeedback($id, $text) {
$course_id = api_get_course_int_id();
global $_course, $dropbox_cnf;
$id = intval($id);

@ -190,164 +190,7 @@ if (isset($_POST['submitWork'])) {
} else {
$return_message = $errormsg;
}
} // end if ( isset( $_POST['submitWork']))
/**
* EXAMINE OR SEND MAILING (NEW)
* @deprecated The $_GET[mailingIndex] is never called
*/
/*
if (isset($_GET['mailingIndex'])) {
// examine or send
$dropbox_person = new Dropbox_Person( $_user['user_id'], $is_courseAdmin, $is_courseTutor);
if (isset($_SESSION['sentOrder'])) {
$dropbox_person->orderSentWork($_SESSION['sentOrder']);
}
$i = $_GET['mailingIndex'];
$mailing_item = $dropbox_person->sentWork[$i];
$mailing_title = $mailing_item->title;
$mailing_file = dropbox_cnf('sysPath') . '/' . $mailing_item->filename;
$errormsg = '<b>' . $mailing_item->recipients[0]['name'] . ' ('
. "<a href='dropbox_download.php?origin=$origin&id=".urlencode($mailing_item->id)."'>"
. htmlspecialchars($mailing_title, ENT_QUOTES, api_get_system_encoding()) . '</a>):</b><br /><br />';
if (preg_match( dropbox_cnf('mailingZipRegexp'), $mailing_title, $nameParts)) {
$var = api_strtoupper($nameParts[2]); // the variable part of the name
$course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$sel = "SELECT u.user_id, u.lastname, u.firstname, cu.status
FROM ".$_configuration['main_database'].".user u
LEFT JOIN $course_user cu
ON cu.user_id = u.user_id AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND cu.course_code = '".$_course['sysCode']."'";
$sel .= " WHERE u.".dropbox_cnf("mailingWhere".$var)." = '";
$preFix = $nameParts[1]; $postFix = $nameParts[3];
$preLen = api_strlen($preFix); $postLen = api_strlen($postFix);
require api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
$zipFile = new PclZip($mailing_file);
$goodFiles = array();
$zipContent = $zipFile->listContent();
$ucaseFiles = array();
if ($zipContent) {
foreach( $zipFile->listContent() as $thisContent) {
$thisFile = substr(strrchr('/' . $thisContent['filename'], '/'), 1);
$thisFileUcase = strtoupper($thisFile);
if (preg_match("~.(php.*|phtml)$~i", $thisFile)) {
$error = true;
$errormsg .= $thisFile . ': ' . get_lang('MailingZipPhp');
break;
} elseif (!$thisContent['folder']) {
if ($ucaseFiles[$thisFileUcase]) {
$error = true;
$errormsg .= $thisFile . ': ' . get_lang('MailingZipDups');
break;
} else {
$goodFiles[$thisFile] = findRecipient($thisFile);
$ucaseFiles[$thisFileUcase] = 'yep';
}
}
}
} else {
$error = true;
$errormsg .= get_lang('MailingZipEmptyOrCorrupt');
}
if (!$error) {
$students = array(); // collect all recipients in this course
foreach ($goodFiles as $thisFile => $thisRecip) {
$errormsg .= htmlspecialchars($thisFile, ENT_QUOTES, api_get_system_encoding()) . ': ';
if (is_string($thisRecip)) { // see findRecipient
$errormsg .= '<font color="#FF0000">'
. htmlspecialchars($thisRecip, ENT_QUOTES, api_get_system_encoding()) . '</font><br />';
} else {
if ( isset( $_GET['mailingSend'])) {
$errormsg .= get_lang('MailingFileSentTo');
} else {
$errormsg .= get_lang('MailingFileIsFor');
}
$errormsg .= htmlspecialchars(api_get_person_name($thisRecip[2], $thisRecip[1]), ENT_QUOTES, api_get_system_encoding());
if (is_null($thisRecip[3])) {
$errormsg .= get_lang('MailingFileNotRegistered');
} else {
$students[] = $thisRecip[0];
}
$errormsg .= '<br />';
}
}
// find student course members not among the recipients
$course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$sql = "SELECT u.lastname, u.firstname
FROM $course_user cu
LEFT JOIN ".$_configuration['main_database'].".user u
ON cu.user_id = u.user_id AND cu.course_code = '".$_course['sysCode']."'
WHERE cu.status = 5
AND u.user_id NOT IN ('" . implode("', '" , $students) . "')";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$remainingUsers = '';
while ($res = Database::fetch_array($result)) {
$remainingUsers .= ', ' . htmlspecialchars(api_get_person_name($res[1], $res[0]), ENT_QUOTES, api_get_system_encoding());
}
$errormsg .= '<br />' . get_lang('MailingNothingFor') . api_substr($remainingUsers, 1) . '.<br />';
}
if (isset($_GET['mailingSend'])) {
chdir(dropbox_cnf('sysPath'));
$zipFile->extract(PCLZIP_OPT_REMOVE_ALL_PATH);
$mailingPseudoId = dropbox_cnf('mailingIdBase') + $mailing_item->id;
foreach ($goodFiles as $thisFile => $thisRecip) {
if (is_string($thisRecip)) { // remove problem file
@unlink(dropbox_cnf('sysPath') . '/' . $thisFile);
} else {
$newName = getLoginFromId( $_user['user_id']) . '_' . $thisFile . '_' . uniqid('');
if (rename(dropbox_cnf('sysPath') . '/' . $thisFile, dropbox_cnf('sysPath') . '/' . $newName))
new Dropbox_SentWork($mailingPseudoId, $thisFile, $mailing_item->description, $mailing_item->author, $newName, $thisContent['size'], array($thisRecip[0]));
}
}
$sendDT = api_get_utc_datetime();
// set filesize to zero on send, to avoid 2nd send (see index.php)
$sql = "UPDATE ".dropbox_cnf("tbl_file")."
SET filesize = '0' , upload_date = '".$sendDT."', last_upload_date = '".$sendDT."'
WHERE id='".addslashes($mailing_item->id)."'";
$result = Database::query($sql);
} elseif ($mailing_item->filesize != 0) {
$errormsg .= '<br />' . get_lang('MailingNotYetSent') . '<br />';
}
}
} else {
$error = true;
$errormsg .= get_lang('MailingWrongZipfile');
}
//EXAMINE OR SEND MAILING RESULTMESSAGE
if ($error) {
?>
<b><font color="#FF0000"><?php echo $errormsg?></font></b><br /><br />
<a href="index.php<?php echo "?origin=$origin"; ?>"><?php echo get_lang('BackList'); ?></a><br />
<?php
} else {
?>
<?php echo $errormsg?><br /><br />
<a href="index.php<?php echo "?origin=$origin"; ?>"><?php echo get_lang('BackList'); ?></a><br />
<?php
}
}
*/
function findRecipient($thisFile) {
// string result = error message, array result = [user_id, lastname, firstname, status]

@ -1,5 +0,0 @@
<?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';

@ -145,9 +145,9 @@ if (isset($_POST['submitWork'])) {
$check = Security::check_token();
if ($check) {
$message = store_add_dropbox();
if (!empty($message)) {
if (!empty($message)) {
Display :: display_confirmation_message($message);
}
}
}
}
@ -309,7 +309,7 @@ if ($action != 'add') {
}
}
if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
// This is for the categories
if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
$view_dropbox_category_sent = $_GET['view_sent_category'];
@ -365,7 +365,7 @@ if ($action != 'add') {
/* RECEIVED FILES */
if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
// This is for the categories
if (isset($_GET['view_received_category']) AND $_GET['view_received_category'] != '') {
$view_dropbox_category_received = $_GET['view_received_category'];
@ -457,7 +457,7 @@ if ($action != 'add') {
<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=movereceived&amp;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='.Security::remove_XSS($_GET['view_received_category']).'&amp;view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&amp;view='.Security::remove_XSS($_GET['view']).'&amp;action=deletereceivedfile&amp;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' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) {
@ -516,7 +516,7 @@ if ($action != 'add') {
/* SENT FILES */
if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
// This is for the categories
if (isset($_GET['view_sent_category']) AND $_GET['view_sent_category'] != '') {
$view_dropbox_category_sent = $_GET['view_sent_category'];
@ -526,7 +526,7 @@ if ($action != 'add') {
// 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();
@ -650,7 +650,6 @@ if ($action != 'add') {
}
Display::display_sortable_config_table('dropbox', $column_header, $dropbox_data_sent, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
}
}
Display::display_footer();

@ -1,5 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
require_once 'dropbox_init.inc.php';
$file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
@ -19,10 +19,10 @@ if (!api_is_allowed_to_session_edit(false, true)) {
echo Display::page_subheader(get_lang('RecoverDropboxFiles'));
if (isset($_GET['recover_id']) && !empty($_GET['recover_id'])) {
$recover_id = intval($_GET['recover_id']);
$sql = "INSERT INTO $person_tbl VALUES('$course_id', $recover_id, $user_id)";
$result = Database::query($sql);
if ($result) {
if ($result) {
Display::display_confirmation_message(get_lang('Recovered'));
}
}
@ -38,9 +38,9 @@ if (Database::num_rows($result)) {
$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[] = array(
$file['filename'],
$file['filename'],
api_convert_and_format_date($file['upload_date']),
Display::url(get_lang('Recover'), api_get_self().'?recover_id='.$file['id'], array('class' => 'btn'))
);

Loading…
Cancel
Save