From 0b397e2e485424db566aebbb95eaf7c230b2dcf4 Mon Sep 17 00:00:00 2001 From: David Siegfried Date: Thu, 30 Nov 2023 16:40:59 +0100 Subject: cleanup, re #2660 --- app/controllers/admin/login_faq.php | 74 ---------- app/controllers/admin/login_style.php | 219 +++++++++++++++++++++++++++++ app/controllers/admin/loginstyle.php | 220 ------------------------------ app/views/admin/login_style/edit_faq.php | 7 +- app/views/admin/login_style/login_faq.php | 91 +++++++----- app/views/admin/login_style/newpic.php | 5 +- public/pictures/loginbackgrounds/9.png | Bin 0 -> 173856 bytes templates/_standard_loginform.php | 10 +- 8 files changed, 286 insertions(+), 340 deletions(-) delete mode 100644 app/controllers/admin/login_faq.php create mode 100644 app/controllers/admin/login_style.php delete mode 100644 app/controllers/admin/loginstyle.php create mode 100644 public/pictures/loginbackgrounds/9.png diff --git a/app/controllers/admin/login_faq.php b/app/controllers/admin/login_faq.php deleted file mode 100644 index 611277f..0000000 --- a/app/controllers/admin/login_faq.php +++ /dev/null @@ -1,74 +0,0 @@ - - * @license GPL2 or any later version - * @category Stud.IP - * @package admin - * @since 5.5 - */ -class Admin_LoginFaqController extends AuthenticatedController -{ - protected $_autobind = true; - public function before_filter(&$action, &$args) - { - if ($action === 'add') { - $action = 'edit'; - } - - parent::before_filter($action, $args); - $GLOBALS['perm']->check('admin'); - PageLayout::setTitle(_('Hinweise zum Login')); - Navigation::activateItem('/admin/locations/login_faq'); - } - - public function index_action() - { - $this->setupSidebar(); - $this->faq_entries = LoginFaq::findBySql('1'); - } - - - public function edit_action(LoginFaq $entry = null) - { - PageLayout::setTitle( - $entry->isNew() ? _('Hilfetext hinzufügen') : _('Hilfetext bearbeiten') - ); - } - - public function store_action(LoginFaq $entry = null) - { - CSRFProtection::verifyRequest(); - $entry->setData([ - 'title' => Request::get('title'), - 'description' => Request::get('description'), - ]); - - if ($entry->store()) { - PageLayout::postSuccess(_('Hilfetext wurde gespeichert.')); - } - $this->redirect($this->indexURL()); - } - - public function delete_action($faq_entry_id) - { - CSRFProtection::verifyRequest(); - - if (LoginFaq::deleteBySQL('faq_id = ?', [$faq_entry_id])) { - PageLayout::postSuccess(_("Der Hilfetext wurde gelöscht.")); - } - $this->relocate($this->indexURL()); - } - - protected function setupSidebar() - { - $actions = new ActionsWidget(); - $actions->addLink( - _('Hilfetext hinzufügen'), - $this->edit_URL(), - Icon::create('add') - )->asDialog(); - Sidebar::get()->addWidget($actions); - } -} diff --git a/app/controllers/admin/login_style.php b/app/controllers/admin/login_style.php new file mode 100644 index 0000000..7d379d9 --- /dev/null +++ b/app/controllers/admin/login_style.php @@ -0,0 +1,219 @@ + + * @license GPL2 or any later version + * @category Stud.IP + * @package admin + * @since 4.0 + */ + +class Admin_LoginStyleController extends AuthenticatedController +{ + protected $_autobind = true; + /** + * common tasks for all actions + * + * @param String $action Action that has been called + * @param Array $args List of arguments + */ + public function before_filter(&$action, &$args) + { + parent::before_filter($action, $args); + + $GLOBALS['perm']->check('root'); + + //setting title and navigation + PageLayout::setTitle(_('Hintergrundbilder für den Startbildschirm')); + Navigation::activateItem('/admin/locations/loginstyle'); + + $views = new ViewsWidget(); + $views->addLink( + _('Bilder'), + $this->indexURL() + )->setActive($action === 'index'); + + $views->addLink( + _('Hinweise zum Login'), + $this->login_faqURL() + )->setActive($action === 'login_faq'); + + Sidebar::Get()->addWidget($views); + } + + /** + * Display all available background pictures + */ + public function index_action() + { + // Setup sidebar + $this->setSidebar('index'); + $this->pictures = LoginBackground::findBySQL("1 ORDER BY `background_id`"); + } + + /** + * Provides a form for uploading a new picture. + */ + public function newpic_action() + { + } + + /** + * Adds a new picture ass possible login background. + */ + public function add_pic_action() + { + CSRFProtection::verifyRequest(); + $success = 0; + foreach ($_FILES['pictures']['name'] as $index => $filename) { + if ($_FILES['pictures']['error'][$index] !== UPLOAD_ERR_OK) { + continue; + } + + $extension = pathinfo($filename, PATHINFO_EXTENSION); + $extension = strtolower($extension); + if (!in_array($extension, ['gif', 'jpeg', 'jpg', 'png'])) { + continue; + } + + $entry = new LoginBackground(); + $entry->filename = $filename; + $entry->desktop = Request::int('desktop', 0); + $entry->mobile = Request::int('mobile', 0); + if ($entry->store()) { + $destination = LoginBackground::getPictureDirectory() . DIRECTORY_SEPARATOR + . $entry->id . '.' . $extension; + if (move_uploaded_file($_FILES['pictures']['tmp_name'][$index], $destination)) { + $success++; + } else { + $entry->delete(); + } + } + } + + if ($success > 0) { + PageLayout::postSuccess(sprintf(ngettext( + 'Ein Bild wurde hochgeladen.', + '%u Bilder wurden hochgeladen', + $success + ), $success)); + } + + $fail = count($_FILES['pictures']['name']) - $success; + if ($fail > 0) { + PageLayout::postError(sprintf(ngettext( + 'Ein Bild konnte nicht hochgeladen werden.', + '%u Bilder konnten nicht hochgeladen werden.', + $fail + ), $fail)); + } + $this->relocate($this->indexURL()); + } + + /** + * Deletes the given picture. + * @param string $id the picture to delete + */ + public function delete_pic_action($id) + { + CSRFProtection::tokenTag(); + $pic = LoginBackground::find($id); + if ($pic->in_release) { + PageLayout::postError(_('Dieses Bild wird vom System mitgeliefert und kann daher nicht gelöscht werden.')); + } elseif ($pic->delete()) { + PageLayout::postSuccess(_('Das Bild wurde gelöscht.')); + } else { + PageLayout::postError(_('Das Bild konnte nicht gelöscht werden.')); + } + + $this->relocate($this->indexURL()); + } + + /** + * (De-)activate the given picture for given view. + * @param string $id the picture to change activation for + * @param string $view one of 'desktop', 'mobile', view to (de-) activate picture for + * @param string $newStatus new activation status for given view. + */ + public function activation_action($id, $view, $newStatus) + { + CSRFProtection::tokenTag(); + $pic = LoginBackground::find($id); + $pic->$view = $newStatus; + if ($pic->store()) { + PageLayout::postSuccess(_('Der Aktivierungsstatus wurde gespeichert.')); + } else { + PageLayout::postSuccess(_('Der Aktivierungsstatus konnte nicht gespeichert werden.')); + } + $this->relocate($this->indexURL()); + } + + + /** + * FAQ part of login page + */ + public function login_faq_action() + { + PageLayout::setTitle(_('Hinweise zum Login für den Startbildschirm')); + + $this->setSidebar('login_faq'); + $this->faq_entries = LoginFaq::findBySql('1'); + } + + public function edit_faq_action(LoginFaq $entry = null) + { + PageLayout::setTitle( + $entry->isNew() ? _('Hilfetext hinzufügen') : _('Hilfetext bearbeiten') + ); + } + + public function store_faq_action(LoginFaq $entry = null) + { + CSRFProtection::verifyRequest(); + + $entry->setData([ + 'title' => Request::get('title'), + 'description' => Request::get('description'), + ]); + + if ($entry->store()) { + PageLayout::postSuccess(_('Hilfetext wurde gespeichert.')); + } + + $this->relocate($this->login_faqURL()); + } + + public function delete_faq_action(LoginFaq $entry) + { + CSRFProtection::verifyRequest(); + + if ($entry->delete()) { + PageLayout::postSuccess(_('Der Hilfetext wurde gelöscht')); + } + + $this->relocate($this->login_faqURL()); + } + + /** + * Adds the content to sidebar + */ + protected function setSidebar($action) + { + $links = new ActionsWidget(); + if ($action === 'index') { + $links->addLink( + _('Bild hinzufügen'), + $this->newpicURL(), + Icon::create('add') + )->asDialog('size=auto'); + } else if ($action === 'login_faq') { + $links->addLink( + _('Hilfetext hinzufügen'), + $this->edit_faqURL(), + Icon::create('add') + )->asDialog(); + } + Sidebar::get()->addWidget($links); + } +} diff --git a/app/controllers/admin/loginstyle.php b/app/controllers/admin/loginstyle.php deleted file mode 100644 index 6358d26..0000000 --- a/app/controllers/admin/loginstyle.php +++ /dev/null @@ -1,220 +0,0 @@ - - * @license GPL2 or any later version - * @category Stud.IP - * @package admin - * @since 4.0 - */ - -class Admin_LoginStyleController extends AuthenticatedController -{ - protected $_autobind = true; - /** - * common tasks for all actions - * - * @param String $action Action that has been called - * @param Array $args List of arguments - */ - public function before_filter(&$action, &$args) - { - parent::before_filter($action, $args); - - $GLOBALS['perm']->check('root'); - - //setting title and navigation - PageLayout::setTitle(_('Hintergrundbilder für den Startbildschirm')); - Navigation::activateItem('/admin/locations/loginstyle'); - - $views = new ViewsWidget(); - $views->addLink( - _('Bilder'), - $this->indexURL() - )->setActive($action === 'index'); - - $views->addLink( - _('Hinweise zum Login'), - $this->url_for('admin/loginstyle/login_faq') - )->setActive($action === 'login_faq'); - - Sidebar::Get()->addWidget($views); - } - - /** - * Display all available background pictures - */ - public function index_action() - { - // Setup sidebar - $this->setSidebar('index'); - $this->pictures = LoginBackground::findBySQL("1 ORDER BY `background_id`"); - } - - /** - * Provides a form for uploading a new picture. - */ - public function newpic_action() - { - } - - /** - * Adds a new picture ass possible login background. - */ - public function add_pic_action() - { - CSRFProtection::verifyRequest(); - $success = 0; - foreach ($_FILES['pictures']['name'] as $index => $filename) { - if ($_FILES['pictures']['error'][$index] !== UPLOAD_ERR_OK) { - continue; - } - - $extension = pathinfo($filename, PATHINFO_EXTENSION); - $extension = strtolower($extension); - if (!in_array($extension, ['gif', 'jpeg', 'jpg', 'png'])) { - continue; - } - - $entry = new LoginBackground(); - $entry->filename = $filename; - $entry->desktop = Request::int('desktop', 0); - $entry->mobile = Request::int('mobile', 0); - if ($entry->store()) { - $destination = LoginBackground::getPictureDirectory() . DIRECTORY_SEPARATOR - . $entry->id . '.' . $extension; - if (move_uploaded_file($_FILES['pictures']['tmp_name'][$index], $destination)) { - $success++; - } else { - $entry->delete(); - } - } - } - - if ($success > 0) { - PageLayout::postSuccess(sprintf(ngettext( - 'Ein Bild wurde hochgeladen.', - '%u Bilder wurden hochgeladen', - $success - ), $success)); - } - - $fail = count($_FILES['pictures']['name']) - $success; - if ($fail > 0) { - PageLayout::postError(sprintf(ngettext( - 'Ein Bild konnte nicht hochgeladen werden.', - '%u Bilder konnten nicht hochgeladen werden.', - $fail - ), $fail)); - } - $this->relocate($this->indexURL()); - } - - /** - * Deletes the given picture. - * @param string $id the picture to delete - */ - public function delete_pic_action($id) - { - CSRFProtection::tokenTag(); - $pic = LoginBackground::find($id); - if ($pic->in_release) { - PageLayout::postError(_('Dieses Bild wird vom System mitgeliefert und kann daher nicht gelöscht werden.')); - } elseif ($pic->delete()) { - PageLayout::postSuccess(_('Das Bild wurde gelöscht.')); - } else { - PageLayout::postError(_('Das Bild konnte nicht gelöscht werden.')); - } - - $this->relocate($this->indexURL()); - } - - /** - * (De-)activate the given picture for given view. - * @param string $id the picture to change activation for - * @param string $view one of 'desktop', 'mobile', view to (de-) activate picture for - * @param string $newStatus new activation status for given view. - */ - public function activation_action($id, $view, $newStatus) - { - CSRFProtection::tokenTag(); - $pic = LoginBackground::find($id); - $pic->$view = $newStatus; - if ($pic->store()) { - PageLayout::postSuccess(_('Der Aktivierungsstatus wurde gespeichert.')); - } else { - PageLayout::postSuccess(_('Der Aktivierungsstatus konnte nicht gespeichert werden.')); - } - $this->relocate('admin/loginstyle'); - } - - - /** - * FAQ part of login page - */ - public function login_faq_action() - { - PageLayout::setTitle(_('Hinweise zum Login für den Startbildschirm')); - - $this->setSidebar('login_faq'); - $this->faq_entries = LoginFaq::findBySql('1'); - } - - public function edit_faq_action(LoginFaq $entry = null) - { - PageLayout::setTitle( - $entry->isNew() ? _('Hilfetext hinzufügen') : _('Hilfetext bearbeiten') - ); - } - - public function store_faq_action(LoginFaq $entry = null) - { - CSRFProtection::verifyRequest(); - - $entry->setData([ - 'title' => Request::get('title'), - 'description' => Request::get('description'), - ]); - - if ($entry->store()) { - PageLayout::postSuccess(_('Hilfetext wurde gespeichert.')); - } - - $this->relocate($this->login_faqURL()); - } - - public function delete_faq_action($faq_entry_id) - { - CSRFProtection::verifyRequest(); - - if (LoginFaq::deleteBySQL('faq_id = ?', [$faq_entry_id])) { - PageLayout::postSuccess(_('Der Hilfetext wurde gelöscht')); - } - - $this->relocate($this->login_faqURL()); - } - - /** - * Adds the content to sidebar - */ - protected function setSidebar($action) - { - - $links = new ActionsWidget(); - if ($action === 'index') { - $links->addLink( - _('Bild hinzufügen'), - $this->newpicURL(), - Icon::create('add') - )->asDialog('size=auto'); - } else if ($action === 'login_faq') { - $links->addLink( - _('Hilfetext hinzufügen'), - $this->add_faqURL(), - Icon::create('add') - )->asDialog(); - } - Sidebar::get()->addWidget($links); - } -} diff --git a/app/views/admin/login_style/edit_faq.php b/app/views/admin/login_style/edit_faq.php index 768434e..b31a7a5 100644 --- a/app/views/admin/login_style/edit_faq.php +++ b/app/views/admin/login_style/edit_faq.php @@ -8,14 +8,17 @@ method="post" enctype="multipart/form-data" class="default"> + -