Code:
<?php
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
/*
* global variables used in various places...
*/
global $setOptions;
global $set_options;
global $plays;
/*
* build HTML options out of config variable set_options
*/
$setOptions = array();
$setOptions[] = mosHTML::makeOption(' ');
$set_options = explode(';',$match_mode_config['set_options']);
foreach($set_options as $set_option) {
if ($set_option) { // ignore witespaces
$setOptions[] = mosHTML::makeOption(trim($set_option));
}
}
$plays = explode(';',$match_mode_config['plays']);
for ($i=0; $i < count($plays); $i++) {
if ($plays[$i]){
$plays[$i] = trim($plays[$i]);
} else {
unset($plays[$i]);
}
}
function makeSingle ($order,$pos1,$pos2,$playerlist1,$playerlist2,$players,$match_mode_config) {
$pid1 = $playerlist1[$pos1-1];
$pid2 = $playerlist2[$pos2-1];
printf ("<td>%s</td><td>%s</td>",
searchPlayer($players[0],$pid1),
searchPlayer($players[1],$pid2));
createSets($order,$match_mode_config);
makeHiddenField ("player1_$order",$pid1);
makeHiddenField ("player2_$order",$pid2);
makeHiddenField ("pos1_$order",$pos1);
makeHiddenField ("pos2_$order",$pos2);
}
function makeDouble ($order,$double1,$double2,$doubleplayer1,$doubleplayer2,$players,$match_mode_config) {
$pid1a = $doubleplayer1[$double1*2-2];
$pid1b = $doubleplayer1[$double1*2-1];
$pid2a = $doubleplayer2[$double2*2-2];
$pid2b = $doubleplayer2[$double2*2-1];
printf ("<td>%s<br/>%s</td><td>%s<br/>%s</td>",
searchPlayer($players[0],$pid1a),searchPlayer($players[0],$pid1b),
searchPlayer($players[1],$pid2a),searchPlayer($players[1],$pid2b));
createSets($order,$match_mode_config);
makeHiddenField ("player1_$order",$pid1a);
makeHiddenField ("player1b_$order",$pid1b);
makeHiddenField ("player2_$order",$pid2a);
makeHiddenField ("player2b_$order",$pid2b);
makeHiddenField ("pos1_$order",$double1);
makeHiddenField ("pos2_$order",$double2);
}
function makeHiddenField($name,$value) {
printf ("<td><input type='hidden' name='$name' value='$value' /></td>");
}
function createSets ($order,$match_mode_config) {
for($i=1;$i<=$match_mode_config['anz_sets'];$i++) {
printf ('<td>%s</td>',createSet($order,$i));
}
printf ("<td><input size='1' readonly='readonly' name='sets_%s' onfocus='this.blur()'/></td>",$order);
printf ("<td><input size='1' readonly='readonly' name='match_%s' onfocus='this.blur()'/></td>",$order);
}
function createSet ($match,$set) {
global $setOptions;
return mosHTML::selectList($setOptions,'set_'.$match.'_'.$set,
'onchange="checkSet('.$match.','.$set.')"','value','text','-99');
// return "<input type='text' name='set_$match_$set_$partner' size='1' maxlength='2'/>";
// return "<div name='set_$match_$set_$partner'>11</div>";
}
// search a player in a list of players by id and return full name
function searchPlayer($players,$pid) {
foreach ($players as $player) {
if ($player->id == $pid) {
return $player->firstname.' '.$player->lastname;
}
}
return "";
}
?>
<script type="text/javascript"><!--
function checkForm() {
var f=document.adminForm;
var points1=0;
var points2=0;
var anz_win_plays=<?=$match_mode_config['anz_win_plays'];?>;
for (var i=1;i<=<?=count($plays)?>;i++) {
var v = f.elements['match_'+i].value;
if (v == '1:0') { points1++; }
else if (v == '0:1') { points2++; }
else { break; }
}
if ((points1 >= anz_win_plays) || (points2 >= anz_win_plays) ||
((points1==anz_win_plays-1) && (points2==anz_win_plays-1))) {
return true;
} else {
alert ("<?=_JL_TT_NOT_ENOUGH_PLAYS;?>");
return false;
}
}
function checkSet(play,set) {
var f=document.adminForm;
var set1=0;
var set2=0;
var anz_sets=<?=$match_mode_config['anz_sets'];?>;
var anz_win_sets=<?=$match_mode_config['anz_win_sets'];?>;
for (var i=1;i<=anz_sets;i++) {
sel = getSetValue(f,play,i);
if (sel.indexOf(":") == -1) {
return;
}
var s=sel.split(':');
if (parseInt(s[0]) > parseInt(s[1])) {
set1++;
} else {
set2++;
}
if (set1==anz_win_sets || set2==anz_win_sets) {
f.elements['sets_'+play].value = set1 + ':' + set2;
if (set1 > set2) {
f.elements['match_'+play].value = '1:0';
} else {
f.elements['match_'+play].value = '0:1';
}
while (++i<=anz_sets) {
getSet(f,play,i).options.selectedIndex=0;
}
getSet(f,play+1,1).focus();
break;
}
}
}
function getSetValue(f,play,set) {
var s = getSet(f,play,set);
return s.options[s.selectedIndex].value;
}
function getSet(f,play,set) {
return f.elements['set_'+play+'_'+set];
}
//--></script>
<div class="componentheading"><?=$project->name;?></div>
<form action="index.php?option=com_joomleague&func=saveMatchResults&p=<?=$project->id;?>&mid=<?=$mid;?>&Itemid=<?=$Itemid;?>"
method="post" name="adminForm" onsubmit="return checkForm()">
<table width="100%" class="contentpaneopen">
<tr><td class="contentheading">
<?php printf ("%s %s : %s",_JL_TT_RESULT_INPUT,$team[0]->name,$team[1]->name);?>
</td></tr>
</table>
<?php if ($team1withdrawal || $team2withdrawal) {
if ($team1withdrawal) {
printf (_JL_TT_TEAM_WITHDRAWAL, $team[0]->name);
echo '<input type="hidden" name="team1withdrawal" value="1"/>';
echo '<input type="hidden" name="team2withdrawal" value="0"/>';
} else {
printf (_JL_TT_TEAM_WITHDRAWAL, $team[1]->name);
echo '<input type="hidden" name="team1withdrawal" value="0"/>';
echo '<input type="hidden" name="team2withdrawal" value="1"/>';
}
} else { ?>
<br/>
<table width="96%" align="center" border="0" cellpadding="5" cellspacing="0">
<thead><tr>
<th> </th>
<th><?php echo $team[0]->name;?></th>
<th><?php echo $team[1]->name;?></th>
<?php for ($i=1;$i<=$match_mode_config['anz_sets'];$i++) {
printf("<th>%s. %s</th>",$i,_JL_TT_SET);}
?>
<th><?php echo _JL_TT_SETS; ?></th>
<th><?php echo _JL_TT_PLAYS; ?></th>
</tr></thead>
<?php
for ($i=0; $i < count($plays); $i++) {
$p = explode(':',$plays[$i]);
printf ("<tr><td>%s-%s</td>",$p[0],$p[1]);
if (ord($p[0]) == ord('D')) {
makeDouble($i+1,$p[0][1],$p[1][1],$doubleplayer1,$doubleplayer2,$players,$match_mode_config);
} else {
makeSingle($i+1,$p[0],$p[1],$playerlist1,$playerlist2,$players,$match_mode_config);
}
echo "</tr>";
}
?>
</table>
<?php } ?>
<br/>
<center>
<input type="submit" class="button" name="ok" value="<?=_JL_TT_SAVE_RESULTS;?>"/>
</center>
</form>
<!-- Footer -->
<?php include("show_footer.tpl.php"); ?>
<!-- Footer Ende -->
Lesezeichen