public function execute()
 {
     if (!shopAffiliate::isEnabled()) {
         throw new waException(_w('Unknown page'), 404);
     }
     $scm = new shopCustomerModel();
     $customer = $scm->getById(wa()->getUser()->getId());
     $atm = new shopAffiliateTransactionModel();
     $affiliate_history = $atm->getByContact(wa()->getUser()->getId());
     $url_tmpl = wa()->getRouteUrl('/frontend/myOrder', array('id' => '%ID%'));
     foreach ($affiliate_history as &$row) {
         if ($row['order_contact_id'] == $row['contact_id']) {
             $row['order_url'] = str_replace('%ID%', $row['order_id'], $url_tmpl);
         }
     }
     $this->view->assign('customer', $customer);
     $this->view->assign('affiliate_history', $affiliate_history);
     // Set up layout and template from theme
     $this->setThemeTemplate('my.affiliate.html');
     $this->view->assign('my_nav_selected', 'affiliate');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('Affiliate program'));
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
     /**
      *
      * @event frontend_my_affiliate
      * @return array[string]string $return[%plugin_id%] html output
      */
     $this->view->assign('frontend_my_affiliate', wa()->event('frontend_my_affiliate'));
 }
예제 #2
0
 public function execute()
 {
     $cache = null;
     if ($cache_time = $this->getConfig()->getOption('cache_time')) {
         //$cache = new waSerializeCache('pages/'.$domain.$url.'page');
     }
     $page = array();
     if ($cache && $cache->isCached()) {
         $page = $cache->get();
     } else {
         $site = new siteFrontend();
         if (waRequest::param('error')) {
             $page = array();
         } else {
             $page = $site->getPage(waRequest::param('url', ''));
         }
         if ($page && $cache) {
             $cache->set($page);
         }
     }
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new siteFrontendLayout());
     }
     try {
         $this->executeAction(new siteFrontendAction($page));
     } catch (Exception $e) {
         if (waSystemConfig::isDebug()) {
             echo $e;
         } else {
             waSystem::setActive('site');
             $this->executeAction(new siteFrontendAction($e));
         }
     }
 }
예제 #3
0
 public function execute()
 {
     parent::execute();
     $this->view->assign('my_nav_selected', 'profile');
     $user = wa()->getUser();
     $user_info = array();
     foreach ($this->form->fields as $id => $field) {
         if (!in_array($id, array('password', 'password_confirm'))) {
             if ($id === 'photo') {
                 $user_info[$id] = array('name' => _ws('Photo'), 'value' => '<img src="' . $user->getPhoto() . '">');
             } else {
                 $user_info[$id] = array('name' => $this->form->fields[$id]->getName(null, true), 'value' => $user->get($id, 'html'));
             }
         }
     }
     $this->view->assign('user_info', $user_info);
     // Set up layout and template from theme
     $this->setThemeTemplate('my.profile.html');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new photosDefaultFrontendLayout());
         $this->getResponse()->setTitle(_w('My account') . ' — ' . _w('My profile'));
         $this->layout->assign('breadcrumbs', $this->getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
예제 #4
0
 public function __construct($params = null)
 {
     parent::__construct($params);
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
     }
 }
 public function __construct($params = null)
 {
     parent::__construct($params);
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new photosDefaultFrontendLayout());
     }
     $this->view->getHelper()->globals($this->getRequest()->param());
     return $this;
 }
 public function execute()
 {
     $code = waRequest::param('code');
     $encoded_order_id = waRequest::param('id');
     $order_id = shopHelper::decodeOrderId($encoded_order_id);
     if (!$order_id) {
         // fall back to non-encoded id
         $order_id = $encoded_order_id;
         $encoded_order_id = shopHelper::encodeOrderId($order_id);
     }
     if (!$order_id || $order_id != substr($code, 16, -16)) {
         throw new waException(_w('Order not found'), 404);
     }
     // When user is authorized, check if order belongs to him.
     // When it does, redirect to plain order page.
     if (wa()->getUser()->isAuth()) {
         $om = new shopOrderModel();
         $order = $om->getOrder($order_id);
         if (!$order) {
             throw new waException(_w('Order not found'), 404);
         }
         if ($order['contact_id'] == wa()->getUser()->getId()) {
             $this->redirect(wa()->getRouteUrl('/frontend/myOrder', array('id' => $order_id)));
         }
     }
     // Check auth code
     $opm = new shopOrderParamsModel();
     $params = $opm->get($order_id);
     if (ifset($params['auth_code']) !== $code || empty($params['auth_pin'])) {
         throw new waException(_w('Order not found'), 404);
     }
     // Check auth pin and show order page if pin is correct
     $pin = waRequest::request('pin', wa()->getStorage()->get('shop/pin/' . $order_id));
     if ($pin && $pin == $params['auth_pin']) {
         wa()->getStorage()->set('shop/pin/' . $order_id, $pin);
         parent::execute();
         if (!waRequest::isXMLHttpRequest()) {
             $this->layout->assign('breadcrumbs', self::getBreadcrumbs());
         }
         return;
     }
     //
     // No pin or pin is incorrect: show form to enter pin
     //
     $this->view->assign('wrong_pin', !!$pin);
     $this->view->assign('pin_required', true);
     $this->view->assign('encoded_order_id', $encoded_order_id);
     $this->view->assign('my_nav_selected', 'orders');
     // Set up layout and template from theme
     $this->setThemeTemplate('my.order.html');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('Order') . ' ' . $encoded_order_id);
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
예제 #7
0
 public function updateLastPage()
 {
     if (waRequest::isXMLHttpRequest() || !$this->id || wa()->getEnv() !== 'backend' || waRequest::method() == 'post') {
         return;
     }
     $page = wa()->getRequest()->server('REQUEST_URI');
     $backend = wa()->getConfig()->getBackendUrl(true);
     if ($page === $backend || substr($page, 0, strlen($backend) + 1) === $backend . '?') {
         return;
     }
     wa()->getResponse()->setCookie('last_page', $this->getId() . '^^^' . $page, null, null, '', false, true);
 }
 public function display()
 {
     if (waRequest::isXMLHttpRequest()) {
         $this->getResponse()->addHeader('Content-Type', 'application/json');
     }
     $this->getResponse()->sendHeaders();
     if (!$this->errors) {
         $data = array('status' => 'ok', 'data' => $this->response);
         echo json_encode($data);
     } else {
         echo json_encode(array('status' => 'fail', 'errors' => $this->errors));
     }
 }
 public function execute()
 {
     parent::execute();
     $this->view->assign('my_nav_selected', 'profile');
     // Set up layout and template from theme
     $this->setThemeTemplate('my.profile.html');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('Account'));
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
 public function finite()
 {
     $collection = new photosCollection($this->hash);
     $photos = $collection->getPhotos("*,thumb,frontend_link,tags", $this->offset, $this->photos_per_page);
     $photos = photosCollection::extendPhotos($photos);
     if ($this->hash) {
         $title = $collection->getTitle();
         if (!$title) {
             $this->getResponse()->setTitle(waRequest::param('title') ? waRequest::param('title') : wa()->accountName());
         } else {
             $this->getResponse()->setTitle($title);
         }
         $this->view->assign('title', photosPhoto::escape($title));
     } else {
         $this->getResponse()->setTitle(waRequest::param('title') ? waRequest::param('title') : wa()->accountName());
         $this->getResponse()->setMeta('keywords', waRequest::param('meta_keywords'));
         $this->getResponse()->setMeta('description', waRequest::param('meta_description'));
         $this->view->assign('title', '');
     }
     $this->workupPhotos($photos);
     $total_count = $collection->count();
     $this->view->assign('photos_per_page', $this->photos_per_page);
     $this->view->assign('pages_count', floor($total_count / $this->photos_per_page) + 1);
     $this->view->assign('total_photos_count', $total_count);
     $this->view->assign('offset', $this->offset);
     $this->view->assign('photos', $photos);
     $is_xhr = waRequest::isXMLHttpRequest();
     $this->view->assign('is_xhr', $is_xhr);
     if ($is_xhr) {
         $this->view->assign('frontend_collection', array());
     } else {
         /**
          * @event frontend_collection
          * @return array[string][string]string $return[%plugin_id%]['name'] Extra name info
          * @return array[string][string]string $return[%plugin_id%]['content'] Extra album description and etc
          * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section
          * @return array[string][string]string $return[%plugin_id%]['sidebar'] Footer section
          * @return array[string][string]string $return[%plugin_id%]['footer'] Footer section
          */
         $this->view->assign('frontend_collection', wa()->event('frontend_collection'));
     }
     $this->view->assign('lazy_load', !is_null(waRequest::get('lazy')));
     $v = wa()->getVersion();
     $this->getResponse()->addJs('js/lazy.load.js?v=' . $v, true);
     $this->getResponse()->addJs('js/frontend.photos.js?v=' . $v, true);
 }
 public function execute()
 {
     wa()->getStorage()->close();
     $filters = waRequest::post();
     if (waRequest::post('save_filters')) {
         unset($filters['save_filters']);
         wa()->getUser()->setSettings('webasyst', 'dashboard_activity', waRequest::post('app_id'));
     }
     $logs = $this->getLogs($filters, $count);
     $this->view->assign('activity', $logs);
     if ($logs && waRequest::isXMLHttpRequest()) {
         $row = reset($logs);
         $this->view->assign('datetime_group', $this->getDatetimeGroup($row['datetime']));
     }
     if ($count == 50) {
         $this->view->assign('activity_load_more', true);
     }
 }
 public function execute()
 {
     $contact = wa()->getUser();
     $scm = new shopCustomerModel();
     // Customer orders
     $om = new shopOrderModel();
     $orders = $om->where('contact_id=?', $contact->getId())->order('id DESC')->fetchAll('id');
     // Items for all orders, one query
     $im = new shopOrderItemsModel();
     foreach ($im->getByField('order_id', array_keys($orders), true) as $row) {
         $orders[$row['order_id']]['items'][] = $row;
     }
     // Params for all orders, one query
     $opm = new shopOrderParamsModel();
     foreach ($opm->getByField('order_id', array_keys($orders), true) as $row) {
         $orders[$row['order_id']]['params'][$row['name']] = $row['value'];
     }
     // Prepare order data for template
     $url_tmpl = wa()->getRouteUrl('/frontend/myOrder', array('id' => '%ID%'));
     $workflow = new shopWorkflow();
     foreach ($orders as $k => &$o) {
         if ($o['state_id'] == 'deleted') {
             unset($orders[$k]);
             continue;
         }
         $o['id_str'] = shopHelper::encodeOrderId($o['id']);
         $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
         $o['shipping_name'] = ifset($o['params']['shipping_name'], '');
         $o['payment_name'] = ifset($o['params']['payment_name'], '');
         $o['state'] = $workflow->getStateById($o['state_id']);
         $o['url'] = str_replace('%ID%', $o['id'], $url_tmpl);
     }
     $this->view->assign('orders', array_values($orders));
     $this->view->assign('my_nav_selected', 'orders');
     // Set up layout and template from theme
     $this->setThemeTemplate('my.orders.html');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('Orders'));
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
예제 #13
0
 public function execute()
 {
     /**
      *
      * @event frontend_my
      * @return array[string]string $return[%plugin_id%] html output
      */
     $this->view->assign('frontend_my', wa()->event('frontend_my'));
     // Set up layout and template from theme
     $this->setThemeTemplate('my.html');
     if (!file_exists($this->getTheme()->path . '/my.html')) {
         $this->redirect(wa()->getRouteUrl('/frontend/myOrders'));
     }
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('My account'));
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
예제 #14
0
 protected function checkXMLHttpRequest()
 {
     // Voodoo magic: reload page when user performs an AJAX request after session died.
     if (waRequest::isXMLHttpRequest() && (waRequest::param('secure') || waRequest::param('auth'))) {
         //
         // The idea behind this is quite complicated.
         //
         // When browser expects JSON and gets this response then the error handler is called.
         // Default error handler (see wa.core.js) looks for the wa-session-expired header
         // and reloads the page when it's found.
         //
         // On the other hand, when browser expects HTML, it's most likely to insert it to the DOM.
         // In this case <script> gets executed and browser reloads the whole layout to show login page.
         // (This is also the reason to use 200 HTTP response code here: no error handler required at all.)
         //
         header('wa-session-expired: 1');
         echo _ws('Session has expired. Please reload current page and log in again.') . '<script>window.location.reload();</script>';
         exit;
     }
 }
예제 #15
0
    public function __toString()
    {
        $wa_url = wa()->getRootUrl();
        $app_settings_model = new waAppSettingsModel();
        $account_name = $app_settings_model->get('webasyst', 'name', 'Webasyst');
        $wa_header = wa_header();
        $t = "_ws";
        $html = "";
        if (!waRequest::isXMLHttpRequest()) {
            $html .= <<<HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{$t("Welcome")} &mdash; {$account_name}</title>
<link href="{$wa_url}wa-content/css/wa/wa-1.0.css" rel="stylesheet">
<!--[if IE 8]><link type="text/css" href="{$wa_url}wa-content/css/wa/wa-1.0.ie8.css" rel="stylesheet"><![endif]-->
<!--[if IE 7]><link type="text/css" href="{$wa_url}wa-content/css/wa/wa-1.0.ie7.css" rel="stylesheet"><![endif]-->
<script src="{$wa_url}wa-content/js/jquery/jquery-1.7.1.min.js"></script>
</head>
<body>
{$wa_header}
<div id="wa-app" class="block double-padded">
HTML;
        } else {
            $response = new waResponse();
            $response->setStatus(403);
            $response->sendHeaders();
        }
        $html .= <<<HTML
  <h1>{$t("Error")} #403</h1>
  <div style="border:1px solid #EAEAEA;padding:10px; margin:10px 0">
  <p style="color:red; font-weight: bold">{$t("You have no permission to access this page.")}</p>

  <p>{$t("Please refer to your system administrator.")}</p>
  </div>
HTML;
        if (!waRequest::isXMLHttpRequest()) {
            $html .= "</div></body></html>";
        }
        return $html;
    }
 public function execute()
 {
     $code = waRequest::cookie('shop_cart');
     if (!$code) {
         $code = md5(uniqid(time(), true));
         // header for IE
         wa()->getResponse()->addHeader('P3P', 'CP="NOI ADM DEV COM NAV OUR STP"');
         // set cart cookie
         wa()->getResponse()->setCookie('shop_cart', $code, time() + 30 * 86400, null, '', false, true);
     }
     $this->cart = new shopCart($code);
     $this->cart_model = new shopCartItemsModel();
     $data = waRequest::post();
     $this->is_html = waRequest::request('html');
     // add service
     if (isset($data['parent_id'])) {
         $this->addService($data);
         return;
     }
     // add sku
     $sku_model = new shopProductSkusModel();
     $product_model = new shopProductModel();
     if (!isset($data['product_id'])) {
         $sku = $sku_model->getById($data['sku_id']);
         $product = $product_model->getById($sku['product_id']);
     } else {
         $product = $product_model->getById($data['product_id']);
         if (isset($data['sku_id'])) {
             $sku = $sku_model->getById($data['sku_id']);
         } else {
             if (isset($data['features'])) {
                 $product_features_model = new shopProductFeaturesModel();
                 $sku_id = $product_features_model->getSkuByFeatures($product['id'], $data['features']);
                 if ($sku_id) {
                     $sku = $sku_model->getById($sku_id);
                 } else {
                     $sku = null;
                 }
             } else {
                 $sku = $sku_model->getById($product['sku_id']);
                 if (!$sku['available']) {
                     $sku = $sku_model->getByField(array('product_id' => $product['id'], 'available' => 1));
                 }
                 if (!$sku) {
                     $this->errors = _w('This product is not available for purchase');
                     return;
                 }
             }
         }
     }
     $quantity = waRequest::post('quantity', 1);
     if ($product && $sku) {
         // check quantity
         if (!wa()->getSetting('ignore_stock_count')) {
             $c = $this->cart_model->countSku($code, $sku['id']);
             if ($sku['count'] !== null && $c + $quantity > $sku['count']) {
                 $quantity = $sku['count'] - $c;
                 $name = $product['name'] . ($sku['name'] ? ' (' . $sku['name'] . ')' : '');
                 if (!$quantity) {
                     $this->errors = sprintf(_w('Only %d pcs of %s are available, and you already have all of them in your shopping cart.'), $sku['count'], $name);
                     return;
                 } else {
                     $this->response['error'] = sprintf(_w('Only %d pcs of %s are available, and you already have all of them in your shopping cart.'), $sku['count'], $name);
                 }
             }
         }
         $services = waRequest::post('services', array());
         if ($services) {
             $variants = waRequest::post('service_variant');
             $temp = array();
             $service_ids = array();
             foreach ($services as $service_id) {
                 if (isset($variants[$service_id])) {
                     $temp[$service_id] = $variants[$service_id];
                 } else {
                     $service_ids[] = $service_id;
                 }
             }
             if ($service_ids) {
                 $service_model = new shopServiceModel();
                 $temp_services = $service_model->getById($service_ids);
                 foreach ($temp_services as $row) {
                     $temp[$row['id']] = $row['variant_id'];
                 }
             }
             $services = $temp;
         }
         $item_id = null;
         $item = $this->cart_model->getItemByProductAndServices($code, $product['id'], $sku['id'], $services);
         if ($item) {
             $item_id = $item['id'];
             $this->cart->setQuantity($item_id, $item['quantity'] + $quantity);
         }
         if (!$item_id) {
             $data = array('create_datetime' => date('Y-m-d H:i:s'), 'product_id' => $product['id'], 'sku_id' => $sku['id'], 'quantity' => $quantity, 'type' => 'product');
             if ($services) {
                 $data_services = array();
                 foreach ($services as $service_id => $variant_id) {
                     $data_services[] = array('service_id' => $service_id, 'service_variant_id' => $variant_id);
                 }
             } else {
                 $data_services = array();
             }
             $item_id = $this->cart->addItem($data, $data_services);
         }
         if (waRequest::isXMLHttpRequest()) {
             $this->response['item_id'] = $item_id;
             $this->response['total'] = $this->currencyFormat($this->cart->total());
             $this->response['discount'] = $this->currencyFormat($this->cart->discount());
             $this->response['count'] = $this->cart->count();
         } else {
             $this->redirect(waRequest::server('HTTP_REFERER'));
         }
     } else {
         throw new waException('product not found');
     }
 }
 public function execute()
 {
     $steps = $this->getConfig()->getCheckoutSettings();
     $current_step = waRequest::param('step', waRequest::request('step'));
     if (!$current_step) {
         $current_step = key($steps);
     }
     $title = _w('Checkout');
     if ($current_step == 'success') {
         $order_id = waRequest::get('order_id');
         if (!$order_id) {
             $order_id = wa()->getStorage()->get('shop/order_id');
             $payment_success = false;
         } else {
             $payment_success = true;
             $this->view->assign('payment_success', true);
         }
         if (!$order_id) {
             wa()->getResponse()->redirect(wa()->getRouteUrl('shop/frontend'));
         }
         $order_model = new shopOrderModel();
         $order = $order_model->getById($order_id);
         if ($order) {
             $order['_id'] = $order['id'];
         }
         if (!$payment_success) {
             $order_params_model = new shopOrderParamsModel();
             $order['params'] = $order_params_model->get($order_id);
             $order_items_model = new shopOrderItemsModel();
             $order['items'] = $order_items_model->getByField('order_id', $order_id, true);
             $payment = '';
             if (!empty($order['params']['payment_id'])) {
                 try {
                     /**
                      * @var waPayment $plugin
                      */
                     $plugin = shopPayment::getPlugin(null, $order['params']['payment_id']);
                     $payment = $plugin->payment(waRequest::post(), shopPayment::getOrderData($order, $plugin), true);
                 } catch (waException $ex) {
                     $payment = $ex->getMessage();
                 }
             }
             $order['id'] = shopHelper::encodeOrderId($order_id);
             $this->getResponse()->addGoogleAnalytics($this->getGoogleAnalytics($order));
         } else {
             $order['id'] = shopHelper::encodeOrderId($order_id);
         }
         $this->view->assign('order', $order);
         if (isset($payment)) {
             $this->view->assign('payment', $payment);
         }
     } else {
         $cart = new shopCart();
         if (!$cart->count() && $current_step != 'error') {
             $current_step = 'error';
             $this->view->assign('error', _w('Your shopping cart is empty. Please add some products to cart, and then proceed to checkout.'));
         }
         if ($current_step != 'error') {
             if (waRequest::method() == 'post') {
                 if (waRequest::post('wa_auth_login')) {
                     $login_action = new shopLoginAction();
                     $login_action->run();
                 } else {
                     $redirect = false;
                     foreach ($steps as $step_id => $step) {
                         if ($step_id == $current_step) {
                             $step_instance = $this->getStep($step_id);
                             if ($step_instance->execute()) {
                                 $redirect = true;
                             }
                         } elseif ($redirect) {
                             $this->redirect(wa()->getRouteUrl('/frontend/checkout', array('step' => $step_id)));
                         }
                     }
                     // last step
                     if ($redirect) {
                         if ($this->createOrder()) {
                             $this->redirect(wa()->getRouteUrl('/frontend/checkout', array('step' => 'success')));
                         }
                     }
                 }
             } else {
                 $this->view->assign('error', '');
             }
             $title .= ' - ' . $steps[$current_step]['name'];
             $steps[$current_step]['content'] = $this->getStep($current_step)->display();
             $this->view->assign('checkout_steps', $steps);
         }
     }
     $this->getResponse()->setTitle($title);
     $this->view->assign('checkout_current_step', $current_step);
     /**
      * @event frontend_checkout
      * @return array[string]string $return[%plugin_id%] html output
      */
     $event_params = array('step' => $current_step);
     $this->view->assign('frontend_checkout', wa()->event('frontend_checkout', $event_params));
     if (waRequest::isXMLHttpRequest()) {
         $this->setThemeTemplate('checkout.' . $current_step . '.html');
     } else {
         $this->setLayout(new shopFrontendLayout());
         $this->setThemeTemplate('checkout.html');
     }
 }
예제 #18
0
 public function execute()
 {
     $encoded_order_id = waRequest::param('id');
     $order_id = shopHelper::decodeOrderId($encoded_order_id);
     if (!$order_id) {
         // fall back to non-encoded id
         $order_id = $encoded_order_id;
         $encoded_order_id = shopHelper::encodeOrderId($order_id);
     }
     // Check that order exists and belongs to this user
     $om = new shopOrderModel();
     $order = $om->getOrder($order_id);
     if (!$order || !$this->isAuth($order)) {
         throw new waException(_w('Order not found'), 404);
     }
     if ($order['paid_date']) {
         foreach ($order['items'] as &$i) {
             if (!empty($i['file_name'])) {
                 $i['download_link'] = wa()->getRouteUrl('/frontend/myOrderDownload', array('id' => $order['id'], 'code' => $order['params']['auth_code'], 'item' => $i['id']), true);
             }
         }
         unset($i);
     }
     $workflow = new shopWorkflow();
     $order_params_model = new shopOrderParamsModel();
     $order['params'] = $order_params_model->get($order['id']);
     $order['id_str'] = $encoded_order_id;
     $order['state'] = $workflow->getStateById($order['state_id']);
     // Order subtotal
     $subtotal = 0;
     foreach ($order['items'] as $item) {
         $subtotal += $item['price'] * $item['quantity'];
     }
     // Order comment
     $lm = new shopOrderLogModel();
     $l = $lm->getByField(array('action_id' => 'create', 'order_id' => $order['id']));
     $order['comment'] = ifempty($l['text']);
     $order['payment_name'] = ifset($order['params']['payment_name'], '');
     $order['shipping_name'] = ifset($order['params']['shipping_name'], '');
     // Shipping and billing addresses
     $settings = wa('shop')->getConfig()->getCheckoutSettings();
     $form_fields = ifset($settings['contactinfo']['fields'], array());
     $formatter = new waContactAddressSeveralLinesFormatter();
     $shipping_address = shopHelper::getOrderAddress($order['params'], 'shipping');
     if ($shipping_address) {
         $shipping_address = $formatter->format(array('data' => $shipping_address));
         $shipping_address = $shipping_address['value'];
     }
     if (isset($form_fields['address.billing'])) {
         $billing_address = shopHelper::getOrderAddress($order['params'], 'billing');
         $billing_address = $formatter->format(array('data' => $billing_address));
         $billing_address = $billing_address['value'];
     } else {
         $billing_address = null;
     }
     if (wa()->getUser()->getId() == $order['contact_id']) {
         $contact = wa()->getUser();
     } else {
         $contact = new waContact($order['contact_id']);
     }
     $payment = '';
     if (!empty($order['params']['payment_id']) && !$order['paid_date']) {
         try {
             $plugin = shopPayment::getPlugin(null, $order['params']['payment_id']);
             $payment = $plugin->payment(waRequest::post(), shopPayment::getOrderData($order, $plugin), false);
         } catch (waException $ex) {
             $payment = $ex->getMessage();
         }
     }
     $this->view->assign('payment', $payment);
     $tracking = '';
     if (!empty($order['params']['shipping_id']) && !empty($order['params']['tracking_number'])) {
         try {
             $plugin = shopShipping::getPlugin(null, $order['params']['shipping_id']);
             $tracking = $plugin->tracking($order['params']['tracking_number']);
         } catch (waException $ex) {
             $tracking = $ex->getMessage();
         }
     }
     $this->view->assign('tracking', $tracking);
     $this->view->assign('order', $order);
     $this->view->assign('contact', $contact);
     $this->view->assign('shipping_address', $shipping_address);
     $this->view->assign('billing_address', $billing_address);
     $this->view->assign('subtotal', $subtotal);
     // Set up layout and template from theme
     $this->setThemeTemplate('my.order.html');
     $this->view->assign('my_nav_selected', 'orders');
     if (!waRequest::isXMLHttpRequest()) {
         $this->setLayout(new shopFrontendLayout());
         $this->getResponse()->setTitle(_w('Order') . ' ' . $encoded_order_id);
         $this->view->assign('breadcrumbs', self::getBreadcrumbs());
         $this->layout->assign('nofollow', true);
     }
 }
 public function execute($plugin = null, $module = null, $action = null, $default = false)
 {
     try {
         if (!waRequest::param('page_id')) {
             if (!waRequest::isXMLHttpRequest()) {
                 $request_url = parse_url($this->system->getRootUrl() . $this->system->getConfig()->getRequestUrl());
                 if (!empty($request_url['path']) && empty($request_url['query']) && substr($request_url['path'], -1) != '/') {
                     $request_url['path'] .= '/';
                     $this->system->getResponse()->redirect(implode('', $request_url), 301);
                 }
             }
         }
         if ($module == 'frontend' && $action != 'album') {
             // request params
             $id = waRequest::param('id', '', waRequest::TYPE_STRING_TRIM);
             $tag = waRequest::param('tag', '', waRequest::TYPE_STRING_TRIM);
             $author = waRequest::param('author', '', waRequest::TYPE_INT);
             $search = waRequest::param('search', '', waRequest::TYPE_STRING_TRIM);
             $favorites = waRequest::param('favorites', '', waRequest::TYPE_STRING_TRIM);
             $url = waRequest::param('url', '', waRequest::TYPE_STRING_TRIM);
             $type = 'all';
             $hash = '';
             $album = null;
             if ($author) {
                 $hash = 'author/' . $author;
                 $type = 'author';
             } else {
                 if ($search) {
                     $hash = 'search/' . $search;
                     $type = 'search';
                 } else {
                     if ($id) {
                         $hash = 'id/' . $id;
                         $type = 'id';
                     } else {
                         if ($tag) {
                             $hash = 'tag/' . $tag;
                             $type = 'tag';
                         } else {
                             if ($favorites) {
                                 $hash = 'favorites';
                                 $type = 'favorites';
                             } else {
                                 if ($url) {
                                     if (preg_match('/^([^\\s]+)\\/([^\\s\\/]+)/', trim($url, '/'), $m)) {
                                         $album_url = $m[1];
                                         $url = $m[2];
                                         $hash = photosCollection::frontendAlbumUrlToHash($album_url, $album);
                                         if (!$album) {
                                             throw new waException(_w('Page not found'), 404);
                                         }
                                         $type = 'album';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $url = rtrim($url, '/');
             waRequest::setParam('url', $url);
             waRequest::setParam('album', $album);
             waRequest::setParam('hash', $hash);
             waRequest::setParam('type', $type);
         }
         parent::execute($plugin, $module, $action, $default);
     } catch (Exception $e) {
         if ($module == 'frontend') {
             $action = new photosFrontendErrorAction($e);
             $action->display();
         } else {
             throw $e;
         }
     }
 }