function compareDatabaseFixProductToCategoryLinking()
 {
     $messages = array();
     $str = "show indexes from `tx_multishop_products_to_categories` ";
     $qry = $GLOBALS['TYPO3_DB']->sql_query($str);
     $unique_indexes = array();
     if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry)) {
         while (($rs = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) != false) {
             $unique_indexes[] = $rs['Key_name'];
         }
         if (!in_array('p2c_unique_key', $unique_indexes)) {
             // add unique p2c key
             $unique_key = 'ALTER IGNORE TABLE `tx_multishop_products_to_categories` ADD UNIQUE `p2c_unique_key` (`products_id`, `categories_id`, `page_uid`, `node_id`, `is_deepest`, `crumbar_identifier`)';
             $res = $GLOBALS['TYPO3_DB']->sql_query($unique_key);
             $messages[] = $unique_key;
         }
     }
     //
     $p2c_records = mslib_befe::getRecords('', 'tx_multishop_products_to_categories', '', array(), '', '', '');
     if (is_array($p2c_records) && count($p2c_records)) {
         foreach ($p2c_records as $p2c_record) {
             //if (!strlen($p2c_record['crumbar_identifier'])) {
             tx_mslib_catalog::compareDatabaseRebuildProductsToCategoryTree($p2c_record['products_id'], $p2c_record['categories_id']);
             //}
         }
     }
     // p2c fixer routine code for redundant records
     $query_p2c = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_to_categories', '', 'products_id,node_id', 'products_to_categories_id asc', '');
     $res_p2c = $GLOBALS['TYPO3_DB']->sql_query($query_p2c);
     $delete_counter = 0;
     if ($GLOBALS['TYPO3_DB']->sql_num_rows($res_p2c)) {
         while ($row_p2c = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_p2c)) {
             $query_p2c_del = $GLOBALS['TYPO3_DB']->SELECTquery('products_to_categories_id', 'tx_multishop_products_to_categories', 'products_id = \'' . $row_p2c['products_id'] . '\' and categories_id = \'' . $row_p2c['categories_id'] . '\' and node_id=\'' . $row_p2c['node_id'] . '\' and is_deepest=\'' . $row_p2c['is_deepest'] . '\'', '', 'products_to_categories_id asc', '');
             $res_p2c_del = $GLOBALS['TYPO3_DB']->sql_query($query_p2c_del);
             if ($GLOBALS['TYPO3_DB']->sql_num_rows($res_p2c_del)) {
                 while ($row_del = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_p2c_del)) {
                     if ($row_p2c['products_to_categories_id'] != $row_del['products_to_categories_id']) {
                         $del_p2c_query = $GLOBALS['TYPO3_DB']->DELETEquery('tx_multishop_products_to_categories', 'products_to_categories_id=\'' . $row_del['products_to_categories_id'] . '\'');
                         $res = $GLOBALS['TYPO3_DB']->sql_query($del_p2c_query);
                         $delete_counter++;
                     }
                 }
             }
         }
         if ($delete_counter) {
             $messages[] = 'Delete ' . $delete_counter . ' redundant record(s) from tx_multishop_products_to_categories';
         }
     }
     // p2c fixer routine code for redundant records eol
     $message = implode("\n\n", $messages);
     if (count($messages)) {
         return $message;
     }
     return '';
 }
 function setProductDefaultCrumpath($product_id)
 {
     $p2c_records = mslib_befe::getRecords($product_id, 'tx_multishop_products_to_categories', 'products_id', array('is_deepest=1'), '', 'products_to_categories_id asc');
     if (is_array($p2c_records) && count($p2c_records) > 1) {
         $set_default_path = true;
         foreach ($p2c_records as $p2c_record) {
             if ($p2c_record['default_path'] > 0) {
                 $set_default_path = false;
                 break;
             }
         }
         if ($set_default_path) {
             $updateArray = array();
             $updateArray['default_path'] = 1;
             $queryProduct = $GLOBALS['TYPO3_DB']->UPDATEquery('tx_multishop_products_to_categories', 'products_to_categories_id=\'' . $p2c_records[0]['products_to_categories_id'] . '\' and categories_id=\'' . $p2c_records[0]['categories_id'] . '\' and products_id=\'' . $p2c_records[0]['products_id'] . '\'', $updateArray);
             $GLOBALS['TYPO3_DB']->sql_query($queryProduct);
         }
     }
 }
if (!defined('TYPO3_MODE')) {
    die('Access denied.');
}
// hook
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/includes/admin_stats_orders/turn_over_per_month.php']['monthlyStatsOrdersPagePreProc'])) {
    $params = array();
    foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/includes/admin_stats_orders/turn_over_per_month.php']['monthlyStatsOrdersPagePreProc'] as $funcRef) {
        \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
    }
}
// billing countries
$additional_where = array();
if (!$this->masterShop) {
    $additional_where[] = 'page_uid=\'' . $this->shop_pid . '\'';
}
$order_countries = mslib_befe::getRecords('', 'tx_multishop_orders', '', $additional_where, 'billing_country', 'billing_country asc');
$order_billing_country = array();
foreach ($order_countries as $order_country) {
    $cn_localized_name = htmlspecialchars(mslib_fe::getTranslatedCountryNameByEnglishName($this->lang, $order_country['billing_country']));
    if (!empty($cn_localized_name)) {
        $order_billing_country[] = '<option value="' . mslib_befe::strtolower($order_country['billing_country']) . '" ' . (mslib_befe::strtolower($this->get['country']) == strtolower($order_country['billing_country']) ? 'selected' : '') . '>' . $cn_localized_name . '</option>';
    }
}
ksort($order_billing_country);
$billing_countries_sb = '<select class="invoice_select2" name="country" id="country""><option value="">' . $this->pi_getLL('all_countries') . '</option>' . implode("\n", $order_billing_country) . '</select>';
$all_orders_status = mslib_fe::getAllOrderStatus($GLOBALS['TSFE']->sys_language_uid);
if ($this->post['Search'] and $this->get['payment_status'] != $this->cookie['payment_status']) {
    $this->cookie['payment_status'] = $this->get['payment_status'];
    $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_multishop_cookie', $this->cookie);
    $GLOBALS['TSFE']->storeSessionData();
}
     } else {
         $parentClasses[] = 'text-info';
     }
 }
 if ($order['by_phone']) {
     $classes[] = 'fa fa-phone fa-stack-1x fa-inverse';
     $markerArray['MANUAL_ORDER_ICON'] = '<span class="' . implode(' ', $parentClasses) . '"><i class="fa fa-circle fa-stack-2x fa-circle-phone"></i><i class="' . implode(' ', $classes) . '"></i></span>';
 } else {
     $classes[] = 'fa fa-cart-plus fa-stack-1x fa-inverse';
     $markerArray['MANUAL_ORDER_ICON'] = '<span class="' . implode(' ', $parentClasses) . '"><i class="fa fa-circle fa-stack-2x fa-circle-cart-plus"></i><i class="' . implode(' ', $classes) . '"></i></span>';
 }
 $markerArray['INVOICE_NUMBER'] = '';
 if ($this->ms['MODULES']['ADMIN_INVOICE_MODULE']) {
     $markerArray['INVOICE_NUMBER'] = '<td align="right">';
     $filter = array();
     $invoices = mslib_befe::getRecords($order['orders_id'], 'tx_multishop_invoices i', 'i.orders_id', $filter);
     $links = array();
     if (is_array($invoices) && count($invoices)) {
         foreach ($invoices as $invoice) {
             $invoice = mslib_fe::getInvoice($invoice['id'], 'id');
             $links[] = '<a href="' . mslib_fe::typolink($this->shop_pid . ',2002', 'tx_multishop_pi1[page_section]=download_invoice&tx_multishop_pi1[hash]=' . $invoice['hash']) . '" target="_blank">' . $invoice['invoice_id'] . '</a>';
         }
     }
     if (count($links)) {
         $markerArray['INVOICE_NUMBER'] .= implode('<br/>', $links);
     }
     $markerArray['INVOICE_NUMBER'] .= '</td>';
 }
 if (isset($this->get['tx_multishop_pi1']['is_proposal'])) {
     $markerArray['ORDER_EDIT_URL'] = mslib_fe::typolink($this->shop_pid . ',2003', '&tx_multishop_pi1[page_section]=edit_order&orders_id=' . $order['orders_id'] . '&action=edit_order&tx_multishop_pi1[is_proposal]=1');
 } else {
 public function getUsersByGroup($group_id)
 {
     if (is_numeric($group_id)) {
         $additional_where = array();
         $additional_where[] = 'FIND_IN_SET(\'' . $group_id . '\',usergroup) > 0';
         $users = mslib_befe::getRecords(0, 'fe_users', 'disable', $additional_where);
         return $users;
     }
 }
Exemple #6
0
        $row['shipping_method'] = 'nosm';
        $row['shipping_method_label'] = 'Empty shipping method';
    }
    $shipping_methods[$row['shipping_method']] = $row['shipping_method_label'];
}
$shipping_method_input = '';
$shipping_method_input .= '<select id="shipping_method" class="order_select2" name="shipping_method">' . "\n";
$shipping_method_input .= '<option value="all">' . $this->pi_getLL('all_shipping_methods') . '</option>' . "\n";
if (is_array($shipping_methods) and count($shipping_methods)) {
    foreach ($shipping_methods as $shipping_method_code => $shipping_method) {
        $shipping_method_input .= '<option value="' . $shipping_method_code . '"' . ($this->post['shipping_method'] == $shipping_method_code ? ' selected="selected"' : '') . '>' . $shipping_method . '</option>' . "\n";
    }
}
$shipping_method_input .= '</select>' . "\n";
// billing country
$order_countries = mslib_befe::getRecords('', 'tx_multishop_orders', '', array(), 'billing_country', 'billing_country asc');
$order_billing_country = array();
if (is_array($order_countries) && count($order_countries)) {
    foreach ($order_countries as $order_country) {
        $cn_localized_name = htmlspecialchars(mslib_fe::getTranslatedCountryNameByEnglishName($this->lang, $order_country['billing_country']));
        $order_billing_country[$cn_localized_name] = '<option value="' . mslib_befe::strtolower($order_country['billing_country']) . '" ' . (mslib_befe::strtolower($this->post['country']) == strtolower($order_country['billing_country']) ? 'selected' : '') . '>' . $cn_localized_name . '</option>';
    }
    ksort($order_billing_country);
}
$billing_countries_selectbox = '<select class="order_select2" name="country" id="country"><option value="">' . $this->pi_getLL('all_countries') . '</option>' . implode("\n", $order_billing_country) . '</select>';
$subpartArray = array();
$subpartArray['###AJAX_ADMIN_EDIT_ORDER_URL###'] = mslib_fe::typolink($this->shop_pid . ',2003', '&tx_multishop_pi1[page_section]=edit_order&action=edit_order');
$subpartArray['###FORM_SEARCH_ACTION_URL###'] = mslib_fe::typolink($this->shop_pid . ',2003', 'tx_multishop_pi1[page_section]=admin_orders');
$subpartArray['###SHOP_PID###'] = $this->shop_pid;
//
$subpartArray['###UNFOLD_SEARCH_BOX###'] = '';
 function mailOrder($orders_id, $copy_to_merchant = 1, $custom_email_address = '', $mail_template = '')
 {
     $order = mslib_fe::getOrder($orders_id);
     if ($order['orders_id']) {
         $order['mail_template'] = $mail_template;
         if (isset($order['language_id'])) {
             // Switch to language that is stored in the order
             mslib_befe::setSystemLanguage($order['language_id']);
         }
         if (!$custom_email_address) {
             $custom_email_address = $order['billing_email'];
         }
         $billing_address = '';
         $delivery_address = '';
         $full_customer_name = $order['billing_first_name'];
         if ($order['billing_middle_name']) {
             $full_customer_name .= ' ' . $order['billing_middle_name'];
         }
         if ($order['billing_last_name']) {
             $full_customer_name .= ' ' . $order['billing_last_name'];
         }
         $delivery_full_customer_name = $order['delivery_first_name'];
         if ($order['delivery_middle_name']) {
             $delivery_full_customer_name .= ' ' . $order['delivery_middle_name'];
         }
         if ($order['delivery_last_name']) {
             $delivery_full_customer_name .= ' ' . $order['delivery_last_name'];
         }
         $full_customer_name = preg_replace('/\\s+/', ' ', $full_customer_name);
         $delivery_full_customer_name = preg_replace('/\\s+/', ' ', $delivery_full_customer_name);
         if (!$order['delivery_address'] or !$order['delivery_city']) {
             $order['delivery_company'] = $order['billing_company'];
             $order['delivery_street_name'] = $order['billing_street_name'];
             $order['delivery_building'] = $order['billing_building'];
             $order['delivery_address'] = $order['billing_address'];
             $order['delivery_address_number'] = $order['billing_address_number'];
             $order['delivery_address_ext'] = $order['billing_address_ext'];
             $order['delivery_zip'] = $order['billing_zip'];
             $order['delivery_city'] = $order['billing_city'];
             $order['delivery_telephone'] = $order['billing_telephone'];
             $order['delivery_mobile'] = $order['billing_mobile'];
         }
         if ($order['delivery_company']) {
             $delivery_address = $order['delivery_company'] . "<br />";
         }
         if ($delivery_full_customer_name) {
             $delivery_address .= $delivery_full_customer_name . "<br />";
         }
         if ($order['delivery_building']) {
             $delivery_address .= $order['delivery_building'] . "<br />";
         }
         if ($order['delivery_address']) {
             $delivery_address .= $order['delivery_address'] . "<br />";
         }
         if ($order['delivery_zip'] and $order['delivery_city']) {
             $delivery_address .= $order['delivery_zip'] . " " . $order['delivery_city'];
         }
         if ($order['delivery_country'] && mslib_befe::strtolower($order['delivery_country']) != mslib_befe::strtolower($this->tta_shop_info['country'])) {
             // ONLY PRINT COUNTRY IF THE COUNTRY OF THE CUSTOMER IS DIFFERENT THAN FROM THE SHOP
             $delivery_address .= '<br />' . mslib_fe::getTranslatedCountryNameByEnglishName($this->lang, $order['delivery_country']);
         }
         //		if ($order['delivery_telephone']) 		$delivery_address.=ucfirst($this->pi_getLL('telephone')).': '.$order['delivery_telephone']."<br />";
         //		if ($order['delivery_mobile']) 			$delivery_address.=ucfirst($this->pi_getLL('mobile')).': '.$order['delivery_mobile']."<br />";
         if ($order['billing_company']) {
             $billing_address = $order['billing_company'] . "<br />";
         }
         if ($full_customer_name) {
             $billing_address .= $full_customer_name . "<br />";
         }
         if ($order['billing_building']) {
             $billing_address .= $order['billing_building'] . "<br />";
         }
         if ($order['billing_address']) {
             $billing_address .= $order['billing_address'] . "<br />";
         }
         if ($order['billing_zip'] and $order['billing_city']) {
             $billing_address .= $order['billing_zip'] . " " . $order['billing_city'];
         }
         if ($order['billing_country'] && mslib_befe::strtolower($order['billing_country']) != mslib_befe::strtolower($this->tta_shop_info['country'])) {
             // ONLY PRINT COUNTRY IF THE COUNTRY OF THE CUSTOMER IS DIFFERENT THAN FROM THE SHOP
             $billing_address .= '<br />' . mslib_fe::getTranslatedCountryNameByEnglishName($this->lang, $order['billing_country']);
         }
         $loadFromPids = array();
         if ($this->conf['masterShop']) {
             $loadFromPids[] = $order['page_uid'];
             $loadFromPids[] = $this->shop_pid;
             if ($this->showCatalogFromPage and $this->showCatalogFromPage != $this->shop_pid) {
                 $loadFromPids[] = $this->showCatalogFromPage;
             }
         }
         // psp email template
         $psp_mail_template = array();
         if ($order['payment_method']) {
             $psp_data = mslib_fe::loadPaymentMethod($order['payment_method']);
             $psp_vars = unserialize($psp_data['vars']);
             if (isset($psp_vars['order_confirmation'])) {
                 $psp_mail_template['order_confirmation'] = '';
                 if ($psp_vars['order_confirmation'] > 0) {
                     $psp_mail_template['order_confirmation'] = mslib_fe::getCMSType($psp_vars['order_confirmation']);
                 }
             }
             if (isset($psp_vars['order_paid'])) {
                 $psp_mail_template['order_paid'] = '';
                 if ($psp_vars['order_paid'] > 0) {
                     $psp_mail_template['order_paid'] = mslib_fe::getCMSType($psp_vars['order_paid']);
                 }
             }
         }
         // loading the email template
         $page = array();
         //hook to let other plugins further manipulate the replacers
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderPreCMSContent'])) {
             $params = array('page' => &$page, 'order' => &$order, 'mail_template' => $mail_template, 'psp_mail_template' => $psp_mail_template, 'loadFromPids' => $loadFromPids);
             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderPreCMSContent'] as $funcRef) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
             }
         }
         if ($mail_template) {
             switch ($mail_template) {
                 case 'email_order_paid_letter':
                     if (isset($psp_mail_template['order_paid'])) {
                         $page = array();
                         if (!empty($psp_mail_template['order_paid'])) {
                             $page = mslib_fe::getCMScontent($psp_mail_template['order_paid'], $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
                         }
                     } else {
                         if ($order['payment_method']) {
                             $page = mslib_fe::getCMScontent('email_order_paid_letter_' . $order['payment_method'], $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
                         }
                         if (!count($page[0])) {
                             $page = mslib_fe::getCMScontent('email_order_paid_letter', $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
                         }
                     }
                     break;
                 default:
                     $page = mslib_fe::getCMScontent($mail_template, $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
                     break;
             }
         } else {
             if ($order['is_proposal']) {
                 // proposal template
                 $mail_template = 'email_order_proposal';
                 $page = mslib_fe::getCMScontent($mail_template, $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
             } else {
                 // normal order template
                 if (isset($psp_mail_template['order_confirmation'])) {
                     $page = array();
                     if (!empty($psp_mail_template['order_confirmation'])) {
                         $page = mslib_fe::getCMScontent($psp_mail_template['order_confirmation'], $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
                     }
                 } else {
                     if ($order['payment_method']) {
                         $page = mslib_fe::getCMScontent('email_order_confirmation_' . $order['payment_method'], $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
                     }
                     if (!count($page[0])) {
                         $page = mslib_fe::getCMScontent('email_order_confirmation', $GLOBALS['TSFE']->sys_language_uid, $loadFromPids);
                     }
                 }
             }
         }
         //hook to let other plugins further manipulate the replacers
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderPostCMSContent'])) {
             $params = array('page' => &$page, 'order' => &$order, 'mail_template' => $mail_template, 'psp_mail_template' => $psp_mail_template, 'loadFromPids' => $loadFromPids);
             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderPostCMSContent'] as $funcRef) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
             }
         }
         if ($page[0]['content']) {
             // loading the email confirmation letter eof
             // replacing the variables with dynamic values
             $array1 = array();
             $array2 = array();
             $array1[] = '###GENDER_SALUTATION###';
             $array2[] = mslib_fe::genderSalutation($order['billing_gender']);
             // full billing name
             $array1[] = '###BILLING_FULL_NAME###';
             $array2[] = $full_customer_name;
             $array1[] = '###FULL_NAME###';
             $array2[] = $full_customer_name;
             $array1[] = '###BILLING_NAME###';
             $array2[] = $order['billing_name'];
             $array1[] = '###BILLING_COMPANY###';
             $array2[] = $order['billing_company'];
             $array1[] = '###BILLING_FIRST_NAME###';
             $array2[] = $order['billing_first_name'];
             $array1[] = '###BILLING_LAST_NAME###';
             $array2[] = preg_replace('/\\s+/', ' ', $order['billing_middle_name'] . ' ' . $order['billing_last_name']);
             $array1[] = '###BILLING_EMAIL###';
             $array2[] = $order['billing_email'];
             $array1[] = '###BILLING_TELEPHONE###';
             $array2[] = $order['billing_telephone'];
             $array1[] = '###BILLING_MOBILE###';
             $array2[] = $order['billing_mobile'];
             // full delivery name
             $array1[] = '###DELIVERY_NAME###';
             $array2[] = $order['delivery_name'];
             $array1[] = '###DELIVERY_FULL_NAME###';
             $array2[] = $delivery_full_customer_name;
             $array1[] = '###DELIVERY_COMPANY###';
             $array2[] = $order['delivery_company'];
             $array1[] = '###DELIVERY_FIRST_NAME###';
             $array2[] = $order['delivery_first_name'];
             $array1[] = '###DELIVERY_LAST_NAME###';
             $array2[] = preg_replace('/\\s+/', ' ', $order['delivery_middle_name'] . ' ' . $order['delivery_last_name']);
             $array1[] = '###DELIVERY_EMAIL###';
             $array2[] = $order['delivery_email'];
             $array1[] = '###DELIVERY_TELEPHONE###';
             $array2[] = $order['delivery_telephone'];
             $array1[] = '###DELIVERY_MOBILE###';
             $array2[] = $order['delivery_mobile'];
             $array1[] = '###CUSTOMER_EMAIL###';
             $array2[] = $order['billing_email'];
             if ($order['cruser_id'] && is_numeric($order['cruser_id'])) {
                 $crUser = mslib_fe::getUser($order['cruser_id']);
                 $array1[] = '###CREATED_BY_FIRST_NAME###';
                 $array2[] = preg_replace('/\\s+/', ' ', $crUser['first_name']);
                 $array1[] = '###CREATED_BY_LAST_NAME###';
                 $array2[] = preg_replace('/\\s+/', ' ', $crUser['middle_name'] . ' ' . $crUser['last_name']);
                 $array1[] = '###CREATED_BY_FULL_NAME###';
                 $array2[] = preg_replace('/\\s+/', ' ', $crUser['first_name'] . ' ' . $crUser['middle_name'] . ' ' . $crUser['last_name']);
             } else {
                 $array1[] = '###CREATED_BY_FIRST_NAME###';
                 $array2[] = '';
                 $array1[] = '###CREATED_BY_LAST_NAME###';
                 $array2[] = '';
                 $array1[] = '###CREATED_BY_FULL_NAME###';
                 $array2[] = '';
             }
             $time = $order['crdate'];
             $long_date = strftime($this->pi_getLL('full_date_format'), $time);
             $array1[] = '###ORDER_DATE_LONG###';
             // ie woensdag 23 juni, 2010
             $array2[] = $long_date;
             $array1[] = '###ORDER_DATE###';
             // 21-12-2010 in localized format
             $array2[] = strftime("%x", $time);
             // backwards compatibility
             $array1[] = '###LONG_DATE###';
             // ie woensdag 23 juni, 2010
             $array2[] = $long_date;
             $time = time();
             $long_date = strftime($this->pi_getLL('full_date_format'), $time);
             $array1[] = '###CURRENT_DATE_LONG###';
             // ie woensdag 23 juni, 2010
             $array2[] = $long_date;
             $array1[] = '###STORE_NAME###';
             $array2[] = $this->ms['MODULES']['STORE_NAME'];
             $array1[] = '###TOTAL_AMOUNT###';
             $array2[] = mslib_fe::amount2Cents($order['total_amount']);
             $array1[] = '###PROPOSAL_NUMBER###';
             $array2[] = $order['orders_id'];
             $array1[] = '###ORDER_NUMBER###';
             $array2[] = $order['orders_id'];
             $array1[] = '###ORDER_LINK###';
             $array2[] = '';
             $array1[] = '###ORDER_STATUS###';
             $array2[] = $order['orders_status'];
             $array1[] = '###TRACK_AND_TRACE_CODE###';
             $array2[] = $order['track_and_trace_code'];
             $array1[] = '###BILLING_ADDRESS###';
             $array2[] = $billing_address;
             $array1[] = '###DELIVERY_ADDRESS###';
             $array2[] = $delivery_address;
             $array1[] = '###BILLING_STREET_NAME###';
             $array2[] = $order['billing_street_name'];
             $array1[] = '###BILLING_ADDRESS_NUMBER###';
             $array2[] = $order['billing_address_number'];
             $array1[] = '###BILLING_ADDRESS_EXT###';
             $array2[] = $order['billing_address_ext'];
             $array1[] = '###BILLING_ZIP###';
             $array2[] = $order['billing_zip'];
             $array1[] = '###BILLING_CITY###';
             $array2[] = $order['billing_city'];
             $array1[] = '###BILLING_COUNTRY###';
             $array2[] = mslib_fe::getTranslatedCountryNameByEnglishName($this->lang, $order['billing_country']);
             $array1[] = '###DELIVERY_STREET_NAME###';
             $array2[] = $order['delivery_street_name'];
             $array1[] = '###DELIVERY_ADDRESS_NUMBER###';
             $array2[] = $order['delivery_address_number'];
             $array1[] = '###DELIVERY_ADDRESS_EXT###';
             $array2[] = $order['delivery_address_ext'];
             $array1[] = '###DELIVERY_ZIP###';
             $array2[] = $order['delivery_zip'];
             $array1[] = '###DELIVERY_CITY###';
             $array2[] = $order['delivery_city'];
             $array1[] = '###DELIVERY_COUNTRY###';
             $array2[] = mslib_fe::getTranslatedCountryNameByEnglishName($this->lang, $order['delivery_country']);
             $array1[] = '###CUSTOMER_ID###';
             $array2[] = $order['customer_id'];
             $ORDER_DETAILS = self::printOrderDetailsTable($order, 'email');
             if ($this->ms['MODULES']['CREATE_INVOICE_DIRECTLY_AFTER_CREATING_ORDER']) {
                 // FORCE CREATE INVOICE IF NOT ALREADY EXISTING
                 $invoice = mslib_fe::getOrderInvoice($order['orders_id'], 1);
             } else {
                 $invoice = mslib_fe::getOrderInvoice($order['orders_id'], 0);
             }
             $invoice_id = '';
             $invoice_link = '';
             if (is_array($invoice)) {
                 $invoice_id = $invoice['invoice_id'];
                 $invoice_link = '<a href="' . $this->FULL_HTTP_URL . mslib_fe::typolink($this->shop_pid . ',2002', '&tx_multishop_pi1[page_section]=download_invoice&tx_multishop_pi1[hash]=' . $invoice['hash']) . '">' . $invoice['invoice_id'] . '</a>';
             }
             $array1[] = '###INVOICE_NUMBER###';
             $array2[] = $invoice_id;
             $array1[] = '###INVOICE_LINK###';
             $array2[] = $invoice_link;
             $array1[] = '###ORDER_DETAILS###';
             $array2[] = $ORDER_DETAILS;
             $array1[] = '###SHIPPING_METHOD###';
             $array2[] = $order['shipping_method_label'];
             $array1[] = '###PAYMENT_METHOD###';
             $array2[] = $order['payment_method_label'];
             $array1[] = '###EXPECTED_DELIVERY_DATE###';
             if ($order['expected_delivery_date'] > 0) {
                 $array2[] = strftime("%x", $order['expected_delivery_date']);
             } else {
                 $array2[] = '';
             }
             $array1[] = '###EXPECTED_DELIVERY_DATE_LONG###';
             if ($order['expected_delivery_date'] > 0) {
                 $array2[] = strftime($this->pi_getLL('full_date_format'), $order['expected_delivery_date']);
             } else {
                 $array2[] = '';
             }
             $array1[] = '###CUSTOMER_COMMENTS###';
             $array2[] = $order['customer_comments'];
             if ($order['customer_id'] > 0) {
                 $user = mslib_fe::getUser($order['customer_id']);
                 $array1[] = '###USERNAME###';
                 $array2[] = $user['username'];
                 if (isset($this->post['password']) && !empty($this->post['password']) && $order['customer_id'] > 0) {
                     $array1[] = '###PASSWORD###';
                     $array2[] = $this->post['password'];
                 }
             }
             //hook to let other plugins further manipulate the replacers
             if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderReplacersPostProc'])) {
                 $params = array('array1' => &$array1, 'array2' => &$array2, 'order' => &$order, 'mail_template' => $mail_template, 'loadFromPids' => $loadFromPids);
                 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderReplacersPostProc'] as $funcRef) {
                     \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
                 }
             }
             // Copy
             $pageCopyToMerchant = $page;
             if ($page[0]['content']) {
                 $page[0]['content'] = str_replace($array1, $array2, $page[0]['content']);
             }
             if ($page[0]['name']) {
                 $page[0]['name'] = str_replace($array1, $array2, $page[0]['name']);
             }
             // replacing the variables with dynamic values eof
             $user = array();
             $user['name'] = $full_customer_name;
             $user['email'] = $custom_email_address;
             //hook
             $send_mail = 1;
             $mail_attachment = array();
             $add_invoice_attachment_on_templates = array();
             $add_invoice_attachment_on_templates[] = 'email_order_paid_letter';
             if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrder'])) {
                 $params = array('this' => &$this, 'page' => &$page, 'content' => &$content, 'send_mail' => &$send_mail, 'user' => $user, 'order' => $order, 'order_details' => $ORDER_DETAILS, 'copy_to_merchant' => $copy_to_merchant, 'mail_attachment' => &$mail_attachment, 'loadFromPids' => $loadFromPids, 'add_invoice_attachment_on_templates' => &$add_invoice_attachment_on_templates);
                 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrder'] as $funcRef) {
                     \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
                 }
             }
             if ($send_mail) {
                 if ($user['email']) {
                     if (in_array($mail_template, $add_invoice_attachment_on_templates) && $this->ms['MODULES']['ATTACH_INVOICE_PDF_IN_PAID_LETTER_EMAIL'] > 0) {
                         $filterInvoice = array();
                         $filterInvoice[] = 'orders_id=' . $order['orders_id'];
                         $invoices = mslib_befe::getRecords('', 'tx_multishop_invoices', '', $filterInvoice, '', 'id desc');
                         $invoice = $invoices[0];
                         $pdfFileName = $invoice['invoice_id'] . '_' . $invoice['orders_id'] . '.pdf';
                         $pdfFilePath = $this->DOCUMENT_ROOT . 'uploads/tx_multishop/tmp/' . $pdfFileName;
                         // generate the invoice PDF
                         // Get Language code (ie nl, en, de)
                         $language_code = mslib_befe::getLanguageIso2ByLanguageUid($order['language_id']);
                         $language_code = strtolower($language_code);
                         // Download invoice in the language of the order
                         $invoice_data = mslib_fe::file_get_contents($this->FULL_HTTP_URL . mslib_fe::typolink($this->shop_pid . ',2002', 'tx_multishop_pi1[page_section]=download_invoice&tx_multishop_pi1[hash]=' . $invoice['hash'] . '&tx_multishop_pi1[forceRecreate]=1&language=' . $language_code));
                         file_put_contents($pdfFilePath, $invoice_data);
                         $mail_attachment[] = $pdfFilePath;
                     }
                     mslib_fe::mailUser($user, $page[0]['name'], $page[0]['content'], $this->ms['MODULES']['STORE_EMAIL'], $this->ms['MODULES']['STORE_NAME'], $mail_attachment);
                     // moved to cleaning up section
                     //if (strpos($mail_template, 'email_order_paid_letter')!==false && $this->ms['MODULES']['ATTACH_INVOICE_PDF_IN_PAID_LETTER_EMAIL']>0 && file_exists($pdfFilePath)) {
                     //	unlink($pdfFilePath);
                     //}
                 }
                 if ($copy_to_merchant) {
                     $mailSubject = '';
                     if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderToMerchant'])) {
                         $conf = array('this' => &$this, 'page' => &$page, 'content' => &$content, 'send_mail' => &$send_mail, 'user' => $user, 'order' => $order, 'order_details' => $ORDER_DETAILS, 'mail_attachment' => &$mail_attachment, 'mail_template' => $mail_template, 'psp_mail_template' => $psp_mail_template, 'loadFromPids' => $loadFromPids, 'mailSubject' => &$mailSubject, 'pageCopyToMerchant' => &$pageCopyToMerchant, 'array1' => &$array1, 'array2' => &$array2);
                         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_fe.php']['mailOrderToMerchant'] as $funcRef) {
                             \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $conf, $this);
                         }
                     }
                     if ($pageCopyToMerchant[0]['content']) {
                         $pageCopyToMerchant[0]['content'] = str_replace($array1, $array2, $pageCopyToMerchant[0]['content']);
                     }
                     if ($pageCopyToMerchant[0]['name']) {
                         $pageCopyToMerchant[0]['name'] = str_replace($array1, $array2, $pageCopyToMerchant[0]['name']);
                     }
                     if ($mailSubject == '') {
                         $mailSubject = $this->pi_getLL('copy_for_merchant') . ': ' . $pageCopyToMerchant[0]['name'];
                     }
                     // now mail a copy to the merchant
                     $merchant = array();
                     $merchant['name'] = $this->ms['MODULES']['STORE_NAME'];
                     $merchant['email'] = $this->ms['MODULES']['STORE_EMAIL'];
                     mslib_fe::mailUser($merchant, $mailSubject, $pageCopyToMerchant[0]['content'], $this->ms['MODULES']['STORE_EMAIL'], $this->ms['MODULES']['STORE_NAME'], $mail_attachment);
                     if ($this->ms['MODULES']['SEND_ORDER_CONFIRMATION_LETTER_ALSO_TO']) {
                         $email = array();
                         if (!strstr($this->ms['MODULES']['SEND_ORDER_CONFIRMATION_LETTER_ALSO_TO'], ",")) {
                             $email[] = $this->ms['MODULES']['SEND_ORDER_CONFIRMATION_LETTER_ALSO_TO'];
                         } else {
                             $email = explode(',', $this->ms['MODULES']['SEND_ORDER_CONFIRMATION_LETTER_ALSO_TO']);
                         }
                         if (count($email)) {
                             foreach ($email as $item) {
                                 $merchant = array();
                                 $merchant['name'] = $this->ms['MODULES']['STORE_NAME'];
                                 $merchant['email'] = $item;
                                 mslib_fe::mailUser($merchant, $mailSubject, $pageCopyToMerchant[0]['content'], $this->ms['MODULES']['STORE_EMAIL'], $this->ms['MODULES']['STORE_NAME'], $mail_attachment);
                             }
                         }
                     }
                 }
                 // cleaning up the temporary attachment files
                 if (is_array($mail_attachment) && count($mail_attachment)) {
                     foreach ($mail_attachment as $filepath) {
                         if (strpos($filepath, 'tx_multishop/tmp') !== false) {
                             if (file_exists($filepath)) {
                                 @unlink($filepath);
                             }
                         }
                     }
                 }
             }
         }
         if (isset($order['language_id'])) {
             // Switch back to default language
             mslib_befe::resetSystemLanguage();
         }
         return 1;
     }
 }
 }
 if ($this->get['format'] == 'excel') {
     $excelRows[] = $excelHeaderCols;
 } else {
     $excelRows[] = implode($post_data['delimeter_type'], $excelHeaderCols);
 }
 foreach ($records as $row) {
     $excelCols = array();
     $total = count($fields);
     $count = 0;
     foreach ($fields as $counter => $field) {
         $count++;
         $tmpcontent = '';
         switch ($field) {
             case 'orders_id':
                 $orders_record = mslib_befe::getRecords($row['uid'], 'tx_multishop_orders', 'customer_id', array(), '', 'orders_id asc');
                 $order_id_rec = array();
                 if (is_array($orders_record) && count($orders_record)) {
                     foreach ($orders_record as $order) {
                         $order_id_rec[] = $order['orders_id'];
                     }
                 }
                 if ($this->get['format'] == 'excel') {
                     $excelCols[] = implode(',', $order_id_rec);
                 } else {
                     $excelCols[] = '"' . implode(',', $order_id_rec) . '"';
                 }
                 break;
             case 'customer_id':
                 $excelCols[] = $row['uid'];
                 break;
     if ($dbFilename) {
         $folder = mslib_befe::getImagePrefixFolder($dbFilename);
         $newFilename = mslib_befe::resizeProductImage($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . '/' . $dbFilename, $dbFilename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath('multishop'), 1);
         if ($newFilename) {
             $content .= $newFilename . '<BR>';
             if ($newFilename != $dbFilename) {
                 //if ($this->ms['MODULES']['ADMIN_AUTO_CONVERT_UPLOADED_IMAGES_TO_PNG'] && $newFilename!=$dbFilename) {
                 // FILE IS ALSO CONVERTED. LETS UPDATE THE DATABASE
                 $content .= '<i>(' . $dbFilename . ' has been converted to: ' . $newFilename . ')</i><br/>';
                 $updateArray[$col] = $newFilename;
             }
         }
     }
 }
 if ($this->ms['MODULES']['ADMIN_CROP_PRODUCT_IMAGES']) {
     $crop_images_data = mslib_befe::getRecords($item['products_id'], 'tx_multishop_product_crop_image_coordinate', 'products_id');
     if (is_array($crop_images_data) && count($crop_images_data)) {
         foreach ($crop_images_data as $crop_image_data) {
             $src_image_size = $crop_image_data['image_size'] == 'enlarged' ? 'normal' : $crop_image_data['image_size'];
             $src = $this->DOCUMENT_ROOT . mslib_befe::getImagePath($crop_image_data['image_filename'], 'products', $src_image_size);
             $src_original = $this->DOCUMENT_ROOT . mslib_befe::getImagePath($crop_image_data['image_filename'], 'products', 'original');
             // backup original
             copy($src, $src . '-ori-' . $image_size);
             mslib_befe::cropImage($src, $src_original, $crop_image_data['image_size'], $crop_image_data['coordinate_x'], $crop_image_data['coordinate_y'], $crop_image_data['coordinate_w'], $crop_image_data['coordinate_h'], 'products');
         }
     }
 }
 if (count($updateArray)) {
     $query = $GLOBALS['TYPO3_DB']->UPDATEquery('tx_multishop_products', 'products_id=\'' . $item['products_id'] . '\'', $updateArray);
     $res = $GLOBALS['TYPO3_DB']->sql_query($query);
     if ($this->ms['MODULES']['FLAT_DATABASE']) {
$customer_groups_input .= '<select id="groups" class="invoice_select2" name="usergroup">' . "\n";
$customer_groups_input .= '<option value="0">' . $this->pi_getLL('all') . '</option>' . "\n";
if (is_array($groups) and count($groups)) {
    foreach ($groups as $group) {
        $customer_groups_input .= '<option value="' . $group['uid'] . '"' . ($this->get['usergroup'] == $group['uid'] ? ' selected="selected"' : '') . '>' . $group['title'] . '</option>' . "\n";
    }
}
$customer_groups_input .= '</select>' . "\n";
$searchCharNav = '<div id="msAdminSearchByCharNav" class="no-mb"><ul class="pagination">';
$chars = array();
$chars = array('0-9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '#', 'all');
foreach ($chars as $char) {
    $searchCharNav .= '<li><a href="' . mslib_fe::typolink($this->shop_pid . ',2003', 'tx_multishop_pi1[searchByChar]=' . $char . '&tx_multishop_pi1[page_section]=admin_customers') . '">' . mslib_befe::strtoupper($char) . '</a></li>';
}
$searchCharNav .= '</ul></div>';
$user_countries = mslib_befe::getRecords('', 'fe_users f', '', array(), 'f.country', 'f.country asc');
$fe_user_country = array();
foreach ($user_countries as $user_country) {
    if (!empty($user_country['country'])) {
        $cn_localized_name = htmlspecialchars(mslib_fe::getTranslatedCountryNameByEnglishName($this->lang, $user_country['country']));
        $fe_user_country[$cn_localized_name] = $fe_user_countries[] = '<option value="' . mslib_befe::strtolower($user_country['country']) . '" ' . (mslib_befe::strtolower($this->get['country']) == mslib_befe::strtolower($user_country['country']) ? 'selected' : '') . '>' . $cn_localized_name . '</option>';
    }
}
ksort($fe_user_country);
$user_countries_sb = '<select class="invoice_select2" name="country" id="country""><option value="">' . $this->pi_getLL('all') . '</option>' . implode("\n", $fe_user_country) . '</select>';
$formTopSearch = '
<form id="form1" name="form1" method="get" action="index.php">
<div class="panel panel-default no-mb">
    <div class="panel-heading">
            <div class="form-inline form-collapse">
                <div class="input-group">
								</div>
							</div>
							<div class="col-md-5">
								<div class="row">
								<label class="control-label col-md-7">' . $this->pi_getLL('order_date') . '</label><div class="col-md-5"><p class="form-control-static">' . $order_date . '</p></div>
								</div>
							</div>
						</div>
					</div>
				</div>
            ';
            if ($this->ms['MODULES']['ADMIN_INVOICE_MODULE']) {
                $filter = array();
                $filter[] = 'orders_id=' . $orders['orders_id'];
                //$filter[]='deleted=0';
                $invoices = mslib_befe::getRecords('', 'tx_multishop_invoices', '', $filter, '', 'id desc');
                $invoiceArray = array();
                if (count($invoices)) {
                    foreach ($invoices as $invoice) {
                        $link = mslib_fe::typolink($this->shop_pid . ',2002', 'tx_multishop_pi1[page_section]=download_invoice&tx_multishop_pi1[hash]=' . $invoice['hash']);
                        $invoiceArray[] = '<a href="' . $link . '" target="_blank" rel="nofollow">' . $invoice['invoice_id'] . '</a>';
                    }
                }
                if (count($invoiceArray)) {
                    $orderDetails[] = '
					<div class="form-group">
						<label class="control-label col-md-3">' . $this->pi_getLL('admin_invoice_number') . '</label>
						<div class="col-md-9">
							<div class="row">
								<div class="col-md-12">
									<div class="row">