All checks were successful
		
		
	
	Build and push / Pulling repo on server (push) Successful in 2s
				
		
			
				
	
	
		
			180 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			180 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
class Runs extends Page {
 | 
						|
 | 
						|
    function setMenu()
 | 
						|
    {
 | 
						|
        // $this->menu_text = 'Läufe';
 | 
						|
        // $this->menu_image = 'fas fa-running';
 | 
						|
        // $this->menu_priority = 3;
 | 
						|
    }
 | 
						|
 | 
						|
    function overview()
 | 
						|
    {
 | 
						|
        $run = new Run();
 | 
						|
        $rid = $this->params[0];
 | 
						|
        if(!$run->exists($rid))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Dieser Lauf existiert nicht']);
 | 
						|
        $run->load($rid);
 | 
						|
        $t = new Tournament();
 | 
						|
        $t->load($run->data['tournament']);
 | 
						|
 | 
						|
        $this->set('admin',$t->amIAdmin());
 | 
						|
        $this->set('tournament', $t->data);
 | 
						|
        $this->set('tournament_id', $run->data['tournament']);
 | 
						|
        $this->set('run', $run->data);
 | 
						|
        $this->set('run_id', $rid);
 | 
						|
        $this->set('template', 'run.html');
 | 
						|
    }
 | 
						|
 | 
						|
    function addresults()
 | 
						|
    {
 | 
						|
        $rid = $this->params[0];
 | 
						|
        $run = new Run();
 | 
						|
        if(!$run->exists($rid))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Dieser Lauf existiert nicht']);
 | 
						|
        $run->load($rid);
 | 
						|
        $t = new Tournament();
 | 
						|
        $tid = $run->data['tournament'];
 | 
						|
        $t->load($tid);
 | 
						|
        if(!$t->amIAdmin() && !$t->isMyEvent($tid))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Du bist in diesem Turnier nicht angemeldet']);
 | 
						|
        else
 | 
						|
        {
 | 
						|
            $this->set('tournament', $t->data);
 | 
						|
            $this->set('tournament_id', $tid);
 | 
						|
            $this->set('run', $run->data);
 | 
						|
            $this->set('run_id', $rid);
 | 
						|
            $this->set('template', 'edit_result.html');
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    function validateResults()
 | 
						|
    {
 | 
						|
        $rid = $_REQUEST['run_id'];
 | 
						|
        $run = new Run();
 | 
						|
        if(!$run->exists($rid))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Dieser Lauf existiert nicht']);
 | 
						|
        $run->load($rid);
 | 
						|
        $t = new Tournament();
 | 
						|
        $tid = $run->data['tournament'];
 | 
						|
        $t->load($tid);
 | 
						|
        if(!$t->amIAdmin() && !$t->isMyEvent($tid))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Du bist in diesem Turnier nicht angemeldet']);
 | 
						|
        else
 | 
						|
        {
 | 
						|
            $run->data['results'] = [];
 | 
						|
            $run->data['results']['time'] = $_REQUEST['time'];
 | 
						|
            $run->data['results']['penalty'] = $_REQUEST['penalty'];
 | 
						|
            $run->data['results']['disq'] = $_REQUEST['disq'];
 | 
						|
            $run->data['results']['comment'] = $_REQUEST['comment'];
 | 
						|
            $run->data['results']['referee'] = $_REQUEST['referee'];
 | 
						|
            $run->data['results']['judge'] = $_REQUEST['judge'];
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    function add()
 | 
						|
    {
 | 
						|
        $tournament = $this->params[0];
 | 
						|
        $t = new Tournament();
 | 
						|
        if(!$t->exists($tournament))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Dieses Turnier existiert nicht']);
 | 
						|
        $t->load($tournament);
 | 
						|
        if(!$t->amIAdmin($tournament))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Du bist kein Admin dieses Turniers']);
 | 
						|
        else
 | 
						|
        {
 | 
						|
            $this->set('tournament', $t->data);
 | 
						|
            $this->set('tournament_id', $tournament);
 | 
						|
            $this->set('template', 'edit_run.html');
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    function edit()
 | 
						|
    {
 | 
						|
        $rid = $this->params[0];
 | 
						|
        $r = new Run();
 | 
						|
        $t = new Tournament();
 | 
						|
        if(!$r->exists($rid))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Dieser Run existiert nicht']);
 | 
						|
        $r->load($rid);
 | 
						|
        $tournament = $r->data['tournament'];
 | 
						|
        $t->load($tournament);
 | 
						|
        if(!$t->amIAdmin($tournament))
 | 
						|
            return partial('error.html', ['errorMessage' => 'Du bist kein Admin dieses Turniers']);
 | 
						|
        else
 | 
						|
        {
 | 
						|
            $this->set('tournament', $t->data);
 | 
						|
            $this->set('tournament_id', $tournament);
 | 
						|
            $this->set('run_id',$rid);
 | 
						|
            $this->set('run',$r->data);
 | 
						|
            $this->set('template', 'edit_run.html');
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    function validate()
 | 
						|
    {
 | 
						|
        
 | 
						|
        if($_REQUEST['submit'])
 | 
						|
        {
 | 
						|
            $t = new Tournament();
 | 
						|
            
 | 
						|
            if(!$t->exists($_REQUEST['tournament_id']))
 | 
						|
                return partial('error.html', ['errorMessage' => 'Dieses Turnier existiert nicht']);
 | 
						|
            $t->load($_REQUEST['tournament_id']);
 | 
						|
            
 | 
						|
            if(!$t->amIAdmin($_REQUEST['tournament_id']))
 | 
						|
                return partial('error.html', ['errorMessage' => 'Du bist kein Admin dieses Turniers']);
 | 
						|
                
 | 
						|
            $run = new Run();
 | 
						|
            if($_REQUEST['run_id'])
 | 
						|
            {
 | 
						|
                if(!$run->exists($_REQUEST['run_id']))
 | 
						|
                    return partial('error.html', ['errorMessage' => 'Dieser Lauf existiert nicht']);
 | 
						|
                $run->load($_REQUEST['run_id']);
 | 
						|
                if(!$run->data['tournament']==$t->id)
 | 
						|
                    return partial('error.html', ['errorMessage' => 'Dieser Lauf gehört nicht zu diesem Turnier']);
 | 
						|
            }
 | 
						|
            else
 | 
						|
                $run->id = gen_ulid();
 | 
						|
 | 
						|
            
 | 
						|
    
 | 
						|
            $run->data['tournament'] = $_REQUEST['tournament_id'];
 | 
						|
            $run->data['name'] = trim($_REQUEST['name']);
 | 
						|
            $run->data['category'] = $_REQUEST['category'];
 | 
						|
            $run->data['length'] = $_REQUEST['length'];
 | 
						|
            $run->data['time_standard'] = $_REQUEST['time_standard'];
 | 
						|
            $run->data['time_max'] = $_REQUEST['time_max'];
 | 
						|
            $run->data['referee'] = $_REQUEST['referee'];
 | 
						|
 | 
						|
            try{
 | 
						|
                $runid = $run->save();
 | 
						|
            }
 | 
						|
            catch(Exception $e)
 | 
						|
            {
 | 
						|
                return partial('error.html', ['errorMessage' => 'Fehler beim Speichern des Laufs: '.$e->getMessage()]);
 | 
						|
            }
 | 
						|
 | 
						|
            if(!in_array($runid, $t->data['runs']))
 | 
						|
            {
 | 
						|
                $t->data['runs'][] = $runid;
 | 
						|
                $t->save();
 | 
						|
            }
 | 
						|
 | 
						|
            if($_REQUEST['submit']=='forward')
 | 
						|
            {
 | 
						|
                $this->redirect('/runs/addresults/'.$runid);
 | 
						|
            }
 | 
						|
            else
 | 
						|
                $this->redirect('/tournaments/event/'.$t->id);
 | 
						|
        }
 | 
						|
        else return partial('error.html', ['errorMessage' => 'Fehler beim Speichern des Laufs']);
 | 
						|
    }
 | 
						|
 | 
						|
    function maySeeThisPage() {
 | 
						|
        if($_SESSION['user']) //wenn eingeloggt, kein problem
 | 
						|
            return true;
 | 
						|
        else return false;
 | 
						|
    }
 | 
						|
} |