tiki-take_survey.php 3.46 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
changi67's avatar
changi67 committed
2 3
// (c) Copyright 2002-2009 by authors of the Tiki Wiki/CMS/Groupware Project
// 
4 5
// 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.
changi67's avatar
changi67 committed
6
// $Id: /cvsroot/tikiwiki/tiki/tiki-take_survey.php,v 1.18.2.1 2007-12-07 05:56:38 mose Exp $
7
$section = 'surveys';
8 9
require_once ('tiki-setup.php');
include_once ('lib/surveys/surveylib.php');
10
if ($prefs['feature_categories'] == 'y') {
11 12
	global $categlib;
	if (!is_object($categlib)) {
changi67's avatar
changi67 committed
13
		include_once ('lib/categories/categlib.php');
14 15
	}
}
16
if ($prefs['feature_surveys'] != 'y') {
changi67's avatar
changi67 committed
17
	$smarty->assign('msg', tra("This feature is disabled") . ": feature_surveys");
18
	$smarty->display("error.tpl");
19
	die;
lrargerich's avatar
lrargerich committed
20
}
21 22
if (!isset($_REQUEST["surveyId"])) {
	$smarty->assign('msg', tra("No survey indicated"));
23
	$smarty->display("error.tpl");
24
	die;
lrargerich's avatar
lrargerich committed
25
}
26 27 28 29 30
$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');
changi67's avatar
changi67 committed
31
		foreach($perms["data"] as $perm) {
32 33 34 35 36 37 38 39 40 41
			$permName = $perm["permName"];
			if ($userlib->object_has_permission($user, $_REQUEST["surveyId"], 'survey', $permName)) {
				$$permName = 'y';
				$smarty->assign("$permName", 'y');
			} else {
				$$permName = 'n';
				$smarty->assign("$permName", 'n');
			}
		}
	}
42
} elseif ($tiki_p_admin != 'y' && $prefs['feature_categories'] == 'y') {
43
	$perms_array = $categlib->get_object_categories_perms($user, 'survey', $_REQUEST['surveyId']);
changi67's avatar
changi67 committed
44 45 46 47 48 49 50 51
	if ($perms_array) {
		$is_categorized = TRUE;
		foreach($perms_array as $perm => $value) {
			$$perm = $value;
		}
	} else {
		$is_categorized = FALSE;
	}
52
	if ($is_categorized && isset($tiki_p_view_categorized) && $tiki_p_view_categorized != 'y') {
53
		$smarty->assign('errortype', 401);
changi67's avatar
changi67 committed
54
		$smarty->assign('msg', tra("Permission denied you cannot view this page"));
55
		$smarty->display("error.tpl");
56 57
		die;
	}
lrargerich's avatar
lrargerich committed
58
}
59 60
$smarty->assign('surveyId', $_REQUEST["surveyId"]);
$survey_info = $srvlib->get_survey($_REQUEST["surveyId"]);
nyloth's avatar
nyloth committed
61
$smarty->assign('survey_info', $survey_info);
62
if ($tiki_p_take_survey != 'y') {
63
	$smarty->assign('msg', tra("You don't have permission to use this feature"));
64
	$smarty->display("error.tpl");
65 66
	die;
}
lrargerich's avatar
lrargerich committed
67
// Check if user has taken this survey
68 69 70
if ($tiki_p_admin != 'y') {
	if ($tikilib->user_has_voted($user, 'survey' . $_REQUEST["surveyId"])) {
		$smarty->assign('msg', tra("You cannot take this survey twice"));
71
		$smarty->display("error.tpl");
72 73
		die;
	}
lrargerich's avatar
lrargerich committed
74
}
changi67's avatar
changi67 committed
75
if ($_REQUEST["vote"]) $srvlib->add_survey_hit($_REQUEST["surveyId"]);
76 77 78
$questions = $srvlib->list_survey_questions($_REQUEST["surveyId"], 0, -1, 'position_asc', '');
$smarty->assign_by_ref('questions', $questions["data"]);
if (isset($_REQUEST["ans"])) {
79
	check_ticket('take-survey');
80 81
	$error_msg = '';
	$srvlib->register_answers($_REQUEST['surveyId'], $questions['data'], $_REQUEST, $error_msg);
changi67's avatar
changi67 committed
82
	if ($error_msg == '') header('Location: tiki-list_surveys.php');
lrargerich's avatar
lrargerich committed
83
}
84
include_once ('tiki-section_options.php');
nyloth's avatar
nyloth committed
85
include_once ('textareasize.php');
86
include_once ('lib/quicktags/quicktagslib.php');
changi67's avatar
changi67 committed
87
$quicktags = $quicktagslib->list_quicktags(0, -1, 'taglabel_asc', '', 'wiki');
88 89
$smarty->assign_by_ref('quicktags', $quicktags["data"]);
$smarty->assign('quicktagscant', $quicktags["cant"]);
90
ask_ticket('take-survey');
lrargerich's avatar
lrargerich committed
91
// Display the template
nyloth's avatar
nyloth committed
92
$smarty->assign('error_msg', $error_msg);
93
$smarty->assign('mid', 'tiki-take_survey.tpl');
94
$smarty->display("tiki.tpl");