3 * GForge Survey Facility
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
9 * This file is part of GForge.
11 * GForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * GForge 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
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 require_once('../../env.inc.php');
27 require_once $gfwww.'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();
56 $sh->header(array('title'=>_('Survey Results')));
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 '<div class="warning_msg">' . _('No Survey Question is found') . '</div>';
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"