-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-node.php
More file actions
39 lines (35 loc) · 1.09 KB
/
create-node.php
File metadata and controls
39 lines (35 loc) · 1.09 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
<?php
$errorAsJSON = true;
require 'engine.php';
function processHTML(&$thing, $iid) {
return str_replace('{id}', $thing['name_id'].$iid, $thing['html']);
}
function processID(&$thing, $iid) {
return $thing['name_id'].$iid;
}
if (getPassed('type') && getPassed('page') && is_numeric($_GET['page'])) {
$thingResult = $db->query('SELECT * FROM things WHERE name_id="'.
mysqli_escape_string($db, $_GET['type']).'"');
if ($thingResult !== FALSE && $thingResult->num_rows > 0) {
$thing = $thingResult->fetch_assoc();
$nodeResult = $db->query('INSERT INTO nodes (id_things, id_page, state) VALUES('.
$thing['id'].', '.
$_GET['page'].',"")');
if ($nodeResult !== FALSE) {
$iid = $db->insert_id;
$data = array('html' => processHTML($thing, $iid),
'id' => processID($thing, $iid));
echo json_encode($data);
}
else {
exit('{"error" : true, "desc" : "error while inserting node"}');
}
}
else {
exit('{"error" : true, "desc" : "thing not found in database"}');
}
}
else {
exit('{"error" : true, "desc" : "type / page not specified"}');
}
?>