예제 #1
0
파일: Rules.php 프로젝트: xJakub/LCE
    /**
     * @return void
     */
    public function show()
    {
        $editing = false;

        if (Team::isSuperAdmin()) {
            $editing = HTMLResponse::fromGET('edit', '');
            if (!$editing) {
                ?>
                <a href="<?=HTMLResponse::getRoute()?>?edit=1">
                    Editar página
                </a>
            <? } else { ?>
                <a href="<?=HTMLResponse::getRoute()?>" onclick="return confirm('Quieres descartar los cambios?')">
                    Descartar y volver a la página
                </a>
            <? } ?>
            <div style="height: 6px"></div>
            <?
        }

        $content = Setting::getKey('rules_content');

        if (!$editing) {
            ?><div class="inblock" style="margin: 0 auto; max-width: 90%; text-align: justify">
                <?=$content?>
            </div><?
        }
        else {

            if (!$csrf = $_SESSION['csrf']) {
                $_SESSION['csrf'] = $csrf = rand(1, 1000000);
            }

            if (HTMLResponse::fromGETorPOST('csrf', '') == $csrf) {
                $content = HTMLResponse::fromPOST('content');
                Setting::setKey('rules_content', $content);
                HTMLResponse::exitWithRoute(HTMLResponse::getRoute());
            }

            $this->design->addJavaScript('//cdn.ckeditor.com/4.5.7/full/ckeditor.js');
            $this->design->addJavaScript("
                CKEDITOR.replace( 'editor' )
            ", false);
            ?>
            <form action="<?=HTMLResponse::getRoute()?>?edit=1" method="post">
                <div style="width:90%; margin: 0 auto">
                    <textarea name="content" id="editor"><?=htmlentities($content)?></textarea>
                </div>
                <br>
                <input type="hidden" name="csrf" value="<?=$csrf?>">
                <button type="submit">Guardar cambios</button>
            </form>
            <?
        }

    }
예제 #2
0
파일: Admin_Team.php 프로젝트: xJakub/LCE
    /**
     * @return void
     */
    public function show()
    {
        if (!Team::isSuperAdmin()) {
            HTMLResponse::exitWithRoute('/');
        }

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000);
        }
        $postCsrf = HTMLResponse::fromPOST('csrf', '');

        $disabled = '';
        /*
        if (Team::isSuperAdmin($this->team->username) && $this->team->username != TwitterAuth::getUserName()) {
            $disabled = 'disabled';
        }
        */

        if ($postCsrf == $csrf) {
            $this->team->name = HTMLResponse::fromPOST('name', $this->team->name);
            if ($_FILES['avatar']['tmp_name']) {
                $con = file_get_contents($_FILES['avatar']['tmp_name']);
                file_put_contents($this->team->getImageLink(), $con);
                $this->team->clearImageCache();
            }
            $this->team->ismember = !!HTMLResponse::fromPOST("ismember", 0);
            $this->team->ispublic = !!HTMLResponse::fromPOST("ispublic", 0);
            $this->team->isadmin = !!HTMLResponse::fromPOST("isadmin", 0);
            $this->team->save();
        }

        ?>
        <div class="inblock middle" style="margin-right: 16px">
            <a target="_blank" href="/<?=$this->team->getImageLink()?>">
                <img src="/<?=$this->team->getImageLink(300, 200)?>?<?=time()?>" alt="Logo" class="teamlogo"><br>
            </a>
            <a target="_blank" href="/equipos/<?=$this->team->getLink()?>/">
                Ver página del equipo<br>
            </a>
        </div>
        <div class="inblock middle">
            <form enctype="multipart/form-data" action="<?=HTMLResponse::getRoute()?>" method="post">
                <table style="width:512px; margin: 0 auto; text-align: left">
                    <thead>
                    <tr style="text-align: center">
                        <td>
                            Propiedad
                        </td>
                        <td>
                            Valor
                        </td>
                    </tr>
                    </thead>
                    <tr>
                        <td>
                            <b>Usuario en Twitter</b>
                        </td><td>
                            <input disabled value="<?=htmlentities($this->team->username)?>">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Nombre del equipo</b>
                        </td><td>
                            <input name="name" value="<?=htmlentities($this->team->name)?>">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Nuevo avatar</b>
                        </td><td>
                            <input name="avatar" type="file">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Opciones</b>
                        </td><td>
                            <input type="checkbox" name="ispublic" <?=$this->team->ispublic?'checked':''?> <?=$disabled?>>
                            Visible<br>

                            <input type="checkbox" name="ismember" <?=$this->team->ismember?'checked':''?> <?=$disabled?>>
                            Miembro<br>

                            <input type="checkbox" name="isadmin" <?=$this->team->isadmin?'checked':''?> <?=$disabled?>>
                            Admin<br>
                        </td>
                    </tr>
                </table>
                <input type="hidden" name="csrf" value="<?= $csrf ?>"><br>
                <button type="submit">Guardar cambios</button><br><br>
            </form>
        </div>
        <?
    }
예제 #3
0
파일: Team_Index.php 프로젝트: xJakub/LCE
    private function showFriendlyMatches() {
        $csrf = $_SESSION['csrf'];
        $opponents = Model::indexBy($this->season->getTeams(), 'teamid');

        $postCsrf = HTMLResponse::fromPOST('friendlycsrf', '');

        if ($postCsrf == $csrf && $this->team->isManager()) {
            $url = HTMLResponse::fromPOST('friendlyurl');
            $opponentsId = HTMLResponse::fromPOST('friendlyopponentsid');
            $publishDate = HTMLResponse::fromPOST('friendlydate');
            $publishTime = HTMLResponse::fromPOST('friendlytime');

            if (!strlen($publishDate)) $publishDate = date('Y-m-d');
            if (!strlen($publishTime)) $publishTime = date('H').':00';

            $possibleOpponents = Model::pluck($this->season->getTeams(), 'teamid');

            $regex = '/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/';
            $timeRegex = "'^[0-9]{2}:[0-9]{2}$'";
            $dateRegex = "'^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}$'";

            $removeId = HTMLResponse::fromPOST('removeid');
            if ($removeId) {
                /** @var Video $video */
                if ($video = Video::findOne('seasonid = ? and type = ? and videoid = ? and teamid = ?',
                    [$this->season->seasonid, 3, $removeId, $this->team->teamid])) {
                    $video->delete();
                    HTMLResponse::exitWithRoute(HTMLResponse::getRoute());
                }
            }

            if (!strlen($opponentsId) || !strlen($publishTime) || !strlen($publishDate) || !strlen($url)) {
                $this->design->addJavaScript("
                    $(function() { alert(\"No has rellenado todos los datos\"); })
                ", false);
            } else {
                if ($opponentsId != $this->team->teamid && in_array($opponentsId, $possibleOpponents)) {
                    if (!preg_match($regex, $url)) {
                        $this->design->addJavaScript("
                    $(function() { alert(\"El enlace que has puesto no es un enlace de YouTube válido\"); })
                ", false);
                    } else {
                        if (!preg_match($timeRegex, $publishTime)) {
                            $this->design->addJavaScript("
                    $(function() { alert(\"La hora que has puesto tiene un formato inválido (ha de ser 08:06)\"); })
                ", false);
                        } else {
                            if (!preg_match($dateRegex, $publishDate)) {
                                $this->design->addJavaScript("
                    $(function() { alert(\"La fecha que has puesto tiene un formato inválido (ha de ser 2099-12-31)\"); })
                ", false);
                            } else {
                                $video = Video::create();
                                $video->dateline = time();
                                $video->publishdate = $publishDate;
                                $video->publishtime = $publishTime;
                                $video->link = $url;
                                $video->opponentid = $opponentsId * 1;
                                $video->teamid = $this->team->teamid;
                                $video->type = 3;
                                $video->seasonid = $this->season->seasonid;
                                $video->save();
                                HTMLResponse::exitWithRoute(HTMLResponse::getRoute());
                            }
                        }
                    }
                }
            }
        }

        $videos = Video::find('seasonid = ? and teamid = ? and type = ? order by publishdate asc, publishtime asc',
            [$this->season->seasonid, $this->team->teamid, 3]);

        if ($videos || $this->team->isManager()) {
            ?>
            <h2>Combates amistosos</h2>
            <? if ($this->team->isManager()) { ?>
                <form action="<?=HTMLResponse::getRoute()?>" method="post">
            <? } ?>
            <table>
                <thead>
                <tr>
                    <td>Fecha</td>
                    <td>Hora</td>
                    <td>Oponentes</td>
                    <td>Vídeo</td>
                </tr>
                </thead>
                <? foreach($videos as $video) {
                    if (!$this->team->isManager() &&
                        ($video->publishdate > date('Y-m-d') ||
                            ($video->publishdate == date('Y-m-d') && $video->publishtime > date('H:i')))) {
                        continue;
                    }
                    ?>
                    <tr>
                        <td><?= $video->publishdate ?></td>
                        <td><?= $video->publishtime ?></td>
                        <td>
                            <a href="/<?=$this->season->getLink()?>/equipos/<?=$opponents[$video->opponentid]->getLink()?>/">
                                <?= htmlentities($opponents[$video->opponentid]->name) ?>
                            </a>
                        </td>
                        <td>
                            <a href="<?=htmlentities($video->link)?>" target="_blank">
                                Ver combate
                            </a>
                            <? if ($this->team->isManager()) { ?>
                                <a style="font-size: 10px" href="javascript:void(0)" onclick="removeFriendlyVideo(this, <?=$video->videoid?>)">
                                    (Quitar)
                                </a>
                            <? } ?>
                        </td>
                    </tr>
                <? } ?>
                <? if ($this->team->isManager()) { ?>
                    <tr>
                        <td>
                            <input type="date" name="friendlydate" placeholder="<?=date('Y-m-d')?>" style="width:80px">
                        </td>
                        <td>
                            <input name="friendlytime" placeholder="<?=date('H:i')?>" style="width: 64px">
                        </td>
                        <td>
                            <select name="friendlyopponentsid">
                                <option value="">-- Elige oponentes --</option>
                                <?
                                foreach($this->season->getTeams() as $team) {
                                    if ($team->teamid == $this->team->teamid) continue;
                                    ?>
                                    <option value="<?=$team->teamid?>">
                                        <?= htmlentities($team->name) ?>
                                    </option>
                                    <?
                                }
                                ?>
                            </select>
                        </td>
                        <td>
                            <input name="friendlyurl" placeholder="http://youtube.com/..." style="width:200px">
                        </td>
                    </tr>
                <? } ?>
            </table>
            <? if ($this->team->isManager()) { ?>
                <div style="height: 6px"></div>
                <button type="submit">Añadir amostoso</button>
                <input type="hidden" name="friendlycsrf" value="<?=$csrf?>">
                <input type="hidden" name="removeid" value="">
                </form>
            <? }
        }
    }
예제 #4
0
파일: AddPoll.php 프로젝트: xJakub/LCE
    /**
     * @return void
     */
    public function show()
    {
        if (!TwitterAuth::isLogged()) {
            ?>
            Sólo los administradores pueden ver esta página.
            <a href="<?=HTMLResponse::getRoute()?>?authenticate=1">
                Inicia sesión.
            </a><br>
            <?
            return;
        }
        else if (!Team::isAdmin()) {
            ?>
            Sólo los administradores pueden ver esta página.<br>
            <?
            return;
        }
        else {
            $title = trim(HTMLResponse::fromPOST('title', ''));
            $description = trim(HTMLResponse::fromPOST('description', ''));
            $options = [];
            for ($i=1; $i<6; $i++) {
                $value = trim(HTMLResponse::fromPOST('option'.$i, ''));
                if (strlen($value)) {
                    $options[] = $value;
                }
            }

            if (strlen($title) && count($options)>=2) {
                $poll = Poll::create();
                $poll->title = $title;
                $poll->description = $description;
                $poll->isvisible = true;
                $poll->isopen = true;
                $poll->username = TwitterAuth::getUserName();
                $poll->userid = TwitterAuth::getUserId();
                $poll->dateline = time();
                $poll->avatar = TwitterAuth::getAvatar();
                $poll->save();

                foreach($options as $index => $option) {
                    $pollOption = PollOption::create();
                    $pollOption->pollid = $poll->pollid;
                    $pollOption->userid = TwitterAuth::getUserId();
                    $pollOption->username = TwitterAuth::getUserName();
                    $pollOption->title = $option;
                    $pollOption->save();
                }

                HTMLResponse::exitWithRoute("/votaciones/{$poll->pollid}/");
            }

            ?>
            <form action="<?=HTMLResponse::getRoute()?>" method="post">
                <div style="padding:3px">
                    <div class="inblock middle" style="width:120px">
                        Título
                    </div>
                    <input name="title" value="<?=htmlentities($title)?>">
                </div>

                <div style="padding:3px">
                    <div class="inblock middle" style="width:120px">
                        Descripción
                    </div>
                    <input name="description" value="<?=htmlentities($description)?>">
                </div>

                <?
                for ($i=1; $i<=6; $i++) {
                    ?>
                    <div style="padding:3px">
                        <div class="inblock middle" style="width:120px">
                            Opción <?=$i?>
                        </div>
                        <input name="option<?=$i?>" value="<?=htmlentities($options[$i-1])?>">
                    </div>
                    <?
                }
                ?>

                <div style="padding:3px">
                    <div class="inblock middle" style="width:120px">

                    </div>
                    <input type="submit" value="Crear votación">
                </div>
            </form>
            <?


        }
    }
예제 #5
0
파일: Season_Index.php 프로젝트: xJakub/LCE
    /**
     * @return void
     */
    public function show()
    {
        $week = $this->week;
        $canVote = $this->canVote;

        $publishTime = $this->season->getPublishTimeForWeek($week);

        if ($publishTime >= 1000) {

            $days = explode(',', 'Domingo,Lunes,Martes,Miércoles,Jueves,Viernes,Sábado');
            $months = explode(',', 'enero,febrero,marzo,abril,mayo,junio,julio,agosto,septiembre,octubre,noviembre,diciembre')

            ?>
            <div>
                <?= $days[date('w', $publishTime)] ?>
                <?= date('j', $publishTime)?> de <?= $months[date('m', $publishTime)-1] ?> de <?= date('Y', $publishTime) ?>,
                <?= date('H:i', $publishTime) ?> (hora española)
            </div>
        <? } ?>
        <div style="height: 6px"></div>
        <table style="border: 0; padding: 0; margin: 0; width: 100%">
            <tr>
                <td style="width: 150px; border: 0; padding: 0; margin: 0; text-align: left">
                    <?
                    if ($this->week > 1) {
                        ?>
                        <a style="float:left; margin-left: 24px" href="/<?=$this->season->getLink()?>/jornadas/<?=$this->week-1?>/">
                            &lt;&lt;
                            Ver <?= strtolower($this->season->getWeekName($this->week-1)) ?>
                        </a>
                        <?
                    }
                    ?>
                </td>
                <td style="border: 0; padding: 0; margin: 0; text-align: center">
                    <?
                    if (time() >= $publishTime) {
                        ?>
                        <a href="javascript:void(0)" onclick="$('._grayscale').toggleClass('grayscale'); $('.result').toggle(); $(this).find('span').toggle()">
                            <span>Mostrar resultados</span>
                            <span style="display: none">Ocultar resultados</span>
                        </a>
                        <?
                    }
                    ?>
                </td>
                <td style="width: 150px; border: 0; padding: 0; margin: 0; text-align: right"><?
                    if ($this->week < $this->maxWeek) {
                        ?>
                        <a style="float:right; margin-right: 24px" href="/<?=$this->season->getLink()?>/jornadas/<?=$this->week+1?>/">
                            Ver <?= strtolower($this->season->getWeekName($this->week+1)) ?>
                            &gt;&gt;
                        </a>
                        <?
                    }
                    ?>
                </td>
            </tr>
        </table>
        <?

        $matches = Match::find('seasonid = ? and week = ? order by matchid asc', [$this->season->seasonid, $week]);
        #shuffle($matches);

        if (!$matches) {
            ?>
            No hay enfrentamientos disponibles en estos momentos.<br><br>
            <?
            return;
        }

        foreach($matches as $match) {
            $team1 = $match->getTeam1();
            $team2 = $match->getTeam2();

            if (false && rand(0,1) == 1) {
                $tmp = $team2;
                $team2 = $team1;
                $team1 = $tmp;
            }


            $voteTeamid = HTMLResponse::fromPOST('teamid','') * 1;
            $voteMatchid = HTMLResponse::fromPOST('matchid','') * 1;
            $voteUnteamid = HTMLResponse::fromPOST('unteamid','') * 1;
            $voteUnmatchid = HTMLResponse::fromPOST('unmatchid','') * 1;

            if ($canVote && TwitterAuth::isLogged() && !$match->hasVoted() && $match->matchid &&
                $voteMatchid == $match->matchid && ($voteTeamid == $team1->teamid || $voteTeamid == $team2->teamid)) {
                $bet = Bet::create();
                $bet->matchid = $match->matchid;
                $bet->dateline = time();
                $bet->userid = TwitterAuth::getUserId();
                $bet->teamid = $voteTeamid;
                $bet->username = TwitterAuth::getUserName();
                $bet->avatar = $_SESSION['twitter-avatar'];
                $bet->save();
            }

            if ($canVote && TwitterAuth::isLogged() && $match->hasVoted() &&
                $voteUnmatchid == $match->matchid && ($voteUnteamid == $team1->teamid || $voteUnteamid == $team2->teamid)) {
                $bet = Bet::findOne('matchid = ? and teamid = ? and userid = ?', array($voteUnmatchid, $voteUnteamid, TwitterAuth::getUserId()));
                $bet->delete();
            }

            $votes = $match->getVotes();
            $votesCount = array_sum($votes);

            $team1votes = 0;
            $team2votes = 0;
            if ($votesCount != 0) {
                $team1votes = $votes[$team1->teamid]*1;
                $team2votes = $votes[$team2->teamid]*1;
            }

            ?>

            <div class="matchbox">
                <? $this->showTeamBox($match, $team1, $team1votes, $votesCount) ?>
                <div class="vsbox">
                    <? if ($match->isPublished() && $match->getWinner()) {
                        $score1 = $team1->teamid==$match->getWinner() ? 6-$match->getLooserKills() : 0;
                        $score2 = $team2->teamid==$match->getWinner() ? 6-$match->getLooserKills() : 0;
                        ?>
                        <div style="font-size:90%; display: none" class="result">
                            <?=$score1?>-<?=$score2?>
                        </div>
                        <?
                    } else if ($match->isPublished() && $match->isDelayed()) { ?>
                        <div style="font-size:90%; display: none" class="result">
                            Apl.
                        </div>
                    <? } ?>
                    VS
                </div>
                <? $this->showTeamBox($match, $team2, $team2votes, $votesCount) ?>
            </div>
            <?
        }
    }
예제 #6
0
    /**
     * @return void
     */
    public function show()
    {
        if (!Team::isSuperAdmin()) {
            HTMLResponse::exitWithRoute('/');
        }
        if (!TwitterAuth::getBotConfig()) {
            ?>Error: el bot no está configurado<br><?
            return;
            }

        if (HTMLResponse::fromPOST('csrf', '') && strlen(trim(HTMLResponse::fromPOST('message','')))) {
            if ($_SESSION['csrf'] != HTMLResponse::fromPOST('csrf', '')) {
                ?>Error: código de seguridad incorrecto.<br><br><?
            }
            else {
                $message = HTMLResponse::fromPOST('message');
                ?>
                <b>Mensaje</b>: <?=htmlentities($message)?><br><br>

<?
                foreach(Team::find('ismember order by username asc') as $team) {
                    $lowname = strtolower($team->username);
                    if (HTMLResponse::fromPOST("check{$lowname}", '')) {
                        $ok = false;

                        $ok = !!TwitterAuth::botSendPrivateMessage($lowname, $message);

                        ?>-<?=$team->username?>:
                        <?= $ok?'Enviado correctamente':'Error en el envío' ?>
                        <br>
                        <?
                    }
                }
                ?><br><br><?
                return;
            }
        }

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000);
        }

        ?><div style="max-width: 640px; margin: 0 auto">
        <form action="<?=HTMLResponse::getRoute()?>" method="post">
            <b>Texto del comunicado (será enviado por MD en Twitter):</b><br>
            <textarea style="width: 320px" name="message"></textarea><br>
            <br>
            <b>Destinatarios del comunicado (
                <a href="javascript:void(0)" onclick="$(this).closest('div').find('input[type=checkbox]').attr('checked','checked')">
                    seleccionar todos
                </a>
                ):</b><br>
            <?
            foreach(Team::find('ismember order by username asc') as $team) {
                $lowname = strtolower($team->username);
                ?>
                <div class="inblock" style="margin: 6px; text-align: left; width: 180px">
                    <div class="inblock middle">
                        <input id="check<?=$lowname?>"type="checkbox" name="check<?=$lowname?>">
                    </div>
                    <div class="inblock middle">
                        <label for="check<?=$lowname?>">
                            <?= $team->username ?><br>
                            <span style="font-style:italic; color: #666">
                                <?= $team->name ?>
                            </span>
                        </label>
                    </div>
                </div>
                <?
            }
            ?></div><br>
            <input type="hidden" name="csrf" value="<?= $csrf ?>">
            <button type="submit">Enviar comunicado</button>
        </form><br><br><?
    }
예제 #7
0
    /**
     * @return void
     */
    public function show()
    {
        if (!Team::isSuperAdmin()) {
            HTMLResponse::exitWithRoute('/');
        }

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000);
        }
        $postCsrf = HTMLResponse::fromPOST('csrf', '');

        $totalWeeks = $this->season->getWeeksCount();
        if ($csrf == $postCsrf) {
            $this->season->mainweeks = HTMLResponse::fromPOST('mainweeks', $this->season->mainweeks);
            $this->season->playoffsweeks = HTMLResponse::fromPOST('playoffsweeks', $this->season->playoffsweeks);
            $this->season->save();
        }

        ?>
        <div class="inblock middle">
        <form action="<?=HTMLResponse::getRoute()?>" method="post">
            <table style="width:640px; margin: 0 auto; text-align: left">
                <thead>
                <tr style="text-align: center">
                    <td>
                        Propiedad
                    </td>
                    <td>
                        Valor
                    </td>
                </tr>
                </thead>
                <tr>
                    <td>
                        <b>Número de jornadas (principales)</b>
                    </td><td>
                        <input name="mainweeks" type="number" value="<?=htmlentities($this->season->mainweeks)?>">
                    </td>
                </tr>
                <tr>
                    <td>
                        <b>Número de jornadas (playoffs)</b>
                    </td><td>
                        <input name="playoffsweeks" type="number" value="<?=htmlentities($this->season->playoffsweeks)?>">
                    </td>
                </tr>
            </table>

            <?
            $teams = $this->season->getTeams(false);
            $maxMatches = ceil(count($teams)/2);

            $matches =
                Model::groupBy(
                    Match::find('seasonid = ? order by week asc, matchid asc', [$this->season->seasonid]),
                    'week'
                );

            if ($csrf == $postCsrf) {
                for ($week=1; $week<=$totalWeeks; $week++) {
                    $name = HTMLResponse::fromPOST("week{$week}name");
                    $date = HTMLResponse::fromPOST("week{$week}date");
                    $this->season->setWeekName($week, $name);
                    $this->season->setWeekDate($week, $date);
                }
                $this->season->save();

                $newMatches = [];
                $oldMatches = [];
                for ($week=1; $week<=$this->season->getWeeksCount(); $week++) {
                    for ($i=0; $i<$maxMatches; $i++) {
                        $team1id = HTMLResponse::fromPOST("week{$week}match{$i}team1id");
                        $team2id = HTMLResponse::fromPOST("week{$week}match{$i}team2id");
                        if ($team1id === null || $team2id === null) continue;

                        $team1id *= 1;
                        $team2id *= 1;

                        if ($team1id && $team2id) {
                            if (isset($matches[$week][$i])) {
                                $match = $matches[$week][$i];
                                $match->team1id = "$team1id";
                                $match->team2id = "$team2id";
                                $oldMatches[] = $match;
                            }
                            else {
                                $match = Match::create();
                                $match->result = 0;
                                $match->week = $week;
                                $match->seasonid = $this->season->seasonid;
                                $match->team1id = $team1id;
                                $match->team2id = $team2id;
                                $newMatches[] = $match;
                            }
                        }
                        else {
                            if (isset($matches[$week][$i])) {
                                $matches[$week][$i]->delete();
                            }
                        }
                    }
                }
                Model::saveAll($newMatches);
                Model::saveAll($oldMatches);

                $matches =
                    Model::groupBy(
                        Match::find('seasonid = ? order by week asc, matchid asc', [$this->season->seasonid]),
                        'week'
                    );
            }


            for ($week=1; $week<=$totalWeeks; $week++) {
                ?>
                <br>
                <table style="width:640px; margin: 0 auto; text-align: left">
                    <thead>
                    <tr>
                        <td colspan="2" style="text-align: center">Jornada Nº<?=$week?></td>
                    </tr>
                    </thead>
                    <tr>
                        <td>
                            <b>Nombre de la jornada</b>
                        </td><td>
                            <input name="week<?=$week?>name" value="<?=htmlentities($this->season->getWeekName($week))?>">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <b>Fecha de publicación</b>
                        </td><td>
                            <input name="week<?=$week?>date" type="date" value="<?=htmlentities($this->season->getWeekDate($week))?>">
                        </td>
                    </tr>
                    <?
                    for ($i=0; $i<$maxMatches; $i++) {
                        ?>
                        <tr>
                            <td>
                                <b>- Enfrentamiento #<?=$i+1?></b>
                            </td>
                            <td>
                                <select name="week<?=$week?>match<?=$i?>team1id">
                                    <option value="0">-- Elige equipo --</option>
                                    <?
                                    foreach($teams as $team) {
                                        $selected = isset($matches[$week][$i])
                                            ? (
                                            $matches[$week][$i]->team1id == $team->teamid
                                                ? 'selected'
                                                : ''
                                            )
                                            : '';
                                        ?>
                                        <option value="<?=$team->teamid?>" <?=$selected?>>
                                            <?=htmlentities($team->name)?>
                                        </option>
                                        <?
                                    }
                                    ?>
                                </select>
                                VS
                                <select name="week<?=$week?>match<?=$i?>team2id">
                                    <option value="0">-- Elige equipo --</option>
                                    <?
                                    foreach($teams as $team) {
                                        $selected = isset($matches[$week][$i])
                                            ? (
                                            $matches[$week][$i]->team2id == $team->teamid
                                                ? 'selected'
                                                : ''
                                            )
                                            : '';
                                        ?>
                                        <option value="<?=$team->teamid?>" <?=$selected?>>
                                            <?=htmlentities($team->name)?>
                                        </option>
                                        <?
                                    }
                                    ?>
                                </select>
                            </td>
                        </tr>
                        <?
                    }
                    ?>
                </table>
                <?
            }
            ?>

            <input type="hidden" name="csrf" value="<?= $csrf ?>"><br>
            <button type="submit">Guardar cambios</button><br><br>

        </form>
        </div><?
    }
예제 #8
0
    /**
     * @return void
     */
    public function show()
    {
        if (!Team::isSuperAdmin()) {
            HTMLResponse::exitWithRoute('/');
        }

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000);
        }
        $postCsrf = HTMLResponse::fromPOST('csrf', '');

        if ($postCsrf == $csrf) {
            $newSeason = Season::create();
            $newSeason->ispublic = false;
            $newSeason->isdefault = false;
            $newSeason->save();
            $newSeason->name = "Temporada {$newSeason->seasonid}";
            $newSeason->save();
        }

        ?>
        <table style="width: 512px; margin: 0 auto">
            <thead>
            <tr>
                <td>#</td>
                <td>Nombre</td>
                <td>Opciones</td>
                <td>Acciones</td>
            </tr>
            </thead>
            <?
            foreach(Season::find('1=1') as $season) {
                ?>
                <tr>
                    <td><?=$season->seasonid?></td>
                    <td><?=htmlentities($season->name)?></td>
                    <td>
                        <?= $season->ispublic ? 'Pública' : 'Oculta' ?>
                        <?= $season->isdefault ? '(por defecto)' : '' ?>
                    </td>
                    <td style="text-align: left">
                        <a href="/admin/temporadas/<?=$season->seasonid?>/">
                            Editar temporada
                        </a><br>
                        <a href="/admin/temporadas/<?=$season->seasonid?>/jornadas/">
                            Editar jornadas
                        </a><br>
                        <a href="/admin/temporadas/<?=$season->seasonid?>/eventos/">
                            Editar eventos
                        </a>
                    </td>
                </tr>
                <?
            }
            ?>
        </table><br>

        <form action="<?=HTMLResponse::getRoute()?>" method="post">
            <input type="hidden" name="csrf" value="<?=$csrf?>">
            <button type="submit">Añadir nueva temporada</button>
        </form><br>
        <?
    }
예제 #9
0
    /**
     * @return void
     */
    public function show()
    {
        if (!Team::isSuperAdmin()) {
            HTMLResponse::exitWithRoute('/');
        }

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000);
        }
        $postCsrf = HTMLResponse::fromPOST('csrf', '');


        $events = $this->season->getEvents();;

        if ($postCsrf == $csrf) {
            $oldEvents = $events;
            $oldEvents[] = ["", "", ""];
            $events = [];

            foreach($oldEvents as $index => $event) {
                $event[0] = HTMLResponse::fromPOST("name{$index}", $event[0]);
                $event[1] = HTMLResponse::fromPOST("date{$index}", $event[0]);
                $event[2] = HTMLResponse::fromPOST("link{$index}", $event[0]);

                if (strlen($event[0])) {
                    $events[] = $event;
                }
            }

            $this->season->setEvents($events);
            $this->season->save();
        }

        $events[] = ["Nuevo evento", "2099-12-31", "http://example.com"];


        ?><div class="inblock middle">
        <form enctype="multipart/form-data" action="<?=HTMLResponse::getRoute()?>" method="post">

            <table style="width: 640px">
                <thead>
                <tr>
                    <td>Nombre</td>
                    <td>Fecha</td>
                    <td>Enlace</td>
                </tr>
                </thead>
                <? foreach($events as $index => $event) {
                    $key = ($index == count($events)-1) ? 'placeholder' : 'value';
                    ?>
                    <tr>
                        <td>
                            <input style="width: 150px" name="name<?=$index?>" <?=$key?>="<?=htmlentities($event[0])?>">
                        </td>
                        <td>
                            <input style="width: 100px" name="date<?=$index?>" type="date" <?=$key?>="<?=htmlentities($event[1])?>">
                        </td>
                        <td>
                            <input style="width: 250px" name="link<?=$index?>" <?=$key?>="<?=htmlentities($event[2])?>">
                        </td>
                    </tr>
                    <?
                } ?>
            </table><br>

            <input type="hidden" name="csrf" value="<?= $csrf ?>">
            <button type="submit">Guardar cambios</button><br><br>

        </form>
        </div><?
    }