From f13fb20a37631e86407358f2ef6f95e581fdd064 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 15 Apr 2014 18:31:02 +0200 Subject: [PATCH] Replacing globals. --- main/survey/fillsurvey.php | 1 - main/survey/question.php | 9 ++- main/survey/reporting.php | 22 +++-- main/survey/survey.lib.php | 161 +++++++++++++++---------------------- 4 files changed, 87 insertions(+), 106 deletions(-) diff --git a/main/survey/fillsurvey.php b/main/survey/fillsurvey.php index 69fcfccfc5..be6c125154 100644 --- a/main/survey/fillsurvey.php +++ b/main/survey/fillsurvey.php @@ -43,7 +43,6 @@ $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION); - $table_user = Database :: get_main_table(TABLE_MAIN_USER); // Check if user is anonymous or not diff --git a/main/survey/question.php b/main/survey/question.php index a3c74072d1..758287d34c 100644 --- a/main/survey/question.php +++ b/main/survey/question.php @@ -161,7 +161,10 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types)) // An action has been performed (for instance adding a possible answer, moving an answer, ...) if ($_POST) { $form_content = $_POST; - $form_content = $form->handle_action($form_content); + $form_content = $form->handle_action( + $survey_data, + $form_content + ); } if ($error_message != '') { @@ -176,12 +179,12 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types)) unset($_SESSION['temp_horizontalvertical']); } - $form->create_form($form_content); + $form->create_form($survey_data, $form_content); $form->render_form(); } else { $form_content = $_POST; $form = new survey_question(); - $form->handle_action($form_content); + $form->handle_action($survey_data, $form_content); } // Footer diff --git a/main/survey/reporting.php b/main/survey/reporting.php index 4908d5b844..6d9e9fe1da 100644 --- a/main/survey/reporting.php +++ b/main/survey/reporting.php @@ -17,7 +17,6 @@ $language_file = 'survey'; require_once '../inc/global.inc.php'; require_once 'survey.lib.php'; $this_section = SECTION_COURSES; - $survey_id = intval($_GET['survey_id']); // Export @@ -29,13 +28,13 @@ if (isset($_POST['export_report']) && $_POST['export_report']) { case 'xls': $survey_data = survey_manager::get_survey($survey_id); $filename = 'survey_results_'.$survey_id.'.xls'; - $data = SurveyUtil::export_complete_report_xls($filename, $_GET['user_id']); + $data = SurveyUtil::export_complete_report_xls($survey_data, $filename, $_GET['user_id']); exit; break; case 'csv': default: $survey_data = survey_manager::get_survey($survey_id); - $data = SurveyUtil::export_complete_report($_GET['user_id']); + $data = SurveyUtil::export_complete_report($survey_data, $_GET['user_id']); //$filename = 'fileexport.csv'; $filename = 'survey_results_'.$survey_id.'.csv'; @@ -61,8 +60,19 @@ if (isset($_POST['export_report']) && $_POST['export_report']) { } } +if ($survey_data['anonymous'] == 0) { + $people_filled_full_data = true; +} else { + $people_filled_full_data = false; +} +$people_filled = survey_manager::get_people_who_filled_survey( + $_GET['survey_id'], + $people_filled_full_data +); + // Checking the parameters -SurveyUtil::check_parameters(); +SurveyUtil::check_parameters($people_filled); + /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/ if (!api_is_allowed_to_edit(false, true)) { @@ -121,7 +131,7 @@ if (!$_GET['action'] OR $_GET['action'] == 'overview') { Display::display_header($tool_name, 'Survey'); // Action handling -SurveyUtil::handle_reporting_actions(); +SurveyUtil::handle_reporting_actions($people_filled); // Actions bar echo '
'; @@ -135,7 +145,7 @@ if (!$_GET['action'] || $_GET['action'] == 'overview') { echo '
'.get_lang('DetailedReportByQuestionDetail').'
'; echo '
'.get_lang('DetailedReportByUserDetail').'.
'; echo '
'.get_lang('ComparativeReportDetail').'.
'; - echo '
'.get_lang('CompleteReportDetail').'
'; + echo '
'.get_lang('CompleteReportDetail').'
'; } // Footer diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 370ae108ab..c9f184171b 100644 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -766,10 +766,8 @@ class survey_manager * @author Patrick Cool , Ghent University * @version January 2007 */ - public function save_question($form_content) + public function save_question($survey_data, $form_content) { - global $survey_data; - if (strlen($form_content['question']) > 1) { // Checks lenght of the question $empty_answer = false; @@ -1399,12 +1397,10 @@ class survey_question * @todo the form_text has to become a wysiwyg editor or adding a question_comment field * @todo consider adding a question_comment form element */ - function create_form($form_content) + function create_form($survey_data, $form_content) { $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; $questionId = isset($_GET['question_id']) ? Security::remove_XSS($_GET['question_id']) : null; - - global $survey_data; $tool_name = Display::return_icon( survey_manager::icon_question(Security::remove_XSS($_GET['type'])), get_lang(ucfirst(Security::remove_XSS($_GET['type']))), @@ -1526,7 +1522,7 @@ class survey_question * @author Patrick Cool , Ghent University * @version January 2007 */ - function handle_action($form_content) + function handle_action($survey_data, $form_content) { $course_id = api_get_course_int_id(); global $config; @@ -1568,7 +1564,10 @@ class survey_question // Saving a question if (isset($_POST['save_question'])) { - $message = survey_manager::save_question($form_content); + $message = survey_manager::save_question( + $survey_data, + $form_content + ); if ($message == 'QuestionAdded' || $message == 'QuestionUpdated' ) { $sql='SELECT COUNT(*) FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION).' WHERE c_id = '.$course_id.' AND survey_id = '.intval($_GET['survey_id']); @@ -1661,9 +1660,9 @@ class ch_yesno extends survey_question * @author Patrick Cool , Ghent University * @version January 2007 */ - function create_form($form_content) + function create_form($survey_data, $form_content) { - $this->html = parent::create_form($form_content); + $this->html = parent::create_form($survey_data, $form_content); // Horizontal or vertical $this->html .= '
'; $this->html .= '