tiki-take_survey.php 1.84 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
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 7
// $Id$

8
$section = 'surveys';
9 10
require_once ('tiki-setup.php');
include_once ('lib/surveys/surveylib.php');
11
if ($prefs['feature_categories'] == 'y') {
12 13
	global $categlib;
	if (!is_object($categlib)) {
changi67's avatar
changi67 committed
14
		include_once ('lib/categories/categlib.php');
15 16
	}
}
17 18 19

$access->check_feature('feature_surveys');

20 21
if (!isset($_REQUEST["surveyId"])) {
	$smarty->assign('msg', tra("No survey indicated"));
22
	$smarty->display("error.tpl");
23
	die;
lrargerich's avatar
lrargerich committed
24
}
25 26
$tikilib->get_perm_object( $_REQUEST["surveyId"], 'survey' );

27 28
$smarty->assign('surveyId', $_REQUEST["surveyId"]);
$survey_info = $srvlib->get_survey($_REQUEST["surveyId"]);
nyloth's avatar
nyloth committed
29
$smarty->assign('survey_info', $survey_info);
30 31
$access->check_permission('tiki_p_take_survey');

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