Bläddra i källkod

Minor - format code.

Julio Montoya 11 år sedan
förälder
incheckning
a3d5f73a84

+ 36 - 29
main/dropbox/dropbox_class.inc.php

@@ -56,26 +56,26 @@ class Dropbox_Work
     public $isOldWork;
     public $feedback_date, $feedback;
 
-	/**
-	 * Constructor calls private functions to create a new work or retreive an existing work from DB
-	 * depending on the number of parameters
-	 *
-	 * @param unknown_type $arg1
-	 * @param unknown_type $arg2
-	 * @param unknown_type $arg3
-	 * @param unknown_type $arg4
-	 * @param unknown_type $arg5
-	 * @param unknown_type $arg6
-	 * @return Dropbox_Work
-	 */
-	function Dropbox_Work($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null)
+    /**
+     * Constructor calls private functions to create a new work or retreive an existing work from DB
+     * depending on the number of parameters
+     *
+     * @param unknown_type $arg1
+     * @param unknown_type $arg2
+     * @param unknown_type $arg3
+     * @param unknown_type $arg4
+     * @param unknown_type $arg5
+     * @param unknown_type $arg6
+     * @return Dropbox_Work
+     */
+    function Dropbox_Work($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null)
     {
-		if (func_num_args() > 1)  {
-		    $this->_createNewWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
-		}  else  {
-			$this->_createExistingWork($arg1);
-		}
-	}
+        if (func_num_args() > 1) {
+            $this->_createNewWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6);
+        }  else  {
+            $this->_createExistingWork($arg1);
+        }
+    }
 
 	/**
 	 * private function creating a new work object
@@ -164,9 +164,9 @@ class Dropbox_Work
 	 *
 	 * @param unknown_type $id
 	 */
-	function _createExistingWork($id) {
+	function _createExistingWork($id)
+    {
 	    $course_id = api_get_course_int_id();
-
 		global $_user, $dropbox_cnf;
 
 		// Do some sanity checks
@@ -443,7 +443,8 @@ class Dropbox_Person
 	 * @param unknown_type $b
 	 * @return -1, 0 or 1 dependent of the result of the comparison.
 	 */
-	function _cmpWork($a, $b) {
+	function _cmpWork($a, $b)
+    {
 		$sort = $this->_orderBy;
 		$aval = $a->$sort;
 		$bval = $b->$sort;
@@ -466,7 +467,8 @@ class Dropbox_Person
 	 *
 	 * @param unknown_type $sort
 	 */
-	function orderSentWork($sort) {
+	function orderSentWork($sort)
+    {
 		switch($sort) {
 			case 'lastDate':
 				$this->_orderBy = 'last_upload_date';
@@ -561,7 +563,8 @@ class Dropbox_Person
 	 *
 	 * @param integer $id
 	 */
-	function deleteReceivedWork($id) {
+	function deleteReceivedWork($id)
+    {
 	    $course_id = api_get_course_int_id();
 		global $dropbox_cnf;
 		$id = intval($id);
@@ -588,7 +591,8 @@ class Dropbox_Person
 	/**
 	 * Deletes all the sent dropbox files of this person
 	 */
-	function deleteAllSentWork() {
+	function deleteAllSentWork()
+    {
 	    $course_id = api_get_course_int_id();
 		global $dropbox_cnf;
 		//delete entries in person table concerning sent works
@@ -604,7 +608,8 @@ class Dropbox_Person
 	 *
 	 * @param unknown_type $id
 	 */
-	function deleteSentWork($id) {
+	function deleteSentWork($id)
+    {
 	    $course_id = api_get_course_int_id();
 
 		global $dropbox_cnf;
@@ -636,7 +641,8 @@ class Dropbox_Person
 	 * @param unknown_type $id
 	 * @param unknown_type $text
 	 */
-	function updateFeedback($id, $text) {
+	function updateFeedback($id, $text)
+    {
 	    $course_id = api_get_course_int_id();
 
 		global $_course, $dropbox_cnf;
@@ -678,11 +684,12 @@ class Dropbox_Person
 	 * @param string $type
 	 * @param string $value
 	 */
-	function filter_received_work($type, $value) {
+	function filter_received_work($type, $value)
+    {
 		global $dropbox_cnf;
 
     	$new_received_work = array();
-		foreach ($this->receivedWork as $index => $work) {
+		foreach ($this->receivedWork as $work) {
 			switch ($type) {
 				case 'uploader_id':
 					if ($work->uploader_id == $value ||

+ 24 - 24
main/dropbox/dropbox_download.php

@@ -37,37 +37,37 @@ if (isset($_GET['cat_id']) AND is_numeric($_GET['cat_id']) AND $_GET['action'] =
 	// in dropbox_person (which stores the link file-person)
 	// Therefore we have to create to separate sql statements to find which files are in the categorie (depending if we zip-download a sent category or a
 	// received category)
-    
+
 	if ($_GET['sent_received'] == 'sent') {
 		// here we also incorporate the person table to make sure that deleted sent documents are not included.
-		$sql = "SELECT DISTINCT file.id, file.filename, file.title 
-                FROM ".$dropbox_cnf['tbl_file']." file INNER JOIN ".$dropbox_cnf['tbl_person']." person 
+		$sql = "SELECT DISTINCT file.id, file.filename, file.title
+                FROM ".$dropbox_cnf['tbl_file']." file INNER JOIN ".$dropbox_cnf['tbl_person']." person
                 ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
-				WHERE 
-                    file.uploader_id = $user_id AND 
-                    file.cat_id='".intval($_GET['cat_id'])."'  AND 
+				WHERE
+                    file.uploader_id = $user_id AND
+                    file.cat_id='".intval($_GET['cat_id'])."'  AND
                     person.user_id = $user_id";
 	}
-    
+
 	if ($_GET['sent_received'] == 'received') {
-		$sql = "SELECT DISTINCT file.id, file.filename, file.title 
+		$sql = "SELECT DISTINCT file.id, file.filename, file.title
                 FROM ".$dropbox_cnf['tbl_file']." file INNER JOIN ".$dropbox_cnf['tbl_person']." person
                 ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
                 INNER JOIN ".$dropbox_cnf['tbl_post']." post
                 ON (post.file_id = file.id AND post.c_id = $course_id AND file.c_id = $course_id)
-				WHERE 
-                    post.cat_id = ".intval($_GET['cat_id'])." AND 
+				WHERE
+                    post.cat_id = ".intval($_GET['cat_id'])." AND
                     post.dest_user_id = $user_id" ;
-	}    
-    
+	}
+
 	$result = Database::query($sql);
 	while ($row = Database::fetch_array($result)) {
 		$files_to_download[] = $row['id'];
-	}    
+	}
 	if (!is_array($files_to_download) OR empty($files_to_download)) {
 		header('location: index.php?view='.Security::remove_XSS($_GET['sent_received']).'&error=ErrorNoFilesInFolder');
 		exit;
-	}    
+	}
 	zip_download($files_to_download);
 	exit;
 }
@@ -99,36 +99,36 @@ if (!$allowed_to_download) {
 	Display::display_error_message(get_lang('YouAreNotAllowedToDownloadThisFile'));
 	Display::display_footer();
 	exit;
-} else {    
-    /*      DOWNLOAD THE FILE */    
+} else {
+    /*      DOWNLOAD THE FILE */
     // the user is allowed to download the file
 	$_SESSION['_seen'][$_course['id']][TOOL_DROPBOX][] = intval($_GET['id']);
 
 	$work = new Dropbox_work($_GET['id']);
 	$path = dropbox_cnf('sysPath') . '/' . $work -> filename; //path to file as stored on server
-	
+
     if (!Security::check_abs_path($path, dropbox_cnf('sysPath').'/')) {
     	exit;
     }
-	$file = $work->title;	
+	$file = $work->title;
 	$mimetype = DocumentManager::file_get_mime_type(true);
 	$fileinfo = pathinfo($file);
 	$extension = $fileinfo['extension'];
-	
-	if (!empty($extension) && isset($mimetype[$extension]) && $_GET['action'] != 'download') {		
+
+	if (!empty($extension) && isset($mimetype[$extension]) && $_GET['action'] != 'download') {
 	    // give hint to browser about filetype
     	header( 'Content-type: ' . $mimetype[$extension] . "\n");
 	} else {
 		//no information about filetype: force a download dialog window in browser
 		header( "Content-type: application/octet-stream\n");
 	}
-	
+
 	/*if (!in_array(strtolower($extension), array('doc', 'xls', 'ppt', 'pps', 'sxw', 'sxc', 'sxi'))) {
 		header('Content-Disposition: inline; filename='.$file); // bugs with open office
 	} else {
 		header('Content-Disposition: attachment; filename='.$file);
 	}*/
-	
+
 	header('Content-Disposition: attachment; filename='.$file);
 
 	/**
@@ -153,10 +153,10 @@ if (!$allowed_to_download) {
 	    header("Cache-Control: no-store, no-cache, must-revalidate\n"); // HTTP/1.1
 	    header("Cache-Control: post-check=0, pre-check=0\n", false);
 	}*/
-	
+
 	header('Content-Description: '.trim(htmlentities($file)));
 	header('Content-transfer-encoding: binary');
-	
+
 	header("Content-Length: " . filesize($path)."\n" );
 
 	$fp = fopen( $path, 'rb');

+ 42 - 39
main/dropbox/dropbox_functions.inc.php

@@ -37,10 +37,10 @@ function handle_multiple_actions() {
 
 	// STEP 2: at least one file has to be selected. If not we return an error message
     $ids = Request::get('id', array());
-    if(count($ids)>0){        
+    if(count($ids)>0){
         $checked_file_ids = $_POST['id'];
     }
-    else{      
+    else{
         foreach ($_POST as $key => $value) {
             if (strstr($value, $part.'_') AND $key != 'view_received_category' AND $key != 'view_sent_category') {
                 $checked_files = true;
@@ -112,11 +112,11 @@ function delete_category($action, $id, $user_id = null) {
 
 	global $dropbox_cnf;
 	global $is_courseAdmin, $is_courseTutor;
-    
+
     if (empty($user_id)) {
         $user_id = api_get_user_id();
     }
-    
+
     $cat = get_dropbox_category($id);
     if (count($cat)==0) { return false; }
     if ($cat['user_id'] != $user_id && !api_is_platform_admin($user_id)) {
@@ -166,7 +166,8 @@ function delete_category($action, $id, $user_id = null) {
 * @author Julio Montoya - function rewritten
 
 */
-function display_move_form($part, $id, $target = array(), $extra_params = array()) {
+function display_move_form($part, $id, $target = array(), $extra_params = array())
+{
     $form = new FormValidator('form1', 'post', api_get_self().'?view_received_category='.Security::remove_XSS($_GET['view_received_category']).'&view_sent_category='.Security::remove_XSS($_GET['view_sent_category']).'&view='.Security::remove_XSS($_GET['view']).'&'.$extra_params);
 	$form->addElement('header', get_lang('MoveFileTo'));
     $form->addElement('hidden', 'id', intval($id));
@@ -194,12 +195,13 @@ function display_move_form($part, $id, $target = array(), $extra_params = array(
 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 * @version march 2006
 */
-function store_move($id, $target, $part) {
+function store_move($id, $target, $part)
+{
 	global $_user, $dropbox_cnf;
     $course_id = api_get_course_int_id();
 
 	if ((isset($id) AND $id != '') AND (isset($target) AND $target != '') AND (isset($part) AND $part != '')) {
-        
+
 		if ($part == 'received') {
 			$sql = "UPDATE ".$dropbox_cnf["tbl_post"]." SET cat_id='".Database::escape_string($target)."'
 						WHERE c_id = $course_id AND dest_user_id='".Database::escape_string($_user['user_id'])."'
@@ -229,7 +231,8 @@ function store_move($id, $target, $part) {
 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 * @version march 2006
 */
-function display_action_options($part, $categories, $current_category = 0) {
+function display_action_options($part, $categories, $current_category = 0)
+{
 	echo '<select name="actions">';
 	echo '<option value="download">'.get_lang('Download').'</option>';
 	echo '<option value="delete">'.get_lang('Delete').'</option>';
@@ -279,7 +282,8 @@ function display_file_checkbox($id, $part) {
 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 * @version march 2006
 */
-function get_dropbox_categories($filter = '') {
+function get_dropbox_categories($filter = '')
+{
     $course_id = api_get_course_int_id();
 	global $_user;
 	global $dropbox_cnf;
@@ -309,7 +313,7 @@ function get_dropbox_categories($filter = '') {
 function get_dropbox_category($id) {
     global $dropbox_cnf;
     $course_id = api_get_course_int_id();
-    if (empty($id) or $id != intval($id)) { return array(); }    
+    if (empty($id) or $id != intval($id)) { return array(); }
     $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE c_id = $course_id AND cat_id='".$id."'";
     $res = Database::query($sql);
     if ($res === false) {
@@ -522,8 +526,8 @@ function display_add_form() {
     	}
     	$complete_user_list_for_dropbox = TableSort::sort_table($complete_user_list_for_dropbox, 'lastcommafirst');
     }
-    
-    echo '<select name="recipients[]" size="10" multiple class="span4">';	
+
+    echo '<select name="recipients[]" size="10" multiple class="span4">';
 	/*
 		Create the options inside the select box:
 		List all selected users their user id as value and a name string as display
@@ -574,7 +578,6 @@ function display_add_form() {
 	echo '</select>
 		</div>
 	</div>';
-
 	echo '
 		<div class="control-group">
 			<div class="controls">
@@ -582,7 +585,6 @@ function display_add_form() {
 			</div>
 		</div>
 	';
-
 	echo '</form>';
 }
 
@@ -645,20 +647,18 @@ function removeUnusedFiles() {
     // select all files that aren't referenced anymore
     $sql = "SELECT DISTINCT f.id, f.filename
 			FROM " . dropbox_cnf('tbl_file') . " f
-			LEFT JOIN " . dropbox_cnf('tbl_person') . " p 
+			LEFT JOIN " . dropbox_cnf('tbl_person') . " p
             ON (f.id = p.file_id)
 			WHERE p.user_id IS NULL AND
-                  f.c_id = $course_id 
+                  f.c_id = $course_id
             ";
     $result = Database::query($sql);
     while ($res = Database::fetch_array($result)) {
-        
 		//delete the selected files from the post and file tables
         $sql = "DELETE FROM " . dropbox_cnf('tbl_post') . " WHERE c_id = $course_id AND file_id = '" . $res['id'] . "'";
         Database::query($sql);
         $sql = "DELETE FROM " . dropbox_cnf('tbl_file') . " WHERE c_id = $course_id AND id ='" . $res['id'] . "'";
         Database::query($sql);
-
 		//delete file from server
         @unlink( dropbox_cnf('sysPath') . '/' . $res['filename']);
     }
@@ -676,7 +676,8 @@ function removeUnusedFiles() {
 *
 * @todo check if this function is still necessary.
 */
-function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '') {
+function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '')
+{
     $course_id = api_get_course_int_id();
 
 	global $dropbox_cnf;
@@ -684,9 +685,9 @@ function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '') {
     $sql = "SELECT f.uploader_id
 			FROM " . $dropbox_cnf['tbl_file'] . " f
 			LEFT JOIN " . $dropbox_cnf['tbl_post'] . " p ON (f.id = p.file_id AND f.c_id = $course_id AND p.c_id = $course_id)
-			WHERE 
-                p.dest_user_id = '" . $mailingPseudoId . "' AND 
-                p.c_id = $course_id 
+			WHERE
+                p.dest_user_id = '" . $mailingPseudoId . "' AND
+                p.c_id = $course_id
             ";
     $result = Database::query($sql);
 
@@ -701,7 +702,8 @@ function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '') {
 * @author René Haentjens, Ghent University
 * @todo check if this function is still necessary.
 */
-function removeMoreIfMailing($file_id) {
+function removeMoreIfMailing($file_id)
+{
     $course_id = api_get_course_int_id();
 	global $dropbox_cnf;
     // when deleting a mailing zip-file (posted to mailingPseudoId):
@@ -734,7 +736,8 @@ function removeMoreIfMailing($file_id) {
 *
 * @author René Haentjens, Ghent University
 */
-function dropbox_cnf($variable) {
+function dropbox_cnf($variable)
+{
     return $GLOBALS['dropbox_cnf'][$variable];
 }
 
@@ -806,9 +809,9 @@ function store_add_dropbox() {
 	if (!is_uploaded_file($dropbox_filetmpname)) { // check user fraud : no clean error msg.
 		return get_lang('TheFileIsNotUploaded');
 	}
-    
+
     $upload_ok = process_uploaded_file($_FILES['file'], true);
-        
+
     if (!$upload_ok) {
         return null;
     }
@@ -819,7 +822,7 @@ function store_add_dropbox() {
 	$dropbox_filename = replace_dangerous_char($dropbox_filename);
 	// Transform any .php file in .phps fo security
 	$dropbox_filename = php2phps($dropbox_filename);
-    
+
 	//filter extension
     if (!filter_extension($dropbox_filename)) {
     	return get_lang('UplUnableToSaveFileFilteredExtension');
@@ -926,6 +929,7 @@ function display_user_link_work($user_id, $name = '') {
 * @version march 2006
 */
 function feedback($array) {
+    $output = null;
 	foreach ($array as $key => $value) {
 		$output .= format_feedback($value);
 	}
@@ -943,7 +947,7 @@ function feedback($array) {
 * @version march 2006
 */
 function format_feedback($feedback) {
-	$output .= display_user_link_work($feedback['author_user_id']);
+	$output = display_user_link_work($feedback['author_user_id']);
 	$output .= '&nbsp;&nbsp;'.api_convert_and_format_date($feedback['feedback_date'], DATE_TIME_FORMAT_LONG).'<br />';
 	$output .= '<div style="padding-top:6px">'.nl2br($feedback['feedback']).'</div><hr size="1" noshade/><br />';
 	return $output;
@@ -957,7 +961,7 @@ function format_feedback($feedback) {
 * @version march 2006
 */
 function feedback_form() {
-	$return = get_lang('AddNewFeedback').'<br />';	
+	$return = get_lang('AddNewFeedback').'<br />';
 	$number_users_who_see_file = check_if_file_exist($_GET['id']);
 	if ($number_users_who_see_file) {
 		$token = Security::get_token();
@@ -976,14 +980,14 @@ function user_can_download_file($id, $user_id) {
     $course_id = api_get_course_int_id();
     $id = intval($id);
     $user_id = intval($user_id);
-    
-    $sql = "SELECT file_id FROM ".$dropbox_cnf['tbl_person']." WHERE c_id = $course_id AND user_id = $user_id AND file_id = ".$id;    
+
+    $sql = "SELECT file_id FROM ".$dropbox_cnf['tbl_person']." WHERE c_id = $course_id AND user_id = $user_id AND file_id = ".$id;
 	$result = Database::query($sql);
 	$number_users_who_see_file = Database::num_rows($result);
-    
+
     $sql = "SELECT file_id FROM ".$dropbox_cnf["tbl_post"]."  WHERE c_id = $course_id AND dest_user_id = $user_id AND file_id = ".$id;
     $result = Database::query($sql);
-	$count = Database::num_rows($result);    
+	$count = Database::num_rows($result);
     return $number_users_who_see_file > 0 || $count > 0;
 }
 
@@ -993,13 +997,13 @@ function check_if_file_exist($id) {
     global $dropbox_cnf;
     $id = intval($id);
     $course_id = api_get_course_int_id();
-    $sql = "SELECT file_id FROM ".$dropbox_cnf['tbl_person']." WHERE c_id = $course_id AND file_id = ".$id;    
+    $sql = "SELECT file_id FROM ".$dropbox_cnf['tbl_person']." WHERE c_id = $course_id AND file_id = ".$id;
 	$result = Database::query($sql);
 	$number_users_who_see_file = Database::num_rows($result);
-    
+
     $sql = "SELECT file_id FROM ".$dropbox_cnf["tbl_post"]."  WHERE c_id = $course_id AND file_id = ".$id;
     $result = Database::query($sql);
-	$count = Database::num_rows($result);    
+	$count = Database::num_rows($result);
     return $number_users_who_see_file > 0 || $count > 0;
 }
 
@@ -1044,7 +1048,6 @@ function zip_download($array) {
 	global $files;
 
     $course_id = api_get_course_int_id();
-
 	$sys_course_path = api_get_path(SYS_COURSE_PATH);
 
 	// place to temporarily stash the zipfiles
@@ -1058,7 +1061,7 @@ function zip_download($array) {
             ON (person.file_id=file.id AND file.c_id = $course_id AND person.c_id = $course_id)
             INNER JOIN ".$dropbox_cnf['tbl_post']." post
             ON (post.file_id = file.id AND post.c_id = $course_id AND file.c_id = $course_id)
-			WHERE   file.id IN (".implode(', ',$array).") AND 
+			WHERE   file.id IN (".implode(', ',$array).") AND
                     file.id = person.file_id AND
                     (person.user_id = '".api_get_user_id()."' OR post.dest_user_id = '".api_get_user_id()."' ) ";
 	$result = Database::query($sql);
@@ -1070,7 +1073,7 @@ function zip_download($array) {
 	// Step 3: create the zip file and add all the files to it
 	$temp_zip_file = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip";
 	$zip_folder = new PclZip($temp_zip_file);
-	foreach ($files as $key => $value) {
+	foreach ($files as $value) {
 		$zip_folder->add(api_get_path(SYS_COURSE_PATH).$_course['path'].'/dropbox/'.$value['filename'], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_CB_PRE_ADD, 'my_pre_add_callback');
 	}
 	$name = 'dropbox-'.api_get_utc_datetime().'.zip';

+ 0 - 2
main/dropbox/dropbox_init.inc.php

@@ -275,5 +275,3 @@ if ($origin != 'learnpath') {
 	echo '<link rel="stylesheet" type="text/css" href="', api_get_path(WEB_CODE_PATH), 'css/default.css">';
 	echo $javascript;
 }
-
-// api_display_tool_title($nameTools);

+ 2 - 2
main/dropbox/recover_dropbox_files.php

@@ -1,5 +1,6 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 require_once 'dropbox_init.inc.php';
 
 $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE);
@@ -38,7 +39,6 @@ if (Database::num_rows($result)) {
         $sql = "SELECT * FROM $person_tbl WHERE c_id = $course_id AND user_id = $user_id AND file_id = {$file['id']}";
         $result_person = Database::query($sql);
         if (Database::num_rows($result_person) == 0 ) {
-
             $rows[] = array(
                     $file['filename'],
                     api_convert_and_format_date($file['upload_date']),
@@ -49,4 +49,4 @@ if (Database::num_rows($result)) {
     $headers = array(get_lang('Filename'), get_lang('UploadedDate'), get_lang('Action'));
     echo Display::table($headers, $rows);
 }
-Display::display_footer();
+Display::display_footer();