function easyshop_sendalert($product_id, $newstock, $minimum_level, $alert_type)
 {
     // Determine admin e-mail address from e107 preferences
     global $pref;
     $to_email = !(isset($pref['siteadminemail']) && strlen($pref['siteadminemail']) == 0) ? $pref['replyto_email'] : $pref['siteadminemail'];
     // Keep 0.7.8 compatible
     // Retrieve product data
     $product_id = intval($product_id);
     $sql = new db();
     $sql->db_Select(DB_TABLE_SHOP_ITEMS, "*", "item_id={$product_id}");
     if ($row = $sql->db_Fetch()) {
         // Set subject and message for each alert type
         if ($alert_type == "1") {
             // Alert 1: stock is below minimum level of this product
             $subject = EASYSHOP_CLASS_06 . " " . $row['item_name'];
             $message = EASYSHOP_CLASS_08 . " <a href='" . SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $product_id . "'>" . $row['item_name'] . "</a>!<br /><br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_09 . ": {$minimum_level}<br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_10 . ": {$newstock}";
         }
         if ($alert_type == "2") {
             // Alert 2: last buyer purchased more of this product than actual in stock
             $subject = EASYSHOP_CLASS_07 . " " . $row['item_name'];
             $message = EASYSHOP_CLASS_11 . " <a href='" . SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $product_id . "'>" . $row['item_name'] . "</a>!<br /><br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_09 . ": {$minimum_level}<br />\r\n\t\t\t\t\t" . EASYSHOP_CLASS_10 . ": {$newstock}";
         }
         if ($alert_type == "3") {
             // Alert 3: product is out of stock
             $subject = EASYSHOP_CLASS_12 . " " . $row['item_name'];
             $message = EASYSHOP_CLASS_13 . " <a href='" . SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $product_id . "'>" . $row['item_name'] . "</a>!<br />";
         }
         // Send alert
         ShopMail::easyshop_sendemail($to_email, $subject, $message, $header, $attachment_name);
     }
 }
Exemple #2
0
/**
 * Cloudrexx
 *
 * @link      http://www.cloudrexx.com
 * @copyright Cloudrexx AG 2007-2015
 *
 * According to our dual licensing model, this program can be used either
 * under the terms of the GNU Affero General Public License, version 3,
 * or under a proprietary license.
 *
 * The texts of the GNU Affero General Public License with an additional
 * permission and of our proprietary license can be found at and
 * in the LICENSE file you have received along with this program.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * "Cloudrexx" is a registered trademark of Cloudrexx AG.
 * The licensing of the program under the AGPLv3 does not imply a
 * trademark license. Therefore any rights, title and interest in
 * our trademarks remain entirely with us.
 */
function _shopUpdate()
{
    global $objDatabase, $_ARRAYLANG, $objUpdate;
    if (!defined('MODULE_INDEX')) {
        define('MODULE_INDEX', '');
    }
    try {
        $table_name = DBPREFIX . 'module_shop_config';
        // Mind that this table does no longer exist from version 3
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            // Shop settings
            // Shop thumbnail default settings: shop_thumbnail_max_width
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE name='shop_thumbnail_max_width'";
            $objResult = $objDatabase->Execute($query);
            if ($objResult) {
                if ($objResult->RecordCount() == 0) {
                    $query = "\n                        INSERT INTO `{$table_name}` (\n                            name, value\n                        ) VALUES (\n                            'shop_thumbnail_max_width', '120'\n                        )";
                    $objResult = $objDatabase->Execute($query);
                    if ($objResult) {
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            // Shop thumbnail default settings: shop_thumbnail_max_height
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE name='shop_thumbnail_max_height'";
            $objResult = $objDatabase->Execute($query);
            if ($objResult) {
                if ($objResult->RecordCount() == 0) {
                    $query = "\n                        INSERT INTO `{$table_name}` (\n                            name, value\n                        ) VALUES (\n                            'shop_thumbnail_max_height', '90'\n                        )";
                    $objResult = $objDatabase->Execute($query);
                    if ($objResult) {
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            // Shop thumbnail default settings: shop_thumbnail_quality
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE name='shop_thumbnail_quality'";
            $objResult = $objDatabase->Execute($query);
            if ($objResult) {
                if ($objResult->RecordCount() == 0) {
                    $query = "\n                        INSERT INTO `{$table_name}` (\n                            name, value\n                        ) VALUES (\n                            'shop_thumbnail_quality', '80'\n                        )";
                    $objResult = $objDatabase->Execute($query);
                    if ($objResult) {
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            // Add Yellowpay payment methods default settings:
            // Accepted payment methods
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE name='yellowpay_accepted_payment_methods'";
            $objResult = $objDatabase->Execute($query);
            if ($objResult) {
                if ($objResult->RecordCount() == 0) {
                    $query = "\n                        INSERT INTO `{$table_name}` (\n                            `id`, `name`, `value`, `status`\n                        ) VALUES (\n                            NULL, 'yellowpay_accepted_payment_methods', '', '1'\n                        )";
                    $objResult = $objDatabase->Execute($query);
                    if ($objResult) {
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            // Change old yellowpay_delivery_payment_type setting
            // to new yellowpay_authorization_type
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE `name`='yellowpay_delivery_payment_type'";
            $objResult = $objDatabase->Execute($query);
            if ($objResult) {
                if ($objResult->RecordCount() == 1) {
                    $query = "\n                        UPDATE `{$table_name}`\n                           SET `name`='yellowpay_authorization_type'\n                         WHERE `name`='yellowpay_delivery_payment_type'";
                    $objResult = $objDatabase->Execute($query);
                    if ($objResult) {
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            // Add yellowpay test server flag setting
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE `name`='yellowpay_use_testserver'";
            $objResult = $objDatabase->Execute($query);
            if ($objResult) {
                if ($objResult->RecordCount() == 0) {
                    $query = "\n                        INSERT INTO `{$table_name}` (\n                            `id`, `name`, `value`, `status`\n                        ) VALUES (\n                            NULL, 'yellowpay_use_testserver', '1', '1'\n                        )";
                    $objResult = $objDatabase->Execute($query);
                    if ($objResult) {
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            // Add weight enable flag setting
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE `name`='shop_weight_enable'";
            $objResult = $objDatabase->Execute($query);
            if ($objResult) {
                if ($objResult->RecordCount() == 0) {
                    $query = "\n                        INSERT INTO `{$table_name}` (\n                            `id`, `name`, `value`, `status`\n                        ) VALUES (\n                            NULL, 'shop_weight_enable', '1', '1'\n                        )";
                    $objResult = $objDatabase->Execute($query);
                    if ($objResult) {
                    } else {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                }
            } else {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            // Add shop_show_products_default:
            // Which products are shown on the first shop page?
            $query = "\n                SELECT 1 FROM `{$table_name}`\n                WHERE `name`='shop_show_products_default'";
            $objResult = $objDatabase->Execute($query);
            if (!$objResult) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            if ($objResult->RecordCount() == 0) {
                $query = "\n                    INSERT INTO `{$table_name}` (\n                        `name`, `value`\n                    ) VALUES (\n                        'shop_show_products_default', '1'\n                    )";
                $objResult = $objDatabase->Execute($query);
                if (!$objResult) {
                    return _databaseError($query, $objDatabase->ErrorMsg());
                }
            }
            // Update VAT settings
            $query = "\n                SELECT `value` FROM `{$table_name}`\n                WHERE `name`='tax_enabled'";
            $objResult = $objDatabase->Execute($query);
            if (!$objResult) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            if ($objResult->RecordCount()) {
                $flagVatEnabled = $objResult->fields['value'];
                $arrVatEnabled = array('vat_enabled_foreign_customer', 'vat_enabled_foreign_reseller', 'vat_enabled_home_customer', 'vat_enabled_home_reseller');
                foreach ($arrVatEnabled as $strSetting) {
                    $query = "\n                        SELECT 1 FROM `{$table_name}`\n                        WHERE `name`='{$strSetting}'";
                    $objResult = $objDatabase->Execute($query);
                    if (!$objResult) {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                    if ($objResult->RecordCount() == 0) {
                        $query = "\n                            INSERT INTO `{$table_name}` (\n                                `name`, `value`\n                            ) VALUES (\n                                '{$strSetting}', '{$flagVatEnabled}'\n                            )";
                        $objResult = $objDatabase->Execute($query);
                        if (!$objResult) {
                            return _databaseError($query, $objDatabase->ErrorMsg());
                        }
                    }
                }
            }
            $query = "\n                SELECT `value` FROM `{$table_name}`\n                WHERE `name`='tax_included'";
            $objResult = $objDatabase->Execute($query);
            if (!$objResult) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            if ($objResult->RecordCount()) {
                $flagVatIncluded = $objResult->fields['value'];
                $arrVatIncluded = array('vat_included_foreign_customer', 'vat_included_foreign_reseller', 'vat_included_home_customer', 'vat_included_home_reseller');
                foreach ($arrVatIncluded as $strSetting) {
                    $query = "\n                        SELECT 1 FROM `{$table_name}`\n                        WHERE `name`='{$strSetting}'";
                    $objResult = $objDatabase->Execute($query);
                    if (!$objResult) {
                        return _databaseError($query, $objDatabase->ErrorMsg());
                    }
                    if ($objResult->RecordCount() == 0) {
                        $query = "\n                            INSERT INTO `{$table_name}` (\n                                `name`, `value`\n                            ) VALUES (\n                                '{$strSetting}', '{$flagVatIncluded}'\n                            )";
                        $objResult = $objDatabase->Execute($query);
                        if (!$objResult) {
                            return _databaseError($query, $objDatabase->ErrorMsg());
                        }
                    }
                }
            }
            $query = "\n                DELETE FROM `{$table_name}`\n                WHERE `name`='tax_enabled' OR `name`='tax_included'";
            $objResult = $objDatabase->Execute($query);
            if (!$objResult) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
        }
        // Update Attribute price to signed.
        // price_prefix is removed for version 3.  See Attribute::errorHandler()
        $table_name = DBPREFIX . 'module_shop_products_attributes_value';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'price_prefix') && Cx\Lib\UpdateUtil::table_exist(DBPREFIX . 'module_shop_order_items_attributes') && Cx\Lib\UpdateUtil::column_exist(DBPREFIX . 'module_shop_order_items_attributes', 'price_prefix')) {
            $query = "\n                UPDATE `{$table_name}`\n                   SET `price`=-`price`,\n                       `price_prefix`='+'\n                WHERE `price`>0\n                  AND `price_prefix`='-'";
            $objResult = $objDatabase->Execute($query);
            if (!$objResult) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            $query = "\n                UPDATE `" . DBPREFIX . "module_shop_order_items_attributes`\n                   SET `product_option_values_price`=-`product_option_values_price`\n                WHERE `product_option_values_price`>0\n                  AND `price_prefix`='-'";
            $objResult = $objDatabase->Execute($query);
            if (!$objResult) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
        }
        // Update tables' field types and indices
        $table_name = DBPREFIX . 'module_shop_article_group';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '', 'renamefrom' => 'name')));
        }
        $table_name = DBPREFIX . 'module_shop_customer_group';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '')));
        }
        $table_name = DBPREFIX . 'module_shop_discountgroup_count_name';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'unit' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '')));
        }
        $table_name = DBPREFIX . 'module_shop_discountgroup_count_rate';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('group_id' => array('type' => 'INT(10) UNSIGNED', 'notnull' => true, 'primary' => true, 'default' => 0), 'count' => array('type' => 'INT(10) UNSIGNED', 'notnull' => true, 'primary' => true, 'default' => '1'), 'rate' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => true, 'default' => '0.0')));
        }
        $table_name = DBPREFIX . 'module_shop_rel_discount_group';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('customer_group_id' => array('type' => 'INT(10) UNSIGNED', 'notnull' => true, 'primary' => true, 'default' => '0'), 'article_group_id' => array('type' => 'INT(10) UNSIGNED', 'notnull' => true, 'primary' => true, 'default' => '0'), 'rate' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.0')));
        }
        $table_name = DBPREFIX . 'module_shop_lsv';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'order_id'), 'order_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'holder' => array('type' => 'TINYTEXT'), 'bank' => array('type' => 'TINYTEXT'), 'blz' => array('type' => 'TINYTEXT')), array('order_id' => array('fields' => array('order_id'), 'type' => 'UNIQUE')));
        }
        $table_name = DBPREFIX . 'module_shop_shipment_cost';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'price_free')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'shipper_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'max_weight' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'cost' => array('type' => 'DECIMAL(10,2)', 'unsigned' => true, 'notnull' => false), 'price_free' => array('type' => 'DECIMAL(10,2)', 'unsigned' => true, 'notnull' => false)));
        }
        $table_name = DBPREFIX . 'module_shop_shipper';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name' => array('type' => 'TINYTEXT'), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        }
        // Note that countries are migrated to the core_countries table
        // for version 3, and this table is then dropped.
        // See Country::errorHandler()
        $table_name = DBPREFIX . 'module_shop_countries';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('countries_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'countries_name' => array('type' => 'VARCHAR(64)', 'notnull' => true, 'default' => ''), 'countries_iso_code_2' => array('type' => 'CHAR(2)', 'notnull' => true, 'default' => ''), 'countries_iso_code_3' => array('type' => 'CHAR(3)', 'notnull' => true, 'default' => ''), 'activation_status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1')), array('countries_name' => array('fields' => array('countries_name'))));
        }
        // Add Category description to old table version with "catid"
        // primary key only!  Fulltext indices are added when migrating
        // to core_text anyway, so don't bother with text fields here.
        $table_name = DBPREFIX . 'module_shop_categories';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'catid')) {
            Cx\Lib\UpdateUtil::table($table_name, array('catid' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'parentid' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'catname' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'catdesc' => array('type' => 'TEXT', 'notnull' => true, 'default' => ''), 'catsorting' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '100'), 'catstatus' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'picture' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'flags' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '')), array('flags' => array('fields' => array('flags'), 'type' => 'FULLTEXT')));
        }
        // Settings table fields -- this is supposed to exist; see above
        /*        $table_name = DBPREFIX.'module_shop_config';
                if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
                    Cx\Lib\UpdateUtil::table($table_name,
                        array(
                            'id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'primary' => true, 'auto_increment' => true),
                            'name' => array('type' => 'VARCHAR(64)', 'notnull' => true, 'default' => ''),
                            'value' => array('type' => 'VARCHAR(255)', 'notnull', 'default' => ''),
                            'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'),
                        )
                    );
                }*/
        $table_name = DBPREFIX . 'module_shop_currencies';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
            $query = "\n                UPDATE `{$table_name}`\n                SET sort_order = 0 WHERE sort_order IS NULL";
            Cx\Lib\UpdateUtil::sql($query);
            // Currencies table fields
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'code' => array('type' => 'CHAR(3)', 'notnull' => true, 'default' => ''), 'symbol' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'name' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''), 'rate' => array('type' => 'DECIMAL(10,4)', 'unsigned' => true, 'notnull' => true, 'default' => '1.0000'), 'sort_order' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'is_default' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        }
        // Note that this table is migrated to access_users for version 3,
        // then dropped.
        $table_name = DBPREFIX . 'module_shop_customers';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('customerid' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'username' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'password' => array('type' => 'VARCHAR(32)', 'notnull' => true, 'default' => ''), 'prefix' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''), 'company' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'firstname' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''), 'lastname' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'address' => array('type' => 'VARCHAR(40)', 'notnull' => true, 'default' => ''), 'city' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'zip' => array('type' => 'VARCHAR(10)', 'notnull' => false), 'country_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'phone' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'fax' => array('type' => 'VARCHAR(25)', 'notnull' => true, 'default' => ''), 'email' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'ccnumber' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'ccdate' => array('type' => 'VARCHAR(10)', 'notnull' => true, 'default' => ''), 'ccname' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'cvc_code' => array('type' => 'VARCHAR(5)', 'notnull' => true, 'default' => ''), 'company_note' => array('type' => 'TEXT', 'notnull' => true), 'is_reseller' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'register_date' => array('type' => 'DATETIME', 'notnull' => true, 'default' => '0000-00-00 00:00:00'), 'customer_status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'group_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false)));
        }
        $table_name = DBPREFIX . 'module_shop_importimg';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('img_id' => array('type' => 'INT(10) UNSIGNED', 'notnull' => true, 'primary' => true, 'auto_increment' => true), 'img_name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'img_cats' => array('type' => 'TEXT', 'notnull' => true, 'default' => ''), 'img_fields_file' => array('type' => 'TEXT', 'notnull' => true, 'default' => ''), 'img_fields_db' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => '')));
        }
        // Note that the following two tables are migrated to MailTemplate
        // for version 3, then dropped.
        $table_name = DBPREFIX . 'module_shop_mail';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'tplname' => array('type' => 'VARCHAR(60)', 'notnull' => true, 'default' => ''), 'protected' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        }
        $table_name = DBPREFIX . 'module_shop_mail_content';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'tpl_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'lang_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'from_mail' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'xsender' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'subject' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'message' => array('type' => 'TEXT', 'notnull' => true)));
        }
        // Note:  No changes necessary; the manufacturer table will be
        // completely modified in Manufacturer::errorHandler() below.
        /*        $table_name = DBPREFIX.'module_shop_manufacturer';
                if (   Cx\Lib\UpdateUtil::table_exist($table_name)
                    && Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
                    Cx\Lib\UpdateUtil::table($table_name,
                        DBPREFIX.'',
                        array(
                            'id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true),
                            'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''),
                            'url' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''),
                        )
                    );
                }*/
        $table_name = DBPREFIX . 'module_shop_order_items';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'order_items_id')) {
            Cx\Lib\UpdateUtil::table($table_name, array('order_items_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'orderid' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'productid' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'product_name' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'price' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'quantity' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'vat_percent' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => false), 'weight' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false)));
        }
        // Note: Removed field price_prefix for version 2.2; no changes since
        $table_name = DBPREFIX . 'module_shop_order_items_attributes';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'price_prefix')) {
            Cx\Lib\UpdateUtil::table($table_name, array('orders_items_attributes_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'order_items_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'order_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'product_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'product_option_name' => array('type' => 'VARCHAR(32)', 'notnull' => true, 'default' => ''), 'product_option_value' => array('type' => 'VARCHAR(32)', 'notnull' => true, 'default' => ''), 'product_option_values_price' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00')));
        }
        $table_name = DBPREFIX . 'module_shop_orders';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'orderid')) {
            Cx\Lib\UpdateUtil::table($table_name, array('orderid' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'customerid' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'selected_currency_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'order_sum' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'currency_order_sum' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'order_date' => array('type' => 'DATETIME', 'notnull' => true, 'default' => '0000-00-00 00:00:00'), 'order_status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'ship_prefix' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''), 'ship_company' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'ship_firstname' => array('type' => 'VARCHAR(40)', 'notnull' => true, 'default' => ''), 'ship_lastname' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'ship_address' => array('type' => 'VARCHAR(40)', 'notnull' => true, 'default' => ''), 'ship_city' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'ship_zip' => array('type' => 'VARCHAR(10)', 'notnull' => false), 'ship_country_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'ship_phone' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'tax_price' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'currency_ship_price' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'shipping_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'payment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'currency_payment_price' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'customer_ip' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => ''), 'customer_host' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'customer_lang' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'customer_browser' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'customer_note' => array('type' => 'TEXT'), 'last_modified' => array('type' => 'DATETIME', 'notnull' => true, 'default' => '0000-00-00 00:00:00'), 'modified_by' => array('type' => 'VARCHAR(50)', 'notnull' => true, 'default' => '')), array('order_status' => array('fields' => array('order_status'))));
        }
        $table_name = DBPREFIX . 'module_shop_payment';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name' => array('type' => 'VARCHAR(50)', 'notnull' => false), 'processor_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'costs' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'costs_free_sum' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'sort_order' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => false, 'default' => '0'), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => false, 'default' => '1')));
        }
        // Note:  No changes (still single language in version 3)
        $table_name = DBPREFIX . 'module_shop_payment_processors';
        Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'type' => array('type' => 'ENUM(\'internal\',\'external\')', 'notnull' => true, 'default' => 'internal'), 'name' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => ''), 'description' => array('type' => 'TEXT'), 'company_url' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => false, 'default' => '1'), 'picture' => array('type' => 'VARCHAR(100)', 'notnull' => true, 'default' => '')));
        Cx\Lib\UpdateUtil::sql('
            INSERT IGNORE INTO `' . DBPREFIX . 'module_shop_payment_processors` (`id`, `type`, `name`, `description`, `company_url`, `status`, `picture`)
            VALUES (12,"external","paymill_cc","","https://www.paymill.com",1,""),
                   (13,"external","paymill_elv","","https://www.paymill.com",1,""),
                   (14,"external","paymill_iban","","https://www.paymill.com",1,"")
        ');
        // Note:  No changes (still single language in version 3)
        $table_name = DBPREFIX . 'module_shop_pricelists';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name' => array('type' => 'VARCHAR(25)', 'notnull' => true, 'default' => ''), 'lang_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'border_on' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'header_on' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'header_left' => array('type' => 'TEXT', 'notnull' => false), 'header_right' => array('type' => 'TEXT', 'notnull' => false), 'footer_on' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'footer_left' => array('type' => 'TEXT', 'notnull' => false), 'footer_right' => array('type' => 'TEXT', 'notnull' => false), 'categories' => array('type' => 'TEXT')));
        }
        $table_name = DBPREFIX . 'module_shop_products';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'title')) {
            $query = "\n                UPDATE `{$table_name}`\n                   SET `description`=''\n                 WHERE `description` IS NULL";
            if ($objDatabase->Execute($query) == false) {
                return _databaseError($query, $objDatabase->ErrorMsg());
            }
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'product_id' => array('type' => 'VARCHAR(100)'), 'picture' => array('type' => 'TEXT'), 'title' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'catid' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'handler' => array('type' => 'ENUM(\'none\',\'delivery\',\'download\')', 'notnull' => true, 'default' => 'delivery'), 'normalprice' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'resellerprice' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'shortdesc' => array('type' => 'TEXT'), 'description' => array('type' => 'TEXT'), 'stock' => array('type' => 'INT(10)', 'notnull' => true, 'default' => '10'), 'stock_visibility' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'discountprice' => array('type' => 'DECIMAL(9,2)', 'notnull' => true, 'default' => '0.00'), 'is_special_offer' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'property1' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'default' => ''), 'property2' => array('type' => 'VARCHAR(100)', 'notnull' => false, 'default' => ''), 'status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'b2b' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'b2c' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1'), 'startdate' => array('type' => 'DATETIME', 'notnull' => true, 'default' => '0000-00-00 00:00:00'), 'enddate' => array('type' => 'DATETIME', 'notnull' => true, 'default' => '0000-00-00 00:00:00'), 'thumbnail_percent' => array('type' => 'TINYINT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'thumbnail_quality' => array('type' => 'TINYINT(2)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'manufacturer' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'manufacturer_url' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'external_link' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'sort_order' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'vat_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'weight' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'flags' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'usergroups' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'group_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'article_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false), 'keywords' => array('type' => 'TEXT')), array('group_id' => array('fields' => array('group_id')), 'article_id' => array('fields' => array('article_id')), 'shopindex' => array('fields' => array('title', 'description'), 'type' => 'FULLTEXT'), 'flags' => array('fields' => array('flags'), 'type' => 'FULLTEXT'), 'keywords' => array('fields' => array('keywords'), 'type' => 'FULLTEXT')));
        }
        // Note:  The following three tables are renamed for version 3.
        // See Attribute::errorHandler()
        $table_name = DBPREFIX . 'module_shop_products_attributes';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('attribute_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'product_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'attributes_name_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'attributes_value_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'sort_id' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        }
        $table_name = DBPREFIX . 'module_shop_products_attributes_name';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'display_type' => array('type' => 'TINYINT(3)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        }
        $table_name = DBPREFIX . 'module_shop_products_attributes_value';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'name_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'value' => array('type' => 'VARCHAR(255)', 'notnull' => true, 'default' => ''), 'price' => array('type' => 'DECIMAL(9,2)', 'notnull' => false, 'default' => '0.00')));
        }
        // Note:  Obsolete for a while already
        $table_name = DBPREFIX . 'module_shop_products_downloads';
        if (Cx\Lib\UpdateUtil::table_exist($table_name)) {
            Cx\Lib\UpdateUtil::drop_table($table_name);
        }
        // Note:  The id field is removed for version 3 from the following
        // three tables
        $table_name = DBPREFIX . 'module_shop_rel_countries';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'id')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'zones_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'countries_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        }
        $table_name = DBPREFIX . 'module_shop_rel_payment';
        Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'zones_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'payment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        Cx\Lib\UpdateUtil::sql('
            INSERT IGNORE INTO `' . DBPREFIX . 'module_shop_rel_payment` (`zones_id`, `payment_id`)
            VALUES (1,16),
                   (1,17),
                   (1,18)
        ');
        // Note: This is renamed to module_shop_rel_shipper for version 3.0
        $table_name = DBPREFIX . 'module_shop_rel_shipment';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'id')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'zones_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0'), 'shipment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0')));
        }
        $table_name = DBPREFIX . 'module_shop_vat';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'class')) {
            Cx\Lib\UpdateUtil::table($table_name, array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'class' => array('type' => 'TINYTEXT'), 'percent' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => true, 'default' => '0.00')));
        }
        $table_name = DBPREFIX . 'module_shop_zones';
        if (Cx\Lib\UpdateUtil::table_exist($table_name) && Cx\Lib\UpdateUtil::column_exist($table_name, 'zones_id')) {
            Cx\Lib\UpdateUtil::table($table_name, array('zones_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'zones_name' => array('type' => 'VARCHAR(64)', 'notnull' => true, 'default' => ''), 'activation_status' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1')));
        }
        // Contrexx 3.0.0 updates from here.
        // NOTE: All of these methods return false.
        Attribute::errorHandler();
        Coupon::errorHandler();
        // Prerequisites:
        //        ShopSettings::errorHandler();
        //ShopSettings::errorHandler(); // Called by Coupon::errorHandler();Customer::errorHandler();Order::errorHandler();ShopCategory::errorHandler();
        // Prerequisites:
        //        \Cx\Core\Setting\Controller\Setting::errorHandler();
        Currency::errorHandler();
        // Prerequisites:
        //        Text::errorHandler();
        //Text::errorHandler(); // Called by Currency::errorHandler();Product::errorHandler();Payment::errorHandler();ShopCategory::errorHandler();
        Product::errorHandler();
        // Prerequisites:
        //        Text::errorHandler();
        //        Discount::errorHandler(); // Called by Customer::errorHandler();
        //        Manufacturer::errorHandler();
        // Postrequisites:
        //        Customer::errorHandler();
        //Discount::errorHandler(); // Called by Customer::errorHandler();
        //Manufacturer::errorHandler(); // Called by Product::errorHandler();
        // Prerequisites:
        //        Text::errorHandler();
        //Customer::errorHandler(); // Called by Product::errorHandler();
        // Prerequisites:
        //        ShopSettings::errorHandler();
        //        Country::errorHandler(); // Called by Order::errorHandler();
        //        Order::errorHandler(); // Calls required Country::errorHandler();
        //        Discount::errorHandler(); // Called by Product::errorHandler();
        //Order::errorHandler(); // Called by Customer::errorHandler();
        // Prerequisites:
        //        ShopSettings::errorHandler();
        //        Country::errorHandler();
        ShopMail::errorHandler();
        // Prerequisites:
        //        MailTemplate::errorHandler();
        Payment::errorHandler();
        // Prerequisites:
        //        Text::errorHandler();
        //        Zones::errorHandler();
        //        Yellowpay::errorHandler();
        //Zones::errorHandler(); // Called by Payment::errorHandler();Shipment::errorHandler();
        // Prerequisites:
        //        Text::errorHandler();
        //Yellowpay::errorHandler(); // Called by Payment::errorHandler();
        // Prerequisites:
        //        \Cx\Core\Setting\Controller\Setting::errorHandler();
        PaymentProcessing::errorHandler();
        Shipment::errorHandler();
        // Prerequisites:
        //        Zones::errorHandler();
        // TODO: Check for and resolve recursion!
        ShopCategory::errorHandler();
        // Prerequisites:
        //        Text::errorHandler();
        //        ShopSettings::errorHandler();
        Vat::errorHandler();
        // Update page templates
        // Remove
        //        [[SHOP_JAVASCRIPT_CODE]]
        Cx\Lib\UpdateUtil::migrateContentPageUsingRegex(array('module' => 'shop'), '/{SHOP_JAVASCRIPT_CODE}[\\r\\n]*/', '', array('content'), '3.0.0');
        // Replace
        // In <!-- BEGIN subCategoriesRow -->...<!-- END subCategoriesRow -->
        //    [[SHOP_PRODUCT_DETAILLINK_IMAGE]] =>
        //    index.php?section=shop[[MODULE_INDEX]]&amp;catId=[[SHOP_CATEGORY_ID]]
        Cx\Lib\UpdateUtil::migrateContentPageUsingRegex(array('module' => 'shop'), '/(<!-- *BEGIN *subCategoriesRow *-->.+?)' . '{SHOP_PRODUCT_DETAILLINK_IMAGE}' . '(.+?<!-- *END *subCategoriesRow *-->)/s', '$1index.php?section=shop{MODULE_INDEX}&amp;catId={SHOP_CATEGORY_ID}$2', array('content'), '3.0.0');
        //    [[TXT_SEE_LARGE_PICTURE]] => [[TXT_SHOP_GO_TO_CATEGORY]]
        Cx\Lib\UpdateUtil::migrateContentPageUsingRegex(array('module' => 'shop'), '/(<!-- *BEGIN *subCategoriesRow *-->.+?)' . '{TXT_SEE_LARGE_PICTURE}' . '(.+?<!-- *END *subCategoriesRow *-->)/s', '$1{TXT_SHOP_GO_TO_CATEGORY}$2', array('content'), '3.0.0');
        //    [[SHOP_PRODUCT_...]] => [[SHOP_CATEGORY_...]]
        // There may be up to nine different such placeholders!
        $subject = NULL;
        Cx\Lib\UpdateUtil::migrateContentPageUsingRegexCallback(array('module' => 'shop'), '/(<!-- *BEGIN *subCategoriesRow *-->.+?)' . '{SHOP_PRODUCT_(.*?)}' . '(.+?<!-- *END *subCategoriesRow *-->)/s', function ($subject) {
            preg_replace('/{SHOP_PRODUCT_(.*?)}/', '{SHOP_CATEGORY_$1}', $subject);
        }, array('content'), '3.0.0');
        // shop/account
        // Needs to be replaced completely
        Cx\Lib\UpdateUtil::migrateContentPageUsingRegex(array('module' => 'shop', 'cmd' => 'account'), '/^.+$/s', <<<EOF
<div id="shop"><!-- BEGIN core_message -->
  <span class="{MESSAGE_CLASS}">{MESSAGE_TEXT}</span><!-- END core_message -->
  <div id="shop_acc_data">
    <form name="account" action="{SHOP_ACCOUNT_ACTION}" method="post"
          onsubmit="copy_address()" onreset="return shopReset()">
      <div class="customer_address">
        <h2>{TXT_CUSTOMER_ADDRESS}</h2>
        <div class="shop_text">
          <p><label>{TXT_COMPANY}</label>
            <input type="text" tabindex="1" name="company" value="{SHOP_ACCOUNT_COMPANY}" />
          </p>
          <p><label>{TXT_GREETING}<font color="#ff0000">&nbsp;*</font></label>
            <select tabindex="2" name="gender">{SHOP_ACCOUNT_PREFIX}</select>
          </p>
          <p><label>{TXT_SURNAME}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="3" name="lastname" value="{SHOP_ACCOUNT_LASTNAME}" />
          </p>
          <p><label>{TXT_FIRSTNAME}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="4" name="firstname" value="{SHOP_ACCOUNT_FIRSTNAME}" />
          </p>
          <p><label>{TXT_ADDRESS}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="5" name="address" value="{SHOP_ACCOUNT_ADDRESS}" />
          </p>
          <p><label>{TXT_POSTALE_CODE}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="6" name="zip" value="{SHOP_ACCOUNT_ZIP}" />
          </p>
          <p><label>{TXT_CITY}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="7" name="city" value="{SHOP_ACCOUNT_CITY}" />
          </p>
          <p><label>{TXT_COUNTRY}</label>
            <select name="countryId" id="countryId" tabindex="8">
            {SHOP_ACCOUNT_COUNTRY_MENUOPTIONS}
            </select>
          </p>
          <p><label>{TXT_PHONE_NUMBER}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="9" name="phone" value="{SHOP_ACCOUNT_PHONE}" />
          </p>
          <p><label>{TXT_FAX_NUMBER}</label>
            <input type="text" tabindex="10" name="fax" value="{SHOP_ACCOUNT_FAX}" />
          </p>
        </div>
      </div><!-- BEGIN shipping_address -->
      <div class="shipping_address">
        <h2>{TXT_SHIPPING_ADDRESS}</h2>
        <p><input type="checkbox" tabindex="21" value="1" onclick="copy_address();"
          id="equal_address" name="equal_address" {SHOP_EQUAL_ADDRESS_CHECKED} />
          <label class="description" for="equal_address">{TXT_SAME_BILLING_ADDRESS}</label>
        </p>
      </div>
      <div id="shipping_address" style="display: {SHOP_EQUAL_ADDRESS_DISPLAY};">
        <div class="shop_text">
          <p><label>{TXT_COMPANY}</label>
            <input type="text" tabindex="31" name="company2" value="{SHOP_ACCOUNT_COMPANY2}" />
          </p>
          <p><label>{TXT_GREETING}<font color="#ff0000">&nbsp;*</font></label>
            <select tabindex="32" name="gender2">{SHOP_ACCOUNT_PREFIX2}</select>
          </p>
          <p><label>{TXT_SURNAME}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="33" name="lastname2" value="{SHOP_ACCOUNT_LASTNAME2}" />
          </p>
          <p><label>{TXT_FIRSTNAME}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="34" name="firstname2" value="{SHOP_ACCOUNT_FIRSTNAME2}" />
          </p>
          <p><label>{TXT_ADDRESS}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="35" name="address2" value="{SHOP_ACCOUNT_ADDRESS2}" />
          </p>
          <p><label>{TXT_POSTALE_CODE}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="36" name="zip2" value="{SHOP_ACCOUNT_ZIP2}" size="6" />
          </p>
          <p><label>{TXT_CITY}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="37" name="city2" value="{SHOP_ACCOUNT_CITY2}" />
          </p>
          <p><label>{TXT_COUNTRY}</label>
            <input type="hidden" name="countryId2" id="countryId2" value="{SHOP_ACCOUNT_COUNTRY2_ID}" />{SHOP_ACCOUNT_COUNTRY2}
          </p>
          <p><label>{TXT_PHONE_NUMBER}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="38" name="phone2" value="{SHOP_ACCOUNT_PHONE2}" />
          </p>
        </div>
      </div><!-- END shipping_address --><!-- BEGIN account_details -->
      <div class="account_details">
        <h2>{TXT_YOUR_ACCOUNT_DETAILS}</h2><!-- BEGIN dont_register -->
        <p>
          <input type="checkbox" tabindex="61" value="1" id="dont_register"
                 name="dont_register" {SHOP_DONT_REGISTER_CHECKED}
                 onClick="document.getElementById('account_password').style.display = (this.checked ? 'none' : 'block');" />
          <label class="description" for="dont_register">{TXT_SHOP_ACCOUNT_DONT_REGISTER}</label>
          <br />
          {TXT_SHOP_ACCOUNT_DONT_REGISTER_NOTE}
        </p><!-- END dont_register -->
        <div class="shop_text">
          <p>
            <label>{TXT_EMAIL}<font color="#ff0000">&nbsp;*</font></label>
            <input type="text" tabindex="51" name="email" value="{SHOP_ACCOUNT_EMAIL}" />
          </p>
          <div id="account_password" style="{SHOP_ACCOUNT_PASSWORD_DISPLAY};">
            <p>
              <label>{TXT_PASSWORD}<font color="#ff0000">&nbsp;*</font></label>
              <input type="password" tabindex="52" name="password" value="" />
            </p>
            <p>{TXT_SHOP_ACCOUNT_PASSWORD_HINT}</p>
          </div>
        </div>
      </div><!-- END account_details -->
      <p>
        <input type="reset" value="{TXT_RESET}" name="reset" tabindex="71" />
        <input type="submit" value="{TXT_SHOP_CONTINUE_ARROW}" name="bsubmit" tabindex="72" />
      </p>
    </form>
  </div>
</div>
<script type="text/javascript">//<![CDATA[
function copy_address() {
  with (document.account) {
    if (jQuery("#equal_address:checked").length) {
      gender2.value = gender.value;
      company2.value = company.value;
      lastname2.value = lastname.value;
      firstname2.value = firstname.value;
      address2.value = address.value;
      zip2.value = zip.value;
      city2.value = city.value;
      phone2.value = phone.value;
      countryId2.value = countryId.value;
      jQuery("#shipping_address").hide();
    } else {
      jQuery("#shipping_address").show();
// Optionally clear the shipment address
//      gender2.value = "";
//      company2.value = "";
//      lastname2.value = "";
//      firstname2.value = "";
//      address2.value = "";
//      zip2.value = "";
//      city2.value = "";
//      phone2.value = "";
    }
  }
}
jQuery(function () {
  jQuery(".customer_address").delegate("input", "blur", function() {
    if (jQuery("#equal_address:checked").length) {
      copy_address();
    }
  });
});
// Redisplay the shipping address after the reset button has been clicked
function shopReset()
{
  if (!confirm("{TXT_SHOP_FORM_RESET_CONFIRM}")) {
    return false;
  }
  jQuery("#shipping_address").show();
  return true;
}
copy_address();
//}></script>
EOF
, array('content'), '3.0.0');
        // shop/login
        // Needs to be replaced completely
        Cx\Lib\UpdateUtil::migrateContentPageUsingRegex(array('module' => 'shop', 'cmd' => 'login'), '/^.+$/s', <<<EOF
<div id="shop">
  <!-- BEGIN core_message -->
  <span class="{MESSAGE_CLASS}">{MESSAGE_TEXT}</span>
  <!-- END core_message -->
  <div class="customer_old">
    <form name="shop_login" action="index.php?section=login" method="post">
      <input name="redirect" type="hidden" value="{SHOP_LOGIN_REDIRECT}" />
      <h2>{TXT_SHOP_ACCOUNT_EXISTING_CUSTOMER}</h2>
      <p>
        <label for="username">{TXT_SHOP_EMAIL_ADDRESS}</label>
        <input type="text" maxlength="250" value="{SHOP_LOGIN_EMAIL}" id="username" name="USERNAME" />
      </p>
      <p>
        <label for="password">{TXT_SHOP_PASSWORD}</label>
        <input type="password" maxlength="50" id="password" name="PASSWORD" />
      </p>
      <p>
        <input type="submit" value="{TXT_SHOP_ACCOUNT_LOGIN}" name="login" />
      </p>
      <p>
        <a class="lostpw" href="index.php?section=login&amp;cmd=lostpw" title="{TXT_SHOP_ACCOUNT_LOST_PASSWORD}">
        {TXT_SHOP_ACCOUNT_LOST_PASSWORD}
        </a>
      </p>
    </form>
  </div>
  <div class="customer_new">
    <form name="shop_register" action="index.php?section=shop&amp;cmd=login" method="post">
      <h2>{TXT_SHOP_ACCOUNT_NEW_CUSTOMER}</h2>
      {TXT_SHOP_ACCOUNT_NOTE}<br />
      <br />
      <!-- BEGIN register -->
      <input type="submit" value="{TXT_SHOP_BUTTON_REGISTRATION}" name="baccount" />
      <!-- END register -->
      <!-- BEGIN dont_register -->
      <input type="submit" value="{TXT_SHOP_BUTTON_NO_REGISTRATION}" name="bnoaccount" />
      <!-- END dont_register -->
    </form>
  </div>
</div>
EOF
, array('content'), '3.0.0');
        // Note:  Other templates may contain new placeholders and/or blocks,
        // however, these need to be added manually for version 3.0.0 features
        // to work.
    } catch (Cx\Lib\UpdateException $e) {
        return Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    //update settingsDB for missing values
    if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.0.0')) {
        try {
            \Cx\Lib\UpdateUtil::sql('INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`)
                                    VALUES (\'shop\', \'orderitems_amount_min\', \'config\', \'text\', \'0\')');
        } catch (\Cx\Lib\UpdateException $e) {
            return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
        }
    }
    // add access id 4 for user groups which had access to 13 or 161
    if ($objUpdate->_isNewerVersion($_CONFIG['coreCmsVersion'], '3.1.0')) {
        try {
            $result = \Cx\Lib\UpdateUtil::sql("SELECT `group_id` FROM `" . DBPREFIX . "access_group_static_ids` WHERE access_id = 13 OR access_id = 161 GROUP BY `group_id`");
            if ($result !== false) {
                while (!$result->EOF) {
                    \Cx\Lib\UpdateUtil::sql("INSERT IGNORE INTO `" . DBPREFIX . "access_group_static_ids` (`access_id`, `group_id`)\n                                                VALUES (4, " . intval($result->fields['group_id']) . ")");
                    $result->MoveNext();
                }
            }
        } catch (\Cx\Lib\UpdateException $e) {
            return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
        }
    }
    try {
        // add some necessary buttons to the confirmation page
        // fix of http://bugs.contrexx.com/contrexx/ticket/2015
        Cx\Lib\UpdateUtil::migrateContentPageUsingRegexCallback(array('module' => 'shop', 'cmd' => 'confirm'), '/.*/s', function ($content) {
            $content .= '<a href="{NODE_SHOP_ACCOUNT}">{TXT_ORDER_BACK_TO_ACCOUNT}</a><br />
                             <a href="{NODE_SHOP_CART}">{TXT_ORDER_BACK_TO_CART}</a>';
        }, array('content'), '3.2.0');
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    try {
        $queries = array('INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","payment_lsv_active","config","text","1","",18)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","paymill_active","config","text","1","",3)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","paymill_live_private_key","config","text","","",0)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","paymill_live_public_key","config","text","","",0)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","paymill_live_public_key","config","text","","",0)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","paymill_test_private_key","config","text","","",2)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","paymill_test_public_key","config","text","","",16)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES ("shop","paymill_use_test_account","config","text","0","",15)', 'INSERT IGNORE INTO `' . DBPREFIX . 'core_setting` (`section`, `name`, `group`, `type`, `value`, `values`, `ord`) VALUES (\'shop\',\'orderitems_amount_min\',\'config\',\'text\',\'0\',\'\',0);');
        foreach ($queries as $query) {
            \Cx\Lib\UpdateUtil::sql($query);
        }
    } catch (\Cx\Lib\UpdateException $e) {
        return \Cx\Lib\UpdateUtil::DefaultActionHandler($e);
    }
    return true;
}
function update_stock($txn_id = NULL, $phpsessionid = NULL)
{
    global $pref;
    $sqlcheck = new db();
    $trans_array = transaction($phpsessionid, 0, 0, "Completed");
    $items_array = unserialize($trans_array['all_items']);
    $count = 1;
    $temp_array = "";
    while ($items_array["db_id_" . $count]) {
        if ($sqlcheck->db_Select("easyshop_items", "*", "item_id = '" . $items_array["db_id_" . $count] . "'")) {
            while ($row = $sqlcheck->db_Fetch()) {
                if ($row['item_track_stock'] == 2) {
                    // Is this a tracked stock item?
                    if ($row['item_instock'] >= $items_array["quantity" . $count]) {
                        $newstock = $row['item_instock'] - $items_array["quantity_" . $count];
                        if ($row['item_minimum'] == 0 || $row['item_minimum'] == NULL) {
                            // Minimum level is flexible, but with bottom-level 1.
                            $minimum_level = 1;
                        } else {
                            $minimum_level = $row['item_minimum'];
                        }
                        if ($newstock <= $minimum_level && $newstock != 0) {
                            // Minimum level is reached; send e-mail alert
                            ShopMail::easyshop_sendalert($row['item_id'], $newstock, $minimum_level, 1);
                            // Alert-type = 1
                        }
                        if ($newstock == 0) {
                            $sqlcheck->db_Update("easyshop_items", "item_instock = '" . $newstock . "', item_out_of_stock = '2'\r\n\t\t\t\t\t\t\t\t\tWHERE item_id = '" . $items_array["db_id_" . $count] . "'");
                            ShopMail::easyshop_sendalert($row['item_id'], $newstock, $minimum_level, 3);
                            // Alert-type = 3
                        } else {
                            $sqlcheck->db_Update("easyshop_items", "item_instock = '" . $newstock . "'\r\n\t\t\t\t\t\t\t\t\tWHERE item_id = '" . $items_array["db_id_" . $count] . "'");
                        }
                    } else {
                        // There is a problem; client has paid for more items than are in stock
                        // Raise out of stock flag and send email
                        $sqlcheck->db_Update("easyshop_items", "item_instock = '0', item_out_of_stock = '2'\r\n\t\t\t\t\t\t\t\t\tWHERE item_id = '" . $items_array["db_id_" . $count] . "'");
                        ShopMail::easyshop_sendalert($row['item_id'], $newstock, $minimum_level, 2);
                        // Alert-type = 2
                    }
                }
                if ($row['prod_promo_class'] != 255 && $row['prod_promo_class'] != 0 && $trans_array['ipn_user_id'] > 0) {
                    // Auto promotion of user
                    $sqlcheck2 = new db();
                    $sqlcheck3 = new db();
                    require_once e_HANDLER . 'userclass_class.php';
                    $promo_class_name = r_userclass_name($row['prod_promo_class']);
                    $sqlcheck2->db_Select("user", "*", "user_id='" . $trans_array['ipn_user_id'] . "'");
                    if ($row2 = $sqlcheck2->db_Fetch()) {
                        $user_name = $row2['user_name'];
                        $class_extant = explode(',', $row2['user_class']);
                        foreach ($class_extant as $key => $value) {
                            if (intval($value) == 0) {
                                unset($class_extant[$key]);
                            }
                        }
                        if ($row['prod_promo_class'] != 255 && $row['prod_promo_class'] != 0 && !in_array($row['prod_promo_class'], $class_extant)) {
                            $class_extant[] = $row['prod_promo_class'];
                        }
                        $new_array = array_unique($class_extant);
                        sort($new_array);
                        $class_list = implode(',', $new_array);
                        $sqlcheck3->db_Update("user", "user_class='" . $class_list . "' where user_id='" . $trans_array['ipn_user_id'] . "'");
                        $mailto = !(isset($pref['siteadminemail']) && strlen($pref['siteadminemail']) == 0) ? $pref['replyto_email'] : $pref['siteadminemail'];
                        // Keep 0.7.8 compatible
                        $subject = $pref['sitename'] . ": " . EASYSHOP_IPN_30;
                        // [USERNAME] upgraded to class [PROMOCLASS]
                        $subject = str_replace("[USERNAME]", $user_name, $subject);
                        $subject = str_replace("[PROMOCLASS]", $promo_class_name, $subject);
                        $message = EASYSHOP_IPN_31 . "<br /><br />";
                        $message .= EASYSHOP_IPN_32 . "<br /><br />";
                        $message .= EASYSHOP_IPN_33 . "<br />";
                        $message .= "<br />" . EASYSHOP_IPN_34 . " " . $pref['siteurl'];
                        $message .= "<br /><br />&copy; " . date("Y") . " EasyShop";
                        $message = str_replace("[USERNAME]", $row2['user_name'], $message);
                        $message = str_replace("[USERLINK]", SITEURL . "user.php?id." . $trans_array['ipn_user_id'], $message);
                        $message = str_replace("[PROMOCLASS]", r_userclass_name($row['prod_promo_class']), $message);
                        $message = str_replace("[TRANSACTIONID]", $trans_array['txn_id'], $message);
                        $message = str_replace("[PRODUCTPRICE]", $items_array["amount_" . $count], $message);
                        $message = str_replace("[PRODUCTQTY]", $items_array["quantity_" . $count], $message);
                        $message = str_replace("[CURRENCY]", $trans_array['mc_currency'], $message);
                        $message = str_replace("[GROSSAMOUNT]", $trans_array['mc_gross'], $message);
                        $message = str_replace("[PAYMENTDATE]", $trans_array['payment_date'], $message);
                        $message = str_replace("[PRODLINK]", SITEURL . e_PLUGIN . "easyshop/easyshop.php?prod." . $items_array["db_id_" . $count], $message);
                        $message = str_replace("[PRODUCTNAME]", $items_array["item_name_" . $count], $message);
                        $user_message = EASYSHOP_IPN_35;
                        $user_message .= "<br />" . EASYSHOP_IPN_36;
                        $user_message .= "<br />" . EASYSHOP_IPN_34 . " " . $pref['siteurl'];
                        $user_message .= "<br /><br />&copy; " . date("Y") . " EasyShop";
                        $user_message = str_replace("[PRODUCTNAME]", $items_array["item_name_" . $count], $user_message);
                        $user_message = str_replace("[PROMOCLASS]", r_userclass_name($row['prod_promo_class']), $user_message);
                        //ShopMail::easyshop_sendemail($mailto, $subject, $message, $headers2, $attachment_name);
                        if ($row2['user_class'] != $class_list) {
                            // Only send an e-mail if the user_class array actually changed
                            ShopMail::easyshop_sendemail($mailto, $subject, $message, $headers2, $attachment_name);
                            // Mail to admin
                            ShopMail::easyshop_sendemail($row2['user_email'], $subject, $user_message, $headers2, $attachment_name);
                            // Mail to user
                        }
                    }
                }
                $temp_array = array($row['item_id'] => array("item_name" => $items_array["item_name_" . $count], "db_id" => $row['item_id']));
            }
        } else {
            // This item does not exist!!!
            //$sqlcheck -> db_Close();
            return FALSE;
        }
        $count++;
    }
    // Send downloads
    $to_email = $trans_array['payer_email'];
    ShopMail::easyshop_senddownloads($temp_array, $to_email);
    //$sqlcheck -> db_Close();
    return TRUE;
}
Exemple #4
0
function MailOrder($unicode_character_before, $unicode_character_after, $pref_sitename, $sender_name, $sender_email, $to_name, $to_email, $print_special_instr, $special_instr_text, $to_id, $email_info_level, $to_address1, $to_address2, $to_zipcode, $to_city, $to_telephone, $to_mobile, $email_additional_text)
{
    //if(isset($_POST['email'])){
    $check = TRUE;
    if ($check) {
        if ($error) {
            $message .= "<div style='text-align:center'><b>" . EASYSHOP_SHOP_60 . " " . $error . "</b></div>";
        } else {
            $time_stamp = date('r', time());
            $address = $to_email;
            // Provide multiple To: addresses separated with comma
            $pre_subject = isset($pref_sitename) ? "[" : "";
            $post_subject = isset($pref_sitename) ? "]" : "";
            $subject = $pre_subject . $pref_sitename . $post_subject . " " . ($_SESSION['sc_total']['quotation'] == 2 ? EASYSHOP_SHOP_94 : EASYSHOP_SHOP_62) . " " . date("Y-m-d");
            $message = EASYSHOP_SHOP_58 . "&nbsp;" . $time_stamp . "&nbsp;" . ($_SESSION['sc_total']['quotation'] == 2 ? EASYSHOP_SHOP_95 : EASYSHOP_SHOP_59) . "<br />\n\t\t\t\t\t<div style='text-align:center;'>\n\t\t\t\t\t\t<table border='1' cellspacing='1'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_21 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_22 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_23 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_24 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_25 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_26 . "</td>\n\t\t\t\t\t\t\t<td class='tbox'>" . EASYSHOP_SHOP_27 . "</td>\n\t\t\t\t\t\t</tr>";
            // Fill the message with products from the basket
            $count_items = count($_SESSION['shopping_cart']);
            // Count number of different products in basket
            $sum_quantity = $_SESSION['sc_total']['items'];
            // Display cached sum of total quantity of items in basket
            $sum_shipping = $_SESSION['sc_total']['shipping'];
            // Display cached sum of shipping costs for 1st item
            $sum_shipping2 = $_SESSION['sc_total']['shipping2'];
            // Display cached sum of shipping costs for additional items (>1)
            $sum_handling = $_SESSION['sc_total']['handling'];
            // Display cached sum of handling costs
            $sum_shipping_handling = number_format($sum_shipping + $sum_shipping2 + $sum_handling, 2, '.', '');
            // Calculate total handling and shipping price
            $sum_price = number_format($_SESSION['sc_total']['sum'] + $sum_shipping_handling, 2, '.', '');
            // Display cached sum of total price of items in basket + shipping + handling costs
            $array = $_SESSION['shopping_cart'];
            // PayPal requires to pass multiple products in a sequence starting at 1; we do as well in the mail
            $cart_count = 1;
            // For each product in the shopping cart array write PayPal details
            foreach ($array as $id => $item) {
                $display_sku_number = $item['sku_number'];
                if ($item['sku_number'] == "") {
                    $display_sku_number = "&nbsp;";
                    // Force a space in the cell for proper border display
                }
                $message .= "\n\t\t\t\t\t\t  <tr>\n\t\t\t\t\t\t\t  <td class='tbox'>" . $display_sku_number . "</td>\n\t\t\t\t\t\t\t  <td class='tbox'>" . $item['item_name'] . "</td>\n\t\t\t\t\t\t\t  <td class='tbox'>" . $unicode_character_before . $item['item_price'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t\t  <td class='tbox'>" . $item['quantity'] . "</td>\n\t\t\t\t\t\t\t  <td class='tbox'>" . $unicode_character_before . $item['shipping'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t\t  <td class='tbox'>" . $unicode_character_before . $item['shipping2'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t\t  <td class='tbox'>" . $unicode_character_before . $item['handling'] . $unicode_character_after . "</td>\n\t\t\t\t\t\t  </tr>";
                $cart_count++;
            }
            $message .= "\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div style='text-align:left;'>\n\t\t\t\t\t<br />" . EASYSHOP_SHOP_16 . " " . $sum_quantity . "\n\t\t\t\t\t<br />" . EASYSHOP_SHOP_18 . " " . $unicode_character_before . $sum_price . $unicode_character_after . "\n\t\t\t\t\t\t";
            if ($sum_shipping_handling > 0) {
                $message .= "<br />" . EASYSHOP_SHOP_20 . " " . $unicode_character_before . $sum_shipping_handling . $unicode_character_after;
            }
            // Add special instructions
            if ($print_special_instr == '1') {
                $message .= "<br /><br />" . EASYSHOP_SHOP_82 . ":<br />{$special_instr_text}<br />";
            }
            // Add loggin in user info
            if (USER) {
                $message .= "<br /><br />" . EASYSHOP_SHOP_93 . ": <a href='" . SITEURL . "user.php?id." . $to_id . "'>" . USERNAME . "</a> (<a href='mailto:" . USEREMAIL . "'>" . USEREMAIL . "</a>)";
            }
            // Add extra address info
            if (($email_info_level == 1 || $email_info_level == 2) && !USER) {
                $message .= "<br /><br />{$to_name}<br />\n\t\t\t\t\t\t  {$to_address1}<br />\n\t\t\t\t\t\t  {$to_address2}<br />\n\t\t\t\t\t\t  {$to_zipcode}  {$to_city}<br />\n\t\t\t\t\t\t  " . EASYSHOP_SHOP_90 . ": {$to_telephone}\n\t\t\t\t\t\t  " . EASYSHOP_SHOP_91 . ": {$to_mobile}<br /><br />";
            }
            // Add extra admin info from seller
            if (strlen(trim($email_additional_text)) > 0) {
                $message .= "<br /><br />\n\t\t\t\t\t\t   {$email_additional_text}\n\t\t\t\t\t\t   <br /><br />";
            }
            $message .= "</div><br /><br /><div style='text-align:center;'>&copy; <a href='http://e107.webstartinternet.com/'>EasyShop</a></div>";
            if (!ShopMail::easyshop_sendemail($address, $subject, $message, $header)) {
                $message = EASYSHOP_SHOP_55;
                // Order e-mail failed
            } else {
                // Send also a copy to the shop owner
                //$address = $sender_name." <".$sender_email.">";
                $address = $sender_email;
                $message = EASYSHOP_SHOP_64 . " " . $to_name . " (<a href'" . $to_email . "'>" . $to_email . "</a>)<br /><br />" . $message;
                // Extra in admin mail: "Following mail has been send to"
                global $e107;
                $ip = $e107->getip();
                $message .= "<br />" . EASYSHOP_SHOP_81 . ": " . $ip;
                // Add 'Send from IP address' to mail message
                if (!ShopMail::easyshop_sendemail($address, $subject, $message, $header)) {
                    $message = EASYSHOP_SHOP_63;
                    // Order e-mail to admin failed
                } else {
                    $message = EASYSHOP_SHOP_56;
                    // Order e-mail succeeded
                    $mail_result = 1;
                }
            }
            // Send downloads
            ShopMail::easyshop_senddownloads($_SESSION['shopping_cart'], $to_email);
        }
    } else {
        $message = EASYSHOP_SHOP_57;
        // Please fill in all fields correctly
    }
    //}
    return array($message, $mail_result);
}
 /**
  * The mailtemplate settings view
  *
  * Stores MailTemplates posted from the {@see MailTemplate::edit()} view.
  * Deletes a MailTemplate on request from the
  * {@see MailTemplate::overview()} view.
  * Includes both the overview and the edit view, activates one depending
  * on the outcome of the call to {@see MailTemplate::storeFromPost()}
  * or the current active_tab.
  * @return  boolean               True on success, false otherwise
  */
 static function view_settings_mail()
 {
     global $_CORELANG;
     // TODO: TEMPORARY.  Remove when a proper update is available.
     $template = \Cx\Core\MailTemplate\Controller\MailTemplate::get('Shop', 'order_confirmation');
     //die(var_export($template, true));
     if (!$template) {
         ShopMail::errorHandler();
     }
     $result = true;
     $_REQUEST['active_tab'] = 1;
     if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'mailtemplate_edit') {
         $_REQUEST['active_tab'] = 2;
     }
     \Cx\Core\MailTemplate\Controller\MailTemplate::deleteTemplate('Shop');
     // If there is anything to be stored, and if that fails, return to
     // the edit view in order to save the posted form content
     $result_store = \Cx\Core\MailTemplate\Controller\MailTemplate::storeFromPost('Shop');
     if ($result_store === false) {
         $_REQUEST['active_tab'] = 2;
     }
     $objTemplate = null;
     $result &= \Cx\Core\Setting\Controller\Setting::show_external($objTemplate, $_CORELANG['TXT_CORE_MAILTEMPLATES'], \Cx\Core\MailTemplate\Controller\MailTemplate::overview('Shop', 'config', \Cx\Core\Setting\Controller\Setting::getValue('numof_mailtemplate_per_page_backend', 'Shop'))->get());
     $result &= \Cx\Core\Setting\Controller\Setting::show_external($objTemplate, empty($_REQUEST['key']) ? $_CORELANG['TXT_CORE_MAILTEMPLATE_ADD'] : $_CORELANG['TXT_CORE_MAILTEMPLATE_EDIT'], \Cx\Core\MailTemplate\Controller\MailTemplate::edit('Shop')->get());
     self::$objTemplate->addBlock('SHOP_SETTINGS_FILE', 'settings_block', $objTemplate->get());
     self::$objTemplate->touchBlock('settings_block');
     return $result;
 }