Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / vote.php
index e778439ebcd39d6b7714d3cb554bc0eb2286c816..c66a3601ad16de4cb22f76a64e2ac944d1194c5c 100644 (file)
--- a/vote.php
+++ b/vote.php
@@ -1,65 +1,78 @@
 <?php
 /*=====================================================================*\
-|| ################################################################### ||
-|| # BugStrike [#]version[#]
-|| # --------------------------------------------------------------- # ||
-|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
-|| # This file may not be reproduced in any way without permission.  # ||
-|| # --------------------------------------------------------------- # ||
-|| # User License Agreement at http://www.iris-studios.com/license/  # ||
-|| ################################################################### ||
+|| ###################################################################
+|| # Bugdar
+|| # Copyright (c)2004-2009 Blue Static
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version 2 of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
 \*=====================================================================*/
 
-define('SVN', '$Id$');
 
 $focus['showreport'] = 'focus';
 
 require_once('./global.php');
 
-if (!can_perform('canvote'))
-{
-       $message->error_permission();
-}
-
 // ###################################################################
 
 if (empty($_REQUEST['do']))
 {
-       $message->error(lang::p('error_invalid_id'));
+       $message->error(L_INVALID_ID);
 }
 
 // ###################################################################
 
 if ($_REQUEST['do'] == 'vote')
 {
-       $bug = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . intval($bugsys->in['bugid']) . ((!can_perform('canviewhidden')) ? " AND !bug.hidden" : ''));
-       $vote =  $db->query_first("SELECT *, FIND_IN_SET(" . $bugsys->userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
+       $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = " . $input->inputClean('bugid', TYPE_UINT));
+       $vote =  $db->queryFirst("SELECT *, FIND_IN_SET(" . bugdar::$userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
+       
+       if (!check_bug_permissions($bug))
+       {
+               $message->errorPermission();
+       }
+       
+       if (!can_perform('canvote', $bug['product']))
+       {
+               $message->errorPermission();
+       }
        
        if (!$bug)
        {
-               $message->error(lang::p('error_invalid_id'));
+               $message->error(L_INVALID_ID);
        }
        
        if ($vote['uservote'])
        {
-               $message->error(lang::p('error_already_voted'));
+               $message->error(T('You have already voted on this bug.'));
        }
        
        // handle userids
        $userids = $vote['userids'];
-       if ($bugsys->userinfo['userid'])
+       if (bugdar::$userinfo['userid'])
        {
                if (trim($vote['userids']))
                {
-                       $userids .= ',' . $bugsys->userinfo['userid'];
+                       $userids .= ',' . bugdar::$userinfo['userid'];
                }
                else
                {
-                       $userids = $bugsys->userinfo['userid'];
+                       $userids = bugdar::$userinfo['userid'];
                }
        }
        
-       $uservote = intval($bugsys->in['vote']);
+       $uservote = $input->inputClean('vote', TYPE_INT);
        
        $votefor = $vote['votefor'];
        $voteagainst = $vote['voteagainst'];
@@ -68,20 +81,18 @@ if ($_REQUEST['do'] == 'vote')
        {
                $votefor++;
        }
-       else
+       else if ($uservote < 0)
        {
                $voteagainst++;
        }
+       else
+       {
+               $message->error(T('You need to specify whether you want to vote for or against this bug.'));
+       }
        
        $db->query("UPDATE " . TABLE_PREFIX . "vote SET userids = '$userids', votefor = $votefor, voteagainst = $voteagainst WHERE bugid = $bug[bugid]");
 
-       $message->redirect(lang::p('vote_added'), "showreport.php?bugid=$bug[bugid]");
+       $message->redirect(T('Your vote has been added.'), "showreport.php?bugid=$bug[bugid]");
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file