Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ##############################################################
- ## Définitions des chemins d'accès à / et au dossier admin ##
- ## Initialisation de l'interface ##
- ##############################################################
- DEFINE('ROOT_PATH', '');
- DEFINE('ADMIN_PATH', ROOT_PATH . 'admin/');
- require_once(ROOT_PATH . 'init.php');
- ##############################################################
- ## Définitions des scripts/styles à charger pour la page ##
- ##############################################################
- $scripts_to_load = array();
- $styles_to_load = array();
- ##############################################################
- ## Traitements PHP ##
- ##############################################################
- if(isset($_POST['action']) && $_POST['action'] == 'rate') {
- // on stocke les données postées en session
- $_SESSION['form-rating'] = $_POST;
- // on vérifie qu'aucun champ obligatoire n'est vide
- if(!empty($_POST['server']) && !empty($_POST['name']) && !empty($_POST['rating'])) {
- // on vérifie si le summoner existe dans la base de données
- $handler_summoners = new Handler_Summoners();
- $summoner = $handler_summoners->get_summoner_from_server_and_name($_POST['server'], $_POST['name']);
- // si le summoner n'existe pas encore, on le créé
- if(!$summoner) {
- $summoner = new Summoner();
- $summoner->server_id = $_POST['server'];
- $summoner->name = $_POST['name'];
- $summoner->create();
- }
- // on instancie le vote
- $rating = new Rating();
- $rating->summoner_id = $summoner->id;
- $rating->rating = $_POST['rating'];
- $rating->comment = $_POST['comment'];
- $rating->ip = $_SERVER['REMOTE_ADDR'];
- // on verifie que le vote est permis
- if($rating->is_permitted()) {
- // on enregistre le vote
- $rating->create();
- // notice
- $notice = new Notice('success', '<strong>Thank you!</strong> Your choice was successfully submitted.');
- $notice->sessionize();
- }
- else {
- // notice
- $notice = new Notice('danger', '<strong>Sorry, but...</strong> You recently rated this summoner. Wait a bit longer before rating this summoner again.');
- $notice->sessionize();
- }
- }
- else {
- // notice
- $notice = new Notice('danger', '<strong>Sorry, but...</strong> One or several fields are empty.');
- $notice->sessionize();
- }
- // redirection
- header('Location: index.php');
- exit();
- }
- ##############################################################
- ## Chargement du header ##
- ##############################################################
- require_once(ROOT_PATH . 'includes/inc.head.php');
- ?>
- <script type="text/javascript">
- $(function() {
- // Typeahead
- $('.typeahead').typeahead({
- source: function (query, process) {
- return $.get('ajax_queries.php', { action: "get_summoners_from_server_and_string", server: $('#rating-server').val(), string: query }, function (data) {
- return process(data);
- });
- }
- });
- // Modal
- // $('#myModal').modal();
- $('.modal-trigger').on('click', function(e) {
- e.preventDefault();
- $.getJSON("ajax_queries.php", { action: "get_ratings_from_summoner", id: $(this).data('id') }, function(summoner) {
- var modal = '<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
- ' <div class="modal-header">' +
- ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
- ' <h3>Comments about ' + summoner.name + '</h3>' +
- ' </div>' +
- ' <div class="modal-body">' +
- ' <div class="modal-comment">';
- $.each(summoner.ratings, function(key, rating) {
- if(rating.comment != '') {
- modal += ' <blockquote>' +
- ' <p>' + rating.comment + '</p>' +
- ' <small>on ' + rating.formatted_datetime + '</small>' +
- ' </blockquote>';
- }
- });
- modal += ' </div>' +
- ' </div>' +
- ' <div class="modal-footer">' +
- ' <a href="#" class="btn" data-dismiss="modal" aria-hidden="true">Close</a>' +
- ' </div>' +
- '</div>';
- $('body').append(modal);
- $('#myModal').modal('show').on('hidden', function () {
- $(this).remove();
- });
- });
- });
- // Rating pro/con
- $('#rating-pro').hide().on('change', function() { $('#rating-pro-label').addClass('btn-success'); $('#rating-con-label').removeClass('btn-danger'); });
- $('#rating-con').hide().on('change', function() { $('#rating-con-label').addClass('btn-danger'); $('#rating-pro-label').removeClass('btn-success'); });
- $('#rating-pro-label').on('mouseover', function() {
- $(this).addClass('btn-success');
- }).on('mouseleave', function() {
- if(!$('#rating-pro').is(':checked')) {
- $(this).removeClass('btn-success');
- }
- });
- $('#rating-con-label').on('mouseover', function() {
- $(this).addClass('btn-danger');
- }).on('mouseleave', function() {
- if(!$('#rating-con').is(':checked')) {
- $(this).removeClass('btn-danger');
- }
- });
- // Summoner inspect
- $('#form-inspect').submit(function(e) {
- e.preventDefault();
- $('#inspect-progress').fadeIn();
- $.getJSON("ajax_queries.php", { action: "get_summoner_from_server_and_name", server: $('#inspect-server').val(), name: $('#inspect-name').val() }, function(summoner) {
- if(summoner) {
- if(summoner.reliability >= 50) {
- var advice_text = 'Stay!';
- var advice_class = 'good';
- var advice_icon = 'thumb-up.png';
- }
- else {
- var advice_text = 'Dodge!';
- var advice_class = 'bad';
- var advice_icon = 'thumb-down.png';
- }
- var inspect_details = 'Details: ' + summoner.pros + ' pros, ' + summoner.cons + ' cons, ' + Math.round(summoner.reliability) + '% reliability';
- setTimeout(function(){
- $('#inspect-progress').fadeOut(500, function() {
- $('#inspect-advice-container').addClass(advice_class).html('<img src="images/' + advice_icon + '" alt="" class="advice-icon" />' + advice_text).show();
- $('#inspect-details').text(inspect_details).show();
- });
- }, 1000);
- }
- else {
- var advice_class = 'neutral';
- var advice_text = 'No data about this summoner..';
- setTimeout(function(){
- $('#inspect-progress').fadeOut(500, function() {
- $('#inspect-advice-container').addClass(advice_class).html(advice_text).show();
- });
- }, 1000);
- }
- });
- });
- // Table initialisation
- $('#table-summoners').dataTable( {
- "aaSorting": [],
- "iDisplayLength": 50,
- "aLengthMenu": [25, 50, 100, 500],
- "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
- "sPaginationType": "bootstrap",
- "oLanguage": {
- "sLengthMenu": "_MENU_ records per page"
- }
- } );
- });
- </script>
- </head>
- <body>
- <div id="wrap">
- <div class="navbar navbar-inverse navbar-fixed-top">
- <div class="navbar-inner">
- <div class="container">
- <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </a>
- <a class="brand" href="<?php echo $config->site_url; ?>/"><?php echo $site->_s($config->site_name); ?></a>
- <div class="nav-collapse collapse">
- <ul class="nav">
- <li class="active"><a href="#">Home</a></li>
- <li><a href="#about">About</a></li>
- <li><a href="#contact">Contact</a></li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div id="push"></div>
- <div id="main" class="container clear-top">
- <div class="hero-unit">
- <h1>LoL Fame: rate your teammates and ennemies</h1>
- <p>A troll just ruined your game ? Or maybe someone carried you like a boss ? Rate him right now, and help all other players to decide if they should stay in their lobby, or dodge it !</p>
- </div>
- <?php
- $handler_notices->display_all();
- $handler_notices->clear();
- ?>
- <div class="row">
- <div class="span6">
- <h2>Inspect a summoner</h2>
- <form method="post" class="block form-inspect form-inline" id="form-inspect">
- <select class="span2" name="server" id="inspect-server">
- <option value="1">EU West</option>
- <option value="2">EU East</option>
- <option value="3">NA</option>
- </select>
- <input type="text" name="name" id="inspect-name" class="span3 typeahead" placeholder="Summoner name" autocomplete="off">
- <input type="hidden" name="action" value="inspect">
- <input type="submit" class="btn btn-inverse" name="submit-inspect" value="Inspect">
- <br />
- <div class="progress progress-striped active hide" id="inspect-progress">
- <div class="bar" id="inspect-progress-bar" style="width: 100%;"></div>
- </div>
- <div id="inspect-advice-container"></div>
- <div id="inspect-details"></div>
- </form>
- </div>
- <div class="span6">
- <h2>Rate a summoner</h2>
- <form method="post" class="block form-rating">
- <div>
- <select class="span2" name="server" id="rating-server">
- <option value="1"<?php if(isset($_SESSION['form-rating']['server']) && $_SESSION['form-rating']['server'] == 1) { echo ' selected="selected"'; } ?>>EU West</option>
- <option value="2"<?php if(isset($_SESSION['form-rating']['server']) && $_SESSION['form-rating']['server'] == 2) { echo ' selected="selected"'; } ?>>EU East</option>
- <option value="3"<?php if(isset($_SESSION['form-rating']['server']) && $_SESSION['form-rating']['server'] == 3) { echo ' selected="selected"'; } ?>>NA</option>
- </select>
- <input type="text" name="name" class="span2 typeahead" placeholder="Summoner name" autocomplete="off">
- <div class="rating-choice-container">
- Your choice :
- <label class="btn" id="rating-pro-label" for="rating-pro"><input type="radio" name="rating" id="rating-pro" value="pro">+1</label>
- <label class="btn" id="rating-con-label" for="rating-con"><input type="radio" name="rating" id="rating-con" value="con">-1</label>
- </div>
- </div>
- <div>
- <textarea name="comment" rows="2" style="width:534px;" placeholder="Optional: Leave a comment about this summoner.."></textarea>
- </div>
- <input type="hidden" name="action" value="rate">
- <input type="submit" class="btn btn-inverse btn-large" name="submit-rating" value="Submit">
- </form>
- </div>
- <div class="span12">
- <h3>Summoners list</h3>
- <?php
- $handler_summoners = new Handler_Summoners();
- $summoners = $handler_summoners->get_list();
- if(!empty($summoners)) {
- ?>
- <table class="table table-striped table-bordered datatable" id="table-summoners">
- <thead>
- <tr>
- <th width="25%">Summoner</th>
- <th width="15%">Server</th>
- <th width="15%">Pros</th>
- <th width="15%">Cons</th>
- <th width="15%">Reliability</th>
- <th width="15%">Comments</th>
- </tr>
- </thead>
- <tbody>
- <?php
- foreach($summoners as $summoner) {
- if($summoner->reliability < 50) {
- $class = ' badge-important';
- }
- else {
- $class = ' badge-success';
- }
- ?>
- <tr>
- <td><?php echo $site->_s($summoner->name); ?></td>
- <td><?php echo $site->_s($summoner->server->name); ?></td>
- <td><?php echo $site->_s($summoner->pros); ?></td>
- <td><?php echo $site->_s($summoner->cons); ?></td>
- <td><span class="badge<?php echo $class; ?>"><?php echo round($site->_s($summoner->reliability)); ?> %</span></td>
- <td><?php if($summoner->nb_comments != 0) { ?><a href="#" class="modal-trigger" data-id="<?php echo $site->_s($summoner->id); ?>">read (<?php echo $summoner->nb_comments; ?>)</a><?php } ?></td>
- </tr>
- <?php
- }
- ?>
- </tbody>
- </table>
- <?php
- }
- ?>
- </div>
- </div>
- </div>
- </div>
- <footer class="footer">
- <div class="container">
- <div class="row">
- <div class="span4">
- <h5>Navigate</h5>
- <ul>
- <li><span class="icon-chevron-right"></span> <a href="#">Lorem ipsum</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Dolor sit amet</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Consectetur adipiscing</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Integer luctus</a></li>
- </ul>
- </div>
- <div class="span4">
- <h5>About us</h5>
- <ul>
- <li><span class="icon-chevron-right"></span> <a href="#">Nulla quis iaculis mattis</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Risus quam</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Porttitor quam</a></li>
- </ul>
- </div>
- <div class="span4">
- <h5>What's coming next ?</h5>
- <ul>
- <li><span class="icon-chevron-right"></span> <a href="#">Nulla quis iaculis mattis</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Risus quam</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Et gravida tortor augue</a></li>
- <li><span class="icon-chevron-right"></span> <a href="#">Suspendisse ipsum nisi</a></li>
- </ul>
- </div>
- </div>
- </div>
- </footer>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement