PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/solar27/include/game/classes/supply.php

https://bitbucket.org/sebs/mosolar
PHP | 70 lines | 44 code | 16 blank | 10 comment | 14 complexity | bc1612bcbc870a4b872f8b9347d7ab27 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 Supply
  4. {
  5. var $DB;
  6. var $TEMPLATE;
  7. var $data;
  8. var $data_footprint;
  9. var $game_id;
  10. //////////////////////////////////////////////////////////////////////////
  11. //
  12. //////////////////////////////////////////////////////////////////////////
  13. function Supply($DB,$TEMPLATE)
  14. {
  15. $this->DB = $DB;
  16. $this->game_id =round($_SESSION["game"]);
  17. $this->TEMPLATE = $TEMPLATE;
  18. }
  19. ///////////////////////////////////////////////////////////////////////
  20. //
  21. ///////////////////////////////////////////////////////////////////////
  22. function load($empire_id)
  23. {
  24. $this->data = $this->DB->Execute("SELECT * FROM game".$this->game_id."_tb_supply 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_supply 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. ?>