Source for file dropbox_class.inc.php
Documentation is available at dropbox_class.inc.php
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2006 Dokeos S.A.
Copyright (c) 2006 Ghent University (UGent)
Copyright (c) various contributors
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
==============================================================================
* Dropbox module for Dokeos
* Classes for the dropbox module.
* . uploader_id => who sent it // RH: Mailing: or mailing pseudo_id
* . filename => name of file stored on the server
* . filesize // RH: Mailing: zero for sent zip
* . 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
* . 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 // RH: Feedback
* . feedback => feedback text (or HTML?) // RH: Feedback
* - Dropbox_SentWork extends Dropbox_Work
* . recipients => array of ["id"]["name"] lists the recipients of the work
* // RH: Mailing: or mailing pseudo_id
* ["feedback_date"]["feedback"] // RH: Feedback
* . receivedWork => array of Dropbox_Work objects
* . sentWork => array of Dropbox_SentWork objects
* . _orderBy =>private property used for determining the field by which the works have to be ordered
* @author Jan Bols <jan@ivpv.UGent.be>
* with contributions by Ren� Haentjens <rene.haentjens@UGent.be> (see RH)
* @package dokeos.dropbox
* Constructor calls private functions to create a new work or retreive an existing work from DB
* depending on the number of parameters
* @param unknown_type $arg1
* @param unknown_type $arg2
* @param unknown_type $arg3
* @param unknown_type $arg4
* @param unknown_type $arg5
* @param unknown_type $arg6
function Dropbox_Work ($arg1, $arg2= null, $arg3= null, $arg4= null, $arg5= null, $arg6= null)
* private function creating a new work object
* @param unknown_type $uploader_id
* @param unknown_type $title
* @param unknown_type $description
* @param unknown_type $author
* @param unknown_type $filename
* @param unknown_type $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
function _createNewWork ($uploader_id, $title, $description, $author, $filename, $filesize)
settype($uploader_id, 'integer') or die(dropbox_lang("generalError"). " (code 201)"); //set $uploader_id to correct type
//if (! isCourseMember($uploader_id)) die(); //uploader must be coursemember to be able to upload
//-->this check is done when submitting data so it isn't checked here
// Fill in the properties
$this->author = $_user['firstName']. ' '. $_user['lastName'];
// Check if object exists already. If it does, the old object is used
// with updated information (authors, descriptio, upload_date)
$sql= "SELECT id, upload_date
// insert or update the dropbox_file table and set the id property
(uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, session_id)
, ". intval($_SESSION['id_session']). "
// insert entries into person table
$result = api_sql_query($sql); //if work already exists no error is generated
* private function creating existing object by retreiving info from db
* @param unknown_type $id
global $_user; // RH: Feedback
settype($id, 'integer') or die(dropbox_lang("generalError"). " (code 205)"); //set $id to correct type
$sql= "SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id
// Check if uploader is still in Dokeos system
if ($uploaderName == FALSE)
$this->category = $res['cat_id'];
// Getting the feedback on the work.
if ($_GET['action']== 'viewfeedback' AND $this->id== $_GET['id'])
$sql_feedback = "SELECT * FROM ". dropbox_cnf("tbl_feedback"). " WHERE file_id='". $id. "' ORDER BY feedback_id ASC";
$feedback2[]= $row_feedback;
$this->feedback2= $feedback2;
$result = api_sql_query("SELECT feedback_date, feedback, cat_id FROM ".
dropbox_cnf("tbl_post")." WHERE dest_user_id='".$_user['user_id'].
"' AND file_id='".$id."'",__FILE__,__LINE__);
if ($res = mysql_fetch_array($result))
$this->feedback_date = $res["feedback_date"];
$this->feedback = $res["feedback"];
$this->category = $res['cat_id'];
} // do not fail if there is no recipient = current user...*/
* Constructor calls private functions to create a new work or retreive an existing work from DB
* depending on the number of parameters
* @param unknown_type $arg1
* @param unknown_type $arg2
* @param unknown_type $arg3
* @param unknown_type $arg4
* @param unknown_type $arg5
* @param unknown_type $arg6
* @param unknown_type $arg7
* @return Dropbox_SentWork
function Dropbox_SentWork ($arg1, $arg2= null, $arg3= null, $arg4= null, $arg5= null, $arg6= null, $arg7= null)
* private function creating a new SentWork object
* @param unknown_type $uploader_id
* @param unknown_type $title
* @param unknown_type $description
* @param unknown_type $author
* @param unknown_type $filename
* @param unknown_type $filesize
* @param unknown_type $recipient_ids
function _createNewSentWork ($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids)
// Call constructor of Dropbox_Work object
$this->Dropbox_Work($uploader_id, $title, $description, $author, $filename, $filesize);
// Do sanity checks on recipient_ids array & property fillin
// The sanity check for ex-coursemembers is already done in base constructor
settype($uploader_id, 'integer') or die(dropbox_lang("generalError"). " (code 208)"); //set $uploader_id to correct type
$justSubmit = FALSE; // RH: mailing zip-file or just upload
$justSubmit = TRUE; $recipient_ids = array($recipient_ids + $this->id);
elseif ( count($recipient_ids) == 0) // RH: Just Upload
$justSubmit = TRUE; $recipient_ids = array($uploader_id);
foreach ($recipient_ids as $rec)
if (empty($rec)) die(dropbox_lang("generalError"). " (code 210)");
//if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
//this check is done when validating submitted data
// insert data in dropbox_post and dropbox_person table for each recipient
(file_id, dest_user_id, session_id)
$result = api_sql_query($sql); //if work already exists no error is generated
//insert entries into person table
// RH: do not add recipient in person table if mailing zip or just upload
if (!$justSubmit) $result = api_sql_query($sql); //if work already exists no error is generated
//update item_property (previously last_tooledit) table for each recipient
global $_course, $dropbox_cnf;
if (($ownerid = $this->uploader_id) > $dropbox_cnf["mailingIdBase"])
if (($recipid = $rec["id"]) > $dropbox_cnf["mailingIdBase"])
$recipid = $ownerid; // mailing file recipient = mailing id, not a person
* private function creating existing object by retreiving info from db
* @param unknown_type $id
// Call constructor of Dropbox_Work object
// Do sanity check. The sanity check for ex-coursemembers is already done in base constructor
settype($id, 'integer') or die(dropbox_lang("generalError"). " (code 211)"); //set $id to correct type
//Fill in recipients array/
$this->recipients = array(); // RH: Feedback: added to SELECT
$sql= "SELECT dest_user_id, feedback_date, feedback
// check for deleted users
$dest_user_id = $res["dest_user_id"];
//$this->category=$res['cat_id'];
if ($recipientName == FALSE)
$this->recipients[] = array("id"=> $dest_user_id, "name"=> $recipientName, "user_id"=> $dest_user_id,
"feedback_date"=> $res["feedback_date"], "feedback"=> $res["feedback"]); // RH: Feedback
var $sentWork; //array of Dropbox_SentWork objects
var $_orderBy = ''; //private property that determines by which field
//the receivedWork and the sentWork arrays are sorted
* Constructor for recreating the Dropbox_Person object
* @param unknown_type $userId
* @param unknown_type $isCourseAdmin
* @param unknown_type $isCourseTutor
//Note: perhaps include an ex coursemember check to delete old files
// find all entries where this person is the recipient
$sql = "SELECT r.file_id, r.cat_id
FROM $post_tbl r, $person_tbl p
AND r.dest_user_id = p.user_id
AND r.file_id = p.file_id";
if(intval($_SESSION['id_session']> 0))
$sql .= " AND r.session_id = ". intval($_SESSION['id_session']);
$temp -> category = $res['cat_id'];
// find all entries where this person is the sender/uploader
FROM $file_tbl f, $person_tbl p
AND f.uploader_id = p.user_id
if(intval($_SESSION['id_session']> 0))
$sql .= " AND f.session_id = ". intval($_SESSION['id_session']);
* This private method is used by the usort function in the
* orderSentWork and orderReceivedWork methods.
* It compares 2 work-objects by 1 of the properties of that object, dictated by the
* private property _orderBy
* @return -1, 0 or 1 dependent of the result of the comparison.
if ($sort == 'recipients')
{ //the recipients property is an array so we do the comparison based on the first item of the recipients array
$aval = $aval[0]['name'];
$bval = $bval[0]['name'];
{ //filesize is not a string, so we use other comparison technique
return $aval< $bval ? - 1 : 1;
* method that sorts the objects in the sentWork array, dependent on the $sort parameter.
* $sort can be lastDate, firstDate, title, size, ...
* @param unknown_type $sort
usort($this->sentWork, array($this,"_cmpWork")); //this calls the _cmpWork method
* method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
* $sort can be lastDate, firstDate, title, size, ...
* @param unknown_type $sort
usort($this->receivedWork, array($this,"_cmpWork")); //this calls the _cmpWork method
* Deletes all the received work of this person
//delete entries in person table concerning received works
* Deletes a received dropbox file of this person with id=$id
//delete entries in person table concerning received works
* Deletes all the sent dropbox files of this person
//delete entries in person table concerning sent works
* Deletes a sent dropbox file of this person with id=$id
* @param unknown_type $id
if (!$found) die(dropbox_lang("generalError"). " (code 219)");
//$file_id = $this->sentWork[$index]->id; // RH: Mailing
//delete entries in person table concerning sent works
* Updates feedback for received work of this person with id=$id
* @param unknown_type $id
* @param unknown_type $text
global $_course, $dropbox_cnf;
$found = false; $wi = - 1;
$wi++ ; if ($w->id == $id)
} // foreach (... as $wi -> $w) gives error 221! (no idea why...)
if (! $found) die(dropbox_lang("generalError"). " (code 221)");
$feedback_date = date("Y-m-d H:i:s",time());
"' WHERE dest_user_id='". $this->userId. "' AND file_id='". $id. "'",__FILE__ ,__LINE__ );
//update item_property (previously last_tooledit) table
if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf["mailingIdBase"])
* Filter the received work
$new_received_work = array();
if ($work->uploader_id == $value ||
($work->uploader_id > $dropbox_cnf["mailingIdBase"] &&
$new_received_work[] = $work;
$new_received_work[] = $work;
|