5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2010, FusionForge Team
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * vote_number_to_stars() - Turns vote results into *'s
28 * @param int Raw value
30 function vote_number_to_stars($raw) {
32 // echo "\n\n<!-- $raw -->\n\n";
38 $count=intval($raw/2);
39 for ($i=0; $i<$count; $i++) {
40 $return .= html_image("ic/check.png","15","16");
43 $return .= html_image("ic/halfcheck.png","15","16");
49 * vote_show_thumbs() - Show vote stars
51 * @param int The survey ID
52 * @param string The rating type
54 function vote_show_thumbs($id,$flag) {
62 $rating=vote_get_rating ($id,$flag);
64 return "<strong>(unrated)</strong>";
66 return vote_number_to_stars($rating).'('.$rating.')';
71 * vote_get_rating() - Get a vote rating
73 * @param int The survey ID
74 * @param string The rating type
76 function vote_get_rating ($id,$flag) {
77 $result = db_query_params ('SELECT response FROM survey_rating_aggregate WHERE type=$1 AND id=$2',
80 if (!$result || (db_numrows($result) < 1) || (db_result($result,0,0)==0)) {
83 return db_result($result,0,0);
88 * vote_show_release_radios() - Show release radio buttons
90 * @param int Survey ID
91 * @param string The rating type
93 function vote_show_release_radios ($vote_on_id,$flag) {
102 //html_blankimage($height,$width)
103 $rating=vote_get_rating ($vote_on_id,$flag);
107 $rating=((16*vote_get_rating ($vote_on_id,$flag))-15);
111 <form action="/survey/rating_resp.php" method="post">
112 <input type="radio" name="vote_on_id" value="<?php echo $vote_on_id; ?>" />
113 <input type="radio" name="redirect_to" value="<?php echo urlencode(getStringFromServer('REQUEST_URI')); ?>" />
114 <input type="radio" name="flag" value="<?php echo $flag; ?>" />
115 <div style="margin-left: auto; margin-right: auto;">
116 <?php echo html_image("rateit.png","100","9"); ?>
119 echo html_blankimage(1,$rating);
120 echo html_image("ic/caret.png","9","6");
123 <input type="radio" name="response" value="1" />
124 <input type="radio" name="response" value="2" />
125 <input type="radio" name="response" value="3" />
126 <input type="radio" name="response" value="4" />
127 <input type="radio" name="response" value="5" />
129 <input type="submit" name="submit" value="Rate" />
138 * show_survey() - Select and show a specific survey from the database
140 * @param int The group ID
141 * @param int The survey ID
143 function show_survey ($group_id,$survey_id) {
145 Select this survey from the database
148 $result = db_query_params ('SELECT * FROM surveys WHERE survey_id=$1 and group_id = $2',
152 if (db_numrows($result) > 0) {
154 <h3>'.db_result($result, 0, 'survey_title').'</h3>
155 <form action="/survey/survey_resp.php" method="post">
156 <input type="hidden" name="group_id" value="'.$group_id.'" />
157 <input type="hidden" name="survey_id" value="'.$survey_id.'" />';
160 Select the questions for this survey
163 $questions=db_result($result, 0, 'survey_questions');
164 $quest_array=explode(',', $questions);
165 $count=count($quest_array);
170 for ($i=0; $i<$count; $i++) {
172 Build the questions on the HTML form
175 $result = db_query_params ('SELECT * FROM survey_questions WHERE question_id=$1',
176 array ($quest_array[$i]));
177 $question_type=db_result($result, 0, 'question_type');
179 if ($question_type == '4') {
181 Don't show question number if it's just a comment
185 <tr><td class="top"> </td><td>';
189 <tr><td class="top"><strong>';
191 If it's a 1-5 question box and first in series, move Quest
194 if (($question_type != $last_question_type) && (($question_type == '1') || ($question_type == '3'))) {
198 echo $q_num.' <br /></td><td>';
202 if ($question_type == "1") {
204 This is a radio-button question. Values 1-5.
206 // Show the 1-5 markers only if this is the first in a series
208 if ($question_type != $last_question_type) {
210 <strong>1</strong>'._('Low').' <strong>5</strong>' ._('High');
215 for ($j=1; $j<=5; $j++) {
217 <input type="radio" name="_'.$quest_array[$i].'" value="'.$j.'" />';
220 echo ' '.stripslashes(db_result($result, 0, 'question'));
222 } else if ($question_type == '2') {
224 This is a text-area question.
227 echo stripslashes(db_result($result, 0, 'question')).'<br />';
229 <textarea name="_'.$quest_array[$i].'" rows="5" cols="60"></textarea>';
231 } else if ($question_type == '3') {
233 This is a Yes/No question.
236 //Show the Yes/No only if this is the first in a series
238 if ($question_type != $last_question_type) {
239 echo '<strong>Yes / No</strong><br />';
243 <input type="radio" name="_'.$quest_array[$i].'" value="1" />';
245 <input type="radio" name="_'.$quest_array[$i].'" value="5" />';
247 echo ' '.stripslashes(db_result($result, 0, 'question'));
249 } else if ($question_type == '4') {
251 This is a comment only.
254 echo ' <br /><strong>'.util_make_links(stripslashes(db_result($result, 0, 'question'))).'</strong>';
256 <input type="hidden" name="_'.$quest_array[$i].'" value="-666" />';
258 } else if ($question_type == '5') {
260 This is a text-field question.
263 echo stripslashes(db_result($result, 0, 'question')).'<br />';
265 <input type="text" name="_'.$quest_array[$i].'" size="20" maxlength="70" />';
269 // no answers, just show question
270 echo stripslashes(db_result($result, 0, 'question')).'<br />';
275 $last_question_type=$question_type;
279 <tr><td class="align-center" colspan="2">
281 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
283 <?php util_make_link ('/survey/privacy.php',_('Survey Privacy')) ?>
290 echo "<strong>"._('Survey not found.')."</strong>";
296 * Show a single question for the new user rating system
298 * @param string The question to show
299 * @param string The array element
301 function vote_show_a_question ($question,$element_name) {
303 <tr><td colspan="2" style="white-space: nowrap;">
304 <input type="radio" name="Q_'. $element_name .'" value="-3">
305 <input type="radio" name="Q_'. $element_name .'" value="-2" />
306 <input type="radio" name="Q_'. $element_name .'" value="-1" />
307 <input type="radio" name="Q_'. $element_name .'" value="0.1" />
308 <input type="radio" name="Q_'. $element_name .'" value="1" />
309 <input type="radio" name="Q_'. $element_name .'" value="2" />
310 <input type="radio" name="Q_'. $element_name .'" value="3" />
313 <tr><td colspan="2">'.$question.'
314 <br /> </td></tr>';
320 The ratings system is actually flexible enough
321 to let you do N number of questions, but we are just going with 5
322 that apply to everyone
326 $USER_RATING_QUESTIONS=array();
327 //sorry - array starts at 1 so we can test for the questions on the receiving page
328 $USER_RATING_QUESTIONS[1]='Teamwork / Attitude';
329 $USER_RATING_QUESTIONS[2]='Code';
330 $USER_RATING_QUESTIONS[3]='Design / Architecture';
331 $USER_RATING_QUESTIONS[4]='Follow-Through / Reliability';
332 $USER_RATING_QUESTIONS[5]='Leadership / Management';
334 $USER_RATING_POPUP1[]='0 - Soloist';
335 $USER_RATING_POPUP1[]='1';
336 $USER_RATING_POPUP1[]='2';
337 $USER_RATING_POPUP1[]='3';
338 $USER_RATING_POPUP1[]='4';
339 $USER_RATING_POPUP1[]='5';
340 $USER_RATING_POPUP1[]='6 - Team Player';
342 $USER_RATING_POPUP2[]='0 - Beginner';
343 $USER_RATING_POPUP2[]='1';
344 $USER_RATING_POPUP2[]='2';
345 $USER_RATING_POPUP2[]='3';
346 $USER_RATING_POPUP2[]='4';
347 $USER_RATING_POPUP2[]='5';
348 $USER_RATING_POPUP2[]='6 - Master';
350 $USER_RATING_POPUP3[]='0 - Basic';
351 $USER_RATING_POPUP3[]='1';
352 $USER_RATING_POPUP3[]='2';
353 $USER_RATING_POPUP3[]='3';
354 $USER_RATING_POPUP3[]='4';
355 $USER_RATING_POPUP3[]='5';
356 $USER_RATING_POPUP3[]='6 - Elaborate';
358 $USER_RATING_POPUP4[]='0 - Unreliable';
359 $USER_RATING_POPUP4[]='1';
360 $USER_RATING_POPUP4[]='2';
361 $USER_RATING_POPUP4[]='3';
362 $USER_RATING_POPUP4[]='4';
363 $USER_RATING_POPUP4[]='5';
364 $USER_RATING_POPUP4[]='6 - Dependable';
366 $USER_RATING_POPUP5[]='0 - Weak';
367 $USER_RATING_POPUP5[]='1';
368 $USER_RATING_POPUP5[]='2';
369 $USER_RATING_POPUP5[]='3';
370 $USER_RATING_POPUP5[]='4';
371 $USER_RATING_POPUP5[]='5';
372 $USER_RATING_POPUP5[]='6 - Strong';
374 $USER_RATING_VALUES[]='-3';
375 $USER_RATING_VALUES[]='-2';
376 $USER_RATING_VALUES[]='-1';
377 $USER_RATING_VALUES[]='0.1';
378 $USER_RATING_VALUES[]='1';
379 $USER_RATING_VALUES[]='2';
380 $USER_RATING_VALUES[]='3';
383 * vote_show_user_rate_box() - Show user rating box
385 * @param int The user ID
386 * @param int The user ID of the user who is rating $user_id
388 function vote_show_user_rate_box ($user_id, $by_id=0) {
390 $res = db_query_params ('
391 SELECT rate_field,rating FROM user_ratings
397 $prev_vote = util_result_columns_to_assoc($res);
398 while (list($k,$v) = each($prev_vote)) {
400 $prev_vote[$k] = 0.1;
405 global $USER_RATING_VALUES,$USER_RATING_QUESTIONS,$USER_RATING_POPUP1,$USER_RATING_POPUP2,$USER_RATING_POPUP3,$USER_RATING_POPUP4,$USER_RATING_POPUP5;
408 <form action="/developer/rate.php" method="post">
410 for ($i=1; $i<=count($USER_RATING_QUESTIONS); $i++) {
411 $popup="USER_RATING_POPUP$i";
412 if (!isset($prev_vote[$i])) {
417 <td><strong>'. $USER_RATING_QUESTIONS[$i] .':</strong></td>
418 <td>'. html_build_select_box_from_arrays($USER_RATING_VALUES,$$popup,"Q_$i",$prev_vote[$i]/*'xzxz'*/,true,'Unrated').'</td>
424 <input type="submit" name="submit" value="Rate User" />
425 <input type="hidden" name="rated_user" value="'.$user_id.'" />
432 * vote_show_user_rating() - Show a user rating
434 * @param int The user ID
436 function vote_show_user_rating($user_id) {
437 global $USER_RATING_QUESTIONS;
438 $res = db_query_params ('SELECT rate_field,(avg(rating)+3) AS avg_rating,count(*) as count
441 GROUP BY rate_field',
443 $rows=db_numrows($res);
444 if (!$res || $rows < 1) {
446 echo '<tr><td colspan="2"><h4>Not Yet Rated</h4></td></tr>';
449 echo '<tr><td colspan="2">
450 <h4>Current Ratings</h4>
452 Includes untrusted ratings.</p></td></tr>';
453 for ($i=0; $i<$rows; $i++) {
455 <tr><td>'.$USER_RATING_QUESTIONS[db_result($res,$i,'rate_field')].'</td>
456 <td>'.db_result($res,$i,'avg_rating').' (By '. db_result($res,$i,'count') .' Users)</td></tr>';
459 $res = db_query_params ('SELECT ranking,metric,importance_factor FROM user_metric WHERE user_id=$1',
461 if ($res && db_numrows($res) > 0) {
462 echo '<tr><td colspan="2"><strong>Trusted Overall Rating</strong></td></tr>';
463 echo '<tr><td>Sitewide Ranking:</td><td><strong>'. db_result($res,0,'ranking') .'</strong></td></tr>
464 <tr><td>Aggregate Score:</td><td><strong>'. number_format (db_result($res,0,'metric'),3) .'</strong></td></tr>
465 <tr><td>Personal Importance:</td><td><strong>'. number_format (db_result($res,0,'importance_factor'),3) .'</strong></td></tr>';
467 echo '<tr><td colspan="2"><h4>Not Yet Included In Trusted Rankings</h4></td></tr>';
474 // c-file-style: "bsd"