Advertisement
Guest User

index.php

a guest
Apr 13th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.21 KB | None | 0 0
  1. <?php
  2. ##############################################################
  3. ## Définitions des chemins d'accès à / et au dossier admin   ##
  4. ## Initialisation de l'interface                            ##
  5. ##############################################################
  6. DEFINE('ROOT_PATH', '');
  7. DEFINE('ADMIN_PATH', ROOT_PATH . 'admin/');
  8. require_once(ROOT_PATH . 'init.php');
  9.  
  10. ##############################################################
  11. ## Définitions des scripts/styles à charger pour la page  ##
  12. ##############################################################
  13. $scripts_to_load = array();
  14. $styles_to_load = array();
  15.  
  16. ##############################################################
  17. ## Traitements PHP                                          ##
  18. ##############################################################
  19. if(isset($_POST['action']) && $_POST['action'] == 'rate') {
  20.    
  21.     // on stocke les données postées en session
  22.     $_SESSION['form-rating'] = $_POST;
  23.    
  24.     // on vérifie qu'aucun champ obligatoire n'est vide
  25.     if(!empty($_POST['server']) && !empty($_POST['name']) && !empty($_POST['rating'])) {
  26.    
  27.         // on vérifie si le summoner existe dans la base de données
  28.         $handler_summoners = new Handler_Summoners();
  29.         $summoner = $handler_summoners->get_summoner_from_server_and_name($_POST['server'], $_POST['name']);
  30.        
  31.         // si le summoner n'existe pas encore, on le créé
  32.         if(!$summoner) {
  33.             $summoner = new Summoner();
  34.             $summoner->server_id    = $_POST['server'];
  35.             $summoner->name         = $_POST['name'];
  36.             $summoner->create();
  37.         }
  38.        
  39.         // on instancie le vote
  40.         $rating = new Rating();
  41.         $rating->summoner_id    = $summoner->id;
  42.         $rating->rating         = $_POST['rating'];
  43.         $rating->comment        = $_POST['comment'];
  44.         $rating->ip             = $_SERVER['REMOTE_ADDR'];
  45.        
  46.         // on verifie que le vote est permis
  47.         if($rating->is_permitted()) {
  48.             // on enregistre le vote
  49.             $rating->create();
  50.            
  51.             // notice
  52.             $notice = new Notice('success', '<strong>Thank you!</strong> Your choice was successfully submitted.');
  53.             $notice->sessionize();
  54.         }
  55.         else {
  56.             // notice
  57.             $notice = new Notice('danger', '<strong>Sorry, but...</strong> You recently rated this summoner. Wait a bit longer before rating this summoner again.');
  58.             $notice->sessionize();
  59.         }
  60.        
  61.     }
  62.     else {
  63.         // notice
  64.         $notice = new Notice('danger', '<strong>Sorry, but...</strong> One or several fields are empty.');
  65.         $notice->sessionize();
  66.     }
  67.    
  68.     // redirection
  69.     header('Location: index.php');
  70.     exit();
  71. }
  72.  
  73. ##############################################################
  74. ## Chargement du header                                     ##
  75. ##############################################################
  76. require_once(ROOT_PATH . 'includes/inc.head.php');
  77. ?>
  78. <script type="text/javascript">
  79. $(function() {
  80.     // Typeahead
  81.     $('.typeahead').typeahead({
  82.         source: function (query, process) {
  83.             return $.get('ajax_queries.php', { action: "get_summoners_from_server_and_string", server: $('#rating-server').val(), string: query }, function (data) {
  84.                 return process(data);
  85.             });
  86.         }
  87.     });
  88.    
  89.     // Modal
  90.     // $('#myModal').modal();
  91.     $('.modal-trigger').on('click', function(e) {
  92.         e.preventDefault();
  93.        
  94.         $.getJSON("ajax_queries.php", { action: "get_ratings_from_summoner", id: $(this).data('id') }, function(summoner) {
  95.            
  96.             var modal =         '<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">' +
  97.                                 '   <div class="modal-header">' +
  98.                                 '       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>' +
  99.                                 '       <h3>Comments about ' + summoner.name + '</h3>' +
  100.                                 '   </div>' +
  101.                                 '   <div class="modal-body">' +
  102.                                 '       <div class="modal-comment">';
  103.            
  104.             $.each(summoner.ratings, function(key, rating) {
  105.                 if(rating.comment != '') {
  106.                     modal +=    '           <blockquote>' +
  107.                                 '               <p>' + rating.comment + '</p>' +
  108.                                 '               <small>on ' + rating.formatted_datetime + '</small>' +
  109.                                 '           </blockquote>';
  110.                 }
  111.             });
  112.            
  113.             modal +=            '       </div>' +
  114.                                 '   </div>' +
  115.                                 '   <div class="modal-footer">' +
  116.                                 '       <a href="#" class="btn" data-dismiss="modal" aria-hidden="true">Close</a>' +
  117.                                 '   </div>' +
  118.                                 '</div>';
  119.            
  120.             $('body').append(modal);
  121.             $('#myModal').modal('show').on('hidden', function () {
  122.                 $(this).remove();
  123.             });
  124.            
  125.            
  126.         });    
  127.  
  128.     });
  129.    
  130.     // Rating pro/con
  131.     $('#rating-pro').hide().on('change', function() { $('#rating-pro-label').addClass('btn-success'); $('#rating-con-label').removeClass('btn-danger');  });
  132.     $('#rating-con').hide().on('change', function() { $('#rating-con-label').addClass('btn-danger'); $('#rating-pro-label').removeClass('btn-success');  });
  133.     $('#rating-pro-label').on('mouseover', function() {
  134.     $(this).addClass('btn-success');
  135.        
  136.     }).on('mouseleave', function() {
  137.         if(!$('#rating-pro').is(':checked')) {
  138.             $(this).removeClass('btn-success');
  139.         }
  140.     });
  141.     $('#rating-con-label').on('mouseover', function() {
  142.         $(this).addClass('btn-danger');
  143.     }).on('mouseleave', function() {
  144.         if(!$('#rating-con').is(':checked')) {
  145.             $(this).removeClass('btn-danger');
  146.         }
  147.     });
  148.    
  149.     // Summoner inspect
  150.     $('#form-inspect').submit(function(e) {
  151.         e.preventDefault();
  152.         $('#inspect-progress').fadeIn();
  153.         $.getJSON("ajax_queries.php", { action: "get_summoner_from_server_and_name", server: $('#inspect-server').val(), name: $('#inspect-name').val() }, function(summoner) {
  154.             if(summoner) {
  155.                 if(summoner.reliability >= 50) {
  156.                     var advice_text = 'Stay!';
  157.                     var advice_class = 'good';
  158.                     var advice_icon = 'thumb-up.png';
  159.                    
  160.                 }
  161.                 else {
  162.                     var advice_text = 'Dodge!';
  163.                     var advice_class = 'bad';
  164.                     var advice_icon = 'thumb-down.png';
  165.                 }
  166.                 var inspect_details = 'Details: ' + summoner.pros + ' pros, ' + summoner.cons + ' cons, ' + Math.round(summoner.reliability) + '% reliability';
  167.                
  168.                 setTimeout(function(){
  169.                     $('#inspect-progress').fadeOut(500, function() {
  170.                         $('#inspect-advice-container').addClass(advice_class).html('<img src="images/' + advice_icon + '" alt="" class="advice-icon" />' + advice_text).show();
  171.                         $('#inspect-details').text(inspect_details).show();
  172.                     });
  173.                 }, 1000);
  174.             }
  175.             else {
  176.                 var advice_class = 'neutral';
  177.                 var advice_text = 'No data about this summoner..';
  178.                 setTimeout(function(){
  179.                     $('#inspect-progress').fadeOut(500, function() {
  180.                         $('#inspect-advice-container').addClass(advice_class).html(advice_text).show();
  181.                     });
  182.                 }, 1000);
  183.             }
  184.         });
  185.     });
  186.    
  187.    
  188.     // Table initialisation
  189.     $('#table-summoners').dataTable( {
  190.         "aaSorting": [],
  191.         "iDisplayLength": 50,
  192.         "aLengthMenu": [25, 50, 100, 500],
  193.         "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
  194.         "sPaginationType": "bootstrap",
  195.         "oLanguage": {
  196.             "sLengthMenu": "_MENU_ records per page"
  197.         }
  198.     } );
  199.    
  200. });
  201. </script>
  202. </head>
  203.  
  204. <body>
  205.  
  206. <div id="wrap">
  207.  
  208.     <div class="navbar navbar-inverse navbar-fixed-top">
  209.         <div class="navbar-inner">
  210.             <div class="container">
  211.                 <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
  212.                     <span class="icon-bar"></span>
  213.                     <span class="icon-bar"></span>
  214.                     <span class="icon-bar"></span>
  215.                 </a>
  216.                 <a class="brand" href="<?php echo $config->site_url; ?>/"><?php echo $site->_s($config->site_name); ?></a>
  217.                 <div class="nav-collapse collapse">
  218.                     <ul class="nav">
  219.                         <li class="active"><a href="#">Home</a></li>
  220.                         <li><a href="#about">About</a></li>
  221.                         <li><a href="#contact">Contact</a></li>
  222.                     </ul>
  223.                 </div>
  224.             </div>
  225.         </div>
  226.     </div>
  227.     <div id="push"></div>
  228.    
  229.     <div id="main" class="container clear-top">
  230.        
  231.         <div class="hero-unit">
  232.             <h1>LoL Fame: rate your teammates and ennemies</h1>
  233.             <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>
  234.         </div>
  235.        
  236.         <?php
  237.         $handler_notices->display_all();
  238.         $handler_notices->clear();
  239.         ?>
  240.        
  241.         <div class="row">
  242.        
  243.             <div class="span6">
  244.                 <h2>Inspect a summoner</h2>
  245.                 <form method="post" class="block form-inspect form-inline" id="form-inspect">
  246.                     <select class="span2" name="server" id="inspect-server">
  247.                         <option value="1">EU West</option>
  248.                         <option value="2">EU East</option>
  249.                         <option value="3">NA</option>
  250.                     </select>
  251.                     <input type="text" name="name" id="inspect-name" class="span3 typeahead" placeholder="Summoner name" autocomplete="off">
  252.                     <input type="hidden" name="action" value="inspect">
  253.                     <input type="submit" class="btn btn-inverse" name="submit-inspect" value="Inspect">
  254.                    
  255.                     <br />
  256.                    
  257.                     <div class="progress progress-striped active hide" id="inspect-progress">
  258.                         <div class="bar" id="inspect-progress-bar" style="width: 100%;"></div>
  259.                     </div>
  260.                        
  261.                     <div id="inspect-advice-container"></div>
  262.                    
  263.                     <div id="inspect-details"></div>
  264.                 </form>
  265.             </div>
  266.            
  267.             <div class="span6">
  268.                 <h2>Rate a summoner</h2>
  269.                 <form method="post" class="block form-rating">
  270.                     <div>
  271.                         <select class="span2" name="server" id="rating-server">
  272.                             <option value="1"<?php if(isset($_SESSION['form-rating']['server']) && $_SESSION['form-rating']['server'] == 1) { echo ' selected="selected"'; } ?>>EU West</option>
  273.                             <option value="2"<?php if(isset($_SESSION['form-rating']['server']) && $_SESSION['form-rating']['server'] == 2) { echo ' selected="selected"'; } ?>>EU East</option>
  274.                             <option value="3"<?php if(isset($_SESSION['form-rating']['server']) && $_SESSION['form-rating']['server'] == 3) { echo ' selected="selected"'; } ?>>NA</option>
  275.                         </select>
  276.                         <input type="text" name="name" class="span2 typeahead" placeholder="Summoner name" autocomplete="off">
  277.                         <div class="rating-choice-container">
  278.                             Your choice :
  279.                             <label class="btn" id="rating-pro-label" for="rating-pro"><input type="radio" name="rating" id="rating-pro" value="pro">+1</label>
  280.                             <label class="btn" id="rating-con-label" for="rating-con"><input type="radio" name="rating" id="rating-con" value="con">-1</label>
  281.                         </div>
  282.                     </div>
  283.                     <div>
  284.                         <textarea name="comment" rows="2" style="width:534px;" placeholder="Optional: Leave a comment about this summoner.."></textarea>
  285.                     </div>
  286.                     <input type="hidden" name="action" value="rate">
  287.                     <input type="submit" class="btn btn-inverse btn-large" name="submit-rating" value="Submit">
  288.                 </form>
  289.             </div>
  290.            
  291.             <div class="span12">
  292.                 <h3>Summoners list</h3>
  293.                
  294.                 <?php
  295.                 $handler_summoners = new Handler_Summoners();
  296.                 $summoners = $handler_summoners->get_list();
  297.                
  298.                 if(!empty($summoners)) {
  299.                     ?>
  300.                
  301.                 <table class="table table-striped table-bordered datatable" id="table-summoners">
  302.                     <thead>
  303.                         <tr>
  304.                             <th width="25%">Summoner</th>
  305.                             <th width="15%">Server</th>
  306.                             <th width="15%">Pros</th>
  307.                             <th width="15%">Cons</th>
  308.                             <th width="15%">Reliability</th>
  309.                             <th width="15%">Comments</th>
  310.                         </tr>
  311.                     </thead>
  312.                     <tbody>
  313.                     <?php
  314.                     foreach($summoners as $summoner) {
  315.                         if($summoner->reliability < 50) {
  316.                             $class = ' badge-important';
  317.                         }
  318.                         else {
  319.                             $class = ' badge-success';
  320.                         }
  321.                         ?>
  322.                         <tr>
  323.                             <td><?php echo $site->_s($summoner->name); ?></td>
  324.                             <td><?php echo $site->_s($summoner->server->name); ?></td>
  325.                             <td><?php echo $site->_s($summoner->pros); ?></td>
  326.                             <td><?php echo $site->_s($summoner->cons); ?></td>
  327.                             <td><span class="badge<?php echo $class; ?>"><?php echo round($site->_s($summoner->reliability)); ?> %</span></td>
  328.                             <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>
  329.                         </tr>
  330.                         <?php
  331.                     }
  332.                     ?>
  333.                     </tbody>
  334.                 </table>
  335.                
  336.                     <?php
  337.                 }
  338.                 ?>
  339.                
  340.             </div>
  341.            
  342.         </div>
  343.     </div>
  344.    
  345. </div>
  346.  
  347. <footer class="footer">
  348.     <div class="container">
  349.         <div class="row">
  350.             <div class="span4">
  351.                 <h5>Navigate</h5>
  352.                 <ul>
  353.                     <li><span class="icon-chevron-right"></span> <a href="#">Lorem ipsum</a></li>
  354.                     <li><span class="icon-chevron-right"></span> <a href="#">Dolor sit amet</a></li>
  355.                     <li><span class="icon-chevron-right"></span> <a href="#">Consectetur adipiscing</a></li>
  356.                     <li><span class="icon-chevron-right"></span> <a href="#">Integer luctus</a></li>
  357.                 </ul>
  358.             </div>
  359.             <div class="span4">
  360.                 <h5>About us</h5>
  361.                 <ul>
  362.                     <li><span class="icon-chevron-right"></span> <a href="#">Nulla quis iaculis mattis</a></li>
  363.                     <li><span class="icon-chevron-right"></span> <a href="#">Risus quam</a></li>
  364.                     <li><span class="icon-chevron-right"></span> <a href="#">Porttitor quam</a></li>
  365.                    
  366.                 </ul>
  367.             </div>
  368.             <div class="span4">
  369.                 <h5>What's coming next ?</h5>
  370.                 <ul>
  371.                     <li><span class="icon-chevron-right"></span> <a href="#">Nulla quis iaculis mattis</a></li>
  372.                     <li><span class="icon-chevron-right"></span> <a href="#">Risus quam</a></li>
  373.                     <li><span class="icon-chevron-right"></span> <a href="#">Et gravida tortor augue</a></li>
  374.                     <li><span class="icon-chevron-right"></span> <a href="#">Suspendisse ipsum nisi</a></li>
  375.                 </ul>
  376.             </div>
  377.         </div>
  378.     </div>
  379. </footer>
  380.  
  381. </body>
  382. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement