dropbox_class.inc.php 24 KB

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