5 * SourceForge: Breaking Down the Barriers to Open Source Development
6 * Copyright 1999-2001 (c) VA Linux Systems
7 * http://sourceforge.net
13 * vote_number_to_stars() - Turns vote results into *'s
15 * @param int Raw value
17 function vote_number_to_stars($raw) {
19 // echo "\n\n<!-- $raw -->\n\n";
25 $count=intval($raw/2);
26 for ($i=0; $i<$count; $i++) {
27 $return .= html_image("ic/check.png","15","16",array());
30 $return .= html_image("ic/halfcheck.png","15","16",array());
36 * vote_show_thumbs() - Show vote stars
38 * @param int The survey ID
39 * @param string The rating type
41 function vote_show_thumbs($id,$flag) {
49 $rating=vote_get_rating ($id,$flag);
51 return "<strong>(unrated)</strong>";
53 return vote_number_to_stars($rating).'('.$rating.')';
58 * vote_get_rating() - Get a vote rating
60 * @param int The survey ID
61 * @param string The rating type
63 function vote_get_rating ($id,$flag) {
64 $sql="SELECT response FROM survey_rating_aggregate WHERE type='$flag' AND id='$id'";
65 $result=db_query($sql);
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) {
133 Select this survey from the database
136 $sql="SELECT * FROM surveys WHERE survey_id='$survey_id' and group_id = '$group_id'";
138 $result=db_query($sql);
140 if (db_numrows($result) > 0) {
142 <h3>'.db_result($result, 0, 'survey_title').'</h3>
143 <form action="/survey/survey_resp.php" method="post">
144 <input type="hidden" name="group_id" value="'.$group_id.'" />
145 <input type="hidden" name="survey_id" value="'.$survey_id.'" />';
148 Select the questions for this survey
151 $questions=db_result($result, 0, 'survey_questions');
152 $quest_array=explode(',', $questions);
153 $count=count($quest_array);
158 for ($i=0; $i<$count; $i++) {
160 Build the questions on the HTML form
163 $sql="SELECT * FROM survey_questions WHERE question_id='".$quest_array[$i]."'";
164 $result=db_query($sql);
165 $question_type=db_result($result, 0, 'question_type');
167 if ($question_type == '4') {
169 Don't show question number if it's just a comment
173 <tr><td valign="top"> </td><td>';
177 <tr><td valign="top"><strong>';
179 If it's a 1-5 question box and first in series, move Quest
182 if (($question_type != $last_question_type) && (($question_type == '1') || ($question_type == '3'))) {
186 echo $q_num.' <br /></td><td>';
190 if ($question_type == "1") {
192 This is a radio-button question. Values 1-5.
194 // Show the 1-5 markers only if this is the first in a series
196 if ($question_type != $last_question_type) {
198 <strong>1</strong>'.$Language->getText('survey','low').' <strong>5</strong>' .$Language->getText('survey','high');
203 for ($j=1; $j<=5; $j++) {
205 <input type="radio" name="_'.$quest_array[$i].'" value="'.$j.'" />';
208 echo ' '.stripslashes(db_result($result, 0, 'question'));
210 } else if ($question_type == '2') {
212 This is a text-area question.
215 echo stripslashes(db_result($result, 0, 'question')).'<br />';
217 <textarea name="_'.$quest_array[$i].'" rows="5" cols="60" wrap="soft"></textarea>';
219 } else if ($question_type == '3') {
221 This is a Yes/No question.
224 //Show the Yes/No only if this is the first in a series
226 if ($question_type != $last_question_type) {
227 echo '<strong>Yes / No</strong><br />';
231 <input type="radio" name="_'.$quest_array[$i].'" value="1" />';
233 <input type="radio" name="_'.$quest_array[$i].'" value="5" />';
235 echo ' '.stripslashes(db_result($result, 0, 'question'));
237 } else if ($question_type == '4') {
239 This is a comment only.
242 echo ' <br /><strong>'.util_make_links(stripslashes(db_result($result, 0, 'question'))).'</strong>';
244 <input type="hidden" name="_'.$quest_array[$i].'" value="-666" />';
246 } else if ($question_type == '5') {
248 This is a text-field question.
251 echo stripslashes(db_result($result, 0, 'question')).'<br />';
253 <input type="text" name="_'.$quest_array[$i].'" size="20" maxlength="70" />';
257 // no answers, just show question
258 echo stripslashes(db_result($result, 0, 'question')).'<br />';
263 $last_question_type=$question_type;
267 <tr><td style="text-align:center" colspan="2">
269 <input type="submit" name="submit" value="<?php echo $Language->getText('general','submit') ?>" />
271 <a href="<?php echo $GLOBALS['sys_urlprefix']; ?>/survey/privacy.php"><?php echo $Language->getText('survey','survey_privacy') ?></a>
278 echo "<strong>".$Language->getText('survey','survey_not_found')."</strong>";
284 * Show a single question for the new user rating system
286 * @param string The question to show
287 * @param string The array element
289 function vote_show_a_question ($question,$element_name) {
291 <tr><td colspan="2" nowrap="nowrap">
292 <input type="radio" name="Q_'. $element_name .'" value="-3">
293 <input type="radio" name="Q_'. $element_name .'" value="-2" />
294 <input type="radio" name="Q_'. $element_name .'" value="-1" />
295 <input type="radio" name="Q_'. $element_name .'" value="0.1" />
296 <input type="radio" name="Q_'. $element_name .'" value="1" />
297 <input type="radio" name="Q_'. $element_name .'" value="2" />
298 <input type="radio" name="Q_'. $element_name .'" value="3" />
301 <tr><td colspan="2">'.$question.'
302 <br /> </td></tr>';
308 The ratings system is actually flexible enough
309 to let you do N number of questions, but we are just going with 5
310 that apply to everyone
314 $USER_RATING_QUESTIONS=array();
315 //sorry - array starts at 1 so we can test for the questions on the receiving page
316 $USER_RATING_QUESTIONS[1]='Teamwork / Attitude';
317 $USER_RATING_QUESTIONS[2]='Code';
318 $USER_RATING_QUESTIONS[3]='Design / Architecture';
319 $USER_RATING_QUESTIONS[4]='Follow-Through / Reliability';
320 $USER_RATING_QUESTIONS[5]='Leadership / Management';
322 $USER_RATING_POPUP1[]='0 - Soloist';
323 $USER_RATING_POPUP1[]='1';
324 $USER_RATING_POPUP1[]='2';
325 $USER_RATING_POPUP1[]='3';
326 $USER_RATING_POPUP1[]='4';
327 $USER_RATING_POPUP1[]='5';
328 $USER_RATING_POPUP1[]='6 - Team Player';
330 $USER_RATING_POPUP2[]='0 - Beginner';
331 $USER_RATING_POPUP2[]='1';
332 $USER_RATING_POPUP2[]='2';
333 $USER_RATING_POPUP2[]='3';
334 $USER_RATING_POPUP2[]='4';
335 $USER_RATING_POPUP2[]='5';
336 $USER_RATING_POPUP2[]='6 - Master';
338 $USER_RATING_POPUP3[]='0 - Basic';
339 $USER_RATING_POPUP3[]='1';
340 $USER_RATING_POPUP3[]='2';
341 $USER_RATING_POPUP3[]='3';
342 $USER_RATING_POPUP3[]='4';
343 $USER_RATING_POPUP3[]='5';
344 $USER_RATING_POPUP3[]='6 - Elaborate';
346 $USER_RATING_POPUP4[]='0 - Unreliable';
347 $USER_RATING_POPUP4[]='1';
348 $USER_RATING_POPUP4[]='2';
349 $USER_RATING_POPUP4[]='3';
350 $USER_RATING_POPUP4[]='4';
351 $USER_RATING_POPUP4[]='5';
352 $USER_RATING_POPUP4[]='6 - Dependable';
354 $USER_RATING_POPUP5[]='0 - Weak';
355 $USER_RATING_POPUP5[]='1';
356 $USER_RATING_POPUP5[]='2';
357 $USER_RATING_POPUP5[]='3';
358 $USER_RATING_POPUP5[]='4';
359 $USER_RATING_POPUP5[]='5';
360 $USER_RATING_POPUP5[]='6 - Strong';
362 $USER_RATING_VALUES[]='-3';
363 $USER_RATING_VALUES[]='-2';
364 $USER_RATING_VALUES[]='-1';
365 $USER_RATING_VALUES[]='0.1';
366 $USER_RATING_VALUES[]='1';
367 $USER_RATING_VALUES[]='2';
368 $USER_RATING_VALUES[]='3';
371 * vote_show_user_rate_box() - Show user rating box
373 * @param int The user ID
374 * @param int The user ID of the user who is rating $user_id
376 function vote_show_user_rate_box ($user_id, $by_id=0) {
379 SELECT rate_field,rating FROM user_ratings
380 WHERE rated_by='$by_id'
381 AND user_id='$user_id'
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";
400 <td colspan="2"><strong>'. $USER_RATING_QUESTIONS[$i] .':</strong><br /> '
401 .html_build_select_box_from_arrays($USER_RATING_VALUES,$$popup,"Q_$i",$prev_vote[$i]/*'xzxz'*/,true,'Unrated').'</td></tr>';
405 <tr><td colspan="2"><input type="submit" name="submit" value="Rate User" /></td></tr>
411 * vote_show_user_rating() - Show a user rating
413 * @param int The user ID
415 function vote_show_user_rating($user_id) {
416 global $USER_RATING_QUESTIONS;
417 $sql="SELECT rate_field,(avg(rating)+3) AS avg_rating,count(*) as count ".
418 "FROM user_ratings ".
419 "WHERE user_id='$user_id' ".
420 "GROUP BY rate_field";
422 $rows=db_numrows($res);
423 if (!$res || $rows < 1) {
425 echo '<tr><td colspan="2"><h4>Not Yet Rated</h4></td></tr>';
428 echo '<tr><td colspan="2">
429 <h4>Current Ratings</h4>
431 Includes untrusted ratings.</p></td></tr>';
432 for ($i=0; $i<$rows; $i++) {
434 <tr><td>'.$USER_RATING_QUESTIONS[db_result($res,$i,'rate_field')].'</td>
435 <td>'.db_result($res,$i,'avg_rating').' (By '. db_result($res,$i,'count') .' Users)</td></tr>';
438 $res=db_query("SELECT ranking,metric,importance_factor FROM user_metric WHERE user_id='$user_id'");
439 if ($res && db_numrows($res) > 0) {
440 echo '<tr><td colspan="2"><strong>Trusted Overall Rating</strong></td></tr>';
441 echo '<tr><td>Sitewide Ranking:</td><td><strong>'. db_result($res,0,'ranking') .'</strong></td></tr>
442 <tr><td>Aggregate Score:</td><td><strong>'. number_format (db_result($res,0,'metric'),3) .'</strong></td></tr>
443 <tr><td>Personal Importance:</td><td><strong>'. number_format (db_result($res,0,'importance_factor'),3) .'</strong></td></tr>';
445 echo '<tr><td colspan="2"><h4>Not Yet Included In Trusted Rankings</h4></td></tr>';
451 * vote_remove_all_ratings_by() - Remove all ratings by a particular user
453 * @param int The user ID
455 function vote_remove_all_ratings_by($user_id) {
457 DELETE FROM user_ratings
458 WHERE rated_by='$user_id'