admin_irodak_model.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. class admin_irodak_model extends Model {
  3. public function getIrodaList() {
  4. $result = $this->query("SELECT * FROM irodak WHERE office_id<>'' ORDER BY id ASC;");
  5. return $result;
  6. }
  7. public function getOffices() {
  8. $result = $this->query("SELECT * FROM hiper_iroda WHERE aktiv='1' ORDER BY nev ASC;");
  9. return $result;
  10. }
  11. public function getOffice($id) {
  12. $result = $this->query("SELECT * FROM hiper_iroda WHERE azonosito='".$id."';");
  13. return $result[0];
  14. }
  15. public function getIroda($id) {
  16. $result = $this->query("SELECT * FROM irodak WHERE id='".$id."';");
  17. return $result[0];
  18. }
  19. public function isAlredyIroda($id) {
  20. $result = $this->query("SELECT * FROM irodak WHERE office_id='".$id."';");
  21. if (sizeof($result)>0) {
  22. return true;
  23. }
  24. else {
  25. return false;
  26. }
  27. }
  28. public function getIrodaByOfficeID($id) {
  29. $result = $this->query("SELECT * FROM irodak WHERE office_id='".$id."';");
  30. return $result[0]->id;
  31. }
  32. public function getReferens($id) {
  33. if ($id!='') {
  34. $id = $this->escapeString($id);
  35. $result = $this->query("SELECT * FROM referensek WHERE id='".$id."';");
  36. return $result[0];
  37. }
  38. else {
  39. return false;
  40. }
  41. }
  42. public function saveIroda($data) {
  43. $data = $this->escapeArray($data);
  44. $check = $data['pixelid']+0;
  45. if (is_integer($check)) {
  46. $this->execute("UPDATE irodak SET description='".$data['description']."', pixelid='".$data['pixelid']."' WHERE id='".$data['id']."'");
  47. return true;
  48. }
  49. else {
  50. return false;
  51. }
  52. }
  53. public function add_iroda($id) {
  54. if ($id!='') {
  55. $id = $this->escapeString($id);
  56. if ($this->isAlredyIroda($id)) {
  57. return $this->getIrodaByOfficeID($id);
  58. }
  59. else {
  60. $office = $this->getOffice($id);
  61. $this->execute("INSERT INTO irodak SET office_id='".$office->azonosito."';");
  62. return $this->getLastInsertID();
  63. }
  64. }
  65. else {
  66. return false;
  67. }
  68. }
  69. public function deleteIroda($id) {
  70. if ($id!='') {
  71. $id = $this->escapeString($id);
  72. $this->execute("DELETE FROM irodak WHERE id='".$id."';");
  73. return true;
  74. }
  75. else {
  76. return false;
  77. }
  78. }
  79. public function setIrodaState($id) {
  80. if ($id!='') {
  81. $res = $this->query("SELECT * FROM irodak WHERE id='".$id."';");
  82. if ($res[0]->active=='1') {
  83. $new = '0';
  84. }
  85. else {
  86. $new = '1';
  87. }
  88. $this->execute("UPDATE irodak SET active='".$new."' WHERE id='".$id."';");
  89. return true;
  90. }
  91. else {
  92. return false;
  93. }
  94. }
  95. }