5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
8 * Copyright 2013-2014, Franck Villaume - TrivialDev
9 * http://fusionforge.org/
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once '../../env.inc.php';
28 require_once $gfcommon.'include/pre.php';
30 require_once $gfcommon.'survey/Survey.class.php';
31 require_once $gfcommon.'survey/SurveyFactory.class.php';
32 require_once $gfcommon.'survey/SurveyQuestion.class.php';
33 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
34 require_once $gfcommon.'survey/SurveyResponse.class.php';
35 require_once $gfcommon.'survey/SurveyResponseFactory.class.php';
36 require_once $gfwww.'survey/include/SurveyHTML.class.php';
40 $group_id = getIntFromRequest('group_id');
41 $survey_id = getIntFromRequest('survey_id');
42 $graph = getStringFromRequest('graph');
43 $show_comment = getStringFromRequest('show_comment');
45 /* We need a group_id */
50 $g = group_get_object($group_id);
51 if (!$g || !is_object($g) || $g->isError()) {
55 $sh = new SurveyHtml();
57 html_use_jqueryjqplotpluginCanvas();
58 html_use_jqueryjqplotpluginPie();
59 html_use_jqueryjqplotpluginhighlighter();
60 html_use_jqueryjqplotplugindateAxisRenderer();
61 html_use_jqueryjqplotpluginBar();
63 $title = _('Survey Results');
64 $sh->header(array('title' => $title, 'modal' => 1));
66 if (!session_loggedin() || !forge_check_perm('project_admin', $group_id)) {
67 echo $HTML->error_msg(_('Permission denied.'));
72 /* Show detailed results of a survey */
74 $s = new Survey($g, $survey_id);
76 if (!$s || !is_object($s)) {
77 echo $HTML->error_msg(_('Error')._(': ')._('Cannot get Survey'));
80 } elseif ( $s->isError()) {
81 echo $HTML->error_msg(_('Error')._(': ').$s->getErrorMessage());
86 /* A specific question */
87 $question_id = getIntFromRequest('question_id');
89 /* Create a Survey Question for general purpose */
90 $sq = new SurveyQuestion($g, $question_id);
91 if (!$sq || !is_object($sq)) {
92 echo $HTML->error_msg(_('Error')._(': ')._('Cannot get Survey Question'));
93 } elseif ($sq->isError()) {
94 echo $HTML->error_msg(_('Error')._(': ').$sq->getErrorMessage());
96 showResult($sh, $s, $sq, 1, 0, $graph);
100 echo html_e('h2', array(),$s->getTitle().' ('. $s->getNumberOfVotes() .' ' . _("Votes") . ')');
102 /* Get questions of this survey */
103 $questions = $s->getQuestionInstances();
105 $question_number = 1;
106 for ($i=0; $i<count($questions); $i++) {
107 if ($questions[$i]->isError()) {
108 echo $questions[$i]->getErrorMessage();
110 if ($questions[$i]->getQuestionType()!='4') {
111 showResult($sh, $s, $questions[$i], $show_comment, $question_number++, $graph);
118 /* Show list of Surveys with result link */
119 /* Show list of Surveys */
120 $sf = new SurveyFactory($g);
121 $ss = & $sf->getSurveys();
123 echo $HTML->information(_('No Survey Question is found'));
125 echo $sh->showSurveys($ss, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1);
131 * showResult - Get Result from Survey and Question. Pass the result to Show Result HTML class
133 * @param object $SurveyHTML a survey object
134 * @param object $Survey
135 * @param object $Question a question object
136 * @param int $show_comment whether print out export(csv) format
137 * @param string $q_num
140 function showResult(&$SurveyHTML, &$Survey, &$Question, $show_comment=0, $q_num="", $graph=0) {
143 $srf = new SurveyResponseFactory($Survey, $Question);
144 if (!$srf || !is_object($srf)) {
145 echo $HTML->error_msg(_('Error'). ' ' . _('Cannot get Survey Response Factory'));
146 } elseif ($srf->isError()) {
147 echo $HTML->error_msg(_('Error'). $srf->getErrorMessage());
149 /* Show result in HTML*/
150 echo $SurveyHTML->showResult($srf, $show_comment, $q_num, $graph);