aboutsummaryrefslogtreecommitdiffstats
path: root/admin/user
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-02-24 21:27:59 +0100
committerThomas Lange <code@nerdmind.de>2017-02-24 21:27:59 +0100
commit52b077a48c743ba4d08ac00520a0bf1ef6deef5f (patch)
treeb4205c194167e0e03e273957cdd0aab3be9fdf01 /admin/user
downloadblog-52b077a48c743ba4d08ac00520a0bf1ef6deef5f.tar.gz
blog-52b077a48c743ba4d08ac00520a0bf1ef6deef5f.tar.xz
blog-52b077a48c743ba4d08ac00520a0bf1ef6deef5f.zip
Initial commit.v1.0
Diffstat (limited to 'admin/user')
-rw-r--r--admin/user/delete.php72
-rw-r--r--admin/user/index.php72
-rw-r--r--admin/user/insert.php78
-rw-r--r--admin/user/update.php89
4 files changed, 311 insertions, 0 deletions
diff --git a/admin/user/delete.php b/admin/user/delete.php
new file mode 100644
index 0000000..ed8f925
--- /dev/null
+++ b/admin/user/delete.php
@@ -0,0 +1,72 @@
+<?php
+#===============================================================================
+# DEFINE: Administration
+#===============================================================================
+define('ADMINISTRATION', TRUE);
+define('AUTHENTICATION', TRUE);
+
+#===============================================================================
+# INCLUDE: Main configuration
+#===============================================================================
+require_once '../../core/application.php';
+
+#===============================================================================
+# TRY: User\Exception
+#===============================================================================
+try {
+ $User = User\Factory::build(HTTP::GET('id'));
+ $Attribute = $User->getAttribute();
+
+ if(HTTP::issetPOST(['token' => Application::getSecurityToken()], 'delete')) {
+ try {
+ if($Attribute->databaseDELETE($Database)) {
+ HTTP::redirect(Application::getAdminURL('user/'));
+ }
+ } catch(PDOException $Exception) {
+ $messages[] = $Exception->getMessage();
+ }
+ }
+
+ #===============================================================================
+ # TRY: Template\Exception
+ #===============================================================================
+ try {
+ $FormTemplate = Template\Factory::build('user/form');
+ $FormTemplate->set('HTML', $User->getHTML());
+ $FormTemplate->set('FORM', [
+ 'TYPE' => 'DELETE',
+ 'INFO' => $messages ?? [],
+ 'DATA' => [
+ 'ID' => $Attribute->get('id'),
+ 'BODY' => $Attribute->get('body'),
+ 'TIME_INSERT' => $Attribute->get('time_insert'),
+ 'TIME_UPDATE' => $Attribute->get('time_update'),
+ ],
+ 'TOKEN' => Application::getSecurityToken()
+ ]);
+
+ $DeleteTemplate = Template\Factory::build('user/delete');
+ $DeleteTemplate->set('HTML', $FormTemplate);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('NAME', $Language->text('title_user_delete'));
+ $MainTemplate->set('HTML', $DeleteTemplate);
+ echo $MainTemplate;
+ }
+
+ #===============================================================================
+ # CATCH: Template\Exception
+ #===============================================================================
+ catch(Template\Exception $Exception) {
+ $Exception->defaultHandler();
+ }
+}
+
+#===============================================================================
+# CATCH: User\Exception
+#===============================================================================
+catch(User\Exception $Exception) {
+ Application::exit(404);
+}
+?>
+
diff --git a/admin/user/index.php b/admin/user/index.php
new file mode 100644
index 0000000..3dca93a
--- /dev/null
+++ b/admin/user/index.php
@@ -0,0 +1,72 @@
+<?php
+#===============================================================================
+# DEFINE: Administration
+#===============================================================================
+define('ADMINISTRATION', TRUE);
+define('AUTHENTICATION', TRUE);
+
+#===============================================================================
+# INCLUDE: Main configuration
+#===============================================================================
+require_once '../../core/application.php';
+
+$site_size = Application::get('POST.LIST_SIZE');
+$site_sort = Application::get('POST.LIST_SORT');
+
+$lastSite = ceil($Database->query(sprintf('SELECT COUNT(id) FROM %s', User\Attribute::TABLE))->fetchColumn() / $site_size);
+
+$currentSite = HTTP::GET('site') ?? 1;
+$currentSite = abs(intval($currentSite));
+
+if($currentSite < 1 OR ($currentSite > $lastSite AND $lastSite > 0)) {
+ Application::exit(404);
+}
+
+#===============================================================================
+# Fetch user IDs from database
+#===============================================================================
+$execSQL = "SELECT id FROM %s ORDER BY {$site_sort} LIMIT ".(($currentSite-1) * $site_size).", {$site_size}";
+$userIDs = $Database->query(sprintf($execSQL, User\Attribute::TABLE))->fetchAll($Database::FETCH_COLUMN);
+
+#===============================================================================
+# TRY: Template\Exception
+#===============================================================================
+try {
+ foreach($userIDs as $userID) {
+ try {
+ $User = User\Factory::build($userID);
+ $ItemTemplate = generateUserItemTemplate($User);
+
+ $users[] = $ItemTemplate;
+ } catch(User\Exception $Exception){}
+ }
+
+ $PaginationTemplate = Template\Factory::build('pagination');
+ $PaginationTemplate->set('THIS', $currentSite);
+ $PaginationTemplate->set('LAST', $lastSite);
+ $PaginationTemplate->set('HREF', Application::getAdminURL('user/?site=%d'));
+
+ $ListTemplate = Template\Factory::build('user/index');
+ $ListTemplate->set('LIST', [
+ 'USERS' => $users ?? []
+ ]);
+
+ $ListTemplate->set('PAGINATION', [
+ 'THIS' => $currentSite,
+ 'LAST' => $lastSite,
+ 'HTML' => $PaginationTemplate
+ ]);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('NAME', $Language->text('title_user_overview', $currentSite));
+ $MainTemplate->set('HTML', $ListTemplate);
+ echo $MainTemplate;
+}
+
+#===============================================================================
+# CATCH: Template\Exception
+#===============================================================================
+catch(Template\Exception $Exception) {
+ $Exception->defaultHandler();
+}
+?> \ No newline at end of file
diff --git a/admin/user/insert.php b/admin/user/insert.php
new file mode 100644
index 0000000..7c892d4
--- /dev/null
+++ b/admin/user/insert.php
@@ -0,0 +1,78 @@
+<?php
+#===============================================================================
+# DEFINE: Administration
+#===============================================================================
+define('ADMINISTRATION', TRUE);
+define('AUTHENTICATION', TRUE);
+
+#===============================================================================
+# INCLUDE: Main configuration
+#===============================================================================
+require_once '../../core/application.php';
+
+$Attribute = new User\Attribute();
+
+if(HTTP::issetPOST('id', 'slug', 'username', 'password', 'fullname', 'mailaddr', 'body', 'time_insert', 'time_update', 'insert')) {
+ $Attribute->set('id', HTTP::POST('id') ? HTTP::POST('id') : FALSE);
+ $Attribute->set('slug', HTTP::POST('slug') ? HTTP::POST('slug') : makeSlugURL(HTTP::POST('username')));
+ $Attribute->set('username', HTTP::POST('username') ? HTTP::POST('username') : NULL);
+ $Attribute->set('password', HTTP::POST('password') ? password_hash(HTTP::POST('password'), PASSWORD_BCRYPT, ['cost' => 10]) : FALSE);
+ $Attribute->set('fullname', HTTP::POST('fullname') ? HTTP::POST('fullname') : NULL);
+ $Attribute->set('mailaddr', HTTP::POST('mailaddr') ? HTTP::POST('mailaddr') : NULL);
+ $Attribute->set('body', HTTP::POST('body') ? HTTP::POST('body') : NULL);
+ $Attribute->set('time_insert', HTTP::POST('time_insert') ? HTTP::POST('time_insert') : date('Y-m-d H:i:s'));
+ $Attribute->set('time_update', HTTP::POST('time_update') ? HTTP::POST('time_update') : date('Y-m-d H:i:s'));
+
+ if(HTTP::issetPOST(['token' => Application::getSecurityToken()])) {
+ try {
+ if($Attribute->databaseINSERT($Database)) {
+ HTTP::redirect(Application::getAdminURL('user/'));
+ }
+ } catch(PDOException $Exception) {
+ $messages[] = $Exception->getMessage();
+ }
+ }
+
+ else {
+ $messages[] = $Language->text('error_security_csrf');
+ }
+}
+
+#===============================================================================
+# TRY: Template\Exception
+#===============================================================================
+try {
+ $FormTemplate = Template\Factory::build('user/form');
+ $FormTemplate->set('FORM', [
+ 'TYPE' => 'INSERT',
+ 'INFO' => $messages ?? [],
+ 'DATA' => [
+ 'ID' => $Attribute->get('id'),
+ 'SLUG' => $Attribute->get('slug'),
+ 'USERNAME' => $Attribute->get('username'),
+ 'PASSWORD' => NULL,
+ 'FULLNAME' => $Attribute->get('fullname'),
+ 'MAILADDR' => $Attribute->get('mailaddr'),
+ 'BODY' => $Attribute->get('body'),
+ 'TIME_INSERT' => $Attribute->get('time_insert'),
+ 'TIME_UPDATE' => $Attribute->get('time_update'),
+ ],
+ 'TOKEN' => Application::getSecurityToken()
+ ]);
+
+ $InsertTemplate = Template\Factory::build('user/insert');
+ $InsertTemplate->set('HTML', $FormTemplate);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('NAME', $Language->text('title_user_insert'));
+ $MainTemplate->set('HTML', $InsertTemplate);
+ echo $MainTemplate;
+}
+
+#===============================================================================
+# CATCH: Template\Exception
+#===============================================================================
+catch(Template\Exception $Exception) {
+ $Exception->defaultHandler();
+}
+?> \ No newline at end of file
diff --git a/admin/user/update.php b/admin/user/update.php
new file mode 100644
index 0000000..cab582e
--- /dev/null
+++ b/admin/user/update.php
@@ -0,0 +1,89 @@
+<?php
+#===============================================================================
+# DEFINE: Administration
+#===============================================================================
+define('ADMINISTRATION', TRUE);
+define('AUTHENTICATION', TRUE);
+
+#===============================================================================
+# INCLUDE: Main configuration
+#===============================================================================
+require_once '../../core/application.php';
+
+#===============================================================================
+# TRY: User\Exception
+#===============================================================================
+try {
+ $User = User\Factory::build(HTTP::GET('id'));
+ $Attribute = $User->getAttribute();
+
+ if(HTTP::issetPOST('slug', 'username', 'password', 'fullname', 'mailaddr', 'body', 'time_insert', 'time_update', 'update')) {
+ $Attribute->set('slug', HTTP::POST('slug') ? HTTP::POST('slug') : makeSlugURL(HTTP::POST('username')));
+ $Attribute->set('username', HTTP::POST('username') ? HTTP::POST('username') : NULL);
+ $Attribute->set('password', HTTP::POST('password') ? password_hash(HTTP::POST('password'), PASSWORD_BCRYPT, ['cost' => 10]) : FALSE);
+ $Attribute->set('fullname', HTTP::POST('fullname') ? HTTP::POST('fullname') : NULL);
+ $Attribute->set('mailaddr', HTTP::POST('mailaddr') ? HTTP::POST('mailaddr') : NULL);
+ $Attribute->set('body', HTTP::POST('body') ? HTTP::POST('body') : NULL);
+ $Attribute->set('time_insert', HTTP::POST('time_insert') ? HTTP::POST('time_insert') : date('Y-m-d H:i:s'));
+ $Attribute->set('time_update', HTTP::POST('time_update') ? HTTP::POST('time_update') : date('Y-m-d H:i:s'));
+
+ if(HTTP::issetPOST(['token' => Application::getSecurityToken()])) {
+ try {
+ if($Attribute->databaseUPDATE($Database)) {
+ }
+ } catch(PDOException $Exception) {
+ $messages[] = $Exception->getMessage();
+ }
+ }
+
+ else {
+ $messages[] = $Language->text('error_security_csrf');
+ }
+ }
+
+#===============================================================================
+# TRY: Template\Exception
+#===============================================================================
+ try {
+ $FormTemplate = Template\Factory::build('user/form');
+ $FormTemplate->set('FORM', [
+ 'TYPE' => 'UPDATE',
+ 'INFO' => $messages ?? [],
+ 'DATA' => [
+ 'ID' => $Attribute->get('id'),
+ 'SLUG' => $Attribute->get('slug'),
+ 'USERNAME' => $Attribute->get('username'),
+ 'PASSWORD' => NULL,
+ 'FULLNAME' => $Attribute->get('fullname'),
+ 'MAILADDR' => $Attribute->get('mailaddr'),
+ 'BODY' => $Attribute->get('body'),
+ 'TIME_INSERT' => $Attribute->get('time_insert'),
+ 'TIME_UPDATE' => $Attribute->get('time_update'),
+ ],
+ 'TOKEN' => Application::getSecurityToken()
+ ]);
+
+ $InsertTemplate = Template\Factory::build('user/update');
+ $InsertTemplate->set('HTML', $FormTemplate);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('NAME', $Language->text('title_user_update'));
+ $MainTemplate->set('HTML', $InsertTemplate);
+ echo $MainTemplate;
+ }
+
+#===============================================================================
+# CATCH: Template\Exception
+#===============================================================================
+ catch(Template\Exception $Exception) {
+ $Exception->defaultHandler();
+ }
+}
+
+#===============================================================================
+# CATCH: User\Exception
+#===============================================================================
+catch(User\Exception $Exception) {
+ Application::exit(404);
+}
+?> \ No newline at end of file