PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/solar27/include/game/classes/planets.php

https://bitbucket.org/sebs/mosolar
PHP | 92 lines | 59 code | 20 blank | 13 comment | 14 complexity | c8444660f10302d84bd38d0d3ac1183f MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-2.0
  1. <?php
  2. // Solar Imperium is licensed under GPL2, Check LICENSE.TXT for mode details //
  3. class Planets
  4. {
  5. var $DB;
  6. var $TEMPLATE;
  7. var $data;
  8. var $data_footprint;
  9. var $game_id;
  10. ///////////////////////////////////////////////////////////////////////
  11. //
  12. ///////////////////////////////////////////////////////////////////////
  13. function Planets($DB,$TEMPLATE)
  14. {
  15. $this->DB = $DB;
  16. $this->TEMPLATE = $TEMPLATE;
  17. $this->game_id = round($_SESSION["game"]);
  18. }
  19. ///////////////////////////////////////////////////////////////////////
  20. //
  21. ///////////////////////////////////////////////////////////////////////
  22. function load($empire_id)
  23. {
  24. $this->data = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_planets WHERE empire='".intval($empire_id)."'");
  25. if (!$this->data) trigger_error($this->DB->ErrorMsg());
  26. if ($this->data->EOF) return false;
  27. $this->data = $this->data->fields;
  28. $this->data_footprint = md5(serialize($this->data));
  29. return true;
  30. }
  31. ///////////////////////////////////////////////////////////////////////
  32. //
  33. ///////////////////////////////////////////////////////////////////////
  34. function save()
  35. {
  36. if (md5(serialize($this->data)) == $this->data_footprint) return;
  37. $query = "UPDATE game".$this->game_id."_tb_planets SET ";
  38. reset($this->data);
  39. while (list($key,$value) = each($this->data))
  40. {
  41. if ($key == "id") continue;
  42. if ($key == "empire") continue;
  43. if (is_numeric($key)) continue;
  44. if ((is_numeric($value)) && ($key != "logo"))
  45. $query .= "$key=$value,";
  46. else
  47. $query .= "$key='".addslashes($value)."',";
  48. }
  49. $query = substr($query,0,strlen($query)-1); // removing remaining ,
  50. $query .= " WHERE empire='".$this->data["empire"]."'";
  51. if (!$this->DB->Execute($query)) trigger_error($this->DB->ErrorMsg());
  52. }
  53. ///////////////////////////////////////////////////////////////////////
  54. //
  55. ///////////////////////////////////////////////////////////////////////
  56. function getCount()
  57. {
  58. $count = 0;
  59. $count += $this->data["food_planets"];
  60. $count += $this->data["ore_planets"];
  61. $count += $this->data["tourism_planets"];
  62. $count += $this->data["supply_planets"];
  63. $count += $this->data["gov_planets"];
  64. $count += $this->data["edu_planets"];
  65. $count += $this->data["research_planets"];
  66. $count += $this->data["urban_planets"];
  67. $count += $this->data["petro_planets"];
  68. $count += $this->data["antipollu_planets"];
  69. return $count;
  70. }
  71. }
  72. ?>