dropbox_class.inc.php 22 KB

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