Esempio n. 1
0
    public function __construct($seasonId, $requestedWeek = null) {

        $this->season = Season::getByLink($seasonId);
        $this->week = 1;
        $time = time();

        while($this->week < $this->season->getWeeksCount()
            && $this->season->weekIsPublished($this->week)) {
            $this->week++;
        }

        $maxWeekMatch = Match::findOne('seasonid = ? order by week desc limit 1', [$this->season->seasonid]);
        $this->maxWeek = $maxWeekMatch->week;

        if (!Team::isMember()) {
            while (!$this->season->weekIsPublic($this->maxWeek)) {
                $this->maxWeek--;
            }
        }

        if ($requestedWeek && $requestedWeek <= $this->maxWeek) {
            $this->week = $requestedWeek;
        }
        else if ($requestedWeek) {
            HTMLResponse::exitWithRoute("/");
        }

        $this->canVote = ($this->season->getPublishTimeForWeek($this->week) - $time > 3600);
    }
Esempio n. 2
0
File: Index.php Progetto: xJakub/LCE
 /**
  * @return void
  */
 public function show()
 {
     $season = Season::findOne('ispublic order by isdefault desc limit 1');
     if ($season) {
         HTMLResponse::exitWithRoute('/' . $season->getLink() . '/');
     }
 }
Esempio n. 3
0
File: Rules.php Progetto: 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>
            <?
        }

    }
Esempio n. 4
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>
     <?
 }
Esempio n. 5
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', '');

        $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>
        <?
    }
Esempio n. 6
0
    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>
            <? }
        }
    }
Esempio n. 7
0
    /**
     * @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>
            <?


        }
    }
Esempio n. 8
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><?
    }
Esempio n. 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', '');

        $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><?
    }
Esempio n. 10
0
    /**
     * @return void
     */
    public function show()
    {
        if (!TwitterAuth::isLogged()) {
            ?>
            Sólo los miembros pueden ver esta página.
            <a href="<?=HTMLResponse::getRoute()?>?authenticate=1">
                Inicia sesión.
            </a><br>
            <?
            return;
        }
        else {
            if (!Team::isMember()) {
                HTMLResponse::exitWithRoute('/votaciones/');
            }

            $answer = PollVote::findOne('userid = ? and pollid = ?',
                [TwitterAuth::getUserId(), $this->poll->pollid]);

            $options = PollOption::find('pollid = ? order by polloptionid asc', [$this->poll->pollid]);


            if (!$answer && strlen($hash = HTMLResponse::fromGET('hash', ''))) {
                $optionid = HTMLResponse::fromGET('vote');

                foreach($options as $index => $option) {
                    if ($option->polloptionid == $optionid && $option->getHash() == $hash) {
                        $answer = PollVote::create();
                        $answer->userid = TwitterAuth::getUserId();
                        $answer->dateline = time();
                        $answer->avatar = TwitterAuth::getAvatar();
                        $answer->pollid = $this->poll->pollid;
                        $answer->polloptionid = $option->polloptionid;
                        $answer->username = TwitterAuth::getUserName();
                        $answer->save();
                    }
                }
            }

            $answers = Model::groupBy(PollVote::find('pollid = ?', [$this->poll->pollid]), 'polloptionid');

            $hasAnswered = !!$answer;

            ?><div style="text-align:left; margin: 0 auto" class="inblock">
            <table style="width:640px">
                <thead>
                <tr>
                    <td>Lista de opciones</td>
                </tr>
                </thead>
                <?

                foreach($options as $index => $option) {
                    ?>
                    <tr><td class="row" style="text-align: left">
                            <div style="height: 6px"></div>
                            <div class="inblock middle" style="width:320px">
                                <b>Opción <?=$index+1?></b>: <?= htmlentities($option->title) ?>
                            </div>
                            <div class="inblock middle">
                                <div class="moreless inblock middle" style="width: 150px">
                                    <a href="javascript:void(0)" onclick="$(this).closest('.row').find('.moreless').toggle(); $(this).closest('.row').find('.onmore').slideDown(500);">+ Mostrar más</a>
                                </div>
                                <div class="moreless inblock middle" style="width: 150px; display: none">
                                    <a href="javascript:void(0)" onclick="$(this).closest('.row').find('.moreless').toggle(); $(this).closest('.row').find('.onmore').slideUp(400);">- Mostrar menos</a>
                                </div>
                            </div>
                            <div class="inblock middle">
                                <? if (!$hasAnswered) { ?>
                                    <a href="<?=HTMLResponse::getRoute()?>?vote=<?=$option->polloptionid?>&hash=<?=$option->getHash()?>" onclick="return confirm('¿Votas <?=htmlentities($option->title)?>?')">
                                        Votar esta opción
                                    </a>
                                <? } else if ($answer->polloptionid == $option->polloptionid) { ?>
                                    <i>Votaste esta opción</i>
                                <? } ?>
                            </div>
                            <div class="onmore" style="display: none; padding: 12px">
                                <?= $option->description ?>
                            </div>
                            <div style="height: 6px"></div>
                            <?
                            if (!$hasAnswered) {
                                ?><i>Vota primero para ver los resultados</i><?
                            }
                            else {
                                $optionAnswers = $answers[$option->polloptionid];
                                ?>
                                Votado por: <?= $optionAnswers
                                    ? '<b>'.implode(', ', Model::pluck($optionAnswers, 'username')).'</b> ('.count($optionAnswers).' votos)'
                                    : '<i>Nadie</i>'; ?>
                                <?
                            }
                            ?>
                            <div style="height: 6px"></div>
                        </td></tr>
                    <?
                }

                ?></table></div><br><br><?
        }
    }
Esempio n. 11
0
 public static function forceLogin()
 {
     if (!self::isLogged()) {
         if (!self::doLogin()) {
             HTMLResponse::exitWithRoute(self::getAuthorizeURL());
         }
     }
 }
Esempio n. 12
0
    public function __construct(PublicSection $section)
    {
        parent::__construct();

        if (HTMLResponse::fromGET('authenticate')) {
            HTMLResponse::exitWithRoute(TwitterAuth::getAuthorizeURL(HTMLResponse::getRoute()));
        }


        if (HTMLResponse::fromGET('logout')) {
            session_destroy();
            HTMLResponse::exitWithRoute(HTMLResponse::getRoute());
        }

        TwitterAuth::isLogged();

        if (TwitterAuth::isBot()) {
            if (HTMLResponse::fromGET('authenticatebot')) {
                HTMLResponse::exitWithRoute(TwitterAuth::getBotAuthorizeURL(HTMLResponse::getRoute()));
            }
            TwitterAuth::doBotLogin();
        }

        $this->topMenu = array();

        $this->setMeta('charset', 'utf-8');
        $this->setMeta('viewport', 'width=device-width, initial-scale=1.0');
        $this->setTitle($section->getTitle() . ' - ' . $section->getSubtitle());

        $this->addStyleSheet('/css/style.css');

        if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1') {
            $this->addJavaScript("http://localhost/jquery.js", true);
        }
        else {
            $this->addJavaScript("https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js", true);
        }

        $this->addJavaScript("
            $(document).ready(function() {
                if(screen.width <= 512) {
                    document.getElementById('meta-viewport').setAttribute('content','width=512');
                }
            })
        ", false);



        $this->season = null;
        if ($_SESSION['seasonid']) {
            $this->season = Season::get($_SESSION['seasonid']);
        }

        $section->setDesign($this);
        $this->section = $section;

        if ($this->season == null) {
            $this->season = Season::findOne('ispublic order by isdefault desc');
        }
        $seasonLink = $this->season->getLink();

        $this->addToTopMenu("/{$seasonLink}/", 'Enfrentamientos', '/');
        $this->addToTopMenu("/{$seasonLink}/equipos/", 'Equipos', '/equipos/.*');
        $this->addToTopMenu("/{$seasonLink}/calendario/", 'Calendario', '/calendario/');
        $this->addToTopMenu("/{$seasonLink}/clasificacion/", 'Clasificación', '/clasificacion/');
        $this->addToTopMenu("/{$seasonLink}/quiniela/", 'Quiniela', '/quiniela/');

        $this->addToTopMenu('/normas/', 'Normas', '/normas/');

        if (Team::isAdmin()) {
            $this->addToTopMenu('/unete/', '¡Únete!', '/unete/');
        }

        /*
        if (Team::isMember()) {
            // $this->addToTopMenu('/votaciones/', 'Votaciones', '/votaciones/.*');
        }

        if (Team::isSuperAdmin()) {
            // $this->addToTopMenu('/admin/', 'Admin', '/admin/.*');
            // $this->addToTopMenu('/comunicados/', 'Comunicados', '/comunicados/.*');
        }
        */

        $this->addJavaScript('/js/lce.js', true);
        $this->addStyleSheet("
            html {
                background: url(/".$this->season->getBackgroundLink().") no-repeat center center fixed;
                -webkit-background-size: cover;
                -moz-background-size: cover;
                -o-background-size: cover;
                background-size: cover;
            }
        ", false);
        ob_start();
        $this->section->show();
        $this->contents = ob_get_contents();
        ob_end_clean();
    }
Esempio n. 13
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>
        <?
    }
Esempio n. 14
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><?
    }