Просмотр файла phpmytourney/admin/adminmysql.php

Размер файла: 7.8Kb
<html>
<body>
<?php
/***********************************************************
* This file was created by Jйrфme Poulin under the phpmytourney
* project.  
* You can modify and redistribute this file as long as this
* copyright notice stays in the file.
*
* If you want to do major upgrades on my script, please contact
* me and we could work together.
* 
* Jйrфme Poulin
* Student University of Sherbrooke
* [email protected] <== dont use for support !!!
* http:/phpmytourney.sourceforge.net/ <== use sourceforce forum for support
* 
*  phpMyTourney <C> 2001-2002
************************************************************/
include('../config.inc');
include($functions_file);

if(!isset($action))	echo("this page wasnt properly called");
else{
	$action();
}
function checkin_adm(){
	global $id,$tourney_id;
	checkin_sql($id);
	viewplayers();
}
function reportloss(){
	global $id,$tourney_id;
	report_loss_tourney($id);
	viewplayers();
}
function reportbye(){
	global $tourney_id;

	$position = "SELECT r1 from tourney_data_" . $tourney_id . " where id ='0'";	
	$array = get_mysql_rows($position);
	$nb_bye = count($array);

	for($i=0;$i<$nb_bye;$i++){
		$position_winner = get_position_winner($array[$i][0]);
		$new_position = get_new_position($position_winner);
		$new_round = 2;
		$sql[] = "UPDATE tourney_data_" . $tourney_id . " SET
			  r" . $new_round . " = '$new_position',
			  curround = '$new_round'
			  WHERE r1 = '$position_winner'";
	}
	$sql[] = "UPDATE tourney_data_" . $tourney_id . " SET
		 dead = '1'
		 WHERE id='0'";	
	if(execute_queries($sql)){
		echo("Reported byes Loss Successful");
	}
	else
		echo("there was an error while reporting byes loss");
	viewplayers();
}
function newtourney(){
	echo("New Tourney MySQL");
	global $hostname, $nb_per_team, $tname, $tdatetime, $ttype, $tspeed, $prize, $maps;
	
	if($ttype <= 0)
	{
		 $ttype = 1;
		 echo("<br>Tourney type specified was invalid, changet to Single Eliminations");
	}
	if($nb_per_team <= 0)
	{
		$nb_per_team = 1;
		echo("	<br>Nb per Team submitted wasnt a number or was under 1. Tourney was set
			to singles (1 per team...), if thats not what you want you will have to start over");
	}
	
	
			
	$sql = "INSERT INTO  " . $GLOBALS['dbtable_header'] . "info SET 
		hostname = '$hostname',
		tname = '$tname',
		tdatetime = '$tdatetime',
		ttype = '$ttype',
		prize = '$prize',
		maps = '$maps',
		nb_per_team = '$nb_per_team',
		status = 0";
	
	execute_query($sql);
		
	$tourney_id =  mysql_insert_id();
	print_error("bob" . $tourney_id);
	
	if($tourney_id != 0)
	{
	
	$bob_sql[] = "CREATE TABLE tourney_signup_" . $tourney_id . "(
		ordre		int(11) unsigned NOT NULL auto_increment PRIMARY KEY,
		id		int(11) unsigned NOT NULL,
		checkin		int(1) unsigned,
		tid		int(11) unsigned NOT NULL,
		teamname	text)";
		
	$bob_sql[] = "CREATE TABLE tourney_data_" . $tourney_id . "(
		id		int(11) unsigned NOT NULL,
		r1		int(3) unsigned,
		r2		int(3) unsigned,
		r3		int(3) unsigned,
		r4		int(3) unsigned,
		r5		int(3) unsigned,
		r6		int(3) unsigned,
		r7		int(3) unsigned,
		r8		int(3) unsigned,
		dead		int(1) unsigned,
		curround	int(1) unsigned,
		commment	text)";
		
	if (get_tourney_type($tourney_id) == "team" or get_tourney_type_id($tourney_id) == 3)
	{
		$bob_sql[] = "CREATE TABLE tourney_team_members_" . $tourney_id . " (
		nb	int(2) unsigned NOT NULL,
		id	int(11) unsigned NOT NULL,
		pid 	int(11) unsigned NOT NULL DEFAULT '0')";	
		
	}
		execute_queries($bob_sql);
	}
	else 
		print_error("ERROR : Tourney table not created !");

	
}
function deletetourney(){
	echo("deletetourney");
	global $tourney_id;
	$tou_type = get_tourney_type($tourney_id);
	$sql[] = "DELETE FROM  " . $GLOBALS['dbtable_header'] . "info where id='$tourney_id'";
	$sql[] = "DROP TABLE tourney_signup_" . $tourney_id;
	$sql[] = "DROP TABLE tourney_data_" . $tourney_id;
	if($tou_type == "team") 
		$sql[] = "DROP TABLE tourney_team_members_" . $tourney_id;
	execute_queries($sql);
}
function edittourney(){
	echo("Edit Tourney MySQL");
	global $tourney_id,$hostname, $tname, $tdatetime, $ttype, $tspeed, $prize, $maps;
	$sql = "UPDATE  " . $GLOBALS['dbtable_header'] . "info SET 
		hostname = '$hostname',
		tname = '$tname',
		tdatetime = '$tdatetime',
		prize = '$prize',
		maps = '$maps'
		WHERE id = '$tourney_id'";
	execute_query($sql);
}
function changestatus(){
	global $tourney_id,$status;
	$type_id = get_tourney_type_id($tourney_id);
	
	if (update_status($status)){
		echo("Status updated to " . $status);
		// add here various functions to call depending on status change...
		if($status == 4) fill_signup_table($tourney_id);
		if($status == 7) print_nb_player_form($tourney_id,"startit_order");
		if($status == 8){
			$flag = 1;
			 if($type_id == 3) $flag = generate_team_blind_draw();
			 if($flag) 	
			 	print_nb_player_form($tourney_id,"startit_shuffle");
			 else
			 	print_error("sorry an error occured while generating teams");
		}
		if($status == 9) end_tourney($tourney_id);
	}
}
function print_nb_player_form($tourney_id,$action){
	
	$values[0][0] = 4;
	$values[1][0] = 8;
	$values[2][0] = 16;
	$values[3][0] = 32;
	$values[4][0] = 64;
	$values[5][0] = 128;
	$values[6][0] = 256;
	$values[0][1] = 4;
	$values[1][1] = 8;
	$values[2][1] = 16;
	$values[3][1] = 32;
	$values[4][1] = 64;
	$values[5][1] = 128;
	$values[6][1] = 256;
	
	
	$nb_checked = get_nb_checked($tourney_id);
	$nb_player = get_nb_signup($tourney_id);
	echo("<P>Number of Sign ups :<b> " . $nb_player . "</b></p>");
	echo("<p>Number of Checked in :<b>" . $nb_checked . "</b></p>");
	echo("<p>You have to pick here the number of player you want to play in the tourney.
	      In most cases you should pick a number higher then the number of Checked in player.
	      The script will automaticly add the proper number of byes..</p>
	      <p>Choose this number wisely , because the script entirely trust your judgement.
		<br>(i.e. there's 15 check in and you say 64 , there will be 49 byes...)</p>");	
	print_top_form("NB player tourney","adminmysql.php");
	print_select_2dim_array("Pick Number","nb",$values);
	echo("	<input type=\"HIDDEN\" name=\"action\" value=\"" . $action ."\">
		<input type=\"HIDDEN\" name=\"tourney_id\" value=\"" . $tourney_id . "\">");
	print_submit("Start Tourney");
}
function startit_shuffle(){
	global $nb,$tourney_id;
	start_tourney_shuffle($nb);
	echo("Tourney Started and players have been placed randomly...");
}
function startit_order(){
	global $nb,$tourney_id;
	start_tourney_order($nb);
	echo("Tourney Started and players have been placed according to their rank...");
}
function replacebye_sql(){
	global $tourney_id, $pos, $id;
	$sql = "UPDATE tourney_data_" . $tourney_id . " SET id='$id' WHERE r1='$pos'";
	if(execute_query($sql))
		echo("Bye replaced by player successfully");
	else
		echo("An error occured while replacing bye...");
	viewplayers();
}
function add_player(){
	global $tourney_id,$id,$teamname;
	$tou_type = get_tourney_type($tourney_id);
	$flag = 1;
	if($tou_type == "team") $flag = insert_in_team_members($id);
	if(signup_sql($id,$teamname) && $flag)
		echo($tou_type . " was added to tourney");
	else
		print_error("There was an error adding " . $tou_type);
	viewplayers();
}
function remove_from_tourney(){
	global $tourney_id,$id;
	$tou_type = get_tourney_type($tourney_id);
	$flag = 1;
	
	$sql = "Delete from tourney_signup_" . $tourney_id . " where id='$id'";
	if(!execute_query($sql))
		print_error("$tou_type could not be removed.");
	else{
		if($tou_type == "team"){
			$sql = "delete from tourney_team_members_" . $tourney_id . " where id='$id'";	
			$flag = execute_query($sql);
		}
		if($flag){
			echo($tou_type . " was deleted succesfully");
			viewplayers();
		}
	}
}
?>
</body>
</html>