profile_model.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. class profile_model extends Model {
  3. public function loadSettings($userid) {
  4. $result = $this->query("SELECT * FROM users WHERE id='".$userid."';");
  5. if (sizeof($result)>0) {
  6. return $result[0];
  7. }
  8. else {
  9. return false;
  10. }
  11. }
  12. public function saveSettings($data) {
  13. $data = $this->escapeArray($data);
  14. $this->execute("UPDATE users SET
  15. username='".$data['username']."',
  16. firstname='".$data['fname']."',
  17. lastname='".$data['lname']."',
  18. email='".$data['email']."',
  19. subscribe='".$data['subscribe']."' WHERE id='".$_SESSION['userid']."';");
  20. /*$this->execute("UPDATE users SET
  21. username='".$data['username']."',
  22. firstname='".$data['fname']."',
  23. lastname='".$data['lname']."',
  24. email='".$data['email']."',
  25. delivery_country='".$data['country']."',
  26. delivery_postal_code='".$data['zip']."',
  27. delivery_settlement='".$data['city']."',
  28. delivery_address='".$data['street']."',
  29. delivery_region='".$data['state']."', subscribe='".$data['subscribe']."' WHERE id='".$_SESSION['userid']."';");*/
  30. return true;
  31. }
  32. public function savePass($pass) {
  33. if ($pass!=='') {
  34. $pass = $this->escapeString($pass);
  35. $newpass = hash('ripemd160',$pass);
  36. $this->execute("UPDATE users SET pass='".$newpass."' WHERE id='".$_SESSION['userid']."';");
  37. return true;
  38. }
  39. else {
  40. return false;
  41. }
  42. }
  43. public function checkPass($pass) {
  44. if ($pass!=='') {
  45. $pass = $this->escapeString($pass);
  46. $newpass = hash('ripemd160',$pass);
  47. $check = $this->query("SELECT * FROm users WHERE pass='".$newpass."' AND id='".$_SESSION['userid']."';");
  48. if (sizeof($check)>0) {
  49. return 'ok';
  50. }
  51. else {
  52. return 'error';
  53. }
  54. }
  55. else {
  56. return 'error';
  57. }
  58. }
  59. public function save_search($query) {
  60. $query = serialize($query);
  61. if ($query!='') {
  62. $this->execute("INSERT INTO saved_search SET
  63. sch_query='".$query."',
  64. sch_userid='".$_SESSION['userid']."';");
  65. return true;
  66. }
  67. else {
  68. return false;
  69. }
  70. }
  71. public function deleteSearch($id) {
  72. $id = $this->escapeString($id);
  73. if ($id!='') {
  74. $this->execute("DELETE FROM saved_search WHERE sch_id='".$id."';");
  75. return true;
  76. }
  77. else {
  78. return false;
  79. }
  80. }
  81. public function check_favorite($property_id) {
  82. $property_id = $this->escapeString($property_id);
  83. $check = $this->query("SELECT * FROM saved_properties WHERE
  84. sp_userid='".$_SESSION['userid']."' AND
  85. sp_property_id='".$property_id."' AND
  86. sp_status='1';");
  87. if (sizeof($check)>0) {
  88. return true;
  89. }
  90. else {
  91. return false;
  92. }
  93. }
  94. public function add_to_favorites($property_id) {
  95. $property_id = $this->escapeString($property_id);
  96. if ($property_id!='' && !$this->check_favorite($property_id)) {
  97. $this->execute("INSERT INTO saved_properties SET
  98. sp_userid='".$_SESSION['userid']."',
  99. sp_property_id='".$property_id."';");
  100. return true;
  101. }
  102. else {
  103. return false;
  104. }
  105. }
  106. public function getUserFavoritePropertiesCount($userid) {
  107. $userid = $this->escapeString($userid);
  108. if ($userid!='') {
  109. $check = $this->query("SELECT * FROM saved_properties WHERE
  110. sp_userid='".$_SESSION['userid']."' AND
  111. sp_status='1';");
  112. return sizeof($check);
  113. }
  114. else {
  115. return false;
  116. }
  117. }
  118. public function getUserFavoriteAgentsCount($userid) {
  119. $userid = $this->escapeString($userid);
  120. if ($userid!='') {
  121. $check = $this->query("SELECT * FROM saved_agents WHERE
  122. sp_userid='".$_SESSION['userid']."' AND
  123. sp_status='1';");
  124. return sizeof($check);
  125. }
  126. else {
  127. return false;
  128. }
  129. }
  130. public function getUserFavoriteOfficesCount($userid) {
  131. $userid = $this->escapeString($userid);
  132. if ($userid!='') {
  133. $check = $this->query("SELECT * FROM saved_offices WHERE
  134. sp_userid='".$_SESSION['userid']."' AND
  135. sp_status='1';");
  136. return sizeof($check);
  137. }
  138. else {
  139. return false;
  140. }
  141. }
  142. public function check_agent_favorite($agent_id) {
  143. $agent_id = $this->escapeString($agent_id);
  144. $check = $this->query("SELECT * FROM saved_agents WHERE
  145. sp_userid='".$_SESSION['userid']."' AND
  146. sp_agent_id='".$agent_id."' AND
  147. sp_status='1';");
  148. if (sizeof($check)>0) {
  149. return true;
  150. }
  151. else {
  152. return false;
  153. }
  154. }
  155. public function add_agent_to_favorites($agent_id) {
  156. $agent_id = $this->escapeString($agent_id);
  157. if ($agent_id!='' && !$this->check_agent_favorite($agent_id)) {
  158. $this->execute("INSERT INTO saved_agents SET
  159. sp_userid='".$_SESSION['userid']."',
  160. sp_agent_id='".$agent_id."';");
  161. return true;
  162. }
  163. else {
  164. return false;
  165. }
  166. }
  167. public function check_office_favorite($office_id) {
  168. $office_id = $this->escapeString($office_id);
  169. $check = $this->query("SELECT * FROM saved_offices WHERE
  170. sp_userid='".$_SESSION['userid']."' AND
  171. sp_office_id='".$office_id."' AND
  172. sp_status='1';");
  173. if (sizeof($check)>0) {
  174. return true;
  175. }
  176. else {
  177. return false;
  178. }
  179. }
  180. public function add_office_to_favorites($office_id) {
  181. $office_id = $this->escapeString($office_id);
  182. if ($office_id!='' && !$this->check_office_favorite($office_id)) {
  183. $this->execute("INSERT INTO saved_offices SET
  184. sp_userid='".$_SESSION['userid']."',
  185. sp_office_id='".$office_id."';");
  186. return true;
  187. }
  188. else {
  189. return false;
  190. }
  191. }
  192. public function getProperty($id) {
  193. if ($id!=='') {
  194. $id = $this->escapeString($id);
  195. $res = $this->query("SELECT *,getimgurl(indexkep,'ingatlan') AS indexkep FROM hiper_ingatlan WHERE id='".$id."' AND (rockhomera_mehet='1' OR rockhomera_mehet='0');");
  196. if (sizeof($res)>0) {
  197. return $res[0];
  198. }
  199. else {
  200. return false;
  201. }
  202. }
  203. else {
  204. return false;
  205. }
  206. }
  207. public function getAgent($id) {
  208. if ($id!=='') {
  209. $id = $this->escapeString($id);
  210. $res = $this->query("SELECT * FROM hiper_munkatars WHERE id='".$id."';");
  211. if (sizeof($res)>0) {
  212. return $res[0];
  213. }
  214. else {
  215. return false;
  216. }
  217. }
  218. else {
  219. return false;
  220. }
  221. }
  222. public function getOffice($id) {
  223. if ($id!=='') {
  224. $id = $this->escapeString($id);
  225. $res = $this->query("SELECT * FROM hiper_iroda WHERE id='".$id."';");
  226. if (sizeof($res)>0) {
  227. return $res[0];
  228. }
  229. else {
  230. return false;
  231. }
  232. }
  233. else {
  234. return false;
  235. }
  236. }
  237. public function getPropertyListByID($userid) {
  238. $userid = $this->escapeString($userid);
  239. if ($userid!='') {
  240. $check = $this->query("SELECT * FROM saved_properties WHERE sp_userid='".$userid."' AND sp_status='1' ORDER BY sp_createdate DESC;");
  241. foreach ($check as $row) {
  242. $list[] = $row->sp_property_id;
  243. }
  244. if (is_array($list)) {
  245. foreach ($list as $item) {
  246. $results[] = $this->getProperty($item);
  247. }
  248. return $results;
  249. }
  250. else {
  251. return false;
  252. }
  253. }
  254. else {
  255. return false;
  256. }
  257. }
  258. public function getAgentListByID($userid) {
  259. $userid = $this->escapeString($userid);
  260. if ($userid!='') {
  261. $check = $this->query("SELECT * FROM saved_agents WHERE sp_userid='".$userid."' AND sp_status='1' ORDER BY sp_createdate DESC;");
  262. foreach ($check as $row) {
  263. $list[] = $row->sp_agent_id;
  264. }
  265. if (is_array($list)) {
  266. foreach ($list as $item) {
  267. $results[] = $this->getAgent($item);
  268. }
  269. return $results;
  270. }
  271. else {
  272. return false;
  273. }
  274. }
  275. else {
  276. return false;
  277. }
  278. }
  279. public function getOfficesListByID($userid) {
  280. $userid = $this->escapeString($userid);
  281. if ($userid!='') {
  282. $check = $this->query("SELECT * FROM saved_offices WHERE sp_userid='".$userid."' AND sp_status='1' ORDER BY sp_createdate DESC;");
  283. foreach ($check as $row) {
  284. $list[] = $row->sp_office_id;
  285. }
  286. if (is_array($list)) {
  287. foreach ($list as $item) {
  288. $results[] = $this->getOffice($item);
  289. }
  290. return $results;
  291. }
  292. else {
  293. return false;
  294. }
  295. }
  296. else {
  297. return false;
  298. }
  299. }
  300. public function getUserFavoriteSearchesCount($userid) {
  301. $result = $this->query("SELECT sch_id FROM saved_search WHERE sch_userid='".$userid."' AND sch_status='1';");
  302. return sizeof($result);
  303. }
  304. public function getSearchesListByID($userid) {
  305. $result = $this->query("SELECT * FROM saved_search WHERE sch_userid='".$userid."' AND sch_status='1';");
  306. return $result;
  307. }
  308. public function deleteProfileProperty($id) {
  309. $id = $this->escapeString($id);
  310. if ($id!='') {
  311. $this->execute("DELETE FROM saved_properties WHERE sp_property_id='".$id."' AND sp_userid='".$_SESSION['userid']."';");
  312. return true;
  313. }
  314. else {
  315. return false;
  316. }
  317. }
  318. public function deleteProfileOffice($id) {
  319. $id = $this->escapeString($id);
  320. if ($id!='') {
  321. $this->execute("DELETE FROM saved_offices WHERE sp_office_id='".$id."' AND sp_userid='".$_SESSION['userid']."';");
  322. return true;
  323. }
  324. else {
  325. return false;
  326. }
  327. }
  328. public function deleteProfileAgent($id) {
  329. $id = $this->escapeString($id);
  330. if ($id!='') {
  331. $this->execute("DELETE FROM saved_agents WHERE sp_agent_id='".$id."' AND sp_userid='".$_SESSION['userid']."';");
  332. return true;
  333. }
  334. else {
  335. return false;
  336. }
  337. }
  338. }