Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Admin controller
- *
- * @package Comandeer/Controller
- * @author Comandeer
- * @copyright (c) 2014 Comandeer
- * @license EULA
- */
- namespace Comandeer\Controller;
- use \Comandeer\Auth, \Comandeer\Model, \Comandeer\Mailer;
- class Admin extends \Comandeer\Controller
- {
- /**
- * Generates admin's panel homepage
- *
- * @return void
- */
- public function get_index()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $this->app->render('partials/admin/homepage.twig');
- }
- //SETTINGS
- /**
- * Shows form for editing settings
- *
- * @return void
- */
- public function get_settings()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $this->app->render('/partials/admin/settings.twig');
- }
- /**
- * Handles updating settings
- *
- * @return void
- */
- public function post_settings()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- file_put_contents('./config.php', '<?php return ' . var_export(array_merge($this->config, $this->app->request->post()), true) . ';');
- $this->app->response->redirect('/admin');
- }
- //USERS
- /**
- * Show all users
- *
- * @return void
- */
- public function get_users()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $users = Model::factory('User')->getUsers();
- $this->app->render('partials/admin/users.twig', [
- 'users' => $users
- ]);
- }
- /**
- * Show specified user
- *
- * @return void
- */
- public function get_user($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $user = Model::factory('User')->getUser($id);
- $this->app->render('partials/admin/user.twig', [
- 'user' => $user
- ]);
- }
- /**
- * Generates user's edit form
- *
- * @return void
- */
- public function get_userEdit($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $user = Model::factory('User')->getData($id);
- $this->app->render('/partials/admin/user-edit.twig', [
- 'user' => $user
- ]);
- }
- /**
- * Handles user's edit
- *
- * @return void
- */
- public function post_userEdit($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- Model::factory('User')->updateUser($id, $this->app->request->post());
- $this->app->response->redirect('/admin/uzytkownicy', 303);
- }
- /**
- * Generates new password for user and sends it via e-mail
- *
- * @return void
- */
- public function get_userPassword($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $password = substr(uniqid(rand(0, 9999), true), 0, 8);
- $user = Model::factory('User')->getData($id);
- Model::factory('User')->updatePassword($id, $password);
- \Comandeer\Mailer::send([$user['email']], 'Zmiana hasła', $this->view->render('mails/password.twig', [
- 'password' => $password
- ]), $this->config['admin']);
- $this->app->response->redirect('/admin/uzytkownicy', 303);
- }
- /**
- * Delete user
- *
- * @return void
- */
- public function get_userDelete($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- Model::factory('User')->deleteUser($id);
- $this->app->response->redirect('/admin/uzytkownicy', 303);
- }
- /**
- * Activates user
- *
- * @return void
- */
- public function get_userActivate($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $model = Model::factory('User');
- $user = $model->getData($id);
- $model->updatePayment($id);
- \Comandeer\Mailer::send([$user['email']], 'Link aktywacyjny', $this->view->render('mails/activation.twig', [
- 'name' => $user['name']
- ,'hash' => $user['hash']
- ]), $this->config['admin']);
- $this->app->response->redirect('/admin/uzytkownicy', 303);
- }
- //WIZARD
- /**
- * Generate wizard list
- *
- * @return void
- */
- public function get_wizard()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $questions = Model::factory('Wizard')->generate();
- $this->app->render('/partials/admin/wizard.twig', [
- 'questions' => $questions
- ]);
- }
- /**
- * Generate form for adding question to wizard
- *
- * @return void
- */
- public function get_wizardAdd()
- {
- $this->app->render('/partials/admin/wizard-edit.twig');
- }
- /**
- * Handles adding questions to wizard
- *
- * @return void
- */
- public function post_wizardAdd()
- {
- Model::factory('Wizard')->addQuestion($this->app->request->post());
- $this->app->response->redirect('/admin/kreator', 303);
- }
- /**
- * Generate form for editing question in wizard
- *
- * @return void
- */
- public function get_wizardEdit($id)
- {
- $question = Model::factory('Wizard')->getQuestion($id);
- $this->app->render('/partials/admin/wizard-edit.twig', [
- 'question' => $question
- ]);
- }
- /**
- * Handling editing question in wizard
- *
- * @return void
- */
- public function post_wizardEdit($id)
- {
- Model::factory('Wizard')->updateQuestion($id, $this->app->request->post());
- $this->app->response->redirect('/admin/kreator', 303);
- }
- /**
- * Deletes question
- *
- * @return void
- */
- public function get_wizardDelete($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- Model::factory('Wizard')->deleteQuestion($id);
- $this->app->response->redirect('/admin/kreator', 303);
- }
- //OFFERS
- /**
- * Shows users' offers
- *
- * @return void
- */
- public function get_offers()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $offers = Model::factory('Offers')->getAll();
- $this->app->render('/partials/admin/offers.twig', [
- 'offers' => $offers
- ]);
- }
- /**
- * Shows offers from archive
- *
- * @return void
- */
- public function get_offersArchived()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $offers = Model::factory('Offers')->getArchived();
- $this->app->render('/partials/admin/offers-archive.twig', [
- 'offers' => $offers
- ]);
- }
- /**
- * Shows specified offer
- *
- * @param $id integer offer's id
- * @return void
- */
- public function get_offer($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $offer = Model::factory('Offers')->getOffer($id);
- if(!$offer)
- $this->app->response->redirect('/admin/zapytania', 303);
- $this->app->render('partials/admin/offer.twig', [
- 'offer' => $offer
- ]);
- }
- /**
- * Archive specified offer
- *
- * @param $id integer offer's id
- * @return void
- */
- public function get_offerArchive($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- Model::factory('Offers')->archiveOffer($id);
- $this->app->response->redirect('/admin/zapytania', 303);
- }
- /**
- * Deletes offer
- *
- * @param $id integer offer's id
- * @return void
- */
- public function get_offerDelete($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- Model::factory('Offers')->deleteOffer($id);
- $this->app->response->redirect($this->app->request->get('archive') ? '/admin/zapytania/archiwum' : '/admin/zapytania', 303);
- }
- //BILLS
- /**
- * Show all current bills
- *
- * @return void
- */
- public function get_bills()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $bills = Model::factory('Bills')->getAll();
- $this->app->render('/partials/admin/bills.twig', [
- 'bills' => $bills
- ]);
- }
- /**
- * Show all archived bills
- *
- * @return void
- */
- public function get_billsArchived()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $bills = Model::factory('Bills')->getArchived();
- $this->app->render('/partials/admin/bills-archive.twig', [
- 'bills' => $bills
- ]);
- }
- /**
- * Get specified bill
- *
- * @param $id integer bill's id
- * @return void
- */
- public function get_bill($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $file = Model::factory('Bills')->getBill($id);
- $this->app->response->headers->set('Content-Type', 'application/pdf');
- $this->app->response->headers->set('Content-Disposition', 'attachment; filename="wycena.pdf"');
- $this->app->response->setBody($file);
- }
- /**
- * Generates form for generating bill
- *
- * @return void
- */
- public function get_billNew()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $user = $this->app->request->get('user');
- if(!$user)
- $this->app->response->redirect('/admin/wyceny', 303);
- $this->app->render('partials/admin/generate-bill.twig', [
- 'user' => $user
- ,'image' => $this->config['image']
- ]);
- }
- /**
- * Generates new bill
- *
- * @return void
- */
- public function post_billNew()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $data = $this->app->request->post();
- $data['image'] = isset($data['image']) && filter_var($data['image'], FILTER_VALIDATE_URL) ? $data['image'] : $this->config['image'];
- $filename = Model::factory('Bills')->generateBill($data, $this->view);
- $email = Model::factory('User')->getData($data['user'], 'email');
- \Comandeer\Mailer::send([$email], 'Wycena dostępna', $this->view->render('mails/new_bill.twig'), $this->config['admin'], [
- [
- DIR . '/files/' . $filename
- ,'wycena.pdf'
- ]
- ]);
- $this->app->response->redirect('/admin/wyceny');
- }
- //BANS
- /**
- * Shows list of all bans
- *
- * @return void
- */
- public function get_banned()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $banned = Model::factory('User')->getBanned();
- $this->app->render('partials/admin/banned.twig', [
- 'banned' => $banned
- ]);
- }
- /**
- * Shows bans' form
- *
- * @return void
- */
- public function get_banNew()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $this->app->render('partials/admin/ban-new.twig');
- }
- /**
- * Handles ban's form
- *
- * @return void
- */
- public function post_banNew()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $who = $this->app->request->post('who');
- switch($this->app->request->post('type'))
- {
- case 'user':
- $model = Model::factory('User');
- $model->banUser($model->getUserBy('name', $who)['id']);
- break;
- case 'ip':
- Model::factory('User')->banIp($who);
- break;
- case 'email':
- Model::factory('User')->banEmail($who);
- break;
- }
- $this->app->response->redirect('/admin/zbanowani', 303);
- }
- /**
- * Ban user
- *
- * @param $user integer user's id
- * @return void
- */
- public function get_banUser($user)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- Model::factory('User')->banUser($user);
- $this->app->response->redirect('/admin/zbanowani', 303);
- }
- /**
- * Unban
- *
- * @param $id integer ban's id
- * @return void
- */
- public function get_unban($id)
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- Model::factory('User')->unban($id);
- $this->app->response->redirect('/admin/zbanowani', 303);
- }
- //SEARCH
- /**
- * Search user
- *
- * @return void
- */
- public function get_search()
- {
- if(!Auth::isAdmin())
- $this->app->response->redirect('/', 303);
- $query = $this->app->request->get('query');
- if(!$query)
- $this->app->response->redirect('/admin/uzytkownicy', 303);
- $users = Model::factory('User')->search($query);
- $this->app->render('partials/admin/users.twig', [
- 'users' => $users
- ,'query' => $query
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement