tiki-take_survey.php 2.23 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
$tikilib->get_perm_object( $_REQUEST["surveyId"], 'survey' );

28 29
$smarty->assign('surveyId', $_REQUEST["surveyId"]);
$survey_info = $srvlib->get_survey($_REQUEST["surveyId"]);
nyloth's avatar
nyloth committed
30
$smarty->assign('survey_info', $survey_info);
31
if ($tiki_p_take_survey != 'y') {
32
	$smarty->assign('msg', tra("You don't have permission to use this feature"));
33
	$smarty->display("error.tpl");
34 35
	die;
}
lrargerich's avatar
lrargerich committed
36
// Check if user has taken this survey
37 38 39
if ($tiki_p_admin != 'y') {
	if ($tikilib->user_has_voted($user, 'survey' . $_REQUEST["surveyId"])) {
		$smarty->assign('msg', tra("You cannot take this survey twice"));
40
		$smarty->display("error.tpl");
41 42
		die;
	}
lrargerich's avatar
lrargerich committed
43
}
changi67's avatar
changi67 committed
44
if ($_REQUEST["vote"]) $srvlib->add_survey_hit($_REQUEST["surveyId"]);
45 46 47
$questions = $srvlib->list_survey_questions($_REQUEST["surveyId"], 0, -1, 'position_asc', '');
$smarty->assign_by_ref('questions', $questions["data"]);
if (isset($_REQUEST["ans"])) {
48
	check_ticket('take-survey');
49 50
	$error_msg = '';
	$srvlib->register_answers($_REQUEST['surveyId'], $questions['data'], $_REQUEST, $error_msg);
changi67's avatar
changi67 committed
51
	if ($error_msg == '') header('Location: tiki-list_surveys.php');
lrargerich's avatar
lrargerich committed
52
}
53
include_once ('tiki-section_options.php');
nyloth's avatar
nyloth committed
54
include_once ('textareasize.php');
55
$smarty->assign('toolbarscant', $toolbars["cant"]);
56
ask_ticket('take-survey');
lrargerich's avatar
lrargerich committed
57
// Display the template
nyloth's avatar
nyloth committed
58
$smarty->assign('error_msg', $error_msg);
59
$smarty->assign('mid', 'tiki-take_survey.tpl');
60
$smarty->display("tiki.tpl");