Update database.php
This commit is contained in:
@@ -585,7 +585,7 @@ include "root.php";
|
|||||||
if (is_array($new_array)) {
|
if (is_array($new_array)) {
|
||||||
foreach ($new_array as $schema_name => $schema_array) {
|
foreach ($new_array as $schema_name => $schema_array) {
|
||||||
|
|
||||||
$this->name = preg_replace('#[^a-zA-Z0-9_/]#', '', $schema_name);
|
$this->name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $schema_name);
|
||||||
if (is_array($schema_array)) {
|
if (is_array($schema_array)) {
|
||||||
foreach ($schema_array as $schema_id => $array) {
|
foreach ($schema_array as $schema_id => $array) {
|
||||||
|
|
||||||
@@ -1005,7 +1005,7 @@ include "root.php";
|
|||||||
}
|
}
|
||||||
//set the name
|
//set the name
|
||||||
if (isset($array['name'])) {
|
if (isset($array['name'])) {
|
||||||
$this->name = preg_replace('#[^a-zA-Z0-9_/]#', '', $array['name']);
|
$this->name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $array['name']);
|
||||||
}
|
}
|
||||||
//set the uuid
|
//set the uuid
|
||||||
if (isset($array['uuid'])) {
|
if (isset($array['uuid'])) {
|
||||||
@@ -1139,7 +1139,7 @@ include "root.php";
|
|||||||
$this->debug["sql"] = true;
|
$this->debug["sql"] = true;
|
||||||
|
|
||||||
//start the atomic transaction
|
//start the atomic transaction
|
||||||
$this->db->beginTransaction();
|
// $this->db->beginTransaction();
|
||||||
|
|
||||||
//debug info
|
//debug info
|
||||||
//echo "<pre>\n";
|
//echo "<pre>\n";
|
||||||
@@ -1150,13 +1150,13 @@ include "root.php";
|
|||||||
//loop through the array
|
//loop through the array
|
||||||
if (is_array($new_array)) foreach ($new_array as $schema_name => $schema_array) {
|
if (is_array($new_array)) foreach ($new_array as $schema_name => $schema_array) {
|
||||||
|
|
||||||
$this->name = preg_replace('#[^a-zA-Z0-9_/]#', '', $schema_name);
|
$this->name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $schema_name);
|
||||||
if (is_array($schema_array)) foreach ($schema_array as $schema_id => $array) {
|
if (is_array($schema_array)) foreach ($schema_array as $schema_id => $array) {
|
||||||
|
|
||||||
//set the variables
|
//set the variables
|
||||||
$table_name = "v_".$this->name;
|
$table_name = "v_".$this->name;
|
||||||
$parent_key_name = $this->singular($this->name)."_uuid";
|
$parent_key_name = $this->singular($this->name)."_uuid";
|
||||||
$parent_key_name = preg_replace('#[^a-zA-Z0-9_/]#', '', $parent_key_name);
|
$parent_key_name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $parent_key_name);
|
||||||
|
|
||||||
//if the uuid is set then set parent key exists and value
|
//if the uuid is set then set parent key exists and value
|
||||||
//determine if the parent_key_exists
|
//determine if the parent_key_exists
|
||||||
@@ -1176,13 +1176,13 @@ include "root.php";
|
|||||||
}
|
}
|
||||||
|
|
||||||
//allow characters found in the uuid only.
|
//allow characters found in the uuid only.
|
||||||
$parent_key_value = preg_replace('#[^a-zA-Z0-9_/]#', '', $parent_key_value);
|
$parent_key_value = preg_replace('#[^a-zA-Z0-9_\-]#', '', $parent_key_value);
|
||||||
|
|
||||||
//get the parent field names
|
//get the parent field names
|
||||||
$parent_field_names = array();
|
$parent_field_names = array();
|
||||||
if (is_array($array)) foreach ($array as $key => $value) {
|
if (is_array($array)) foreach ($array as $key => $value) {
|
||||||
if (!is_array($value)) {
|
if (!is_array($value)) {
|
||||||
$parent_field_names[] = preg_replace('#[^a-zA-Z0-9_/]#', '', $key);
|
$parent_field_names[] = preg_replace('#[^a-zA-Z0-9_\-]#', '', $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1234,7 +1234,7 @@ include "root.php";
|
|||||||
//}
|
//}
|
||||||
if (is_array($array)) foreach ($array as $array_key => $array_value) {
|
if (is_array($array)) foreach ($array as $array_key => $array_value) {
|
||||||
if (!is_array($array_value)) {
|
if (!is_array($array_value)) {
|
||||||
$array_key = preg_replace('#[^a-zA-Z0-9_/]#', '', $array_key);
|
$array_key = preg_replace('#[^a-zA-Z0-9_\-]#', '', $array_key);
|
||||||
$sql .= $array_key.", ";
|
$sql .= $array_key.", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1253,8 +1253,9 @@ include "root.php";
|
|||||||
$sql .= "now(), ";
|
$sql .= "now(), ";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= "'".check_str($array_value)."', ";
|
//$sql .= "'".check_str($array_value)."', ";
|
||||||
//$sql .= ":".$array_key.", ";
|
$sql .= ':'.$array_key.", ";
|
||||||
|
$params[$array_key] = $array_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1262,24 +1263,12 @@ include "root.php";
|
|||||||
$sql = str_replace(", )", ")", $sql);
|
$sql = str_replace(", )", ")", $sql);
|
||||||
|
|
||||||
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
//$prep_statement = $this->db->prepare($sql);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//bind the parameters key and values
|
//$this->db->query(check_sql($sql));
|
||||||
//if (is_array($array)) foreach ($array as $array_key => $array_value) {
|
$prep_statement = $this->db->prepare($sql);
|
||||||
// if (!is_array($array_value)) {
|
$prep_statement->execute($params);
|
||||||
// if (strlen($array_value) == 0) {}
|
unset($prep_statement);
|
||||||
// elseif ($array_value === "now()") {}
|
|
||||||
// else {
|
|
||||||
// $prep_statement->bindParam(':'.$array_key, $array_value);
|
|
||||||
// $params[$array_key] = $array_value;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
$this->db->query(check_sql($sql));
|
|
||||||
//$prep_statement->execute();
|
|
||||||
//unset($prep_statement);
|
|
||||||
$message["message"] = "OK";
|
$message["message"] = "OK";
|
||||||
$message["code"] = "200";
|
$message["code"] = "200";
|
||||||
$message["uuid"] = $parent_key_value;
|
$message["uuid"] = $parent_key_value;
|
||||||
@@ -1289,9 +1278,10 @@ include "root.php";
|
|||||||
$message["details"][$m]["uuid"] = $parent_key_value;
|
$message["details"][$m]["uuid"] = $parent_key_value;
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
//if (is_array($params)) {
|
if (is_array($params)) {
|
||||||
// $message["details"][$m]["params"] = $params;
|
$message["details"][$m]["params"] = $params;
|
||||||
//}
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$m++;
|
$m++;
|
||||||
@@ -1302,11 +1292,13 @@ include "root.php";
|
|||||||
$message["details"][$m]["name"] = $this->name;
|
$message["details"][$m]["name"] = $this->name;
|
||||||
$message["details"][$m]["message"] = $e->getMessage();
|
$message["details"][$m]["message"] = $e->getMessage();
|
||||||
$message["details"][$m]["code"] = "400";
|
$message["details"][$m]["code"] = "400";
|
||||||
|
$message["details"][$m]["array"] = $array;
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
//if (is_array($params)) {
|
if (is_array($params)) {
|
||||||
// $message["details"][$m]["params"] = $params;
|
$message["details"][$m]["params"] = $params;
|
||||||
//}
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//print_r($message);
|
//print_r($message);
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
@@ -1333,7 +1325,7 @@ include "root.php";
|
|||||||
if (is_array($array)) {
|
if (is_array($array)) {
|
||||||
foreach ($array as $array_key => $array_value) {
|
foreach ($array as $array_key => $array_value) {
|
||||||
if (!is_array($array_value) && $array_key != $parent_key_name) {
|
if (!is_array($array_value) && $array_key != $parent_key_name) {
|
||||||
$array_key = preg_replace('#[^a-zA-Z0-9_/]#', '', $array_key);
|
$array_key = preg_replace('#[^a-zA-Z0-9_\-]#', '', $array_key);
|
||||||
if (strlen($array_value) == 0) {
|
if (strlen($array_value) == 0) {
|
||||||
$sql .= $array_key." = null, ";
|
$sql .= $array_key." = null, ";
|
||||||
}
|
}
|
||||||
@@ -1341,7 +1333,9 @@ include "root.php";
|
|||||||
$sql .= $array_key." = now(), ";
|
$sql .= $array_key." = now(), ";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= $array_key." = '".check_str($array_value)."', ";
|
//$sql .= $array_key." = '".check_str($array_value)."', ";
|
||||||
|
$sql .= $array_key." = :".$array_key.", ";
|
||||||
|
$params[$array_key] = $array_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1350,7 +1344,9 @@ include "root.php";
|
|||||||
$sql = str_replace(", WHERE", " WHERE", $sql);
|
$sql = str_replace(", WHERE", " WHERE", $sql);
|
||||||
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
try {
|
try {
|
||||||
$this->db->query(check_sql($sql));
|
$prep_statement = $this->db->prepare($sql);
|
||||||
|
$prep_statement->execute($params);
|
||||||
|
//$this->db->query(check_sql($sql));
|
||||||
$message["message"] = "OK";
|
$message["message"] = "OK";
|
||||||
$message["code"] = "200";
|
$message["code"] = "200";
|
||||||
$message["uuid"] = $parent_key_value;
|
$message["uuid"] = $parent_key_value;
|
||||||
@@ -1360,6 +1356,10 @@ include "root.php";
|
|||||||
$message["details"][$m]["uuid"] = $parent_key_value;
|
$message["details"][$m]["uuid"] = $parent_key_value;
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
|
if (is_array($params)) {
|
||||||
|
$message["details"][$m]["params"] = $params;
|
||||||
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$m++;
|
$m++;
|
||||||
@@ -1373,6 +1373,10 @@ include "root.php";
|
|||||||
$message["details"][$m]["code"] = "400";
|
$message["details"][$m]["code"] = "400";
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
|
if (is_array($params)) {
|
||||||
|
$message["details"][$m]["params"] = $params;
|
||||||
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$m++;
|
$m++;
|
||||||
@@ -1396,11 +1400,11 @@ include "root.php";
|
|||||||
|
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
$table_name = "v_".$key;
|
$table_name = "v_".$key;
|
||||||
$table_name = preg_replace('#[^a-zA-Z0-9_/]#', '', $table_name);
|
$table_name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $table_name);
|
||||||
foreach ($value as $id => $row) {
|
foreach ($value as $id => $row) {
|
||||||
//prepare the variables
|
//prepare the variables
|
||||||
$child_name = $this->singular($key);
|
$child_name = $this->singular($key);
|
||||||
$child_name = preg_replace('#[^a-zA-Z0-9_/]#', '', $child_name);
|
$child_name = preg_replace('#[^a-zA-Z0-9_\-]#', '', $child_name);
|
||||||
$child_key_name = $child_name."_uuid";
|
$child_key_name = $child_name."_uuid";
|
||||||
|
|
||||||
//determine if the parent key exists in the child array
|
//determine if the parent key exists in the child array
|
||||||
@@ -1425,13 +1429,13 @@ include "root.php";
|
|||||||
}
|
}
|
||||||
|
|
||||||
//allow characters found in the uuid only.
|
//allow characters found in the uuid only.
|
||||||
$child_key_value = preg_replace('#[^a-zA-Z0-9_/]#', '', $child_key_value);
|
$child_key_value = preg_replace('#[^a-zA-Z0-9_\-]#', '', $child_key_value);
|
||||||
|
|
||||||
//get the child field names
|
//get the child field names
|
||||||
$child_field_names = array();
|
$child_field_names = array();
|
||||||
if (is_array($row)) foreach ($row as $k => $v) {
|
if (is_array($row)) foreach ($row as $k => $v) {
|
||||||
if (!is_array($v)) {
|
if (!is_array($v)) {
|
||||||
$child_field_names[] = preg_replace('#[^a-zA-Z0-9_/]#', '', $k);
|
$child_field_names[] = preg_replace('#[^a-zA-Z0-9_\-]#', '', $k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1469,7 +1473,7 @@ include "root.php";
|
|||||||
if (is_array($row)) {
|
if (is_array($row)) {
|
||||||
foreach ($row as $k => $v) {
|
foreach ($row as $k => $v) {
|
||||||
if (!is_array($v) && ($k != $parent_key_name || $k != $child_key_name)) {
|
if (!is_array($v) && ($k != $parent_key_name || $k != $child_key_name)) {
|
||||||
$k = preg_replace('#[^a-zA-Z0-9_/]#', '', $k);
|
$k = preg_replace('#[^a-zA-Z0-9_\-]#', '', $k);
|
||||||
if (strlen($v) == 0) {
|
if (strlen($v) == 0) {
|
||||||
$sql .= $k." = null, ";
|
$sql .= $k." = null, ";
|
||||||
}
|
}
|
||||||
@@ -1477,7 +1481,9 @@ include "root.php";
|
|||||||
$sql .= $k." = now(), ";
|
$sql .= $k." = now(), ";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= "$k = '".check_str($v)."', ";
|
//$sql .= "$k = '".check_str($v)."', ";
|
||||||
|
$sql .= $array_key." = :".$array_key.", ";
|
||||||
|
$params[$array_key] = $array_value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1490,13 +1496,19 @@ include "root.php";
|
|||||||
//$prep_statement->bindParam(':domain_uuid', $_SESSION["domain_uuid"] );
|
//$prep_statement->bindParam(':domain_uuid', $_SESSION["domain_uuid"] );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->db->query(check_sql($sql));
|
//$this->db->query(check_sql($sql));
|
||||||
|
$prep_statement = $this->db->prepare($sql);
|
||||||
|
$prep_statement->execute($params);
|
||||||
$message["details"][$m]["name"] = $key;
|
$message["details"][$m]["name"] = $key;
|
||||||
$message["details"][$m]["message"] = "OK";
|
$message["details"][$m]["message"] = "OK";
|
||||||
$message["details"][$m]["code"] = "200";
|
$message["details"][$m]["code"] = "200";
|
||||||
$message["details"][$m]["uuid"] = $child_key_value;
|
$message["details"][$m]["uuid"] = $child_key_value;
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
|
if (is_array($params)) {
|
||||||
|
$message["details"][$m]["params"] = $params;
|
||||||
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$m++;
|
$m++;
|
||||||
@@ -1511,6 +1523,10 @@ include "root.php";
|
|||||||
$message["details"][$m]["code"] = "400";
|
$message["details"][$m]["code"] = "400";
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
|
if (is_array($params)) {
|
||||||
|
$message["details"][$m]["params"] = $params;
|
||||||
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$m++;
|
$m++;
|
||||||
@@ -1559,7 +1575,7 @@ include "root.php";
|
|||||||
if (is_array($row)) {
|
if (is_array($row)) {
|
||||||
foreach ($row as $k => $v) {
|
foreach ($row as $k => $v) {
|
||||||
if (!is_array($v)) {
|
if (!is_array($v)) {
|
||||||
$k = preg_replace('#[^a-zA-Z0-9_/]#', '', $k);
|
$k = preg_replace('#[^a-zA-Z0-9_\-]#', '', $k);
|
||||||
$sql .= $k.", ";
|
$sql .= $k.", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1583,7 +1599,10 @@ include "root.php";
|
|||||||
$sql .= "now(), ";
|
$sql .= "now(), ";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$sql .= "'".check_str($v)."', ";
|
$k = preg_replace('#[^a-zA-Z0-9_\-]#', '', $k);
|
||||||
|
//$sql .= "'".check_str($v)."', ";
|
||||||
|
$sql .= ':'.$k.", ";
|
||||||
|
$params[$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1592,13 +1611,20 @@ include "root.php";
|
|||||||
$sql = str_replace(", )", ")", $sql);
|
$sql = str_replace(", )", ")", $sql);
|
||||||
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
try {
|
try {
|
||||||
$this->db->query(check_sql($sql));
|
//$this->db->query(check_sql($sql));
|
||||||
|
$prep_statement = $this->db->prepare($sql);
|
||||||
|
$prep_statement->execute($params);
|
||||||
|
unset($prep_statement);
|
||||||
$message["details"][$m]["name"] = $key;
|
$message["details"][$m]["name"] = $key;
|
||||||
$message["details"][$m]["message"] = "OK";
|
$message["details"][$m]["message"] = "OK";
|
||||||
$message["details"][$m]["code"] = "200";
|
$message["details"][$m]["code"] = "200";
|
||||||
$message["details"][$m]["uuid"] = $child_key_value;
|
$message["details"][$m]["uuid"] = $child_key_value;
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
|
if (is_array($params)) {
|
||||||
|
$message["details"][$m]["params"] = $params;
|
||||||
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$m++;
|
$m++;
|
||||||
@@ -1613,6 +1639,10 @@ include "root.php";
|
|||||||
$message["details"][$m]["code"] = "400";
|
$message["details"][$m]["code"] = "400";
|
||||||
if ($this->debug["sql"]) {
|
if ($this->debug["sql"]) {
|
||||||
$message["details"][$m]["sql"] = $sql;
|
$message["details"][$m]["sql"] = $sql;
|
||||||
|
if (is_array($params)) {
|
||||||
|
$message["details"][$m]["params"] = $params;
|
||||||
|
unset($params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
$m++;
|
$m++;
|
||||||
@@ -1655,7 +1685,7 @@ include "root.php";
|
|||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
|
|
||||||
//commit the atomic transaction
|
//commit the atomic transaction
|
||||||
$this->db->commit();
|
// $this->db->commit();
|
||||||
|
|
||||||
//get the UUIDs
|
//get the UUIDs
|
||||||
$user_uuid = $_SESSION['user_uuid'];
|
$user_uuid = $_SESSION['user_uuid'];
|
||||||
|
|||||||
Reference in New Issue
Block a user