public function action_index() { $username = $this->request->param('username'); $this->view = new View_Message_Create(); $this->view->username = $username; if ($this->request->method() == HTTP_Request::POST) { try { $post = $this->request->post(); $receiver = ORM::factory('User')->where('username', '=', $post['receiver'])->find(); if (!$receiver->loaded()) { return Hint::error('Cannot find a user with the username: '******'You cannot send a message to yourself!'); } $message_data = Arr::merge($this->request->post(), array('sender_id' => $this->user->id, 'receiver_id' => $receiver->id)); $message = ORM::factory('Message')->create_message($message_data, array('receiver_id', 'subject', 'content', 'sender_id')); $message_data_sent = Arr::merge($this->request->post(), array('receiver_id' => $this->user->id, 'sender_id' => $receiver->id, 'sent' => 1, 'read' => 1)); ORM::factory('Message')->create_message($message_data_sent, array('receiver_id', 'subject', 'content', 'sender_id', 'sent', 'read')); Hint::success('You have sent a message'); $this->redirect(Route::get('message.inbox')->uri()); } catch (ORM_Validation_Exception $e) { Hint::error($e->errors('models')); } } }
/** * Bootstrap the application services. * * @return void */ public function boot() { // Publish config $configPath = __DIR__ . '/../../config/config.php'; $this->publishes([$configPath => config_path('liebigCron.php')], 'config'); // Build in Cron run route \Route::get('cron.php', function () { // Get security key from config $cronkeyConfig = \Config::get('liebigCron.cronKey'); // If no security key is set in the config, this route is disabled if (empty($cronkeyConfig)) { \Log::error('Cron route call with no configured security key'); \App::abort(404); } // Get security key from request $cronkeyRequest = \Input::get('key'); // Create validator for security key $validator = \Validator::make(array('cronkey' => $cronkeyRequest), array('cronkey' => 'required|alpha_num')); if ($validator->passes()) { if ($cronkeyConfig === $cronkeyRequest) { \Artisan::call('cron:run', array()); } else { // Configured security key is not equals the sent security key \Log::error('Cron route call with wrong security key'); \App::abort(404); } } else { // Validation not passed \Log::error('Cron route call with missing or no alphanumeric security key'); \App::abort(404); } }); }
/** * CRUD controller: UPDATE */ public function action_update() { $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $this->request->param('id'); $form = new FormOrm($this->_orm_model, $this->request->param('id')); if ($this->request->post()) { if ($success = $form->submit()) { if (Valid::email($form->object->email, TRUE)) { //check we have this email in the DB $user = new Model_User(); $user = $user->where('email', '=', Kohana::$_POST_ORIG['formorm']['email'])->where('id_user', '!=', $this->request->param('id'))->limit(1)->find(); if ($user->loaded()) { Alert::set(Alert::ERROR, __('A user with the email you specified already exists')); } else { $form->save_object(); Alert::set(Alert::SUCCESS, __('Item updated') . '. ' . __('Please to see the changes delete the cache') . '<br><a class="btn btn-primary btn-mini ajax-load" href="' . Route::url('oc-panel', array('controller' => 'tools', 'action' => 'cache')) . '?force=1" title="' . __('Delete cache') . '">' . __('Delete cache') . '</a>'); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller()))); } } else { Alert::set(Alert::ERROR, __('Invalid Email')); } } else { Alert::set(Alert::ERROR, __('Check form for errors')); } } return $this->render('oc-panel/pages/user/update', array('form' => $form)); }
public function action_index() { $loader_uri = Jx_Loader::uri(array('file' => array('loader'), 'clearSession' => 'true', 'rebuild' => 'true', 'compress' => 'false')); Jx_Assets::add_js_file('options', 'main', 'options'); Jx_Assets::add_js_file($loader_uri, 'main', 'loader', 'options'); //add the menu $menu = Jx_Menu::get_admin_menu(); $menu = json_encode($menu); $menu_script = <<<MENU var menu = {$menu}; MENU; Jx_Assets::add_js_script($menu_script, 'main', 'menu', 'loader'); $loader_uri = Jx_Loader::uri(array('file' => array('admin'))); $script = <<<'SCRIPT' $uses(['admin'],'admin',null,function(){}); SCRIPT; Jx_Assets::add_js_script($script, 'main', 'admin', 'menu'); //styles... hide the page $styles = <<<styles #page-container { visibility: hidden; opacity: 0; } styles; Jx_Assets::add_css_styles($styles, 'main', 'hide_page'); //other things needed $this->template->username = $this->auth->get_user()->username; $this->template->logout_link = Route::get('users')->uri(array('action' => 'logout')); }
public function action_index() { $view = View::factory('kadldap/index'); $this->template->content = $view; $this->template->title = 'Kadldap'; $this->template->menu = NULL; $this->template->breadcrumb = array(Route::get('docs/guide')->uri() => __('User Guide'), Route::get('docs/guide')->uri() . '/kadldap.about' => $this->template->title, 'Configuration Test'); $view->message = FALSE; if (isset($_POST['login'])) { $post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('username', 'not_empty')->rule('username', 'min_length', array(1))->rule('password', 'not_empty'); if ($post->check()) { $username = $post['username']; $password = arr::get($post, 'password', ''); try { if (Auth::instance()->login($username, $password)) { $view->message = 'Successful login.'; } else { $view->message = 'Login failed.'; } } catch (adLDAPException $e) { $view->message = $e->getMessage(); } } else { $view->message = 'You must enter both your username and password.'; } } if (Auth::instance()->logged_in()) { $username = Auth::instance()->get_user(); $password = Auth::instance()->password($username); $view->kadldap = Kadldap::instance(); $view->kadldap->authenticate($username, $password); } }
private function registerRoutes() { Route::get('/account', MainController::class . '@index'); Route::get('/account/forms/fields', MainController::class . '@forms'); Route::post('/account/forms/user', MainController::class . '@formUser'); Route::post('/account/forms/password', MainController::class . '@formPassword'); Route::post('/account/forms/card/save', MainController::class . '@formCardSave'); Route::post('/account/forms/autopay/save', MainController::class . '@formAutopaySave'); Route::post('/account/forms/card/remove', MainController::class . '@formCardRemove'); Route::get('/account/orders', MainController::class . '@orders'); Route::get('/account/history', MainController::class . '@history'); Route::get('/account/order/{id}', MainController::class . '@order'); Route::get('/account/order/services/{id}', MainController::class . '@orderServices'); Route::get('/account/order/services/pdf/{id}', MainController::class . '@orderServicesPdf'); Route::get('/account/pay/init/{id}/{target}/{reset}', MainController::class . '@pay'); Route::get('/account/new_card', MainController::class . '@newCard'); Route::post('/account/delete_card', MainController::class . '@deleteCard'); Route::post('/account/autopay', MainController::class . '@autopay'); Route::post('/account/pay_finish', MainController::class . '@payFinish'); Route::get('/account/pay/card', MainController::class . '@card'); Route::get('/account/prepayment', MainController::class . '@prepayment'); Route::post('/account/pay_by_token', MainController::class . '@payByToken'); Route::get('/account/pay/check/{id}', MainController::class . '@checkPay'); Route::post('/account/pay/token', MainController::class . '@token'); Route::post('/account/pay/refund', MainController::class . '@refund'); Route::get('/account/flash/message/{type}', ServiceController::class . '@flash'); Route::get('/account/bonus', MainController::class . '@bonus'); Route::get('/account/order/review/{id}', MainController::class . '@review'); Route::post('/account/order/review', MainController::class . '@reviewOrder'); Route::get('/account/subscriptions', MainController::class . '@subscriptions'); Route::get('/account/customers_cards', MainController::class . '@customersCards'); Route::get('/account/lang/{lang}', ['as' => 'lang.set', 'before' => 'lang.set', function () { return App::getLocale(); }]); }
public function action_index() { $breadcrumb = 'menu_navigation_production_applis'; $elements = ORM::factory('syntaxchecker_project')->order_by('namespace')->order_by('title')->find_all()->as_array('id'); $view = View::factory($this->request->controller() . '/' . $this->request->action(), array('elements' => $elements)); Design::instance()->set_title(__($breadcrumb))->set_breadcrumb('index', __($breadcrumb), Route::get('default')->uri(array('controller' => 'applis', 'action' => 'index')))->set_content('index', $view); }
public function action_complete() { // Get the transaction details. $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send(); $data = $fetch->getData(); // Add the buyer email to parameters. $parameters = $this->_payment_vars() + array('email' => $data['EMAIL']); /** @var Payment_PayPal_CreateRecurringPaymentsRequest $request */ $request = $this->_gateway->createRecurringPaymentsProfile($parameters); // Overwrite Item Category. $data = $request->getData(); $data['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = $this->_config['itemCategory']; /** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */ $response = $request->sendData($data); if ($response->isSuccessful()) { $response_data = $response->getData(); // Get the transaction details. // $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send(); // $data = $fetch->getData(); ORM::factory('Payment_Subscription')->values(array('user_id' => $this->user->id, 'package_id' => $this->_package->id, 'status' => Model_Payment_Subscription::PENDING, 'recurring_payment_id' => $response_data['PROFILEID']))->create(); Hint::success(Kohana::message('payment', 'payment.success')); $this->redirect(Route::get('payment')->uri()); } else { // Log the error. Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData())); throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!'); } }
/** * Loads test suite */ public function before() { parent::before(); if( ! Kohana_Tests::enabled()) { // Pretend this is a normal 404 error... $this->status = 404; throw new Kohana_Request_Exception('Unable to find a route to match the URI: :uri', array(':uri' => $this->request->uri)); } // Prevent the whitelist from being autoloaded, but allow the blacklist // to be laoded Kohana_Tests::configure_enviroment(FALSE); $this->config = Kohana::$config->load('phpunit'); // This just stops some very very long lines $route = Route::get('unittest'); $this->report_uri = $route->uri(array('controller' => 'phpunit', 'action' => 'report')); $this->run_uri = $route->uri(array('controller' => 'phpunit', 'action' => 'run')); // Switch used to disable cc settings $this->xdebug_loaded = extension_loaded('xdebug'); $this->template->set_global('xdebug_enabled', $this->xdebug_loaded); }
/** * Basic logout action */ public function action_logout() { Auth::instance()->logout(); Session::instance()->destroy(); // $this->content = View::factory('admin/login'); $this->redirect(Route::get('login')->uri()); }
/** * * @return string */ public function user() { if (empty($this->user_id)) { return NULL; } return HTML::anchor(Route::get('backend')->uri(array('controller' => 'users', 'action' => 'profile', 'id' => $this->user->id)), $this->user->username); }
/** * Returns a string with a backend url string based on arguments * * @param string $controller * @param string $action * @param mixed $id * @return string */ public static function backend($controller = null, $action = null, $id = null) { if (!is_array($controller)) { $controller = array('controller' => $controller, 'action' => $action, 'id' => $id); } return URL::site(Route::get('backend')->uri($controller)); }
public static function handler(Exception $e) { if (Kohana::$environment !== Kohana::PRODUCTION) { parent::handler($e); } else { try { //not saving 404 as error if ($e->getCode() != 404) { Kohana::$log->add(Log::ERROR, parent::text($e)); } $params = array('action' => 500, 'origuri' => rawurlencode(Arr::get($_SERVER, 'REQUEST_URI')), 'message' => rawurlencode($e->getMessage())); if ($e instanceof HTTP_Exception) { $params['action'] = $e->getCode(); } //d($params); // Error sub-request. echo Request::factory(Route::get('error')->uri($params))->execute()->send_headers()->body(); } catch (Exception $e) { // Clean the output buffer if one exists ob_get_level() and ob_clean(); // Display the exception text echo parent::text($e); // Exit with an error status exit(1); } } }
/** * Render view. * * @return string */ public function content() { ob_start(); ?> <ul class="thumbnails"> <?php foreach ($this->flyers as $flyer) { $name = $flyer->event ? $flyer->event->name : $flyer->name; ?> <li class="span2"> <?php echo HTML::anchor(Route::get('flyer')->uri(array('id' => $flyer->id)), HTML::image($flyer->image->get_url('thumbnail')), array('class' => 'thumbnail')); ?> <h4><?php echo HTML::anchor(Route::get('flyer')->uri(array('id' => $flyer->id)), HTML::chars($name), array('title' => HTML::chars($name))); ?> </h4> </li> <?php } ?> </ul> <?php return ob_get_clean(); }
public static function url_to_route($route_str) { $route_name = self::route_name($route_str); $route_name = mb_strtolower($route_name); $route_params = self::route_params($route_str); return Route::get($route_name)->uri($route_params); }
public function action_index() { $job = ORM::factory('job'); $errors = array(); $this->template->content = View::factory('post')->set('job', $job)->bind('preview', $preview)->bind('errors', $errors); if (isset($_POST) and !empty($_POST)) { $job->values($_POST, array('company', 'location', 'website', 'email', 'title', 'description', 'apply')); if (isset($_POST['preview'])) { $preview = View::factory('job')->set('job', $job); } if (!isset($_POST['terms'])) { // TODO: Use Validation? $errors += array('terms' => __('Agree to the terms of use in order to post a job.')); } // Check the data against validation rules defined in the model if ($job->check()) { // Save the model if (empty($errors) and $job->save()) { // Redirect to job listing $this->request->redirect(Route::get('jobs')->uri()); } } else { $errors = $job->validate()->errors('post/errors') + $errors; } } }
public static function setRoutes($routes) { foreach ($routes as $c) { if (class_exists($c->action)) { if ($c->route_name == '/') { $routable = \Route::getInspector()->getRoutable($c->action, ''); } else { $routable = \Route::getInspector()->getRoutable($c->action, $c->route_name); } foreach ($routable as $k => $v) { if ($v[0]['verb'] == 'get') { if (isset($v[1])) { if ($v[1]['plain'] == '') { \Route::get('/', ['as' => '/', 'uses' => $c->action . '@' . $k]); } else { \Route::get($v[1]['plain'], ['as' => $v[1]['plain'], 'uses' => $c->action . '@' . $k]); } continue; } \Route::get($v[0]['plain'], ['as' => $v[0]['plain'], 'uses' => $c->action . '@' . $k]); } elseif ($v[0]['verb'] == 'post') { if (preg_match('/[\\s\\S]+\\/index/', $v[0]['plain'])) { $v[0]['plain'] = str_replace('/index', '', $v[0]['plain']); } \Route::post($v[0]['plain'], ['as' => $v[0]['plain'], 'uses' => $c->action . '@' . $k]); } } if ($c->other_route != '') { \Route::controller($c->other_route, $c->action); } } } }
/** * CRUD controller: UPDATE */ public function action_update() { $id_role = $this->request->param('id'); //we do not allow modify the admin if ($id_role == Model_Role::ROLE_ADMIN) { Alert::set(Alert::WARNING, __('Admin Role can not be modified!')); $this->redirect(Route::url('oc-panel', array('controller' => 'role'))); } $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $id_role; $role = new Model_Role($id_role); if ($this->request->post() and $role->loaded()) { //delete all the access DB::delete('access')->where('id_role', '=', $role->id_role)->execute(); //set all the access where post = on foreach ($_POST as $key => $value) { if ($value == 'on') { DB::insert('access', array('id_role', 'access'))->values(array($role->id_role, str_replace('|', '.', $key)))->execute(); } } //saving the role params $role->name = core::post('name'); $role->description = core::post('description'); $role->save(); Alert::set(Alert::SUCCESS, __('Item updated')); $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller()))); } //getting controllers actions $controllers = Model_Access::list_controllers(); //get all the access this user has $query = DB::select('access')->from('access')->where('id_role', '=', $id_role)->execute(); $access_in_use = array_keys($query->as_array('access')); // d(in_array('access_index',$access_in_use)); //d($access_in_use); return $this->render('oc-panel/pages/role/update', array('role' => $role, 'controllers' => $controllers, 'access_in_use' => $access_in_use)); }
public function setRoutes() { $pages = collect(\Config::get('pages')); foreach ($pages as $page) { if (!$page['uses']) { continue; } switch ($page['method']) { case 'get': \Route::get($this->getUri($page), ['as' => $this->getName($page), 'uses' => $page['uses']]); break; case 'post': \Route::post($this->getUri($page), ['as' => $this->getName($page), 'uses' => $page['uses']]); break; case 'patch': \Route::patch($this->getUri($page), ['as' => $this->getName($page), 'uses' => $page['uses']]); break; case 'delete': \Route::patch($this->getUri($page), ['as' => $this->getName($page), 'uses' => $page['uses']]); break; case 'any': \Route::any($this->getUri($page), ['as' => $this->getName($page), 'uses' => $page['uses']]); } } }
public function setUp() { $this->assertInstanceOf('Supermon\\Url\\Uri', Route::get('test', 'test', 'test')); $this->assertInstanceOf('Supermon\\Url\\Uri', Route::post('test', 'test', 'test')); Route::get('test/{var}', 'testvar', 'testvar')->where('var', '[0-9]+'); parent::setUp(); }
public static function registerRoutes() { $class = get_class(); \Route::get("code/barcode/{code}", ['as' => "code.barcode.default", 'uses' => "{$class}@barcode"]); \Route::get("code/barcode/{code}/{type}", ['as' => "code.barcode", 'uses' => "{$class}@barcode"]); \Route::get("code/qrcode/{code}", ['as' => "code.qrcode", 'uses' => "{$class}@qrcode"]); }
/** * Generate a Response for the 404 Exception. * * The user should be shown a nice 404 page. * * @return Response */ public function get_response() { Kohana_Exception::log($this); $response = Request::factory(Route::get('default')->uri(array('controller' => 'Errors', 'action' => '404')))->execute(); $response->status(404); return $response; }
public function action_login() { if ($this->_auth->logged_in()) { // redirect to the user account $this->request->redirect(Route::get('admin')->uri(), 200); } // Disable sidebars on login page $this->_sidebars = FALSE; $this->title = __('Sign In'); $user = ORM::factory('user'); // Create form action $destination = isset($_GET['destination']) ? $_GET['destination'] : 'admin'; $params = array('action' => 'login'); $action = Route::get('admin/login')->uri($params) . URL::query(array('destination' => $destination)); if ($layout = kohana::find_file('views', 'layouts/login')) { $this->template->set_filename('layouts/login'); } $view = View::factory('admin/login')->set('use_username', Config::get('auth.username'))->set('post', $user)->set('action', $action)->bind('errors', $this->_errors); if ($this->valid_post('login')) { try { // Check Auth $user->login($this->request->post()); // If the post data validates using the rules setup in the user model Message::success(__('Welcome, %title!', array('%title' => $user->nick))); Log::info('User :name logged in.', array(':name' => $user->name)); // redirect to the user account $this->request->redirect(isset($_GET['destination']) ? $_GET['destination'] : 'admin', 200); } catch (Validation_Exception $e) { $this->_errors = $e->array->errors('login', TRUE); } } $this->response->body($view); }
public function action_user() { $id = (int) $this->request->param('id', 0); $post = ORM::factory('user', $id); if (!$post->loaded() or $id === 1) { Message::error(__("User doesn't exists!")); Log::error('Attempt to access non-existent user.'); $this->request->redirect(Route::get('admin/user')->uri(array('action' => 'list')), 404); } $this->title = __(':user Permissions', array(":user" => $post->name)); $action = Route::get('admin/permission')->uri(array('action' => 'user', 'id' => isset($post->id) ? $post->id : 0)); $view = View::factory('admin/permission/user')->set('post', $post)->set('oldperms', $post->perms())->set('permissions', ACL::all())->set('action', $action)->bind('errors', $this->_errors); if ($this->valid_post('permissions')) { $perms = array_filter($_POST['perms']); $post->data = array('permissions' => $perms); try { $post->save(); Message::success(__('Permissions: saved successful!')); $this->request->redirect(Route::get('admin/permission')->uri(array('action' => 'user', 'id' => $post->id))); } catch (ORM_Validation_Exception $e) { Message::error(__('Permissions save failed!')); $this->_errors = $e->errors('models', TRUE); } catch (Exception $e) { Message::error(__('Permissions save failed!')); $this->_errors = array($e->getMessage()); } } $this->response->body($view); }
/** * Bootstrap the application events. * * @return void */ public function boot() { $this->package('kkstudio/blog'); \Route::get('blog', '\\Kkstudio\\Blog\\Controllers\\BlogController@index'); \Route::get('blog/category/{slug}', '\\Kkstudio\\Blog\\Controllers\\BlogController@fromCategory'); \Route::get('blog/{slug}', '\\Kkstudio\\Blog\\Controllers\\BlogController@show'); \Route::group(['prefix' => 'admin', 'before' => 'admin'], function () { \Route::get('blog', '\\Kkstudio\\Blog\\Controllers\\BlogController@admin'); \Route::get('blog/create', '\\Kkstudio\\Blog\\Controllers\\BlogController@create'); \Route::post('blog/create', '\\Kkstudio\\Blog\\Controllers\\BlogController@postCreate'); \Route::get('blog/{slug}/edit', '\\Kkstudio\\Blog\\Controllers\\BlogController@edit'); \Route::post('blog/{slug}/edit', '\\Kkstudio\\Blog\\Controllers\\BlogController@postEdit'); \Route::get('blog/{slug}/delete', '\\Kkstudio\\Blog\\Controllers\\BlogController@delete'); \Route::post('blog/{slug}/delete', '\\Kkstudio\\Blog\\Controllers\\BlogController@postDelete'); // Categories \Route::get('blog/categories', '\\Kkstudio\\Blog\\Controllers\\BlogController@categories'); \Route::get('blog/categories/create', '\\Kkstudio\\Blog\\Controllers\\BlogController@category_create'); \Route::post('blog/categories/create', '\\Kkstudio\\Blog\\Controllers\\BlogController@category_postCreate'); \Route::get('blog/categories/{slug}/edit', '\\Kkstudio\\Blog\\Controllers\\BlogController@category_edit'); \Route::post('blog/categories/{slug}/edit', '\\Kkstudio\\Blog\\Controllers\\BlogController@category_postEdit'); \Route::get('blog/categories/{slug}/delete', '\\Kkstudio\\Blog\\Controllers\\BlogController@category_delete'); \Route::post('blog/categories/{slug}/delete', '\\Kkstudio\\Blog\\Controllers\\BlogController@category_postDelete'); \Route::post('blog/categories/swap', '\\Kkstudio\\Blog\\Controllers\\BlogController@category_swap'); }); }
public function action_index() { if ($this->request->method() == HTTP_Request::POST) { try { if ($this->request->post('active')) { $pet = ORM::factory('User_Pet')->where('user_pet.id', '=', $this->request->post('active'))->where('user_id', '=', $this->user->id)->find(); $pet->active = time(); $pet->save(); Hint::success($pet->name . ' is now your active pet.'); } if ($this->request->post('abandon')) { $pet = ORM::factory('User_Pet')->where('user_pet.id', '=', $this->request->post('abandon'))->where('user_id', '=', $this->user->id)->find(); $pet->user_id = NULL; $pet->abandoned = time(); $pet->save(); Hint::success('You have abandoned ' . $pet->name . '.'); } $this->redirect(Route::get('pets')->uri()); } catch (ORM_Validation_Exception $e) { Hint::error($e->errors('models')); } } $this->view = new View_Pet_Index(); $pets = ORM::factory('User_Pet')->where('user_id', '=', $this->user->id)->order_by('active', 'desc'); $paginate = Paginate::factory($pets)->execute(); $this->view->pagination = $paginate->render(); $this->view->pets = $paginate->result(); $this->view->pets_count = count($pets); $this->view->href = array('create' => Route::url('pet.create'), 'adopt' => Route::url('pet.adopt')); }
public function action_logout() { // Logout the current user $this->_kuaas->logout(); // Return the to the homepage $this->request->redirect(Route::get('home')->uri(), 202); }
public function action_buy() { $shop_id = $this->request->param('id'); $shop = ORM::factory('Shop', $shop_id); if (!$shop->loaded()) { Hint::error('You can\'t buy an item from a shop that does not exist.'); } elseif ($shop->status == 'closed') { Hint::error('You\'re trying to buy an item from a closed shop.'); } else { $item_id = $this->request->post('id'); $item = ORM::factory('Shop_Inventory')->where('shop_id', '=', $shop->id)->where('item_id', '=', $item_id)->find(); if (!$item->loaded()) { Hint::error('The item you tried to buy has already been sold.'); } elseif ($item->price > $this->user->get_property('points')) { Hint::error('You don\'t have enough points to buy ' . $item->item->name); } else { // retract the points $this->user->set_property('points', $this->user->get_property('points') - $item->price); $this->user->save(); // send over the item Item::factory($item->item)->to_user($this->user, 'shops.' . $shop_id); // remove from shop if needed if ($shop->stock_type != 'steady') { if ($item->stock - 1 == 0) { $item->delete(); } else { $item->stock -= 1; $item->save(); } } Hint::success('You\'ve successfully bought ' . $item->item->name); } } $this->redirect(Route::get('item.shops.view')->uri(array('id' => $shop_id))); }
public function action_index() { if ($this->auth->logged_in()) { $this->redirect(Route::get('user.dashboard')->uri()); } $this->view = new View_Welcome(); }
/** * * @param Datasource_Section $ds * @param Datasource_Document $doc */ public function action_post() { $id = (int) $this->request->post('id'); $doc = $this->_get_document($id); Session::instance()->set('post_data', $this->request->post()); try { $doc->read_values($this->request->post())->read_files($_FILES)->validate(); } catch (Validation_Exception $e) { Messages::errors($e->errors('validation')); $this->go_back(); } catch (DataSource_Exception_Document $e) { Messages::errors($e->getMessage()); $this->go_back(); } if ($doc->loaded()) { $this->section()->update_document($doc); } else { $doc = $this->section()->create_document($doc); } Messages::success(__('Document saved')); Session::instance()->delete('post_data'); // save and quit or save and continue editing? if ($this->request->post('commit') !== NULL) { $this->go(Route::get('datasources')->uri(array('directory' => 'datasources', 'controller' => 'data')) . URL::query(array('ds_id' => $this->section()->id()), FALSE)); } else { $this->go(Route::get('datasources')->uri(array('directory' => $this->section()->type(), 'controller' => 'document', 'action' => 'view')) . URL::query(array('ds_id' => $this->section()->id(), 'id' => $doc->id), FALSE)); } }