Main Page | Directories | File List | File Members

my/votes.php

Go to the documentation of this file.
00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: votes.php 5477 2006-02-23 10:57:47Z yeupou $
00006 #
00007 #  Copyright 2005-2006 (c) Mathieu Roy <yeupou--gnu.org>
00008 #
00009 # The Savane project is free software; you can redistribute it and/or
00010 # modify it under the terms of the GNU General Public License
00011 # as published by the Free Software Foundation; either version 2
00012 # of the License, or (at your option) any later version.
00013 #
00014 # The Savane project is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 #
00019 # You should have received a copy of the GNU General Public License
00020 # along with the Savane project; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 
00024 require '../include/pre.php';
00025 require_directory("trackers");
00026 
00027 register_globals_off();
00028 
00029 if (user_isloggedin())
00030 {
00031   $remaining_votes = trackers_votes_user_remains_count(user_getid());
00032 
00033   if (sane_post("submit"))
00034     {
00035       $sql = "SELECT vote_id,tracker,item_id FROM user_votes WHERE user_id='".user_getid()."' ORDER BY howmuch DESC , item_id ASC LIMIT 100 ";
00036       $result = db_query($sql);
00037       unset($count);
00038       
00039       # Build a list of votes to update: we must proceed in two step because
00040       # we must check that the vote count does not exceed the limit (100)
00041       $new_votes_list = array();
00042       $new_votes_list_item_id = array();
00043       $new_votes_list_tracker = array();
00044 
00045       while ($row = db_fetch_array($result)) 
00046         {
00047           $new_vote = "new_vote_$row[vote_id]";
00048           $new_vote = sane_post($new_vote);
00049           $count = $count + $new_vote;
00050           $new_votes_list[$row[vote_id]] = $new_vote;
00051           $new_votes_list_item_id[$row[vote_id]] = $row[item_id];
00052           $new_votes_list_tracker[$row[vote_id]] = $row[tracker];
00053         }
00054       
00055       if ($count > 100)
00056         {
00057           fb(_("Vote count exceed limits, your changes have been discarded"), 1);
00058         }
00059       else
00060         {
00061           while (list($vote_id,$new_vote) = each($new_votes_list)) 
00062             {
00063               trackers_votes_update ($new_votes_list_item_id[$vote_id],
00064                                      0,
00065                                      $new_vote,
00066                                      $new_votes_list_tracker[$vote_id]);
00067             }     
00068         }
00069       
00070       $remaining_votes = trackers_votes_user_remains_count(user_getid());
00071     }
00072 
00073   site_user_header(array('context'=>'votes'));
00074 
00075 
00076   # Simple listing. No need of anything really fancy, there will be no more 
00077   # than hundred entries
00078 
00079   # The SQL is not exactly designed to save requests, just simple stuff.
00080 
00081   print '<p>'._("Here is the list of your votes.").' '.sprintf(ngettext("%s vote remains at your disposal.", "%s votes remain at your disposal.", $remaining_votes), $remaining_votes).'</p>';
00082 
00083   if ($remaining_votes < 100) 
00084     {
00085       print '<p>'._("To change your votes, type in new numbers (using zero removes the entry from your votes list).").'</p>';
00086       
00087       print '<form action="'.$PHP_SELF.'" method="post">';
00088       
00089       $sql = "SELECT * FROM user_votes WHERE user_id='".user_getid()."' ORDER BY howmuch DESC , item_id ASC LIMIT 100 ";
00090       $result = db_query($sql);
00091       
00092       while ($row=db_fetch_array($result))
00093         {
00094           $sql = "SELECT summary,vote,status_id,priority,group_id FROM ".$row['tracker']." WHERE bug_id='".$row['item_id']."' LIMIT 1 ";
00095           $res_item = db_query($sql);
00096           
00097           $prefix = utils_get_tracker_prefix($row['tracker']);
00098           $icon = utils_get_tracker_icon($row['tracker']);
00099           
00100           print '<div class="'.utils_get_priority_color(db_result($res_item, 0, 'priority'), db_result($res_item, 0, 'status_id')).'">'.
00101             '<input type="text" name="new_vote_'.$row['vote_id'].'" size="3" maxlength="3" value="'.$row['howmuch'].'" /> / '.($row['howmuch']+$remaining_votes).
00102             '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.$GLOBALS['sys_home'].$row['tracker'].'/?func=detailitem&amp;item_id='.$row['item_id'].'">'.
00103             '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/'.$icon.'.png" class="icon" alt="'.$row['tracker'].'" />'.
00104             ' '.stripslashes(db_result($res_item, 0, 'summary')).', '.sprintf(ngettext("%s vote", "%s votes", db_result($res_item, 0, 'vote')), db_result($res_item, 0, 'vote')).'&nbsp;<span class="xsmall">('.$prefix .' #'.$row['item_id'].', '.group_getname(db_result($res_item, 0, 'group_id')).')</span></div>';
00105           
00106           
00107         }
00108       
00109 #  ################################ Submit
00110       
00111       print '<br /><div align="center" class="noprint"><input type="submit" name="submit" class="bold" value="'._("Submit Changes").'" /></div></form>';
00112       
00113 # End
00114       print "\n\n".show_priority_colors_key();
00115       
00116     }
00117 
00118   $HTML->footer(array());
00119 
00120 }
00121 else
00122 {
00123 
00124   exit_not_logged_in();
00125 
00126 }
00127 
00128 ?>

Generated on Sun Feb 26 13:23:04 2006 for Savane PHP Frontend Developer Reference by  doxygen 1.4.4