common.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <?php
  2. class common {
  3. static function dbconnect() {
  4. global $config;
  5. global $conn;
  6. $conn = mysqli_connect($config['db_host'],$config['db_username'],$config['db_password'],$config['db_name']);
  7. mysqli_query($conn,"SET NAMES utf8");
  8. mysqli_set_charset($conn, 'utf8mb4');
  9. return true;
  10. }
  11. static function dbconnect2() {
  12. global $config;
  13. global $conn;
  14. $conn = mysqli_connect($config['db_host'],$config['db_username'],$config['db_password'],'rockhome_backend');
  15. mysqli_query($conn,"SET NAMES utf8");
  16. mysqli_set_charset($conn, 'utf8mb4');
  17. return true;
  18. }
  19. static function checkIPAddress() {
  20. $ip = $this->getIPAddress();
  21. if ($ip!='') {
  22. return true;
  23. }
  24. else {
  25. return false;
  26. }
  27. }
  28. static function getIPAddress() {
  29. return $_SERVER['REMOTE_ADDR'];
  30. }
  31. static function validate_ip($ip) {
  32. if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
  33. return false;
  34. }
  35. return true;
  36. }
  37. static function getMainCategories() {
  38. self::dbconnect();
  39. global $conn;
  40. $res = mysqli_query($conn,"select * from azonics_categories where category_status='0' order by category_id asc;");
  41. if (mysqli_num_rows($res)>0) {
  42. while ($row = mysqli_fetch_object($res)) {
  43. $menu[] = $row;
  44. }
  45. }
  46. return $menu;
  47. }
  48. static function checkAgentInFavorites($agentid) {
  49. self::dbconnect();
  50. global $conn;
  51. $res = mysqli_query($conn,"select * from saved_agents where sp_userid='".$_SESSION['userid']."' and sp_agent_id='".$agentid."' and sp_status='1';");
  52. if (mysqli_num_rows($res)>0) {
  53. return true;
  54. }
  55. else {
  56. return false;
  57. }
  58. }
  59. static function checkOfficeInFavorites($officeid) {
  60. self::dbconnect();
  61. global $conn;
  62. $res = mysqli_query($conn,"select * from saved_offices where sp_userid='".$_SESSION['userid']."' and sp_office_id='".$officeid."' and sp_status='1';");
  63. if (mysqli_num_rows($res)>0) {
  64. return true;
  65. }
  66. else {
  67. return false;
  68. }
  69. }
  70. static function get_user_data($userid) {
  71. self::dbconnect();
  72. global $conn;
  73. if ($userid!='') {
  74. $res = mysqli_query($conn,"SELECT * FROM users WHERE id='".$userid."';");
  75. if (mysqli_num_rows($res)>0) {
  76. return mysqli_fetch_object($res);
  77. }
  78. else {
  79. return false;
  80. }
  81. }
  82. else {
  83. return false;
  84. }
  85. }
  86. static function checkPropertyInFavorites($propertyID) {
  87. self::dbconnect();
  88. global $conn;
  89. $res = mysqli_query($conn,"select * from saved_properties where sp_userid='".$_SESSION['userid']."' and sp_property_id='".$propertyID."' and sp_status='1';");
  90. if (mysqli_num_rows($res)>0) {
  91. return true;
  92. }
  93. else {
  94. return false;
  95. }
  96. }
  97. static function getUsernameByUserID($uid='') {
  98. self::dbconnect();
  99. global $conn;
  100. if ($uid) {
  101. $res = mysqli_query($conn,"select * from azonics_users where user_id='".$uid."';");
  102. if (mysqli_num_rows($res)>0) {
  103. $row = mysqli_fetch_array($res);
  104. return $row['user_nick'];
  105. }
  106. else {
  107. return '';
  108. }
  109. }
  110. else {
  111. return false;
  112. }
  113. }
  114. static function getPropertyImagesCount($id) {
  115. self::dbconnect2();
  116. global $conn;
  117. if ($id!=='') {
  118. $res = mysqli_query($conn,"SELECT * FROM hiper_ingatlan_kep WHERE regszam='".$id."' ORDER BY sorrend ASC;");
  119. return mysqli_num_rows($res);
  120. }
  121. else {
  122. return 0;
  123. }
  124. }
  125. static function getOfficeName($officeID) {
  126. self::dbconnect();
  127. global $conn;
  128. if ($officeID!='') {
  129. $res = mysqli_query($conn,"SELECT * FROM hiper_iroda WHERE azonosito='".$officeID."';");
  130. if (mysqli_num_rows($res)>0) {
  131. $row = mysqli_fetch_array($res);
  132. return $row['nev'];
  133. }
  134. else {
  135. return false;
  136. }
  137. }
  138. else {
  139. return false;
  140. }
  141. }
  142. static function get_image_url($fname) {
  143. $maindir = substr($fname,1,3);
  144. $subdir = substr($fname,1,5);
  145. //return 'https://prod.rockhome.hu:8445/pictures/ingatlan/'.$maindir.'/'.$subdir.'/'.$fname;
  146. return 'https://prod.rockhome.hu'.$fname;
  147. }
  148. static function get_image_url_mark($fname) {
  149. return 'https://prod.rockhome.hu'.$fname;
  150. }
  151. static function url_exists($url) {
  152. $file = $url;
  153. $file_headers = @get_headers($file);
  154. if(!$file_headers || stristr($file_headers[0],"404 Not Found")) {
  155. $exists = false;
  156. }
  157. else {
  158. $exists = true;
  159. }
  160. return $exists;
  161. }
  162. static function getOfficeRate($id,$justVotesNumber=false) {
  163. self::dbconnect();
  164. global $conn;
  165. if ($id!=='') {
  166. $res = mysqli_query($conn,"SELECT SUM(rate) AS maxpoints, COUNT(rate) AS votes FROM iroda_ratings WHERE iroda='".$id."' AND statusz='1';");
  167. if (mysqli_num_rows($res)>0) {
  168. $row = mysqli_fetch_array($res);
  169. $rate = round($row['maxpoints']/$row['votes']);
  170. if ($justVotesNumber) {
  171. return $row['votes'];
  172. }
  173. else {
  174. return $rate;
  175. }
  176. }
  177. else {
  178. return 0;
  179. }
  180. }
  181. else {
  182. return 0;
  183. }
  184. }
  185. static function getTitleByURL() {
  186. self::dbconnect();
  187. global $conn;
  188. $temp = explode('?',$_SERVER['REQUEST_URI']);
  189. $res = mysqli_query($conn,"SELECT * FROM azonics_news WHERE slide_title='".$temp[0]."';");
  190. if (mysqli_num_rows($res)>0 && $temp[0]!='/') {
  191. $row = mysqli_fetch_array($res);
  192. return $row['slide_subtitle'];
  193. }
  194. else {
  195. return 'Rock Home ingatlanok';
  196. }
  197. }
  198. static function getKeywordsByURL() {
  199. self::dbconnect();
  200. global $conn;
  201. $temp = explode('?',$_SERVER['REQUEST_URI']);
  202. $res = mysqli_query($conn,"SELECT * FROM azonics_news WHERE slide_title='".$temp[0]."';");
  203. if (mysqli_num_rows($res)>0 && $temp[0]!='/') {
  204. $row = mysqli_fetch_array($res);
  205. return $row['slide_buttontitle'];
  206. }
  207. else {
  208. return 'Rock Home, ingatlanok';
  209. }
  210. }
  211. static function getDescriptionByURL() {
  212. self::dbconnect();
  213. global $conn;
  214. $temp = explode('?',$_SERVER['REQUEST_URI']);
  215. $res = mysqli_query($conn,"SELECT * FROM azonics_news WHERE slide_title='".$temp[0]."';");
  216. if (mysqli_num_rows($res)>0 && $temp[0]!='/') {
  217. $row = mysqli_fetch_array($res);
  218. return $row['slide_buttonURL'];
  219. }
  220. else {
  221. return 'A Rock Home dinamikusan növekvő ingatlanhálózata magas szinvonalú és emberközpontú szolgáltatásokkal vár. Lakáseladás, kiadás vagy vétel? Velünk biztosan jól jársz! Új hangot hozunk a hazai ingatlanközvetítésbe - okosabban, gyorsabban, személyesebben - és persze rockosabban.';
  222. }
  223. }
  224. static function getAgentRate($id,$justVotesNumber=false) {
  225. self::dbconnect();
  226. global $conn;
  227. if ($id!=='') {
  228. $res = mysqli_query($conn,"SELECT SUM(rate) AS maxpoints, COUNT(rate) AS votes FROM munkatars_ratings WHERE munkatars='".$id."' AND statusz='1';");
  229. if (mysqli_num_rows($res)>0) {
  230. $row = mysqli_fetch_array($res);
  231. $rate = round($row['maxpoints']/$row['votes']);
  232. if ($justVotesNumber==true) {
  233. return $row['votes'];
  234. }
  235. else {
  236. return $rate;
  237. }
  238. }
  239. else {
  240. return 0;
  241. }
  242. }
  243. else {
  244. return 0;
  245. }
  246. }
  247. static function getErtekesitesTipusOptions($selected='') {
  248. }
  249. static function getKey($key,$val) {
  250. self::dbconnect2();
  251. global $conn;
  252. if ($key!='' && $val!='') {
  253. $res = mysqli_query($conn,"SELECT `config_value` AS emelet FROM `dictionary` WHERE `group`='".$key."' AND `config_key`='".$val."';") or die(mysqli_error($conn));
  254. if (mysqli_num_rows($res)>0) {
  255. $row = mysqli_fetch_array($res);
  256. return $row['emelet'];
  257. }
  258. else {
  259. return false;
  260. }
  261. }
  262. else {
  263. return false;
  264. }
  265. }
  266. static function getPropertyTeaser($property,$showAddress=true) {
  267. if ($property->ertekesites=='elado') {
  268. $result = 'Eladó';
  269. }
  270. else {
  271. $result = 'Kiadó';
  272. }
  273. if ($property->tipus=='tarsashazi') {
  274. $result.= ' lakás';
  275. }
  276. elseif ($property->tipus=='csaladihaz') {
  277. $result.= ' családi ház';
  278. }
  279. elseif ($property->tipus=='epuletresz') {
  280. $result.= ' épületrész';
  281. }
  282. elseif ($property->tipus=='hazresz') {
  283. $result.= ' házrész';
  284. }
  285. elseif ($property->tipus=='ikerhaz') {
  286. $result.= ' ikerház';
  287. }
  288. elseif ($property->tipus=='onalloepulet') {
  289. $result.= ' önálló épület';
  290. }
  291. elseif ($property->tipus=='teljesepulet' && $property->jelleg!='telek') {
  292. $result.= ' teljes épület';
  293. }
  294. elseif ($property->tipus=='beruhazasi') {
  295. $result.= ' beruházás';
  296. }
  297. elseif ($property->jelleg=='garazs') {
  298. $result.= ' garázs';
  299. }
  300. elseif ($property->jelleg=='kereskedelmi') {
  301. $result.= ' kereskedelmi';
  302. }
  303. elseif ($property->jelleg=='mezogazdasagi') {
  304. $result.= ' mezőgazdasági';
  305. }
  306. elseif ($property->tipus=='tarolo') {
  307. $result.= ' tároló';
  308. }
  309. elseif ($property->jelleg=='telek') {
  310. $result.= ' telek';
  311. }
  312. /*if ($showAddress) {
  313. if (stristr($property->telepules,'Budapest')) {
  314. $result.= ' '.$property->telepules.'. kerület';
  315. }
  316. else {
  317. $result.= ' '.$property->telepules;
  318. }
  319. }*/
  320. return $result;
  321. }
  322. static function getPageSlug($pageID) {
  323. self::dbconnect();
  324. global $conn;
  325. if ($pageID!='') {
  326. $res = mysqli_query($conn,"SELECT page_slug FROM azonics_pages WHERE page_id='".$pageID."';");
  327. if (mysqli_num_rows($res)>0) {
  328. $row = mysqli_fetch_array($res);
  329. return $row['page_slug'];
  330. }
  331. else {
  332. return false;
  333. }
  334. }
  335. else {
  336. return false;
  337. }
  338. }
  339. static function generateSlug($key) {
  340. $key = strtolower($key);
  341. $key = str_replace(" ","-",$key);
  342. $key = str_replace(".","",$key);
  343. $key = str_replace("(","-",$key);
  344. $key = str_replace(")","-",$key);
  345. $accented = array( "á", "é", "í", "ó", "ö", "ő", "ú", "ü", "ű" );
  346. $mask = array( "a", "e", "i", "o", "o", "o", "u", "u", "u" );
  347. $key = str_replace($accented,$mask,$key);
  348. if (stristr($key,'budapest')) {
  349. $roman = array(
  350. "budapest-i",
  351. "budapest-ii",
  352. "budapest-iii",
  353. "budapest-iv",
  354. "budapest-v",
  355. "budapest-vi",
  356. "budapest-vii",
  357. "budapest-viii",
  358. "budapest-ix",
  359. "budapest-x",
  360. "budapest-xi",
  361. "budapest-xii",
  362. "budapest-xiii",
  363. "budapest-xiv",
  364. "budapest-xv",
  365. "budapest-xvi",
  366. "budapest-xvii",
  367. "budapest-xviii",
  368. "budapest-xix",
  369. "budapest-xx",
  370. "budapest-xxi",
  371. "budapest-xxii",
  372. "budapest-xxiii");
  373. $arab = array(
  374. "budapest-01",
  375. "budapest-02",
  376. "budapest-03",
  377. "budapest-04",
  378. "budapest-05",
  379. "budapest-06",
  380. "budapest-07",
  381. "budapest-08",
  382. "budapest-09",
  383. "budapest-10",
  384. "budapest-11",
  385. "budapest-12",
  386. "budapest-13",
  387. "budapest-14",
  388. "budapest-15",
  389. "budapest-16",
  390. "budapest-17",
  391. "budapest-18",
  392. "budapest-19",
  393. "budapest-20",
  394. "budapest-21",
  395. "budapest-22",
  396. "budapest-23"
  397. );
  398. $key = str_replace($arab,$roman,$key);
  399. $key.= '-kerulet';
  400. }
  401. return $key;
  402. }
  403. }