* @link https://TheTempusProject.com * @license https://opensource.org/licenses/MIT [MIT LICENSE] */ namespace TheTempusProject\Controllers\Admin; use TheTempusProject\TTPForms; use TheTempusProject\Houdini\Classes\Views; use TheTempusProject\Houdini\Classes\Issues; use TheTempusProject\Houdini\Classes\Navigation; use TheTempusProject\Houdini\Classes\Components; use TheTempusProject\Houdini\Classes\Forms; use TheTempusProject\Classes\AdminController; use TheTempusProject\Models\Routes as RoutesClass; use TheTempusProject\Bedrock\Functions\Input; use TheTempusProject\Bedrock\Functions\Check; use TheTempusProject\Hermes\Functions\Redirect; use TheTempusProject\Bedrock\Functions\Session; class Routes extends AdminController { public static $routes; public function __construct() { parent::__construct(); self::$title = 'Admin - Redirects'; self::$routes = new RoutesClass; $view = Navigation::activePageSelect( 'nav.admin', '/admin/routes' ); Components::set( 'ADMINNAV', $view ); } public function create() { if ( Input::exists( 'redirect_type' ) ) { if ( !TTPForms::check( 'createRoute' ) ) { Issues::add( 'error', [ 'There was an error with your route.' => Check::userErrors() ] ); } if ( self::$routes->create( Input::post( 'original_url' ), Input::post( 'forwarded_url' ), Input::post( 'nickname' ), Input::post( 'redirect_type' ) ) ) { Session::flash( 'success', 'Route Created' ); Redirect::to( 'admin/routes' ); } } Views::view( 'admin.routes.create' ); } public function delete( $id = null ) { if ( Input::exists( 'submit' ) ) { $id = Input::post( 'R_' ); } if ( self::$routes->delete( [ $id ] ) ) { Session::flash( 'success', 'Route(s) deleted.' ); } else { Session::flash( 'error', 'There was an error with your request.' ); } Redirect::to( 'admin/routes' ); } public function edit( $id = null ) { $route = self::$routes->findById( $id ); if ( Input::exists( 'redirect_type' ) ) { if ( !TTPForms::check( 'editRoute' ) ) { Issues::add( 'error', [ 'There was an error with your route.' => Check::userErrors() ] ); } else { if ( self::$routes->update( $id, Input::post( 'original_url' ), Input::post( 'forwarded_url' ), Input::post( 'nickname' ), Input::post( 'redirect_type' ) ) ) { Session::flash( 'success', 'Route Updated' ); Redirect::to( 'admin/routes' ); } } } Forms::selectOption( $route->redirect_type ); return Views::view( 'admin.routes.edit', $route ); } public function index() { return Views::view( 'admin.routes.list', self::$routes->list() ); } public function view( $id = null ) { return Views::view( 'admin.routes.view', self::$routes->findById( $id ) ); } }