123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- <?php
- class Dropbox_Work {
- var $id;
- var $uploader_id;
- var $uploaderName;
- var $filename;
- var $filesize;
- var $title;
- var $description;
- var $author;
- var $upload_date;
- var $last_upload_date;
- var $isOldWork;
- var $feedback_date, $feedback;
-
-
- 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 {
- $this->_createExistingWork($arg1);
- }
- }
-
-
- function _createNewWork ($uploader_id, $title, $description, $author, $filename, $filesize) {
- global $_user;
-
-
- settype($uploader_id, 'integer') or die(dropbox_lang("generalError")." (code 201)");
-
-
-
-
- $this->uploader_id = $uploader_id;
- $this->uploaderName = getUserNameFromId($this->uploader_id);
- $this->filename = $filename;
- $this->filesize = $filesize;
- $this->title = $title;
- $this->description = $description;
- $this->author = $_user['firstName'].' '.$_user['lastName'];
- $this->last_upload_date = date("Y-m-d H:i:s",time());
-
-
- $this->isOldWork = FALSE;
- $sql="SELECT id, upload_date
- FROM ".dropbox_cnf("tbl_file")."
- WHERE filename = '".addslashes($this->filename)."'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- $res = mysql_fetch_array($result);
- if ($res != FALSE) {
- $this->isOldWork = TRUE;
- }
-
- if ($this->isOldWork) {
- $this->id = $res["id"];
- $this->upload_date = $res["upload_date"];
- $sql = "UPDATE ".dropbox_cnf("tbl_file")."
- SET filesize = '".addslashes($this->filesize)."'
- , title = '".addslashes($this->title)."'
- , description = '".addslashes($this->description)."'
- , author = '".addslashes($this->author)."'
- , last_upload_date = '".addslashes($this->last_upload_date)."'
- WHERE id='".addslashes($this->id)."'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- } else {
- $this->upload_date = $this->last_upload_date;
- $sql="INSERT INTO ".dropbox_cnf("tbl_file")."
- (uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, session_id)
- VALUES ('".addslashes($this->uploader_id)."'
- , '".addslashes($this->filename)."'
- , '".addslashes($this->filesize)."'
- , '".addslashes($this->title)."'
- , '".addslashes($this->description)."'
- , '".addslashes($this->author)."'
- , '".addslashes($this->upload_date)."'
- , '".addslashes($this->last_upload_date)."'
- , ".intval($_SESSION['id_session'])."
- )";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- $this->id = mysql_insert_id();
- }
-
-
- $sql="INSERT INTO ".dropbox_cnf("tbl_person")."
- (file_id, user_id)
- VALUES ('".addslashes($this->id)."'
- , '".addslashes($this->uploader_id)."'
- )";
- $result = api_sql_query($sql);
- }
-
-
- function _createExistingWork ($id) {
- global $_user;
-
-
- settype($id, 'integer') or die(dropbox_lang("generalError")." (code 205)");
-
- $sql="SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id
- FROM ".dropbox_cnf("tbl_file")."
- WHERE id='".addslashes($id)."'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- $res = mysql_fetch_array($result,MYSQL_ASSOC);
-
-
- $uploader_id = stripslashes($res["uploader_id"]);
- $uploaderName = getUserNameFromId($uploader_id);
- if ($uploaderName == FALSE) {
-
- $this->uploader_id = -1;
- $this->uploaderName = dropbox_lang("anonymous", "noDLTT");
- } else {
- $this->uploader_id = $uploader_id;
- $this->uploaderName = $uploaderName;
- }
-
-
- $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'];
-
-
-
- if ($_GET['action']=='viewfeedback' AND $this->id==$_GET['id']) {
- $feedback2=array();
- $sql_feedback = "SELECT * FROM ".dropbox_cnf("tbl_feedback")." WHERE file_id='".$id."' ORDER BY feedback_id ASC";
- $result = api_sql_query($sql_feedback, __FILE__, __LINE__);
- while ($row_feedback=Database::fetch_array($result)) {
- $feedback2[]=$row_feedback;
- }
- $this->feedback2=$feedback2;
- }
-
- }
- }
- class Dropbox_SentWork extends Dropbox_Work
- {
- var $recipients;
-
-
- 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 {
- $this->_createExistingSentWork ($arg1);
- }
- }
-
- function _createNewSentWork ($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) {
-
- $this->Dropbox_Work($uploader_id, $title, $description, $author, $filename, $filesize);
-
-
- settype($uploader_id, 'integer') or die(dropbox_lang("generalError")." (code 208)");
-
- $justSubmit = FALSE;
- if ( is_int($recipient_ids)) {
- $justSubmit = TRUE; $recipient_ids = array($recipient_ids + $this->id);
- } elseif ( count($recipient_ids) == 0) {
- $justSubmit = TRUE; $recipient_ids = array($uploader_id);
- }
- if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
- die(dropbox_lang("generalError")." (code 209)");
- }
- foreach ($recipient_ids as $rec) {
- if (empty($rec)) die(dropbox_lang("generalError")." (code 210)");
-
-
- $this->recipients[] = array("id"=>$rec, "name"=>getUserNameFromId($rec));
- }
-
-
- foreach ($this->recipients as $rec) {
- $sql="INSERT INTO ".dropbox_cnf("tbl_post")."
- (file_id, dest_user_id, session_id)
- VALUES ('".addslashes($this->id)."', '".addslashes($rec["id"])."', ".intval($_SESSION['id_session']).")";
- $result = api_sql_query($sql);
-
-
- $sql="INSERT INTO ".dropbox_cnf("tbl_person")."
- (file_id, user_id)
- VALUES ('".addslashes($this->id)."'
- , '".addslashes($rec["id"])."'
- )";
-
- if (!$justSubmit) {
- $result = api_sql_query($sql);
- }
-
-
- global $_course, $dropbox_cnf;
-
- if (($ownerid = $this->uploader_id) > $dropbox_cnf["mailingIdBase"]) {
- $ownerid = getUserOwningThisMailing($ownerid);
- }
- if (($recipid = $rec["id"]) > $dropbox_cnf["mailingIdBase"]) {
- $recipid = $ownerid;
- }
- api_item_property_update($_course, TOOL_DROPBOX, $this->id, "DropboxFileAdded", $ownerid, NULL, $recipid) ;
- }
- }
-
-
- function _createExistingSentWork ($id) {
-
- $this->Dropbox_Work($id);
-
-
- settype($id, 'integer') or die(dropbox_lang("generalError")." (code 211)");
-
- $this->recipients = array();
- $sql="SELECT dest_user_id, feedback_date, feedback
- FROM ".dropbox_cnf("tbl_post")."
- WHERE file_id='".addslashes($id)."'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- while ($res = Database::fetch_array($result)) {
-
- $dest_user_id = $res["dest_user_id"];
- $recipientName = getUserNameFromId($dest_user_id);
-
- if ($recipientName == FALSE) {
- $this->recipients[] = array("id"=>-1, "name"=> dropbox_lang("anonymous", "noDLTT"));
- } else {
- $this->recipients[] = array("id"=>$dest_user_id, "name"=>$recipientName, "user_id"=>$dest_user_id,
- "feedback_date"=>$res["feedback_date"], "feedback"=>$res["feedback"]);
- }
- }
- }
- }
- class Dropbox_Person
- {
- var $receivedWork;
- var $sentWork;
- var $userId = 0;
- var $isCourseAdmin = FALSE;
- var $isCourseTutor = FALSE;
- var $_orderBy = '';
-
-
- function Dropbox_Person ($userId, $isCourseAdmin, $isCourseTutor) {
-
- $this->userId = $userId;
- $this->isCourseAdmin = $isCourseAdmin;
- $this->isCourseTutor = $isCourseTutor;
- $this->receivedWork = array();
- $this->sentWork = array();
-
-
- $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);
-
- $sql = "SELECT r.file_id, r.cat_id
- FROM $post_tbl r, $person_tbl p
- WHERE r.dest_user_id = '".addslashes($this->userId)."'
- 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']);
- }
- $result = api_sql_query($sql,__FILE__,__LINE__);
- while ($res = Database::fetch_array($result)) {
- $temp = new Dropbox_Work($res["file_id"]);
- $temp -> category = $res['cat_id'];
- $this->receivedWork[] = $temp;
- }
-
- $sql = "SELECT f.id
- FROM $file_tbl f, $person_tbl p
- WHERE f.uploader_id = '".addslashes($this->userId)."'
- AND f.uploader_id = p.user_id
- AND f.id = p.file_id";
-
- if(intval($_SESSION['id_session']>0)) {
- $sql .= " AND f.session_id = ".intval($_SESSION['id_session']);
- }
- $result =api_sql_query($sql,__FILE__,__LINE__);
- while ($res = Database::fetch_array($result)) {
- $this->sentWork[] = new Dropbox_SentWork($res["id"]);
- }
- }
-
-
- function _cmpWork ($a, $b) {
- $sort = $this->_orderBy;
- $aval = $a->$sort;
- $bval = $b->$sort;
- if ($sort == 'recipients') {
- $aval = $aval[0]['name'];
- $bval = $bval[0]['name'];
- }
- if ($sort == 'filesize') {
- return $aval<$bval ? -1 : 1;
- } else {
- return strcasecmp($aval, $bval);
- }
- }
-
-
- function orderSentWork($sort) {
-
- switch($sort) {
- case 'lastDate':
- $this->_orderBy = 'last_upload_date';
- break;
- case 'firstDate':
- $this->_orderBy = 'upload_date';
- break;
- case 'title':
- $this->_orderBy = 'title';
- break;
- case 'size':
- $this->_orderBy = 'filesize';
- break;
- case 'author':
- $this->_orderBy = 'author';
- break;
- case 'recipient':
- $this->_orderBy = 'recipients';
- break;
- default:
- $this->_orderBy = 'last_upload_date';
- }
-
- usort($this->sentWork, array($this,"_cmpWork"));
- }
-
-
- function orderReceivedWork($sort) {
- switch($sort) {
- case 'lastDate':
- $this->_orderBy = 'last_upload_date';
- break;
- case 'firstDate':
- $this->_orderBy = 'upload_date';
- break;
- case 'title':
- $this->_orderBy = 'title';
- break;
- case 'size':
- $this->_orderBy = 'filesize';
- break;
- case 'author':
- $this->_orderBy = 'author';
- break;
- case 'sender':
- $this->_orderBy = 'uploaderName';
- break;
- default:
- $this->_orderBy = 'last_upload_date';
- }
-
- usort($this->receivedWork, array($this,"_cmpWork"));
- }
-
-
- function deleteAllReceivedWork () {
-
- foreach ($this->receivedWork as $w) {
- api_sql_query("DELETE FROM ".dropbox_cnf("tbl_person")." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'",__FILE__,__LINE__);
- }
- removeUnusedFiles();
- }
-
- function deleteReceivedWorkFolder($id) {
- $sql = "DELETE FROM ".dropbox_cnf("tbl_file")." where cat_id = '".$id."' ";
- if(!api_sql_query($sql)) return false;
- $sql = "DELETE FROM ".dropbox_cnf("tbl_category")." where cat_id = '".$id."' ";
- if(!api_sql_query($sql)) return false;
- $sql = "DELETE FROM ".dropbox_cnf("tbl_post")." where cat_id = '".$id."' ";
- if(!api_sql_query($sql)) return false;
- return true;
- }
-
- function deleteReceivedWork ($id) {
-
- $found = false;
- foreach($this->receivedWork as $w) {
- if ($w->id == $id) {
- $found = true;
- break;
- }
- }
- if (! $found) {
- if(!$this->deleteReceivedWorkFolder($id)) {
- die(dropbox_lang("generalError")." (code 216)");
- }
- }
-
- api_sql_query("DELETE FROM ".dropbox_cnf("tbl_person")." WHERE user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__);
- removeUnusedFiles();
- }
-
-
- function deleteAllSentWork () {
-
- foreach ($this->sentWork as $w) {
- api_sql_query("DELETE FROM ".dropbox_cnf("tbl_person")." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'",__FILE__,__LINE__);
- removeMoreIfMailing($w->id);
- }
- removeUnusedFiles();
- }
-
-
- function deleteSentWork ($id) {
-
- $found = false;
- foreach($this->sentWork as $w) {
- if ($w->id == $id) {
- $found = true;
- break;
- }
- }
- if (!$found) {
- if(!$this->deleteReceivedWorkFolder($id)) {
- die(dropbox_lang("generalError")." (code 219)");
- }
- }
-
-
- api_sql_query("DELETE FROM ".dropbox_cnf("tbl_person")." WHERE user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__);
- removeMoreIfMailing($id);
- removeUnusedFiles();
- }
-
-
- function updateFeedback($id, $text) {
- global $_course, $dropbox_cnf;
-
- $found = false; $wi = -1;
- foreach($this->receivedWork as $w) {
- $wi++;
- if ($w->id == $id){
- $found = true;
- break;
- }
- }
- if (! $found) {
- die(dropbox_lang("generalError")." (code 221)");
- }
-
- $feedback_date = date("Y-m-d H:i:s",time());
- $this->receivedWork[$wi]->feedback_date = $feedback_date;
- $this->receivedWork[$wi]->feedback = $text;
-
- api_sql_query("UPDATE ".dropbox_cnf("tbl_post")." SET feedback_date='".
- addslashes($feedback_date)."', feedback='".addslashes($text).
- "' WHERE dest_user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__);
-
-
- if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf["mailingIdBase"]) {
- $ownerid = getUserOwningThisMailing($ownerid);
- }
- api_item_property_update($_course, TOOL_DROPBOX, $this->receivedWork[$wi]->id, "DropboxFileUpdated", $this->userId, NULL, $ownerid) ;
- }
-
- function filter_received_work($type,$value) {
- global $dropbox_cnf;
-
- $new_received_work = array();
- foreach ($this->receivedWork as $index => $work) {
- switch ($type) {
- case 'uploader_id':
- if ($work->uploader_id == $value ||
- ($work->uploader_id > $dropbox_cnf["mailingIdBase"] &&
- getUserOwningThisMailing($work->uploader_id) == $value)) {
- $new_received_work[] = $work;
- }
- break;
- default:
- $new_received_work[] = $work;
- }
- }
- $this->receivedWork = $new_received_work;
- }
- }
|