Exemple #1
0
 public function action_index()
 {
     // log out.
     \Model_Accounts::logout();
     // go back
     if (\Input::referrer() != null && \Input::referrer() != \Uri::main()) {
         \Response::redirect(\Input::referrer());
     } else {
         \Response::redirect(\Uri::base());
     }
 }
Exemple #2
0
 /**
  * Redirects back to the previous page, if that page is within the current
  * application. If not, it will redirect to the given url, and if none is
  * given, back to the application root
  *
  * @param   string  $url     The url
  * @param   string  $method  The redirect method
  * @param   int     $code    The redirect status code
  *
  * @return  void
  */
 public static function redirect_back($url = '', $method = 'location', $code = 302)
 {
     // do we have a referrer?
     if ($referrer = \Input::referrer()) {
         // is it within our website? And not equal to the current url?
         if (strpos($referrer, \Uri::base()) === 0 and $referrer != \Uri::current()) {
             // redirect back to where we came from
             static::redirect($referrer, $method, $code);
         }
     }
     // no referrer or an external link, do a normal redirect
     static::redirect($url, $method, $code);
 }
Exemple #3
0
 /**
  * An editor view for the fuel lang entries
  */
 public function post_terms()
 {
     $terms = \Input::post('terms', array());
     try {
         foreach ($terms as $lang => $phrases) {
             \Lang::save('common.db', $phrases, $lang);
         }
     } catch (\Exception $e) {
         // Nothing
     }
     \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => \Lang::get('admin.messages.translations_save_success')));
     $referrer = \Input::referrer('/admin');
     return \Response::redirect($referrer);
 }
Exemple #4
0
 /**
  * get and set submit redirection url
  * 
  * @return string
  */
 private function getAndSetSubmitRedirection()
 {
     $session = \Session::forge();
     if ($session->get('submitted_redirect') == null) {
         if (\Input::referrer() != null && \Input::referrer() != \Uri::main()) {
             $session->set('submitted_redirect', \Input::referrer());
             return \Input::referrer();
         } else {
             $redirect_uri = 'dbhelper/admin';
             $session->set('submitted_redirect', $redirect_uri);
             return $redirect_uri;
         }
     } else {
         return $session->get('submitted_redirect');
     }
 }
Exemple #5
0
 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());
         }
     }
 }
 /**
  * Redirects back to the previous page, if that page is within the current
  * application. If not, it will redirect to the given url, and if none is
  * given, back to the application root. If the current page is the application
  * root, an exception is thrown
  *
  * @param   string  $url     The url
  * @param   string  $method  The redirect method
  * @param   int     $code    The redirect status code
  *
  * @return  void
  *
  * @throws  RuntimeException  If it would redirect back to itself
  */
 public static function redirect_back($url = '', $method = 'location', $code = 302)
 {
     // do we have a referrer?
     if ($referrer = \Input::referrer()) {
         // is it within our website? And not equal to the current url?
         if (strpos($referrer, \Uri::base()) === 0 and $referrer != \Uri::current()) {
             // redirect back to where we came from
             static::redirect($referrer, $method, $code);
         }
     }
     // make sure we're not redirecting back to ourself
     if (\Uri::create($url) == \Uri::current()) {
         throw new \RuntimeException('You can not redirect back here, it would result in a redirect loop!');
     }
     // no referrer or an external link, do a normal redirect
     static::redirect($url, $method, $code);
 }
 public static function action_view($short_url)
 {
     if (is_object($short_url) === false) {
         $short_url = Model_Url::query()->where('short_url', $short_url)->get_one();
     }
     $short_url->hits = $short_url->hits + 1;
     $short_url->save();
     if (empty($short_url) === false) {
         $results = Controller_Url::check_loop($short_url);
         $data['url'] = $results['url'];
         $data['iframe'] = $results['iframe'];
         if (isset($results['image']) === true) {
             $data['image'] = $results['image'];
         }
         if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
             $ip = $_SERVER["HTTP_CF_CONNECTING_IP"];
         } else {
             $ip = Input::real_ip();
         }
         $country = Model_Url_Stats_Country::query()->where('start_ip', '<=', ip2long($ip))->where('end_ip', '>=', ip2long($ip))->get_one();
         if (empty($country) === false) {
             $country = $country->country;
         } else {
             $country = 'N/A';
         }
         $lang = Agent::languages();
         // Insert Some Stats
         $stats = Model_Url_Stat::forge(array('url_id' => $short_url->id, 'ip' => $ip, 'country' => $country, 'referer' => Input::referrer(), 'language' => serialize($lang)));
         $stats->save();
         return new Response(View::Forge('url/redirect', $data));
     } else {
         Session::set('error', 'We couldn\'t');
         Response::Redirect(Uri::Base());
     }
 }
Exemple #8
0
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Attribute_Group::find_one_by_id($id)) {
             // Delete item
             try {
                 // Delete relation to attributes
                 $attributes = Model_Attribute_To_Groups::find_by_group_id($item->id);
                 if (!is_null($attributes)) {
                     foreach ($attributes as $attribute) {
                         $attribute->delete();
                     }
                 }
                 $item->delete();
                 \Messages::success('Attribute group successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete attribute group</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer(\Uri::create('admin/attribute/group/list')));
 }
 /**
  * Delete content image
  * 
  * @param $content_id		= Content ID
  */
 public function action_delete_image($content_id = null)
 {
     try {
         if ($application = Model_Application::find_one_by_id($content_id)) {
             if (!empty($application->hotspot) && !empty($application->hotspot->images)) {
                 foreach ($application->hotspot->images as $image) {
                     $this->delete_image($image->image);
                     $image->delete();
                 }
             }
             $this->delete_image($application->hotspot_image);
             $application->hotspot_alt_text = null;
             $application->hotspot_image = null;
             if ($application->save()) {
                 \Messages::success('Hotspot image was successfully deleted.');
             } else {
                 \Messages::error('There was an error while trying to delete hotspot image.');
             }
         }
     } catch (\Database_Exception $e) {
         // show validation errors
         \Messages::error('There was an error while trying to delete hotspot image.');
         // Uncomment lines below to show database errors
         $errors = $e->getMessage();
         \Messages::error($errors);
     }
     \Response::redirect(\Input::referrer());
 }
 protected function save_order()
 {
     if (!$this->check_logged()) {
         \Messages::error('You must be logged in if you want to continue with your order.');
         \Response::redirect(\Uri::create('order/checkout/address'));
     }
     // Save order
     $user = false;
     $order = false;
     $items = \Cart::items();
     if (\Sentry::check()) {
         $user = \Sentry::user();
     }
     if (\Input::post() && $items && $user) {
         $group_id = $user['groups'][0]['id'];
         $item_with_discount = array();
         foreach ($items as $item) {
             $id = $item->get('id');
             $product_groups = \Product\Model_Product_To_Groups::find_by_product_id($item->get('id'));
             foreach ($product_groups as $group) {
                 $all_discounts = \Product\Model_Group_Discounts::find_by(array('user_group_id' => $group_id, 'product_group_id' => $group->group_id), null, null, null);
                 foreach ($all_discounts as $discount) {
                     $discount = (int) $item_with_discount[$id]['discount'] + $discount->discount;
                     $sub_total = $item->totalPrice(true) - (int) $discount / $item->totalPrice(true) * 100;
                     $item_with_discount[$id] = array('product_group_id' => $group->product_id, 'user_group_id' => $group->group_id, 'discount' => $discount, 'sub_total' => $sub_total);
                 }
             }
             $item_with_discount['total_discount'] = (int) $item_with_discount['total_discount'] + (int) $item_with_discount[$id]['total_discount'];
             $item_with_discount['total_price'] = (double) $item_with_discount['total_price'] + (double) $item_with_discount[$id]['sub_total'];
         }
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost')));
         }
         try {
             // Update or create order
             if (is_numeric(\Session::get('order.id'))) {
                 $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
             }
             if (!$order) {
                 $order = \Order\Model_Order::forge();
             }
             $shipping_price = $order->shipping_price(null, null, true);
             $metadata = $user['metadata'];
             if ($billing = \Arr::filter_prefixed($metadata, 'shipping_')) {
                 foreach ($billing as $key => $value) {
                     $order->{$key} = $metadata[$key];
                     unset($metadata[$key]);
                 }
             }
             foreach ($metadata as $key => $value) {
                 $order->{$key} = $value;
             }
             $order->email = $user->get('email');
             $order->user_id = $user->get('id');
             $order->status = 'Pending';
             $order->discount_amount = $item_with_discount['total_discount'];
             //\Cart::getTotal('price');
             $order->total_price = $item_with_discount['total_price'];
             //\Cart::getTotal('price');
             $order->finished = 1;
             $order->guest = $metadata['guest'] ? 1 : 0;
             $order->accepted = $metadata['master'] == 1 ? 1 : 0;
             $order->credit_account = $metadata['credit_account'] == 1 ? 1 : 0;
             $order->shipping_price = $shipping_price;
             // Save order, add products to order products
             if ($order->save()) {
                 foreach ($items as $item) {
                     $product_data = null;
                     if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
                         $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
                     }
                     if ($product_data) {
                         $order_products = \Order\Model_Products::forge();
                         $order_products->order_id = $order->id;
                         $order_products->title = $product->title;
                         $order_products->code = $product_data['code'];
                         $order_products->price = $item->singlePrice(true);
                         $order_products->price_type = $product_data['price_type'];
                         $order_products->quantity = $item->get('quantity');
                         $order_products->product_id = $product->id;
                         $order_products->artwork_required = $product->artwork_required;
                         $order_products->artwork_free_over = $product->artwork_free_over;
                         $order_products->subtotal = $item_with_discount[$item->get('id')]['sub_total'];
                         //$item->totalPrice(true);
                         $order_products->attributes = json_encode(\Product\Model_Attribute::get_combination($item->get('attributes')));
                         if (!empty($product->categories)) {
                             $categories = array();
                             foreach ($product->categories as $category) {
                                 $categories[] = $category->title;
                             }
                             if ($categories) {
                                 $order_products->product_category = implode(',', $categories);
                             }
                         }
                         $order_products->save();
                         // Find artworks
                         if ($unique_id = $item->get('unique_id')) {
                             if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order->id)))) {
                                 $ysi = \Yousendit\Base::forge();
                                 // Artworks (update, delete)
                                 foreach ($artworks as $artwork) {
                                     // Remove deleted artwork
                                     if ($artwork->deleted_at > 0) {
                                         $ysi->delete_artwork($artwork->file_id);
                                         $artwork->delete();
                                     } else {
                                         $artwork->order_product_id = $order_products->id;
                                         $artwork->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($order) {
                 return $order;
             } else {
                 return false;
             }
         } catch (\Database_Exception $e) {
             // show validation errors
             \Messages::error('There was an error while trying to save your order.');
             // Uncomment lines below to show database errors
             $errors = $e->getMessage();
             \Messages::error($errors);
             \Response::redirect(\Uri::create('order/checkout/cost'));
         }
         return false;
     }
 }
Exemple #11
0
 public function action_clear_cart()
 {
     $items = \Cart::items();
     $order = null;
     if (is_numeric(\Session::get('order.id'))) {
         $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
     }
     if ($order) {
         $order->delete();
     }
     if ($items) {
         foreach ($items as $item) {
             // Find artworks
             if ($unique_id = $item->get('unique_id')) {
                 if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => \Session::get('order.id'))))) {
                     $ysi = \Yousendit\Base::forge();
                     // Artworks (update, delete)
                     foreach ($artworks as $artwork) {
                         // Remove deleted artwork
                         if ($artwork->file_id) {
                             $ysi->delete_artwork($artwork->file_id);
                         }
                     }
                 }
             }
         }
     }
     // Delete order & cart session
     \Session::delete('order.id');
     \Cart::clear();
     \Messages::info('Your cart is empty.');
     if (\Input::is_ajax()) {
         echo \Messages::display();
         exit;
     } else {
         \Response::redirect(\Input::referrer(\Uri::create('order/checkout/address')));
     }
 }
Exemple #12
0
 /**
  * Delete content image
  * 
  * @param $content_id	= Content ID
  */
 public function action_delete_image($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Product_To_Infotabs::find_by_pk($id)) {
             // Delete hotspot images
             if (!empty($item->images)) {
                 foreach ($item->images as $image) {
                     \Request::forge('admin/product/delete_infotab_image/' . $image->id . '/' . $image->infotab_id)->execute()->response();
                 }
             }
             // Delete item
             try {
                 $this->delete_image($item->image);
                 $item->image = NULL;
                 $item->alt_text = NULL;
                 // Make infotab inactive as it cant show without image
                 $item->active = 0;
                 $item->save();
                 \Messages::success('Info Tab image successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete info tab image</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     if (\Request::is_hmvc()) {
         \Messages::reset();
     } else {
         \Response::redirect(\Input::referrer(\Uri::create('admin/product/infotab/list')));
     }
 }
Exemple #13
0
 /**
  * Manage upsell products
  * 
  * @param $id	= Product ID
  */
 public function action_list($id)
 {
     if (!is_numeric($id)) {
         \Response::redirect('admin/product/list');
     }
     // Get news item to edit
     if (!($item = Model_Product::find_one_by_id($id))) {
         \Response::redirect('admin/product/list');
     }
     if (\Input::post()) {
         $add = \Input::post('products.add', array());
         $remove = \Input::post('products.remove', array());
         $discounts = \Input::post('discount', array());
         if (\Input::post('add', false)) {
             foreach ($add as $value) {
                 $upsell = Model_Product_To_Upsell::forge(array('upsell_id' => $value, 'product_id' => $item->id));
                 $upsell->save();
             }
             \Messages::success('Upsell products successfully added.');
         } else {
             if (\Input::post('remove', false)) {
                 foreach ($remove as $value) {
                     $upsell = Model_Product_To_Upsell::find_one_by(array(array('upsell_id', '=', $value), array('product_id', '=', $item->id)));
                     if (!is_null($upsell)) {
                         $upsell->delete();
                     }
                 }
                 \Messages::success('Upsell products successfully removed.');
             } else {
                 if (\Input::post('save', false)) {
                     foreach ($discounts as $key => $value) {
                         $upsell = Model_Product_To_Upsell::find_one_by(array(array('upsell_id', '=', $key), array('product_id', '=', $item->id)));
                         if (!is_null($upsell)) {
                             $upsell->discount = round($value, 0);
                             $upsell->save();
                         }
                     }
                     \Messages::success('Upsell discounts successfully saved.');
                 }
             }
         }
         if (\Input::is_ajax()) {
             echo \Messages::display('left', false);
             exit;
         } else {
             \Response::redirect(\Input::referrer(\Uri::create('admin/product/list')));
         }
     }
     \View::set_global('title', 'List Upsell Products');
     $search = $this->get_search_items($item);
     $pagination = $search['pagination'];
     $status = $search['status'];
     $item = $search['item'];
     \Theme::instance()->set_partial('content', $this->view_dir . 'list')->set('product', $item)->set('pagination', $pagination, false)->set('status', $status);
 }
Exemple #14
0
 public function action_delete_referral($id = false)
 {
     if (is_numeric($id)) {
         // Get user delete
         if ($item = Model_Referal::find_one_by_id((int) $id)) {
             // Delete item
             try {
                 // Delete group
                 $item->delete();
                 \Messages::success('User successfully deleted.');
             } catch (\Sentry\SentryUserException $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete item</strong>');
                 // Uncomment lines below to show database errors
                 $errors = $e->getMessage();
                 \Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }
Exemple #15
0
 public function action_delete_artwork($file_id = null)
 {
     $ysi = \Yousendit\Base::forge();
     $response = $ysi->delete_artwork($file_id, true);
     if (isset($response['errormessage'])) {
         \Messages::error('<strong>' . 'There was an error while trying to delete artwork file.' . '</strong>');
     } else {
         \Messages::success('Artwork file successfully deleted.');
     }
     \Response::redirect(\Input::referrer(\Uri::create('admin/order/list')));
 }
Exemple #16
0
 public function action_multiple()
 {
     $ids = \Input::post('id');
     $act = trim(\Input::post('act'));
     if (\Extension\NoCsrf::check()) {
         if ($act == 'del') {
             // check permission.
             if (\Model_AccountLevelPermission::checkAdminPermission('blog_perm', 'blog_manage_perm') == false) {
                 \Response::redirect(\Uri::create('admin'));
             }
             if (is_array($ids)) {
                 foreach ($ids as $id) {
                     \Blog\Model_Blog::find($id)->delete();
                 }
             }
         }
     }
     // go back
     if (\Input::referrer() != null && \Input::referrer() != \Uri::main()) {
         \Response::redirect(\Input::referrer());
     } else {
         \Response::redirect('blog/admin');
     }
 }
 protected function save_order()
 {
     if (!$this->check_logged()) {
         \Messages::error('You must be logged in if you want to continue with your order.');
         \Response::redirect(\Uri::create('order/checkout/address'));
     }
     // Save order
     $user = false;
     $order = false;
     $items = \Cart::items();
     if (\Sentry::check()) {
         $user = \Sentry::user();
     }
     if (\Input::post() && $items && $user) {
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('order/checkout/cost')));
         }
         try {
             // Update or create order
             if (is_numeric(\Session::get('order.id'))) {
                 $order = \Order\Model_Order::find_one_by_id(\Session::get('order.id'));
             }
             if (!$order) {
                 $order = \Order\Model_Order::forge();
             }
             $cart_total = 0;
             foreach ($items as $item) {
                 $product_data = null;
                 if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
                     $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
                 }
                 $total_price = $item->totalDiscountedPrice(true);
                 if (isset($product_data["price"]) && $product_data["price"] != 0) {
                     $total_price = $product_data["price"] * $item->get('quantity');
                 }
                 $cart_total += $total_price;
             }
             $method = \Input::post('delivery') == 'pickup' ? false : true;
             $shipping_price = $order->shipping_price(null, null, true, $method);
             $metadata = $user['metadata'];
             $data = array('email' => $user->get('email'), 'user_id' => $user->get('id'), 'status' => 'Pending', 'total_price' => $cart_total, 'finished' => 1, 'guest' => $metadata['guest'] ? 1 : 0, 'accepted' => $metadata['master'] == 1 ? 1 : 0, 'credit_account' => $metadata['credit_account'] == 1 ? 1 : 0, 'shipping_method' => \Input::post('delivery'), 'shipping_price' => $shipping_price, 'gst_price' => ($cart_total + $shipping_price) * 0.1);
             // $order->discount_amount = $item_with_discount['total_discount'];//\Cart::getTotal('price');
             //\Cart::getDiscountedTotal('price');//\Cart::getTotal('price');
             if ($billing = \Arr::filter_prefixed($metadata, 'shipping_')) {
                 foreach ($billing as $key => $value) {
                     $data[$key] = $metadata[$key];
                     unset($metadata[$key]);
                 }
             }
             foreach ($metadata as $key => $value) {
                 $data[$key] = $value;
             }
             $order->set($data);
             // Save order, add products to order products
             if ($order->save()) {
                 foreach ($items as $item) {
                     $product_data = null;
                     if ($product = \Product\Model_Product::find_one_by_id($item->get('id'))) {
                         $product_data = \Product\Model_Product::product_data($product, $item->get('attributes'));
                     }
                     $item_exists = \Order\Model_Products::find(array('where' => array('product_id' => $product->id, 'order_id' => $order->id)));
                     if ($product_data && !$item_exists) {
                         $order_products = \Order\Model_Products::forge(array('order_id' => $order->id, 'title' => $product->title, 'code' => $product_data['code'], 'price' => $product_data['price'], 'price_type' => $product_data['price_type'], 'quantity' => $item->get('quantity'), 'product_id' => $product->id, 'artwork_required' => $product->artwork_required, 'artwork_free_over' => $product->artwork_free_over, 'subtotal' => $product_data['price'] * $item->get('quantity'), 'attributes' => json_encode(\Product\Model_Attribute::get_combination($item->get('attributes'))), 'attributes_id' => $item->get('attributes')));
                         //$item->singleDiscountedPrice(true);//$item->singlePrice(true);
                         //$item->totalDiscountedPrice(true);//$item->totalPrice(true);
                         if (!empty($product->categories)) {
                             $categories = array();
                             foreach ($product->categories as $category) {
                                 $categories[] = $category->title;
                             }
                             if ($categories) {
                                 $order_products->product_category = implode(',', $categories);
                             }
                         }
                         // update stock quantity
                         \Product\Model_Attribute::update_stock_quantity($item->get('attributes'), $item->get('quantity'));
                         $order_products->save();
                         // Find artworks
                         if ($unique_id = $item->get('unique_id')) {
                             if ($artworks = \Order\Model_Artwork::find(array('where' => array('unique_id' => $unique_id, 'order_id' => $order->id)))) {
                                 $ysi = \Yousendit\Base::forge();
                                 // Artworks (update, delete)
                                 foreach ($artworks as $artwork) {
                                     // Remove deleted artwork
                                     if ($artwork->deleted_at > 0) {
                                         $ysi->delete_artwork($artwork->file_id);
                                         $artwork->delete();
                                     } else {
                                         $artwork->set(array('order_product_id' => $order_products->id));
                                         $artwork->save();
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($order) {
                 return $order;
             } else {
                 return false;
             }
         } catch (\Database_Exception $e) {
             // show validation errors
             \Messages::error('There was an error while trying to save your order.');
             // Uncomment lines below to show database errors
             $errors = $e->getMessage();
             \Messages::error($errors);
             \Response::redirect(\Uri::create('order/checkout/cost'));
         }
         return false;
     }
 }
Exemple #18
0
 /**
  * Delete content image
  * 
  * @param $image_id		= Image ID
  * @param $content_id	= Content ID
  */
 public function action_delete_image($image_id = false, $content_id = false)
 {
     if ($image_id && $content_id) {
         $images = Model_Attribute_Image::find(array('where' => array('content_id' => $content_id), 'order_by' => array('sort' => 'asc')), 'id');
         if ($images) {
             if (isset($images[$image_id])) {
                 $image = $images[$image_id];
                 // Check if image used for more than one combination
                 $image2 = Model_Attribute_Image::find(array('where' => array('image' => $image->image)), 'id');
                 if ($image2 && count($image2) > 1) {
                     // Reset sort fields
                     \DB::update(Model_Attribute_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute();
                     $image->delete();
                     \Messages::success('Image was successfully deleted.');
                     \Response::redirect(\Input::referrer());
                 }
                 // If there is only one image and image is required
                 if (count($images) == 1) {
                     if (\Config::get('details.image.required', false)) {
                         \Messages::error('You can\'t delete all images. Please add new image in order to delete this one.');
                     } else {
                         // Reset sort fields
                         \DB::update(Model_Attribute_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute();
                         // Delete image
                         $this->delete_image($image->image);
                         $image->delete();
                         \Messages::success('Image was successfully deleted.');
                     }
                 } else {
                     if ($image->cover == 1) {
                         \Messages::error('You can\'t delete cover image. Set different image as cover in order to delete this one.');
                     } else {
                         // Reset sort fields
                         \DB::update(Model_Attribute_Image::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $image->sort)->execute();
                         // Delete image
                         $this->delete_image($image->image);
                         $image->delete();
                         \Messages::success('Image was successfully deleted.');
                     }
                 }
             } else {
                 \Messages::error('Image you are trying to delete don\'t exists. Check your url and try again.');
             }
         } else {
             \Messages::error('Content Image you are trying to delete don\'t exists. Check your url and try again.');
         }
     }
     \Response::redirect(\Input::referrer());
 }
 /**
  * Delete content file
  * 
  * @param $file_id		= File ID
  * @param $content_id	= Content ID
  */
 public function action_delete_file($file_id = false, $content_id = false)
 {
     if ($file_id && $content_id) {
         $files = Model_File::find(array('where' => array('content_id' => $content_id), 'order_by' => array('sort' => 'asc')), 'id');
         if ($files) {
             if (isset($files[$file_id])) {
                 $file = $files[$file_id];
                 // If there is only one image and image is required
                 if (count($files) == 1) {
                     if (\Config::get('details.file.required', false)) {
                         \Messages::error('You can\'t delete all files. Please add new file in order to delete this one.');
                     } else {
                         // Reset sort fields
                         \DB::update(Model_File::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $file->sort)->execute();
                         // Delete file
                         $this->delete_file($file->file);
                         $file->delete();
                         \Messages::success('File was successfully deleted.');
                     }
                 } else {
                     // Dont use cover option for files
                     if (FALSE && $file->cover == 1) {
                         \Messages::error('You can\'t delete cover file. Set different file as cover in order to delete this one.');
                     } else {
                         // Reset sort fields
                         \DB::update(Model_File::get_protected('_table_name'))->value('sort', \DB::expr('sort - 1'))->where('sort', '>', $file->sort)->execute();
                         // Delete file
                         $this->delete_file($file->file);
                         $file->delete();
                         // Set another file as cover if cover is deleted
                         if ($file->cover == 1) {
                             $files = Model_File::find(array('where' => array('content_id' => $content_id), 'order_by' => array('sort' => 'asc')));
                             $files[0]->cover = 1;
                             $files[0]->save();
                         }
                         \Messages::success('File was successfully deleted.');
                     }
                 }
             } else {
                 \Messages::error('File you are trying to delete don\'t exists. Check your url and try again.');
             }
         } else {
             \Messages::error('File you are trying to delete don\'t exists. Check your url and try again.');
         }
     }
     \Response::redirect(\Input::referrer(\Uri::create('admin/application/list')));
 }
 /**
  * Delete Order
  * 
  * @param type $id  = Order ID
  */
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get discount code to delete
         if ($item = Model_Discountcode::find_one_by_id($id)) {
             try {
                 $item->delete();
                 \Messages::success('Discount successfully deleted.');
             } catch (\Database_Exception $e) {
                 \Messages::error('<strong>' . 'There was an error while trying to delete discount' . '</strong>');
             }
         } else {
             \Messages::error('<strong>' . 'Discount code does not exists' . '</strong>');
         }
     }
     \Response::redirect(\Input::referrer(\Uri::create('admin/discountcode/list')));
 }
Exemple #21
0
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Team::find_one_by_id($id)) {
             // Delete other content data like images, files, etc.
             if (!empty($item->images)) {
                 foreach ($item->images as $image) {
                     $this->delete_image($image->image);
                     $image->delete();
                 }
             }
             // if(!empty($item->files))
             // {
             // 	foreach($item->files as $file)
             // 	{
             // 		$this->delete_file($file->file);
             // 		$file->delete();
             // 	}
             // }
             // if(!empty($item->videos))
             // {
             // 	foreach($item->videos as $video)
             // 	{
             // 		$this->delete_image($video->thumbnail, 'video');
             // 		$video->delete();
             // 	}
             // }
             // if(!empty($item->accordions))
             // {
             // 	foreach($item->accordions as $accordion)
             // 	{
             // 		\Request::forge('admin/team/accordion/delete/'.$accordion->id)->execute();
             // 	}
             // }
             try {
                 $item->seo->delete();
                 $item->delete();
                 \Messages::success('Member successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete team</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }
 /**
  * Subscribe
  * 
  * @access  public
  * @param   $slug
  */
 public function action_subscribe()
 {
     if (\Input::post()) {
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('/')));
         }
         $val = $this->validate();
         if ($val->run()) {
             try {
                 //get lists in mailchimp
                 // $subscribe_list = \TinyChimp::lists(array('start' => 0, 'limit' => 50));
                 $list_id = 'dddc7bdb6a';
                 // $subscribe_list->data[0]->id
                 $params = array('id' => $list_id, 'email_address' => \Input::post('email'), 'double_optin' => true, 'send_welcome' => true);
                 \TinyChimp::listSubscribe($params);
                 \Messages::success('Stay tuned for juicy news');
             } catch (\FuelException $e) {
                 \Messages::error($e->getMessage());
             }
         } else {
             if ($val->error() != array()) {
                 // show validation errors
                 \Messages::error('There was an error while trying to subscribe to newsletter.');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
         /*if($val->run())
         		{
                        $nl = \Newsletter\Base::forge();
                        
                        if($list = $nl->get_list())
                        {
                            $confirmed_list = $list->response->ConfirmedOptIn;
                        }
                        
                        $data = array(
                            'EmailAddress' => \Input::post('email'),
                            'Name' => \Input::post('firstname'),
                            'CustomFields' => array(
                                array(
                                      'Key' => 'Company',
                                     'Value' => \Input::post('company_name')
                                 ),
                                array(
                                      'Key' => 'Surname',
                                     'Value' => \Input::post('surname')
                                 ),
                             ),
                            //'Resubscribe' => true,
                            //'RestartSubscriptionBasedAutoresponders' => true
                        );
                        $response = $nl->add_subscriber($data);
                        
                        if($response->http_status_code == 201)
                        {
                            if(isset($confirmed_list) && $confirmed_list)
                            {
                                \Messages::success('<b>Thank You for Subscribing</b><br>
                                You\'ve just been sent an email that contains a confirm link.
                                In order to activate your subscription, check your email and click on the link in that email. 
                                You will not receive your subscription until you click that link to activate it.');
                            }
                            else
                            {
                                // \Messages::success('<b>Thank You for Subscribing</b>');
                                \Messages::success('Thanks for signing up for our newsletter!');
                            }
                           
                        }
                        else 
                        {
                            \Messages::error($response->response->Message);
                        }
                    }
                    else
         		{
         			if($val->error() != array())
         			{
         				// show validation errors
         				\Messages::error('There was an error while trying to subscribe to newsletter.');
         				foreach($val->error() as $e)
         				{
         					\Messages::error($e->get_message());
         				}
         			}
         		}*/
     }
     \Response::redirect(\Input::referrer(\Uri::create('/')));
 }
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Attribute::find_one_by_id($id)) {
             // Delete item
             try {
                 // Delete attribute options
                 if (!empty($item->options)) {
                     foreach ($item->options as $option) {
                         \Request::forge('admin/attribute/option/delete/' . $option->id)->execute()->response();
                     }
                 }
                 $item->delete();
                 \Messages::success('Attribute successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete attribute</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     \Response::redirect(\Input::referrer());
 }
Exemple #24
0
 public function action_accept_order($id = null)
 {
     // Get order
     $order = \Order\Model_Order::find_one_by_id($id);
     if (!$order) {
         \Messages::error('Order with that ID does not exist or has been deleted.');
         \Response::redirect(\Uri::front_create('user/account/orders'));
     }
     // Get current user
     $user = \Sentry::user();
     $master_user = false;
     if (isset($user['metadata']['master']) && $user['metadata']['master']) {
         $master_user = true;
     }
     if (!$master_user) {
         \Messages::error("You don't have permssion for this action.");
         \Response::redirect(\Uri::front_create('user/account'));
     }
     try {
         $order->accepted = 1;
         $order->save();
         \Messages::success('Order successfully updated.');
         \Response::redirect(\Input::referrer(\Uri::front_create('user/account')));
     } catch (\Database_Exception $e) {
         \Messages::error('There was an error while trying to update order.');
     }
 }
Exemple #25
0
 public function action_login()
 {
     if (Input::method() == 'POST') {
         if (!\Security::check_token()) {
             \Log::info('CSRF detected from IP:' . \Input::ip() . ', Real IP:' . \Input::real_ip() . ', Ref:' . \Input::referrer() . ', Agent:' . \Input::user_agent());
             throw new \HttpNotFoundException();
         }
         $val = \Validation::forge('users');
         $val->add_field('username', 'Your username', 'required|min_length[3]|max_length[20]');
         $val->add_field('password', 'Your password', 'required|min_length[3]|max_length[20]');
         if ($val->run()) {
             $valid_login = \Auth::instance()->login($val->validated('username'), $val->validated('password'));
             if ($valid_login) {
                 $user = \Auth::instance()->get_user_info();
                 \Session::set('user_info', $user);
                 \Session::set_flash('success', 'Welcome, ' . $val->validated('username'));
                 $url = \Session::get('redirect_url', '/');
                 \Session::delete('redirect_url');
                 \Response::redirect($url);
             } else {
                 $data['username'] = $val->validated('username');
                 \Session::set_flash('error', 'Wrong username/password. Try again');
             }
         } else {
             \Session::set_flash('error', 'Please correct the error(s).');
             $this->template->set_global('errors', $val->error());
         }
     }
     $this->template->title = 'Login';
     $this->template->page_title = 'Login';
     $this->template->content = \View::forge('petro/login');
 }
Exemple #26
0
 public function action_discuss_brief()
 {
     if (\Input::post()) {
         // check for a valid CSRF token
         if (!\Security::check_token()) {
             \Messages::error('CSRF attack or expired CSRF token.');
             \Response::redirect(\Input::referrer(\Uri::create('/')));
         }
         $file = null;
         // Send autoresponder
         $autoresponder = \Autoresponder\Autoresponder::forge();
         $autoresponder->view_custom = 'discuss_brief';
         $autoresponder->view_admin = 'discuss_brief';
         $post = \Input::post();
         if ($product = \Product\Model_Product::find_one_by_id(\Input::post('product'))) {
             $post['product'] = $product;
         }
         $content['content'] = $post;
         $config = array('path' => APPPATH . 'tmp', 'normalize' => true, 'max_size' => 5242880);
         // Check if file uploaded
         if (isset($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['name'] != '') {
             // process the uploaded files in $_FILES
             \Upload::process($config);
             // if there are any valid files
             if (\Upload::is_valid()) {
                 // save them according to the config
                 \Upload::save();
                 $file = \Upload::get_files(0);
             }
             // Upload errors
             if (\Upload::get_errors() !== array()) {
                 foreach (\Upload::get_errors() as $file) {
                     foreach ($file['errors'] as $key => $value) {
                         \Messages::error($value['message']);
                     }
                 }
                 \Response::redirect(\Input::referrer(\Uri::create('/')));
             }
         }
         $attachment = array();
         if (isset($file['saved_to']) && is_file($file['saved_to'] . $file['saved_as'])) {
             $attachment = array($file['saved_to'] . $file['saved_as']);
         }
         // echo 'test';
         // die;
         $content['subject'] = 'Thanks for contacting Evan Evans';
         $autoresponder->autoresponder_custom($content, \Input::post('email'), $attachment);
         $content['subject'] = 'Autoresponder Discuss Brief for Admin';
         $autoresponder->autoresponder_admin($content, \Config::get('auto_response_emails.discuss_brief'), $attachment);
         if ($autoresponder->send()) {
             \Messages::success('Thank You for sending request.');
         } else {
             \Messages::error('There was an error while trying to submit request.');
         }
         // Delete uploaded files
         if (!empty($attachment)) {
             foreach ($attachment as $file) {
                 if (is_file($file)) {
                     unlink($file);
                 }
             }
         }
         \Response::redirect(\Input::referrer(\Uri::create('/')));
     }
     if (\Input::is_ajax()) {
         $products = \Product\Model_Product::fetch_pair('id', 'title', array('order_by' => array('title' => 'asc')));
         echo \Theme::instance()->view('views/_partials/discuss_brief')->set('products', $products, false);
         exit;
     }
     throw new \HttpNotFoundException();
 }
 /**
  * Generate values for the "properties" key for the page() method.
  * 
  * @return array The array of data for the "properties" key.
  */
 private function _get_page_properties()
 {
     $properties_data['properties'] = array('url' => \Uri::base() . 'SEGMENT_PACKAGE_NO_URL_SET', 'referrer' => \Input::referrer(), 'path' => '/' . \Uri::string());
     /*
      * Fix: When \Request::main() is false, \Uri::main() tryies to get a property of the non-object
      * \Request::main().
      */
     if (\Request::main() instanceof \Request) {
         $properties_data['properties']['url'] = \Uri::main();
     }
     return $properties_data;
 }
Exemple #28
0
 /**
  * Add infotabs to product
  * 
  * @param $product_id	= Product ID
  * 
  */
 public function action_infotab_list($produt_id = false)
 {
     if (!is_numeric($produt_id)) {
         \Response::redirect('admin/product/list');
     }
     // Get news item to edit
     if (!($item = Model_Product::find_one_by_id($produt_id))) {
         \Response::redirect('admin/product/list');
     }
     if (\Input::post()) {
         $add = \Input::post('infotabs.add', array());
         $remove = \Input::post('infotabs.remove', array());
         if (\Input::post('add', false)) {
             foreach ($add as $value) {
                 $infotab = Model_Product_To_Infotabs::forge(array('infotab_id' => $value, 'product_id' => $item->id));
                 $infotab->save();
             }
             \Messages::success('Info Tabs successfully added.');
         } else {
             if (\Input::post('remove', false)) {
                 foreach ($remove as $value) {
                     $this->action_infotab_delete($value);
                 }
                 \Messages::success('Info Tabs successfully removed.');
             }
         }
         if (\Input::is_ajax()) {
             echo \Messages::display('left', false);
             exit;
         } else {
             \Response::redirect(\Input::referrer(\Uri::create('admin/product/list')));
         }
     }
     \View::set_global('title', 'Product Infotabs');
     /************ Get non related infotabs ***********/
     $items = Model_Infotab::find(function ($query) use($item) {
         $related_ids = array();
         foreach ($item->infotabs as $infotab) {
             array_push($related_ids, $infotab->infotab_id);
         }
         if (!empty($related_ids)) {
             $related_ids = '(' . implode(',', $related_ids) . ')';
             $query->where('id', 'NOT IN', \DB::expr($related_ids));
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     $item->not_related_infotabs = $items ? $items : array();
     \Theme::instance()->set_partial('content', $this->view_dir . 'infotabs_list')->set('product', $item);
 }
Exemple #29
0
 /**
  * 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');
     }
 }
Exemple #30
0
 public function action_delete($id = false)
 {
     if (is_numeric($id)) {
         // Get news item to edit
         if ($item = Model_Attribute_Option::find_one_by_id($id)) {
             // Delete item
             try {
                 $item->delete();
                 // NRB-Gem: remove from product_attributes and product_attribute_price
                 $a_attr = \Product\Model_Attribute::find_by(array(array('attributes', 'like', '%"' . $item->attribute_id . '":"' . $id . '"%')));
                 $a_attr_id = array();
                 foreach ($a_attr as $o_attr) {
                     $a_attr_id[] = $o_attr->id;
                 }
                 if (count($a_attr_id)) {
                     $s_ids = '(' . implode(',', $a_attr_id) . ')';
                     \DB::delete('product_attributes')->where('id', 'IN', \DB::expr($s_ids))->execute();
                     \DB::delete('product_attribute_price')->where('product_attribute_id', 'IN', \DB::expr($s_ids))->execute();
                 }
                 \Messages::success('Attribute option successfully deleted.');
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to delete attribute option</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         }
     }
     if (\Request::is_hmvc()) {
         \Messages::reset();
     } else {
         \Response::redirect(\Input::referrer(\Uri::create('admin/attribute/list')));
     }
 }