Feature #272 - Some corrections in "Assignments" tool. Code cleaning for "Assignments" and "Dropbox" tools.

skala
Ivan Tcholakov 16 years ago
parent a5a4b9ecc5
commit 02c7a86e61
  1. 62
      main/dropbox/dropbox_download.php
  2. 2
      main/dropbox/dropbox_functions.inc.php
  3. 34
      main/dropbox/dropbox_init.inc.php
  4. 2
      main/dropbox/dropbox_submit.php
  5. 28
      main/dropbox/index.php
  6. 47
      main/work/download.php
  7. 79
      main/work/downloadfolder.inc.php
  8. 867
      main/work/work.lib.php
  9. 1024
      main/work/work.php

@ -1,9 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
/*
INIT SECTION
*/
/* INIT SECTION */
// We cannot use dropbox_init.inc.php because this one already outputs data.
$language_file = 'dropbox';
@ -22,10 +21,8 @@ require_once 'dropbox_class.inc.php';
require_once api_get_path(LIBRARY_PATH).'/document.lib.php';
/* DOWNLOAD A FOLDER */
/*
DOWNLOAD A FOLDER
*/
if (isset($_GET['cat_id']) AND is_numeric($_GET['cat_id']) AND $_GET['action'] == 'downloadcategory' AND isset($_GET['sent_received'])) {
// step 1: constructingd' the sql statement. Due to the nature off the classes of the dropbox the categories for sent files are stored in the table
// dropbox_file while the categories for the received files are stored in dropbox_post. It would have been more elegant if these could be stored
@ -62,12 +59,10 @@ if (isset($_GET['cat_id']) AND is_numeric($_GET['cat_id']) AND $_GET['action'] =
}
/*
DOWNLOAD A FILE
*/
/*
AUTHORIZATION
*/
/* DOWNLOAD A FILE */
/* AUTHORIZATION */
// Check if the id makes sense
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
Display::display_header($nameTools, 'Dropbox');
@ -86,9 +81,8 @@ if (Database::num_rows($result) > 0) {
$allowed_to_download = true;
}
/*
ERROR IF NOT ALLOWED TO DOWNLOAD
*/
/* ERROR IF NOT ALLOWED TO DOWNLOAD */
if (!$allowed_to_download) {
Display::display_header($nameTools, 'Dropbox');
Display :: display_error_message(get_lang('YouAreNotAllowedToDownloadThisFile'));
@ -96,9 +90,8 @@ if (!$allowed_to_download) {
exit;
}
/*
DOWNLOAD THE FILE
*/
/* DOWNLOAD THE FILE */
// the user is allowed to download the file
else {
$_SESSION['_seen'][$_course['id']][TOOL_DROPBOX][] = intval($_GET['id']);
@ -123,7 +116,6 @@ else {
header('Content-Disposition: attachment; filename='.$file);
}
/**
* Note that if you use these two headers from a previous example:
* header('Cache-Control: no-cache, must-revalidate');
@ -135,7 +127,6 @@ else {
header("Cache-Control: \n");
header("Cache-Control: public\n"); // IE cannot download from sessions without a cache
/*if (isset($_SERVER['HTTPS'])) {
/**
* We need to set the following headers to make downloads work using IE in HTTPS mode.
@ -148,8 +139,6 @@ else {
header("Cache-Control: post-check=0, pre-check=0\n", false);
}*/
header('Content-Description: ' . trim(htmlentities($file)) . "\n");
header("Content-Transfer-Encoding: binary\n");
header("Content-Length: " . filesize($path)."\n" );
@ -160,7 +149,6 @@ else {
}
/**
* Dropbox module for Chamilo
* handles downloads of files. Direct downloading is prevented because of an .htaccess file in the
@ -249,16 +237,14 @@ else {
* @package chamilo.dropbox
*/
/*
INITIALISING VARIABLES
*/
/* INITIALISING VARIABLES */
require_once 'dropbox_init.inc.php'; //only call init1 because init2 outputs data
require_once 'dropbox_class.inc.php';
/*
AUTHORISATION SECTION
*/
/* AUTHORISATION SECTION */
if (!isset($_user['user_id']) || !$is_course_member) {
exit();
}
@ -266,9 +252,8 @@ if (!isset($_user['user_id']) || !$is_course_member) {
if ($_GET['mailing']) // RH: Mailing detail window call
getUserOwningThisMailing($_GET['mailing'], $_user['user_id'], '500'); // RH or die
/*
SANITY CHECKS OF GET DATA & FILE
*/
/* SANITY CHECKS OF GET DATA & FILE */
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) die(get_lang('GeneralError').' (code 501)');
$work = new Dropbox_work($_GET['id']);
@ -282,9 +267,8 @@ if (!is_file($path)) {
die(get_lang('GeneralError').' (code 504)');
}
/*
SEND HEADERS
*/
/* SEND HEADERS */
require_once api_get_path(LIBRARY_PATH) . '/document.lib.php';
$mimetype = DocumentManager::file_get_mime_type(true);
@ -305,7 +289,6 @@ if (!in_array(strtolower($fileparts [$filepartscount - 1]), array('doc', 'xls',
header('Content-Disposition: attachment; filename='.$file);
}
/**
* Note that if you use these two headers from a previous example:
* header('Cache-Control: no-cache, must-revalidate');
@ -317,7 +300,6 @@ header( "Pragma: \n");
header( "Cache-Control: \n");
header( "Cache-Control: public\n"); // IE cannot download from sessions without a cache
/*if (isset($_SERVER['HTTPS'])) {
/**
* We need to set the following headers to make downloads work using IE in HTTPS mode.
@ -330,14 +312,12 @@ header( "Cache-Control: public\n"); // IE cannot download from sessions without
header("Cache-Control: post-check=0, pre-check=0\n", false);
}*/
header('Content-Description: ' . trim(htmlentities($file)) . "\n");
header("Content-Transfer-Encoding: binary\n");
header('Content-Length: ' . filesize($path)."\n" );
/*
SEND FILE
*/
/* SEND FILE */
$fp = fopen( $path, 'rb');
fpassthru($fp);
exit();

@ -50,7 +50,6 @@ function handle_multiple_actions() {
return get_lang('CheckAtLeastOneFile');
}
// STEP 3A: deleting
if ($_POST['action'] == 'delete_received' || $_POST['action'] == 'delete_sent') {
$dropboxfile = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
@ -272,7 +271,6 @@ function display_file_checkbox($id, $part) {
return $return_value;
}
/**
* This function retrieves all the dropbox categories and returns them as an array
*

@ -24,9 +24,7 @@
* @package chamilo.dropbox
*/
/*
INIT SECTION
*/
/* INIT SECTION */
$language_file = 'dropbox';
@ -53,10 +51,8 @@ require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
// protecting the script
api_protect_course_script();
/* Libraries */
/*
Libraries
*/
require_once api_get_path(LIBRARY_PATH) . 'debug.lib.inc.php';
require_once api_get_path(LIBRARY_PATH) . 'course.lib.php';
require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
@ -73,9 +69,8 @@ require_once api_get_path(LIBRARY_PATH) . 'fileDisplay.lib.php'; // the function
require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
/*
Virtual course support
*/
/* Virtual course support */
$user_id = api_get_user_id();
$course_code = $_course['sysCode'];
$course_info = Database::get_course_info($course_code);
@ -84,9 +79,8 @@ $session_id = api_get_session_id();
$is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_code,$session_id);
/*
Object Initialisation
*/
/* Object Initialisation */
// 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
@ -95,10 +89,8 @@ if ($_GET['action'] == 'add') {
$dropbox_person = new Dropbox_Person($_user['user_id'], $is_courseAdmin, $is_courseTutor);
}
/*
create javascript and htmlHeaders
// RH: Mailing: new function confirmsend
*/
/* Create javascript and htmlHeaders */
// RH: Mailing: new function confirmsend
$javascript = "<script type=\"text/javascript\">
function confirmsend ()
@ -247,9 +239,8 @@ if ((!$is_allowed_in_course || !$is_course_member) && !api_is_allowed_to_edit(nu
exit();
}
/*
BREADCRUMBS
*/
/* BREADCRUMBS */
if ($_GET['view'] == 'received') {
$interbreadcrumb[] = array('url' => '../dropbox/index.php', 'name' => get_lang('Dropbox', ''));
$nameTools = get_lang('ReceivedFiles');
@ -274,10 +265,7 @@ if ($_GET['view'] == 'sent' OR empty($_GET['view'])) {
}
}
/*
HEADER & TITLE
*/
/* HEADER & TITLE */
if ($origin != 'learnpath') {
Display::display_header($nameTools, 'Dropbox');

@ -226,7 +226,7 @@ if (isset($_POST['submitWork'])) {
/**
* // RH: EXAMINE OR SEND MAILING (NEW)
* RH: EXAMINE OR SEND MAILING (NEW)
*/
if (isset($_GET['mailingIndex'])) { // examine or send

@ -89,9 +89,7 @@ Version 1.4 (Yannick Warnier)
- removed all self-built database tables names
*/
/*
INIT SECTION
*/
/* INIT SECTION */
// the file that contains all the initialisation stuff (and includes all the configuration stuff)
require_once 'dropbox_init.inc.php';
@ -110,18 +108,14 @@ event_access_tool(TOOL_DROPBOX);
//this var is used to give a unique value to every page request. This is to prevent resubmiting data
$dropbox_unid = md5(uniqid(rand(), true));
/*
DISPLAY SECTION
*/
/* DISPLAY SECTION */
// Tool introduction
Display::display_introduction_section(TOOL_DROPBOX);
/*
ACTIONS: add a dropbox file, add a dropbox category.
*/
/* ACTIONS: add a dropbox file, add a dropbox category. */
// *** display the form for adding a new dropbox item. ***
// Display the form for adding a new dropbox item.
if ($_GET['action'] == 'add') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
api_not_allowed();
@ -137,7 +131,6 @@ if (isset($_POST['submitWork'])) {
}
}
// display the form for adding a category
if ($_GET['action'] == 'addreceivedcategory' or $_GET['action'] == 'addsentcategory') {
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
@ -338,10 +331,8 @@ if ($_GET['action'] != 'add') {
}
}
/* THE MENU TABS */
/*
THE MENU TABS
*/
if ($dropbox_cnf['sent_received_tabs']) {
?>
<div id="tabbed_menu">
@ -353,9 +344,8 @@ if ($_GET['action'] != 'add') {
<?php
}
/*
RECEIVED FILES
*/
/* RECEIVED FILES */
if ($_GET['view'] == 'received' OR !$dropbox_cnf['sent_received_tabs']) {
//echo '<h3>'.get_lang('ReceivedFiles').'</h3>';
@ -507,9 +497,7 @@ if ($_GET['action'] != 'add') {
Display::display_sortable_config_table($column_header, $dropbox_data_recieved, $sorting_options, $paging_options, $additional_get_parameters, $column_show, $column_order, $selectlist);
}
/*
SENT FILES
*/
/* SENT FILES */
if (!$_GET['view'] OR $_GET['view'] == 'sent' OR !$dropbox_cnf['sent_received_tabs']) {
//echo '<h3>'.get_lang('SentFiles').'</h3>';

@ -1,29 +1,22 @@
<?php // $Id: download.php 22201 2009-07-17 19:57:03Z cfasanando $
/* For licensing terms, see /dokeos_license.txt */
<?php
/* For licensing terms, see /license.txt */
/**
==============================================================================
* This file is responsible for passing requested documents to the browser.
* Html files are parsed to fix a few problems with URLs,
* but this code will hopefully be replaced soon by an Apache URL
* rewrite mechanism.
*
* @package dokeos.work
==============================================================================
*/
/*
==============================================================================
MAIN CODE
==============================================================================
*/
* This file is responsible for passing requested documents to the browser.
* Html files are parsed to fix a few problems with URLs,
* but this code will hopefully be replaced soon by an Apache URL
* rewrite mechanism.
*
* @package chamilo.work
*/
session_cache_limiter('public');
require '../inc/global.inc.php';
$this_section=SECTION_COURSES;
$this_section = SECTION_COURSES;
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
//include 'agenda.inc.php';
// IMPORTANT to avoid caching of documents
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Cache-Control: public');
@ -38,7 +31,8 @@ $doc_url = str_replace('///', '&', $doc_url);
//still a space present? it must be a '+' (that got replaced by mod_rewrite)
$doc_url = str_replace(' ', '+', $doc_url);
$doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
if (! isset($_course)) {
if (!isset($_course)) {
api_not_allowed(true);
}
@ -48,13 +42,12 @@ $tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION)
// launch event
event_download($doc_url);
$sql='SELECT title FROM '.$tbl_student_publication.'
$sql = 'SELECT title FROM '.$tbl_student_publication.'
WHERE url LIKE BINARY "'.$doc_url.'"';
$result= Database::query($sql);
$row= Database::fetch_array($result);
$title = str_replace(' ','_', $row['title']);
DocumentManager::file_send_for_download($full_file_name,TRUE, $title);
$result = Database::query($sql);
$row = Database::fetch_array($result);
$title = str_replace(' ', '_', $row['title']);
DocumentManager::file_send_for_download($full_file_name, true, $title);
exit;
?>

@ -1,29 +1,27 @@
<?php // $Id: downloadfolder.inc.php 17989 2009-01-25 05:51:54Z yannoo $
/* For licensing terms, see /dokeos_license.txt */
<?php
/* For licensing terms, see /license.txt */
/**
==============================================================================
* Functions and main code for the download folder feature
*
* @package dokeos.work
==============================================================================
*/
* Functions and main code for the download folder feature
*
* @package chamilo.work
*/
$path = $_GET['path'];
//prevent some stuff
if(empty($path))
{
$path='/';
if (empty($path)) {
$path = '/';
}
//zip library for creation of the zipfile
include(api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php');
require api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
//we need this path to clean it out of the zip file
//I'm not using dirname as it gives too much problems (cfr. \)
$remove_dir = ($path!='/') ? substr($path,0,strlen($path) - strlen(basename($path))) : '/';
$remove_dir = ($path != '/') ? substr($path, 0, strlen($path) - strlen(basename($path))) : '/';
//place to temporarily stash the zipfiles
$temp_zip_dir = $sys_course_path.$_course['path']."/temp";
$temp_zip_dir = $sys_course_path.$_course['path'].'/temp';
//create the temp dir if it doesn't exist
//or do a cleanup befor creating the zipfile
@ -31,9 +29,9 @@ if (!is_dir($temp_zip_dir)) {
mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
} else {
//cleanup: check the temp dir for old files and delete them
$handle=opendir($temp_zip_dir);
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$handle = opendir($temp_zip_dir);
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
//the "age" of the file in hours
$Diff = (time() - filemtime("$temp_zip_dir/$file"))/60/60;
//delete files older than 4 hours
@ -47,7 +45,7 @@ if (!is_dir($temp_zip_dir)) {
//create zipfile of given directory
$temp_zip_file = $temp_zip_dir."/".md5(time()).".zip";
$zip_folder= new PclZip($temp_zip_file);
$zip_folder = new PclZip($temp_zip_file);
$tbl_student_publication = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$prop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
//Put the files in the zip
@ -61,27 +59,26 @@ if (is_allowed_to_edit()) {
//creation of the zipped folder
//$zip_folder->create($what_to_zip ,PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path']."/document".$remove_dir );
//set the path that will be used in the query
if($path=='/') {
$querypath=''; // to prevent ...path LIKE '//%'... in query
if ($path == '/') {
$querypath = ''; // to prevent ...path LIKE '//%'... in query
} else {
$querypath=$path;
$querypath = $path;
}
//search for all files that are not deleted => visibility != 2
$query = Database::query("SELECT url FROM $tbl_student_publication AS work,$prop_table AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'2'");
//add tem to the zip file
while ($not_deleted_file = Database::fetch_assoc($query)) { //var_dump($sys_course_path.$_course['path']."/".$not_deleted_file['url']);exit();
$zip_folder->add($sys_course_path.$_course['path']."/".$not_deleted_file['url'],PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path']."/work".$remove_dir);
while ($not_deleted_file = Database::fetch_assoc($query)) { //var_dump($sys_course_path.$_course['path'].'/'.$not_deleted_file['url']);exit();
$zip_folder->add($sys_course_path.$_course['path'].'/'.$not_deleted_file['url'], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work'.$remove_dir);
}
}
//for other users, we need to create a zipfile with only visible files and folders
else
{
if ($path=='/') {
$querypath=''; // to prevent ...path LIKE '//%'... in query
else {
if ($path == '/') {
$querypath = ''; // to prevent ...path LIKE '//%'... in query
} else {
$querypath=$path;
$querypath = $path;
}
//big problem: visible files that are in a hidden folder are included when we do a query for visiblity='v'!!!
//so... I do it in a couple of steps:
@ -96,7 +93,7 @@ else
$query2 = Database::query("SELECT url FROM $tbl_student_publication AS work,$prop_table AS props WHERE props.tool='work' AND work.id=props.ref AND work.url LIKE 'work".$querypath."/%' AND work.filetype='file' AND props.visibility<>'1' AND props.lastedit_user_id='".api_get_user_id()."'");
//if we get invisible folders, we have to filter out these results from all visible files we found
if (Database::num_rows($query2)>0) {
if (Database::num_rows($query2) > 0) {
//add tem to an array
while ($invisible_folders = Database::fetch_assoc($query2)) {
//3rd: get all files that are in the found invisible folder (these are "invisible" too)
@ -108,14 +105,14 @@ else
}
//compare the array with visible files and the array with files in invisible folders
//and keep the difference (= all visible files that are not in an invisible folder)
$files_for_zipfile = diff((array) $all_visible_files_path,(array) $files_in_invisible_folder_path);
$files_for_zipfile = diff((array) $all_visible_files_path, (array) $files_in_invisible_folder_path);
} else {
//no invisible folders found, so all visible files can be added to the zipfile
$files_for_zipfile = $all_visible_files_path;
}
//add all files in our final array to the zipfile
for ($i=0;$i<count($files_for_zipfile);$i++) {
$zip_folder->add($sys_course_path.$_course['path']."/".$files_for_zipfile[$i],PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path']."/work".$remove_dir);
$zip_folder->add($sys_course_path.$_course['path'].'/'.$files_for_zipfile[$i], PCLZIP_OPT_REMOVE_PATH, $sys_course_path.$_course['path'].'/work'.$remove_dir);
}
}//end for other users
//logging
@ -124,15 +121,11 @@ event_download(basename($path).'.zip (folder)');
//start download of created file
$name = basename($path).'.zip';
DocumentManager::file_send_for_download($temp_zip_file,true,$name);
DocumentManager::file_send_for_download($temp_zip_file, true, $name);
@unlink($temp_zip_file);
exit;
/**
==============================================================================
* Extra function (only used here)
==============================================================================
*/
/* Extra function (only used here) */
/**
* Return the difference between two arrays, as an array of those key/values
@ -142,12 +135,14 @@ exit;
* @param array $arr2 second array
* @return difference between the two arrays
*/
function diff($arr1,$arr2) {
$res = array(); $r=0;
function diff($arr1, $arr2) {
$res = array();
$r = 0;
foreach ($arr1 as $av) {
if (!in_array($av,$arr2)){
$res[$r]=$av; $r++;
if (!in_array($av, $arr2)) {
$res[$r] = $av;
$r++;
}
}
return $res;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save