-
Notifications
You must be signed in to change notification settings - Fork 0
/
addnewlocality.php
114 lines (104 loc) · 4.22 KB
/
addnewlocality.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
include_once("smartyConfig.php");
include_once("appWideConfig.php");
include_once("dbConfig.php");
include_once("includes/configs/configs.php");
include_once("builder_function.php");
include_once("function/locality_functions.php");
AdminAuthentication();
require $_SERVER['DOCUMENT_ROOT'].'/dbConfig.php';
$subcityval = $_GET['subcityval'];
$localityvalNew = $_GET['localityval'];
$localityval = str_replace("@","&",$localityvalNew);
$id = $_GET['id'];
$cityid = $_GET['cityid'];
$sel_id = $_GET['id'];
$ins = 0;
$c = 0;
$deleteloc = $_GET['localitydelete'];
$deletect = $_GET['cid'];
$deletesub = $_GET['subiddelete'];
if($deleteloc != '')
{
$qry = "DELETE FROM ".LOCALITY." WHERE LOCALITY_ID = '".$deleteloc."'";
$res = mysql_query($qry) or die(mysql_error());
if($res)
{
$selqry = "SELECT l.LOCALITY_ID,l.LABEL FROM ".LOCALITY." l
inner join suburb s on l.suburb_id = s.suburb_id
WHERE s.CITY_ID = '".$cityid."' AND l.SUBURB_ID = '".$deletesub."' ORDER BY l.LABEL";
$ressel = mysql_query($selqry);
?>
<select name="localityId" id = "localityId" class="localityId" onchange="displocality(this.value,1);" STYLE="width: 150px">
<option value =''>Select Locality</option>
<?php
while($data = mysql_fetch_array($ressel))
{
?>
<option value ='<?php echo $data['LOCALITY_ID']; ?>'><?php echo $data['LABEL']; ?></option>
<?php
}
?>
</select>
<?php
}
}
else
{
require $_SERVER['DOCUMENT_ROOT'].'/dbConfig.php';
$qryCity = "SELECT LABEL FROM ".CITY." WHERE CITY_ID = $cityid";
$resCity = mysql_query($qryCity);
$dataCity = mysql_fetch_assoc($resCity);
mysql_free_result($resCity);
$localityval = trim($localityval);
$url = "";
//code for duplicate value
$seldata = "SELECT l.LABEL FROM ".LOCALITY." l
inner join suburb s on l.suburb_id = s.suburb_id
WHERE s.CITY_ID = '".$deletect."' AND l.LABEL = '".$localityval."'";
$resdata = mysql_query($seldata);
$ins = mysql_num_rows($resdata);
$qryLocalityExists = "select l.label from locality l inner join suburb s on l.suburb_id = s.suburb_id
where s.city_id = $cityid and l.label = '".$localityval."'";
$qryLocalityExistsRes = mysql_query($qryLocalityExists);
$qryLocalityExistsRows = mysql_num_rows($qryLocalityExistsRes);
if($qryLocalityExistsRows >0)
echo "Duplicate locality#";
if($subcityval!='' && $id!='' && $qryLocalityExistsRows == 0)
{
$url = createLocalityURL($localityval, $dataCity['LABEL'], $id, 'locality');
$seldata = "UPDATE ".LOCALITY." SET LABEL = '".$localityval."', URL = '$url' WHERE LOCALITY_ID='".$id."' AND SUBURB_ID='".$subcityval."'";
$resdata = mysql_query($seldata);
$c = mysql_affected_rows();
}
if($c==0 && $ins==0 && $qryLocalityExistsRows == 0)
{
$qry = "INSERT INTO ".LOCALITY." (LABEL,SUBURB_ID,status,updated_by)
value('".$localityval."','".$subcityval."','Active','".$_SESSION['adminId']."')";
$res = mysql_query($qry);
$locId = mysql_insert_id();
$sel_id = $ctid;
$url = createLocalityURL($localityval, $dataCity['LABEL'], $locId, 'locality');
$qry = "UPDATE ".LOCALITY." SET URL = '$url',updated_by = '".$_SESSION['adminId']."'
WHERE LOCALITY_ID=".$locId;
$res = mysql_query($qry) or die(mysql_error());
}
$selqry = "SELECT l.LABEL,l.locality_id FROM ".LOCALITY." l
inner join suburb s on l.suburb_id = s.suburb_id
WHERE s.CITY_ID = '".$cityid."' AND l.suburb_id = '".$subcityval."' ORDER BY LABEL";
$ressel = mysql_query($selqry);
?>
<select name="localityId" id = "localityId" class="localityId" onchange="displocality(this.value,1);" STYLE="width: 150px">
<option value =''>Select Locality</option>
<?php
while($data = mysql_fetch_array($ressel))
{
?>
<option value ='<?php echo $data['LOCALITY_ID']; ?>' <?php if( $data['LOCALITY_ID'] == $sel_id ) echo "selected='selected'"; ?>><?php echo $data['LABEL']; ?></option>
<?php
}
?>
</select>
<?php
}
?>