Skip to content

Commit

Permalink
Remove all uses of dropbox_config.inc.php and remove file and corresp…
Browse files Browse the repository at this point in the history
…onding config options and function - loosely refs BT#11658
  • Loading branch information
ywarnier committed Sep 15, 2016
1 parent e0ee622 commit 7871ca0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 91 deletions.
16 changes: 9 additions & 7 deletions main/dropbox/dropbox_class.inc.php
Expand Up @@ -310,8 +310,9 @@ public function _createNewSentWork($uploader_id, $title, $description, $author,
$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
// 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'];
Expand All @@ -335,10 +336,10 @@ public function _createNewSentWork($uploader_id, $title, $description, $author,
}

// Update item_property table for each recipient
if (($ownerid = $this->uploader_id) > $dropbox_cnf['mailingIdBase']) {
if (($ownerid = $this->uploader_id) > $mailId) {
$ownerid = getUserOwningThisMailing($ownerid);
}
if (($recipid = $rec["id"]) > $dropbox_cnf['mailingIdBase']) {
if (($recipid = $rec["id"]) > $mailId) {
$recipid = $ownerid; // mailing file recipient = mailing id, not a person
}
api_item_property_update(
Expand Down Expand Up @@ -630,8 +631,8 @@ public function updateFeedback($id, $text)
);

// Update item_property table

if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf['mailingIdBase']) {
$mailId = get_mail_id_base();
if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $mailId) {
$ownerid = getUserOwningThisMailing($ownerid);
}

Expand All @@ -656,11 +657,12 @@ public function filter_received_work($type, $value)
{
$dropbox_cnf = getDropboxConf();
$new_received_work = array();
foreach ($this->receivedWork as $work) {
$mailId = get_mail_id_base();
foreach ($this->receivedWork as $work) {
switch ($type) {
case 'uploader_id':
if ($work->uploader_id == $value ||
($work->uploader_id > $dropbox_cnf['mailingIdBase'] &&
($work->uploader_id > $mailId &&
getUserOwningThisMailing($work->uploader_id) == $value)
) {
$new_received_work[] = $work;
Expand Down
34 changes: 0 additions & 34 deletions main/dropbox/dropbox_config.inc.php

This file was deleted.

3 changes: 0 additions & 3 deletions main/dropbox/dropbox_download.php
Expand Up @@ -7,9 +7,6 @@
// including the basic Chamilo initialisation file
require_once '../inc/global.inc.php';

// the dropbox configuration parameters
require_once 'dropbox_config.inc.php';

// the dropbox file that contains additional functions
require_once 'dropbox_functions.inc.php';

Expand Down
57 changes: 33 additions & 24 deletions main/dropbox/dropbox_functions.inc.php
Expand Up @@ -495,13 +495,15 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor
);

$form->addElement('header', get_lang('UploadNewFile'));
$form->addElement('hidden', 'MAX_FILE_SIZE', dropbox_cnf('maxFilesize'));
$maxFileSize = api_get_setting('dropbox_max_filesize');
$form->addElement('hidden', 'MAX_FILE_SIZE', $maxFileSize);
$form->addElement('hidden', 'dropbox_unid', $dropbox_unid);
$form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'origin', $origin);
$form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);'));

if (dropbox_cnf('allowOverwrite')) {
$allowOverwrite = api_get_setting('dropbox_allow_overwrite');
if ($allowOverwrite == 'true') {
$form->addElement('checkbox', 'cb_overwrite', null, get_lang('OverwriteFile'), array('id' => 'cb_overwrite'));
}

Expand Down Expand Up @@ -575,12 +577,13 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor
*/

$current_user_id = '';
$allowStudentToStudent = api_get_setting('dropbox_allow_student_to_student');
$options = array();
$userGroup = new UserGroup();
foreach ($complete_user_list_for_dropbox as $current_user) {
if (($dropbox_person -> isCourseTutor
|| $dropbox_person -> isCourseAdmin
|| dropbox_cnf('allowStudentToStudent')
|| $allowStudentToStudent == 'true'
|| $current_user['status'] != 5 // Always allow teachers.
|| $current_user['is_tutor'] == 1 // Always allow tutors.
) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself.
Expand All @@ -607,10 +610,11 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor
/*
* Show groups
*/
$allowGroups = api_get_setting('dropbox_allow_group');
if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin)
&& dropbox_cnf('allowGroup') || dropbox_cnf('allowStudentToStudent')
&& $allowGroups == 'true' || $allowStudentToStudent == 'true'
) {
$complete_group_list_for_dropbox = GroupManager::get_group_list(null, dropbox_cnf('courseId'));
$complete_group_list_for_dropbox = GroupManager::get_group_list(null, $course_info['code']);

if (count($complete_group_list_for_dropbox) > 0) {
foreach ($complete_group_list_for_dropbox as $current_group) {
Expand All @@ -621,7 +625,8 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor
}
}

if (dropbox_cnf('allowJustUpload')) {
$allowUpload = api_get_setting('dropbox_allow_just_upload');
if ($allowUpload == 'true') {
$options['user_'.$_user['user_id']] = get_lang('JustUploadInSelect');
}

Expand Down Expand Up @@ -692,7 +697,8 @@ function isCourseMember($user_id)
*/
function removeUnusedFiles()
{
$course_id = api_get_course_int_id();
$_course = api_get_course_info();
$course_id = $_course['real_id'];

// select all files that aren't referenced anymore
$sql = "SELECT DISTINCT f.id, f.filename
Expand All @@ -712,7 +718,7 @@ function removeUnusedFiles()
WHERE c_id = $course_id AND id ='" . $res['id'] . "'";
Database::query($sql);
//delete file from server
@unlink( dropbox_cnf('sysPath') . '/' . $res['filename']);
@unlink( api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/dropbox/' . $res['filename']);
}
}

Expand Down Expand Up @@ -770,7 +776,8 @@ function removeMoreIfMailing($file_id)

if ($res = Database::fetch_array($result)) {
$mailingPseudoId = $res['dest_user_id'];
if ($mailingPseudoId > dropbox_cnf('mailingIdBase')) {
$mailId = get_mail_id_base();
if ($mailingPseudoId > $mailId) {
$sql = "DELETE FROM " . Database::get_course_table(TABLE_DROPBOX_PERSON) . "
WHERE c_id = $course_id AND user_id='" . $mailingPseudoId . "'";
Database::query($sql);
Expand All @@ -783,17 +790,6 @@ function removeMoreIfMailing($file_id)
}
}

/**
* Function that finds a given config setting
*
* @author René Haentjens, Ghent University
*/
function dropbox_cnf($variable)
{
$dropbox_cnf = getDropboxConf();
return $dropbox_cnf[$variable];
}

/**
* @param array $file
*
Expand Down Expand Up @@ -868,7 +864,8 @@ function store_add_dropbox($file = [])
$dropbox_filetmpname = $file['tmp_name'];

// check if the filesize does not exceed the allowed size.
if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) {
$maxFileSize = api_get_setting('dropbox_max_filesize');
if ($dropbox_filesize <= 0 || $dropbox_filesize > $maxFileSize) {
Display::addFlash(Display::return_message(get_lang('DropboxFileTooBig'), 'warning'));

return false;
Expand Down Expand Up @@ -911,10 +908,10 @@ function store_add_dropbox($file = [])
api_is_course_admin(),
api_is_course_tutor()
);

$mailId = get_mail_id_base();
foreach ($dropbox_person->sentWork as $w) {
if ($w->title == $dropbox_filename) {
if (($w->recipients[0]['id'] > dropbox_cnf('mailingIdBase')) xor $thisIsAMailing) {
if (($w->recipients[0]['id'] > $mailId) xor $thisIsAMailing) {
Display::addFlash(Display::return_message(get_lang('MailingNonMailingError'), 'warning'));
return false;
}
Expand Down Expand Up @@ -947,7 +944,7 @@ function store_add_dropbox($file = [])
}
}

@move_uploaded_file($dropbox_filetmpname, dropbox_cnf('sysPath') . '/' . $dropbox_filename);
@move_uploaded_file($dropbox_filetmpname, api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/dropbox/' . $dropbox_filename);

$b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox');

Expand Down Expand Up @@ -1344,3 +1341,15 @@ function get_last_tool_access($tool, $courseId = null, $user_id = null)
$row = Database::fetch_array($result);
return $row['access_date'];
}
/**
* Previously $dropbox_cnf['mailingIdBase'], returns a mailing ID to generate a mail ID
* @return int
*/
function get_mail_id_base()
{
// false = no mailing functionality
//$dropbox_cnf['mailingIdBase'] = 10000000; // bigger than any user_id,
// allowing enough space for pseudo_ids as uploader_id, dest_user_id, user_id:
// mailing pseudo_id = dropbox_cnf('mailingIdBase') + mailing id
return 10000000;
}
7 changes: 2 additions & 5 deletions main/dropbox/dropbox_init.inc.php
Expand Up @@ -121,10 +121,6 @@

$current_course_tool = TOOL_DROPBOX;

// the dropbox configuration parameters
$dropbox_cnf = require_once 'dropbox_config.inc.php';
Session::write('dropbox_conf', $dropbox_cnf);

// the dropbox file that contains additional functions
require_once 'dropbox_functions.inc.php';

Expand Down Expand Up @@ -209,7 +205,8 @@ function checkForm (frm)
}
";

if (dropbox_cnf('allowOverwrite')) {
$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
Expand Down
11 changes: 6 additions & 5 deletions main/dropbox/index.php
Expand Up @@ -19,6 +19,7 @@
$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);
Expand Down Expand Up @@ -203,7 +204,7 @@
}

// ACTIONS
if ($view == 'received' || !$dropbox_cnf['sent_received_tabs']) {
if ($view == 'received' || !$showSentReceivedTabs) {
//echo '<h3>'.get_lang('ReceivedFiles').'</h3>';

// This is for the categories
Expand Down Expand Up @@ -240,7 +241,7 @@
}
}

if (!$view || $view == 'sent' || !$dropbox_cnf['sent_received_tabs']) {
if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
// This is for the categories
if (isset($viewSentCategory) AND $viewSentCategory != '') {
$view_dropbox_category_sent = $viewSentCategory;
Expand Down Expand Up @@ -279,7 +280,7 @@
}
}
/* THE MENU TABS */
if ($dropbox_cnf['sent_received_tabs']) {
if ($showSentReceivedTabs) {
?>
<ul class="nav nav-tabs">
<li <?php if (!$view || $view == 'sent') { echo 'class="active"'; } ?> >
Expand All @@ -295,7 +296,7 @@
<?php
}
/* RECEIVED FILES */
if ($view == 'received' || !$dropbox_cnf['sent_received_tabs']) {
if ($view == 'received' || !$showSentReceivedTabs) {
// This is for the categories
if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') {
$view_dropbox_category_received = $viewReceivedCategory;
Expand Down Expand Up @@ -489,7 +490,7 @@

/* SENT FILES */

if (!$view || $view == 'sent' || !$dropbox_cnf['sent_received_tabs']) {
if (!$view || $view == 'sent' || !$showSentReceivedTabs) {
// This is for the categories
if (isset($viewSentCategory) AND $viewSentCategory != '') {
$view_dropbox_category_sent = $viewSentCategory;
Expand Down
13 changes: 0 additions & 13 deletions tests/main/dropbox/dropbox_functions.inc.test.php
Expand Up @@ -347,19 +347,6 @@ function testzip_download() {
}
*/

/**
* Function that finds a given config setting
*/

function testdropbox_cnf() {
$variable = 'test';
$res= dropbox_cnf($variable);
if(!is_null($res)){
$this->assertTrue(is_string($res));
}
//var_dump($res);
}

/**
* This is a callback function to decrypt the files in the zip file to their normal filename (as stored in the database)
* @param $p_event a variable of PCLZip
Expand Down

1 comment on commit 7871ca0

@jmontoyaa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.