rendered paste body<?php
require('inc/Predefined.php');
require('inc/Mysql.php');
require('inc/SaveInputFile.php');
require('parts/m_start.php');
require('parts/m_menu.html');
$row = $_POST;
// Save event
if ($_POST['submit'] == 'Add match')
{
$birth_date = $_POST['year'] .'-'. $_POST['month'] .'-'. $_POST['day'];
if ($_POST['gameID'] && $_POST['opponentID'] && $_POST['eventID']
&& preg_match('/20\d\d-\d\d-\d\d/', $birth_date) && checkdate(intval($_POST['month']), intval($_POST['day']), intval($_POST['year']))
&& $ress->canCreateMatch($_POST['gameID'], $_POST['opponentID'], $_POST['eventID']) )
{
$sql = "INSERT IGNORE INTO s_matches SET
gameID = ". intval($_POST['gameID']) .",
date = ". $sdb->quote_smart("{$_POST['year']}-{$_POST['month']}-{$_POST['day']}") .",
opponentID = ". intval($_POST['opponentID']) .",
eventID = ". intval($_POST['eventID']) .",
map = ". $sdb->quote_smart($_POST['map']) .",
details = ". $sdb->quote_smart($_POST['details']) .",
played = ". intval($_POST['played']) .",
score1 = ". intval($_POST['score1']) .",
score2 = ". intval($_POST['score2']);
$sdb->get_query($sql);
if (!mysql_affected_rows())
{
?><div id="error">Such match already exists.</div><?php
}
else
{
?><div id="info">Match saved.</div><?php
$row = array();
}
// jesli jest obrazek - zapisz go
if ($_FILES['image']['error'] != 4)
{
$status = $sf->saveImg('image', UPLOAD_DIR .'matches_'. mysql_insert_id(), MATCHES_IMG_WIDTH, MATCHES_IMG_HEIGHT, 3);
// zapis udany
if ($status[0])
{
$sql = "UPDATE s_matches SET
img_type='{$status[1]}'
WHERE matchID=". mysql_insert_id() ."
LIMIT 1";
$sdb->get_query($sql);
}
else
{
?><div id="error"><?php echo $status[1] ?></div><?php
}
}
}
elseif ($ress->canCreateMatch($_POST['gameID'], $_POST['opponentID'], $_POST['eventID']))
{
?><div id="error">Please fill all required fields (game, date, opponent, event), and make sure date is correct.</div><?php
}
elseif (!$ress->canCreateMatch($_POST['gameID'], $_POST['opponentID'], $_POST['eventID']))
{
?>
<div id="error">Please fill all required fields (game, date, opponent, event), and make sure date is correct.<br>
Opponent and Event must match the game.</div>
<?php
}
}
// Delete opp
if ($_GET['matchID'])
{
// wykasowanie obrazka, jesli istnieje
$file = UPLOAD_DIR .'matches_'. intval($_GET['matchID']) .'.'. @mysql_result(
$sdb->get_query("SELECT img_type FROM s_matches
WHERE matchID=". intval($_GET['matchID'])),0);
if (file_exists($file))
{
@unlink($file);
}
$sql = "DELETE FROM s_matches
WHERE matchID=". intval($_GET['matchID']) ."
LIMIT 1";
$sdb->get_query($sql);
?><div id="info">Match was removed.</div><?php
}
?>
<div id="inner_header">Matches</div>
<div class="form_body">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<div class="form_cell">
<label for="gameID">Game</label>
<select class="select" name="gameID" id="gameID">
<?php
$sql = "SELECT gameID, name
FROM s_games
ORDER BY name";
$res = $sdb->get_query($sql);
while ($rowIn = mysql_fetch_assoc($res))
{
?><option value="<?php echo $rowIn['gameID'] ?>"<?php if ($rowIn['gameID'] == $row['gameID']) echo ' selected' ?>><?php echo $rowIn['name'] ?></option><?php
}
?>
</select>
</div>
<div class="form_cell">
<label for="day">Match day</label>
<select class="select" name="day" id="day">
<option value="00">--</option>
<?php
for ($i = 1; $i<32; $i++)
{
?><option value="<?php echo sprintf("%'02d",$i) ?>"<?php if ($row['day'] == sprintf("%'02d",$i)) echo ' selected' ?>><?php echo $i ?></option><?php
}
?>
</select>
</div>
<div class="form_cell">
<label for="month">Match month</label>
<select class="select" name="month" id="month">
<option value="00">--</option>
<?php
$month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'Novemeber', 'December');
for ($i = 1; $i<13; $i++)
{
?><option value="<?php echo sprintf("%'02d",$i) ?>"<?php if ($row['month'] == sprintf("%'02d",$i)) echo ' selected' ?>><?php echo $month[$i-1] ?></option><?php
}
?>
</select>
</div>
<div class="form_cell">
<label for="year">Match year</label>
<select class="select" name="year" id="year">
<option value="0000">--</option>
<?php
for ($i = 2005; $i<=2015; $i++)
{
?><option value="<?php echo $i ?>"<?php if ($row['year'] == $i) echo ' selected' ?>><?php echo $i ?></option><?php
}
?>
</select>
</div>
<div class="form_cell">
<label for="opponentID">Opponent</label>
<select class="select" name="opponentID" id="opponentID">
<?php
$sql = "SELECT sop.opponentID, sop.long_name, sga.short_name FROM
s_opponents sop INNER JOIN s_games sga USING(gameID)
ORDER BY sga.short_name, sop.long_name";
$res = $sdb->get_query($sql);
while ($rowIn = mysql_fetch_assoc($res))
{
?><option value="<?php echo $rowIn['opponentID'] ?>"<?php if ($rowIn['opponentID'] == $row['opponentID']) echo ' selected' ?>><?php echo htmlspecialchars($rowIn['short_name']) ?> => <?php echo $rowIn['long_name'] ?></option><?php
}
?>
</select>
</div>
<div class="form_cell">
<label for="eventID">Event</label>
<select class="select" name="eventID" id="eventID">
<?php
$sql = "SELECT sev.eventID, sev.name, sga.short_name FROM
s_events sev INNER JOIN s_games sga USING(gameID)
ORDER BY sga.short_name, sev.name";
$res = $sdb->get_query($sql);
while ($rowIn = mysql_fetch_assoc($res))
{
?><option value="<?php echo $rowIn['eventID'] ?>"<?php if ($rowIn['eventID'] == $row['eventID']) echo ' selected' ?>><?php echo htmlspecialchars($rowIn['short_name']) ?> => <?php echo $rowIn['name'] ?></option><?php
}
?>
</select>
</div>
<div class="form_cell">
<label for="score1">Syko points</label><input class="text" type="text" name="score1" value="<?php echo htmlspecialchars($row['score1']) ?>" id="score1">
</div>
<div class="form_cell">
<label for="score2">Opponent points</label><input class="text" type="text" name="score2" value="<?php echo htmlspecialchars($row['score2']) ?>" id="score2">
</div>
<div class="form_cell">
<label for="details">Details</label><textarea class="textarea2" name="details" id="details"><?php echo htmlspecialchars($row['details']) ?></textarea>
</div>
<div class="form_cell">
<label for="map">Map</label><input class="text" type="text" name="map" value="<?php echo htmlspecialchars($row['map']) ?>" id="map">
</div>
<div class="form_cell">
<label for="played">Played</label><input type="checkbox" name="played" id="played" value="1"<?php if ($row['played']) echo ' checked' ?>>
</div>
<div class="form_cell">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_UPLOAD_FILE_SIZE ?>">
<label for="image">Image</label><input type="file" name="image" id="image" value="">
</div>
<div class="sub">
<input type="submit" class="black_box" name="submit" value="Add match">
</div>
</form>
</div>
<?php
// ========================================================================
// === list of matches
$sql = "SELECT DISTINCT sev.name, sga.short_name, sma.matchID, sma.date, sma.played
FROM s_events sev
INNER JOIN s_matches sma USING(eventID)
INNER JOIN s_games sga USING(gameID)
INNER JOIN s_opponents sop ON (sop.opponentID = sma.opponentID)
ORDER BY sga.short_name, sma.date";
$res = $sdb->get_query($sql);
if (mysql_num_rows($res))
{
?>
<div id="inner_header">Matches List</div>
<div class="tab_cell">
<table class="stats" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td>Event</td>
<td>Category</td>
<td>Date</td>
<td>Played</td>
<td>Modify</td>
<td>Delete</td>
</tr>
</thead>
<tbody>
<?php
// process every found row
while ($row = mysql_fetch_assoc($res))
{
?>
<tr class="tr1" onmouseover="this.className='tr2'" onmouseout="this.className='tr1'">
<td><?php echo htmlspecialchars(substr($row['name'], 0,30)) ?></td>
<td><?php echo htmlspecialchars($row['short_name']) ?></td>
<td><?php echo htmlspecialchars($row['date']) ?></td>
<td><?php echo ($row['played'] ? 'Y' : 'N') ?></td>
<td><a href="m_matches_zoom_edit.php?matchID=<?php echo intval($row['matchID']) ?>">Modify</a></td>
<td><a href="<?php echo $_SERVER['PHP_SELF'] ?>?matchID=<?php echo intval($row['matchID']) ?>">Delete</a></td>
<?php
}
?>
</tbody>
</table>
</div>
<?php
}
?>
<?php
require('parts/end.php');
?>