· 9 years ago · May 17, 2017, 03:16 PM
1<?php error_reporting(0);
2/**
3 * Copyright 2014 Viaviweb.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 */
17
18
19#Admin Login
20
21
22
23
24function adminUser($username, $password){
25
26 $sql = "SELECT id,username FROM tbl_admin where username = '".$username."' and password = '".md5($password)."'";
27
28 $result = mysql_query($sql);
29 $num_rows = mysql_num_rows($result);
30 if ($num_rows > 0){
31 while ($row = mysql_fetch_array($result)){
32 echo $_SESSION['ADMIN_ID'] = $row['id'];
33 echo $_SESSION['ADMIN_USERNAME'] = $row['username'];
34
35
36 return true;
37 }
38 }
39
40}
41
42function select($table_name,$col= '',$val= '')
43{
44 $where = '';
45 if($col != '')
46 {
47 $where = 'where ' .$col .' = '.$val;
48 }
49 $sel = mysql_query("select * from $table_name $where ")or die(mysql_error());
50 return $sel;
51}
52# Insert Data
53function Insert($table, $data){
54
55 $fields = array_keys( $data );
56 $values = array_map( "mysql_real_escape_string", array_values( $data ) );
57 mysql_query( "INSERT INTO $table(".implode(",",$fields).") VALUES ('".implode("','", $values )."');") or die( mysql_error() );
58
59}
60
61
62
63// Update Data, Where clause is left optional
64function Update($table_name, $form_data, $where_clause='')
65{
66 // check for optional where clause
67 $whereSQL = '';
68 if(!empty($where_clause))
69 {
70 // check to see if the 'where' keyword exists
71 if(substr(strtoupper(trim($where_clause)), 0, 5) != 'WHERE')
72 {
73 // not found, add key word
74 $whereSQL = " WHERE ".$where_clause;
75 } else
76 {
77 $whereSQL = " ".trim($where_clause);
78 }
79 }
80 // start the actual SQL statement
81 $sql = "UPDATE ".$table_name." SET ";
82
83 // loop and build the column /
84 $sets = array();
85 foreach($form_data as $column => $value)
86 {
87 $sets[] = "`".$column."` = '".$value."'";
88 }
89 $sql .= implode(', ', $sets);
90
91 // append the where statement
92 $sql .= $whereSQL;
93
94 // run and return the query result
95 return mysql_query($sql);
96}
97
98
99
100//Delete Data, the where clause is left optional incase the user wants to delete every row!
101function Delete($table_name, $where_clause='')
102{
103 // check for optional where clause
104 $whereSQL = '';
105 if(!empty($where_clause))
106 {
107 // check to see if the 'where' keyword exists
108 if(substr(strtoupper(trim($where_clause)), 0, 5) != 'WHERE')
109 {
110 // not found, add keyword
111 $whereSQL = " WHERE ".$where_clause;
112 } else
113 {
114 $whereSQL = " ".trim($where_clause);
115 }
116 }
117 // build the query
118 $sql = "DELETE FROM ".$table_name.$whereSQL;
119
120 // run and return the query result resource
121 return mysql_query($sql);
122}
123
124//Select Data, Function(table,column_name,identifier)
125function Single($table,$tcol,$tid)
126{
127
128 /*Query and link identifier were in the wrong order*/
129 return mysql_query("SELECT * FROM ".$table." WHERE ".$tcol."=".$tid."");
130}
131
132
133//Get date
134function Viavi_Datetime() {
135 $tz_object = new DateTimeZone('Asia/Kolkata');
136 //date_default_timezone_set('Brazil/East');
137 $datetime = new DateTime();
138 $datetime->setTimezone($tz_object);
139return $datetime->format('Y\-m\-d\ h:i:s');
140}
141
142
143//F
144function Viavi_email()
145{
146 $headers = 'MIME-Version: 1.0' . "\r\n";
147 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
148
149 // Mail it
150 if(@mail($to, $subject, $message, $headers)){
151
152 $mail_send="OK";
153 return $mail_send;
154 }
155
156 else
157 {
158 $mail_send= "Fail";
159 return $mail_send;
160 }
161
162}
163
164
165function breadcrumbs(){
166 $path = $_SERVER["PHP_SELF"];
167 $parts = explode('/',$path);
168 if (count($parts) < 2)
169 {
170 echo("home");
171 }
172 else
173 {
174 echo ("<a href=\"/\">home</a> » ");
175 for ($i = 1; $i < count($parts); $i++)
176 {
177 if (!strstr($parts[$i],"."))
178 {
179 echo("<li><a href=\"");
180 for ($j = 0; $j <= $i; $j++) {echo $parts[$j]."/";};
181 echo("\">". str_replace('-', ' ', $parts[$i])."</a><span class='divider'>/</span></li>");
182 }
183 else
184 {
185 $str = $parts[$i];
186 $pos = strrpos($str,".");
187 $parts[$i] = substr($str, 0, $pos);
188 echo str_replace('-', ' ', $parts[$i]);
189 };
190 };
191 };
192}
193// get agents detail from database
194function get_agents_contant()
195{
196 $sql= "select * from agents";
197 $sel = mysql_query($sql);
198 return $sel;
199}
200
201// get about page detail from database
202
203function get_about_contant()
204{
205 $sql= "select * from about_us";
206 $sel = mysql_query($sql);
207 $data = mysql_fetch_assoc($sel);
208 return $data;
209}
210
211
212// add about page detail from database
213
214function addabout()
215{
216 if($_FILES['about_image']['name'] == '')
217 {
218 $image = $_POST['old_image'];
219 }
220 else
221 {
222 unlink('../images/'.$_POST['old_image']);
223 $image = time().'_'.$_FILES['about_image']['name'];
224 move_uploaded_file($_FILES['about_image']['tmp_name'],'../images/'.$image);
225 }
226 $description = addslashes($_POST['description']);
227 $id = $_POST['id'];
228
229
230 $sql= "update about_us set image='$image', contant='$description' where id = $id";
231 mysql_query($sql)or die(mysql_error());
232 echo "Add Detail Successfully";
233}
234function gat_agent_detail($id)
235{
236 $sql= "select * from agents where id = $id ";
237 $sel = mysql_query($sql);
238 $data = mysql_fetch_assoc($sel);
239 return $data;
240}
241function editagent()
242{
243 if($_FILES['agent_image']['name'] == '')
244 {
245 $image = $_POST['old_image'];
246 }
247 else
248 {
249 unlink('../images/'.$_POST['old_image']);
250 $image = time().'_'.$_FILES['agent_image']['name'];
251 move_uploaded_file($_FILES['agent_image']['tmp_name'],'../images/'.$image);
252 }
253 $id = $_POST['id'];
254 $name = $_POST['name'];
255 $description = $_POST['description'];
256 $phone = $_POST['phone'];
257
258 $sql= "update agents set name='$name', description='$description', phone= '$phone', image='$image' where id = $id";
259 mysql_query($sql)or die(mysql_error());
260}
261function get_contact_detail()
262{
263 $sql= "select * from contact_us";
264 $sel = mysql_query($sql);
265 $data = mysql_fetch_assoc($sel);
266 return $data;
267}
268function set_contact_detail()
269{
270 $lat = $_POST['Latitude'];
271 $long = $_POST['Longitude'];
272 $id = $_POST['id'];
273 $title = $_POST['ptitle'];
274
275 $sql = "update contact_us set latitude='$lat',longitude='$long',title = '$title' where id=$id ";
276 mysql_query($sql)or die(mysql_error());
277 //$_SESSION['amsg']= 'Save Changes Successfully';
278
279}
280function get_logo()
281{
282 $sql= "select * from general_setting where key1 = 'logo' ";
283 $sel = mysql_query($sql)or die(mysql_error());
284 $data = mysql_fetch_assoc($sel);
285 return $data;
286
287}
288function setlogo()
289{
290 if($_FILES['logo']['name'] == '')
291 {
292 $image = $_POST['old_image'];
293 }
294 else
295 {
296 unlink('../images/logo/'.$_POST['old_image']);
297 $image = time().'_'.$_FILES['logo']['name'];
298 move_uploaded_file($_FILES['logo']['tmp_name'],'../images/logo/'.$image);
299 }
300 $id = $_POST['id'];
301 $sql = "update general_setting set value='$image' where id=$id ";
302 mysql_query($sql)or die(mysql_error());
303
304}
305function get_fb()
306{
307 $sql= "select * from general_setting where key1 = 'fb' ";
308 $sel = mysql_query($sql)or die(mysql_error());
309 $data = mysql_fetch_assoc($sel);
310 return $data;
311
312
313}
314
315function get_twitter()
316{
317 $sql= "select * from general_setting where key1 = 'twitter' ";
318 $sel = mysql_query($sql)or die(mysql_error());
319 $data = mysql_fetch_assoc($sel);
320 return $data;
321
322
323}
324
325function get_linkdin()
326{
327 $sql= "select * from general_setting where key1 = 'linkdin' ";
328 $sel = mysql_query($sql)or die(mysql_error());
329 $data = mysql_fetch_assoc($sel);
330 return $data;
331
332
333}
334
335function get_instagram()
336{
337 $sql= "select * from general_setting where key1 = 'instagram' ";
338 $sel = mysql_query($sql)or die(mysql_error());
339 $data = mysql_fetch_assoc($sel);
340 return $data;
341
342
343}
344function setsociallink()
345{
346 $fid = $_POST['fid'];
347 $fb = $_POST['fb'];
348
349 $sql = "update general_setting set value='$fb' where id=$fid ";
350 mysql_query($sql)or die(mysql_error());
351 $tid = $_POST['tid'];
352 $twitter = $_POST['twitter'];
353
354 $sql = "update general_setting set value='$twitter' where id=$tid ";
355 mysql_query($sql)or die(mysql_error());
356
357 $lid = $_POST['lid'];
358 $linkd = $_POST['linkd'];
359
360 $sql = "update general_setting set value='$linkd' where id=$lid ";
361 mysql_query($sql)or die(mysql_error());
362
363 $iid = $_POST['iid'];
364 $instagram = $_POST['instagram'];
365
366 $sql = "update general_setting set value='$instagram' where id=$iid ";
367 mysql_query($sql)or die(mysql_error());
368
369}
370function get_address()
371{
372 $sql= "select * from general_setting where key1 = 'contact_add1' ";
373 $sel = mysql_query($sql)or die(mysql_error());
374 $data = mysql_fetch_assoc($sel);
375 return $data;
376
377}
378
379function get_address2()
380{
381 $sql= "select * from general_setting where key1 = 'contact_add2' ";
382 $sel = mysql_query($sql)or die(mysql_error());
383 $data = mysql_fetch_assoc($sel);
384 return $data;
385
386}
387
388function get_address3()
389{
390 $sql= "select * from general_setting where key1 = 'contact_add3' ";
391 $sel = mysql_query($sql)or die(mysql_error());
392 $data = mysql_fetch_assoc($sel);
393 return $data;
394
395}
396
397function get_address4()
398{
399 $sql= "select * from general_setting where key1 = 'contact_add4' ";
400 $sel = mysql_query($sql)or die(mysql_error());
401 $data = mysql_fetch_assoc($sel);
402 return $data;
403
404}
405function setcontact_address()
406{
407 $address1 = $_POST['address1'];
408 $add1 = $_POST['add1'];
409 $sql = "update general_setting set value='$address1' where id=$add1 ";
410 mysql_query($sql)or die(mysql_error());
411
412
413 $address2 = $_POST['address2'];
414 $add2 = $_POST['add2'];
415 $sql = "update general_setting set value='$address2' where id=$add2 ";
416 mysql_query($sql)or die(mysql_error());
417
418
419 $address3 = $_POST['address3'];
420 $add3 = $_POST['add3'];
421 $sql = "update general_setting set value='$address3' where id=$add3 ";
422 mysql_query($sql)or die(mysql_error());
423
424
425 $address4 = $_POST['address4'];
426 $add4 = $_POST['add4'];
427 $sql = "update general_setting set value='$address4' where id=$add4 ";
428 mysql_query($sql)or die(mysql_error());
429
430
431}
432function get_footer()
433{
434 $sql= "select * from general_setting where key1 = 'copyright' ";
435 $sel = mysql_query($sql)or die(mysql_error());
436 $data = mysql_fetch_assoc($sel);
437 return $data;
438
439}
440function set_footer()
441{
442
443
444 $footer = $_POST['footer'];
445 $id = $_POST['id'];
446 $sql = "update general_setting set value='$footer' where id=$id ";
447 mysql_query($sql)or die(mysql_error());
448
449
450}
451function get_property_contant()
452{
453 $sql= "select * from property_detail";
454 $sel = mysql_query($sql)or die(mysql_error());
455 return $sel;
456}
457function get_agent($id)
458{
459 $sql= "select * from agents where id = $id ";
460 $sel = mysql_query($sql)or die(mysql_error());
461 $data = mysql_fetch_assoc($sel);
462 return $data;
463
464}
465function gat_properties_detail($id)
466{
467 $sql= "select * from property_detail where pid = $id ";
468 $sel = mysql_query($sql)or die(mysql_error());
469 $data = mysql_fetch_assoc($sel);
470 return $data;
471}
472function Get_image($id)
473{
474
475 $sql= "select * from p_image where p_id = $id";
476 $sel = mysql_query($sql)or die(mysql_error());
477 return $sel;
478
479}
480function Deleteimage($id)
481{
482
483
484 $sql= "select * from p_image where image_id = $id";
485 $sel = mysql_query($sql)or die(mysql_error());
486 $data = mysql_fetch_assoc($sel);
487 unlink('../images/properties/'.$data['image']);
488 $sql= "delete from p_image where image_id = $id";
489 $sel = mysql_query($sql)or die(mysql_error());
490 return true;
491
492}
493function editproperty()
494{
495if(($_FILES['catalog_image']['name'][0]) != '')
496{
497 $pid = $_POST['pid'];
498
499 $ptitle = addslashes($_POST['ptitle']);
500 $pdetail = addslashes($_POST['pdetail']);
501 $plat = addslashes($_POST['lat']);
502 $plong = addslashes($_POST['long']);
503 $price = $_POST['pprice'];
504// $aid = $_POST['aid'];
505 $bedroom = $_POST['bedroom'];
506 $kitchen = $_POST['kitchen'];
507 $parking = $_POST['parking'];
508 $livingroom = $_POST['livingroom'];
509 $ptype = $_POST['ptype'];
510 $pfor = $_POST['pfor'];
511 $address = $_POST['add'];
512 $pimage=rand(0,99999)."_".$_FILES['catalog_image']['name'][0];
513 move_uploaded_file($_FILES['catalog_image']['tmp_name'][0],"../images/properties/".$pimage);
514
515 $sql = "update property_detail set
516 ptitle='$ptitle',pimage='$pimage',pdetail='$pdetail',plat='$plat',plong='$plong',pprice='$price',bedroom='$bedroom',kitchen='$kitchen',parking='$parking',livingroom='$livingroom',ptype='$ptype',pfor='$pfor',paddress='$address'
517 where pid = $pid ";
518 mysql_query($sql)or die(mysql_error());
519 $count = count($_FILES['catalog_image']['name']);
520
521 for($i=0;$i<$count;$i++)
522 {
523 print_r($_FILES['catalog_image']['name'][$i]);
524 // die();
525 $p_image=rand(0,99999)."_".$_FILES['catalog_image']['name'][$i];
526 move_uploaded_file($_FILES['catalog_image']['tmp_name'][$i],"../images/properties/".$p_image);
527 if($i == 0 )
528 {
529 $sql = "insert into p_image (p_id,image) values ('$pid','$pimage')";
530 mysql_query($sql)or die(mysql_error());
531 }
532 else
533 {
534 $sql = "insert into p_image (p_id,image) values ('$pid','$p_image')";
535 mysql_query($sql);
536 }
537 }
538}
539else
540{
541
542 $pid = $_POST['pid'];
543 $ptitle = $_POST['ptitle'];
544 $pdetail = $_POST['pdetail'];
545 $plat = $_POST['lat'];
546 $plong = $_POST['long'];
547 $price = $_POST['pprice'];
548// $aid = $_POST['aid'];
549 $bedroom = $_POST['bedroom'];
550 $kitchen = $_POST['kitchen'];
551 $parking = $_POST['parking'];
552 $livingroom = $_POST['livingroom'];
553 $ptype = $_POST['ptype'];
554 $pfor = $_POST['pfor'];
555 $address = $_POST['add'];
556// $pimage=rand(0,99999)."_".$_FILES['catalog_image']['name'][0];
557// move_uploaded_file($_FILES['catalog_image']['tmp_name'][0],"images/properties/".$pimage);
558
559 $sql = "update property_detail set
560 ptitle='$ptitle',pdetail='$pdetail',plat='$plat',plong='$plong',pprice='$price',bedroom='$bedroom',kitchen='$kitchen',parking='$parking',livingroom='$livingroom',ptype='$ptype',pfor='$pfor',paddress='$address'
561 where pid = $pid ";
562 mysql_query($sql)or die(mysql_error());
563
564
565}
566
567}
568function get_image_detail($id)
569{
570 $sql = "select * from p_image where image_id = $id";
571 $sel = mysql_query($sql)or die(mysql_error());
572 $data = mysql_fetch_assoc($sel);
573 $pid =$data['p_id'];
574 $sql2 = "select * from property_detail where pid = $pid";
575 $sel2 = mysql_query($sql2);
576 $data2 = mysql_fetch_assoc($sel2);
577
578
579 if($data['image'] == $data2['pimage'])
580 {
581
582 $dsql = "delete from p_image where image_id = $id";
583 mysql_query($dsql)or die(mysql_error());
584 unlink('../images/properties/'.$data['image']);
585 $sql3 = "select * from p_image where p_id = $pid";
586 $sel3 = mysql_query($sql3);
587 $data3 = mysql_fetch_assoc($sel3)or die(mysql_error());
588 if($data3['image'] == '')
589 {
590 $image = "";
591 $sql4 = "update property_detail set pimage='$image' where pid=$pid ";
592 $sel4 = mysql_query($sql4)or die(mysql_error());
593 }
594 else
595 {
596
597 $image = $data3['image'];
598 $sql4 = "update property_detail set pimage='$image' where pid=$pid ";
599 $sel4 = mysql_query($sql4)or die(mysql_error());
600
601 }
602 }
603 else
604 {
605 $dsql = "delete from p_image where image_id = $id";
606 mysql_query($dsql)or die(mysql_error());
607 }
608
609
610}
611function addagent()
612{
613$email = $_POST['email'];
614
615$sel = mysql_query("select * from agents where email like '$email' ");
616if(mysql_num_rows($sel)>0)
617{
618 return 0;
619 // header( "Location:addagents.php");
620
621}
622else
623{
624 $name = $_POST['name'];
625 $pass = $_POST['pass'];
626 $add = addslashes($_POST['add']);
627 $descrition = addslashes($_POST['description']);
628 $phone =$_POST['phone'];
629 $photo = time().'_'.$_FILES['photo']['name'];
630 move_uploaded_file($_FILES['photo']['tmp_name'],'../images/'.$photo);
631 $sql = "insert into agents (name,email,pass,address,description,phone,image,dt,status)
632 values ('$name','$email','$pass','$add','$descrition','$phone','$photo',now(),'0')";
633 mysql_query($sql)or die(mysql_error());
634 $_SESSION['amsg'] = "Account Create Successfully";
635 return 1;
636}
637
638}
639function addproperty()
640{
641$ptitle = addslashes($_POST['ptitle']);
642 $pdetail = addslashes($_POST['pdetail']);
643 $plat = $_POST['lat'];
644 $plong = $_POST['long'];
645
646 $price = $_POST['pprice'];
647 $aid = $_POST['aid'];
648
649 $bedroom = $_POST['bedroom'];
650 $kitchen = $_POST['kitchen'];
651 $parking = $_POST['parking'];
652 $livingroom = $_POST['livingroom'];
653
654 $ptype = $_POST['ptype'];
655
656 $pfor = $_POST['pfor'];
657 $address = $_POST['add'];
658 //$pimage = $_FILES['catalog_image']['name'][0];
659 $pimage=rand(0,99999)."_".$_FILES['catalog_image']['name'][0];
660 move_uploaded_file($_FILES['catalog_image']['tmp_name'][0],"../images/properties/".$pimage);
661
662 $sql = "insert into property_detail
663 (ptitle,pimage,pdetail,plat,plong,pprice,aid,bedroom,kitchen,parking,livingroom,ptype,pfor,status,dt,paddress) values
664 ('$ptitle','$pimage','$pdetail','$plat','$plong','$price','$aid','$bedroom','$kitchen','$parking','$livingroom','$ptype','$pfor','0',now(),'$address')";
665 $qur = mysql_query($sql)or die(mysql_error());
666 $property_id=mysql_insert_id();
667 $count = count($_FILES['catalog_image']['name']);
668 for($i=0;$i<$count;$i++)
669 {
670 $p_image=rand(0,99999)."_".$_FILES['catalog_image']['name'][$i];
671 move_uploaded_file($_FILES['catalog_image']['tmp_name'][$i],"../images/properties/".$p_image);
672 if($i == 0 )
673 {
674 $sql = "insert into p_image (p_id,image) values ('$property_id','$pimage')";
675 mysql_query($sql);
676 }
677 else
678 {
679
680 $sql = "insert into p_image (p_id,image) values ('$property_id','$p_image')";
681 mysql_query($sql);
682 }
683 }
684
685}
686function get_agent_ids()
687{
688 $sql = "select * from agents";
689 $sel = mysql_query($sql);
690 return $sel;
691}
692function get_slider_image_4()
693{
694 $sql= "select * from img_slider where id = 4 ";
695 $sel = mysql_query($sql)or die(mysql_error());
696 $data = mysql_fetch_assoc($sel);
697 return $data;
698
699}
700function get_slider_image_3()
701{
702 $sql= "select * from img_slider where id = 3 ";
703 $sel = mysql_query($sql)or die(mysql_error());
704 $data = mysql_fetch_assoc($sel);
705 return $data;
706
707}
708function get_slider_image_2()
709{
710 $sql= "select * from img_slider where id = 2 ";
711 $sel = mysql_query($sql)or die(mysql_error());
712 $data = mysql_fetch_assoc($sel);
713 return $data;
714
715}
716function get_slider_image_1()
717{
718 $sql= "select * from img_slider where id = 1 ";
719 $sel = mysql_query($sql)or die(mysql_error());
720 $data = mysql_fetch_assoc($sel);
721 return $data;
722
723}
724
725function get_image_slider()
726{
727 $sql = "select * from img_slider";
728 $sel = mysql_query($sql)or die(mysql_error());
729 $data = mysql_fetch_assoc($sel);
730 return $data;
731
732}
733function setslider()
734{
735 $slider_image =implode(',',$_POST['slider']);
736 $id = $_POST['id'];
737 $sql= "update img_slider set img='$slider_image' where id = $id";
738 mysql_query($sql)or die(mysql_error());
739
740}
741function get_Customer_list()
742{
743 $sql = "select * from newsletter";
744 $sel = mysql_query($sql)or die(mysql_error());
745 return $sel;
746}
747
748function get_add_contant()
749{
750 $sql = "select * from ad_banner";
751 $sel = mysql_query($sql)or die(mysql_error());
752 $data = mysql_fetch_assoc($sel);
753 return $data;
754
755}
756function add_set()
757{
758 $id = $_POST['id'];
759 if($_FILES['add_image']['name'] == '')
760 {
761 $img = $_POST['old_image'];
762 }
763 else
764 {
765 $img = rand(0,99999)."_".$_FILES['add_image']['name'];
766 move_uploaded_file($_FILES['add_image']['tmp_name'],'../images/advertisements/'.$img);
767 unlink('../images/advertisements/'.$_POST['old_image']);
768 }
769 $sql = "update ad_banner set img='$img' where id=$id";
770 mysql_query($sql);
771}
772?>