From ec07e3cb0cbd7b68690caa1f6f3906fab62bcbfa Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 8 Sep 2015 16:04:21 +0200 Subject: [PATCH] Format code, add docs, fix PHP warnings. --- main/dashboard/index.php | 22 +-- main/dropbox/dropbox_class.inc.php | 113 ++++++------ main/dropbox/dropbox_functions.inc.php | 65 +++++-- main/dropbox/dropbox_init.inc.php | 38 ++-- main/dropbox/dropbox_submit.php | 50 ++--- main/dropbox/index.php | 10 +- main/dropbox/recover_dropbox_files.php | 11 +- main/forum/download.php | 5 +- main/forum/editpost.php | 13 +- main/forum/forumfunction.inc.php | 2 +- main/inc/lib/TeacherTimeReport.php | 1 - main/inc/lib/dashboard.lib.php | 61 ++++--- main/inc/lib/internationalization.lib.php | 1 + main/inc/lib/legal.lib.php | 7 +- main/inc/lib/link.lib.php | 2 - main/inc/lib/message.lib.php | 119 +++--------- main/inc/lib/myspace.lib.php | 212 +++++++++++++--------- main/inc/lib/nanogong.lib.php | 16 +- main/inc/lib/online.inc.php | 7 +- main/inc/lib/security.lib.php | 17 +- main/inc/lib/skill.lib.php | 2 +- main/inc/lib/statistics.lib.php | 66 ++++--- main/inc/lib/sub_language.class.php | 46 +++-- main/inc/lib/system_announcements.lib.php | 9 +- main/inc/lib/thematic.lib.php | 11 +- main/inc/lib/tracking.lib.php | 133 +++++++------- main/inc/lib/usergroup.lib.php | 25 ++- 27 files changed, 583 insertions(+), 481 deletions(-) diff --git a/main/dashboard/index.php b/main/dashboard/index.php index 766bc1909a..880e40e32e 100755 --- a/main/dashboard/index.php +++ b/main/dashboard/index.php @@ -41,15 +41,15 @@ if (isset($_GET['path'])) { // distpacher actions to controller switch ($action) { - case 'listing': - $dashboard_controller->display(); - break; - case 'store_user_block': - $dashboard_controller->store_user_block(); - break; - case 'disable_block': - $dashboard_controller->close_user_block($path); - break; - default : - $dashboard_controller->display(); + case 'listing': + $dashboard_controller->display(); + break; + case 'store_user_block': + $dashboard_controller->store_user_block(); + break; + case 'disable_block': + $dashboard_controller->close_user_block($path); + break; + default : + $dashboard_controller->display(); } diff --git a/main/dropbox/dropbox_class.inc.php b/main/dropbox/dropbox_class.inc.php index 9331d3e7c0..d1c081073f 100755 --- a/main/dropbox/dropbox_class.inc.php +++ b/main/dropbox/dropbox_class.inc.php @@ -92,7 +92,6 @@ class Dropbox_Work */ public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) { - $_user = api_get_user_info(); $dropbox_cnf = getDropboxConf(); // Fill in the properties @@ -184,51 +183,51 @@ class Dropbox_Work $action = isset($_GET['action']) ? $_GET['action'] : null; - // Do some sanity checks - $id = intval($id); + // Do some sanity checks + $id = intval($id); - // Get the data from DB - $sql = "SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id - FROM ".$dropbox_cnf['tbl_file']." - WHERE c_id = $course_id AND id = ".intval($id).""; + // Get the data from DB + $sql = "SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id + FROM ".$dropbox_cnf['tbl_file']." + WHERE c_id = $course_id AND id = ".$id.""; $result = Database::query($sql); - $res = Database::fetch_array($result, 'ASSOC'); - - // Check if uploader is still in Chamilo system - $uploader_id = stripslashes($res['uploader_id']); - $uploaderName = getUserNameFromId($uploader_id); - if (!$uploaderName) { - //deleted user - $this->uploader_id = -1; - $this->uploaderName = get_lang('Unknown', ''); - } else { - $this->uploader_id = $uploader_id; - $this->uploaderName = $uploaderName; - } + $res = Database::fetch_array($result, 'ASSOC'); + + // Check if uploader is still in Chamilo system + $uploader_id = stripslashes($res['uploader_id']); + $uploaderName = getUserNameFromId($uploader_id); + if (!$uploaderName) { + //deleted user + $this->uploader_id = -1; + $this->uploaderName = get_lang('Unknown', ''); + } else { + $this->uploader_id = $uploader_id; + $this->uploaderName = $uploaderName; + } - // Fill in properties - $this->id = $id; - $this->filename = stripslashes($res['filename']); - $this->filesize = stripslashes($res['filesize']); - $this->title = stripslashes($res['title']); - $this->description = stripslashes($res['description']); - $this->author = stripslashes($res['author']); - $this->upload_date = stripslashes($res['upload_date']); - $this->last_upload_date = stripslashes($res['last_upload_date']); - $this->category = $res['cat_id']; - - // Getting the feedback on the work. - if ($action == 'viewfeedback' AND $this->id == $_GET['id']) { - $feedback2 = array(); - $sql_feedback = "SELECT * FROM ".$dropbox_cnf['tbl_feedback']." - WHERE c_id = $course_id AND file_id='".$id."' ORDER BY feedback_id ASC"; - $result = Database::query($sql_feedback); - while ($row_feedback = Database::fetch_array($result)) { - $row_feedback['feedback'] = Security::remove_XSS($row_feedback['feedback']); - $feedback2[] = $row_feedback; - } - $this->feedback2= $feedback2; - } + // Fill in properties + $this->id = $id; + $this->filename = stripslashes($res['filename']); + $this->filesize = stripslashes($res['filesize']); + $this->title = stripslashes($res['title']); + $this->description = stripslashes($res['description']); + $this->author = stripslashes($res['author']); + $this->upload_date = stripslashes($res['upload_date']); + $this->last_upload_date = stripslashes($res['last_upload_date']); + $this->category = $res['cat_id']; + + // Getting the feedback on the work. + if ($action == 'viewfeedback' AND $this->id == $_GET['id']) { + $feedback2 = array(); + $sql_feedback = "SELECT * FROM ".$dropbox_cnf['tbl_feedback']." + WHERE c_id = $course_id AND file_id='".$id."' ORDER BY feedback_id ASC"; + $result = Database::query($sql_feedback); + while ($row_feedback = Database::fetch_array($result)) { + $row_feedback['feedback'] = Security::remove_XSS($row_feedback['feedback']); + $feedback2[] = $row_feedback; + } + $this->feedback2= $feedback2; + } } } @@ -275,7 +274,14 @@ class Dropbox_SentWork extends Dropbox_Work $_course = api_get_course_info(); // Call constructor of Dropbox_Work object - $this->Dropbox_Work($uploader_id, $title, $description, $author, $filename, $filesize); + $this->Dropbox_Work( + $uploader_id, + $title, + $description, + $author, + $filename, + $filesize + ); $course_id = api_get_course_int_id(); @@ -416,11 +422,11 @@ class Dropbox_Person $course_id = api_get_course_int_id(); // Fill in properties - $this->userId = $userId; - $this->isCourseAdmin = $isCourseAdmin; - $this->isCourseTutor = $isCourseTutor; - $this->receivedWork = array(); - $this->sentWork = array(); + $this->userId = $userId; + $this->isCourseAdmin = $isCourseAdmin; + $this->isCourseTutor = $isCourseTutor; + $this->receivedWork = array(); + $this->sentWork = array(); // Note: perhaps include an ex coursemember check to delete old files @@ -585,11 +591,14 @@ class Dropbox_Person $course_id = api_get_course_int_id(); $id = intval($id); - $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." WHERE c_id = $course_id AND cat_id = '".$id."' "; + $sql = "DELETE FROM ".$dropbox_cnf['tbl_file']." + WHERE c_id = $course_id AND cat_id = '".$id."' "; if (!Database::query($sql)) return false; - $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." WHERE c_id = $course_id AND cat_id = '".$id."' "; + $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." + WHERE c_id = $course_id AND cat_id = '".$id."' "; if (!Database::query($sql)) return false; - $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']." WHERE c_id = $course_id AND cat_id = '".$id."' "; + $sql = "DELETE FROM ".$dropbox_cnf['tbl_post']." + WHERE c_id = $course_id AND cat_id = '".$id."' "; if (!Database::query($sql)) return false; return true; } diff --git a/main/dropbox/dropbox_functions.inc.php b/main/dropbox/dropbox_functions.inc.php index 340d1d6cbd..e33e415c5c 100755 --- a/main/dropbox/dropbox_functions.inc.php +++ b/main/dropbox/dropbox_functions.inc.php @@ -115,7 +115,8 @@ function getDropboxConf() /** * This function deletes a dropbox category * -* @todo give the user the possibility what needs to be done with the files in this category: move them to the root, download them as a zip, delete them +* @todo give the user the possibility what needs to be done with the files + * in this category: move them to the root, download them as a zip, delete them * * @author Patrick Cool , Ghent University * @version march 2006 @@ -156,11 +157,13 @@ function delete_category($action, $id, $user_id = null) } // step 1: delete the category - $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." WHERE c_id = $course_id AND cat_id='".intval($id)."' AND $sentreceived='1'"; + $sql = "DELETE FROM ".$dropbox_cnf['tbl_category']." + WHERE c_id = $course_id AND cat_id='".intval($id)."' AND $sentreceived='1'"; Database::query($sql); // step 2: delete all the documents in this category - $sql = "SELECT * FROM ".$entries_table." WHERE c_id = $course_id AND cat_id='".intval($id)."'"; + $sql = "SELECT * FROM ".$entries_table." + WHERE c_id = $course_id AND cat_id='".intval($id)."'"; $result = Database::query($sql); while($row = Database::fetch_array($result)) { @@ -172,6 +175,7 @@ function delete_category($action, $id, $user_id = null) $dropboxfile->deleteSentWork($row[$id_field]); } } + return $return_message; } @@ -241,6 +245,7 @@ function store_move($id, $target, $part) } else { $return_message = get_lang('NotMovedError'); } + return $return_message; } @@ -291,6 +296,7 @@ function display_file_checkbox($id, $part) { $checked = 'checked'; } $return_value = ''; + return $return_value; } @@ -314,7 +320,8 @@ function get_dropbox_categories($filter = '') $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id); - $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE c_id = $course_id AND user_id='".$_user['user_id']."' $condition_session"; + $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']." + WHERE c_id = $course_id AND user_id='".$_user['user_id']."' $condition_session"; $result = Database::query($sql); while ($row = Database::fetch_array($result)) { @@ -336,7 +343,8 @@ function get_dropbox_category($id) $dropbox_cnf = getDropboxConf(); $course_id = api_get_course_int_id(); 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."'"; + $sql = "SELECT * FROM ".$dropbox_cnf['tbl_category']." + WHERE c_id = $course_id AND cat_id='".$id."'"; $res = Database::query($sql); if ($res === false) { return array(); @@ -524,7 +532,11 @@ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategor $origin = isset($_GET['origin']) ? $_GET['origin'] : null; $token = Security::get_token(); - $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); + $dropbox_person = new Dropbox_Person( + api_get_user_id(), + $is_courseAdmin, + $is_courseTutor + ); $form = new FormValidator( 'sent_form', @@ -695,6 +707,7 @@ function getLoginFromId($id) $result = Database::query($sql); $res = Database::fetch_array($result); if (!$res) return false; + return stripslashes($res['username']); } @@ -707,6 +720,7 @@ function isCourseMember($user_id) $_course = api_get_course_info(); $course_code = $_course['code']; $is_course_member = CourseManager::is_user_subscribed_in_course($user_id, $course_code, true); + return $is_course_member; } @@ -729,9 +743,11 @@ function removeUnusedFiles() $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'] . "'"; + $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'] . "'"; + $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']); @@ -758,7 +774,8 @@ function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '') $mailingPseudoId = intval($mailingPseudoId); $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) + 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 @@ -855,7 +872,8 @@ function store_add_dropbox() } // we are doing a just upload but an additional recipient is selected. - // note: why can't this be valid? It is like sending a document to yourself AND to a different person (I do this quite often with my e-mails) + // note: why can't this be valid? It is like sending a document to + // yourself AND to a different person (I do this quite often with my e-mails) if ($thisIsJustUpload && (count($_POST['recipients']) != 1)) { return get_lang('MailingJustUploadSelectNoOther'); } @@ -881,7 +899,8 @@ function store_add_dropbox() // check if the filesize does not exceed the allowed size. if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) { - return get_lang('DropboxFileTooBig'); // TODO: The "too big" message does not fit in the case of uploading zero-sized file. + return get_lang('DropboxFileTooBig'); + // TODO: The "too big" message does not fit in the case of uploading zero-sized file. } // check if the file is actually uploaded @@ -914,7 +933,8 @@ function store_add_dropbox() $_POST['authors'] = getUserNameFromId($_user['user_id']); } - // note: I think we could better migrate everything from here on to separate functions: store_new_dropbox, store_new_mailing, store_just_upload + // note: I think we could better migrate everything from here on to + // separate functions: store_new_dropbox, store_new_mailing, store_just_upload if ($dropbox_overwrite) { $dropbox_person = new Dropbox_Person($_user['user_id'], api_is_course_admin(), api_is_course_tutor()); @@ -995,7 +1015,15 @@ function store_add_dropbox() } } - new Dropbox_SentWork($_user['user_id'], $dropbox_title, $_POST['description'], strip_tags($_POST['authors']), $dropbox_filename, $dropbox_filesize, $new_work_recipients); + new Dropbox_SentWork( + $_user['user_id'], + $dropbox_title, + $_POST['description'], + strip_tags($_POST['authors']), + $dropbox_filename, + $dropbox_filesize, + $new_work_recipients + ); Security::clear_token(); return get_lang('FileUploadSucces'); @@ -1059,7 +1087,8 @@ function feedback_form() return $return; } -function user_can_download_file($id, $user_id) { +function user_can_download_file($id, $user_id) +{ $dropbox_cnf = getDropboxConf(); $course_id = api_get_course_int_id(); $id = intval($id); @@ -1080,7 +1109,8 @@ function user_can_download_file($id, $user_id) { // we now check if the other users have not delete this document yet. // If this is the case then it is useless to see the // add feedback since the other users will never get to see the feedback. -function check_if_file_exist($id) { +function check_if_file_exist($id) +{ $dropbox_cnf = getDropboxConf(); $id = intval($id); $course_id = api_get_course_int_id(); @@ -1096,8 +1126,6 @@ function check_if_file_exist($id) { return $number_users_who_see_file > 0 || $count > 0; } - - /** * @return a language string (depending on the success or failure. * @@ -1276,7 +1304,8 @@ function generate_html_overview($files, $dont_show_columns = array(), $make_link function get_total_number_feedback($file_id = '') { $dropbox_cnf = getDropboxConf(); $course_id = api_get_course_int_id(); - $sql = "SELECT COUNT(feedback_id) AS total, file_id FROM ".$dropbox_cnf['tbl_feedback']." + $sql = "SELECT COUNT(feedback_id) AS total, file_id + FROM ".$dropbox_cnf['tbl_feedback']." WHERE c_id = $course_id GROUP BY file_id"; $result = Database::query($sql); $return = array(); diff --git a/main/dropbox/dropbox_init.inc.php b/main/dropbox/dropbox_init.inc.php index d4acdce46e..5605a277cc 100755 --- a/main/dropbox/dropbox_init.inc.php +++ b/main/dropbox/dropbox_init.inc.php @@ -1,7 +1,6 @@ function confirmsend () { @@ -204,13 +215,12 @@ $javascript = "