From f230924eae465e1bc16c5f4771de893424615f2d Mon Sep 17 00:00:00 2001 From: markjcrane Date: Fri, 30 Sep 2016 20:25:33 -0600 Subject: [PATCH] Add the database transactions feature. --- app/database_transactions/app_config.php | 97 ++++ app/database_transactions/app_languages.php | 184 +++++++ app/database_transactions/app_menu.php | 19 + .../database_transaction_delete.php | 64 +++ .../database_transaction_edit.php | 460 ++++++++++++++++++ .../database_transactions.php | 206 ++++++++ app/database_transactions/root.php | 90 ++++ 7 files changed, 1120 insertions(+) create mode 100644 app/database_transactions/app_config.php create mode 100644 app/database_transactions/app_languages.php create mode 100644 app/database_transactions/app_menu.php create mode 100644 app/database_transactions/database_transaction_delete.php create mode 100644 app/database_transactions/database_transaction_edit.php create mode 100644 app/database_transactions/database_transactions.php create mode 100644 app/database_transactions/root.php diff --git a/app/database_transactions/app_config.php b/app/database_transactions/app_config.php new file mode 100644 index 0000000000..75e08e1bf7 --- /dev/null +++ b/app/database_transactions/app_config.php @@ -0,0 +1,97 @@ + \ No newline at end of file diff --git a/app/database_transactions/app_languages.php b/app/database_transactions/app_languages.php new file mode 100644 index 0000000000..1f7e77a039 --- /dev/null +++ b/app/database_transactions/app_languages.php @@ -0,0 +1,184 @@ + \ No newline at end of file diff --git a/app/database_transactions/app_menu.php b/app/database_transactions/app_menu.php new file mode 100644 index 0000000000..9bc56043b6 --- /dev/null +++ b/app/database_transactions/app_menu.php @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/app/database_transactions/database_transaction_delete.php b/app/database_transactions/database_transaction_delete.php new file mode 100644 index 0000000000..c5f70090af --- /dev/null +++ b/app/database_transactions/database_transaction_delete.php @@ -0,0 +1,64 @@ + + Portions created by the Initial Developer are Copyright (C) 2016 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes + require_once "root.php"; + require_once "resources/require.php"; + +//check permissions + require_once "resources/check_auth.php"; + if (permission_exists('database_transaction_delete')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get the id + if (count($_GET)>0) { + $id = check_str($_GET["id"]); + } + +//delete database_transaction + if (strlen($id)>0) { + $sql = "delete from v_database_transactions "; + $sql .= "where database_transaction_uuid = '$id' "; + $sql .= "and domain_uuid = '$domain_uuid' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + unset($sql); + } + +//redirect the user + $_SESSION['message'] = $text['message-delete']; + header('Location: database_transactions.php'); + +?> \ No newline at end of file diff --git a/app/database_transactions/database_transaction_edit.php b/app/database_transactions/database_transaction_edit.php new file mode 100644 index 0000000000..bf000b4903 --- /dev/null +++ b/app/database_transactions/database_transaction_edit.php @@ -0,0 +1,460 @@ + + Portions created by the Initial Developer are Copyright (C) 2016 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes + require_once "root.php"; + require_once "resources/require.php"; + +//check permissions + require_once "resources/check_auth.php"; + if (permission_exists('database_transaction_add') || permission_exists('database_transaction_edit')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//action add or update + if (isset($_REQUEST["id"])) { + //$action = "update"; + $database_transaction_uuid = check_str($_REQUEST["id"]); + } + //else { + // $action = "add"; + //} + +//get http post variables and set them to php variables + /* + if (count($_POST) > 0) { + $user_uuid = check_str($_POST["user_uuid"]); + $app_uuid = check_str($_POST["app_uuid"]); + $transaction_code = check_str($_POST["transaction_code"]); + $transaction_address = check_str($_POST["transaction_address"]); + $transaction_type = check_str($_POST["transaction_type"]); + $transaction_date = check_str($_POST["transaction_date"]); + $transaction_old = check_str($_POST["transaction_old"]); + $transaction_new = check_str($_POST["transaction_new"]); + $transaction_result = check_str($_POST["transaction_result"]); + } + */ + +//process the data + /* + if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + + $msg = ''; + if ($action == "update") { + $database_transaction_uuid = check_str($_POST["database_transaction_uuid"]); + } + + //check for all required data + if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-domain_uuid']."
\n"; } + if (strlen($user_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-user_uuid']."
\n"; } + if (strlen($app_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-app_uuid']."
\n"; } + if (strlen($transaction_code) == 0) { $msg .= $text['message-required']." ".$text['label-transaction_code']."
\n"; } + if (strlen($transaction_address) == 0) { $msg .= $text['message-required']." ".$text['label-transaction_address']."
\n"; } + if (strlen($transaction_type) == 0) { $msg .= $text['message-required']." ".$text['label-transaction_type']."
\n"; } + if (strlen($transaction_date) == 0) { $msg .= $text['message-required']." ".$text['label-transaction_date']."
\n"; } + if (strlen($transaction_old) == 0) { $msg .= $text['message-required']." ".$text['label-transaction_old']."
\n"; } + if (strlen($transaction_new) == 0) { $msg .= $text['message-required']." ".$text['label-transaction_new']."
\n"; } + if (strlen($transaction_result) == 0) { $msg .= $text['message-required']." ".$text['label-transaction_result']."
\n"; } + if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { + require_once "resources/header.php"; + require_once "resources/persist_form_var.php"; + echo "
\n"; + echo "
\n"; + echo $msg."
"; + echo "
\n"; + persistformvar($_POST); + echo "
\n"; + require_once "resources/footer.php"; + return; + } + + //add or update the database + if ($_POST["persistformvar"] != "true") { + if ($action == "add" && permission_exists('database_transaction_add')) { + $sql = "insert into v_database_transactions "; + $sql .= "("; + $sql .= "domain_uuid, "; + $sql .= "database_transaction_uuid, "; + $sql .= "domain_uuid, "; + $sql .= "user_uuid, "; + $sql .= "app_uuid, "; + $sql .= "transaction_code, "; + $sql .= "transaction_address, "; + $sql .= "transaction_type, "; + $sql .= "transaction_date, "; + $sql .= "transaction_old, "; + $sql .= "transaction_new, "; + $sql .= "transaction_result "; + $sql .= ")"; + $sql .= "values "; + $sql .= "("; + $sql .= "'$domain_uuid', "; + $sql .= "'".uuid()."', "; + $sql .= "'$domain_uuid', "; + $sql .= "'$user_uuid', "; + $sql .= "'$app_uuid', "; + $sql .= "'$transaction_code', "; + $sql .= "'$transaction_address', "; + $sql .= "'$transaction_type', "; + $sql .= "now(), "; + $sql .= "'$transaction_old', "; + $sql .= "'$transaction_new', "; + $sql .= "'$transaction_result' "; + $sql .= ")"; + $db->exec(check_sql($sql)); + unset($sql); + + $_SESSION["message"] = $text['message-add']; + header("Location: database_transactions.php"); + return; + + } //if ($action == "add") + + if ($action == "update" && permission_exists('database_transaction_edit')) { + $sql = "update v_database_transactions set "; + $sql .= "domain_uuid = '$domain_uuid', "; + $sql .= "user_uuid = '$user_uuid', "; + $sql .= "app_uuid = '$app_uuid', "; + $sql .= "transaction_code = '$transaction_code', "; + $sql .= "transaction_address = '$transaction_address', "; + $sql .= "transaction_type = '$transaction_type', "; + $sql .= "transaction_date = now(), "; + $sql .= "transaction_old = '$transaction_old', "; + $sql .= "transaction_new = '$transaction_new', "; + $sql .= "transaction_result = '$transaction_result' "; + $sql .= "where database_transaction_uuid = '$database_transaction_uuid'"; + $sql .= "and domain_uuid = '$domain_uuid' "; + $db->exec(check_sql($sql)); + unset($sql); + + $_SESSION["message"] = $text['message-update']; + header("Location: database_transactions.php"); + return; + + } //if ($action == "update") + } //if ($_POST["persistformvar"] != "true") + } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + */ + +//pre-populate the form + if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { + $database_transaction_uuid = check_str($_GET["id"]); + + $sql = "select "; + $sql .= "t.database_transaction_uuid, d.domain_name, u.username, t.user_uuid, t.app_name, t.app_uuid, "; + $sql .= "t.transaction_code, t.transaction_address, t.transaction_type, t.transaction_date, "; + $sql .= "t.transaction_old, t.transaction_new, t.transaction_result "; + $sql .= "from v_database_transactions as t, v_domains as d, v_users as u "; + $sql .= "where t.domain_uuid = '$domain_uuid' "; + $sql .= "and t.database_transaction_uuid = '$database_transaction_uuid' "; + $sql .= "and t.user_uuid = u.user_uuid "; + $sql .= "and t.domain_uuid = d.domain_uuid "; + + //$sql = "select *, u.username from v_database_transactions as t, v_users as u "; + //$sql .= "where domain_uuid = '$domain_uuid' "; + //$sql .= "t.user_uuid = u.user_uuid "; + //$sql .= "and database_transaction_uuid = '$database_transaction_uuid' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $user_uuid = $row["user_uuid"]; + $app_name = $row["app_name"]; + $app_uuid = $row["app_uuid"]; + $domain_name = $row["domain_name"]; + $username = $row["username"]; + $transaction_code = $row["transaction_code"]; + $transaction_address = $row["transaction_address"]; + //$transaction_type = $row["transaction_type"]; + $transaction_date = $row["transaction_date"]; + $transaction_old = $row["transaction_old"]; + $transaction_new = $row["transaction_new"]; + $transaction_result = $row["transaction_result"]; + } + unset ($prep_statement); + } + +//show the header + require_once "resources/header.php"; + +//show the content + //echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
".$text['title-database_transaction']."

\n"; + echo " "; + //echo " "; + echo "
\n"; + + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + /*echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + */ + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo " ".$text['label-app_name']."\n"; + echo "\n"; + echo " ".$app_name."\n"; + //echo " \n"; + //echo "
\n"; + //echo $text['description-app_uuid']."\n"; + echo "
\n"; + echo " ".$text['label-domain']."\n"; + echo "\n"; + echo " ".$domain_name; + //echo " \n"; + //echo "
\n"; + //echo " ".$text['description-domain']."\n"; + echo "
\n"; + echo " ".$text['label-user_uuid']."\n"; + echo "\n"; + echo " ".$username."\n"; + //echo " \n"; + //echo "
\n"; + //echo $text['description-user_uuid']."\n"; + echo "
\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo " ".$text['label-transaction_code']."\n"; + echo "\n"; + echo " $transaction_code\n"; + //echo " \n"; + //echo "
\n"; + //echo $text['description-transaction_code']."\n"; + echo "
\n"; + echo " ".$text['label-transaction_address']."\n"; + echo "\n"; + echo " $transaction_address\n"; + //echo " \n"; + //echo "
\n"; + //echo $text['description-transaction_address']."\n"; + echo "
\n"; + echo "
\n"; + + //echo "\n"; + //echo "\n"; + //echo " ".$text['label-transaction_type']."\n"; + //echo "\n"; + //echo "\n"; + //echo " \n"; + //echo "
\n"; + //echo $text['description-transaction_type']."\n"; + //echo "\n"; + //echo "\n"; + + if ($_REQUEST["debug"] == "true") { + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo " ".$text['label-transaction_old']."\n"; + echo "\n"; + //echo " \n"; + echo " \n"; + //echo "
\n"; + //echo $text['description-transaction_old']."\n"; + echo "
\n"; + echo " ".$text['label-transaction_new']."\n"; + echo "\n"; + //echo " \n"; + echo " \n"; + //echo "
\n"; + //echo $text['description-transaction_new']."\n"; + echo "
\n"; + echo " ".$text['label-transaction_result']."\n"; + echo "\n"; + //echo " \n"; + echo " \n"; + //echo "
\n"; + //echo $text['description-transaction_result']."\n"; + echo "
"; + } + + //echo " \n"; + //echo " \n"; + //if ($action == "update") { + // echo " \n"; + //} + //echo " \n"; + //echo " \n"; + //echo " "; + //echo ""; + //echo "
"; + //echo "

"; + +//define the array _difference function + //this adds old and new values to the array + function array_difference($array1, $array2) { + $difference = array(); + foreach($array1 as $key => $value) { + if(is_array($array2[$key])) { + $difference[$key] = array_difference($array1[$key], $array2[$key]); + } + else { + $difference[$key]['old'] = $value; + } + } + foreach($array2 as $key => $value) { + if(is_array($value)) { + $difference[$key] = array_difference($array1[$key], $array2[$key]); + } + else { + $difference[$key]['new'] = $value; + } + } + return $difference; + } + +//show the content from the difference array as a list + function show_difference($array) { + //loop through the array + foreach($array as $key => $value) { + if(is_array($value) && !isset($value['old']) && !isset($value['new'])) { + if (!is_numeric($key)) { + //get the table name + $_SESSION['name'] = $key; + } + else { + //get the row id + $_SESSION['row'] = $key; + } + $array = show_difference($value); + } + else { + //determine if the value has changed + if (strval($value['old']) == strval($value['new']) && isset($value['old'])) { + $color = "#000000"; + } + else { + $color = "#ff0000"; + } + //set the table header + if ($_SESSION['previous_name'] != $_SESSION['name'] || $_SESSION['previous_row'] != $_SESSION['row']) { + echo str_replace("name","".$_SESSION['name']."",$_SESSION['table_header']); + //echo $_SESSION['table_header']; + } + $_SESSION['previous_name'] = $_SESSION['name']; + $_SESSION['previous_row'] = $_SESSION['row']; + //set the variables + $old = $value['old']; + $new = $value['new']; + if (is_null($old)) { $old = "null"; } + if (is_null($new)) { $new = "null"; } + //show the results + echo "\n"; + //echo " ".$_SESSION['name']."\n"; + //echo " ".$_SESSION['row']."\n"; + echo " $key\n"; + echo " ".$old."\n"; + echo " ".$new.""; + echo "\n"; + //echo "\n"; + } + } + } + +//decode the json to arrays + $before = json_decode($transaction_old, true); + $after = json_decode($transaction_new, true); + +//unset the sessions + unset($_SESSION['previous_name']); + unset($_SESSION['previous_row']); + +//create the table header + $array = array_difference($before, $after, 1); + $table_header = " \n"; + $table_header .= "\n"; + //$table_header .= " Table\n"; + //$table_header .= " Row\n"; + $table_header .= " name\n"; + $table_header .= " old\n"; + $table_header .= " new\n"; + $table_header .= "\n"; + $_SESSION['table_header'] = $table_header; + +//show the difference + echo "\n"; + show_difference($array); + echo "
\n"; + + echo "
\n"; + echo "
\n"; + +//include the footer + require_once "resources/footer.php"; + +?> \ No newline at end of file diff --git a/app/database_transactions/database_transactions.php b/app/database_transactions/database_transactions.php new file mode 100644 index 0000000000..11b23d6586 --- /dev/null +++ b/app/database_transactions/database_transactions.php @@ -0,0 +1,206 @@ + + Portions created by the Initial Developer are Copyright (C) 2016 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//includes + require_once "root.php"; + require_once "resources/require.php"; + +//check permissions + require_once "resources/check_auth.php"; + if (permission_exists('database_transaction_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get variables used to control the order + $order_by = check_str($_GET["order_by"]); + $order = check_str($_GET["order"]); + +//add the search term + $search = check_str($_GET["search"]); + if (strlen($search) > 0) { + $sql_search = "and ("; + $sql_search .= "or transaction_code like '%".$search."%'"; + $sql_search .= "or transaction_address like '%".$search."%'"; + $sql_search .= "or transaction_type like '%".$search."%'"; + $sql_search .= "or transaction_date like '%".$search."%'"; + $sql_search .= "or transaction_old like '%".$search."%'"; + $sql_search .= "or transaction_new like '%".$search."%'"; + $sql_search .= "or transaction_result like '%".$search."%'"; + $sql_search .= ")"; + } +//additional includes + require_once "resources/header.php"; + require_once "resources/paging.php"; + +//prepare to page the results + $sql = "select count(database_transaction_uuid) as num_rows from v_database_transactions "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= $sql_search; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] > 0) { + $num_rows = $row['num_rows']; + } + else { + $num_rows = '0'; + } + } + +//prepare to page the results + $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + $param = ""; + $page = $_GET['page']; + if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } + list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); + $offset = $rows_per_page * $page; + +//get the list + $sql = "select "; + $sql .= "t.database_transaction_uuid, d.domain_name, u.username, t.user_uuid, t.app_name, t.app_uuid, "; + $sql .= "t.transaction_code, t.transaction_address, t.transaction_type, t.transaction_date "; + $sql .= "from v_database_transactions as t, v_domains as d, v_users as u "; + $sql .= "where t.domain_uuid = '$domain_uuid' "; + $sql .= "and t.user_uuid = u.user_uuid "; + $sql .= "and t.domain_uuid = d.domain_uuid "; + $sql .= $sql_search; + if (strlen($order_by) == 0) { + $sql .= "order by transaction_date desc "; + } + else { + $sql .= "order by $order_by $order "; + } + $sql .= "limit $rows_per_page offset $offset "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset ($prep_statement, $sql); + +//alternate the row style + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + +//show the content + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
".$text['title-database_transactions']."
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + + echo "\n"; + echo "\n"; + echo th_order_by('domain_name', $text['label-domain'], $order_by, $order); + echo th_order_by('username', $text['label-user_uuid'], $order_by, $order); + echo th_order_by('app_name', $text['label-app_name'], $order_by, $order); + echo th_order_by('transaction_code', $text['label-transaction_code'], $order_by, $order); + echo th_order_by('transaction_address', $text['label-transaction_address'], $order_by, $order); + //echo th_order_by('transaction_type', $text['label-transaction_type'], $order_by, $order); + echo th_order_by('transaction_date', $text['label-transaction_date'], $order_by, $order); + //echo th_order_by('transaction_old', $text['label-transaction_old'], $order_by, $order); + //echo th_order_by('transaction_new', $text['label-transaction_new'], $order_by, $order); + //echo th_order_by('transaction_result', $text['label-transaction_result'], $order_by, $order); + echo "\n"; + echo "\n"; + + if (is_array($result)) { + foreach($result as $row) { + if (permission_exists('database_transaction_edit')) { + $tr_link = "href='database_transaction_edit.php?id=".$row['database_transaction_uuid']."'"; + } + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + //echo " \n"; + echo " \n"; + //echo " \n"; + //echo " \n"; + //echo " \n"; + echo " \n"; + echo "\n"; + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + echo "\n"; + echo "\n"; + echo "\n"; + echo "
"; + if (permission_exists('database_transaction_add')) { + echo "$v_link_label_add"; + } + else { + echo " \n"; + } + echo "
".$row['domain_name']." ".$row['username']." ".$row['app_name']." ".$row['transaction_code']." ".$row['transaction_address']." ".$row['transaction_type']." ".$row['transaction_date']." ".$row['transaction_old']." ".$row['transaction_new']." ".$row['transaction_result']." "; + if (permission_exists('database_transaction_edit')) { + echo "$v_link_label_edit"; + } + if (permission_exists('database_transaction_delete')) { + echo "$v_link_label_delete"; + } + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
 $paging_controls"; + if (permission_exists('database_transaction_add')) { + echo "$v_link_label_add"; + } + else { + echo " "; + } + echo "
\n"; + echo "
"; + echo "

"; + +//include the footer + require_once "resources/footer.php"; + +?> \ No newline at end of file diff --git a/app/database_transactions/root.php b/app/database_transactions/root.php new file mode 100644 index 0000000000..62e2c52383 --- /dev/null +++ b/app/database_transactions/root.php @@ -0,0 +1,90 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +// make sure the PATH_SEPARATOR is defined + umask(2); + if (!defined("PATH_SEPARATOR")) { + if (strpos($_ENV["OS"], "Win") !== false) { + define("PATH_SEPARATOR", ";"); + } else { + define("PATH_SEPARATOR", ":"); + } + } + + if (!isset($output_format)) $output_format = (PHP_SAPI == 'cli') ? 'text' : 'html'; + + // make sure the document_root is set + $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", '/', $_SERVER["SCRIPT_FILENAME"]); + if(PHP_SAPI == 'cli'){ + chdir(pathinfo(realpath($_SERVER["PHP_SELF"]), PATHINFO_DIRNAME)); + $script_full_path = str_replace("\\", '/', getcwd() . '/' . $_SERVER["SCRIPT_FILENAME"]); + $dirs = explode('/', pathinfo($script_full_path, PATHINFO_DIRNAME)); + if (file_exists('/project_root.php')) { + $path = '/'; + } else { + $i = 1; + $path = ''; + while ($i < count($dirs)) { + $path .= '/' . $dirs[$i]; + if (file_exists($path. '/project_root.php')) { + break; + } + $i++; + } + } + $_SERVER["DOCUMENT_ROOT"] = $path; + }else{ + $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); + } + $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); +// try to detect if a project path is being used + if (!defined('PROJECT_PATH')) { + if (is_dir($_SERVER["DOCUMENT_ROOT"]. '/fusionpbx')) { + define('PROJECT_PATH', '/fusionpbx'); + } elseif (file_exists($_SERVER["DOCUMENT_ROOT"]. '/project_root.php')) { + define('PROJECT_PATH', ''); + } else { + $dirs = explode('/', str_replace('\\', '/', pathinfo($_SERVER["PHP_SELF"], PATHINFO_DIRNAME))); + $i = 1; + $path = $_SERVER["DOCUMENT_ROOT"]; + while ($i < count($dirs)) { + $path .= '/' . $dirs[$i]; + if (file_exists($path. '/project_root.php')) { + break; + } + $i++; + } + if(!file_exists($path. '/project_root.php')){ + die("Failed to locate the Project Root by searching for project_root.php please contact support for assistance"); + } + $project_path = str_replace($_SERVER["DOCUMENT_ROOT"], "", $path); + define('PROJECT_PATH', $project_path); + } + $_SERVER["PROJECT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH); + set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER["PROJECT_ROOT"]); + } + +?> \ No newline at end of file