dropbox_class.inc.php 23 KB

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