<?php
  /**************************************************************************\
  * phpGroupWare - Polls                                                     *
  * http://www.phpgroupware.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: admin_deletequestion.php,v 1.4.4.1 2004/01/29 05:39:04 skwashd Exp $ */

	$phpgw_info = array();
	$GLOBALS['phpgw_info']['flags'] = array(
		'currentapp'   => 'polls',
		'enable_nextmatchs_class' => True,
		'admin_header' => True
	);
	if ($_GET['confirm'])
	{
		$GLOBALS['phpgw_info']['flags']['noheader'] = True;
		$GLOBALS['phpgw_info']['flags']['nonavbar'] = True;
		$GLOBALS['phpgw_info']['flags']['admin_header'] = False;
	}
	include('../header.inc.php');

	$poll_id = intval($_GET['poll_id']);
	if ($_GET['confirm'])
	{
		$GLOBALS['phpgw']->db->query("DELETE FROM phpgw_polls_desc WHERE poll_id = $poll_id", __LINE__, __FILE__);
		$GLOBALS['phpgw']->db->query("DELETE FROM phpgw_polls_data WHERE poll_id = $poll_id", __LINE__, __FILE__);
		$GLOBALS['phpgw']->db->query("DELETE FROM phpgw_polls_user WHERE poll_id = $poll_id", __LINE__, __FILE__);
		$GLOBALS['phpgw']->db->query("SELECT MAX(poll_id) as pollmax FROM phpgw_polls_desc", __LINE__, __FILE__);
		$max = $GLOBALS['phpgw']->db->f('pollmax');
		$GLOBALS['phpgw']->db->query("UPDATE phpgw_polls_settings SET setting_value = $max "
			. " WHERE setting_name='currentpoll'", __LINE__, __FILE__);
		Header('Location: ' . $GLOBALS['phpgw']->link('/polls/admin.php','show=questions'));
	}
	else
	{
		echo '<p><br><table border="0" width="40%" align="center"><tr><td align="center" colspan="center">';
		echo lang('Are you sure want to delete this question ?') . '</td></tr>';
		echo '<tr><td align="left"><a href="' . $GLOBALS['phpgw']->link('/polls/admin.php','show=questions') . '">' . lang('No') . '</td>';
		echo '    <td align="right"><a href="' . $GLOBALS['phpgw']->link('/polls/admin_deletequestion.php','poll_id='
			. $poll_id . '&confirm=True') . '">' . lang('Yes') . '</td></tr>';
		echo '</table>';
	}
	$GLOBALS['phpgw']->common->phpgw_footer();
?>
