3 * GForge Survey Facility
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
11 * This file is part of GForge.
13 * GForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * GForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 require_once('../../env.inc.php');
29 require_once('pre.php');
31 require_once('common/survey/Survey.class');
32 require_once('common/survey/SurveyFactory.class');
33 require_once('common/survey/SurveyQuestion.class');
34 require_once('common/survey/SurveyQuestionFactory.class');
35 require_once('common/survey/SurveyResponse.class');
36 require_once('common/survey/SurveyResponseFactory.class');
37 require_once('www/survey/include/SurveyHTML.class');
39 $group_id = getIntFromRequest('group_id');
40 $survey_id = getIntFromRequest('survey_id');
41 $graph = getStringFromRequest('graph');
42 $show_comment = getStringFromRequest('show_comment');
44 /* We need a group_id */
49 $g =& group_get_object($group_id);
50 if (!$g || !is_object($g) || $g->isError()) {
55 $sh = new SurveyHtml();
58 $sh->header(array('title'=>_('Survey Results')));
60 if (!session_loggedin() || !user_ismember($group_id,'A')) {
61 echo "<h1>"._('Permission Denied')."</h1>";
66 /* Show detailed results of a survey */
68 $s = new Survey($g, $survey_id);
70 if (!$s || !is_object($s)) {
71 echo "<h3>"._('Error'). ' Can not get Survey' ."</H3>";
74 } else if ( $s->isError()) {
75 echo "<h3>"._('Error'). $s->getErrorMessage() ."</H3>";
80 /* A specific question */
81 $question_id = getIntFromRequest('question_id');
83 /* Create a Survey Question for general purpose */
84 $sq = new SurveyQuestion($g, $question_id);
85 if (!$sq || !is_object($sq)) {
86 echo "<h3>"._('Error'). ' Can not get Survey Question' ."</H3>";
87 } else if ( $sq->isError()) {
88 echo "<h3>"._('Error'). $sq->getErrorMessage() ."</H3>";
90 showResult($sh, $s, $sq, 1, 0, $graph);
94 echo '<h2>'.$s->getTitle().' ( '. $s->getNumberOfVotes() .' Votes )</h2><p/>';
96 /* Get questions of this survey */
97 $questions = & $s->getQuestionInstances();
100 for ($i=0; $i<count($questions); $i++) {
101 if ($questions[$i]->isError()) {
102 echo $questions[$i]->getErrorMessage();
104 if ($questions[$i]->getQuestionType()!='4') {
105 showResult($sh, $s, $questions[$i], $show_comment, $question_number++, $graph);
112 /* Show list of Surveys with result link */
113 /* Show list of Servey */
114 $sf = new SurveyFactory($g);
115 $ss = & $sf->getSurveys();
117 echo (_('No Survey Question is found'));
119 echo($sh->ShowSurveys($ss, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1));
122 $sh->footer(array());
125 * ShowResult - Get Result from Survey and Question. Pass the reuslt to Show Result HTML class
127 * @param object a survey object
128 * @param object a qustsion object
129 * @param int wheather print out export(csv) format
131 function ShowResult(&$SurveyHTML, &$Survey, &$Question, $show_comment=0, $q_num="", $graph=0) {
133 $srf = new SurveyResponseFactory(&$Survey, &$Question);
134 if (!$srf || !is_object($srf)) {
135 echo "<h3>"._('Error'). ' Can not get Survey Response Factory' ."</H3>";
136 } else if ( $srf->isError()) {
137 echo "<h3>"._('Error'). $srf->getErrorMessage() ."</H3>";
139 /* Show result in HTML*/
140 echo ($SurveyHTML->ShowResult($srf, $show_comment, $q_num, $graph));