<?php
  /**************************************************************************\
  * phpGroupWare - Polls                                                     *
  * http://www.phpgroupware.org                                              *
  *  The file is based on phpPolls                                           *
  *  Copyright (c) 1999 Till Gerken (tig@skv.org)                            *
  * --------------------------------------------                             *
  *  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; either version 2 of the License, or (at your  *
  *  option) any later version.                                              *
  \**************************************************************************/

  /* $Id: vote.php,v 1.9.2.1.4.1 2005/12/08 11:44:59 skwashd Exp $ */

	$GLOBALS['phpgw_info']['flags'] = array();
	if ( isset($_POST['submit']) && $_POST['submit'] )
	{
		$GLOBALS['phpgw_info']['flags'] = array(
			'noheader' => True,
			'nonavbar' => True
		);
	}

	$GLOBALS['phpgw_info']['flags']['currentapp'] = 'polls';
	$GLOBALS['phpgw_info']['flags']['enable_nextmatchs_class'] = True;
	include('../header.inc.php');

	if ( isset($_POST['submit']) && $_POST['submit'] )
	{
		if (verify_uservote($_POST['poll_id']))
		{
			$_POST['poll_id'] = intval($_POST['poll_id']);
			$_POST['poll_voteNr'] = intval($_POST['poll_voteNr']);
			
			//$GLOBALS['phpgw']->db->lock(array("phpgw_polls_data","phpgw_polls_user"));
			$GLOBALS['phpgw']->db->query('UPDATE phpgw_polls_data SET option_count=option_count+1'
				. " WHERE poll_id = {$_POST['poll_id']} AND vote_id = {$_POST['poll_voteNr']}",__LINE__,__FILE__);

			$GLOBALS['phpgw']->db->query('INSERT INTO phpgw_polls_user'
				. " VALUES ({$_POST['poll_id']}, {$_POST['poll_voteNr']}, {$GLOBALS['phpgw_info']['user']['account_id']}," 
				. time() . ')',__LINE__,__FILE__);

			//$GLOBALS['phpgw']->db->unlock();
		}
		Header('Location: ' . $GLOBALS['phpgw']->link('/polls/vote.php','show_results=' . $_POST['poll_id']));
		$GLOBALS['phpgw']->common->phpgw_exit();
	}

	if ( isset($_GET['show_results']) && $_GET['show_results'] )
	{
		poll_viewResults($_GET['show_results']);
	}

	$GLOBALS['phpgw']->common->phpgw_footer();
?>
