示例#1
0
文件: Team.php 项目: xJakub/LCE
 static function isAdmin($username = null)
 {
     if ($username === null) {
         $username = TwitterAuth::getUserName();
     }
     return Team::isSuperAdmin() || !!Team::findOne('lower(username) = ? and isadmin', [strtolower($username)]);
 }
示例#2
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>
            <?
        }

    }
示例#3
0
 /**
  * @return void
  */
 public function show()
 {
     if (!Team::isSuperAdmin()) {
         HTMLResponse::exitWithRoute('/');
     }
     ?>
     <div class="inblock" style="text-align: left; margin: 0 auto">
         <ul>
             <li><a href="/admin/comunicados/">Enviar comunicados (a través de Twitter)</a></li>
             <li><a href="/admin/equipos/">Administrar equipos</a></li>
             <li><a href="/admin/temporadas/">Administrar temporadas</a></li>
         </ul>
     </div>
     <?
 }
示例#4
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>
        <?
    }
示例#5
0
文件: Team_Index.php 项目: xJakub/LCE
    private function showTeamSeasons()
    {
        $teamSeasonIds = Model::pluck(SeasonTeam::find('teamid = ?', [$this->team->teamid]), 'seasonid');
        $teamSeasons = Season::getMultiple($teamSeasonIds);
        Model::orderBy($teamSeasons, 'seasonid');

        $teamMatches = Match::find('team1id = ? or team2id = ?', [$this->team->teamid, $this->team->teamid]);
        // $games = [];
        $playedGames = [];
        $wins = [];
        $losses = [];

        foreach($teamMatches as $match) {
            if (!$match->isPublished()) continue;
            // $games[$match->seasonid]++;
            if ($match->getWinner() == $this->team->teamid) {
                $playedGames[$match->seasonid]++;
                $wins[$match->seasonid]++;
            }
            if ($match->getLooser() == $this->team->teamid) {
                $playedGames[$match->seasonid]++;
                $losses[$match->seasonid]++;
            }
        }

        ?>
        <h2>Actividad por temporadas</h2>

        <table style="width: 400px">
        <thead><tr>
            <td>Nombre</td>
            <td>Combates</td>
            <td>Victorias</td>
            <td>Derrotas</td>
        </tr></thead>
        <?
        foreach($teamSeasons as $season) {
            if (!$season->ispublic && !Team::isSuperAdmin()) continue;
            ?>
            <tr>
                <td>
                    <a href="/<?=$season->getLink()?>/equipos/<?=$this->team->getLink()?>/">
                        <?= htmlentities($season->name) ?>
                    </a>
                </td>
                <td><?= $playedGames[$season->seasonid] * 1 ?></td>
                <td><?= $wins[$season->seasonid] * 1 ?></td>
                <td><?= $losses[$season->seasonid] * 1 ?></td>
            </tr>
            <?
        }
        ?></table><br><?

    }
示例#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
    public function showBody()
    {
        ?>
        <div id="main" class="public">
            <div class="content">
                <div class="banner"></div>
                <div class="nav" style="text-align: left">
                    <?php
                    foreach ($this->topMenu as $arr) {
                        list($link, $label, $re) = $arr;
                        $status = '';
                        if (preg_match("'^$re$'", HTMLResponse::getRoute())) {
                            $status = 'selected';
                        }

                        ?><a href="<?= $link ?>" class="<?= $status ?>"><?= $label ?></a><?php }
                    ?>
                    <div style="float: right">
                        <select name="season" id="navSeason">
                            <?php
                            $seasons = Team::isSuperAdmin() ?
                                Season::find('1=1') :
                                Season::find('ispublic');
                            foreach($seasons as $season) {
                                $selected = $season->seasonid == $this->season->seasonid ? 'selected' : '';
                                ?>
                                <option value="<?=$season->getLink()?>" <?=$selected?>>
                                    <?=htmlentities($season->name)?>
                                </option>
                            <? } ?>
                        </select>
                    </div>
                </div>
                <div style="padding: 6px">
                    <?php if (TwitterAuth::isLogged()) { ?>
                        Estás identificado como <?=htmlentities(TwitterAuth::getUserName())?>. <a href="<?=HTMLResponse::getRoute()?>?logout=1">Cerrar sesión</a>
                        <?php if (Team::isMember()) {
                            ?>/ <a href="/votaciones/">Votaciones</a><?php
                        } ?>
                        <?php if (Team::isSuperAdmin()) {
                            ?>/ <a href="/admin/">Panel de admin</a><?php
                        } ?>
                        <br>
                        <?php
                        if (TwitterAuth::isBot()) {
                            $botConfig = TwitterAuth::getBotConfig();
                            ?>
                            <br>Eres la cuenta oficial de la LCE, haz <a href="/?authenticatebot=1">click aquí</a> para autorizar esta web a usarte como un bot.<br>
                            <b>Última autorización:</b> <?= isset($botConfig['dateline'])
                                ? date('Y/m/d H:i:s', $botConfig['dateline'])
                                : 'Nunca' ?>
                            <?php
                        }
                        ?>
                    <?php } else { ?>
                        No estás identificado. <a href="<?=HTMLResponse::getRoute()?>?authenticate=1">Iniciar sesión</a><br>
                    <?php } ?>
                </div>

                <div class="title">
                    <?= $this->section->getSubtitle() ?>
                </div>

                <?=$this->contents?>
            </div>
        </div>
        <?php
    }
示例#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', '');

        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>
        <?
    }
示例#10
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><?
    }