Location: PHPKode > projects > OSADS Alliance Database > OSADS-2.1/includes/functions.php
<?php
/* +----------------------------------------------------------------------
// | OSADS
// |
// | PHP Source
// +----------------------------------------------------------------------
// | Copyright (C) 2008 by Frank Tetzel <hide@address.com>
// +----------------------------------------------------------------------
// |
// | OSADS is free software; you can redistribute it and/or modify
// | it under the terms of the GNU General Public License as published by
// | the Free Software Foundation; either version 2 of the License, or
// | (at your option) any later version.
// |
// | OSADS is distributed in the hope that it will be useful,
// | but WITHOUT ANY WARRANTY; without even the implied warranty of
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// | GNU General Public License for more details.
// |
// | You should have received a copy of the GNU General Public License
// | along with OSADS. If not, write to the Free Software Foundation, Inc.,
// | 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// |
// +----------------------------------------------------------------------
*/

/**
 * function file modified and cleaned up as far as possible
 * 
 * @author Benjamin Zikarsky <benjamin AT zikarsky DOT de>
 */

// Direktzugriff abwehren
if (!defined('INDEX')) die('not allowed');

// language file
include "./langs/". $member_lang ."/includes_functions.php";


/**
 * create table with planets for any arguments
 *
 * @param int $mode
 * @param string $where
 * @param string $where_args
 * @param string $order
 * @param string $limit
 * @param string $limit_args
 */
function tabelle_planis($mode, $where, $where_args, $order, $limit, $limit_args){
	//mode:	2 - einlesen (leere planeten, ohne sortierungsmoeglichkeit)
	//		1 - gala (leere planeten, mit sortierungsmoeglichkeit)
	//		0 - suche (keine leeren planeten, mit sortierungsmoeglichkeit)
	global $db, $member_spalten, $config_tableprefix;

	$sort 	 = $mode != 2;

	$mapping = Array(
		'0' => Array('p.coords_sysx, p.coords_sysy, p.coords_planet', '', ''),
		'1' => Array('(p.tf_met+p.tf_kris)', L_SHORT_TF, L_SHORT_TOTAL),
		'2' => Array('p.tf_met', L_SHORT_TF, L_SHORT_METAL),
		'3' => Array('p.tf_kris', L_SHORT_TF, L_SHORT_CRYSTAL),
		'4' => Array('p.name', L_PLANETNAME, ''),
		'5' => Array('s.name', L_PLAYERNAME, ''),
		'6' => Array('LEFT(s.zusatz, LOCATE(\';\', s.zusatz)-1)', L_SHORT_STATUS, ''),
		'7' => Array('(s.k_met+s.k_kris+s.k_trit)', L_BOUNTY, L_SHORT_TOTAL),
		'8' => Array('s.k_met', L_BOUNTY, L_SHORT_METAL),
		'9' => Array('s.k_kris', L_BOUNTY, L_SHORT_CRYSTAL),
		'A' => Array('s.k_trit', L_BOUNTY, L_SHORT_TRITIUM),
		'B' => Array('s.allianz', L_ALLY, ''),
		'C' => Array('s.punkte', L_POINTS, L_SHORT_TOTAL),
		'D' => Array('s.platz', L_PLACE, L_SHORT_TOTAL),
		'E' => Array('s.p_konstr', L_POINTS, L_SHORT_CONSTRUCTION),
		'F' => Array('s.pl_konstr', L_PLACE, L_SHORT_CONSTRUCTION),
		'G' => Array('s.p_forsch', L_POINTS, L_SHORT_RESEARCH),
		'H' => Array('s.pl_forsch', L_PLACE, L_SHORT_RESEARCH),
		'I' => Array('s.p_flotte', L_POINTS, L_SHORT_FLEET),
		'J' => Array('s.pl_flotte', L_PLACE, L_SHORT_FLEET)
	);
	//delete all inactive
	$spalten = eregi_replace('0[1-9A-J]', '', $member_spalten);
	$arr_spalten = array();
	for($i=1; $i<strlen($spalten); $i+=2){
		$arr_spalten[] = $spalten[$i];
	}
	$sortTpl =
'			<a href="javascript: order(\'%s\', \'DESC\');" title="'. L_DOWNWARD .'">
				<img src="./bilder/down.png" alt="'. L_DOWNWARD .'">
			</a>
			&nbsp;%s&nbsp;
			<a href="javascript: order(\'%1$s\', \'ASC\');" title="'. L_UPWARD .'">
				<img src="./bilder/top.png" alt="'. L_UPWARD .'">
			</a>
';

	if($order){
		$direction = '';
		if(strpos($order, 'ASC') !== FALSE){
			$direction = 'ASC';
		}else if(strpos($order, 'DESC') !== FALSE){
			$direction = 'DESC';
		}
		$order = str_replace($direction, '', $order);
		$order = ereg_replace('([0-9A-J])', '{$mapping[\\1][0]}', $order);
		eval("\$order = \" ORDER BY $order $direction\";");
	}
	if($where) $where = " WHERE " . $where;
	if($limit) $limit = " LIMIT ". $limit;

	$s = 'p.coords_sysx, p.coords_sysy, p.coords_planet, p.pk, s.pk';
	foreach($arr_spalten as $spalte){
		$s .= ', '. $mapping[$spalte][0];
	}
	$db->saveQuery('SELECT '. $s .' FROM %splaneten p LEFT JOIN %1$sspieler s '
				 . 'ON p.spieler_pk=s.pk ' . $where. ' %s  ' .$limit,
					$config_tableprefix, $where_args, $order, $limit_args);
	$zeile = $db->fetch_array();
	if (empty($zeile)) {
		echo '<font color="#F00"><b>'. L_NOTFOUND .'</b></font><br>';
		$db->free_result();
		return;
	}

	echo '<table width="100%" class="bc stripes">'. "\n";

 // BEGIN write upper captions for the sections
	echo "\t<tr>\n\t\t<th rowspan=\"2\" nowrap>\n";
	if ($mode == 2) {
		echo "\t\t\t&nbsp;&nbsp;". L_SHORT_NUMBER ."&nbsp;&nbsp;\n";
	} else {
		$_name = $mode == 1 ? L_SHORT_NUMBER
							: L_SHORT_COORDS;
		printf($sortTpl, '0', $_name);
	}
	echo "\t\t</th>\n";
	for($i=0; $i<count($arr_spalten); $i+=$j){
		$thattr = '';
		$tmp = $arr_spalten[$i];
		$j = 1;
		while($i+$j < count($arr_spalten) && $mapping[$arr_spalten[$i]][1]==$mapping[$arr_spalten[$i+$j]][1]){
			$tmp .= '+'. $arr_spalten[$i+$j];
			$j++;
		}
		if($j > 1){
			$thattr = ' colspan="'. $j .'"';
			$tmp = "($tmp)";
		}else if($mapping[$arr_spalten[$i]][2]==''){
			$thattr = ' rowspan="2"';
		}
		echo "\t\t<th". $thattr .">\n";
		if($sort){
			printf($sortTpl, $tmp, $mapping[$arr_spalten[$i]][1]);
		}else{
			echo "\t\t\t&nbsp;&nbsp;". $mapping[$arr_spalten[$i]][1] ."&nbsp;&nbsp;\n";
		}
		echo "\t\t</th>\n";
	}
	echo "\t\t<th rowspan=\"2\">". L_NOTE ."</th>\n\t</tr>\n";
	// END write upper captions for the sections

	// BEGIN write lower captions
	echo "\t<tr>\n";
	for($i=0; $i<count($arr_spalten); $i++){
		if($mapping[$arr_spalten[$i]][2]=='') continue;
		echo "\t\t<th>\n";
		if($sort){
			printf($sortTpl, $arr_spalten[$i], $mapping[$arr_spalten[$i]][2]);
		}else{
			echo "\t\t\t&nbsp;&nbsp;". $mapping[$arr_spalten[$i]][2] ."&nbsp;&nbsp;\n";
		}
		echo "\t\t</th>\n";
	}
	echo "\t</tr>\n";
	// END write lower captions

	$i=1;
	do {
		if ($mode) for (; $i<=$zeile[2]; $i++) {
			echo "\t<tr>\n\t\t<td>" . $i . "</td>\n";
			if ($i < $zeile[2]) echo str_repeat("\t\t<td></td>\n", count($arr_spalten)+1), "\t</tr>\n";
		} else echo "\t<tr>\n\t\t<td>\n",
				 	"\t\t\t".'<a href="./index.php?action=gala&amp;xpos='.$zeile[0].'&amp;ypos=',
					$zeile[1].'">', $zeile[0], ":", $zeile[1], ":", $zeile[2], "</a>\n\t\t</td>\n";
		for ($a=5; $a<count($arr_spalten)+5; $a++) {
			if (is_numeric($zeile[$a])) echo "\t\t<td>", number_format($zeile[$a], 0, ',', '.'),
											 "</td>\n";
			else echo "\t\t<td>\n\t\t\t", '<a href="./index.php?action=suche&amp;merkmal='. $arr_spalten[$a-4],
					  '&amp;wert=' . $zeile[$a] . '">', $zeile[$a] ."</a>\n\t\t</td>\n";
		}
		
		echo "\t\t<td nowrap>\n",
			 "\t\t\t".'<a title="', L_NOTE_PLANET, '" href="./index.php?action=notizen&amp;p_pk=',
			 $zeile[3], '">', '<img src="./bilder/planet.png" alt="', L_NOTE_PLANET, '"></a>'."\n";
			 
		if ($zeile[4]) echo	"\t\t\t".'&nbsp;&nbsp;<a title="', L_NOTE_PLAYER, 
							'" href="./index.php?action=notizen&amp;s_pk=', $zeile[4], '">',
							'<img src="./bilder/player.png" alt="', L_NOTE_PLAYER, '"></a>'."\n";
		echo "\t\t</td>\n\t</tr>\n";
	}while($zeile = $db->fetch_array());
	if($mode){
		for(; $i<17; $i++){
			echo "\t<tr>\n\t\t<td>", $i, "</td>\n",
				str_repeat("\t\t<td></td>\n", count($arr_spalten)+1), "\t</tr>\n";
		}
	}
	echo "</table><br>\n";
	if ($mode != 2) {
		echo '<script language="javascript" type="text/javascript">',
			 'function order(orderstr, aufab){
				document.sortierung.order.value = orderstr;
				document.sortierung.aufab.value = aufab;'."\n";
		echo $mode == 1
			? 'document.sortierung.submit();'
			: 'document.sortierung.btn.click();';
		echo '}'."\n".'</script>';
	}
	$db->free_result();
}

/**
 * create table with planets for any arguments
 *
 * @param int $mode
 * @param string $where
 * @param string $where_args
 * @param string $order
 * @param string $limit
 * @param string $limit_args
 */
/*
function tabelle_planis($mode, $where, $where_args, $order, $limit, $limit_args){
	//mode:	2 - einlesen (leere planeten, ohne sortierungsmoeglichkeit)
	//		1 - gala (leere planeten, mit sortierungsmoeglichkeit)
	//		0 - suche (keine leeren planeten, mit sortierungsmoeglichkeit)
	global $db, $member_spalten, $config_tableprefix;

	// TODO: SECURITY!!! -- No SQL into Javascript!
	$sortTpl = '<a href="javascript: order(\'%s\', \'DESC\');" title="'. L_DOWNWARD .'">'
			 . '<img src="./bilder/down.png" alt="'. L_DOWNWARD .'">'
			 . '</a>'
		     . '&nbsp;%s&nbsp;'
			 . '<a href="javascript: order(\'%1$s\', \'ASC\');" title="'. L_UPWARD .'">'
			 . '<img src="./bilder/top.png" alt="'. L_UPWARD .'">'
			 . '</a>';
	
	if($where) $where = " WHERE " . $where;	
	if($order) $order = " ORDER BY " . $order;
	if($limit) $limit = " LIMIT ". $limit;
	
	$sel  	 = array('p.coords_sysx', 'p.coords_sysy', 'p.coords_planet',
					 'p.pk', 's.pk');
	$thoben  = array('Pos');
	$thunten = array('');
	$sort 	 = $mode != 2;
	
	// $member_spalten structure "011203 ... 1F0G" 
	//		2 byte pairs: 
	// 			* x. enables/disables
	//			* .x is a flag identifying the type
	for ($i=0; $i<strlen($member_spalten)/2; $i++) {
		if ($member_spalten[2*$i] == '0') continue; // column is disabled
		switch ($member_spalten[2*$i+1]) {
			// tf
			case '1':
				$sel[] 		= '(p.tf_met+p.tf_kris)';
				$thoben[] 	= L_SHORT_TF;
				$thunten[] 	= L_SHORT_TOTAL;
				break;
			//tf met
			case '2':
				$sel[] 		= 'p.tf_met';
				$thoben[] 	= L_SHORT_TF;
				$thunten[] 	= L_SHORT_METAL;
				break;
			//tf kris
			case '3':
				$sel[] = 'p.tf_kris';
				$thoben[] = L_SHORT_TF;
				$thunten[] = L_SHORT_CRYSTAL;
				break;
			//planetenname
			case '4':
				$sel[] = 'p.name';
				$thoben[] = L_PLANETNAME;
				$thunten[] = '';
				break;
			//spielername
			case '5':
				$sel[] = 's.name';
				$thoben[] = L_PLAYERNAME;
				$thunten[] = '';
				break;
			//zusatz
			case '6':
				$sel[] =  'LEFT(s.zusatz, LOCATE(\';\', s.zusatz)-1)';//'s.zusatz';
				$thoben[] = L_SHORT_STATUS;
				$thunten[] = '';
				break;
			//kopfgeld gesamt
			case '7':
				$sel[] = '(s.k_met+s.k_kris+s.k_trit)';
				$thoben[] = L_BOUNTY;
				$thunten[] = L_SHORT_TOTAL;
				break;
			//k met
			case '8':
				$sel[] = 's.k_met';
				$thoben[] = L_BOUNTY;
				$thunten[] = L_SHORT_METAL;
				break;
			//k kris
			case '9':
				$sel[] = 's.k_kris';
				$thoben[] = L_BOUNTY;
				$thunten[] = L_SHORT_CRYSTAL;
				break;
			//k trit
			case 'A':
				$sel[] = 's.k_trit';
				$thoben[] = L_BOUNTY;
				$thunten[] = L_SHORT_TRITIUM;
				break;
			//allianz
			case 'B':
				$sel[] = 's.allianz';
				$thoben[] = L_ALLY;
				$thunten[] = '';
				break;
			//punkte gesamt
			case 'C':
				$sel[] = 's.punkte';
				$thoben[] = L_POINTS;
				$thunten[] = L_SHORT_TOTAL;
				break;
			//platz gesamt
			case 'D':
				$sel[] = 's.platz';
				$thoben[] = L_PLACE;
				$thunten[] = L_SHORT_TOTAL;
				break;
			//konstr punkte
			case 'E':
				$sel[] = 's.p_konstr';
				$thoben[] = L_POINTS;
				$thunten[] = L_SHORT_CONSTRUCTION;
				break;
			//konstr platz
			case 'F':
				$sel[] = 's.pl_konstr';
				$thoben[] = L_PLACE;
				$thunten[] = L_SHORT_CONSTRUCTION;
				break;
			//forsch punkte
			case 'G':
				$sel[] = 's.p_forsch';
				$thoben[] = L_POINTS;
				$thunten[] = L_SHORT_RESEARCH;
				break;
			//forsch platz
			case 'H':
				$sel[] = 's.pl_forsch';
				$thoben[] = L_PLACE;
				$thunten[] = L_SHORT_RESEARCH;
				break;
			//flotte punkte
			case 'I':
				$sel[] = 's.p_flotte';
				$thoben[] = L_POINTS;
				$thunten[] = L_SHORT_FLEET;
				break;
			//flotte platz
			case 'J':
				$sel[] = 's.pl_flotte';
				$thoben[] = L_PLACE;
				$thunten[] = L_SHORT_FLEET;
				break;
			default: 
				die('Fehler: Spaltenzuordnung in ' . __FILE__ . '/' . __FUNCTION__);
		}
	}
	$s = implode(', ', $sel);
	$db->saveQuery('SELECT '. $s .' FROM %splaneten p LEFT JOIN %1$sspieler s '
				 . 'ON p.spieler_pk=s.pk ' . $where. ' %s  ' .$limit,
					$config_tableprefix, $where_args, $order, $limit_args);
	$zeile = $db->fetch_array();
	
	if (empty($zeile)) {
		echo '<font color="#F00"><b>'. L_NOTFOUND .'</b></font><br>';
		$db->free_result();
		return;
	}
	
	echo '<table width="100%" class="bc stripes">';
	
	// BEGIN write upper captions for the sections
	echo '<tr><th rowspan="2" nowrap>';
	if ($mode == 2) {
		echo '&nbsp;&nbsp;'. L_SHORT_NUMBER .'&nbsp;&nbsp;';
	} else {
		$_type = $mode == 1 ? 'p.coords_planet' 
						    : 'p.coords_sysx, p.coords_sysy, p.coords_planet';
		$_name = $mode == 1 ? L_SHORT_NUMBER
							: L_SHORT_COORDS;
		printf($sortTpl, $_type, $_name);
	}
	echo '</th>';
	for ($i=1; $i<count($thoben);) {
		$thattr = '';
		$tmp_sel = $sel[$i+4];
		$a = 1;
		while($i+$a < count($thoben) && $thoben[$i] == $thoben[$i+$a])
			$tmp_sel .= '+' . $sel[$i+4 + $a++];

		if ($a > 1) {
			$thattr = ' colspan="' . $a . '"';
			$tmp_sel = "($tmp_sel)";
		} else if (in_array($thoben[$i], array(L_ALLY, L_PLANETNAME, 
										 L_PLAYERNAME, L_SHORT_STATUS))) {
			$thattr = ' rowspan="2"';
		}
		echo '<th' . $thattr . '>';
		if ($sort) printf($sortTpl, $tmp_sel, $thoben[$i]);
		else echo '&nbsp;&nbsp;' . $thoben[$i] . '&nbsp;&nbsp;';
		echo '</th>';
		$i += $a;
	}
	echo '<th rowspan="2">'. L_NOTE .'</th></tr>';
	// END write upper captions for the sections
	
	// BEGIN write lower captions
	echo '<tr>';
	for ($i=1; $i<count($thunten); $i++) {
		if ($thunten[$i] == "") continue;
		echo '<th>';
		if ($sort) printf($sortTpl, $sel[$i+4], $thunten[$i]);
		else echo "&nbsp;&nbsp;" . $thunten[$i] . "&nbsp;&nbsp;";
		echo '</th>';
	}
	echo '</tr>';
	// END write lower captions
	
	$i=1;
	do {
		if ($mode) for (; $i<=$zeile[2]; $i++) {
			echo '<tr><td>' . $i . '</td>';
			if ($i < $zeile[2]) echo str_repeat('<td></td>', count($thoben)), '</tr>'. "\n";
		} else echo '<tr><td>',
				 	'<a href="./index.php?action=gala&amp;xpos='.$zeile[0].'&amp;ypos=',
					$zeile[1].'">', $zeile[0], ":", $zeile[1], ":", $zeile[2], '</a></td>';
		for ($a=5; $a<count($thoben)+4; $a++) {
			if (is_numeric($zeile[$a])) echo '<td>', number_format($zeile[$a], 0, ',', '.'), 
											 '</td>';
			else echo '<td><a href="./index.php?action=suche&amp;merkmal=' . $sel[$a],
					  '&amp;wert=' . $zeile[$a] . '">', $zeile[$a] . '</a></td>';
		}
		
		echo '<td nowrap>',
			 '<a title="', L_NOTE_PLANET, '" href="./index.php?action=notizen&amp;p_pk=',
			 $zeile[3], '">', '<img src="./bilder/planet.png" alt="', L_NOTE_PLANET, '"></a>';
			 
		if ($zeile[4]) echo	'&nbsp;&nbsp;<a title="', L_NOTE_PLAYER, 
							'" href="./index.php?action=notizen&amp;s_pk=', $zeile[4], '">',
							'<img src="./bilder/player.png" alt="', L_NOTE_PLAYER, '"></a>';
		echo '</td></tr>';
	} while ($zeile = $db->fetch_array());
			
	if ($mode) for(;$i<17; $i++) echo '<tr><td>', $i, '</td>',
								 str_repeat('<td></td>', count($thoben)), '</tr>';


	echo '</table><br>';
		
	if ($mode != 2) {
		echo '<script language="javascript" type="text/javascript">',
			 'function order(orderstr, aufab){
				document.sortierung.order.value = orderstr;
				document.sortierung.aufab.value = aufab;'."\n";
		echo $mode == 1
			 ? 'document.sortierung.submit();'
			 : 'document.sortierung.btn.click();';
		echo '}'."\n".'</script>';
	}
	$db->free_result();
}*/

/**
 * calc a coloured gradient for any distance
 *
 * @param int $anzahl
 * @param array &$r red
 * @param array &$g green
 * @param array &$b blue
 * @return int
 */
/*function farbwahl($distance, &$r, &$g, &$b) {
	$quot = floor(1530 / $distance);
	for ($i=0; $i<$distance; $i++, $v = $quot* $i) {
		// value: 0     255     510     765     1020     1275     1530
		// red  : 255   255     128      0      128      255      255
		$r[$i] = min(round(abs(765-$v)/2), 255);
		
		// value: 0     255     510     765     1020     1275     1530
		// green: 0     255     255     255     0        0        0
		$g[$i] = round(min($v, abs(1020-$v), 255));
		
		// value: 0     255     510     765     1020     1275     1530
		// blue : 0		0       0		128     255      128      0	
		$b[$i] = round(min(abs(1020-$v), 510) * 127.5);   //werte sind viel zu groß
	}
	return $distance;
}*/

function farbwahl($anzahl, &$r, &$g, &$b){
	$abstand = floor(1530 / $anzahl);
	for($i=0; $i<$anzahl; $i++){
		$wert = $abstand * $i;

		//evaluate red color
		if($wert < 255 || $wert > 1275){
			$r[$i] = 255;
		}else if($wert > 510 && $wert < 1020){
			$r[$i] = 0;
		}else if($wert>=255 && $wert<=510){
			$r[$i] = 510 - $wert;
		}else{  //$wert>=1020 && $wert<=1275
			$r[$i] = $wert - 1020;
		}
		//evaluate green color
		if($wert > 255 && $wert < 765){
			$g[$i] = 255;
		}else if($wert > 1020){
			$g[$i] = 0;
		}else if($wert <= 255){
			$g[$i] = $wert;
		}else{  //$wert>=765 && $wert<=1020
			$g[$i] = 1020 - $wert;
		}
		//evaluate blue color
		if($wert > 765 && $wert < 1275){
			$b[$i] = 255;
		}else if($wert < 510){
			$b[$i] = 0;
		}else if($wert>=510 && $wert<=765){
			$b[$i] = $wert - 510;
		}else{  //$wert>=1275
			$b[$i] = 1530 - $wert;
		}

	}
	return $anzahl;
}



/**
 * add a sector to a user
 *
 * @param int $pk user id
 * @param int $x_ol
 * @param int $y_ol
 * @param int $x_ur
 * @param int $y_ur
 */
function gebiet_hinzu($pk, $x_ol, $y_ol, $x_ur, $y_ur){
	global $db, $config_gala_offsetx, $config_gala_offsety, 
		   $config_gala_endx, $config_gala_endy, $config_tableprefix;
		
	$color = 'ff0';
	$msg   = L_SECTOR_FAIL;
	if ($x_ol>=$config_gala_offsetx && 
			$y_ol>=$config_gala_offsety && 
			$x_ur<=$config_gala_endx && 
			$y_ur<=$config_gala_endy && 
			$x_ol<=$x_ur && $y_ol<=$y_ur) {

		$db->saveQuery('SELECT pk FROM %sgebiete WHERE NOT ' 
			         . '(x_ol>%d OR x_ur<%d OR y_ol>%d OR y_ur<%d)'
			         . ' LIMIT 0,1;', $config_tableprefix, $x_ur, $x_ol, 
			           $y_ur, $y_ol);
		$zeile = $db->fetch_array();
		$db->free_result();

		if (!$zeile['pk']) {	//keine Kollision
			$db->saveQuery('INSERT INTO %sgebiete (pk, user_pk, x_ol, y_ol, x_ur, y_ur) '
				 		 . 'VALUES (0, %d, %d, %d, %d, %d);', $config_tableprefix,
							$pk, $_POST['x_ol'], $_POST['y_ol'], $x_ur, $y_ur);
			$color = '0f0';
			$msg   = L_SECTORADDED;
		} else $msg = L_SECTORBLOCKED;
	}
	echo '<font color="#' . $color .'"><b>'. $msg .'</b></font><br><br>';
}


/**
 * generate firing stats
 *
 * @param integer $pk user id
 */
function abschuss_stat($pk){
	global $db, $config_tableprefix;
	$rows = array('v' => '', 's' => '');
	$db->saveQuery('SELECT u.name, a.pos, a.neg, u.art FROM %sabschuss a '
				 . 'LEFT JOIN %1$sunits u ON a.units_pk=u.pk '
				 . 'WHERE a.user_pk=%d ORDER BY u.art ASC;', $config_tableprefix, $pk);
	$rowTpl = '<tr>'
			. '<td class="tdtitle">%s</td>'
			. '<td style="color: #0F0">%s</td>'
			. '<td style="color: #F00">&minus;%s</td>'
			. '</tr>';
	$tblTpl = '<table class="bc">'
			. '<tr><th>%s</th><th>'.L_KILLS.'</th><th>'.L_LOSSES.'</th></tr>'
			. '%s'
			. '</table>';

	while ($zeile = $db->fetch_array())
		$rows[$zeile['art']] .= sprintf($rowTpl, $zeile['name'], $zeile['pos'], 
										$zeile['neg']);
	
				 
	echo '<b>Abschussstatistik</b><br />',
		 '<table><tr>',
		 '<td>', sprintf($tblTpl, L_SPACESHIP, $rows['s']), '</td>',
		 '<td>', sprintf($tblTpl, L_DEFENCE, $rows['v']), '</td>',
		 '</tr></table>';

	$db->free_result();
}

/**
 * gzip output buffer and send compressed site
 */
function print_gzipped_page() {
	global $HTTP_ACCEPT_ENCODING;
	if(headers_sent()){
		$encoding = false;
	}elseif(strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false){
		$encoding = 'x-gzip';
	}elseif(strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false){
		$encoding = 'gzip';
	}else{
		$encoding = false;
	}
	if($encoding){
		$contents = ob_get_contents();
		ob_end_clean();
		header('Content-Encoding: '. $encoding);
		print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
		$size = strlen($contents);
		$contents = gzcompress($contents, 9);
		$contents = substr($contents, 0, $size);
		print($contents);
		exit();
	}else{
		ob_end_flush();
		exit();
	}
}

?>
Return current item: OSADS Alliance Database