Location: PHPKode > projects > PhpChrystal - An Open Intranet System > 0.071Alpha1/priv_generateTourneyResults.php
<?php
  session_start();
?>
<html>
<head>
<title>phpchrystal.dev-tools: > Ergebnisse automatisch eintragen</title>
</head>

<a href="priv_generateTourneyEntries.php">Teams eintragen</a> | <a href="priv_generateTourneyResults.php">Ergebnisse erstellen</a>
<br />
<form method = post action = 'priv_generateTourneyResults.php'>
Bitte Turnier auswählen:
<?php
#if (!isset($_SESSION['active_login']))
#  exit;

  include_once("./classes/CConfig.php");
  include_once("./classes/CFunction.php");
  include_once("./classes/CTourneyControl.php");
  $ctourn = new CTourneyControl;
  $cfunc = new CFunc;

  $dbh = mysql_connect(mysql_server,mysql_root,mysql_pw) || $cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__);
  $dbs = mysql_select_db(mysql_database) || $cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__);
  (!$dbh) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);

  $sth = mysql_query("SELECT ".mysql_prefix."t_settings.iTourneyID, ".mysql_prefix."t_settings.szSetting, ".mysql_prefix."t_settings.szValue, t_tourneys.enumStatus
  						FROM ".mysql_prefix."t_settings, t_tourneys
  						WHERE ".mysql_prefix."t_settings.iTourneyID = t_tourneys.iTourneyID AND t_tourneys.enumStatus = 'running'
  								AND ".mysql_prefix."t_settings.szSetting = 'game' OR ".mysql_prefix."t_settings.szSetting = 'iMaxTeams' OR ".mysql_prefix."t_settings.szSetting = 'iConstellation'
  	     				ORDER BY iTourneyID DESC");
  (!$sth) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);

  while ($ret = mysql_fetch_row($sth))
  {
    $arFound[$ret[0]][$ret[1]] = $ret[2];
  }

  while(list($key,$val) = each($arFound))
  {
    $sth = mysql_query("SELECT szGame FROM ".mysql_prefix."c_games WHERE iGameID = '".$arFound[$key][game]."'");
    (!$sth) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);
    $ret = mysql_fetch_row($sth);

    $sth = mysql_query("SELECT bIsFreeDummy FROM ".mysql_prefix."t_teams WHERE iTourneyID = '".$key."' AND bIsFreeDummy = '1'");
    (!$sth) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);
    $iFreilose = mysql_num_rows($sth);

  	($_POST['in_iTourneyID'] == $key) ? ($szSelected = "selected") : ($szSelected = "");
  	$szSelect .= "<option value = '".$key."' ".$szSelected.">".$ret[0]." ".$arFound[$key][iConstellation]."on".$arFound[$key][iConstellation]." - ".$arFound[$key][iMaxTeams]." Teams / ".$iFreilose." Freilose</option>";
  }

  print "<select name = in_iTourneyID>".$szSelect."</select>";
?>
 Bitte Bracket / Vorrunde auswählen: <select name = "in_iBracket">
	  <option value = "" <?php if (!$_POST['in_iBracket']) print "selected"; ?>>Vorrunde</option>
	  <option value = "1" <?php if ($_POST['in_iBracket'] == 1) print "selected"; ?>>Winner-Bracket</option>
	  <option value = "2" <?php if ($_POST['in_iBracket'] == 2) print "selected"; ?>>Loser-Bracket</option>
	  </select>
	  <input type = "submit" value = "Eintragen">
	  </form>
	  <hr>
<?php
  if ($_POST['in_iTourneyID'])
  {
    $m_iTourneyID = $_POST['in_iTourneyID'];

    if ($_POST['in_iBracket'])
    {
      $mysqlwhere  = "AND iBracket=\"".$_POST['in_iBracket']."\"";
      $mysqlwhere_bracket = $mysqlwhere;
    }

    if ($tset[iRoundOfWinnerBracket])
      $mysqlwhere .= " AND (iRound=\"".$tset[iRoundOfWinnerBracket]."\" AND iBracket=\"1\")";

    if ($tset[iRoundOfLoserBracket])
      $mysqlwhere .= " OR (iRound=\"".$tset[iRoundOfLoserBracket]."\" AND iBracket=\"2\")";

    $sql = "SELECT iTeam1ID, iTeam2ID, iRound, iBracket, iStatus, iPlanID FROM ".mysql_prefix."t_plan WHERE iTourneyID=\"".$m_iTourneyID."\" $mysqlwhere";
    $sth = mysql_query($sql);
    (!$sth) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);
    $cnt = 0;

    while ($ret = mysql_fetch_row($sth))
    {
  	  $sth2 = mysql_query("SELECT bIsFreeDummy FROM ".mysql_prefix."t_teams WHERE (iTeamID = '".$ret[0]."' OR iTeamID = '".$ret[1]."') AND bIsFreeDummy = '1'");
  	  (!$sth2) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);

  	  $iTemp = mysql_num_rows($sth2);

  	  if (!$iTemp)
  	  {
	    // XML::COMMENT (Punkte zuweisen)
	    $sth2 = mysql_query("UPDATE ".mysql_prefix."t_teams SET iWins = iWins + 1, iPlayedMatches = iPlayedMatches + 1 WHERE iTeamID=\"".$ret[0]."\"  AND iTourneyID=\"".$m_iTourneyID."\" ".$mysqlwhere_bracket);
 	    (!$sth2) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);

	    // XML::COMMENT (Punkte zuweisen)
	    $sth2 = mysql_query("UPDATE ".mysql_prefix."t_teams SET iLosts = iLosts + 1, iPlayedMatches = iPlayedMatches + 1 WHERE iTeamID=\"".$ret[1]."\"  AND iTourneyID=\"".$m_iTourneyID."\" ".$mysqlwhere_bracket);
 	    (!$sth2) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);

        $sth2 = mysql_query("UPDATE ".mysql_prefix."t_plan
        						SET iWinnerID = '".$ret[0]."', iLoserID = '".$ret[1]."', iPointsTeam1 = '3', iPointsTeam2 = '0'
        						WHERE iPlanID = '".$ret[5]."'");
        (!$sth2) ? ($cfunc->faultMySQL(mysql_error(),__FILE__,__LINE__)) : ($dummy);

        print "Runde $ret[2] $ret[0] vs. $ret[1] eingetragen<br />";

        $cnt++;
      }
    }
    echo ("$cnt Ergebnisse erstellt");
  }

  mysql_close();
?>
Return current item: PhpChrystal - An Open Intranet System