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';
28 require_once $gfwww.'include/HTML_Graphs.php';
29 require_once $gfwww.'survey/survey_utils.php';
32 $group_id = getIntFromRequest('group_id');
33 $survey_id = getIntFromRequest('survey_id');
34 survey_header(array('title'=>_('Survey Aggregate Results')));
36 if (!session_loggedin() || !user_ismember($group_id,'A')) {
37 echo '<div class="error">'._('Permission denied').'</div>';
38 survey_footer(array());
43 Select this survey from the database
46 $result = db_query_params ('SELECT * FROM surveys WHERE survey_id=$1 AND group_id=$2',
50 echo "<h2>".db_result($result, 0, "survey_title")."</h2><p> </p>";
53 echo "<h3><a href=\"show_results_csv.php?survey_id=$survey_id&group_id=$group_id\">.CSV File</a></h3><p>";
57 Select the questions for this survey
60 $questions=db_result($result, 0, "survey_questions");
61 $questions=str_replace(" ", "", $questions);
62 $quest_array=explode(',', $questions);
63 $count=count($quest_array);
69 for ($i=0; $i<$count; $i++) {
72 Build the questions on the HTML form
75 $result = db_query_params ('SELECT question_type,question,question_id FROM survey_questions WHERE question_id=$1 AND group_id=$2',
76 array ($quest_array[$i],
79 $question_type=db_result($result, 0, "question_type");
81 if ($question_type == "4") {
83 Don't show question number if it's just a comment
86 echo "\n<tr><td valign=\"top\"> </td>\n<td>";
90 echo "\n<tr><td valign=\"top\"><strong>";
93 If it's a 1-5 question box and first in series, move Quest
97 if (($question_type != $last_question_type) && (($question_type == "1") || ($question_type == "3"))) {
98 echo " <p> </p>";
101 echo $q_num." <br /></td>\n<td>";
106 if ($question_type == "1") { // This is a radio-button question. Values 1-5.
107 // Show the 1-5 markers only if this is the first in a series
109 if ($question_type != $last_question_type) {
110 echo "\n<strong>1 5</strong>\n";
115 // Select the number of responses to this question
117 $result2 = db_query_params ('SELECT count(*) AS count FROM survey_responses WHERE survey_id=$1 AND question_id=$2 AND response IN (1,2,3,4,5) AND group_id=$3',
121 if (!$result2 || db_numrows($result2) < 1) {
125 $response_count = db_result($result2, 0, 'count');
126 echo "<strong>" . $response_count . "</strong>" ._('Responses')."<br />";
130 if ($response_count > 0){
131 $result2 = db_query_params ('SELECT avg(response::int) AS avg FROM survey_responses WHERE survey_id=$1 AND question_id=$2 AND group_id=$3 AND response IN (1,2,3,4,5)',
135 if (!$result2 || db_numrows($result2) < 1) {
139 echo "<strong>". number_format(db_result($result2, 0, 'avg'),2) ."</strong>"._('Average');
142 $result2 = db_query_params ('SELECT response,count(*) AS count FROM survey_responses WHERE survey_id=$1 AND question_id=$2 AND group_id=$3 AND response IN (1,2,3,4,5) GROUP BY response',
146 if (!$result2 || db_numrows($result2) < 1) {
150 GraphResult($result2,stripslashes(db_result($result, 0, "question")));
152 }// end if (responses to survey question present)
153 } else if ($question_type == "2") { // This is a text-area question.
154 echo db_result($result, 0, "question")."<br />\n";
155 echo "<a href=\"show_results_comments.php?survey_id=$survey_id&question_id=$quest_array[$i]&group_id=$group_id\">"._('View All Comments')."</a>";
157 } else if ($question_type == "3") { // This is a Yes/No question.
158 // Show the Yes/No only if this is the first in a series
159 if ($question_type != $last_question_type) {
160 echo "<strong>"._('Yes / No')."</strong><br />\n";
163 // Select the count and average of responses to this question
165 $result2 = db_query_params ('SELECT count(*) AS count FROM survey_responses WHERE survey_id=$1 AND question_id=$2 AND group_id=$3 AND response IN (1,5)',
169 if (!$result2 || db_numrows($result2) < 1) {
173 echo "<strong>".db_result($result2, 0, 0)."</strong> "._('Responses')."<br />";
178 $result2 = db_query_params ('SELECT avg(response::int) AS avg FROM survey_responses WHERE survey_id=$1 AND question_id=$2 AND group_id=$3 and response != $4',
184 if (!$result2 || db_numrows($result2) < 1) {
188 echo "<strong>".number_format(db_result($result2, 0, 0),2)."</strong>"._('Average');
191 // Get the YES responses
192 $result2 = db_query_params ('SELECT count(*) AS count FROM survey_responses WHERE survey_id=$1 AND question_id=$2 AND group_id=$3 AND response=1',
197 $name_array[0]=_('Yes');
199 if (!$result2 || db_numrows($result2) < 1) {
202 $value_array[0]=db_result($result2, 0, "count");
205 // Get the NO responses
206 $result2 = db_query_params ('SELECT count(*) AS count FROM survey_responses WHERE survey_id=$1 AND question_id=$2 AND group_id=$3 AND response=5',
211 $name_array[1]=_('No');
213 if (!$result2 || db_numrows($result2) < 1) {
216 $value_array[1]=db_result($result2, 0, "count");
219 GraphIt($name_array,$value_array,stripslashes(db_result($result, 0, "question")));
221 } else if ($question_type == "4") {
223 echo " <p><strong>".db_result($result, 0, "question")."</strong></p>\n";
224 echo "<input type=\"hidden\" name=\"_".$quest_array[$i]."\" value=\"-666\" />";
226 } else if ($question_type == "5") { // This is a text-field question.
227 echo db_result($result, 0, "question")."<br />\n";
229 echo "<a href=\"show_results_comments.php?survey_id=$survey_id&question_id=$quest_array[$i]&group_id=$group_id\">"._('View All Comments')."</a>";
235 $last_question_type=$question_type;
241 survey_footer(array());
245 // c-file-style: "bsd"