/** * @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> <? } }
/** * @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()) { ?> Sólo los miembros pueden ver esta página.<br> <? return; } else { ?><div style="text-align: left; margin: 0 auto" class="inblock"><? if (Team::isMember()) { ?><ul><? foreach(Poll::find('isvisible order by dateline desc') as $poll) { ?> <li> <a href="/votaciones/<?=$poll->pollid?>/"> <?=htmlentities($poll->title)?> </a> </li> <? } ?></ul><? ?> <a href="/votaciones/crear/"> Haz click aquí para añadir una nueva votación. </a> <? } ?></div><br><br><? } }
/** * @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> <? }
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> <? } } }
/** * @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> <? } }
/** * @param $match Match * @param $team Team * @param $team1votes * @param $votesCount */ private function showTeamBox($match, $team, $team1votes, $votesCount) { $video = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $team->teamid, 1]); $canVote = $this->canVote; $team1per = 50; if ($votesCount != 0) { $team1per = round($team1votes / $votesCount * 100); } $team2 = ($match->team1id == $team->teamid) ? $match->getTeam2() : $match->getTeam1(); $isGray = ($match->isPublished() && $match->getWinner() && $match->getWinner() != $team->teamid); ?> <div class="teambox"> <div class="votecount"><?=$team1votes?> votos (<?=$team1per?>%)</div> <? if ($canVote) { ?> <? if (TwitterAuth::isLogged()) { ?> <? if (!$match->hasVoted()) { ?> <form method="post" action="<?=HTMLResponse::getRoute()?>"> <button type="submit" class="vote">Votar</button> <input type="hidden" name="teamid" value="<?=$team->teamid?>"> <input type="hidden" name="matchid" value="<?=$match->matchid?>"> </form> <? } else if ($match->hasVoted() == $team->teamid) { ?> <form method="post" action="<?=HTMLResponse::getRoute()?>"> <div class="login"> <button type="submit">Quitar voto</button> <a target="_blank" class="twitter-share-button" href="https://twitter.com/intent/tweet?text=<?=urlencode("¡He votado que #".$team->getHashtag()." ganará a #".$team2->getHashtag()." en la @LCE_Pokemon! http://lce.wz.tl")?>"> ¡Twittear!</a> </div> <input type="hidden" name="unteamid" value="<?=$team->teamid?>"> <input type="hidden" name="unmatchid" value="<?=$match->matchid?>"> </form> <? } ?> <? } else { ?> <a href="<?= HTMLResponse::getRoute() ?>?authenticate=1" class="login">¡Usa Twitter para votar!</a> <? } ?> <? } else { ?> <? if (TwitterAuth::isLogged()) { ?> <? if (!$match->isPublished() || !$match->getWinner()) { ?> <? if ($match->hasVoted() == $team->teamid) { ?> <span class="login">Has votado por este equipo</span> <? } ?> <? } else if ($video) { ?> <a class="login" href="<?=htmlentities($video->link)?>" target="_blank"> Ver combate </a> <? } ?> <? } else if (!$match->isPublished()) { ?> <a href="<?= HTMLResponse::getRoute() ?>?authenticate=1" class="login">¡Entra para ver tus votos!</a> <? } else if ($video) { ?> <a class="login" href="<?=htmlentities($video->link)?>" target="_blank"> Ver combate </a> <? } ?> <? } ?> <a href="/<?=$this->season->getLink()?>/equipos/<?=$team->getLink()?>/"><img class="<?=$isGray?'_grayscale':''?>" src="/<?=$team->getImageLink(200, 150)?>"></a> </div> <? }
$router->addRoute("/admin/equipos/{$rNum}/", array('Admin_Team')); $router->addRoute("/admin/temporadas/", array('Admin_Seasons')); $router->addRoute("/admin/temporadas/{$rNum}/", array('Admin_Season')); $router->addRoute("/admin/temporadas/{$rNum}/jornadas/", array('Admin_Season_Weeks')); $router->addRoute("/admin/temporadas/{$rNum}/eventos/", array('Admin_Season_Events')); $router->addRoute("/", array('Index')); $router->addRoute("/batch/", array('Batch')); $router->addRoute("/{$rDir}/jornadas/{$rNum}/", array('Season_Index')); $router->addRoute("/{$rDir}/equipos/", array('Teams')); $router->addRoute("/{$rDir}/equipos/{$rDir}/", array('Team_Index')); $router->addRoute("/{$rDir}/clasificacion/", array('Ranking')); $router->addRoute("/{$rDir}/quiniela/", array('BetsRanking')); $router->addRoute("/{$rDir}/calendario/", array('Calendar')); $router->addRoute("/{$rDir}/", array('Season_Index')); $router->addRoute(".*", array('Error_404')); $route = HTMLResponse::getRoute(); $indent = $router->process($route); if ($indent) { $indentClass = $indent[0]; $indentDir = dirname(str_replace("_", "/", $indentClass)); $indentFile = str_replace("//", "", "pages/{$indentDir}/{$indentClass}.php"); $indentParams = array_slice($indent, 1); if (file_exists("pages/{$indentDir}/{$indentDir}.php")) { require_once "pages/{$indentDir}/{$indentDir}.php"; } if (file_exists($indentFile)) { require_once $indentFile; } $r = new ReflectionClass($indentClass); /** * @var $section PublicSection
/** * @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><? }
/** * @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><? }
/** * @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><? } }
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 }
/** * @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> <? }
/** * @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><? }