tiki-take_survey.php 4.41 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
2

3
// $Id: /cvsroot/tikiwiki/tiki/tiki-take_survey.php,v 1.18.2.1 2007-12-07 05:56:38 mose Exp $
4

5
// Copyright (c) 2002-2007, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
6 7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.

lrargerich's avatar
lrargerich committed
9
// Initialization
10
$section = 'surveys';
11
require_once ('tiki-setup.php');
lrargerich's avatar
lrargerich committed
12

13
include_once ('lib/surveys/surveylib.php');
lrargerich's avatar
lrargerich committed
14

15
if ($prefs['feature_categories'] == 'y') {
16 17 18 19 20 21
	global $categlib;
	if (!is_object($categlib)) {
		include_once('lib/categories/categlib.php');
	}
}

22
if ($prefs['feature_surveys'] != 'y') {
23
	$smarty->assign('msg', tra("This feature is disabled").": feature_surveys");
24

25
	$smarty->display("error.tpl");
26
	die;
lrargerich's avatar
lrargerich committed
27 28
}

29 30 31
if (!isset($_REQUEST["surveyId"])) {
	$smarty->assign('msg', tra("No survey indicated"));

32
	$smarty->display("error.tpl");
33
	die;
lrargerich's avatar
lrargerich committed
34 35
}

36 37 38 39 40 41 42
$smarty->assign('individual', 'n');

if ($userlib->object_has_one_permission($_REQUEST["surveyId"], 'survey')) {
	$smarty->assign('individual', 'y');

	if ($tiki_p_admin != 'y') {
		$perms = $userlib->get_permissions(0, -1, 'permName_desc', '', 'surveys');
lrargerich's avatar
lrargerich committed
43

44 45
		foreach ($perms["data"] as $perm) {
			$permName = $perm["permName"];
lrargerich's avatar
lrargerich committed
46

47 48 49 50 51 52 53 54 55 56 57
			if ($userlib->object_has_permission($user, $_REQUEST["surveyId"], 'survey', $permName)) {
				$$permName = 'y';

				$smarty->assign("$permName", 'y');
			} else {
				$$permName = 'n';

				$smarty->assign("$permName", 'n');
			}
		}
	}
58
} elseif ($tiki_p_admin != 'y' && $prefs['feature_categories'] == 'y') {
59 60 61 62 63 64 65 66 67
	$perms_array = $categlib->get_object_categories_perms($user, 'survey', $_REQUEST['surveyId']);
   	if ($perms_array) {
   		$is_categorized = TRUE;
    	foreach ($perms_array as $perm => $value) {
    		$$perm = $value;
    	}
   	} else {
   		$is_categorized = FALSE;
   	}
68
	if ($is_categorized && isset($tiki_p_view_categorized) && $tiki_p_view_categorized != 'y') {
69
		$smarty->assign('errortype', 401);
70
		$smarty->assign('msg',tra("Permission denied you cannot view this page"));
71
		$smarty->display("error.tpl");
72 73
		die;
	}
lrargerich's avatar
lrargerich committed
74 75
}

76 77
$smarty->assign('surveyId', $_REQUEST["surveyId"]);
$survey_info = $srvlib->get_survey($_REQUEST["surveyId"]);
lrargerich's avatar
lrargerich committed
78

79
if ($tiki_p_take_survey != 'y') {
80
	$smarty->assign('msg', tra("You don't have permission to use this feature"));
81

82
	$smarty->display("error.tpl");
83 84
	die;
}
lrargerich's avatar
lrargerich committed
85 86

// Check if user has taken this survey
87 88 89 90
if ($tiki_p_admin != 'y') {
	if ($tikilib->user_has_voted($user, 'survey' . $_REQUEST["surveyId"])) {
		$smarty->assign('msg', tra("You cannot take this survey twice"));

91
		$smarty->display("error.tpl");
92 93
		die;
	}
lrargerich's avatar
lrargerich committed
94 95
}

96 97
if ($_REQUEST["vote"])
  $srvlib->add_survey_hit($_REQUEST["surveyId"]);
lrargerich's avatar
lrargerich committed
98

99 100 101 102 103 104
$smarty->assign('survey_info', $survey_info);

$questions = $srvlib->list_survey_questions($_REQUEST["surveyId"], 0, -1, 'position_asc', '');
$smarty->assign_by_ref('questions', $questions["data"]);

if (isset($_REQUEST["ans"])) {
105
	check_ticket('take-survey');
106 107 108
	foreach ($questions["data"] as $question) {
		$questionId = $question["questionId"];

109
		//print("question: $questionId<br />");
110 111 112 113 114 115 116 117 118 119 120 121 122
		if (isset($_REQUEST["question_" . $questionId])) {
			if ($question["type"] == 'm') {
				// If we have a multiple question
				$ids = array_keys($_REQUEST["question_" . $questionId]);

				//print_r($ids);
				// Now for each of the options we increase the number of votes
				foreach ($ids as $optionId) {
					$srvlib->register_survey_option_vote($questionId, $optionId);
				}
			} else {
				$value = $_REQUEST["question_" . $questionId];

123
				//print("value: $value<br />");
124 125
				if ($question["type"] == 'r' || $question["type"] == 's') {
					$srvlib->register_survey_rate_vote($questionId, $value);
126
				} elseif ($question["type"] == 't' || $question["type"] == 'x') {
127 128 129 130 131 132 133 134 135 136
					$srvlib->register_survey_text_option_vote($questionId, $value);
				} else {
					$srvlib->register_survey_option_vote($questionId, $value);
				}
			}
		}
	}

	$tikilib->register_user_vote($user, 'survey' . $_REQUEST["surveyId"]);
	header ("location: tiki-list_surveys.php");
lrargerich's avatar
lrargerich committed
137 138 139
}

//print_r($questions);
140
include_once ('tiki-section_options.php');
lrargerich's avatar
lrargerich committed
141

142 143 144 145 146 147 148
include_once("textareasize.php");

include_once ('lib/quicktags/quicktagslib.php');
$quicktags = $quicktagslib->list_quicktags(0,-1,'taglabel_desc','','wiki');
$smarty->assign_by_ref('quicktags', $quicktags["data"]);
$smarty->assign('quicktagscant', $quicktags["cant"]);

149 150
ask_ticket('take-survey');

lrargerich's avatar
lrargerich committed
151
// Display the template
152
$smarty->assign('mid', 'tiki-take_survey.tpl');
153
$smarty->display("tiki.tpl");
154

155
?>