<?php
///////////////////////////////////////////////////////////////////////////////////////
// PHPizabi 0.844b C1 [ALICIA]                               http://www.phpizabi.net //
///////////////////////////////////////////////////////////////////////////////////////
// Please read the license.txt file before using / modifying this software           //
// Original author:         Claude Desjardins, R - feedback@realitymedias.com        //
// Last modification date:  August 26th 2006                                         //
// Version:                 PHPizabi 0.844b C1                                       //
//                                                                                   //
// (C) 2005, 2006 Real!ty Medias / PHPizabi - All rights reserved                    //
///////////////////////////////////////////////////////////////////////////////////////

	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");
	
	// TEMPLATE HANDLING ////////////////////////////////////////////////////////////////// FINAL //
	/*
		Initialize the template engine and
		load the template file. Get objects,
		convert self user.
	*/
	$tpl = new template;
	$tpl -> Load("request");

	$row = myF(myQ("SELECT * FROM `[x]fight` WHERE `id`='{$_GET["id"]}' AND `opponent`='".me("id")."' AND `start`='0'"));
	
	if ($row["id"] > 0) {
		
		if (isset($_POST["Accept"])) {
			myQ("
				UPDATE `[x]fight`
				SET 
					`start` = '".time()."',
					`expire` = '".(time() + $row["duration"])."',
					`votes` = '".pk(array(me("id"), $row["user"]))."'
				WHERE `id`='{$_GET["id"]}'
				LIMIT 1
			");
			reload(0, "?L=fight.details&id={$row["id"]}");
		}
		
		else if (isset($_POST["Reject"])) {
			myQ("DELETE FROM `[x]fight` WHERE `id`='{$_GET["id"]}' LIMIT 1");
			reload(0, "?L=fight.index");
		}
		
		$tpl -> Zone("form", "enabled");
		
		$tpl -> AssignArray(array(
			"fight.user" => 			user($row["user"], "username"),
			"fight.user_picture" => 	user($row["user"], "mainpicture"),
			"fight.topic" =>			substr($row["topic"], 0, 80),
			"fight.body" =>				convertBodyCodes($row["body"]),
		));
		
	}
	
	else reload(0, "?L=fight.index");
	
	$tpl -> CleanZones();
	$tpl -> Flush();
	
?>