// first kill any existing attachment (pending) score $attach = json_decode(file_get_contents("https://api.challonge.com/v1/tournaments/" . $config['challonge_id'] . "/matches/{$m['id']}/attachments.json?api_key=" . $config['challonge_api']), true); foreach ($attach as $n => $payload) { if (substr($payload['match_attachment']['description'], 0, 18) == '$BYEPENDINGSCORE$:') { $resp = httpPut(array('api_key' => $config['challonge_api'], 'match' => $match), "https://api.challonge.com/v1/tournaments/{$config['challonge_id']}" . "/matches/{$m['id']}/attachments/{$payload['match_attachment']['id']}.json", 'DELETE'); $debug['challonge_response_delete_existing'] = json_decode($resp, true); } } if (array_key_exists('done', $_POST)) { $match['winner_id'] = $p1w > $p2w ? $m['player1_id'] : $m['player2_id']; $resp = httpPut(array('api_key' => $config['challonge_api'], 'match' => $match), "https://api.challonge.com/v1/tournaments/{$config['challonge_id']}/matches/{$m['id']}.json"); $debug['challonge_response'] = json_decode($resp, true); } else { // now (re)make the attachement $attachment = array('description' => '$BYEPENDINGSCORE$:' . $match['scores_csv']); $resp = httpPut(array('api_key' => $config['challonge_api'], 'match_attachment' => $attachment), "https://api.challonge.com/v1/tournaments/{$config['challonge_id']}/matches/{$m['id']}/attachments.json", 'POST'); $debug['challonge_response'] = json_decode($resp, true); } // assume it worked--if it didn't we'd get a text wall of errors. Re-get the data since we did something $data = json_decode(file_get_contents("https://api.challonge.com/v1/tournaments/" . $config['challonge_id'] . ".json?api_key=" . $config['challonge_api'] . "&include_participants=1&include_matches=1"), true)['tournament']; } ?> <!DOCTYPE html> <html> <head> <title>Bye - <?php echo $data['name']; ?> </title> <script src="/js/jquery.min.js" type="text/javascript" charset="UTF-8"></script> <link href="/css/bootstrap.css" rel="stylesheet" />
<?php include 'include.php'; isAllowed(); if (!isset($_GET['id'])) { setFlash("action impossible.", "danger"); redirect("accueil.php"); die; } $post = $_GET['id']; $fields = ['titre' => urlencode($_POST['titre']), 'description' => urlencode($_POST['description']), 'privacy' => 0]; $url = 'http://api-rest-youcef-m.c9.io/post/update/' . $post; $result = httpPut($fields, $url); if ($result['code'] == 400) { $error = json_decode($result['content']); foreach ($error as $k => $v) { $_SESSION['errors'][$k] = $v[0]; } redirect('modifier_photo.php?id=' . $post); } elseif ($result['code'] == 500) { setFlash('Nos services sont en panne, nous faisons notre possible pour régler le problème.', 'danger'); redirect('serveur_down.php'); } elseif ($result['code'] == 200) { setFlash("Votre publication a bien été modifiée"); redirect('afficherphoto.php?id=' . $post); } else { setFlash('Nos services sont en panne, nous faisons notre possible pour régler le problème.', 'danger'); redirect('serveur_down.php'); }
function updateVote($user, $post) { $url = 'http://api-rest-youcef-m.c9.io/vote/update'; $fields = ['user_id' => $user, 'post_id' => $post]; $result = httpPut($fields, $url); return json_decode($result['content']); }