Guest User

Untitled

a guest
Feb 24th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.37 KB | None | 0 0
  1. public function thisPage(){
  2. $this->smarty->assign('kats', 0);
  3. if(isset($_GET['kat'])){
  4. $this->smarty->assign('kats', $this->mysqli->escape_string($_GET['kat']));
  5. $kat = $this->mysqli->escape_string($_GET['kat']);
  6. $rechte = $kat;
  7.  
  8. $thisKat = $this->mysqli->query("SELECT * FROM kategorien WHERE id = '".$kat."'");
  9.  
  10. if($thisKat->num_rows == 1){
  11. $thisKat = $thisKat->fetch_object();
  12.  
  13. $this->smarty->assign('kat_name', utf8_encode($thisKat->name));
  14.  
  15. $cars = $this->mysqli->query("SELECT * FROM items WHERE kat_id = '".$thisKat->id."' ORDER by name");
  16. while($Car = $cars->fetch_object()){
  17.  
  18. $thisWert = $this->mysqli->query("SELECT * FROM werte WHERE car_id = '".$Car->id."' ORDER by time DESC LIMIT 1")->fetch_object();
  19. $lastWert = $this->mysqli->query("SELECT * FROM werte WHERE car_id = '".$Car->id."' ORDER by time DESC LIMIT 1,1");
  20.  
  21. if($lastWert->num_rows == 1){
  22. $lastWert = $lastWert->fetch_object();
  23.  
  24. if($thisWert->Preis_1 > $lastWert->Preis_1){
  25. $color = "green";
  26. $unterschied = $thisWert->Preis_1 - $lastWert->Preis_1;
  27. $prozent = round(($unterschied * 100) / $thisWert->Preis_1, 2);
  28. $change = '+ '.number_format($unterschied, 0, '.', '.'). '$ ('.$prozent.'%)';
  29. } elseif($thisWert->Preis_1 < $lastWert->Preis_1){
  30. $color = "red";
  31. $unterschied = $lastWert->Preis_1 - $thisWert->Preis_1;
  32. $prozent = round(($unterschied * 100) / $thisWert->Preis_1, 2);
  33. $change = '- '.number_format($unterschied, 0, '.', '.'). '$ ('.$prozent.'%)';
  34. } else {
  35. $color = "grey";
  36. $change = "Keine Veränderung";
  37. }
  38.  
  39. } else {
  40. $color = "grey";
  41.  
  42. if($thisWert->time < time() - 86400){
  43. $change = "Keine Veränderungen";
  44. } else {
  45. $change = "Neu eingefügt";
  46. }
  47.  
  48. }
  49.  
  50. if($this->rechte < $rechte){
  51. $change = "Keine Rechte";
  52. $color = "grey";
  53. }
  54.  
  55. $newCars[] = array(
  56. "id" => $Car->id,
  57. "name" => $Car->name,
  58. "car_id" => $Car->car_id,
  59. "color" => $color,
  60. "change" => $change
  61. );
  62. }
  63.  
  64. $this->smarty->assign('newCars', $newCars);
  65. } else {
  66. header("Location: index.php?page=car");
  67. exit;
  68. }
  69. } else {
  70. // Neusten Änderungen
  71. $this->smarty->assign('kats', 0);
  72.  
  73. $newestChanges = $this->mysqli->query("SELECT distinct car_id, MAX(time) FROM werte GROUP BY car_id ORDER by MAX(time) DESC LIMIT 20");
  74. while($thisChanges = $newestChanges->fetch_object()){
  75. $thisChange = $this->mysqli->query("SELECT * FROM werte WHERE car_id = '".$thisChanges->car_id."' ORDER by time DESC LIMIT 1")->fetch_object();
  76.  
  77. $lastWert = $this->mysqli->query("SELECT * FROM werte WHERE car_id = '".$thisChange->car_id."' ORDER by time DESC LIMIT 1,1");
  78. if($lastWert->num_rows == 1){
  79.  
  80. $lastWert = $lastWert->fetch_object();
  81.  
  82. if($thisChange->Preis_1 > $lastWert->Preis_1){
  83.  
  84. $color = "green";
  85. $unterschied = $thisChange->Preis_1 - $lastWert->Preis_1;
  86. $prozent = round(($unterschied * 100) / $thisChange->Preis_1, 2);
  87. $change = '+ '.number_format($unterschied, 0, '.', '.'). ' $ ('.$prozent.' %)';
  88. } elseif($thisChange->Preis_1 < $lastWert->Preis_1){
  89. $color = "red";
  90. $unterschied = $lastWert->Preis_1 - $thisChange->Preis_1;
  91. $prozent = round(($unterschied * 100) / $thisChange->Preis_1, 2);
  92. $change = '- '.number_format($unterschied, 0, '.', '.'). ' $ ('.$prozent.' %)';
  93. } else {
  94. $color = "grey";
  95. $change = "Keine Veränderung";
  96. }
  97.  
  98. } else {
  99. $color = "grey";
  100. if($thisChange->time < time() - 86400){
  101. $change = "Keine Veränderungen";
  102. } else {
  103. $change = "Neu eingefügt";
  104. }
  105. }
  106.  
  107. $car_name = $this->mysqli->query("SELECT * FROM items WHERE id = '".$thisChange->car_id."'");
  108. if($car_name->num_rows == 1){
  109. $name = $car_name->fetch_object();
  110. $id = $name->id;
  111. $car_id = $name->car_id;
  112. $rechte = $name->kat_id;
  113. $name = $name->name;
  114. } else {
  115. $name = "Unbekannt";
  116. $car_id = 0;
  117. $id = 0;
  118. $rechte = 0;
  119. }
  120.  
  121. if($this->rechte < $rechte){
  122. $change = "Keine Rechte";
  123. $color = "grey";
  124. }
  125.  
  126. $newCars[] = array(
  127. "id" => $id,
  128. "name" => $name,
  129. "car_id" => $car_id,
  130. "color" => $color,
  131. "change" => $change
  132. );
  133.  
  134. }
  135.  
  136. $this->smarty->assign('newCars', $newCars);
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment