<?php
session_start();
if (empty($_SESSION['ok'])) {
header("Location: ".$_SERVER['HTTP_HOST']."/index.php");
exit;
}
if (empty($_SESSION['files'])) unset($_SESSION['files']);
$rejected=array();
$sendfiles=isset($_POST['file'])?$_POST['file']:array();
$apache2=isset($_POST['apache2'])?1:0;
require_once("cfg.php");
require_once("db_connect.php");
if (isset($_POST['send']) && !empty($sendfiles)) {
require_once("zip.php");
$zipfile = new zipfile();
foreach($sendfiles as $file) {
$query=mysql_query("SELECT name FROM team WHERE id='$file'");
while($j = mysql_fetch_assoc($query)) {
$team=$j['name'];
$team2=$team;
if ($apache2==1) $team2=preg_replace("/[^a-zA-Z0-9]/",'',$team);
}
if (GET_smallTeamIcon($team) != '') {
$zipfile->add_file(implode('',file(substr(GET_smallTeamIcon($team),1))), substr(GET_smallTeamIcon($team),7));
}
if (GET_bigTeamIcon($team) != '') {
$zipfile->add_file(implode('',file(substr(GET_bigTeamIcon($team),1))), substr(GET_bigTeamIcon($team),7));
}
}
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"icons.zip\"");
echo $zipfile->file();
} else {
if (!isset($_SESSION['files'])) $_SESSION['files']=array();
if (!empty($_GET['add'])) {
$add_files=explode(',',$_GET['add']);
foreach ($add_files as $add) {
if (count($_SESSION['files'])<MAXIMUM_ICONS_PER_ZIP) {
$x=array_search($add,$_SESSION['files']);
if ($x===FALSE) {
$_SESSION['files'][]=$add;
} else {
$rejected[]=$add;
}
} else{
$rejected[]=$add;
}
}
}
if(isset($_POST['deleteall']))
unset($_SESSION['files']);
if(isset($_GET['del'])) {
$del = $_GET['del'];
$x = array_search($del, $_SESSION['files']);
if ($x!==FALSE) {
unset($_SESSION['files'][$x]);
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="de">
<head>
<title><?php echo RESULT?></title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="container">
<h1>Auswahl</h1><?php
if (count($_SESSION['files'])>0) {
if (count($rejected)>0) {?>
<dl>
<dt><?php echo NO_ICON_ZIP?><small>(<?php echo NO_ZIP_ARG1?> [<?php echo MAXIMUM_ICONS_PER_ZIP?>] <?php echo NO_ZIP_ARG2?>)</small></dt><?php
foreach ($rejected as $file) {
$query=mysql_query("SELECT name FROM team WHERE id=$file");
$j = mysql_fetch_row($query);
$team=$j[0];?>
<dd><?php echo $team?></dd><?php
}?>
</dl><?php
}?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table>
<tr>
<th colspan="5"><?php echo SEL_ICONS?></th>
</tr><?php
$i=0;
foreach ($_SESSION['files'] as $file) {
$i++;
$query=mysql_query("SELECT name FROM team WHERE id=$file");
$j = mysql_fetch_row($query);
$team=$j[0];?>
<tr>
<td><?php echo $i?>.</td>
<td><?php echo HTML_smallTeamIcon('',$team,"alt=''");?></td>
<td><?php echo check_big(HTML_bigTeamIcon('',$team," alt=''"));?></td>
<td><?php echo $team?><input type="hidden" name="file[]" value="<?php echo $file?>"></td>
<td><a class='label label-danger' href="<?php echo $_SERVER['PHP_SELF']?>?del=<?php echo $file?>"><?php echo DEL_LIST?></a></td>
</tr><?php
}?>
</table>
<table id="choose">
<tr>
<td>
<input type="checkbox" name="apache2">
</td>
<td><acronym title="<?php echo APACHE_HINT?>"><?php echo APACHE_COMP?></acronym></td>
</tr>
<tr>
<td><input class="btn btn-danger btn-xs" type="submit" name="deleteall" value="<?php echo DEL_LIST?>"></td>
</tr>
<tr>
<td><input class="btn btn-success btn-xs" type="submit" name="send" value="<?php echo SAVE_LIST?>"></td>
</tr>
<tr>
<td colspan="2"><h5><?php echo SAVE_LOCAL?>!</h5></td>
</tr>
</table>
</form><?php
}
if ($i==0) {?>
<p><?php echo SEL_TEAM?></p><?php
}
?>
<br /><br />
<address>© René Marth</address>
</div>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</body>
</html><?php
}?>