5 * SourceForge: Breaking Down the Barriers to Open Source Development
6 * Copyright 1999-2001 (c) VA Linux Systems
7 * http://sourceforge.net
12 * vote_number_to_stars() - Turns vote results into *'s
14 * @param int Raw value
16 function vote_number_to_stars($raw) {
18 // echo "\n\n<!-- $raw -->\n\n";
24 $count=intval($raw/2);
25 for ($i=0; $i<$count; $i++) {
26 $return .= html_image("ic/check.png","15","16",array());
29 $return .= html_image("ic/halfcheck.png","15","16",array());
35 * vote_show_thumbs() - Show vote stars
37 * @param int The survey ID
38 * @param string The rating type
40 function vote_show_thumbs($id,$flag) {
48 $rating=vote_get_rating ($id,$flag);
50 return "<strong>(unrated)</strong>";
52 return vote_number_to_stars($rating).'('.$rating.')';
57 * vote_get_rating() - Get a vote rating
59 * @param int The survey ID
60 * @param string The rating type
62 function vote_get_rating ($id,$flag) {
63 $result = db_query_params ('SELECT response FROM survey_rating_aggregate WHERE type=$1 AND id=$2',
66 if (!$result || (db_numrows($result) < 1) || (db_result($result,0,0)==0)) {
69 return db_result($result,0,0);
74 * vote_show_release_radios() - Show release radio buttons
76 * @param int Survey ID
77 * @param string The rating type
79 function vote_show_release_radios ($vote_on_id,$flag) {
88 //html_blankimage($height,$width)
89 $rating=vote_get_rating ($vote_on_id,$flag);
93 $rating=((16*vote_get_rating ($vote_on_id,$flag))-15);
97 <form action="/survey/rating_resp.php" method="post">
98 <input type="radio" name="vote_on_id" value="<?php echo $vote_on_id; ?>" />
99 <input type="radio" name="redirect_to" value="<?php echo urlencode(getStringFromServer('REQUEST_URI')); ?>" />
100 <input type="radio" name="flag" value="<?php echo $flag; ?>" />
102 <?php echo html_image("rateit.png","100","9",array()); ?>
105 echo html_blankimage(1,$rating);
106 echo html_image("ic/caret.png","9","6",array());
109 <input type="radio" name="response" value="1" />
110 <input type="radio" name="response" value="2" />
111 <input type="radio" name="response" value="3" />
112 <input type="radio" name="response" value="4" />
113 <input type="radio" name="response" value="5" />
115 <input type="submit" name="submit" value="Rate" />
124 * show_survey() - Select and show a specific survey from the database
126 * @param int The group ID
127 * @param int The survey ID
129 function show_survey ($group_id,$survey_id) {
131 Select this survey from the database
134 $result = db_query_params ('SELECT * FROM surveys WHERE survey_id=$1 and group_id = $2',
138 if (db_numrows($result) > 0) {
140 <h3>'.db_result($result, 0, 'survey_title').'</h3>
141 <form action="/survey/survey_resp.php" method="post">
142 <input type="hidden" name="group_id" value="'.$group_id.'" />
143 <input type="hidden" name="survey_id" value="'.$survey_id.'" />';
146 Select the questions for this survey
149 $questions=db_result($result, 0, 'survey_questions');
150 $quest_array=explode(',', $questions);
151 $count=count($quest_array);
156 for ($i=0; $i<$count; $i++) {
158 Build the questions on the HTML form
161 $result = db_query_params ('SELECT * FROM survey_questions WHERE question_id=$1',
162 array ($quest_array[$i]));
163 $question_type=db_result($result, 0, 'question_type');
165 if ($question_type == '4') {
167 Don't show question number if it's just a comment
171 <tr><td valign="top"> </td><td>';
175 <tr><td valign="top"><strong>';
177 If it's a 1-5 question box and first in series, move Quest
180 if (($question_type != $last_question_type) && (($question_type == '1') || ($question_type == '3'))) {
184 echo $q_num.' <br /></td><td>';
188 if ($question_type == "1") {
190 This is a radio-button question. Values 1-5.
192 // Show the 1-5 markers only if this is the first in a series
194 if ($question_type != $last_question_type) {
196 <strong>1</strong>'._('Low').' <strong>5</strong>' ._('High');
201 for ($j=1; $j<=5; $j++) {
203 <input type="radio" name="_'.$quest_array[$i].'" value="'.$j.'" />';
206 echo ' '.stripslashes(db_result($result, 0, 'question'));
208 } else if ($question_type == '2') {
210 This is a text-area question.
213 echo stripslashes(db_result($result, 0, 'question')).'<br />';
215 <textarea name="_'.$quest_array[$i].'" rows="5" cols="60"></textarea>';
217 } else if ($question_type == '3') {
219 This is a Yes/No question.
222 //Show the Yes/No only if this is the first in a series
224 if ($question_type != $last_question_type) {
225 echo '<strong>Yes / No</strong><br />';
229 <input type="radio" name="_'.$quest_array[$i].'" value="1" />';
231 <input type="radio" name="_'.$quest_array[$i].'" value="5" />';
233 echo ' '.stripslashes(db_result($result, 0, 'question'));
235 } else if ($question_type == '4') {
237 This is a comment only.
240 echo ' <br /><strong>'.util_make_links(stripslashes(db_result($result, 0, 'question'))).'</strong>';
242 <input type="hidden" name="_'.$quest_array[$i].'" value="-666" />';
244 } else if ($question_type == '5') {
246 This is a text-field question.
249 echo stripslashes(db_result($result, 0, 'question')).'<br />';
251 <input type="text" name="_'.$quest_array[$i].'" size="20" maxlength="70" />';
255 // no answers, just show question
256 echo stripslashes(db_result($result, 0, 'question')).'<br />';
261 $last_question_type=$question_type;
265 <tr><td style="text-align:center" colspan="2">
267 <input type="submit" name="submit" value="<?php echo _('Submit') ?>" />
269 <?php util_make_link ('/survey/privacy.php',_('Survey Privacy')) ?>
276 echo "<strong>"._('Survey not found.')."</strong>";
282 * Show a single question for the new user rating system
284 * @param string The question to show
285 * @param string The array element
287 function vote_show_a_question ($question,$element_name) {
289 <tr><td colspan="2" style="white-space: nowrap;">
290 <input type="radio" name="Q_'. $element_name .'" value="-3">
291 <input type="radio" name="Q_'. $element_name .'" value="-2" />
292 <input type="radio" name="Q_'. $element_name .'" value="-1" />
293 <input type="radio" name="Q_'. $element_name .'" value="0.1" />
294 <input type="radio" name="Q_'. $element_name .'" value="1" />
295 <input type="radio" name="Q_'. $element_name .'" value="2" />
296 <input type="radio" name="Q_'. $element_name .'" value="3" />
299 <tr><td colspan="2">'.$question.'
300 <br /> </td></tr>';
306 The ratings system is actually flexible enough
307 to let you do N number of questions, but we are just going with 5
308 that apply to everyone
312 $USER_RATING_QUESTIONS=array();
313 //sorry - array starts at 1 so we can test for the questions on the receiving page
314 $USER_RATING_QUESTIONS[1]='Teamwork / Attitude';
315 $USER_RATING_QUESTIONS[2]='Code';
316 $USER_RATING_QUESTIONS[3]='Design / Architecture';
317 $USER_RATING_QUESTIONS[4]='Follow-Through / Reliability';
318 $USER_RATING_QUESTIONS[5]='Leadership / Management';
320 $USER_RATING_POPUP1[]='0 - Soloist';
321 $USER_RATING_POPUP1[]='1';
322 $USER_RATING_POPUP1[]='2';
323 $USER_RATING_POPUP1[]='3';
324 $USER_RATING_POPUP1[]='4';
325 $USER_RATING_POPUP1[]='5';
326 $USER_RATING_POPUP1[]='6 - Team Player';
328 $USER_RATING_POPUP2[]='0 - Beginner';
329 $USER_RATING_POPUP2[]='1';
330 $USER_RATING_POPUP2[]='2';
331 $USER_RATING_POPUP2[]='3';
332 $USER_RATING_POPUP2[]='4';
333 $USER_RATING_POPUP2[]='5';
334 $USER_RATING_POPUP2[]='6 - Master';
336 $USER_RATING_POPUP3[]='0 - Basic';
337 $USER_RATING_POPUP3[]='1';
338 $USER_RATING_POPUP3[]='2';
339 $USER_RATING_POPUP3[]='3';
340 $USER_RATING_POPUP3[]='4';
341 $USER_RATING_POPUP3[]='5';
342 $USER_RATING_POPUP3[]='6 - Elaborate';
344 $USER_RATING_POPUP4[]='0 - Unreliable';
345 $USER_RATING_POPUP4[]='1';
346 $USER_RATING_POPUP4[]='2';
347 $USER_RATING_POPUP4[]='3';
348 $USER_RATING_POPUP4[]='4';
349 $USER_RATING_POPUP4[]='5';
350 $USER_RATING_POPUP4[]='6 - Dependable';
352 $USER_RATING_POPUP5[]='0 - Weak';
353 $USER_RATING_POPUP5[]='1';
354 $USER_RATING_POPUP5[]='2';
355 $USER_RATING_POPUP5[]='3';
356 $USER_RATING_POPUP5[]='4';
357 $USER_RATING_POPUP5[]='5';
358 $USER_RATING_POPUP5[]='6 - Strong';
360 $USER_RATING_VALUES[]='-3';
361 $USER_RATING_VALUES[]='-2';
362 $USER_RATING_VALUES[]='-1';
363 $USER_RATING_VALUES[]='0.1';
364 $USER_RATING_VALUES[]='1';
365 $USER_RATING_VALUES[]='2';
366 $USER_RATING_VALUES[]='3';
369 * vote_show_user_rate_box() - Show user rating box
371 * @param int The user ID
372 * @param int The user ID of the user who is rating $user_id
374 function vote_show_user_rate_box ($user_id, $by_id=0) {
376 $res = db_query_params ('
377 SELECT rate_field,rating FROM user_ratings
383 $prev_vote = util_result_columns_to_assoc($res);
384 while (list($k,$v) = each($prev_vote)) {
386 $prev_vote[$k] = 0.1;
391 global $USER_RATING_VALUES,$USER_RATING_QUESTIONS,$USER_RATING_POPUP1,$USER_RATING_POPUP2,$USER_RATING_POPUP3,$USER_RATING_POPUP4,$USER_RATING_POPUP5;
394 <form action="/developer/rate.php" method="post">
395 <input type="hidden" name="rated_user" value="'.$user_id.'" />';
397 for ($i=1; $i<=count($USER_RATING_QUESTIONS); $i++) {
398 $popup="USER_RATING_POPUP$i";
399 if (!isset($prev_vote[$i]))
402 <td colspan="2"><strong>'. $USER_RATING_QUESTIONS[$i] .':</strong><br /> '
403 .html_build_select_box_from_arrays($USER_RATING_VALUES,$$popup,"Q_$i",$prev_vote[$i]/*'xzxz'*/,true,'Unrated').'</td></tr>';
407 <tr><td colspan="2"><input type="submit" name="submit" value="Rate User" /></td></tr>
413 * vote_show_user_rating() - Show a user rating
415 * @param int The user ID
417 function vote_show_user_rating($user_id) {
418 global $USER_RATING_QUESTIONS;
419 $res = db_query_params ('SELECT rate_field,(avg(rating)+3) AS avg_rating,count(*) as count
422 GROUP BY rate_field',
424 $rows=db_numrows($res);
425 if (!$res || $rows < 1) {
427 echo '<tr><td colspan="2"><h4>Not Yet Rated</h4></td></tr>';
430 echo '<tr><td colspan="2">
431 <h4>Current Ratings</h4>
433 Includes untrusted ratings.</p></td></tr>';
434 for ($i=0; $i<$rows; $i++) {
436 <tr><td>'.$USER_RATING_QUESTIONS[db_result($res,$i,'rate_field')].'</td>
437 <td>'.db_result($res,$i,'avg_rating').' (By '. db_result($res,$i,'count') .' Users)</td></tr>';
440 $res = db_query_params ('SELECT ranking,metric,importance_factor FROM user_metric WHERE user_id=$1',
442 if ($res && db_numrows($res) > 0) {
443 echo '<tr><td colspan="2"><strong>Trusted Overall Rating</strong></td></tr>';
444 echo '<tr><td>Sitewide Ranking:</td><td><strong>'. db_result($res,0,'ranking') .'</strong></td></tr>
445 <tr><td>Aggregate Score:</td><td><strong>'. number_format (db_result($res,0,'metric'),3) .'</strong></td></tr>
446 <tr><td>Personal Importance:</td><td><strong>'. number_format (db_result($res,0,'importance_factor'),3) .'</strong></td></tr>';
448 echo '<tr><td colspan="2"><h4>Not Yet Included In Trusted Rankings</h4></td></tr>';
454 * vote_remove_all_ratings_by() - Remove all ratings by a particular user
456 * @param int The user ID
458 function vote_remove_all_ratings_by($user_id) {
460 DELETE FROM user_ratings
468 // c-file-style: "bsd"