Browse Source

Merge pull request #273 from ycastillo/yoselyn1.9.8

Yoselyn1.9.8
Yannick Warnier 11 years ago
parent
commit
13e1583b62
3 changed files with 20 additions and 12 deletions
  1. 2 2
      main/survey/fillsurvey.php
  2. 17 10
      main/survey/preview.php
  3. 1 0
      main/survey/survey.lib.php

+ 2 - 2
main/survey/fillsurvey.php

@@ -70,8 +70,8 @@ if ($surveyCode != "") {
     $resultAnonymous = Database::query($sql);
     $rowAnonymous = Database::fetch_array($resultAnonymous, 'ASSOC');
     // If is anonymous and is not allowed to take the survey to anonymous users, forbid access:
-    if (!isset($rowAnonymous['anonymous']) || ($rowAnonymous['anonymous'] == 0 && api_is_anonymous($_user['user_id'], true)) || count($rowAnonymous) == 0) {
-        api_not_allowed();
+    if (!isset($rowAnonymous['anonymous']) || ($rowAnonymous['anonymous'] == 0 && api_is_anonymous()) || count($rowAnonymous) == 0) {
+        api_not_allowed(true);
     }
     // If is anonymous and it is allowed to take the survey as anonymous, mark survey as anonymous.
 }

+ 17 - 10
main/survey/preview.php

@@ -32,6 +32,7 @@ $course_id = api_get_course_int_id();
 $userId = api_get_user_id();
 $surveyId = Database::escape_string($_GET['survey_id']);
 $userInvited = 0;
+$userAnonymous = 0;
 
 //query to ask if logged user is allowed to see the preview (if he is invited of he is a teacher)
 $sql = "SELECT survey_invitation.user
@@ -46,11 +47,7 @@ $result = Database::query($sql);
 if (Database::num_rows($result) > 0) {
     $userInvited = 1;
 }
-if ($userInvited == 0) {
-    if(!api_is_allowed_to_edit()) {
-        api_not_allowed();
-    }
-}
+
 // We exit here if ther is no valid $_GET parameter
 if (!isset($_GET['survey_id']) || !is_numeric($_GET['survey_id'])){
 	Display::display_header(get_lang('SurveyPreview'));
@@ -71,11 +68,21 @@ if (empty($survey_data)) {
 }
 
 $urlname = strip_tags($survey_data['title']);
-
-// Breadcrumbs
-$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
-$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
-
+if (api_is_allowed_to_edit()) {
+        // Breadcrumbs
+	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList'));
+	$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname);
+}
+$courseCode = $_GET['cidReq'];
+$surveyAnonymous = survey_manager::get_survey($survey_id, 0, $courseCode);
+$surveyAnonymous = $surveyAnonymous['anonymous'];
+if ($surveyAnonymous == 0 && api_is_anonymous()) {
+    api_not_allowed(true);
+} elseif ($surveyAnonymous == 0 && $userInvited == 0) {
+    if (!api_is_allowed_to_edit()) {
+        api_not_allowed(true);
+    }
+}
 // Header
 Display :: display_header(get_lang('SurveyPreview'));
 

+ 1 - 0
main/survey/survey.lib.php

@@ -149,6 +149,7 @@ class survey_manager
 			$return['shuffle']				= $return['shuffle'];
 			$return['parent_id']			= $return['parent_id'];
 			$return['survey_version']		= $return['survey_version'];
+			$return['anonymous']		        = $return['anonymous'];
         }
         return $return;
 	}