www/includes/db_profile_mash.php

changeset 785
aa79acfdf8a9
parent 768
ae1195153fa2
equal deleted inserted replaced
784:d51b05838ac4 785:aa79acfdf8a9
23 $sql = "INSERT INTO"; 23 $sql = "INSERT INTO";
24 } 24 }
25 if (isset($_POST['update'])) { 25 if (isset($_POST['update'])) {
26 $sql = "UPDATE"; 26 $sql = "UPDATE";
27 } 27 }
28 $sql .= " `profile_mash` SET name='" . mysqli_real_escape_string($connect, $_POST['name']); 28 $sql .= " `profile_mash` SET ";
29 if (isset($_POST['uuid']) && (strlen($_POST['uuid']) == 36)) {
30 $sql .= "uuid='" . $_POST['uuid'];
31 } else {
32 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
33 $sql .= "uuid='" . $uuid;
34 }
35 $sql .= "', name='" . mysqli_real_escape_string($connect, $_POST['name']);
29 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']); 36 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
30 $array = $_POST['steps']; 37 $array = $_POST['steps'];
31 $comma = FALSE; 38 $comma = FALSE;
32 $steps = '['; 39 $steps = '[';
33 foreach($array as $key => $item) { 40 foreach($array as $key => $item) {
72 } 79 }
73 exit(json_encode($response)); 80 exit(json_encode($response));
74 81
75 } else { 82 } else {
76 // SELECT COMMAND 83 // SELECT COMMAND
77 $query = "SELECT record,JSON_QUOTE(name),JSON_QUOTE(notes),steps FROM profile_mash ORDER BY name"; 84 $query = "SELECT record,JSON_QUOTE(name),JSON_QUOTE(notes),steps,JSON_QUOTE(uuid) FROM profile_mash ORDER BY name";
78 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 85 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
79 $mashprofiles = '['; 86 $mashprofiles = '[';
80 $comma = FALSE; 87 $comma = FALSE;
81 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 88 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
82 // Manual encode to JSON. 89 // Manual encode to JSON.
85 } 92 }
86 $comma = TRUE; 93 $comma = TRUE;
87 $mashprofile = '{"record":' . $row['record']; 94 $mashprofile = '{"record":' . $row['record'];
88 $mashprofile .= ',"name":' . $row['JSON_QUOTE(name)']; 95 $mashprofile .= ',"name":' . $row['JSON_QUOTE(name)'];
89 $mashprofile .= ',"notes":' . $row['JSON_QUOTE(notes)']; 96 $mashprofile .= ',"notes":' . $row['JSON_QUOTE(notes)'];
90 $mashprofile .= ',"steps":' . $row['steps'] . '}'; 97 $mashprofile .= ',"steps":' . $row['steps'];
98 $mashprofile .= ',"uuid":' . $row['JSON_QUOTE(uuid)'] . '}';
91 $mashprofiles .= $mashprofile; 99 $mashprofiles .= $mashprofile;
92 } 100 }
93 $mashprofiles .= ']'; 101 $mashprofiles .= ']';
94 header("Content-type: application/json"); 102 header("Content-type: application/json");
95 exit($mashprofiles); 103 exit($mashprofiles);

mercurial