agents_model.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <?php
  2. class agents_model extends Model {
  3. public function getAgentsByOffice($id) {
  4. if ($_SESSION['storedAgentOrderField']=='') $_SESSION['storedAgentOrderField'] = 'nev';
  5. if ($_SESSION['storedAgentOrderDirection']=='') $_SESSION['storedAgentOrderDirection'] = 'ASC';
  6. $id = $this->escapeString($id);
  7. if ($id!=='') {
  8. $result = $this->query("SELECT * FROM hiper_munkatars WHERE iroda='".$id."' AND aktiv='1' ORDER BY ".$_SESSION['storedAgentOrderField']." ".$_SESSION['storedAgentOrderDirection'].";");
  9. if (sizeof($result)>0) {
  10. return $result;
  11. }
  12. else {
  13. return false;
  14. }
  15. }
  16. else {
  17. return false;
  18. }
  19. }
  20. public function getAgentsList() {
  21. if ($_SESSION['storedAgentOrderField']=='') $_SESSION['storedAgentOrderField'] = 'nev';
  22. if ($_SESSION['storedAgentOrderDirection']=='') $_SESSION['storedAgentOrderDirection'] = 'ASC';
  23. $result = $this->query("SELECT * FROM hiper_munkatars WHERE aktiv='1' ORDER BY ".$_SESSION['storedAgentOrderField']." ".$_SESSION['storedAgentOrderDirection'].";");
  24. if (sizeof($result)>0) {
  25. return $result;
  26. }
  27. else {
  28. return false;
  29. }
  30. }
  31. public function getAgentsListSearch($search) {
  32. if ($_SESSION['storedAgentOrderField']=='') $_SESSION['storedAgentOrderField'] = 'nev';
  33. if ($_SESSION['storedAgentOrderDirection']=='') $_SESSION['storedAgentOrderDirection'] = 'ASC';
  34. if ($_SESSION['activeOffice']!='') {
  35. $tempSQL = " AND iroda='".$_SESSION['activeOffice']."'";
  36. }
  37. if ($search['city']!='') {
  38. $list = explode(",",$search['city']);
  39. $cities = "";
  40. foreach ($list as $city) {
  41. $cities.= "'".$city."',";
  42. }
  43. $cities = rtrim($cities,',');
  44. $tempSQL.= " AND cim_telepules IN (".$cities.")";
  45. }
  46. if ($search['name']!='') {
  47. $list = explode(",",$search['name']);
  48. $names = "";
  49. foreach ($list as $name) {
  50. $names.= "'".$name."',";
  51. }
  52. $names = rtrim($names,',');
  53. $tempSQL.= " AND nev IN (".$names.")";
  54. }
  55. $result = $this->query("SELECT * FROM hiper_munkatars WHERE aktiv='1'".$tempSQL." ORDER BY ".$_SESSION['storedAgentOrderField']." ".$_SESSION['storedAgentOrderDirection'].";");
  56. //die("SELECT * FROM hiper_munkatars WHERE aktiv='1'".$tempSQL." ORDER BY ".$_SESSION['storedAgentOrderField']." ".$_SESSION['storedAgentOrderDirection'].";");
  57. if (sizeof($result)>0) {
  58. return $result;
  59. }
  60. else {
  61. return false;
  62. }
  63. }
  64. public function getAgentsCountSearch($resultset) {
  65. if (is_array($resultset)) {
  66. return count($resultset);
  67. }
  68. else {
  69. return 0;
  70. }
  71. }
  72. public function getOffice($id) {
  73. $id = $this->escapeString($id);
  74. if ($id!=='') {
  75. $result = $this->query("SELECT * FROM hiper_iroda WHERE azonosito='".$id."';");
  76. if (sizeof($result)>0) {
  77. return $result[0];
  78. }
  79. else {
  80. return false;
  81. }
  82. }
  83. else {
  84. return false;
  85. }
  86. }
  87. public function getAgentsCountByOffice($id) {
  88. if ($_SESSION['storedAgentOrderField']=='') $_SESSION['storedAgentOrderField'] = 'nev';
  89. if ($_SESSION['storedAgentOrderDirection']=='') $_SESSION['storedAgentOrderDirection'] = 'ASC';
  90. $id = $this->escapeString($id);
  91. if ($id!=='') {
  92. $result = $this->query("SELECT * FROM hiper_munkatars WHERE iroda='".$id."' AND aktiv='1' ORDER BY ".$_SESSION['storedAgentOrderField']." ".$_SESSION['storedAgentOrderDirection'].";");
  93. return sizeof($result);
  94. }
  95. else {
  96. return false;
  97. }
  98. }
  99. public function getAgentsCount() {
  100. if ($_SESSION['storedAgentOrderField']=='') $_SESSION['storedAgentOrderField'] = 'nev';
  101. if ($_SESSION['storedAgentOrderDirection']=='') $_SESSION['storedAgentOrderDirection'] = 'ASC';
  102. $result = $this->query("SELECT * FROM hiper_munkatars WHERE aktiv='1' ORDER BY ".$_SESSION['storedAgentOrderField']." ".$_SESSION['storedAgentOrderDirection'].";");
  103. return sizeof($result);
  104. }
  105. public function getAgent($id) {
  106. $id = $this->escapeString($id);
  107. if ($id!=='') {
  108. $result = $this->query("SELECT * FROM hiper_munkatars WHERE id='".$id."';");
  109. if (sizeof($result)>0) {
  110. return $result[0];
  111. }
  112. else {
  113. return false;
  114. }
  115. }
  116. else {
  117. return false;
  118. }
  119. }
  120. public function checkOffice($id) {
  121. $check = $this->query("SELECT * FROM irodak where office_id='".$id."';");
  122. if ($check[0]->active=='1') {
  123. return true;
  124. }
  125. else if ($check[0]->active=='0') {
  126. return false;
  127. }
  128. else {
  129. return true;
  130. }
  131. }
  132. public function getPropertiesList($id) {
  133. $id = $this->escapeString($id);
  134. if ($id!=='') {
  135. $result = $this->query("SELECT *,getimgurl(indexkep,'ingatlan') AS indexkep FROM hiper_ingatlan WHERE tanacsado='".$id."' AND statusz='aktualis' AND rockhomera_mehet='1' ORDER BY letrehozva DESC;");
  136. if (sizeof($result)>0) {
  137. return $result;
  138. }
  139. else {
  140. return false;
  141. }
  142. }
  143. else {
  144. return false;
  145. }
  146. }
  147. public function getPropertiesListShort($id) {
  148. $id = $this->escapeString($id);
  149. if ($id!=='') {
  150. $result = $this->query("SELECT *,getimgurl(indexkep,'ingatlan') AS indexkep FROM hiper_ingatlan WHERE tanacsado='".$id."' AND statusz='aktualis' AND rockhomera_mehet='1' ORDER BY letrehozva DESC LIMIT 0,3;");
  151. if (sizeof($result)>0) {
  152. return $result;
  153. }
  154. else {
  155. return false;
  156. }
  157. }
  158. else {
  159. return false;
  160. }
  161. }
  162. public function getAgentPropertiesCount($agent_code) {
  163. $agent_code = $this->escapeString($agent_code);
  164. if ($agent_code!=='') {
  165. $result = $this->query("SELECT * FROM hiper_ingatlan WHERE tanacsado='".$agent_code."' AND statusz='aktualis' AND rockhomera_mehet='1' ORDER BY letrehozva DESC;");
  166. return sizeof($result);
  167. }
  168. else {
  169. return false;
  170. }
  171. }
  172. public function get_telepulesek() {
  173. $result = $this->query("SELECT cim_telepules FROM hiper_munkatars WHERE cim_telepules<>'' AND aktiv='1' GROUP BY cim_telepules ORDER BY cim_telepules ASC;");
  174. return $result;
  175. }
  176. public function get_names() {
  177. $result = $this->query("SELECT nev FROM hiper_munkatars WHERE nev<>'' AND aktiv='1' ORDER BY nev ASC;");
  178. return $result;
  179. }
  180. public function get_ertekesites_tipusok() {
  181. $result = $this->query("SELECT ertekesites FROM hiper_ingatlan WHERE ertekesites<>'' AND statusz='aktualis' AND (rockhomera_mehet='1' OR rockhomera_mehet='0') GROUP BY ertekesites ORDER BY ertekesites ASC;");
  182. return $result;
  183. }
  184. public function get_jelleg_tipusok() {
  185. $resultx = $this->query("SELECT tipus FROM hiper_ingatlan WHERE tipus<>'' AND statusz='aktualis' AND (rockhomera_mehet='1' OR rockhomera_mehet='0') GROUP BY tipus ORDER BY tipus ASC;");
  186. $resulty = $this->query("SELECT jelleg FROM hiper_ingatlan WHERE jelleg<>'lakoingatlan' AND statusz='aktualis' AND (rockhomera_mehet='1' OR rockhomera_mehet='0') GROUP BY jelleg ORDER BY jelleg ASC;");
  187. foreach ($resultx as $row) {
  188. $row->jelleg = 'Lakóingatlan - '.$row->tipus;
  189. $result[] = $row;
  190. }
  191. foreach ($resulty as $row) {
  192. $result[] = $row;
  193. }
  194. return $result;
  195. }
  196. public function get_properties_telepulesek() {
  197. $result = $this->query("SELECT telepules FROM hiper_ingatlan WHERE telepules<>'' AND statusz='aktualis' AND (rockhomera_mehet='1' OR rockhomera_mehet='0') GROUP BY telepules ORDER BY telepules ASC;");
  198. return $result;
  199. }
  200. public function get_property_list_by_filter($search) {
  201. $search = $this->escapeArray($search);
  202. $tempSQL = "SELECT *,getimgurl(indexkep,'ingatlan') AS indexkep FROM hiper_ingatlan WHERE statusz='aktualis' AND rockhomera_mehet='1'";
  203. if ($_SESSION['storedOrderField']=='') $_SESSION['storedOrderField'] = 'letrehozva';
  204. if ($_SESSION['storedOrderDirection']=='') $_SESSION['storedOrderDirection'] = 'DESC';
  205. if ($search['from']!='') {
  206. $tempSQL.= " AND tanacsado='".$search['agent']."'";
  207. if ($search['ertekesites']!='') $tempSQL.= " AND ertekesites='".$search['ertekesites']."'";
  208. if ($search['jelleg']!='') $tempSQL.= " AND jelleg='".$search['jelleg']."'";
  209. if ($search['tipus']!='') $tempSQL.= " AND tipus='".$search['tipus']."'";
  210. if ($search['city']!='') {
  211. $list = explode(",",$search['city']);
  212. $cities = "";
  213. foreach ($list as $city) {
  214. $cities.= "'".$city."',";
  215. }
  216. $cities = rtrim($cities,',');
  217. $tempSQL.= " AND telepules IN (".$cities.")";
  218. }
  219. if ($search['iranyar_min']!='') $tempSQL.= " AND iranyar>='".$search['iranyar_min']."'";
  220. if ($search['iranyar_max']!='') $tempSQL.= " AND iranyar<='".$search['iranyar_max']."'";
  221. if ($search['meret_netto_min']!='') $tempSQL.= " AND meret_netto>='".$search['meret_netto_min']."'";
  222. if ($search['meret_netto_max']!='') $tempSQL.= " AND meret_netto<='".$search['meret_netto_max']."'";
  223. if ($search['altipus']!='') {
  224. $list = explode(",",$search['altipus']);
  225. $altipusok = "";
  226. foreach ($list as $altipus) {
  227. $altipusok.= "'".$altipus."',";
  228. }
  229. $altipusok = rtrim($altipusok,',');
  230. $tempSQL.= " AND altipus IN (".$altipusok.")";
  231. }
  232. if ($search['jogi_statusz']!='') $tempSQL.= " AND jogi_statusz='".$search['jogi_statusz']."'";
  233. if ($search['szoba_min']!='') $tempSQL.= " AND szoba>='".$search['szoba_min']."'";
  234. if ($search['szoba_max']!='') $tempSQL.= " AND szoba<='".$search['szoba_max']."'";
  235. if ($search['kilatas']!='') {
  236. $list = explode(",",$search['kilatas']);
  237. $kilatasok = "";
  238. foreach ($list as $kilatas) {
  239. $kilatasok.= "'".$kilatas."',";
  240. }
  241. $kilatasok = rtrim($kilatasok,',');
  242. $tempSQL.= " AND kilatas IN (".$kilatasok.")";
  243. }
  244. if ($search['futes']!='') {
  245. $list = explode(",",$search['futes']);
  246. $futesek = "";
  247. foreach ($list as $futes) {
  248. $futesek.= "'".$futes."',";
  249. }
  250. $futesek = rtrim($futesek,',');
  251. $tempSQL.= " AND futes IN (".$futesek.")";
  252. }
  253. if ($search['tajolas']!='') {
  254. $list = explode(",",$search['tajolas']);
  255. $tajolasok = "";
  256. foreach ($list as $tajolas) {
  257. $tajolasok.= "'".$tajolas."',";
  258. }
  259. $tajolasok = rtrim($tajolasok,',');
  260. $tempSQL.= " AND tajolas IN (".$tajolasok.")";
  261. }
  262. if ($search['allapot']!='') {
  263. $list = explode(",",$search['allapot']);
  264. $allapotok = "";
  265. foreach ($list as $allapot) {
  266. $allapotok.= "'".$allapot."',";
  267. }
  268. $allapotok = rtrim($allapotok,',');
  269. $tempSQL.= " AND ingatlan_allapota IN (".$allapotok.")";
  270. }
  271. if ($search['kornyek']!='') {
  272. $list = explode(",",$search['kornyek']);
  273. $kornyekek = "";
  274. foreach ($list as $kornyek) {
  275. $kornyekek.= "'".$kornyek."',";
  276. }
  277. $kornyekek = rtrim($kornyekek,',');
  278. $tempSQL.= " AND kornyek IN (".$kornyekek.")";
  279. }
  280. if ($search['epites_eve_min']!='') $tempSQL.= " AND epites_eve>='".$search['epites_eve_min']."'";
  281. if ($search['epites_eve_max']!='') $tempSQL.= " AND epites_eve<='".$search['epites_eve_max']."'";
  282. if ($search['telek_min']!='') $tempSQL.= " AND meret_telek>='".$search['telek_min']."'";
  283. if ($search['telek_max']!='') $tempSQL.= " AND meret_telek<='".$search['telek_max']."'";
  284. if ($search['ferohely_garazs_min']!='') $tempSQL.= " AND ferohely_garazs>='".$search['ferohely_garazs_min']."'";
  285. if ($search['ferohely_garazs_max']!='') $tempSQL.= " AND ferohely_garazs<='".$search['ferohely_garazs_max']."'";
  286. if ($search['kulon_nyilo_szobak']=='1') $tempSQL.= " AND kulon_nyilo_szobak='1'";
  287. if ($search['terasz']=='1') $tempSQL.= " AND terasz='1'";
  288. if ($search['erkely']=='1') $tempSQL.= " AND erkely='1'";
  289. if ($search['pince']=='1') $tempSQL.= " AND pince='1'";
  290. if ($search['tarolo']=='1') $tempSQL.= " AND tarolo='1'";
  291. if ($search['garazs']=='1') $tempSQL.= " AND garazs='1'";
  292. if ($search['ferohely_fedettbeallo']=='1') $tempSQL.= " AND ferohely_fedettbeallo='1'";
  293. if ($search['kertkapcsolatos']=='1') $tempSQL.= " AND kertkapcsolatos='1'";
  294. if ($search['viz']=='1') $tempSQL.= " AND viz='1'";
  295. if ($search['gaz']=='1') $tempSQL.= " AND gaz='1'";
  296. if ($search['villany']=='1') $tempSQL.= " AND villany='1'";
  297. if ($search['csatorna']=='1') $tempSQL.= " AND csatorna='1'";
  298. if ($search['lift']=='1') $tempSQL.= " AND lift='1'";
  299. }
  300. $tempSQL.= " ORDER BY ".$_SESSION['storedOrderField']." ".$_SESSION['storedOrderDirection'].";";
  301. $querySQL = $tempSQL;
  302. $_SESSION['storedQuery'] = $querySQL;
  303. $result = $this->query($querySQL);
  304. return $result;
  305. }
  306. public function getAgentUserName($id) {
  307. $id = $this->escapeString($id);
  308. if ($id!=='') {
  309. $agent = $this->query("SELECT * FROM hiper_munkatars WHERE id='".$id."';");
  310. if (sizeof($agent)>0) {
  311. return $agent[0]->felhasznalonev;
  312. }
  313. else {
  314. return false;
  315. }
  316. }
  317. else {
  318. return false;
  319. }
  320. }
  321. public function get_agent_languages($nick) {
  322. $nick = $this->escapeString($nick);
  323. $langs = $this->query("SELECT * FROM hiper_munkatars_nyelv WHERE nick='".$nick."' AND nyelv>'0';");
  324. if (sizeof($langs)>0) {
  325. foreach ($langs as $lang) {
  326. switch ($lang->nyelv) {
  327. case '1': $result[] = 'Angol'; break;
  328. case '2': $result[] = 'Német'; break;
  329. case '3': $result[] = 'Spanyol'; break;
  330. case '4': $result[] = 'Francia'; break;
  331. case '5': $result[] = 'Olasz'; break;
  332. case '6': $result[] = 'Orosz'; break;
  333. }
  334. }
  335. return $result;
  336. }
  337. else {
  338. return false;
  339. }
  340. }
  341. public function get_comments($id) {
  342. $id = $this->escapeString($id);
  343. if ($id!='') {
  344. $result = $this->query("SELECT * FROM velemenyek WHERE agent_id='".$id."';");
  345. if (sizeof($result)>0) {
  346. return $result;
  347. }
  348. else {
  349. return false;
  350. }
  351. }
  352. else {
  353. return false;
  354. }
  355. }
  356. public function get_referens($id) {
  357. $id = $this->escapeString($id);
  358. if ($id!='') {
  359. $result = $this->query("SELECT * FROM referensek WHERE agent_id='".$id."';");
  360. if (sizeof($result)>0) {
  361. return $result[0];
  362. }
  363. else {
  364. return false;
  365. }
  366. }
  367. else {
  368. return false;
  369. }
  370. }
  371. }