/** * @return void */ public function show() { $resultNames = [ ['Sin resultado', 'Sin resultado'], ]; for ($i=6; $i>=0; $i--) { $resultNames[] = ["Victoria $i-0", "Derrota 0-$i"]; } for ($i=0; $i<=6; $i++) { $resultNames[] = ["Derrota 0-$i", "Victoria $i-0"]; } $resultNames[] = ["Victoria 6-0 (sin jugar)", "Derrota 0-6 (sin jugar)"]; $resultNames[] = ["Derrota 0-6 (sin jugar)", "Victoria 6-0 (sin jugar)"]; $resultNames[] = ["Aplazado", "Aplazado"]; if (!($csrf = $_SESSION['csrf'])) { $_SESSION['csrf'] = $csrf = rand(1, 1000000) . ""; } $postCsrf = HTMLResponse::fromPOST('csrf', ''); if ($postCsrf == $csrf) { if (HTMLResponse::fromPOST('color') !== null) { $this->team->color = HTMLResponse::fromPOST('color'); $this->team->save(); } } $color = $this->team->color; ?> <div class="inblock" style="margin-right: 16px"> <a target="_blank" href="/<?=$this->team->getImageLink()?>"> <img src="/<?=$this->team->getImageLink(300, 200)?>" alt="Logo" class="teamlogo"><br> </a> <a href="https://twitter.com/hashtag/<?=$this->team->getHashtag()?>" target="_blank">#<?=$this->team->getHashtag()?></a> <div style="height:2px"></div> <a href="https://twitter.com/<?=$this->team->username?>" target="_blank">@<?=$this->team->username?></a> <div style="height: 6px"></div> <span style="text-decoration: underline;">Color oficial</span>: <? if (preg_match("'^#[abcdefABCDEF0-9]{6}$'", $color)) { ?><span id="teamcolor"><?= $color ?></span><? } else { ?><i id="teamcolor">Sin color</i><? $color = '#000000'; } ?> <div class="teamcolor" style="background: <?=$color?>"></div> <br><? if ($this->team->isManager()) { ?> <br>Eres el Manager del equipo. <form action="<?=HTMLResponse::getRoute()?>" method="post" id="colorform"> <input type="hidden" name="color" value="<?=$color?>"> <input type="hidden" name="csrf" value="<?=$csrf?>"> </form> <? $this->design->addJavaScript('/js/jquery-ui.min.js'); $this->design->addStyleSheet('/css/jquery-ui.min.css'); $this->design->addStyleSheet('/css/jquery.colorpicker.css'); $this->design->addJavaScript('/js/jquery.colorpicker.js'); $this->design->addJavaScript(" $('.teamcolor').colorpicker({ inline: false, color: '{$color}', colorFormat: '#HEX', closeOnOutside: false, closeOnEscape: false, ok: function(event, color) { $('#colorform input[name=\"color\"]').val(color.formatted); $('#colorform').submit(); } }).css('cursor', 'pointer'); ", false); } ?> </div> <div class="inblock"> <? ?> <h2>Calendario de enfrentamientos</h2> <table> <thead> <tr> <td>Jornada</td> <td>Fecha</td> <td>Oponentes</td> <td>Resultado</td> <td>Vídeos</td> </tr> </thead> <tbody> <? foreach(Match::find('(team1id = ? or team2id = ?) and seasonid = ? order by week asc', [$this->team->teamid, $this->team->teamid, $this->season->seasonid]) as $match) { if (!$this->team->isManager() && !$this->season->weekIsPublic($match->week)) { continue; } if (HTMLResponse::fromPOST('matchid', '') === $match->matchid && strlen($newResult = HTMLResponse::fromPOST('result', ''))) { $match->result = $newResult; $match->save(); HTMLResponse::exitWithRoute(HTMLResponse::getRoute()); } $date = $this->season->getPublishTimeForWeek($match->week); if ($match->team1id == $this->team->teamid) { $posIndex = 0; } else { $posIndex = 1; } $opponentsId = ($match->team1id != $this->team->teamid) ? $match->team1id : $match->team2id; $opponents = Team::get($opponentsId); ?> <tr> <td style="height:3em"> <? echo $this->season->getWeekName($match->week); ?> </td> <td><?= date("Y-m-d", $date) ?></td> <td style="text-align: center"> <!-- <?=htmlentities($this->team->name)?> VS --> <a href="/<?=$this->season->getLink()?>/equipos/<?=$opponents->getLink()?>/"> <?=htmlentities($opponents->name)?> </a> </td> <td> <i style="color: #666" <? if ($this->team->isManager()) { ?>class="editableResult"<?}?>> <?= ($this->team->isManager() || $match->isPublished()) ? $resultNames[$match->result][$posIndex] : $resultNames[0][0] ?> </i> <form class="editResult" method="POST" action="<?=HTMLResponse::getRoute()?>"> <select name="result"> <? foreach($resultNames as $index => $names) { ?><option <?=($index==$match->result?'selected':'')?> value="<?=$index?>"><?=$names[$posIndex]?></option><? } ?> </select> <input type="hidden" name="matchid" value="<?=$match->matchid?>"> </form> </td> <td> <? $this->showMatchVideo($this->team, $match, 2, "Ver Team Preview") ?> <? $this->showMatchVideo($this->team, $match, 1, "Ver Combate") ?> </td> </tr> <? } ?> </tbody> </table> <? $this->showFriendlyMatches(); if ($this->team->isManager()) { $this->checkPlayerChanges(); } $this->showPlayers(); if ($this->team->isManager()) { $this->showPlayersEditor(); } $sanctionLevels = Sanction::getLevelNames(); $sanctions = Sanction::find('seasonid = ? and teamid = ? order by dateline desc', [$this->season->seasonid, $this->team->teamid]); if ($sanctions && Team::isMember()) { ?> <h2>Sanciones recibidas</h2> <table style="min-width: 512px"> <thead> <tr> <!-- <td>Fecha</td> --> <td>Tipo</td> <td>Razón</td> </tr> </thead> <? foreach($sanctions as $sanction) { ?> <tr> <!-- <td style="font-style: italic"> <?= date("Y-m-d H:i:s", $sanction->dateline) ?> </td> --> <td> <?= $sanctionLevels[$sanction->level] ?> <? if (Team::isAdmin()) { ?> <i style="color: #666"> por </i> <?= htmlentities($sanction->adminname) ?> <? } ?> </td> <td> <?= htmlentities($sanction->reason) ?> </td> </tr> <? } ?> </table><br> <? } if (Team::isAdmin()) { $postCsrf = HTMLResponse::fromPOST('sanctioncsrf', ''); if ($postCsrf == $csrf) { if (strlen($reason = HTMLResponse::fromPOST('sanctionreason'))) { $sanction = Sanction::create(); $sanction->adminid = TwitterAuth::getUserId(); $sanction->adminname = TwitterAuth::getUserName(); $sanction->dateline = time(); $sanction->reason = $reason; $sanction->seasonid = $this->season->seasonid; $sanction->teamid = $this->team->teamid; $sanction->level = HTMLResponse::fromPOST('sanctionlevel', 0); $sanction->save(); HTMLResponse::exitWithRoute(HTMLResponse::getRoute()); } } ?> <h2>Añadir nueva sanción</h2> <form action="<?=HTMLResponse::getRoute()?>" method="post"> <table style="min-width: 512px"> <thead> <tr> <td>Tipo</td> <td>Razón</td> </tr> </thead> <tr> <td> <select name="sanctionlevel"> <? foreach ($sanctionLevels as $index => $label) { ?> <option value="<?=$index?>"> <?= $label ?> </option> <? } ?> </select> </td> <td> <textarea name="sanctionreason" style="width: 250px"></textarea> </td> </tr> </table> <input type="hidden" name="sanctioncsrf" value="<?=$csrf?>"> <div style="height: 6px"></div> <button type="submit">Añadir sanción</button> </form> <? } ?><br> <? $this->showTeamSeasons(); ?> </div> <? }