5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
8 * http://fusionforge.org/
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once('../../env.inc.php');
27 require_once $gfcommon.'include/pre.php';
29 require_once $gfcommon.'survey/Survey.class.php';
30 require_once $gfcommon.'survey/SurveyFactory.class.php';
31 require_once $gfcommon.'survey/SurveyQuestion.class.php';
32 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
33 require_once $gfcommon.'survey/SurveyResponse.class.php';
34 require_once $gfcommon.'survey/SurveyResponseFactory.class.php';
35 require_once $gfwww.'survey/include/SurveyHTML.class.php';
37 $group_id = getIntFromRequest('group_id');
38 $survey_id = getIntFromRequest('survey_id');
39 $graph = getStringFromRequest('graph');
40 $show_comment = getStringFromRequest('show_comment');
42 /* We need a group_id */
47 $g = group_get_object($group_id);
48 if (!$g || !is_object($g) || $g->isError()) {
53 $sh = new SurveyHtml();
55 $title = _('Survey Results');
56 $sh->header(array('title'=>$title));
58 if (!session_loggedin() || !user_ismember($group_id,'A')) {
59 echo '<div class="error">'._('Permission denied').'</div>';
64 /* Show detailed results of a survey */
66 $s = new Survey($g, $survey_id);
68 if (!$s || !is_object($s)) {
69 echo '<div class="error">'._('Error'). ' ' . _('Cannot get Survey') ."</div>";
72 } else if ( $s->isError()) {
73 echo '<div class="error">'._('Error'). $s->getErrorMessage() ."</div>";
78 /* A specific question */
79 $question_id = getIntFromRequest('question_id');
81 /* Create a Survey Question for general purpose */
82 $sq = new SurveyQuestion($g, $question_id);
83 if (!$sq || !is_object($sq)) {
84 echo '<div class="error">'._('Error'). ' ' . _('Cannot get Survey Question') ."</div>";
85 } else if ( $sq->isError()) {
86 echo '<div class="error">'._('Error'). $sq->getErrorMessage() ."</div>";
88 showResult($sh, $s, $sq, 1, 0, $graph);
92 echo '<h2>'.$s->getTitle().' ( '. $s->getNumberOfVotes() .' Votes )</h2><p/>';
94 /* Get questions of this survey */
95 $questions = & $s->getQuestionInstances();
98 for ($i=0; $i<count($questions); $i++) {
99 if ($questions[$i]->isError()) {
100 echo $questions[$i]->getErrorMessage();
102 if ($questions[$i]->getQuestionType()!='4') {
103 showResult($sh, $s, $questions[$i], $show_comment, $question_number++, $graph);
110 /* Show list of Surveys with result link */
111 /* Show list of Servey */
112 $sf = new SurveyFactory($g);
113 $ss = & $sf->getSurveys();
115 echo '<p class="warning_msg">' . _('No Survey Question is found') . '</p>';
117 echo($sh->showSurveys($ss, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1));
120 $sh->footer(array());
123 * showResult - Get Result from Survey and Question. Pass the reuslt to Show Result HTML class
125 * @param object a survey object
126 * @param object a qustsion object
127 * @param int wheather print out export(csv) format
129 function showResult(&$SurveyHTML, &$Survey, &$Question, $show_comment=0, $q_num="", $graph=0) {
131 $srf = new SurveyResponseFactory($Survey, $Question);
132 if (!$srf || !is_object($srf)) {
133 echo '<div class="error">'._('Error'). ' ' . _('Cannot get Survey Response Factory') ."</div>";
134 } else if ( $srf->isError()) {
135 echo '<div class="error">'._('Error'). $srf->getErrorMessage() ."</div>";
137 /* Show result in HTML*/
138 echo ($SurveyHTML->showResult($srf, $show_comment, $q_num, $graph));
144 // c-file-style: "bsd"