Exemple #1
0
 /**
  * Sets up the Order list view
  *
  * Sets the $objTemplate parameter to the default backend template,
  * if empty.
  * @param   \Cx\Core\Html\Sigma $objTemplate    The Template, by reference
  * @param   array       $filter                 The optional filter
  * @return  boolean                             True on success,
  *                                              false otherwise
  */
 static function view_list(&$objTemplate = null, $filter = NULL)
 {
     global $_ARRAYLANG, $objInit;
     $backend = $objInit->mode == 'backend';
     if (!$objTemplate) {
         $objTemplate = new \Cx\Core\Html\Sigma(\Cx\Core\Core\Controller\Cx::instanciate()->getCodeBaseModulePath() . '/Shop/View/Template/Backend');
         //DBG::log("Orders::view_list(): new Template: ".$objTemplate->get());
         $objTemplate->loadTemplateFile('module_shop_orders.html');
         //DBG::log("Orders::view_list(): loaded Template: ".$objTemplate->get());
     }
     $uri = $backend ? \Html::getRelativeUri_entities() : \Cx\Core\Routing\Url::fromModuleAndCmd('Shop', 'history', NULL);
     //DBG::log("Orders::view_list(): URI: $uri");
     // TODO: Better use a redirect after doing stuff!
     \Html::stripUriParam($uri, 'act');
     \Html::stripUriParam($uri, 'searchterm');
     \Html::stripUriParam($uri, 'listletter');
     \Html::stripUriParam($uri, 'customer_type');
     \Html::stripUriParam($uri, 'status');
     \Html::stripUriParam($uri, 'show_pending_orders');
     \Html::stripUriParam($uri, 'order_id');
     \Html::stripUriParam($uri, 'changeOrderStatus');
     \Html::stripUriParam($uri, 'sendMail');
     if (!is_array($filter)) {
         $filter = array();
     }
     if (!empty($_REQUEST['searchterm'])) {
         $filter['term'] = trim(strip_tags(contrexx_input2raw($_REQUEST['searchterm'])));
         \Html::replaceUriParameter($uri, 'searchterm=' . $filter['term']);
     } elseif (!empty($_REQUEST['listletter'])) {
         $filter['letter'] = trim(strip_tags(contrexx_input2raw($_REQUEST['listletter'])));
         \Html::replaceUriParameter($uri, 'listletter=' . $filter['letter']);
     }
     $customer_type = $usergroup_id = null;
     // Ignore
     if (isset($_REQUEST['customer_type']) && $_REQUEST['customer_type'] !== '') {
         $customer_type = intval($_REQUEST['customer_type']);
         \Html::replaceUriParameter($uri, 'customer_type=' . $customer_type);
         if ($customer_type == 0) {
             $usergroup_id = \Cx\Core\Setting\Controller\Setting::getValue('usergroup_id_customer', 'Shop');
         }
         if ($customer_type == 1) {
             $usergroup_id = \Cx\Core\Setting\Controller\Setting::getValue('usergroup_id_reseller', 'Shop');
         }
         $objFWUser = \FWUser::getFWUserObject();
         $objGroup = $objFWUser->objGroup->getGroup($usergroup_id);
         if ($objGroup) {
             $filter['customer_id'] = $objGroup->getAssociatedUserIds();
             // No customers of that type, so suppress all results
             if (empty($filter['customer_id'])) {
                 $filter['customer_id'] = array(0);
             }
             //DBG::log("Orders::view_list(): Group ID $usergroup_id, Customers: ".var_export($filter['customer_id'], true));
         }
     }
     $status = null;
     // Ignore
     $arrStatus = null;
     if (isset($_REQUEST['status']) && $_REQUEST['status'] !== '') {
         $status = intval($_REQUEST['status']);
         if ($status >= Order::STATUS_PENDING && $status < Order::STATUS_MAX) {
             $arrStatus = array($status => true);
             \Html::replaceUriParameter($uri, 'status=' . $status);
             if ($status == Order::STATUS_PENDING) {
                 $_REQUEST['show_pending_orders'] = true;
             }
         }
     }
     // Let the user choose whether to see pending orders, too
     $show_pending_orders = false;
     if ($backend) {
         if (empty($_REQUEST['show_pending_orders'])) {
             if (empty($arrStatus)) {
                 $arrStatus = self::getStatusArray();
                 unset($arrStatus[Order::STATUS_PENDING]);
             }
         } else {
             if ($arrStatus) {
                 $arrStatus[Order::STATUS_PENDING] = true;
             }
             $show_pending_orders = true;
             \Html::replaceUriParameter($uri, 'show_pending_orders=1');
         }
     }
     if ($arrStatus) {
         $filter['status'] = array_keys($arrStatus);
     }
     //DBG::log("Orders::view_list(): URI for Sorting: $uri, decoded ".html_entity_decode($uri));
     $arrSorting = array('id' => $_ARRAYLANG['TXT_SHOP_ID'], 'date_time' => $_ARRAYLANG['TXT_SHOP_ORDER_DATE'], 'customer_name' => $_ARRAYLANG['TXT_SHOP_CUSTOMER'], 'sum' => $_ARRAYLANG['TXT_SHOP_ORDER_SUM'], 'status' => $_ARRAYLANG['TXT_SHOP_ORDER_STATUS']);
     $objSorting = new \Sorting($uri, $arrSorting, false, 'order_shop_orders');
     $uri_search = $uri;
     \Html::stripUriParam($uri_search, 'searchterm');
     \Html::stripUriParam($uri_search, 'customer_type');
     \Html::stripUriParam($uri_search, 'status');
     \Html::stripUriParam($uri_search, 'show_pending_orders');
     $objTemplate->setGlobalVariable($_ARRAYLANG);
     if ($backend) {
         $txt_order_complete = sprintf($_ARRAYLANG['TXT_SEND_TEMPLATE_TO_CUSTOMER'], $_ARRAYLANG['TXT_ORDER_COMPLETE']);
         $objTemplate->setVariable(array('SHOP_SEND_TEMPLATE_TO_CUSTOMER' => $txt_order_complete, 'SHOP_CUSTOMER_TYPE_MENUOPTIONS' => Customers::getTypeMenuoptions($customer_type, true), 'SHOP_CUSTOMER_SORT_MENUOPTIONS' => Customers::getSortMenuoptions($objSorting->getOrderField()), 'SHOP_SHOW_PENDING_ORDERS_CHECKED' => $show_pending_orders ? \Html::ATTRIBUTE_CHECKED : '', 'SHOP_ORDER_STATUS_MENUOPTIONS' => self::getStatusMenuoptions($status, true)));
     }
     //DBG::log("Orders::view_list(): Order complete: $txt_order_complete");
     //DBG::log("Orders::view_list(): URI: $uri");
     $objTemplate->setGlobalVariable(array('SHOP_SEARCH_TERM' => isset($filter['term']) ? $filter['term'] : '', 'SHOP_ORDERS_ORDER_NAME' => $objSorting->getOrderParameterName(), 'SHOP_ORDERS_ORDER_VALUE' => $objSorting->getOrderUriEncoded(), 'SHOP_ACTION_URI_SEARCH_ENCODED' => $uri_search, 'SHOP_ACTION_URI_ENCODED' => $uri, 'SHOP_ACTION_URI' => html_entity_decode($uri), 'SHOP_CURRENCY', Currency::getDefaultCurrencySymbol()));
     $count = 0;
     $limit = \Cx\Core\Setting\Controller\Setting::getValue('numof_orders_per_page_backend', 'Shop');
     // TODO: Obsolete ASAP
     if (!$limit) {
         ShopSettings::errorHandler();
         $limit = 25;
     }
     $tries = 2;
     $arrOrders = null;
     //\DBG::activate(DBG_DB_FIREPHP);
     while ($tries-- && $count == 0) {
         $arrOrders = self::getArray($count, $objSorting->getOrder(), $filter, \Paging::getPosition(), $limit);
         if ($count > 0) {
             break;
         }
         \Paging::reset();
     }
     //DBG::deactivate(DBG_DB);
     //\DBG::log("Orders: ".count($arrOrders));
     $paging = \Paging::get($uri, $_ARRAYLANG['TXT_ORDERS'], $count, $limit, $count > 0);
     $objTemplate->setVariable(array('SHOP_ORDER_PAGING' => $paging, 'SHOP_CUSTOMER_LISTLETTER' => isset($filter['letter']) ? $filter['letter'] : '', 'SHOP_HEADER_ID' => $objSorting->getHeaderForField('id'), 'SHOP_HEADER_DATE_TIME' => $objSorting->getHeaderForField('date_time'), 'SHOP_HEADER_STATUS' => $objSorting->getHeaderForField('status'), 'SHOP_HEADER_CUSTOMER_NAME' => $objSorting->getHeaderForField('customer_name'), 'SHOP_HEADER_NOTES' => $_ARRAYLANG['TXT_SHOP_ORDER_NOTES'], 'SHOP_HEADER_SUM' => $objSorting->getHeaderForField('sum'), 'SHOP_LISTLETTER_LINKS' => self::getListletterLinks(isset($filter['letter']) ? $filter['letter'] : NULL)));
     if (empty($arrOrders)) {
         //            $objTemplate->hideBlock('orderTable');
         $objTemplate->setVariable('SHOP_ORDER_NONE_FOUND', $_ARRAYLANG['TXT_SHOP_ORDERS_NONE_FOUND']);
         //\DBG::log("NO Orders!");
         return true;
     }
     $i = 0;
     // TODO: For Order export
     /*        $min_date = '9999-00-00 00:00:00';
             $max_date = '0000-00-00 00:00:00';
             $min_id = 1e10;
             $max_id = 0;*/
     foreach ($arrOrders as $objOrder) {
         $order_id = $objOrder->id();
         // Custom order ID may be created and used as account name.
         // Adapt the method as needed.
         //            $order_id_custom = ShopLibrary::getCustomOrderId(
         //                $order_id, $objOrder->date_time()
         //            );
         // Take billing address from the Order.
         // No need to load the Customer.
         $customer_name = '';
         $company = $objOrder->billing_company();
         $customer_name = $company ? $company : $objOrder->billing_lastname() . ' ' . $objOrder->billing_firstname();
         $tipNote = $objOrder->note();
         $tipLink = empty($tipNote) ? '' : '<span class="tooltip-trigger icon-comment"></span>' . '<span class="tooltip-message">' . preg_replace('/[\\n\\r]+/', '<br />', nl2br(contrexx_raw2xhtml($tipNote))) . '</span>';
         $status = $objOrder->status();
         $objTemplate->setVariable(array('SHOP_ROWCLASS' => $status == 0 ? 'rowwarn' : 'row' . (++$i % 2 + 1), 'SHOP_ORDERID' => $order_id, 'SHOP_TIP_LINK' => $tipLink, 'SHOP_DATE' => date(ASCMS_DATE_FORMAT_DATETIME, strtotime($objOrder->date_time())), 'SHOP_NAME' => $customer_name, 'SHOP_ORDER_SUM' => Currency::getDefaultCurrencyPrice($objOrder->sum()), 'SHOP_ORDER_STATUS' => $backend ? self::getStatusMenu(intval($status), false, $order_id, 'changeOrderStatus(' . $order_id . ',' . $status . ',this.value)') : $_ARRAYLANG['TXT_SHOP_ORDER_STATUS_' . $status]));
         $objTemplate->parse('orderRow');
         //\DBG::log("Parsed Order ID $order_id");
         // TODO: Order export
         /*            if ($objOrder->date_time() < $min_date)
                         $min_date = $objOrder->date_time();
                     if ($objOrder->date_time() > $max_date)
                         $max_date = $objOrder->date_time();
                     if ($objOrder->id() < $min_id) $min_id = $objOrder->id();
                     if ($objOrder->id() > $max_id) $max_id = $objOrder->id();*/
     }
     $objTemplate->setVariable('SHOP_ORDER_PAGING', $paging);
     // TODO: Order export
     /*        $arrId = range($min_id-1, $max_id);
             $arrId = array(0 => "0") + array_combine($arrId, $arrId);
             $objTemplate->setVariable(array(
                 'SHOP_ORDER_EXPORT_LAST_ID_MENUOPTIONS' =>
                     Html::getOptions($arrId),
                 'SHOP_ORDER_EXPORT_START_DATE' =>
                     Html::getDatepicker('start_date', array(
                         'defaultDate' => date(ASCMS_DATE_FORMAT_DATE,
                             strtotime($min_date)),
                         'minDate' => '-7d',
                         'maxDate' => '+0d', )),
                 'SHOP_ORDER_EXPORT_END_DATE' =>
                     Html::getDatepicker('end_date', array(
                         'defaultDate' => date(ASCMS_DATE_FORMAT_DATE,
                             strtotime($max_date)+86400),
                         'minDate' => '-6d',
                         'maxDate' => '+1d', )),
             ));
     //die("Template: ".  nl2br(htmlentities(var_export($objTemplate, true))));
     //die("Template: ".  $objTemplate->get());*/
     return true;
 }