dokeos-dropbox
[ class tree: dokeos-dropbox ] [ index: dokeos-dropbox ] [ all elements ]

Source for file dropbox_class.inc.php

Documentation is available at dropbox_class.inc.php

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

Documentation generated on Thu, 12 Jun 2008 13:21:09 -0500 by phpDocumentor 1.4.1