From 52b077a48c743ba4d08ac00520a0bf1ef6deef5f Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Fri, 24 Feb 2017 21:27:59 +0100 Subject: Initial commit. --- admin/user/delete.php | 72 +++++++++++++++++++++++++++++++++++++++++ admin/user/index.php | 72 +++++++++++++++++++++++++++++++++++++++++ admin/user/insert.php | 78 ++++++++++++++++++++++++++++++++++++++++++++ admin/user/update.php | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 311 insertions(+) create mode 100644 admin/user/delete.php create mode 100644 admin/user/index.php create mode 100644 admin/user/insert.php create mode 100644 admin/user/update.php (limited to 'admin/user') 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 @@ +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 @@ +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 @@ +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 @@ +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 -- cgit v1.2.3