Browse Source

Fixing PHP warnings.

Julio Montoya 11 years ago
parent
commit
0775194efc

+ 7 - 12
main/survey/create_new_survey.php

@@ -65,19 +65,14 @@ if (!api_is_allowed_to_edit()) {
 }
 
 // Getting the survey information
-$survey_id = Security::remove_XSS($_GET['survey_id']);
+$survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null;
 $survey_data = survey_manager::get_survey($survey_id);
 
 // Additional information
 $course_id = api_get_course_id();
 $session_id = api_get_session_id();
 $gradebook_link_type = 8;
-
-/* $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'], ENT_QUOTES), 0, 40));
-  if (api_strlen(strip_tags($survey_data['title'])) > 40) {
-  $urlname .= '...';
-  } */
-$urlname = $survey_data['title'];
+$urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null;
 
 // Breadcrumbs
 if ($_GET['action'] == 'add') {
@@ -201,14 +196,13 @@ if ($_GET['action'] == 'add') {
     $defaults['parent_id'] = 0;
 }
 
-if ($survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
+if (isset($survey_data['survey_type']) && $survey_data['survey_type'] == 1 || $_GET['action'] == 'add') {
     $form->addElement('checkbox', 'one_question_per_page', null, get_lang('OneQuestionPerPage'));
     $form->addElement('checkbox', 'shuffle', null, get_lang('ActivateShuffle'));
 }
-
+$input_name_list = null;
 if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id)) {
     if ($survey_data['anonymous'] == 0) {
-
         $form->addElement('checkbox', 'show_form_profile', null, get_lang('ShowFormProfile'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
 
         if ($survey_data['show_form_profile'] == 1) {
@@ -226,7 +220,8 @@ if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id))
                     $input_name_list.= 'profile_'.$key.',';
                 }
             }
-            // Necesary to know the fields
+
+            // Necessary to know the fields
             $form->addElement('hidden', 'input_name_list', $input_name_list);
 
             // Set defaults form fields
@@ -323,7 +318,7 @@ if ($form->validate()) {
         Display::display_confirmation_message($return['message'], false);
     } else {
         // Redirecting to the survey page (whilst showing the return message)
-        header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&message='.$return['message'].'&'.api);
+        header('location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$return['id'].'&message='.$return['message'].'&'.api_get_cidreq());
         exit;
     }
 } else {

+ 4 - 0
main/survey/preview.php

@@ -112,6 +112,8 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 		exit;
 	}
 
+    $questions = array();
+
 	if (isset($_GET['show'])) {
 		// Getting all the questions for this page and add them to a multidimensional array where the first index is the page.
 		// as long as there is no pagebreak fount we keep adding questions to the page
@@ -178,6 +180,7 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 			}
 		}
 	}
+
 	// Selecting the maximum number of pages
 	$sql = "SELECT * FROM $table_survey_question
 	        WHERE
@@ -192,6 +195,7 @@ if (api_is_course_admin() || (api_is_course_admin() && $_GET['isStudentView'] ==
 	} else {
 		$show = 0;
 	}
+
 	echo '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.Security::remove_XSS($survey_id).'&show='.$show.'">';
 
 	if (is_array($questions) && count($questions) > 0) {

+ 1 - 1
main/survey/question.php

@@ -33,7 +33,7 @@ if (!api_is_allowed_to_edit(false, true)) {
 }
 
 // Is valid request
-$is_valid_request = $_REQUEST['is_executable'];
+$is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null;
 if ($request_index != $is_valid_request) {
 	if ($request_index == 'save_question') {
 		unset($_POST[$request_index]);

+ 47 - 21
main/survey/survey.lib.php

@@ -281,7 +281,7 @@ class survey_manager
 						'".Database::escape_string($values['survey_thanks'])."',
 						'".date('Y-m-d H:i:s')."',
 						'".Database::escape_string($values['anonymous'])."'".$additional['values'].",
-						".intval($_SESSION['id_session'])."
+						".api_get_session_id()."
 						)";
 			Database::query($sql);
 			$survey_id = Database::insert_id();
@@ -1401,15 +1401,20 @@ class survey_question
 	 */
 	function create_form($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']))),
+            array('align' => 'middle', 'height' => '22px')
+        ).' ';
 
-		//$tool_name = '<img src="../img/'.survey_manager::icon_question($_GET['type']).'" alt="'.get_lang(ucfirst($_GET['type'])).'" title="'.get_lang(ucfirst($_GET['type'])).'" />';
-		$tool_name = Display::return_icon(survey_manager::icon_question(Security::remove_XSS($_GET['type'])), get_lang(ucfirst(Security::remove_XSS($_GET['type']))), array('align' => 'middle', 'height' => '22px')).' ';
-		if ($_GET['action'] == 'add') {
+		if ($action == 'add') {
 			$tool_name .= get_lang('AddQuestion');
 		}
-		if ($_GET['action'] == 'edit') {
+		if ($action == 'edit') {
 			$tool_name .= get_lang('EditQuestion');
 		}
 
@@ -1421,10 +1426,12 @@ class survey_question
 			$tool_name .= ': '.get_lang(api_ucfirst(Security::remove_XSS($_GET['type'])));
 		}
 
-		$this->html .= '<form class="form-horizontal" id="question_form" name="question_form" method="post" action="'.api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&type='.Security::remove_XSS($_GET['type']).'&survey_id='.Security::remove_XSS($_GET['survey_id']).'&question_id='.Security::remove_XSS($_GET['question_id']).'">';
+        $url = api_get_self().'?action='.$action.'&type='.Security::remove_XSS($_GET['type']).'&survey_id='.Security::remove_XSS($_GET['survey_id']).'&question_id='.$questionId;
+
+		$this->html .= '<form class="form-horizontal" id="question_form" name="question_form" method="post" action="'.$url.'">';
         $this->html .= '<legend>'.$tool_name.'</legend>';
 		$this->html .= '		<input type="hidden" name="survey_id" id="survey_id" value="'.Security::remove_XSS($_GET['survey_id']).'"/>';
-		$this->html .= '		<input type="hidden" name="question_id" id="question_id" value="'.Security::remove_XSS($_GET['question_id']).'"/>';
+		$this->html .= '		<input type="hidden" name="question_id" id="question_id" value="'.$questionId.'"/>';
 		$this->html .= '		<input type="hidden" name="shared_question_id" id="shared_question_id" value="'.Security::remove_XSS($form_content['shared_question_id']).'"/>';
 		$this->html .= '		<input type="hidden" name="type" id="type" value="'.Security::remove_XSS($_GET['type']).'"/>';
 
@@ -2457,7 +2464,7 @@ class SurveyUtil
 		}
 
 		// User report
-		if ($_GET['action'] == 'userreport') {
+		if (isset($_GET['action']) && $_GET['action'] == 'userreport') {
 			global $people_filled;
 			if ($survey_data['anonymous'] == 0) {
 				$people_filled_full_data = true;
@@ -2479,7 +2486,7 @@ class SurveyUtil
 		}
 
 		// Question report
-		if ($_GET['action'] == 'questionreport') {
+		if (isset($_GET['action']) && $_GET['action'] == 'questionreport') {
 			if (isset($_GET['question']) && !is_numeric($_GET['question'])) {
 				$error = get_lang('UnknowQuestion');
 			}
@@ -2502,7 +2509,10 @@ class SurveyUtil
 	 * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
 	 * @version February 2007
 	 */
-	static function handle_reporting_actions() {
+	static function handle_reporting_actions()
+    {
+        $action = isset($_GET['action']) ? $_GET['action'] : null;
+
 		// Getting the number of question
 		$temp_questions_data = survey_manager::get_questions($_GET['survey_id']);
 
@@ -2517,19 +2527,19 @@ class SurveyUtil
 		// Counting the number of questions that are relevant for the reporting
 		$survey_data['number_of_questions'] = count($questions_data);
 
-		if ($_GET['action'] == 'questionreport') {
+		if ($action == 'questionreport') {
 			SurveyUtil::display_question_report($survey_data);
 		}
-		if ($_GET['action'] == 'userreport') {
+		if ($action == 'userreport') {
 			SurveyUtil::display_user_report();
 		}
-		if ($_GET['action'] == 'comparativereport') {
+		if ($action == 'comparativereport') {
 			SurveyUtil::display_comparative_report();
 		}
-		if ($_GET['action'] == 'completereport') {
+		if ($action == 'completereport') {
 			SurveyUtil::display_complete_report();
 		}
-		if ($_GET['action'] == 'deleteuserreport') {
+		if ($action == 'deleteuserreport') {
 			SurveyUtil::delete_user_report($_GET['survey_id'], $_GET['user']);
 			//SurveyUtil::display_user_report(); //Could work but looks a bit clunky
 		}
@@ -4542,16 +4552,18 @@ class SurveyUtil
 
 		$sql = "SELECT
 					survey.survey_id AS col0,
-					CONCAT('<a href=\"survey.php?survey_id=',survey.survey_id,'\">',survey.title,'</a>') AS col1,
+					survey.title AS col1,
 					survey.code AS col2,
 					count(survey_question.question_id) AS col3,
 					".(api_is_western_name_order() ? "CONCAT(user.firstname, ' ', user.lastname)" : "CONCAT(user.lastname, ' ', user.firstname)")."	AS col4,
 					survey.avail_from AS col5,
 					survey.avail_till AS col6,
-					CONCAT('<a href=\"survey_invitation.php?view=answered&amp;survey_id=',survey.survey_id,'\">',survey.answered,'</a> / <a href=\"survey_invitation.php?view=invited&amp;survey_id=',survey.survey_id,'\">',survey.invited, '</a>')	AS col7,
+					survey.invited AS col7,
 					survey.anonymous AS col8,
 					survey.survey_id AS col9,
-					survey.session_id AS session_id
+					survey.session_id AS session_id,
+					survey.answered,
+					survey.invited
 				 FROM $table_survey survey
                     LEFT JOIN $table_survey_question survey_question
                     ON (survey.survey_id = survey_question.survey_id AND survey_question.c_id = $course_id)
@@ -4568,8 +4580,12 @@ class SurveyUtil
 		$surveys = array();
 		$array = array();
 		while ($survey = Database::fetch_array($res)) {
+
 			$array[0] = $survey[0];
-			$array[1] = $survey[1];
+			$array[1] = Display::url(
+                $survey[1],
+                api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey[0].'&'.api_get_cidreq()
+            );
 
 			// Validation when belonging to a session
 			$session_img = api_get_session_image($survey['session_id'], $_user['status']);
@@ -4578,7 +4594,16 @@ class SurveyUtil
 			$array[4] = $survey[4];
 			$array[5] = $survey[5];
 			$array[6] = $survey[6];
-			$array[7] = $survey[7];
+			$array[7] =
+                Display::url(
+                    $survey['answered'],
+                    api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=answered&survey_id='.$survey[0].'&'.api_get_cidreq()
+                ).' / '.
+                Display::url(
+                    $survey['invited'],
+                    api_get_path(WEB_CODE_PATH).'survey/survey_invitation.php?view=invited&survey_id='.$survey[0].'&'.api_get_cidreq()
+                );
+
 			$array[8] = $survey[8];
 			$array[9] = $survey[9];
 			//$array[10] = $survey[10];
@@ -4587,7 +4612,8 @@ class SurveyUtil
 		return $surveys;
 	}
 
-	static function get_survey_data_for_coach($from, $number_of_items, $column, $direction) {
+	static function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
+    {
 		require_once api_get_path(LIBRARY_PATH).'surveymanager.lib.php';
 		$survey_tree = new SurveyTree();
 		$last_version_surveys = $survey_tree->get_last_children_from_branch($survey_tree->surveylist);

+ 8 - 6
main/survey/survey.php

@@ -69,10 +69,12 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) {
 	$tool_name .= '...';
 }
 
-if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup') {
+if ($is_survey_type_1 &&
+    isset($_GET['action']) &&
+    ($_GET['action'] == 'addgroup' || $_GET['action'] == 'deletegroup')
+) {
 	$_POST['name'] = trim($_POST['name']);
-
-	if (($_GET['action'] == 'addgroup')) {
+	if ($_GET['action'] == 'addgroup') {
 		if (!empty($_POST['group_id'])) {
 			Database::query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\'
 			                 WHERE c_id = '.$course_id.' AND id = \''.Database::escape_string($_POST['group_id']).'\'');
@@ -98,10 +100,10 @@ if ($is_survey_type_1 && $_GET['action'] == 'addgroup' || $_GET['action'] == 'de
 Display::display_header($tool_name, 'Survey');
 
 // Action handling
-$my_action_survey		= Security::remove_XSS($_GET['action']);
-$my_question_id_survey  = Security::remove_XSS($_GET['question_id']);
+$my_action_survey		= isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
+$my_question_id_survey  = isset($_GET['question_id']) ? Security::remove_XSS($_GET['question_id']) : null;
 $my_survey_id_survey    = Security::remove_XSS($_GET['survey_id']);
-$message_information    = Security::remove_XSS($_GET['message']);
+$message_information    = isset($_GET['message']) ? Security::remove_XSS($_GET['message']) : null;
 
 if (isset($_GET['action'])) {
 	if (($_GET['action'] == 'moveup' || $_GET['action'] == 'movedown') && isset($_GET['question_id'])) {

+ 3 - 3
main/survey/survey_list.php

@@ -81,15 +81,15 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['survey
 
     $return = survey_manager :: delete_survey($_GET['survey_id']);
     if ($return) {
-        Display :: display_confirmation_message(get_lang('SurveyDeleted'), false);
+        Display::display_confirmation_message(get_lang('SurveyDeleted'), false);
     } else {
-        Display :: display_error_message(get_lang('ErrorOccurred'), false);
+        Display::display_error_message(get_lang('ErrorOccurred'), false);
     }
 }
 
 if (isset($_GET['action']) && $_GET['action'] == 'empty') {
     $mysession = api_get_session_id();
-    if ( $mysession != 0 ) {
+    if ($mysession != 0) {
         if (!((api_is_course_coach() || api_is_platform_admin()) &&
             api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) {
             // The coach can't empty a survey not belonging to his session