diff --git a/.gitignore b/.gitignore index 07fe371..e1da2a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor settings.php nbproject/private -*.sync-conflict* \ No newline at end of file +*.sync-conflict* +*.bak \ No newline at end of file diff --git a/composer.json b/composer.json index fb37c32..5909527 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "netsyms/business-app-template", - "description": "Template for a webapp integrated with an AccountHub server.", + "name": "netsyms/hache-membership-portal", + "description": "", "type": "project", "require": { "catfan/medoo": "^1.5", diff --git a/database.mwb b/database.mwb new file mode 100644 index 0000000..d1c92d2 Binary files /dev/null and b/database.mwb differ diff --git a/lib/requiredpublic.php b/lib/requiredpublic.php new file mode 100644 index 0000000..e0b8db6 --- /dev/null +++ b/lib/requiredpublic.php @@ -0,0 +1,164 @@ +" + . "" + . "" + . "Error" + . "" + . "

A fatal application error has occurred.

" + . "(This isn't your fault.)" + . "

Details:

" + . "

" . htmlspecialchars($error) . "

"); +} + +date_default_timezone_set(TIMEZONE); + +// Database settings +// Also inits database and stuff +use Medoo\Medoo; + +$database; +try { + $database = new Medoo([ + 'database_type' => DB_TYPE, + 'database_name' => DB_NAME, + 'server' => DB_SERVER, + 'username' => DB_USER, + 'password' => DB_PASS, + 'charset' => DB_CHARSET + ]); +} catch (Exception $ex) { + //header('HTTP/1.1 500 Internal Server Error'); + sendError("Database error. Try again later. $ex"); +} + +function getdatabase() { + global $database; + return $database; +} + +function getsiteid() { + global $database; + if (isset($_GET['siteid'])) { + $id = preg_replace("/[^0-9]/", '', $_GET['siteid']); + if ($database->has('sites', ["siteid" => $id])) { + return $id; + } + } + $host = $_SERVER['HTTP_HOST']; + $args = $_SERVER['QUERY_STRING']; + $path = str_replace("?$args", "", $_SERVER['REQUEST_URI']); + $dir = str_replace("index.php", "", $path); + $sites = $database->select("sites", ["siteid", "url"], ["OR" => ["url[~]" => $host, "url" => $dir]]); + //var_dump($sites); + if (count($sites) == 1) { + return $sites[0]["siteid"]; + } + if (count($sites) > 1) { + //var_dump($sites); + //die(); + return $sites[0]['siteid']; + } + return $database->get("sites", "siteid"); +} + +function getpageslug() { + global $database; + if (isset($_GET['id'])) { + $id = $_GET['id']; + } else { + $id = "index"; + } + if ($database->has("pages", ["AND" => ["slug" => $id, "siteid" => getsiteid()]])) { + return $id; + } + return null; +} + +function getpageid() { + global $database; + if (isset($_GET['id'])) { + $id = $_GET['id']; + } else { + $id = "index"; + } + $siteid = getsiteid(); + if ($database->has("pages", ["AND" => ["slug" => $id, "siteid" => $siteid]])) { + return $database->get("pages", "pageid", ["AND" => ["slug" => $id, "siteid" => $siteid]]); + } + return null; +} + +function getpagetemplate() { + global $database; + $slug = getpageslug(); + if (isset($_GET['template'])) { + return preg_replace("/[^A-Za-z0-9]/", '', $_GET['template']); + } + if (!is_null($slug)) { + return $database->get("pages", "template", ["AND" => ["slug" => $slug, "siteid" => getsiteid()]]); + } + return "404"; +} + +function formatsiteurl($url) { + if (substr($url, 0) != "/") { + if (strpos($url, "http://") !== 0 && strpos($url, "https://") !== 0) { + if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off") { + $url = "http://$url"; + } else { + $url = "https://$url"; + } + } + } + if (substr($url, -1) != "/") { + $url = $url . "/"; + } + return $url; +} diff --git a/nbproject/project.xml b/nbproject/project.xml index 3edeb05..0ab2e4f 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -3,7 +3,7 @@ org.netbeans.modules.php.project - BusinessAppTemplate + MembershipPortal diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..92ec0e0 --- /dev/null +++ b/public/index.php @@ -0,0 +1,9 @@ +