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
29 require_once('../../env.inc.php');
30 require_once('pre.php');
31 require_once('www/survey/survey_utils.php');
34 $group_id = getIntFromRequest('group_id');
35 $survey_id = getIntFromRequest('survey_id');
36 $customer_id = getIntFromRequest('customer_id');
37 survey_header(array('title'=>$Language->getText('survey_show_results_individual','title')));
39 if (!session_loggedin() || !user_ismember($group_id,'A')) {
40 echo "<h1>".$Language->getText('survey_show_results_individual','permission_denied')."</h1>";
41 survey_footer(array());
51 Select this survey from the database
54 $sql="SELECT * FROM surveys WHERE survey_id='$survey_id' AND group_id='$group_id'";
55 $result=db_query($sql);
57 echo "\n<h2>".db_result($result, 0, "survey_title")."</h2><p> </p>";
60 Select the questions for this survey
63 $questions=db_result($result, 0, "survey_questions");
64 $questions=str_replace(" ", "", $questions);
65 $quest_array=explode(',', $questions);
67 $count=count($quest_array);
70 Display info for this customer
74 $sql="select * from people where cust_id='$customer_id'";
76 $result=db_query($sql);
78 echo "\n<strong>Name: </strong>".db_result($result, 0, "first_name")." ".db_result($result, 0, "last_name")."<br />";
79 echo "\n<strong>Email: </strong>".db_result($result, 0, "email")." / ".db_result($result, 0, "email2")."<br />";
80 echo "\n<strong>Phone: </strong>".db_result($result, 0, "phone")."<br />";
81 echo "\n<strong>Beeper: </strong>".db_result($result, 0, "beeper")."<br />";
82 echo "\n<strong>Cell: </strong>".db_result($result, 0, "cell")."<p>";
89 for ($i=0; $i<$count; $i++) {
92 Build the questions on the HTML form
95 $sql="select questions.question_type,questions.question,questions.question_id,responses.response ".
96 "from questions,responses where questions.question_id='".$quest_array[$i]."' and ".
97 "questions.question_id=responses.question_id and responses.customer_id='$customer_id' AND responses.survey_id='$survey_id'";
99 $result=db_query($sql);
102 See if there was a result. If not a result, join might have failed because of "open ended question".
103 In that case, requery, and test again. If still no response, then this is a "comment only" question
105 if (!$result || db_numrows($result) < 1) {
107 //$result=db_query("select * from responses where question_id='".$quest_array[$i]."' and survey_id='$survey_id' AND customer_id='$customer_id'");
109 //echo "\n\n<!-- falling back 1 -->";
111 //if (!$result || db_numrows($result) < 1) {
112 // echo "\n\n<!-- falling back 2 -->";
113 $result=db_query("select * from survey_questions where question_id='".$quest_array[$i]."'");
123 //echo "\n\nnotfound: '$not_found'";
125 $question_type=db_result($result, 0, "question_type");
127 if ($question_type == "4") {
129 Don't show question number if it's just a comment
132 echo "\n<tr><td valign=\"top\"> </td>\n<td>";
136 echo "\n<tr><td valign=\"top\"><strong>";
139 If it's a 1-5 question box and first in series, move Quest
143 if (($question_type != $last_question_type) && (($question_type == "1") || ($question_type == "3"))) {
144 echo " <p> </p>";
147 echo $q_num." <br /></td>\n<td>";
152 if ($question_type == "1") {
155 This is a radio-button question. Values 1-5.
159 // Show the 1-5 markers only if this is the first in a series
161 if ($question_type != $last_question_type) {
162 echo "\n<strong>1 5</strong>\n";
167 for ($j=1; $j<=5; $j++) {
168 echo "\n<input type=\"radio\" name=\"_".$quest_array[$i]."\" value=\"$j\"";
170 add the checked statement if this was the response
172 if (($not_found==0) && db_result($result, 0, "response")=="$j") { echo " checked=\"checked\""; }
176 echo " ".db_result($result, 0, "question")."\n";
178 } else if ($question_type == "2") {
181 This is a text-area question.
184 echo db_result($result, 0, "question")."<br />\n";
185 echo "\n<textarea name=\"_".$quest_array[$i]."\" rows=\"5\" cols=\"60\" wrap=\"soft\">";
188 Show the person's response if there was one
192 echo db_result($result, 0, "response");
194 echo "</textarea>\n";
196 } else if ($question_type == "3") {
199 This is a Yes/No question.
203 Show the Yes/No only if this is the first in a series
206 if ($question_type != $last_question_type) {
207 echo "<strong>".$Language->getText('survey_show_results_individual','yes_no')."</strong><br />\n";
210 echo "\n<input type=\"radio\" name=\"_".$quest_array[$i]."\" value=\"1\"";
213 add the checked statement if this was the response
216 if (($not_found==0) && db_result($result, 0, "response")=="1") { echo " checked=\"checked\""; }
218 echo "\n<input type=\"radio\" name=\"_".$quest_array[$i]."\" value=\"5\"";
221 add the checked statement if this was the response
223 if (($not_found==0) && db_result($result, 0, "response")=="5") { echo " checked=\"checked\""; }
227 echo " ".db_result($result, 0, "question")."\n";
229 } else if ($question_type == "4") {
232 This is a comment only.
235 echo "\n <p><strong>".db_result($result, 0, "question")."</strong></p>\n";
236 echo "\n<input type=\"hidden\" name=\"_".$quest_array[$i]."\" value=\"-666\" />";
238 } else if ($question_type == "5") {
241 This is a text-field question.
244 echo db_result($result, 0, "question")."<br />\n";
245 echo "\n<input type=\"text\" name=\"_".$quest_array[$i]."\" size=\"20\" maxlength=\"70\" value=\"";
248 Show the person's response if there was one
251 echo db_result($result, 0, "response");
259 $last_question_type=$question_type;
270 survey_footer(array());