dropbox_class.inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php //$id: $
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Dropbox module for Dokeos
  5. * Classes for the dropbox module.
  6. *
  7. * 3 classes are defined:
  8. * - Dropbox_Work:
  9. * . id
  10. * . uploader_id => who sent it // RH: Mailing: or mailing pseudo_id
  11. * . uploaderName
  12. * . filename => name of file stored on the server
  13. * . filesize // RH: Mailing: zero for sent zip
  14. * . title => name of file returned to user. This is the original name of the file
  15. * except when the original name contained spaces. In that case the spaces
  16. * will be replaced by _
  17. * . description
  18. * . author
  19. * . upload_date => date when file was first sent
  20. * . last_upload_date=> date when file was last sent
  21. * . isOldWork => has the work already been uploaded before
  22. *
  23. * . feedback_date => date of most recent feedback // RH: Feedback
  24. * . feedback => feedback text (or HTML?) // RH: Feedback
  25. *
  26. * - Dropbox_SentWork extends Dropbox_Work
  27. * . recipients => array of ["id"]["name"] lists the recipients of the work
  28. * // RH: Mailing: or mailing pseudo_id
  29. * ["feedback_date"]["feedback"] // RH: Feedback
  30. * - Dropbox_Person:
  31. * . userId
  32. * . receivedWork => array of Dropbox_Work objects
  33. * . sentWork => array of Dropbox_SentWork objects
  34. * . isCourseTutor
  35. * . isCourseAdmin
  36. * . _orderBy =>private property used for determining the field by which the works have to be ordered
  37. *
  38. * @version 1.30
  39. * @copyright 2004
  40. * @author Jan Bols <jan@ivpv.UGent.be>
  41. * with contributions by René Haentjens <rene.haentjens@UGent.be> (see RH)
  42. * @package dokeos.dropbox
  43. */
  44. class Dropbox_Work {
  45. public $id;
  46. public $uploader_id;
  47. public $uploaderName;
  48. public $filename;
  49. public $filesize;
  50. public $title;
  51. public $description;
  52. public $author;
  53. public $upload_date;
  54. public $last_upload_date;
  55. public $isOldWork;
  56. public $feedback_date, $feedback; // RH: Feedback
  57. /**
  58. * Constructor calls private functions to create a new work or retreive an existing work from DB
  59. * depending on the number of parameters
  60. *
  61. * @param unknown_type $arg1
  62. * @param unknown_type $arg2
  63. * @param unknown_type $arg3
  64. * @param unknown_type $arg4
  65. * @param unknown_type $arg5
  66. * @param unknown_type $arg6
  67. * @return Dropbox_Work
  68. */
  69. function Dropbox_Work ($arg1, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $arg6=null) {
  70. if (func_num_args()>1) {
  71. $this->_createNewWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  72. } else {
  73. $this->_createExistingWork($arg1);
  74. }
  75. }
  76. /**
  77. * private function creating a new work object
  78. *
  79. * @param unknown_type $uploader_id
  80. * @param unknown_type $title
  81. * @param unknown_type $description
  82. * @param unknown_type $author
  83. * @param unknown_type $filename
  84. * @param unknown_type $filesize
  85. *
  86. * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads)
  87. * As a consequence this parameter can be removed
  88. */
  89. function _createNewWork ($uploader_id, $title, $description, $author, $filename, $filesize) {
  90. global $_user,$dropbox_cnf;
  91. // Do some sanity checks
  92. settype($uploader_id, 'integer') or die(dropbox_lang("generalError")." (code 201)"); //set $uploader_id to correct type
  93. //if (! isCourseMember($uploader_id)) die(); //uploader must be coursemember to be able to upload
  94. //-->this check is done when submitting data so it isn't checked here
  95. // Fill in the properties
  96. $this->uploader_id = $uploader_id;
  97. $this->uploaderName = getUserNameFromId($this->uploader_id);
  98. $this->filename = $filename;
  99. $this->filesize = $filesize;
  100. $this->title = $title;
  101. $this->description = $description;
  102. $this->author = api_get_person_name($_user['firstName'], $_user['lastName']);
  103. $this->last_upload_date = date("Y-m-d H:i:s",time());
  104. // Check if object exists already. If it does, the old object is used
  105. // with updated information (authors, descriptio, upload_date)
  106. $this->isOldWork = FALSE;
  107. $sql="SELECT id, upload_date
  108. FROM ".$dropbox_cnf["tbl_file"]."
  109. WHERE filename = '".Database::escape_string($this->filename)."'";
  110. $result = Database::query($sql);
  111. $res = Database::fetch_array($result);
  112. if ($res != FALSE) {
  113. $this->isOldWork = TRUE;
  114. }
  115. // insert or update the dropbox_file table and set the id property
  116. if ($this->isOldWork) {
  117. $this->id = $res["id"];
  118. $this->upload_date = $res["upload_date"];
  119. $sql = "UPDATE ".$dropbox_cnf["tbl_file"]."
  120. SET filesize = '".Database::escape_string($this->filesize)."'
  121. , title = '".Database::escape_string($this->title)."'
  122. , description = '".Database::escape_string($this->description)."'
  123. , author = '".Database::escape_string($this->author)."'
  124. , last_upload_date = '".Database::escape_string($this->last_upload_date)."'
  125. WHERE id='".Database::escape_string($this->id)."'";
  126. $result = Database::query($sql);
  127. } else {
  128. $this->upload_date = $this->last_upload_date;
  129. $sql="INSERT INTO ".$dropbox_cnf["tbl_file"]."
  130. (uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, session_id)
  131. VALUES ('".Database::escape_string($this->uploader_id)."'
  132. , '".Database::escape_string($this->filename)."'
  133. , '".Database::escape_string($this->filesize)."'
  134. , '".Database::escape_string($this->title)."'
  135. , '".Database::escape_string($this->description)."'
  136. , '".Database::escape_string($this->author)."'
  137. , '".Database::escape_string($this->upload_date)."'
  138. , '".Database::escape_string($this->last_upload_date)."'
  139. , ".intval($_SESSION['id_session'])."
  140. )";
  141. $result = Database::query($sql);
  142. $this->id = Database::insert_id(); //get automatically inserted id
  143. }
  144. // insert entries into person table
  145. $sql="INSERT INTO ".$dropbox_cnf["tbl_person"]."
  146. (file_id, user_id)
  147. VALUES ('".Database::escape_string($this->id)."'
  148. , '".Database::escape_string($this->uploader_id)."'
  149. )";
  150. $result = Database::query($sql); //if work already exists no error is generated
  151. }
  152. /**
  153. * private function creating existing object by retreiving info from db
  154. *
  155. * @param unknown_type $id
  156. */
  157. function _createExistingWork ($id) {
  158. global $_user,$dropbox_cnf; // RH: Feedback
  159. // Do some sanity checks
  160. settype($id, 'integer') or die(dropbox_lang("generalError")." (code 205)"); //set $id to correct type
  161. $id = intval($id);
  162. // get the data from DB
  163. $sql="SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id
  164. FROM ".$dropbox_cnf["tbl_file"]."
  165. WHERE id='".Database::escape_string($id)."'";
  166. $result = Database::query($sql);
  167. $res = Database::fetch_array($result, 'ASSOC');
  168. // Check if uploader is still in Dokeos system
  169. $uploader_id = stripslashes($res["uploader_id"]);
  170. $uploaderName = getUserNameFromId($uploader_id);
  171. if ($uploaderName == FALSE) {
  172. //deleted user
  173. $this->uploader_id = -1;
  174. $this->uploaderName = dropbox_lang("anonymous", "noDLTT");
  175. } else {
  176. $this->uploader_id = $uploader_id;
  177. $this->uploaderName = $uploaderName;
  178. }
  179. // Fill in properties
  180. $this->id = $id;
  181. $this->filename = stripslashes($res["filename"]);
  182. $this->filesize = stripslashes($res["filesize"]);
  183. $this->title = stripslashes($res["title"]);
  184. $this->description = stripslashes($res["description"]);
  185. $this->author = stripslashes($res["author"]);
  186. $this->upload_date = stripslashes($res["upload_date"]);
  187. $this->last_upload_date = stripslashes($res["last_upload_date"]);
  188. $this->category = $res['cat_id'];
  189. // Getting the feedback on the work.
  190. if ($_GET['action']=='viewfeedback' AND $this->id==$_GET['id']) {
  191. $feedback2=array();
  192. $sql_feedback = "SELECT * FROM ".$dropbox_cnf["tbl_feedback"]." WHERE file_id='".$id."' ORDER BY feedback_id ASC";
  193. $result = Database::query($sql_feedback);
  194. while ($row_feedback=Database::fetch_array($result)) {
  195. $row_feedback['feedback'] = Security::remove_XSS($row_feedback['feedback']);
  196. $feedback2[]=$row_feedback;
  197. }
  198. $this->feedback2= $feedback2;
  199. }
  200. /*
  201. // RH: Feedback
  202. $result = Database::query("SELECT feedback_date, feedback, cat_id FROM ".
  203. dropbox_cnf("tbl_post")." WHERE dest_user_id='".$_user['user_id'].
  204. "' AND file_id='".$id."'");
  205. if ($res = Database::fetch_array($result))
  206. {
  207. $this->feedback_date = $res["feedback_date"];
  208. $this->feedback = $res["feedback"];
  209. $this->category = $res['cat_id'];
  210. } // do not fail if there is no recipient = current user...*/
  211. }
  212. }
  213. class Dropbox_SentWork extends Dropbox_Work
  214. {
  215. public $recipients; //array of ["id"]["name"] arrays
  216. /**
  217. * Constructor calls private functions to create a new work or retreive an existing work from DB
  218. * depending on the number of parameters
  219. *
  220. * @param unknown_type $arg1
  221. * @param unknown_type $arg2
  222. * @param unknown_type $arg3
  223. * @param unknown_type $arg4
  224. * @param unknown_type $arg5
  225. * @param unknown_type $arg6
  226. * @param unknown_type $arg7
  227. * @return Dropbox_SentWork
  228. */
  229. function Dropbox_SentWork ($arg1, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $arg6=null, $arg7=null) {
  230. if (func_num_args()>1) {
  231. $this->_createNewSentWork ($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
  232. } else {
  233. $this->_createExistingSentWork ($arg1);
  234. }
  235. }
  236. /**
  237. * private function creating a new SentWork object
  238. *
  239. * @param unknown_type $uploader_id
  240. * @param unknown_type $title
  241. * @param unknown_type $description
  242. * @param unknown_type $author
  243. * @param unknown_type $filename
  244. * @param unknown_type $filesize
  245. * @param unknown_type $recipient_ids
  246. */
  247. function _createNewSentWork ($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) {
  248. global $dropbox_cnf;
  249. // Call constructor of Dropbox_Work object
  250. $this->Dropbox_Work($uploader_id, $title, $description, $author, $filename, $filesize);
  251. // Do sanity checks on recipient_ids array & property fillin
  252. // The sanity check for ex-coursemembers is already done in base constructor
  253. settype($uploader_id, 'integer') or die(dropbox_lang("generalError")." (code 208)"); //set $uploader_id to correct type
  254. $justSubmit = FALSE; // RH: mailing zip-file or just upload
  255. if ( is_int($recipient_ids)) {
  256. $justSubmit = TRUE; $recipient_ids = array($recipient_ids + $this->id);
  257. } elseif ( count($recipient_ids) == 0) { // RH: Just Upload
  258. $justSubmit = TRUE; $recipient_ids = array($uploader_id);
  259. }
  260. if (! is_array($recipient_ids) || count($recipient_ids) == 0) {
  261. die(dropbox_lang("generalError")." (code 209)");
  262. }
  263. foreach ($recipient_ids as $rec) {
  264. if (empty($rec)) die(dropbox_lang("generalError")." (code 210)");
  265. //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
  266. //this check is done when validating submitted data
  267. $this->recipients[] = array("id"=>$rec, "name"=>getUserNameFromId($rec));
  268. }
  269. // insert data in dropbox_post and dropbox_person table for each recipient
  270. foreach ($this->recipients as $rec) {
  271. $sql="INSERT INTO ".$dropbox_cnf["tbl_post"]."
  272. (file_id, dest_user_id, session_id)
  273. VALUES ('".Database::escape_string($this->id)."', '".Database::escape_string($rec["id"])."', ".intval($_SESSION['id_session']).")";
  274. $result = Database::query($sql); //if work already exists no error is generated
  275. //insert entries into person table
  276. $sql="INSERT INTO ".$dropbox_cnf["tbl_person"]."
  277. (file_id, user_id)
  278. VALUES ('".Database::escape_string($this->id)."'
  279. , '".Database::escape_string($rec["id"])."'
  280. )";
  281. // RH: do not add recipient in person table if mailing zip or just upload
  282. if (!$justSubmit) {
  283. $result = Database::query($sql); //if work already exists no error is generated
  284. }
  285. //update item_property (previously last_tooledit) table for each recipient
  286. global $_course, $dropbox_cnf;
  287. if (($ownerid = $this->uploader_id) > $dropbox_cnf["mailingIdBase"]) {
  288. $ownerid = getUserOwningThisMailing($ownerid);
  289. }
  290. if (($recipid = $rec["id"]) > $dropbox_cnf["mailingIdBase"]) {
  291. $recipid = $ownerid; // mailing file recipient = mailing id, not a person
  292. }
  293. api_item_property_update($_course, TOOL_DROPBOX, $this->id, "DropboxFileAdded", $ownerid, NULL, $recipid) ;
  294. }
  295. }
  296. /**
  297. * private function creating existing object by retreiving info from db
  298. *
  299. * @param unknown_type $id
  300. */
  301. function _createExistingSentWork ($id) {
  302. global $dropbox_cnf;
  303. // Call constructor of Dropbox_Work object
  304. $this->Dropbox_Work($id);
  305. // Do sanity check. The sanity check for ex-coursemembers is already done in base constructor
  306. settype($id, 'integer') or die(dropbox_lang("generalError")." (code 211)"); //set $id to correct type
  307. //Fill in recipients array/
  308. $this->recipients = array(); // RH: Feedback: added to SELECT
  309. $sql="SELECT dest_user_id, feedback_date, feedback
  310. FROM ".$dropbox_cnf["tbl_post"]."
  311. WHERE file_id='".Database::escape_string($id)."'";
  312. $result = Database::query($sql);
  313. while ($res = Database::fetch_array($result)) {
  314. // check for deleted users
  315. $dest_user_id = $res["dest_user_id"];
  316. $recipientName = getUserNameFromId($dest_user_id);
  317. //$this->category=$res['cat_id'];
  318. if ($recipientName == FALSE) {
  319. $this->recipients[] = array("id"=>-1, "name"=> dropbox_lang("anonymous", "noDLTT"));
  320. } else {
  321. $this->recipients[] = array("id"=>$dest_user_id, "name"=>$recipientName, "user_id"=>$dest_user_id,
  322. "feedback_date"=>$res["feedback_date"], "feedback"=>$res["feedback"]); // RH: Feedback
  323. }
  324. }
  325. }
  326. }
  327. class Dropbox_Person
  328. {
  329. public $receivedWork; //array of Dropbox_Work objects
  330. public $sentWork; //array of Dropbox_SentWork objects
  331. public $userId = 0;
  332. public $isCourseAdmin = FALSE;
  333. public $isCourseTutor = FALSE;
  334. public $_orderBy = ''; //private property that determines by which field
  335. //the receivedWork and the sentWork arrays are sorted
  336. /**
  337. * Constructor for recreating the Dropbox_Person object
  338. *
  339. * @param unknown_type $userId
  340. * @param unknown_type $isCourseAdmin
  341. * @param unknown_type $isCourseTutor
  342. * @return Dropbox_Person
  343. */
  344. function Dropbox_Person ($userId, $isCourseAdmin, $isCourseTutor) {
  345. // Fill in properties
  346. $this->userId = $userId;
  347. $this->isCourseAdmin = $isCourseAdmin;
  348. $this->isCourseTutor = $isCourseTutor;
  349. $this->receivedWork = array();
  350. $this->sentWork = array();
  351. //Note: perhaps include an ex coursemember check to delete old files
  352. $session_id = api_get_session_id();
  353. $condition_session = api_get_session_condition($session_id);
  354. $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST);
  355. $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON);
  356. $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
  357. // find all entries where this person is the recipient
  358. $sql = "SELECT r.file_id, r.cat_id
  359. FROM $post_tbl r, $person_tbl p
  360. WHERE r.dest_user_id = '".Database::escape_string($this->userId)."'
  361. AND r.dest_user_id = p.user_id
  362. AND r.file_id = p.file_id $condition_session";
  363. //if (intval($_SESSION['id_session']>0)) { $sql .= " AND r.session_id = ".intval($_SESSION['id_session']); }
  364. $result = Database::query($sql);
  365. while ($res = Database::fetch_array($result)) {
  366. $temp = new Dropbox_Work($res["file_id"]);
  367. $temp -> category = $res['cat_id'];
  368. $this->receivedWork[] = $temp;
  369. }
  370. // find all entries where this person is the sender/uploader
  371. $sql = "SELECT f.id
  372. FROM $file_tbl f, $person_tbl p
  373. WHERE f.uploader_id = '".Database::escape_string($this->userId)."'
  374. AND f.uploader_id = p.user_id
  375. AND f.id = p.file_id $condition_session";
  376. //if(intval($_SESSION['id_session']>0)) { $sql .= " AND f.session_id = ".intval($_SESSION['id_session']); }
  377. $result =Database::query($sql);
  378. while ($res = Database::fetch_array($result)) {
  379. $this->sentWork[] = new Dropbox_SentWork($res["id"]);
  380. }
  381. }
  382. /**
  383. * This private method is used by the usort function in the
  384. * orderSentWork and orderReceivedWork methods.
  385. * It compares 2 work-objects by 1 of the properties of that object, dictated by the
  386. * private property _orderBy
  387. *
  388. * @param unknown_type $a
  389. * @param unknown_type $b
  390. * @return -1, 0 or 1 dependent of the result of the comparison.
  391. */
  392. function _cmpWork ($a, $b) {
  393. $sort = $this->_orderBy;
  394. $aval = $a->$sort;
  395. $bval = $b->$sort;
  396. if ($sort == 'recipients') { //the recipients property is an array so we do the comparison based on the first item of the recipients array
  397. $aval = $aval[0]['name'];
  398. $bval = $bval[0]['name'];
  399. }
  400. if ($sort == 'filesize') { //filesize is not a string, so we use other comparison technique
  401. return $aval<$bval ? -1 : 1;
  402. } elseif ($sort == 'title') { // natural order for sorting titles is more "human-friendly"
  403. return api_strnatcmp($aval, $bval);
  404. } else {
  405. return api_strcasecmp($aval, $bval);
  406. }
  407. }
  408. /**
  409. * method that sorts the objects in the sentWork array, dependent on the $sort parameter.
  410. * $sort can be lastDate, firstDate, title, size, ...
  411. *
  412. * @param unknown_type $sort
  413. */
  414. function orderSentWork($sort) {
  415. /*
  416. */
  417. switch($sort) {
  418. case 'lastDate':
  419. $this->_orderBy = 'last_upload_date';
  420. break;
  421. case 'firstDate':
  422. $this->_orderBy = 'upload_date';
  423. break;
  424. case 'title':
  425. $this->_orderBy = 'title';
  426. break;
  427. case 'size':
  428. $this->_orderBy = 'filesize';
  429. break;
  430. case 'author':
  431. $this->_orderBy = 'author';
  432. break;
  433. case 'recipient':
  434. $this->_orderBy = 'recipients';
  435. break;
  436. default:
  437. $this->_orderBy = 'last_upload_date';
  438. } // switch
  439. usort($this->sentWork, array($this,"_cmpWork")); //this calls the _cmpWork method
  440. }
  441. /**
  442. * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
  443. * $sort can be lastDate, firstDate, title, size, ...
  444. * @param unknown_type $sort
  445. */
  446. function orderReceivedWork($sort) {
  447. switch($sort) {
  448. case 'lastDate':
  449. $this->_orderBy = 'last_upload_date';
  450. break;
  451. case 'firstDate':
  452. $this->_orderBy = 'upload_date';
  453. break;
  454. case 'title':
  455. $this->_orderBy = 'title';
  456. break;
  457. case 'size':
  458. $this->_orderBy = 'filesize';
  459. break;
  460. case 'author':
  461. $this->_orderBy = 'author';
  462. break;
  463. case 'sender':
  464. $this->_orderBy = 'uploaderName';
  465. break;
  466. default:
  467. $this->_orderBy = 'last_upload_date';
  468. } // switch
  469. usort($this->receivedWork, array($this,"_cmpWork")); //this calls the _cmpWork method
  470. }
  471. /**
  472. * Deletes all the received work of this person
  473. *
  474. */
  475. function deleteAllReceivedWork () {
  476. global $dropbox_cnf;
  477. //delete entries in person table concerning received works
  478. foreach ($this->receivedWork as $w) {
  479. Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'");
  480. }
  481. removeUnusedFiles(); //check for unused files
  482. }
  483. /**
  484. * Deletes all the received categories and work of this person
  485. */
  486. function deleteReceivedWorkFolder($id) {
  487. global $dropbox_cnf;
  488. $id = intval($id);
  489. $sql = "DELETE FROM ".$dropbox_cnf["tbl_file"]." where cat_id = '".$id."' ";
  490. if(!Database::query($sql)) return false;
  491. $sql = "DELETE FROM ".$dropbox_cnf["tbl_category"]." where cat_id = '".$id."' ";
  492. if(!Database::query($sql)) return false;
  493. $sql = "DELETE FROM ".$dropbox_cnf["tbl_post"]." where cat_id = '".$id."' ";
  494. if(!Database::query($sql)) return false;
  495. return true;
  496. }
  497. /**
  498. * Deletes a received dropbox file of this person with id=$id
  499. *
  500. * @param integer $id
  501. */
  502. function deleteReceivedWork ($id) {
  503. $id = intval($id);
  504. global $dropbox_cnf;
  505. //id check
  506. $found = false;
  507. foreach($this->receivedWork as $w) {
  508. if ($w->id == $id) {
  509. $found = true;
  510. break;
  511. }
  512. }
  513. if (! $found) {
  514. if(!$this->deleteReceivedWorkFolder($id)) {
  515. die(dropbox_lang("generalError")." (code 216)");
  516. }
  517. }
  518. //delete entries in person table concerning received works
  519. Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$id."'");
  520. removeUnusedFiles(); //check for unused files
  521. }
  522. /**
  523. * Deletes all the sent dropbox files of this person
  524. */
  525. function deleteAllSentWork () {
  526. global $dropbox_cnf;
  527. //delete entries in person table concerning sent works
  528. foreach ($this->sentWork as $w) {
  529. Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'");
  530. removeMoreIfMailing($w->id); // RH: Mailing: see init1
  531. }
  532. removeUnusedFiles(); //check for unused files
  533. }
  534. /**
  535. * Deletes a sent dropbox file of this person with id=$id
  536. *
  537. * @param unknown_type $id
  538. */
  539. function deleteSentWork ($id) {
  540. $id = intval($id);
  541. global $dropbox_cnf;
  542. //index check
  543. $found = false;
  544. foreach($this->sentWork as $w) {
  545. if ($w->id == $id) {
  546. $found = true;
  547. break;
  548. }
  549. }
  550. if (!$found) {
  551. if(!$this->deleteReceivedWorkFolder($id)) {
  552. die(dropbox_lang("generalError")." (code 219)");
  553. }
  554. }
  555. //$file_id = $this->sentWork[$index]->id; // RH: Mailing
  556. //delete entries in person table concerning sent works
  557. Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$id."'");
  558. removeMoreIfMailing($id); // RH: Mailing: see init1
  559. removeUnusedFiles(); //check for unused files
  560. }
  561. /**
  562. * Updates feedback for received work of this person with id=$id
  563. *
  564. * @param unknown_type $id
  565. * @param unknown_type $text
  566. */
  567. function updateFeedback($id, $text) {
  568. global $_course, $dropbox_cnf;
  569. $id = intval($id);
  570. //id check
  571. $found = false; $wi = -1;
  572. foreach($this->receivedWork as $w) {
  573. $wi++;
  574. if ($w->id == $id){
  575. $found = true;
  576. break;
  577. } // foreach (... as $wi -> $w) gives error 221! (no idea why...)
  578. }
  579. if (! $found) {
  580. die(dropbox_lang("generalError")." (code 221)");
  581. }
  582. $feedback_date = date("Y-m-d H:i:s",time());
  583. $this->receivedWork[$wi]->feedback_date = $feedback_date;
  584. $this->receivedWork[$wi]->feedback = $text;
  585. Database::query("UPDATE ".$dropbox_cnf["tbl_post"]." SET feedback_date='".
  586. Database::escape_string($feedback_date)."', feedback='".Database::escape_string($text).
  587. "' WHERE dest_user_id='".$this->userId."' AND file_id='".$id."'");
  588. //update item_property (previously last_tooledit) table
  589. if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf["mailingIdBase"]) {
  590. $ownerid = getUserOwningThisMailing($ownerid);
  591. }
  592. api_item_property_update($_course, TOOL_DROPBOX, $this->receivedWork[$wi]->id, "DropboxFileUpdated", $this->userId, NULL, $ownerid) ;
  593. }
  594. /**
  595. * Filter the received work
  596. * @param string $type
  597. * @param string $value
  598. */
  599. function filter_received_work($type,$value) {
  600. global $dropbox_cnf;
  601. $new_received_work = array();
  602. foreach ($this->receivedWork as $index => $work) {
  603. switch ($type) {
  604. case 'uploader_id':
  605. if ($work->uploader_id == $value ||
  606. ($work->uploader_id > $dropbox_cnf["mailingIdBase"] &&
  607. getUserOwningThisMailing($work->uploader_id) == $value)) {
  608. $new_received_work[] = $work;
  609. }
  610. break;
  611. default:
  612. $new_received_work[] = $work;
  613. }
  614. }
  615. $this->receivedWork = $new_received_work;
  616. }
  617. }