dropbox_class.inc.php 24 KB

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