-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_aoi_ajax.php
59 lines (46 loc) · 1.45 KB
/
save_aoi_ajax.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
<?php
/**
* file updates table aoi with username and aoi description for AJAX request from save_aoi.php, returns JSON with success or failure.
*
*
* @package ncgap
*/
session_start();
$dsn = "pgsql:dbname=ncgap;host=127.0.0.1";
$user = "postgres";
$password ="";
try{
$dbh = new PDO($dsn, $user, $password);
} catch(Exception $e) {
echo "PDO connection error";
}
$user = $_SESSION['username'];
$desc = trim($_POST['desc']);
$aoiname = $_POST['aoiname'];
$del = $_POST['del'];
//echo json_encode(array("desc"=>$desc, "aoiname"=>$aoiname, "del"=>$del));die();
if ($del == 'delete'){
$query1 = "update aoi set username = NULL where name = :aoiname";
$stmt = $dbh->prepare($query1);
$stmt->bindParam(':aoiname', $aoiname);
$stmt->execute();
$query2 = "update aoi set description = NULL where name = :aoiname";
$stmt = $dbh->prepare($query2);
$stmt->bindParam(':aoiname', $aoiname);
$stmt->execute();
}elseif (!empty($desc)){
$query1 = "update aoi set username = :user where name = :aoiname";
$stmt = $dbh->prepare($query1);
$stmt->bindParam(':aoiname', $aoiname);
$stmt->bindParam(':user', $user);
$stmt->execute();
$query2 = "update aoi set description = cast( :desc as character(100)) where name = :aoiname";
$stmt = $dbh->prepare($query2);
$stmt->bindParam(':desc', $desc);
$stmt->bindParam(':aoiname', $aoiname);
$stmt->execute();
} else {
echo json_encode(array("success"=>false));die();
}
echo json_encode(array("success"=>true));die();
?>