AdslHouba

Course : php

Apr 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php
  2. sql::on();
  3. if ($_GET['type']=="depart") {
  4.   sql::query('
  5.    DELETE FROM `course`
  6.    WHERE
  7.          `pseudo` = \''.sql::escape($_GET['pseudo']).'\'
  8.        AND arriver = \'0000-00-00 00:00:00\'
  9.  ');
  10.   sql::query('
  11.    INSERT INTO `course` ( pseudo ) VALUES (\''.sql::escape($_GET['pseudo']).'\' )
  12.  ');
  13. } elseif ($_GET['type']=="arriver") {
  14.   sql::query('
  15.    UPDATE `course`
  16.    SET `arriver` = NOW()
  17.    WHERE `pseudo` = \''.sql::escape($_GET['pseudo']).'\' AND arriver = \'0000-00-00 00:00:00\'
  18.  ');
  19.   sql::query('
  20.    UPDATE `course`
  21.    SET `score` = TIMEDIFF(arriver,depart)
  22.    WHERE `pseudo` = \''.sql::escape($_GET['pseudo']).'\' AND `score`= 0
  23.  ');
  24. }
  25. class LuaSerialize
  26. {
  27.     private static function is_assoc($array)
  28.     {
  29.         return (bool)count(array_filter(array_keys($array), 'is_string')) && array_keys($array) !== range(0, count($array) - 1);
  30.     }
  31.     function serialize($value)
  32.     {
  33.         if (is_object($value)) {
  34.             $value = (array)$value;
  35.         }
  36.         if (is_array($value)) {
  37.             $members = array();
  38.             if (self::is_assoc($value)) {
  39.                 foreach ($value as $k => $v) {
  40.                     $members[] = '[' . $this->serialize($k) .']=' . $this->serialize($v);
  41.                 }
  42.             } else {
  43.                 foreach ($value as $k => $v) {
  44.                     $members[] = $this->serialize($v);
  45.                 }
  46.             }
  47.             return '{'.implode(',', $members).'}';
  48.         } elseif (is_bool($value)) {
  49.             return $value ? 'true' : 'false';
  50.         } elseif (is_string($value)) {
  51.             return var_export($value, true);
  52.         } elseif (is_numeric($value)) {
  53.             return $value;
  54.         } elseif ($value === null) {
  55.             return 'nil';
  56.         }
  57.         throw new \Exception('Unknown type to serialize: ' . $value);
  58.     }
  59. }
  60. $lua=new LuaSerialize();
  61.  
  62. $data=array('record'=>array(),'dernier'=>array());
  63.  
  64. $req=sql::query('
  65.  SELECT c.pseudo, MIN(c.score) AS scoreMin
  66.  FROM course c
  67.  WHERE c.score != 0
  68.  GROUP BY  c.pseudo
  69.  ORDER BY scoreMin
  70.  LIMIT 10
  71. ');
  72. while($d=$req->fetch_object()) {
  73.   $data['record'][]=$d;
  74. }
  75.  
  76. $req=sql::query('
  77.  SELECT `pseudo`, score
  78.  FROM `course`
  79.  WHERE score != 0
  80.  ORDER BY `arriver` DESC
  81.  LIMIT 5
  82. ');
  83. while($d=$req->fetch_object()) {
  84.   $data['dernier'][]=$d;
  85. }
  86. sql::off();
  87. echo $lua->serialize($data);
Add Comment
Please, Sign In to add comment