<?php
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
// start session
session_start();
// load classes
//require_once($_SERVER['DOCUMENT_ROOT'].$_SESSION['srcPath'].'/src/conf/cConfig.php');
//CONFIG::loadConfig();
require_once('conf/cConfig.php');
ngremacsCONFIG::loadConfig();
ngremacsCONFIG::loadPluginConfigIni();
require_once(('lang/lang.'.$_SESSION["language"]));
$lang_php = array_merge($lang_reg, $lang_php);
$db_models_name = 'db_models'.(ngremacsCONFIG::$loadCmpNgReMaCsPHP?'.cmp':'').'.php';
if(file_exists($db_models_name)) {
require_once($db_models_name);
} else {
exit('no database model file exist!!');
}
$exclude = array();
$languageDisable = !empty($_REQUEST['languageDisable']) AND $_REQUEST['languageDisable'] == 'true'? true:false;
$api = new DB_ngREMACS();
switch ($_REQUEST['namespace']) {
case 'ngremacs.getSportlerGrid':
$id = empty($_REQUEST['id']) ? NULL : $_REQUEST['id'];
$data = $api->getSingleSportlerDB($id);
$data = $data[0];
$data['geschlecht'] = $data['geschlecht'] == 'f' ? 'weiblich' : 'mänlich';
//replace _startberechtigt
$data['startberechtigt'] = $data['_startberechtigt'];
unset($data['_startberechtigt']);
break;
case 'ngremacs.getAthletsRegattaGrid':
$id = empty($_REQUEST['id']) ? NULL : $_REQUEST['id'];
$regid = empty($_REQUEST['regid']) ? NULL : $_REQUEST['regid'];
$data = $api->getSingleSportlerDB($id);
$data = $data[0];
$data['geschlecht'] = $data['geschlecht'] == 'f' ? 'weiblich' : 'männlich';
//replace _startberechtigt
$data['startberechtigt'] = $data['_startberechtigt'];
unset($data['_startberechtigt']);
//add data
if(($meld = $api->getMeldungenOfAthlet($id, $regid))!==False && !empty($meld)) {
$strHtml = '<table class="printOutAthletsRennen">';
$strHtml.= '<tr><th>Rennen</th><th>Platz</th><th>Status</th></tr>';
foreach($meld as $value) {
$strHtml.= '<tr><td>'.$value['nummer'].': '.$value['spezifikation'].'</td><td>'.($value['_platz']!=0 && $value['_platz']<99 ? $value['_platz']:'').'</td><td>'.$value['_status'].'</td></tr>';
}
$strHtml.='</table>';
$data[$lang_php['rennenRegGridPrefix']] = $strHtml;
}
break;
default:
break;
}
$data = array_exclude($data, $exclude);
function array_exclude(array $data, array $exclude = array()) {
foreach ($exclude as $field) {
if (is_array($field)) {
foreach ($data as $key => $value) {
$pos = strpos($key, $field['key']);
if ($pos !== false) {
if (($field['place'] == 'start' && $pos == 0) || ($field['place'] == 'end' && $pos == strlen($key)-strlen($field['key']))) {
unset($data[$key]);
}
}
}
} elseif (isset($data[$field])) {
unset($data[$field]);
}
}
return $data;
}
function implode_multi($glue, $array) {
global $lang_php;
$json = @json_decode($array, true);
if (!empty($json) && is_array($json)) {
$array = $json;
}
if (is_array($array)) {
foreach ($array as $key => &$value) {
if (is_array($value)) {
$value = '<li style="list-style:none;padding:0;margin:0">'.implode_multi(' ', CommonUtils::array_trim($value)).'</li>';
} else {
$value = '<li>'.$value.'</li>';
}
}
return '<ul>'.implode($glue, $array).'</ul>';
}
return $array;
}
function load_env()
{
global $lang_js, $lang_php;
$lang_php = array_merge($lang_js, $lang_php);
CONFIG::loadClasses();
CONFIG::loadScripts();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>printOut</title>
<meta <?php echo 'http-equiv="Content-Type" content="text/html; charset='.strtoupper(CONFIG::$encodingData).'"';?>>
<link type="text/css" rel="stylesheet" href="css/print.css" />
</head>
<body<?php echo (empty($_REQUEST['print']) ? null : ' >); ?>>
<table class="printOut" style="min-width: 600px;">
<tr>
<td class="header">FIELD NAME</td>
<td class="header">VALUE</td>
</tr>
<?php foreach ($data as $key => $value): ?>
<tr>
<?php if (strpos($key, '_value') !== false) continue; ?>
<?php if (empty($lang_php[$key])): ?>
<?php if($languageDisable): ?>
<td class="field"><?php echo ucfirst($key); ?></td>
<?php else: ?>
<td class="field unknown"><?php echo ucfirst($key); ?></td>
<?php endif; ?>
<?php else: ?>
<td class="field"><?php echo ucfirst($lang_php[$key]); ?></td>
<?php endif; ?>
<td class="value"><?php echo implode_multi(' ', $value) . (isset($data[$key . '_value']) ? ' (' . $data[$key . '_value'] . ')' : null); ?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>