Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.72 KB | None | 0 0
  1. <?php
  2.  
  3.     include 'check.php';
  4.     include 'dbconnect.php';
  5.     include 'navbar.php';
  6.     include 'functions.php';
  7.  
  8.     $query = $db->prepare("SELECT id,active,registered,lastlogin,name,handle,email,dob,bio,rating,rated,settings,power FROM accounts WHERE handle = :handle LIMIT 1");
  9.     $query->execute(array('handle' => $_GET['user']));
  10.     $user = $query->fetch();
  11.  
  12.     if ($user['active'] != 1)
  13.     {
  14.         exit("<center style='background: #FFFFFF; padding: 10px;'> <p style='font-size: 25px; color: black; font-weight: bold;'>This user has been banned, deleted or doesn't exist. <br> Please contact an admin for help if you believe that this is incorrect.</p></center>");
  15.     }
  16.  
  17.     if (!empty($user['rated']))
  18.     {
  19.         $rated = explode(",",$user['rated']);
  20.     }
  21.     else
  22.     {
  23.         $rated = array(0=>3,);
  24.     }
  25.  
  26.     $script = '';
  27.     print_r($rated);
  28.  
  29.     foreach ($rated as $rater => $rating)
  30.     {
  31.         if ($rater == $_SESSION['id'])
  32.         {
  33.             $script = "<script> rate(" . $rating . "); </script>";
  34.         }
  35.     }
  36.  
  37.     if (isset($_POST['submit']))
  38.     {
  39.         if (count($rated)<$_SESSION['id'])
  40.         {
  41.             $difference = $_SESSION['id'] - count($rated);
  42.            
  43.             $rated = implode(',',$rated);
  44.             while ($difference >= 0)
  45.             {
  46.                 $rated .= "0,";
  47.                 $difference--;
  48.             }
  49.             $rated = explode(',',$rated);
  50.         }
  51.  
  52.         $rated[$_SESSION['id']] = $_POST['rating'];
  53.  
  54.         $ratings = 0;
  55.         $ratingsadded = 0;
  56.         foreach ($rated as $user => $rating)
  57.         {
  58.             if ($rating != 0)
  59.             {
  60.                 $query = $db->prepare("SELECT id, active FROM accounts WHERE id = :id");
  61.                 $query->execute(array('id' => $user));
  62.                 $useractive = $query->fetch();
  63.  
  64.                 if ($useractive['active'] == 1 || $user == 0 || $user == 50)
  65.                 {
  66.                     $ratings++;
  67.                     $ratingsadded += $rating;
  68.                 }
  69.                 else
  70.                 {
  71.                     $rated[$user] = 0;
  72.                 }
  73.             }
  74.         }
  75.         $ratingtotal = $ratingsadded / $ratings;
  76.  
  77.         $query = $db->prepare("UPDATE accounts SET rating = :rating, rated = :rated WHERE id = :id");
  78.         $query->execute(array('rating' => $ratingtotal, 'rated' => implode(",",$rated), 'id' => $user['id']));
  79.         header('Location: ?user=' . $_GET['user']);
  80.     }
  81.    
  82. ?>
  83.  
  84. <html>
  85.     <head>
  86.         <title> Rater - <?php echo $_GET['user'] . ' &apos;s' ?> Profile </title>
  87.         <link rel='stylesheet' type='text/css' href='style.css'>
  88.         <script type='text/js' src='/rater/script.js'></script>
  89.     </head>
  90.     <body>
  91.         <div>
  92.  
  93. <?php
  94.  
  95.     if ($user['rating'] >= 4)
  96.     {
  97.         $star = '/rater/content/filledstar.png';
  98.     }
  99.     elseif ($user['rating'] <= 2)
  100.     {
  101.         $star = '/rater/content/emptystar.png';
  102.     }
  103.     else
  104.     {
  105.         $star = '/rater/content/halffilledstar.png';
  106.     }
  107.     echo $user['name'] . "<br>";
  108.     echo $user['handle'] . "<sup><img height='16px' src='" . $star . "'>" . $user['rating'] . "</sup><br>";
  109.  
  110. ?>
  111.  
  112.         </div>
  113.         <div id='rate'>
  114.             <form method='POST'><img src='/rater/content/emptystar.png' id='button1' height='25px' onclick='rate(1);'></img><img src='/rater/content/emptystar.png' id='button2' height='25px' onclick='rate(2);'></img><img src='/rater/content/emptystar.png' id='button3' height='25px' onclick='rate(3);'></img><img src='/rater/content/emptystar.png' id='button4' height='25px' onclick='rate(4);'></img><img src='/rater/content/emptystar.png' id='button5' height='25px' onclick='rate(5);'></img><input id='rating' name='rating' type='hidden' value='2.5'><button name='submit' type='submit'>Submit</button></form>
  115.         </div>
  116.  
  117. <?php
  118.  
  119.     echo $user['bio'];
  120.  
  121. ?>
  122.  
  123.         <script>
  124.             function rate(num)
  125.             {
  126.                 for (var x = 1; x <= num; x++)
  127.                 {
  128.                     document.getElementById('button'+x).src = '/rater/content/filledstar.png';
  129.                 }
  130.                 for (var x = 5; x > num; x--)
  131.                 {          
  132.                     document.getElementById('button'+x).src = '/rater/content/emptystar.png';
  133.                 }
  134.                 document.getElementById('rating').value = num;
  135.             }
  136.         </script>
  137. <?php echo $script; ?>
  138.     </body>
  139. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement