-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateUserRouteInDatabase.php
More file actions
53 lines (36 loc) · 1.6 KB
/
createUserRouteInDatabase.php
File metadata and controls
53 lines (36 loc) · 1.6 KB
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
<?php
require_once "login.php";
ini_set("session.cookie_httponly", True); // The following line sets the HttpOnly flag for session cookies - make sure to call it before you call session_start()
session_start();
header("Content-Type: application/json");
$body = file_get_contents('php://input');
$dbConn = logIntoPostgreSQL();
createUserRoute($dbConn, $body);
function createUserRoute($dbConn, $body){
error_log($body);
$obj_array = json_decode($body, true);
error_log(print_r($obj_array, true));
//get pickedObjects
$pickedObjects = $obj_array[0];
//user's DB id
$userDbId = $obj_array[1];
// user's route name
$routeName = htmlentities($obj_array[2]);
$charsToReplace = array("'", "\"", "/", "\\", "$", "&", "*", "#", "@", "%", "!", "^", "~", "`",
"(", ")", ",", "<", ">", "?", ":", ";", "=", "+", "[", "]", "{", "}", "|");
$cleanedRouteName = str_replace($charsToReplace,"", $routeName);
$cleanedRouteName = trim($cleanedRouteName);
//clear items
pg_query($dbConn, "DELETE FROM public.temp_selected_bsd_site_ids");
//insert cesium's selection
foreach ($pickedObjects as $itm){
// pg_query($dbConn, "INSERT INTO public.temp_selected_bsd_site_ids (id) VALUES(" . $itm . ")");
pg_query_params($dbConn, "INSERT INTO public.temp_selected_bsd_site_ids (id) VALUES($1)",
array($itm));
}
// create the user's base route data. pass user's route name and their DB id
pg_query_params($dbConn, "select query_route_create_user_base_route($1, $2)"
, array($cleanedRouteName, $userDbId));
pg_close($dbConn);
}
?>