dropbox_class.inc.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. /*
  61.   +----------------------------------------------------------------------
  62.   |   This program is free software; you can redistribute it and/or     
  63.   |   modify it under the terms of the GNU General Public License       
  64.   |   as published by the Free Software Foundation; either version 2    
  65.   |   of the License, or (at your option) any later version.            
  66.   |                                                                     
  67.   |   This program is distributed in the hope that it will be useful,   
  68.   |   but WITHOUT ANY WARRANTY; without even the implied warranty of    
  69.   |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     
  70.   |   GNU General Public License for more details.                      
  71.   |                                                                      
  72.   |   You should have received a copy of the GNU General Public License 
  73.   |   along with this program; if not, write to the Free Software       
  74.   |   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA         
  75.   |   02111-1307, USA. The GNU GPL license is also available through    
  76.   |   the world-wide-web at http://www.gnu.org/copyleft/gpl.html        
  77.   +----------------------------------------------------------------------
  78. | Authors: Jan Bols <jan@ivpv.UGent.be> |
  79.   +----------------------------------------------------------------------
  80. */
  81. class Dropbox_Work {
  82. var $id;
  83. var $uploader_id;
  84. var $uploaderName;
  85. var $filename;
  86. var $filesize;
  87. var $title;
  88. var $description;
  89. var $author;
  90. var $upload_date;
  91. var $last_upload_date;
  92. var $isOldWork;
  93. var $feedback_date, $feedback; // RH: Feedback
  94. function Dropbox_Work ($arg1, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $arg6=null) {
  95. /*
  96. * Constructor calls private functions to create a new work or retreive an existing work from DB
  97. * depending on the number of parameters
  98. */
  99. if (func_num_args()>1) {
  100. $this->_createNewWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
  101. } else {
  102. $this->_createExistingWork($arg1);
  103. }
  104. }
  105. function _createNewWork ($uploader_id, $title, $description, $author, $filename, $filesize) {
  106. /*
  107. * private function creating a new work object
  108. */
  109. /*
  110. * Do some sanity checks
  111. */
  112. settype($uploader_id, 'integer') or die(dropbox_lang("generalError")." (code 201)"); //set $uploader_id to correct type
  113. //if (! isCourseMember($uploader_id)) die(); //uploader must be coursemember to be able to upload
  114. //-->this check is done when submitting data so it isn't checked here
  115. /*
  116. * Fill in the properties
  117. */
  118. $this->uploader_id = $uploader_id;
  119. $this->uploaderName = getUserNameFromId($this->uploader_id);
  120. $this->filename = $filename;
  121. $this->filesize = $filesize;
  122. $this->title = $title;
  123. $this->description = $description;
  124. $this->author = $author;
  125. $this->last_upload_date = date("Y-m-d H:i:s",time());
  126. /*
  127. * Check if object exists already. If it does, the old object is used
  128. * with updated information (authors, descriptio, upload_date)
  129. */
  130. $this->isOldWork = FALSE;
  131. $sql="SELECT id, upload_date
  132. FROM `".dropbox_cnf("fileTbl")."`
  133. WHERE filename = '".addslashes($this->filename)."'";
  134. $result = api_sql_query($sql,__FILE__,__LINE__);
  135. $res = mysql_fetch_array($result);
  136. if ($res != FALSE) $this->isOldWork = TRUE;
  137. /*
  138. * insert or update the dropbox_file table and set the id property
  139. */
  140. if ($this->isOldWork) {
  141. $this->id = $res["id"];
  142. $this->upload_date = $res["upload_date"];
  143. $sql = "UPDATE `".dropbox_cnf("fileTbl")."`
  144. SET filesize = '".addslashes($this->filesize)."'
  145. , title = '".addslashes($this->title)."'
  146. , description = '".addslashes($this->description)."'
  147. , author = '".addslashes($this->author)."'
  148. , last_upload_date = '".addslashes($this->last_upload_date)."'
  149. WHERE id='".addslashes($this->id)."'";
  150. $result = api_sql_query($sql,__FILE__,__LINE__);
  151. } else {
  152. $this->upload_date = $this->last_upload_date;
  153. $sql="INSERT INTO `".dropbox_cnf("fileTbl")."`
  154. (uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date)
  155. VALUES ('".addslashes($this->uploader_id)."'
  156. , '".addslashes($this->filename)."'
  157. , '".addslashes($this->filesize)."'
  158. , '".addslashes($this->title)."'
  159. , '".addslashes($this->description)."'
  160. , '".addslashes($this->author)."'
  161. , '".addslashes($this->upload_date)."'
  162. , '".addslashes($this->last_upload_date)."'
  163. )";
  164. $result = api_sql_query($sql,__FILE__,__LINE__);
  165. $this->id = mysql_insert_id(); //get automatically inserted id
  166. }
  167. /*
  168. * insert entries into person table
  169. */
  170. $sql="INSERT INTO `".dropbox_cnf("personTbl")."`
  171. (file_id, user_id)
  172. VALUES ('".addslashes($this->id)."'
  173. , '".addslashes($this->uploader_id)."'
  174. )";
  175. $result = api_sql_query($sql); //if work already exists no error is generated
  176. }
  177. function _createExistingWork ($id) {
  178. /*
  179. * private function creating existing object by retreiving info from db
  180. */
  181. global $_uid; // RH: Feedback
  182. /*
  183. * Do some sanity checks
  184. */
  185. settype($id, 'integer') or die(dropbox_lang("generalError")." (code 205)"); //set $id to correct type
  186. /*
  187. * get the data from DB
  188. */
  189. $sql="SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id
  190. FROM `".dropbox_cnf("fileTbl")."`
  191. WHERE id='".addslashes($id)."'";
  192. $result = api_sql_query($sql,__FILE__,__LINE__);
  193. $res = mysql_fetch_array($result,MYSQL_ASSOC);
  194. /*
  195. * Check if uploader is still in Dokeos system
  196. */
  197. $uploader_id = stripslashes($res["uploader_id"]);
  198. $uploaderName = getUserNameFromId($uploader_id);
  199. if ($uploaderName == FALSE) {
  200. //deleted user
  201. $this->uploader_id = -1;
  202. $this->uploaderName = dropbox_lang("anonymous", "noDLTT");
  203. } else {
  204. $this->uploader_id = $uploader_id;
  205. $this->uploaderName = $uploaderName;
  206. }
  207. /*
  208. * Fill in properties
  209. */
  210. $this->id = $id;
  211. $this->filename = stripslashes($res["filename"]);
  212. $this->filesize = stripslashes($res["filesize"]);
  213. $this->title = stripslashes($res["title"]);
  214. $this->description = stripslashes($res["description"]);
  215. $this->author = stripslashes($res["author"]);
  216. $this->upload_date = stripslashes($res["upload_date"]);
  217. $this->last_upload_date = stripslashes($res["last_upload_date"]);
  218. $this->category = $res['cat_id'];
  219. /*
  220. * Getting the feedback on the work.
  221. */
  222. if ($_GET['action']=='viewfeedback' AND $this->id==$_GET['id'])
  223. {
  224. $feedback2=array();
  225. $sql_feedback = "SELECT * FROM `".dropbox_cnf("tbl_feedback")."` WHERE file_id='".$id."' ORDER BY feedback_id ASC";
  226. $result = api_sql_query($sql_feedback, __FILE__, __LINE__);
  227. while ($row_feedback=mysql_fetch_array($result))
  228. {
  229. $feedback2[]=$row_feedback;
  230. }
  231. $this->feedback2=$feedback2;
  232. }
  233. /*
  234. // RH: Feedback
  235. $result = api_sql_query("SELECT feedback_date, feedback, cat_id FROM `".
  236. dropbox_cnf("postTbl")."` WHERE dest_user_id='".$_uid.
  237. "' AND file_id='".$id."'",__FILE__,__LINE__);
  238. if ($res = mysql_fetch_array($result))
  239. {
  240. $this->feedback_date = $res["feedback_date"];
  241. $this->feedback = $res["feedback"];
  242. $this->category = $res['cat_id'];
  243. } // do not fail if there is no recipient = current user...*/
  244. }
  245. }
  246. class Dropbox_SentWork extends Dropbox_Work {
  247. var $recipients; //array of ["id"]["name"] arrays
  248. function Dropbox_SentWork ($arg1, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $arg6=null, $arg7=null) {
  249. /*
  250. * Constructor calls private functions to create a new work or retreive an existing work from DB
  251. * depending on the number of parameters
  252. */
  253. if (func_num_args()>1) {
  254. $this->_createNewSentWork ($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7);
  255. } else {
  256. $this->_createExistingSentWork ($arg1);
  257. }
  258. }
  259. function _createNewSentWork ($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) {
  260. /*
  261. * private function creating a new SentWork object
  262. *
  263. * RH: Mailing: $recipient_ids is integer instead of array (mailing zip)
  264. */
  265. /*
  266. * Call constructor of Dropbox_Work object
  267. */
  268. $this->Dropbox_Work($uploader_id, $title, $description, $author, $filename, $filesize);
  269. /*
  270. * Do sanity checks on recipient_ids array & property fillin
  271. * The sanity check for ex-coursemembers is already done in base constructor
  272. */
  273. settype($uploader_id, 'integer') or die(dropbox_lang("generalError")." (code 208)"); //set $uploader_id to correct type
  274. $justSubmit = FALSE; // RH: mailing zip-file or just upload
  275. if ( is_int($recipient_ids))
  276. {
  277. $justSubmit = TRUE; $recipient_ids = array($recipient_ids + $this->id);
  278. }
  279. elseif ( count($recipient_ids) == 0) // RH: Just Upload
  280. {
  281. $justSubmit = TRUE; $recipient_ids = array($uploader_id);
  282. }
  283. if (! is_array($recipient_ids) || count($recipient_ids) == 0) die(dropbox_lang("generalError")." (code 209)");
  284. foreach ($recipient_ids as $rec) {
  285. if (empty($rec)) die(dropbox_lang("generalError")." (code 210)");
  286. //if (!isCourseMember($rec)) die(); //cannot sent document to someone outside of course
  287. //this check is done when validating submitted data
  288. $this->recipients[] = array("id"=>$rec, "name"=>getUserNameFromId($rec));
  289. }
  290. /*
  291. * insert data in dropbox_post and dropbox_person table for each recipient
  292. */
  293. foreach ($this->recipients as $rec) {
  294. $sql="INSERT INTO `".dropbox_cnf("postTbl")."`
  295. (file_id, dest_user_id)
  296. VALUES ('".addslashes($this->id)."', '".addslashes($rec["id"])."')";
  297. $result = api_sql_query($sql); //if work already exists no error is generated
  298. //insert entries into person table
  299. $sql="INSERT INTO `".dropbox_cnf("personTbl")."`
  300. (file_id, user_id)
  301. VALUES ('".addslashes($this->id)."'
  302. , '".addslashes($rec["id"])."'
  303. )";
  304. // RH: do not add recipient in person table if mailing zip or just upload
  305. if (!$justSubmit) $result = api_sql_query($sql); //if work already exists no error is generated
  306. //update item_property (previously last_tooledit) table for each recipient
  307. global $_course, $dropbox_cnf;
  308. if (($ownerid = $this->uploader_id) > $dropbox_cnf["mailingIdBase"])
  309. $ownerid = getUserOwningThisMailing($ownerid);
  310. if (($recipid = $rec["id"]) > $dropbox_cnf["mailingIdBase"])
  311. $recipid = $ownerid; // mailing file recipient = mailing id, not a person
  312. api_item_property_update($_course, TOOL_DROPBOX, $this->id, "DropboxFileAdded", $ownerid, NULL, $recipid) ;
  313. }
  314. }
  315. function _createExistingSentWork ($id) {
  316. /*
  317. * private function creating existing object by retreiving info from db
  318. */
  319. /*
  320. * Call constructor of Dropbox_Work object
  321. */
  322. $this->Dropbox_Work($id);
  323. /*
  324. * Do sanity check
  325. * The sanity check for ex-coursemembers is already done in base constructor
  326. */
  327. settype($id, 'integer') or die(dropbox_lang("generalError")." (code 211)"); //set $id to correct type
  328. /*
  329. * Fill in recipients array
  330. */
  331. $this->recipients = array(); // RH: Feedback: added to SELECT
  332. $sql="SELECT dest_user_id, feedback_date, feedback
  333. FROM `".dropbox_cnf("postTbl")."`
  334. WHERE file_id='".addslashes($id)."'";
  335. $result = api_sql_query($sql,__FILE__,__LINE__);
  336. while ($res = mysql_fetch_array($result)) {
  337. /*
  338. * check for deleted users
  339. */
  340. $dest_user_id = $res["dest_user_id"];
  341. $recipientName = getUserNameFromId($dest_user_id);
  342. //$this->category=$res['cat_id'];
  343. if ($recipientName == FALSE) {
  344. $this->recipients[] = array("id"=>-1, "name"=> dropbox_lang("anonymous", "noDLTT"));
  345. } else {
  346. $this->recipients[] = array("id"=>$dest_user_id, "name"=>$recipientName, "user_id"=>$dest_user_id,
  347. "feedback_date"=>$res["feedback_date"], "feedback"=>$res["feedback"]); // RH: Feedback
  348. }
  349. }
  350. }
  351. }
  352. class Dropbox_Person {
  353. var $receivedWork; //array of Dropbox_Work objects
  354. var $sentWork; //array of Dropbox_SentWork objects
  355. var $userId = 0;
  356. var $isCourseAdmin = FALSE;
  357. var $isCourseTutor = FALSE;
  358. var $_orderBy = ''; //private property that determines by which field
  359. //the receivedWork and the sentWork arrays are sorted
  360. function Dropbox_Person ($userId, $isCourseAdmin, $isCourseTutor) {
  361. /*
  362. * Constructor for recreating the Dropbox_Person object
  363. */
  364. /*
  365. * Fill in properties
  366. */
  367. $this->userId = $userId;
  368. $this->isCourseAdmin = $isCourseAdmin;
  369. $this->isCourseTutor = $isCourseTutor;
  370. $this->receivedWork = array();
  371. $this->sentWork = array();
  372. //Note: perhaps include an ex coursemember check to delete old files
  373. /*
  374. * find all entries where this person is the recipient
  375. */
  376. $sql = "SELECT r.file_id
  377. FROM
  378. `".dropbox_cnf("postTbl")."` r
  379. , `".dropbox_cnf("personTbl")."` p
  380. WHERE r.dest_user_id = '".addslashes($this->userId)."'
  381. AND r.dest_user_id = p.user_id
  382. AND r.file_id = p.file_id";
  383. $result = api_sql_query($sql,__FILE__,__LINE__);
  384. while ($res = mysql_fetch_array($result)) {
  385. $this->receivedWork[] = new Dropbox_Work($res["file_id"]);
  386. }
  387. /*
  388. * find all entries where this person is the sender/uploader
  389. */
  390. $sql = "SELECT f.id
  391. FROM `".dropbox_cnf("fileTbl")."` f, `".dropbox_cnf("personTbl")."` p
  392. WHERE f.uploader_id = '".addslashes($this->userId)."'
  393. AND f.uploader_id = p.user_id
  394. AND f.id = p.file_id";
  395. $result =api_sql_query($sql,__FILE__,__LINE__);
  396. while ($res = mysql_fetch_array($result)) {
  397. $this->sentWork[] = new Dropbox_SentWork($res["id"]);
  398. }
  399. }
  400. function _cmpWork ($a, $b) {
  401. /*
  402. * This private method is used by the usort function in the
  403. * orderSentWork and orderReceivedWork methods.
  404. * It compares 2 work-objects by 1 of the properties of that object, dictated by the
  405. * private property _orderBy.
  406. * It returns -1, 0 or 1 dependent of the result of the comparison.
  407. */
  408. $sort = $this->_orderBy;
  409. $aval = $a->$sort;
  410. $bval = $b->$sort;
  411. if ($sort == 'recipients') { //the recipients property is an array so we do the comparison based
  412. //on the first item of the recipients array
  413. $aval = $aval[0]['name'];
  414. $bval = $bval[0]['name'];
  415. }
  416. if ($sort == 'filesize') { //filesize is not a string, so we use other comparison technique
  417. return $aval<$bval ? -1 : 1;
  418. } else {
  419. return strcasecmp($aval, $bval);
  420. }
  421. }
  422. function orderSentWork($sort) {
  423. /*
  424. * method that sorts the objects in the sentWork array, dependent on the $sort parameter.
  425. * $sort can be lastDate, firstDate, title, size, ...
  426. */
  427. switch($sort){
  428. case 'lastDate':
  429. $this->_orderBy = 'last_upload_date';
  430. break;
  431. case 'firstDate':
  432. $this->_orderBy = 'upload_date';
  433. break;
  434. case 'title':
  435. $this->_orderBy = 'title';
  436. break;
  437. case 'size':
  438. $this->_orderBy = 'filesize';
  439. break;
  440. case 'author':
  441. $this->_orderBy = 'author';
  442. break;
  443. case 'recipient':
  444. $this->_orderBy = 'recipients';
  445. break;
  446. default:
  447. $this->_orderBy = 'last_upload_date';
  448. } // switch
  449. usort($this->sentWork, array($this,"_cmpWork")); //this calls the _cmpWork method
  450. }
  451. function orderReceivedWork($sort) {
  452. /*
  453. * method that sorts the objects in the receivedWork array, dependent on the $sort parameter.
  454. * $sort can be lastDate, firstDate, title, size, ...
  455. */
  456. switch($sort){
  457. case 'lastDate':
  458. $this->_orderBy = 'last_upload_date';
  459. break;
  460. case 'firstDate':
  461. $this->_orderBy = 'upload_date';
  462. break;
  463. case 'title':
  464. $this->_orderBy = 'title';
  465. break;
  466. case 'size':
  467. $this->_orderBy = 'filesize';
  468. break;
  469. case 'author':
  470. $this->_orderBy = 'author';
  471. break;
  472. case 'sender':
  473. $this->_orderBy = 'uploaderName';
  474. break;
  475. default:
  476. $this->_orderBy = 'last_upload_date';
  477. } // switch
  478. usort($this->receivedWork, array($this,"_cmpWork")); //this calls the _cmpWork method
  479. }
  480. function deleteAllReceivedWork () {
  481. /*
  482. * Deletes all the received work of this person
  483. */
  484. //delete entries in person table concerning received works
  485. foreach ($this->receivedWork as $w) {
  486. api_sql_query("DELETE FROM `".dropbox_cnf("personTbl")."` WHERE user_id='".$this->userId."' AND file_id='".$w->id."'",__FILE__,__LINE__);
  487. }
  488. removeUnusedFiles(); //check for unused files
  489. }
  490. function deleteReceivedWork ($id) {
  491. /*
  492. * Deletes a received work of this person with id=$id
  493. */
  494. //id check
  495. $found = false;
  496. foreach($this->receivedWork as $w) {
  497. if ($w->id == $id) {
  498. $found = true; break;
  499. }
  500. }
  501. if (! $found) die(dropbox_lang("generalError")." (code 216)");
  502. //delete entries in person table concerning received works
  503. api_sql_query("DELETE FROM `".dropbox_cnf("personTbl")."` WHERE user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__);
  504. removeUnusedFiles(); //check for unused files
  505. }
  506. function deleteAllSentWork () {
  507. /*
  508. * Deletes all the sent work of this person
  509. */
  510. //delete entries in person table concerning sent works
  511. foreach ($this->sentWork as $w) {
  512. api_sql_query("DELETE FROM `".dropbox_cnf("personTbl")."` WHERE user_id='".$this->userId."' AND file_id='".$w->id."'",__FILE__,__LINE__);
  513. removeMoreIfMailing($w->id); // RH: Mailing: see init1
  514. }
  515. removeUnusedFiles(); //check for unused files
  516. }
  517. function deleteSentWork ($id) {
  518. /*
  519. * Deletes a sent work of this person with id=$id
  520. */
  521. //index check
  522. $found = false;
  523. foreach($this->sentWork as $w) {
  524. if ($w->id == $id) {
  525. $found = true; break;
  526. }
  527. }
  528. if (!$found) die(dropbox_lang("generalError")." (code 219)");
  529. //$file_id = $this->sentWork[$index]->id; // RH: Mailing
  530. //delete entries in person table concerning sent works
  531. api_sql_query("DELETE FROM `".dropbox_cnf("personTbl")."` WHERE user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__);
  532. removeMoreIfMailing($id); // RH: Mailing: see init1
  533. removeUnusedFiles(); //check for unused files
  534. }
  535. function updateFeedback($id, $text) { // RH: Feedback
  536. /*
  537. * Updates feedback for received work of this person with id=$id
  538. */
  539. //id check
  540. $found = false; $wi = -1;
  541. foreach($this->receivedWork as $w) {
  542. $wi++; if ($w->id == $id) {
  543. $found = true; break;
  544. } // foreach (... as $wi -> $w) gives error 221! (no idea why...)
  545. }
  546. if (! $found) die(dropbox_lang("generalError")." (code 221)");
  547. $feedback_date = date("Y-m-d H:i:s",time());
  548. $this->receivedWork[$wi]->feedback_date = $feedback_date;
  549. $this->receivedWork[$wi]->feedback = $text;
  550. api_sql_query("UPDATE `".dropbox_cnf("postTbl")."` SET feedback_date='".
  551. addslashes($feedback_date)."', feedback='".addslashes($text).
  552. "' WHERE dest_user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__);
  553. //update item_property (previously last_tooledit) table
  554. global $_course, $dropbox_cnf;
  555. if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $dropbox_cnf["mailingIdBase"])
  556. $ownerid = getUserOwningThisMailing($ownerid);
  557. api_item_property_update($_course, TOOL_DROPBOX, $this->receivedWork[$wi]->id, "DropboxFileUpdated", $this->userId, NULL, $ownerid) ;
  558. }
  559. /**
  560. * Filter the received work
  561. * @param string $type
  562. * @param string $value
  563. */
  564. function filter_received_work($type,$value)
  565. {
  566. global $dropbox_cnf;
  567. $new_received_work = array();
  568. foreach($this->receivedWork as $index => $work)
  569. {
  570. switch($type)
  571. {
  572. case 'uploader_id':
  573. if ($work->uploader_id == $value ||
  574. ($work->uploader_id > $dropbox_cnf["mailingIdBase"] &&
  575. getUserOwningThisMailing($work->uploader_id) == $value))
  576. {
  577. $new_received_work[] = $work;
  578. }
  579. break;
  580. default:
  581. $new_received_work[] = $work;
  582. }
  583. }
  584. $this->receivedWork = $new_received_work;
  585. }
  586. }
  587. ?>