Example #1
0
function _LS_saveGame($match_key, $eventID, $aRes)
{
    /*
     * TODO v5 change to json string encoding G:L:P: as in the savelegs ...
     * in ax-POST mode we always have 2/4 arrays
     * currently: gpid:gid:pid:tid:legs
     * find out what is needed to win a set in this event ...
     */
    global $dbi, $usertoken;
    $event = reteventconfig($eventID);
    $legsforset = ceil($event['evsgllegs'] / 2);
    $out = 0;
    foreach ($aRes as $a) {
        $res = explode(':', $a);
        if (sizeof($res) > 2) {
            if ($res[4] >= $legsforset) {
                $sSET = ',gplegswon=' . $res[4] . ',gpsetwon=1';
            } else {
                $sSET = ',gplegswon=' . $res[4] . ',gpsetwon=0';
            }
            $qry = 'UPDATE tblgameplayer set gppid=' . $res[2] . $sSET . '  WHERE gpid=' . $res[0] . ' and gptid=' . $res[3] . ' limit 1';
            $p1 = sql_query($qry, $dbi);
            $out = $out + $p1;
        }
    }
    #debug('New Result '.$aRes[0].':'.$aRes[1].' Match '.$match_key.' by direct edit.');
    dsolog(1, $usertoken['uname'], 'Result ' . $aRes[0] . ':' . $aRes[1] . ' Match: ' . $match_key . '.');
    return $out;
}
Example #2
0
#//
#// Main file League System
#// defines basic layout of interface
# // called by every other LS file ...
# // include("ls_main.php");
#include('header.php');	# // -> require_once("mainfile.php"); --> require_once("config.php");
include 'lsdb_layout.php';
# // -> require_once("mainfile.php"); --> require_once("config.php");
require "func_lsdb.php";
require "func_mail.php";
require "lsdbcontroller.php";
require "api_rs.php";
// Backend DB API
require "api_format.php";
// Backend  API
# // make sure we have the actual configuration loaded
if (isset($_REQUEST['eventid']) && intval($_REQUEST['eventid']) > 0) {
    $event_id = strip_tags($_REQUEST['eventid']);
} else {
    $event_id = 0;
}
if ($event_id > 0) {
    $event = reteventconfig($event_id);
}
# // layout
LS_page_start('ls');
// common layout within the MAIN TD
echo '<div style="height:5px">&nbsp;</div>';
echo '<h3 id="pagetitle"></h3>';
echo '<div id="pagetabs"></div>';
echo '<div id="maincontent">';
Example #3
0
function p_createMatch($mkey, $eventid, $rnum, $vtid, $vpoints, $vsets, $vlegs, $vdate)
{
    /*
     * create entries for tblmatch, tblmatchteam,tblgame,tblleg
     */
    # location = home team
    # MatchDate = $vdate
    # SECURITY ON $LS_LEVEL
    global $dbi, $LS_LEVEL, $usertoken;
    $event = reteventconfig($eventid);
    # Make sure both teams are in the same event ...
    #
    $resq = sql_query("select * from tblteam where tevent_id={$eventid} and id in({$vtid['0']},{$vtid['1']})", $dbi);
    # $resrows=sql_fetch_row($resq,$dbi);
    if (mysql_num_rows($resq) != 2) {
        echo "<font color=red>Event: " . $event['evname'] . " Match: {$mkey} Creation failed, Wrong TEAMS for event...</font><br/>";
        return -1;
    }
    # what is the location of the HomeTeam ??
    #
    $resx = sql_query("select T.id,T.tlocation_id,L.lname from tblteam T,tbllocation L where T.tlocation_id=L.id and T.id={$vtid['0']}", $dbi);
    $row = sql_fetch_array($resx, $dbi);
    $loc = $row[lname];
    $locid = $row[tlocation_id];
    $strsql = "INSERT INTO tblmatch(mid,mkey,mevid,mround,mhtid,matid,mdate,mlocation,mstatus,mactive) values(0,\"{$mkey}\",{$eventid},{$rnum},{$vtid['0']},{$vtid['1']},\"{$vdate}\",\"{$loc}\",0,1)";
    $resx = sql_query($strsql, $dbi);
    if ($resx != 1) {
        echo "<font color=red>Event: " . $event['evname'] . " Match: {$mkey} Creation failed, Matchkey Exists...</font><br/>";
        return -1;
    }
    # ok now we create the 2 matching records for match - team, match - team ...
    # make sure we have values instead of NULL ...
    if (!$vlegs[0]) {
        $vlegs[0] = 0;
        $vlegs[1] = 0;
    }
    if (!$vsets[0]) {
        $vsets[0] = 0;
        $vsets[1] = 0;
    }
    if (!$vpoints[0]) {
        $vpoints[0] = 0;
        $vpoints[1] = 0;
    }
    $strsql = "INSERT into tblmatchteam(mtid,mtmkey,mthome,mttid,mtlegs,mtlegslost,mtsetslost,mtsets,mtpoints) values(0,'{$mkey}',1,{$vtid['0']},{$vlegs['0']},{$vlegs['1']},{$vsets['1']},{$vsets['0']},{$vpoints['0']})";
    $resx = sql_query($strsql, $dbi);
    $strsql = "INSERT into tblmatchteam(mtid,mtmkey,mthome,mttid,mtlegs,mtlegslost,mtsetslost,mtsets,mtpoints) values(0,'{$mkey}',0,{$vtid['1']},{$vlegs['1']},{$vlegs['0']},{$vsets['0']},{$vsets['1']},{$vpoints['1']})";
    $resx = sql_query($strsql, $dbi);
    if ($resx != 1) {
        echo "<font color=red>Event: {$eventid} Match: {$mkey} Creation failed ...cannot assign teams...</font><br>";
        return -1;
    }
    # finally we create the number of required SINGLE and pairs GAME records ...
    # read from config ==> use global event ARRAY ??????????
    # $resx=sql_query("select e.evsingles,e.evdoubles,e.evsgllegs,e.evdbllegs from tblevent e where e.id=$eventid",$dbi);
    # $row=sql_fetch_array($resx,$dbi);
    $iSingle = $event['evsingles'];
    $iPair = $event['evdoubles'];
    $iLegSingle = $event['evsgllegs'];
    $iLegPair = $event['evdbllegs'];
    # for every single we create 1 game entry and ?? legentries ....
    for ($i = 1; $i <= $iSingle; $i++) {
        $strsql = "INSERT INTO tblgame(gid,gmkey,gtype,gsets,glegs,gstatus) values (0,\"{$mkey}\",1,1,{$iLegSingle},0)";
        $resx = sql_query($strsql, $dbi);
    }
    for ($i = 1; $i <= $iPair; $i++) {
        $strsql = "INSERT INTO tblgame(gid,gmkey,gtype,gsets,glegs,gstatus) values (0,\"{$mkey}\",2,1,{$iLegPair},0)";
        $resx = sql_query($strsql, $dbi);
    }
    if ($resx != 1) {
        echo "<font color=red>Event: {$eventid} Match: {$mkey} Creation failed ...cannot create GAMES...</font><br>";
        return -1;
    }
    # // the gameentries are done lets create some fake tblgameplayer entries
    # // gpid | gpgid | gppid | gpsetwon | gplegswon
    # // ver 3.17 storing the teamID in the tblgameplayer entry (used for the WO functionality)
    $presult = sql_query("select gid,gtype from tblgame where gmkey=\"{$mkey}\" order by gid asc", $dbi);
    while (list($gid, $gtype) = sql_fetch_row($presult, $dbi)) {
        $i = 0;
        # // it type = 1 single then 2 entries, for type=2 pairs create 4 entries
        $thisTeam = 0;
        for ($i = 0; $i < $gtype * 2; $i++) {
            if ($gtype == 1) {
                if ($i == 0) {
                    $thisTeam = $vtid[0];
                }
                if ($i == 1) {
                    $thisTeam = $vtid[1];
                }
            } elseif ($gtype == 2) {
                if ($i < 2) {
                    $thisTeam = $vtid[0];
                }
                if ($i > 1) {
                    $thisTeam = $vtid[1];
                }
            }
            $resx = sql_query("INSERT into tblgameplayer(gpid,gpgid,gppid,gpsetwon,gplegswon,gptid) values(0,{$gid},0,0,0,{$thisTeam})", $dbi);
            # // we leave the tid entry empty here - this is filled when the player is assigned ...
            if ($resx != 1) {
                echo "<font color=red>Event: {$eventid} Match: {$mkey} Creation failed ...cannot assign players to games ...</font><br>";
                return -1;
            }
        }
    }
    dsolog(1, $usertoken['uname'], "Match {$mkey} initialised");
}
Example #4
0
/**
*	purpose:	return a Complete Game as Table to be included into the MatchSheet DIV
* 				renders both single or pairs depending on the gtype
* 				parts of this code are similar/identical to the generation of the MatchSheet in ls_system.php
* 	params:		$GameID,$eventID
*	returns:	HTML TABLE of GameRecord
*/
function _getGameTable($GameID, $eventID)
{
    global $dbi, $usertoken;
    $event = reteventconfig($eventID);
    $editmode = 1;
    $matchdate = '';
    $RSG = DB_listGameTeams($dbi, $GameID);
    #mid,mkey,mdate,mtid,mthome,T.id,T.tname,gid,gtype,gstatus
    $matchdate = $RSG[0][2];
    $hometeam = $RSG[0][5];
    $awayteam = $RSG[1][5];
    if ($RSG[0][8] == 1) {
        # this is a singles GAME ....
        # Att: the correct order of HOME-AWAY relies on the sequence of the game-player records
        $precord = sql_query('select G.gid,G.gmkey,G.gtype,G.gstatus,GP.gpid,GP.gppid,P.pfname,P.plname' . ' FROM tblgame G,tblgameplayer GP left join tplayer P on GP.gppid=P.pid' . ' WHERE G.gid=GP.gpgid and G.gid=' . $GameID . ' AND G.gtype=1 ORDER by G.gid,GP.gpid', $dbi);
        $lastgameid = 0;
        while (list($gid, $gmkey, $gtype, $gstatus, $gpid, $gppid, $pfname, $plname) = sql_fetch_row($precord, $dbi)) {
            if ($lastgameid != $gid) {
                $PH = array($gid, $gmkey, $gtype, $gstatus, $gpid, $gppid, $pfname, $plname, $hometeam);
            } else {
                $PA = array($gid, $gmkey, $gtype, $gstatus, $gpid, $gppid, $pfname, $plname, $awayteam);
                echo _LS_renderSingleGameRow($event, $editmode, $matchdate, $PH, $PA);
            }
            $lastgameid = $gid;
        }
        /*
         * end SINGLES 
         */
        return;
    } elseif ($RSG[0][8] == 2) {
        # OK, this is a pairs ....
        $precord = sql_query('select G.gid,G.gmkey,G.gtype,G.gstatus,GP.gpid,GP.gppid,P.pfname,P.plname' . ' FROM tblgame G,tblgameplayer GP left join tplayer P on GP.gppid=P.pid' . ' WHERE G.gid=GP.gpgid and G.gid=' . $GameID . ' AND G.gtype=2 ORDER by G.gid,GP.gpid', $dbi);
        while (list($gid, $gmkey, $gtype, $gstatus, $gpid, $gppid, $pfname, $plname) = sql_fetch_row($precord, $dbi)) {
            $aThisGame[] = array($gid, $gmkey, $gtype, $gstatus, $gpid, $gppid, $pfname, $plname);
        }
        $aThisGame[0][8] = $hometeam;
        $aThisGame[1][8] = $hometeam;
        $aThisGame[2][8] = $awayteam;
        $aThisGame[3][8] = $awayteam;
        echo _LS_renderPairsGameRow($event, $editmode, $matchdate, $aThisGame);
        /*
         * END PAIRS
         */
        return;
    } else {
        echo 'This Game Type is not supported ...';
        return;
    }
}
Example #5
0
/**
*	purpose	sum up the stored leg/game results an render Summary Box
*	params		matchkey
*	returns		summary box to be placed into DIV on matchSheet
*/
function _summaryBox($match_key)
{
    global $dbi, $usertoken, $aMkey;
    /*
     * get the accumulatedGame/Leg/results from the DB and try to determine the status
     * GP.gptid,GP.gppid,GP.gpsetswon,GP.gplegswon,G.gid,M.mid,M.mkey
     * order is by team / Game thus we can filter the pairs which are stored twice
     * pass all values to the _LS_renderSaveMatchBox function
     * all Accounts(Verein) do not feature the status selector ...
     */
    if ($usertoken['usertype_id'] == 2) {
        $LS_LEVEL = 1;
    } else {
        $LS_LEVEL = 2;
    }
    $event = reteventconfig($aMkey['event']);
    $RS = DB_getMatchGameResults($dbi, $match_key);
    $sH = 0;
    $lH = 0;
    $sA = 0;
    $lA = 0;
    $lastgame = 0;
    foreach ($RS as $rec) {
        if ($lastgame != $rec[4]) {
            if ($rec[0] == $aMkey['home']) {
                $sH += $rec[2];
                $lH += $rec[3];
            } elseif ($rec[0] == $aMkey['away']) {
                $sA += $rec[2];
                $lA += $rec[3];
            }
        }
        $lastgame = $rec[4];
    }
    /*
     * now we try to determine a sensible status
     */
    if ($lH + $lA == 0) {
        $mstat = 0;
    } else {
        $mstat = 2;
    }
    return _LS_renderSaveMatchBox($LS_LEVEL, $sH, $sA, $lH, $lA, $mstat);
}