public function action_create() { if (\Input::method() == 'POST') { $msg = ['msg' => '', 'errcode' => 0, 'status' => 'succ']; //检测必要的订单信息 $data = \Input::post(); //生成订单明细 $details = []; foreach ($data['goods'] as $id) { $item = \Model_Trolley::find_one_by('goods_id', $id); array_push($details, $item->to_array()); } $this->load_details($details); //生成优惠信息 $this->load_preferential($data['coupons']); if (!$this->save($data)) { $msg = ['msg' => $this->result_message, 'errcode' => 20, 'status' => 'err']; } if (\Input::is_ajax()) { die(json_encode($msg)); } } $params = ['title' => '']; $params['trolley_ids'] = [1, 2, 3]; \View::set_global($params); $this->template->title = '创建订单'; $this->template->content = \View::forge("{$this->theme}/create"); }
/** * @param none * @throws none * @returns void */ public function before() { $result = array(); // users need to be logged in to access this controller if (!\Sentry::check()) { $result = array('message' => 'You need to be logged in to access that page.', 'url' => '/admin/login'); // Don't show this message if url is just 'admin' if (\Uri::string() == 'admin/admin/index') { unset($result['message']); } \Session::set('redirect_to', \Uri::admin('current')); } else { if (!\Sentry::user()->is_admin()) { $result = array('message' => 'Access denied. You need to be a member of staff to access that page.', 'url' => '/admin/login'); \Session::set('redirect_to', \Uri::admin('current')); } } if (!empty($result)) { if (\Input::is_ajax()) { \Messages::error('You need to be logged in to complete this action.'); echo \Messages::display('left', false); exit; } else { if (isset($result['message'])) { \Messages::warning($result['message']); } \Response::redirect($result['url']); } } parent::before(); }
public function action_add_blocked($block = null) { if (empty($block) === true) { $block = $_POST['blocked']; } else { $block = str_replace('-', '.', $block); } $blacklist_item = Model_Blacklist::query()->where('expression', $block)->get_one(); if (empty($blacklist_item) === true) { $blacklist_item = Model_Blacklist::forge(array('expression' => $block)); $blacklist_item->save(); if (Input::is_ajax() === true) { echo $blacklist_item->id; } } else { if (Input::is_ajax() === true) { print_r(Format::forge(array('error' => 'Already Exists'))->to_json()); } else { Session::set('error', $block . ' is already in the blacklist!'); } } if (Input::is_ajax() === true) { die; } Response::Redirect_Back(); }
/** * The index action * * @access public * @return void */ public function action_index() { $settings = \Config::load('autoresponder.db'); // $autoResponder = Model_Setting::find(array('where' => array(array('meta_key', '=', 'auto-responders')))); if (\Input::post()) { $input = \Input::post(); if (!\Input::is_ajax()) { $val = Model_Setting::validate('create'); if (!$val->run()) { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } else { try { \Config::save('autoresponder.db', array('logo_url' => $input['logo_url'], 'company_name' => $input['company_name'], 'address' => $input['address'], 'website' => $input['website'], 'phone' => $input['phone'], 'email_address' => $input['email_address'], 'sender_email_address' => $input['sender_email_address'], 'contact_us_email_address' => $input['contact_us_email_address'], 'instagram_account_name' => $input['instagram_account_name'], 'facebook_account_name' => $input['facebook_account_name'])); // $setting->save(); \Messages::success('Settings successfully created.'); \Response::redirect('admin/settings'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings.</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } } } \View::set_global('title', 'Settings'); \Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false); }
public function action_login() { $url_redirect = \Uri::create('system/index/index'); if (\Auth::check()) { \Response::redirect($url_redirect); } if (\Input::is_ajax()) { $val = \Validation::forge('validate_login'); $val->add_field('email', 'Email', 'required|valid_email'); $val->add_field('password', 'Password', 'required'); if ($val->run(array())) { if (\Auth::instance()->login(\Input::param('email'), \Input::param('password'))) { if (\Input::param('remember', false)) { \Auth::remember_me(); } else { \Auth::dont_remember_me(); } $response = array('status' => 'success', 'url' => $url_redirect); } else { $messages = \Auth::get_error(); $response = array('status' => 'error', 'msg' => $messages); } } else { $messages = $val->error_message(); $response = array('status' => 'error', 'msg' => $messages); } return \Response::forge(json_encode($response)); } $this->theme->set_template('login'); $this->theme->get_template()->set('content', \view::forge('default/login', $this->_arrParam)); }
public function before() { parent::before(); if (!Input::is_ajax()) { $this->_init_nav(); } }
/** * 编辑保存被投票项目 * @param int $id * @throws \Exception * @throws \FuelException */ public function action_save($id = 0) { if (\Input::method() == 'POST') { $msg = ['status' => 'err', 'msg' => '', 'errcode' => 10]; $data = \Input::post(); $data['start_at'] = $data['start_at'] ? strtotime($data['start_at']) : 0; $data['end_at'] = $data['end_at'] ? strtotime($data['end_at']) : 0; $data['account_id'] = \Session::get('WXAccount')->id; $data['seller_id'] = \Session::get('WXAccount')->seller_id; $data['type'] = 'VOTE'; $market = \Model_Marketing::find($id); if (!$market) { $market = \Model_Marketing::forge(); } $market->set($data); if ($market->save()) { $limit = \Model_MarketingLimit::forge(['involved_total_num' => 1, 'marketing_id' => $market->id]); $limit->save(); $msg = ['status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => $market->to_array()]; } if (\Input::is_ajax()) { die(json_encode($msg)); } \Session::set_flash('msg', $msg); } }
public static function output($status = 'success', $message = '', $data = array()) { $output = (object) array('status' => $status, 'message' => $message, 'data' => $data); $response = \Request::active()->controller_instance->response; if (\Input::is_ajax()) { $response->set_header('Content-type', 'application/json'); } return $response->body(json_encode($output)); }
/** * Parse info tab content * * @param $table = Table to parse */ public function action_parse_info_table($table = false) { if (\Input::is_ajax()) { $table = \Input::post('table', ''); echo $this->parse_info_table($table); } if (\Request::is_hmvc()) { echo $this->parse_info_table($table); } }
public function post_is_unique() { if (Input::is_ajax()) { // $this->format = 'json'; $username = Input::post('username'); $username = Model_User::query()->where('email', $username)->get_one(); if ($username === null) { return $this->response(array('unique' => true)); } return $this->response(array('unique' => false)); } return false; }
public function action_ajax_test_ftp() { // is ajax if (!\Input::is_ajax()) { \Response::redirect(\Uri::create('admin')); } // check permission if (\Model_AccountLevelPermission::checkAdminPermission('config_global', 'config_global') == false) { \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string())))); return null; } if (\Input::method() == 'POST') { // get post value and test connection $config['hostname'] = trim(\Input::post('hostname')); $config['username'] = trim(\Input::post('username')); $config['password'] = trim(\Input::post('password')); $config['port'] = (int) trim(\Input::post('port')); $config['passive'] = trim(\Input::post('passive')) == 'true' ? true : false; $config['ssl_mode'] = false; $config['debug'] = false; $basepath = trim(\Input::post('basepath')); // connect to ftp $ftp = \Ftp::forge($config); $ftp->connect(); $ftp->change_dir($basepath); $files = $ftp->list_files(); $ftp->close(); $output = array(); if ($files !== false) { $output['form_status'] = 'success'; $output['form_status_message'] = \Lang::get('config_ftp_connected_check_basepath_from_dir_structure_below'); natsort($files); $output['list_files'] = '<ul>'; foreach ($files as $file) { $output['list_files'] .= '<li>' . $file . '</li>'; } $output['list_files'] .= '</ul>'; } else { // got false from list_files means cannot connect $output['form_status'] = 'error'; $output['form_status_message'] = \Lang::get('config_ftp_could_not_connect_to_server'); } // clear no use variables unset($basepath, $config, $file, $files, $ftp); // send out json values $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } }
public function action_menus() { $params = array('title' => "菜单项", 'menu' => 'wechat-menu', 'action_name' => "自定义菜单"); $account = \Model_WXAccount::find(\Session::get('WXAccount')->id); if (!$account) { if (\Input::is_ajax()) { die(json_encode(array('status' => 'err', 'msg' => '您还未绑定有效公众帐户', 'errcode' => 10))); } die('您还未绑定有效公众帐户'); } $params['items'] = isset($account->menu) && $account->menu ? json_decode($account->menu) : ''; \View::set_global($params); return \View::forge("ace/mp/coustom_menu/moblie"); }
/** * The index action * * @access public * @return void */ public function action_index() { $settings = \Config::load('backup.db'); if (\Input::post()) { $input = \Input::post(); if (!\Input::is_ajax()) { $val = Model_Backup::validate('create'); if (!$val->run()) { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } else { try { \Config::save('backup.db', array('enable' => $input['enable'], 'email' => $input['email'], 'period' => $input['period'])); //save cronjob $output = shell_exec('crontab -l'); $db_backup_cron_file = "/tmp/db_backup_cron.txt"; if ($input['enable']) { if ($input['period'] == 'daily') { $daily_backup_command = '0 0 * * * wget ' . \Uri::create('backup/execute'); file_put_contents($db_backup_cron_file, $daily_backup_command . PHP_EOL); } else { if ($input['period'] == 'weekly') { $weekly_backup_command = '0 0 * * 0 wget ' . \Uri::create('backup/execute'); file_put_contents($db_backup_cron_file, $weekly_backup_command . PHP_EOL); } } } else { file_put_contents($db_backup_cron_file, "" . PHP_EOL); } exec("crontab {$db_backup_cron_file}"); \Messages::success('Settings successfully created.'); \Response::redirect('admin/backup'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings.</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } } } \View::set_global('title', 'Backup'); \Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false); }
/** * After controller method has run, render the theme template * * @param Response $response */ public function after($response) { if (!\Input::is_ajax()) { // If nothing was returned set the theme instance as the response if (empty($response)) { $response = \Response::forge(\Theme::instance()); } if (!$response instanceof Response) { $response = \Response::forge($response); } return $response; } return parent::after($response); }
/** * Returns a list of event agenda items. * The method is mainly intended to be called using ajax * in this case, a json-formated string is returned. * @param int $event_id */ public function action_index($event_id = null) { !isset($event_id) and Response::redirect("event"); $event = Model_Orm_Event::find($event_id, array("related" => array("agendas"))); !isset($event) and Response::redirect("event"); if (Input::is_ajax()) { $response = Response::forge(Format::forge()->to_json($event->agendas)); $response->set_header("Content-Type", "application/json"); return $response; } else { $data['event'] = $event; $this->template->title = "Agenda items: " . $event->title; $this->template->content = View::forge('agenda/index', $data); } }
/** * router * * requests are not made to methods directly The request will be for an "object". * this simply maps the object and method to the correct Controller method. * * this router will call action methods for normal requests, * and REST methods for RESTful calls * * @param string * @param array */ public function router($resource, array $arguments) { // if this is an ajax call if (\Input::is_ajax()) { // have the Controller_Rest router deal with it return parent::router($resource, $arguments); } // check if the action method exists if (method_exists($this, 'action_' . $resource)) { // if so, call the action return call_user_func_array(array($this, 'action_' . $resource), $arguments); } // if not, we got ourselfs a genuine 404! throw new \HttpNotFoundException(); }
public function action_get_states($country = false) { if (!\Input::is_ajax()) { return; } $out = '<option value="">-</option>'; $states = \App\States::forge(); if ($states_array = $states->getStateProvinceArray($country)) { $out = ''; foreach ($states_array as $key => $value) { $out .= '<option value="' . $key . '">' . $value . '</option>'; } } echo $out; exit; }
public function before() { parent::before(); // Load translation \Lang::load('application'); if (Request::is_hmvc()) { $this->template = View::forge('user/hmvc/template'); } elseif (!Input::is_ajax()) { $this->template = View::forge('main_template'); $this->template->title = 'WSJ User Authentication'; $this->_navigation = View::forge('_templates/top_navbar'); $this->_header = View::forge('_templates/header'); // Put navigation view into header $this->_header->set('navigation', $this->_navigation); } }
/** * 出价 * @param int $id 拍品ID */ public function action_bid($id = 0) { if (\Input::method() == 'POST') { $msg = ['status' => 'err', 'msg' => '', 'errcode' => 10]; $order_no = \Model_Order::get_order_on(); $data = ['order_no' => $order_no, 'order_type' => 'AUCTION', 'buyer_id' => \Auth::get_user()->id, 'from_id' => \Session::get('seller')->id, 'total_fee' => \Input::post('bid'), 'original_fee' => \Input::post('bid')]; $order = \Model_Order::forge($data); $order->details = [\Model_OrderDetail::forge(['goods_id' => $id, 'num' => 1, 'price' => \Input::post('bid')])]; if ($order->save()) { $msg = ['status' => 'succ', 'msg' => '', 'errcode' => 0]; } if (\Input::is_ajax()) { die(json_encode($msg)); } \Session::set_flash('msg', $msg); } }
public function action_create() { //assumption: this will only be called using ajax if (!Input::is_ajax()) { return Response::forge("Access forbidden, only AJAX calls allowed", 403); } if (!Auth::has_access("location.create")) { return Response::forge("Only admins allowed here", 403); } if (Input::post("location_title", null) != null) { $loc = Model_Orm_Location::forge(); $loc->title = Input::post("location_title"); $loc->save(); $ret = array("id" => $loc->id); return Response::forge(Format::forge()->to_json($ret), 200, array("Content-Type" => "application/json")); } }
public function before() { // Set template $this->theme = \Theme::instance(); $this->theme->set_template($this->template); // Load translation \Lang::load('blog'); // Get current segments $segments = \Uri::segments(); empty($segments) and $segments[0] = 'home'; $this->dataGlobal['segments'] = $segments; // If ajax or content_only, set a theme with an empty layout if (\Input::is_ajax()) { return parent::before(); } // Don't re-set Media if is an HMVC request !\Request::is_hmvc() and $this->setMedia(); }
public function action_cart_listing($type = 'cart') { if (!\Input::is_ajax()) { die('Access Is Not Allowed!'); } $out = array(); $out['cart_empty'] = 0; $items = \Cart::items(); // Cart is empty? if (!$items) { $out['cart_empty'] = 1; } // Product table $out['product_table'] = \Theme::instance()->view('views/order/_partials/product_listing_table', array('items' => $items), false)->render(); // Price table $out['price_table'] = \Theme::instance()->view('views/order/_partials/product_price_table', array('type' => $type), false)->render(); echo json_encode($out); exit; }
/** * 结束拍品活动 * @param int $id * @throws \Exception * @throws \FuelException */ public function action_end($id = 0) { if (\Input::method() == 'POST') { $msg = ['status' => 'err', 'msg' => '', 'errcode' => 10]; $record = \Model_PlaceBidRecord::query()->where(['lot_id' => $id])->order_by(['bid' => 'DESC'])->get_one(); $order = \Model_Order::find($record->order_id); $order->order_status = 'FINISH'; if ($order->save()) { $msg = ['status' => 'succ', 'msg' => '', 'errcode' => 0]; } if (\Input::is_ajax()) { die(json_encode($msg)); } \Session::set_flash('msg', $msg); } $params = []; $params['item'] = \Model_Lot::find($id); \View::set_global($params); $this->template->content = \View::forge("{$this->theme}/auction/details"); }
public function before() { parent::before(); // Check Auth Access if (\Auth::check()) { /* * Get the current user id and email address * */ list(, $userId) = Auth::get_user_id(); $this->user = Model_User::find($userId); } isset($this->title) ? $this->title : ($this->title = "Rodas Net"); $this->template->title = $this->title; // Load translation \Lang::load('application'); // If ajax or content_only, set a theme with an empty layout if (\Input::is_ajax()) { return parent::before(); } }
public function before() { parent::before(); // $this->languages = array('en', 'cn', 'tw', 'ru'); $this->languages = array(); if (Sentry::user()->has_access('customers_en')) { array_push($this->languages, 'en'); } if (Sentry::user()->has_access('customers_ru')) { array_push($this->languages, 'ru'); } if (Sentry::user()->has_access('customers_tw')) { array_push($this->languages, 'tw'); } if (Sentry::user()->has_access('customers_cn')) { array_push($this->languages, 'cn'); } if (!Input::is_ajax()) { Response::redirect(''); } }
public function action_hotspot($application = null, $hotspot = null) { // Check if we have valid application $item = \Application\Model_Application::find_one_by_id($application); // If no, redirect back to home page if (!$item) { \Response::redirect(\Uri::front_create('/')); } if (\Input::is_ajax()) { // Check if we have valid hotspot $hotspot = \Application\Model_Application_Image::find_one_by_id($hotspot); // If not show error message if (!$hotspot) { echo 'Invalid link. Please try again!'; exit; } // Load hotspot view echo \Theme::instance()->view($this->view_dir . 'hotspot')->set('hotspot', $hotspot, false); } else { \Response::redirect(\Uri::front_create('application/' . $item->seo->slug)); } }
public function action_deleteAvatar() { // get account id from cookie $account = new \Model_Accounts(); $cookie = $account->getAccountCookie(); if (\Input::method() == 'POST') { if (!\Extension\NoCsrf::check()) { // validate token failed $output['form_status'] = 'error'; $output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token'); $output['result'] = false; } else { if (!isset($cookie['account_id']) || \Model_Accounts::isMemberLogin() == false) { $output['result'] = false; } else { $output['result'] = true; $account->deleteAccountAvatar($cookie['account_id']); } } } unset($account, $cookie); if (\Input::is_ajax()) { // re-generate csrf token for ajax form to set new csrf. $output['csrf_html'] = \Extension\NoCsrf::generate(); $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } else { if (\Input::referrer() != null && \Input::referrer() != \Uri::main()) { \Response::redirect(\Input::referrer()); } else { \Response::redirect(\Uri::base()); } } }
/** * Change user password * * @access public * @return void */ public function action_password() { \View::set_global('title', 'Forgot Password'); if (\Input::post('forgot')) { $val = \User\Controller_Validate::forge('forgot_password'); if ($val->run()) { // Get POST values $identity = \Input::post('identity', ''); if (\Sentry::user_exists($identity)) { try { // reset the password $reset = \Sentry::reset_password($identity); if ($reset) { $customer_email = $reset['email']; // Load email package \Package::load('email'); // Load email addresses from config (these will be bcc receivers) \Config::load('auto_response_emails', true); $bcc = \Config::get('autoresponders.forgot_password_emails'); if (!$bcc) { $bcc = \Config::get('autoresponders.default_emails'); } $settings = \Config::load('autoresponder.db'); $email_data = array('site_title' => $settings['company_name'], 'customer_identity' => $identity, 'reset_link' => \Uri::front_create('user/reset_password/' . $reset['link'])); $email = \Email::forge(); $email->to($customer_email); $email->from(\Config::get('auto_response_emails.autoresponder_from_email'), $settings['company_name']); if ($bcc) { $email->bcc($bcc); } $email->subject($email_data['site_title'] . ' - Forgot Password'); $email_html = \Theme::instance()->view('views/_email/forgot_password')->set('email_data', $email_data, false); $email->html_body($email_html); try { $email->send(); \Messages::success('You have been sent an email to reset your password.'); } catch (\EmailValidationFailedException $e) { \Messages::error('Error while sending email.'); } catch (\EmailSendingFailedException $e) { \Messages::error('Error while sending email.'); } \Response::redirect(\Input::referrer(\Uri::front_create('/'))); } else { \Messages::error('There was a problem while trying to change your password. Please try again.'); } } catch (\Sentry\SentryException $e) { // show validation errors //\Messages::error('<h4>There was an error while trying to create user</h4>'); $errors = $e->getMessage(); \Messages::error($errors); } } else { \Messages::error('There doesn`t appear to be an account associated with this email address. Try a different email address or register for a new account on the homepage.'); } } else { if ($val->error() != array()) { // show validation errors //\Messages::error('<h4>There was an error while trying to create user</h4>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } if (\Input::is_ajax()) { echo \Theme::instance()->view($this->view_dir . 'forgot_password'); } else { if (isset($val)) { \View::set_global('validation', $val, false); } \Theme::instance()->set_partial('content', $this->view_dir . 'single_forgot_password'); } }
/** * Decide whether to return RESTful or templated response * Override in subclass to introduce custom switching logic. * * @param boolean */ public function is_restful() { return \Input::is_ajax(); }
/** * Payment methods select list * * @access public * @return void */ public function action_second_option($language = false, $method = false) { if (!\Input::is_ajax()) { die('Access is denied.'); } $out = array(); $out['data'] = ''; $out['data'] = '<h3>Paypal</h3>'; $out['data'] .= '<p class="marg_top_b">' . __('Sie werden am Ende Ihres Bestellvorgangs für die Zahlungsabwicklung direkt zu PayPal weiter geleitet. Erst danach ist Ihre Bestellung erfolgreich abgeschlossen.') . '</p>'; echo json_encode($out); }