Exemple #1
1
 public static function apiUpdateOrder($order, $response)
 {
     if (!defined('ORDER_MANAGEMENT')) {
         define('ORDER_MANAGEMENT', true);
     }
     if (!empty($order['status'])) {
         $statuses = fn_get_statuses(STATUSES_ORDER, false, true);
         if (!isset($statuses[$order['status']])) {
             $response->addError('ERROR_OBJECT_UPDATE', str_replace('[object]', 'orders', __('twgadmin_wrong_api_object_data')));
         } else {
             fn_change_order_status($order['order_id'], $order['status']);
         }
     }
     $cart = array();
     fn_clear_cart($cart, true);
     $customer_auth = fn_fill_auth(array(), array(), false, 'C');
     fn_form_cart($order['order_id'], $cart, $customer_auth);
     $cart['order_id'] = $order['order_id'];
     // update only profile data
     $profile_data = fn_check_table_fields($order, 'user_profiles');
     $cart['user_data'] = fn_array_merge($cart['user_data'], $profile_data);
     $cart['user_data'] = fn_array_merge($cart['user_data'], $order);
     fn_calculate_cart_content($cart, $customer_auth, 'A', true, 'I');
     if (!empty($order['details'])) {
         db_query('UPDATE ?:orders SET details = ?s WHERE order_id = ?i', $order['details'], $order['order_id']);
     }
     if (!empty($order['notes'])) {
         $cart['notes'] = $order['notes'];
     }
     fn_update_payment_surcharge($cart, $customer_auth);
     list($order_id, $process_payment) = fn_place_order($cart, $customer_auth, 'save');
     return array($order_id, $process_payment);
 }
Exemple #2
0
        if (is_array($_REQUEST['delete'])) {
            foreach ($_REQUEST['delete'] as $k => $v) {
                db_query("DELETE FROM ?:countries WHERE code = ?s", $k);
                db_query("DELETE FROM ?:country_descriptions WHERE code = ?s", $k);
            }
        }
    }
    //
    // Adding new countries
    //
    if ($mode == 'add') {
        foreach ($_REQUEST['country_data_add'] as $key => $value) {
            if (!empty($value['code']) && !empty($_REQUEST['country_description_add'][$key]['country'])) {
                if (db_get_field("SELECT COUNT(*) FROM ?:countries WHERE code = ?s", $value['code'])) {
                    continue;
                }
                $_data = fn_check_table_fields($value, 'countries');
                db_query('INSERT INTO ?:countries ?e', $_data);
                unset($_data);
                $_data = fn_check_table_fields($_REQUEST['country_description_add'][$key], 'country_descriptions');
                $_data['code'] = $value['code'];
                foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
                    db_query("INSERT INTO ?:country_descriptions ?e", $_data);
                }
            }
        }
    }
    return array(CONTROLLER_STATUS_OK, "countries.manage");
}
$view->assign('countries', fn_get_countries(DESCR_SL, false, true));
/** /Body **/
 * @version    4.1.x
 * @license    http://www.alt-team.com/addons-license-agreement.html
 ****************************************************************************/
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if ($mode == 'likes') {
    if ($auth['user_id'] && isset($_REQUEST['post_id'])) {
        $data = array();
        $data['user_id'] = $auth['user_id'];
        $data['post_id'] = $_REQUEST['post_id'];
        $data['is_like'] = $_REQUEST['like'];
        $vote = db_get_field('SELECT is_like FROM ?:review_likes WHERE user_id=?i AND post_id=?i', $data['user_id'], $data['post_id']);
        if ($vote !== $data['is_like']) {
            $_data = fn_check_table_fields($data, 'review_likes');
            db_query('REPLACE INTO ?:review_likes ?e', $data);
            $title = $data['is_like'] ? __('you_like_this') : __('you_not_like_this');
            $msg = __('thanks_for_vote');
            fn_set_notification('N', $title, $msg);
        } else {
            fn_set_notification('E', __('error'), __('no_more_vote'), 'I');
        }
    }
    exit;
}
if ($mode == 'view_posts') {
    $posts = array();
    $object_id = $_REQUEST["object_id"];
    if ($object_id) {
        $object_type = $_REQUEST['object_type'];
Exemple #4
0
     }
     $suffix = ".update?selected_section=products&event_id={$_REQUEST['event_id']}";
 }
 // Add products to the event
 if ($mode == 'add_products') {
     foreach ($_REQUEST['product_data'] as $product_id => $data) {
         $data['item_id'] = fn_generate_cart_id($product_id, array("product_options" => @$data['product_options']), false);
         $existent_amount = db_get_field("SELECT amount FROM ?:giftreg_event_products WHERE item_id = ?i", $data['item_id']);
         if (!empty($data['product_options'])) {
             $data['extra'] = serialize($data['product_options']);
         }
         $data['product_id'] = $product_id;
         $data['event_id'] = $_REQUEST['event_id'];
         if (!empty($data['amount'])) {
             $data['amount'] += $existent_amount;
             $data = fn_check_table_fields($data, 'giftreg_event_products');
             db_query("REPLACE INTO ?:giftreg_event_products ?e", $data);
         }
     }
     $suffix = ".update?selected_section=products&event_id={$_REQUEST['event_id']}";
 }
 // Add new event
 if ($mode == 'add') {
     $event_data = $_REQUEST['event_data'];
     list($event_id, $access_key) = fn_update_event($event_data);
     $suffix = ".update?event_id={$event_id}";
     $suffix .= !empty($access_key) ? "&access_key={$access_key}" : '';
 }
 // Update the event
 if ($mode == 'update') {
     if (AREA == 'C' && !defined('EVENT_OWNER') && Registry::get('addons.gift_registry.event_creators') != 'all') {
Exemple #5
0
     }
 }
 // Check if post needs to be approved
 if (AREA != 'A' && !empty($discussion_settings[$object_name . '_post_approval'])) {
     if ($discussion_settings[$object_name . '_post_approval'] == 'any' || $discussion_settings[$object_name . '_post_approval'] == 'anonymous' && empty($auth['user_id'])) {
         fn_set_notification('W', fn_get_lang_var('text_thank_you_for_post'), fn_get_lang_var('text_post_pended'));
         $post_data['status'] = 'D';
     }
 }
 $_data = fn_check_table_fields($post_data, 'discussion_posts');
 $_data['timestamp'] = TIME;
 $_data['user_id'] = $auth['user_id'];
 $post_data['post_id'] = db_query("INSERT INTO ?:discussion_posts ?e", $_data);
 $_data = fn_check_table_fields($post_data, 'discussion_messages');
 db_query("REPLACE INTO ?:discussion_messages ?e", $_data);
 $_data = fn_check_table_fields($post_data, 'discussion_rating');
 db_query("REPLACE INTO ?:discussion_rating ?e", $_data);
 // For orders - set notification to admin or customer
 if ($object['object_type'] == 'O') {
     $email_to = AREA == 'A' ? db_get_field("SELECT email FROM ?:orders WHERE order_id = ?i", $object['object_id']) : Registry::get('settings.Company.company_orders_department');
     $email_from = AREA == 'A' ? Registry::get('settings.Company.company_orders_department') : db_get_field("SELECT email FROM ?:orders WHERE order_id = ?i", $object['object_id']);
     $view_mail->assign('url', fn_url("orders.details?order_id={$object['object_id']}", AREA == 'A' ? 'C' : 'A', 'http', '&'));
 } elseif (!empty($discussion_settings[$object_name . '_notification_email'])) {
     $email_to = $discussion_settings[$object_name . '_notification_email'];
     $email_from = Registry::get('settings.Company.company_site_administrator');
     $url = "discussion_manager.manage?object_type={$object['object_type']}&post_id={$post_data['post_id']}";
     $view_mail->assign('url', fn_url($url, 'A', 'http', '&'));
 }
 $view_mail->assign('object_data', $object_data);
 $view_mail->assign('post_data', $post_data);
 $view_mail->assign('object_name', $object_name);
function fn_report_table_clone($report_id, $table_id)
{
    //tables for report
    $table_data = db_get_row("SELECT a.*, b.description FROM ?:sales_reports_tables as a LEFT JOIN ?:sales_reports_table_descriptions as b ON a.table_id = b.table_id AND lang_code = ?s WHERE a.table_id = ?i", CART_LANGUAGE, $table_id);
    $data['report_id'] = $table_data['report_id'];
    $data['type'] = $table_data['type'];
    $table_id_new = db_query("INSERT INTO ?:sales_reports_tables ?e", $data);
    fn_create_description('sales_reports_table_descriptions', "table_id", $table_id_new, array("description" => $table_data["description"] . '[CLONE]'));
    //Orders element for table
    $_elements = db_get_array("SELECT a.* FROM ?:sales_reports_table_elements as a WHERE a.report_id = ?i AND a.table_id = ?i AND a.time_interval = 'N' ORDER BY a.position", $report_id, $table_id);
    foreach ($_elements as $k => $element) {
        $data = $element;
        $data['table_id'] = $table_id_new;
        $data['condition'] = db_get_fields("SELECT ids FROM ?:sales_reports_table_element_conditions WHERE table_id = ?i AND element_hash = ?s", $table_id, $element['element_hash']);
        $data['element_hash'] = fn_generate_element_hash($table_id_new, $data['element_id'], $data['condition']);
        $_data = fn_check_table_fields($data, 'sales_reports_table_elements');
        db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data);
        $_cond['table_id'] = $table_id_new;
        $_cond['element_hash'] = $data['element_hash'];
        foreach ($data['condition'] as $kk => $value) {
            $_cond['ids'] = $value;
            db_query("INSERT INTO ?:sales_reports_table_element_conditions ?e", $_cond);
        }
    }
    //Intervals for table
    $_intervals = db_get_array("SELECT a.*, b.description FROM ?:sales_reports_table_elements as a WHERE a.report_id = ?i AND a.table_id = ?i AND a.time_interval = 'Y'", $report_id, $table_id);
    foreach ($_intervals as $k => $interval) {
        $data = $interval;
        $data['table_id'] = $table_id_new;
        $_data = fn_check_table_fields($data, 'sales_reports_table_elements');
        db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data);
    }
    return $table_id;
}
Exemple #7
0
function fn_create_description($table_name, $id_name = '', $field_id = '', $data)
{
    if (empty($field_id) || empty($data) || empty($id_name)) {
        return false;
    }
    $_data = fn_check_table_fields($data, $table_name);
    $_data[$id_name] = $field_id;
    foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
        db_query("REPLACE INTO ?:{$table_name} ?e", $_data);
    }
    return true;
}
<?php

/*****************************************************************************
 * This is a commercial software, only users who have purchased a  valid
 * license and accepts the terms of the License Agreement can install and use  
 * this program.
 *----------------------------------------------------------------------------
 * @copyright  LCC Alt-team: http://www.alt-team.com
 * @module     "Alt-team: Extended reviews with attributes"
 * @version    4.1.x
 * @license    http://www.alt-team.com/addons-license-agreement.html
 ****************************************************************************/
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'update') {
        if (!empty($_REQUEST['posts']) && is_array($_REQUEST['posts'])) {
            foreach ($_REQUEST['posts'] as $p_id => $post) {
                if (!empty($post['attributes'])) {
                    foreach ($post['attributes'] as $attr_id => $rate) {
                        $_data['rating'] = $rate;
                        $_data['attr_id'] = $attr_id;
                        $_data['post_id'] = $p_id;
                        $_data = fn_check_table_fields($_data, 'review_rating');
                        db_query("REPLACE INTO ?:review_rating ?e", $_data);
                    }
                }
            }
        }
    }
}
Exemple #9
0
function fn_rma_recalculate_order($order_id, $recalculate_type, $return_id, $is_refund, $ex_data)
{
    if (empty($recalculate_type) || empty($return_id) || empty($order_id) || !is_array($ex_data) || $recalculate_type == 'R' && !isset($ex_data['shipping_costs']) || $recalculate_type == 'M' && !isset($ex_data['total'])) {
        return false;
    }
    $order = db_get_row("SELECT total, subtotal, discount, shipping_cost FROM ?:orders WHERE order_id = ?i", $order_id);
    $order_items = db_get_hash_array("SELECT * FROM ?:order_details WHERE ?:order_details.order_id = ?i", 'item_id', $order_id);
    $additional_data = db_get_hash_single_array("SELECT type, data FROM ?:order_data WHERE order_id = ?i", array('type', 'data'), $order_id);
    $order_return_info = @unserialize(@$additional_data[ORDER_DATA_RETURN]);
    $order_tax_info = @unserialize(@$additional_data['T']);
    if ($recalculate_type == 'R') {
        $shipping_info = @unserialize(@$additional_data['L']);
        if ($is_refund == 'Y') {
            $sign = $ex_data['inventory_to'] == 'I' ? -1 : 1;
            // What for is this section ???
            if (!empty($order_return_info['returned_products'])) {
                foreach ($order_return_info['returned_products'] as $item_id => $item) {
                    if (isset($item['extra']['returns'][$return_id])) {
                        $r_item = $o_item = $item;
                        unset($r_item['extra']['returns'][$return_id]);
                        $r_item['amount'] = $item['amount'] - $item['extra']['returns'][$return_id]['amount'];
                        fn_rma_recalculate_order_routine($order, $r_item, $item, 'O-', $ex_data);
                        if (empty($r_item['amount'])) {
                            unset($order_return_info['returned_products'][$item_id]);
                        } else {
                            $order_return_info['returned_products'][$item_id] = $r_item;
                        }
                        $o_item['primordial_amount'] = (isset($order_items[$item_id]) ? $order_items[$item_id]['amount'] : 0) + $item['extra']['returns'][$return_id]['amount'];
                        $o_item['primordial_discount'] = @$o_item['extra']['discount'];
                        fn_rma_recalculate_order_routine($order, $o_item, $item, 'M+');
                        $o_item['amount'] = (isset($order_items[$item_id]) ? $order_items[$item_id]['amount'] : 0) + $item['extra']['returns'][$return_id]['amount'];
                        if (isset($order_items[$item_id]['extra'])) {
                            $o_item['extra'] = @unserialize($order_items[$item_id]['extra']);
                        }
                        $o_item['extra']['returns'][$return_id] = $item['extra']['returns'][$return_id];
                        $o_item['extra'] = serialize($o_item['extra']);
                        $o_item = fn_check_table_fields($o_item, 'order_details');
                        if (!isset($order_items[$item_id])) {
                            db_query("REPLACE INTO ?:order_details ?e", $o_item);
                        } else {
                            db_query("UPDATE ?:order_details SET ?u WHERE item_id = ?i AND order_id = ?i", $o_item, $item_id, $order_id);
                        }
                    }
                }
            }
            // Check all the products and update their amount and cost.
            foreach ($order_items as $item_id => $item) {
                $item['extra'] = @unserialize($item['extra']);
                if (isset($item['extra']['returns'][$return_id])) {
                    $o_item = $item;
                    $o_item['amount'] = $o_item['amount'] + $sign * $item['extra']['returns'][$return_id]['amount'];
                    unset($o_item['extra']['returns'][$return_id]);
                    if (empty($o_item['extra']['returns'])) {
                        unset($o_item['extra']['returns']);
                    }
                    fn_rma_recalculate_order_routine($order, $o_item, $item);
                    if (empty($o_item['amount'])) {
                        db_query("DELETE FROM ?:order_details WHERE item_id = ?i AND order_id = ?i", $item_id, $order_id);
                    } else {
                        $o_item['extra'] = serialize($o_item['extra']);
                        $o_item = fn_check_table_fields($o_item, 'order_details');
                        db_query("UPDATE ?:order_details SET ?u WHERE item_id = ?i AND order_id = ?i", $o_item, $item_id, $order_id);
                    }
                    if (!isset($order_return_info['returned_products'][$item_id])) {
                        $r_item = $item;
                        unset($r_item['extra']['returns']);
                        $r_item['amount'] = $item['extra']['returns'][$return_id]['amount'];
                    } else {
                        $r_item = $order_return_info['returned_products'][$item_id];
                        $r_item['amount'] = $r_item['amount'] + $item['extra']['returns'][$return_id]['amount'];
                    }
                    fn_rma_recalculate_order_routine($order, $r_item, $item, 'M-O+', $ex_data);
                    $r_item['extra']['returns'][$return_id] = $item['extra']['returns'][$return_id];
                    $order_return_info['returned_products'][$item_id] = $r_item;
                    fn_rma_update_order_taxes($order_tax_info, $item_id, $item['amount'], $o_item['amount'], $order);
                }
            }
            $_ori_data = array('order_id' => $order_id, 'type' => ORDER_DATA_RETURN, 'data' => $order_return_info);
        }
        if ($shipping_info) {
            foreach ((array) $ex_data['shipping_costs'] as $shipping_id => $cost) {
                $_total = array_sum($shipping_info[$shipping_id]['rates']);
                foreach ($shipping_info[$shipping_id]['rates'] as $s_id => $rate) {
                    $shipping_info[$shipping_id]['rates'][$s_id] = fn_format_price($_total ? $rate / $_total * $cost : $cost / count($shipping_info[$shipping_id]['rates']));
                }
                // Correct cost FIXME
                if ($cost != ($new_total = array_sum($shipping_info[$shipping_id]['rates']))) {
                    $deviation = $new_total - $cost;
                    foreach ($shipping_info[$shipping_id]['rates'] as $s_id => $rate) {
                        $shipping_info[$shipping_id]['rates'][$s_id] = fn_format_price($rate + $deviation);
                        break;
                    }
                }
            }
            db_query("UPDATE ?:order_data SET ?u WHERE order_id = ?i AND type = 'L'", array('data' => serialize($shipping_info)), $order_id);
            fn_update_shipping_taxes($order_tax_info, $shipping_info, $order);
        }
        $order['total'] -= $order['shipping_cost'];
        $order['shipping_cost'] = array_sum($ex_data['shipping_costs']);
        $order['total'] += $order['shipping_cost'];
        if (!empty($order_tax_info)) {
            db_query("UPDATE ?:order_data SET ?u WHERE order_id = ?i AND type = 'T'", array('data' => serialize($order_tax_info)), $order_id);
        }
    } elseif ($recalculate_type == 'M') {
        $order['total'] = $order['total'] + $ex_data['total'];
        $_ori_data = array('order_id' => $order_id, 'type' => ORDER_DATA_RETURN, 'data' => array('return' => fn_format_price((isset($order_return_info['return']) ? $order_return_info['return'] : 0) - $ex_data['total']), 'returned_products' => isset($order_return_info['returned_products']) ? $order_return_info['returned_products'] : ''));
        $return_products = db_get_hash_array("SELECT * FROM ?:rma_return_products WHERE return_id = ?i AND type = ?s", 'item_id', $return_id, RETURN_PRODUCT_ACCEPTED);
        foreach ((array) $return_products as $item_id => $v) {
            $v['extra']['product_options'] = @unserialize($v['extra']['product_options']);
            if ($ex_data['inventory_to'] == 'D' || $ex_data['status_to'] == RMA_DEFAULT_STATUS) {
                fn_update_product_amount($v['product_id'], $v['amount'], @$v['extra']['product_options'], '-');
            } elseif ($ex_data['inventory_to'] == 'I') {
                fn_update_product_amount($v['product_id'], $v['amount'], $v['extra']['product_options'], '+');
            }
        }
    }
    if ($is_refund == 'Y') {
        if (isset($_ori_data['data']['return']) && floatval($_ori_data['data']['return']) == 0) {
            unset($_ori_data['data']['return']);
        }
        if (empty($_ori_data['data']['returned_products'])) {
            unset($_ori_data['data']['returned_products']);
        }
        if (!empty($_ori_data['data'])) {
            $_ori_data['data'] = serialize($_ori_data['data']);
            db_query("REPLACE INTO ?:order_data ?e", $_ori_data);
        } else {
            db_query("DELETE FROM ?:order_data WHERE order_id = ?i AND type = ?s", $order_id, ORDER_DATA_RETURN);
        }
    }
    foreach ($order as $k => $v) {
        $order[$k] = fn_format_price($v);
    }
    db_query("UPDATE ?:orders SET ?u WHERE order_id = ?i", $order, $order_id);
}
Exemple #10
0
     if (is_array($_REQUEST['add_fields_data'])) {
         fn_giftreg_add_fields($_REQUEST['add_fields_data']);
     }
     $suffix = ".field_editor";
 }
 // Update event fields
 if ($mode == 'update_fields') {
     if (@is_array($_REQUEST['fields_data'])) {
         foreach ($_REQUEST['fields_data'] as $field_id => $data) {
             $_data = fn_check_table_fields($data, 'giftreg_fields');
             db_query("UPDATE ?:giftreg_fields SET ?u WHERE field_id = ?i", $_data, $field_id);
             $_data = array('object_id' => $field_id, 'object_type' => 'F', 'description' => $data['description'], 'lang_code' => DESCR_SL);
             db_query("REPLACE INTO ?:giftreg_descriptions ?e", $_data);
             if (@is_array($data['variants'])) {
                 foreach ($data['variants'] as $variant_id => $vdata) {
                     $_data = fn_check_table_fields($vdata, 'giftreg_field_variants');
                     db_query("UPDATE ?:giftreg_field_variants SET ?u WHERE variant_id = ?i", $_data, $variant_id);
                     $_data = array('object_id' => $variant_id, 'object_type' => 'V', 'description' => $vdata['description'], 'lang_code' => DESCR_SL);
                     db_query("REPLACE INTO ?:giftreg_descriptions ?e", $_data);
                 }
             }
             if (substr_count('SR', $data['field_type']) && is_array($data['add_variants'])) {
                 fn_giftreg_add_field_variants($data['add_variants'], $field_id);
             } else {
                 fn_giftreg_delete_field_variants($field_id);
             }
         }
     }
     $suffix = ".field_editor";
 }
 // Delete fields and/or variants
Exemple #11
0
function fn_gift_certificates_place_order($order_id, $fake, $fake1, &$cart)
{
    if (!empty($order_id)) {
        if (defined('ORDER_MANAGEMENT')) {
            // If the purchased certificate was deleted when editing, then it should be updated in the database
            if (!empty($cart['gift_certificates_previous_state'])) {
                $flip_gcps = array_flip(array_keys($cart['gift_certificates_previous_state']));
                $flip_gc = array_flip(array_keys(!empty($cart['gift_certificates']) ? $cart['gift_certificates'] : array()));
                $diff = array_diff_key($flip_gcps, $flip_gc);
                if (!empty($diff)) {
                    foreach ($diff as $gift_cert_cart_id => $v) {
                        db_query("UPDATE ?:gift_certificates SET order_ids = ?p WHERE gift_cert_id = ?i", fn_remove_from_set('order_ids', $order_id), $cart['gift_certificates_previous_state'][$gift_cert_cart_id]['gift_cert_id']);
                    }
                    db_query("DELETE FROM ?:order_data WHERE order_id = ?i AND type = ?s", $order_id, ORDER_DATA_PURCHASED_GIFT_CERTIFICATES);
                }
            }
        }
        if (isset($cart['reset_use_gift_certificates'])) {
            foreach ($cart['reset_use_gift_certificates'] as $v) {
                db_query("UPDATE ?:gift_certificates SET order_ids = ?p WHERE gift_cert_id = ?i", fn_remove_from_set('order_ids', $order_id), $v);
            }
            unset($cart['reset_use_gift_certificates']);
        }
        if (isset($cart['gift_certificates'])) {
            foreach ($cart['gift_certificates'] as $k => $v) {
                if (defined('ORDER_MANAGEMENT') && !empty($v['gift_cert_code'])) {
                    $code = $v['gift_cert_code'];
                } else {
                    do {
                        $code = fn_generate_gift_certificate_code();
                    } while (true == fn_check_gift_certificate_code($code));
                }
                $_data = fn_check_table_fields($v, 'gift_certificates');
                $_data = fn_array_merge($_data, array('gift_cert_code' => $code, 'timestamp' => TIME, 'status' => 'P'));
                $_data['products'] = !empty($_data['products']) ? serialize($_data['products']) : '';
                $gift_cert_id = db_query('REPLACE INTO ?:gift_certificates ?e', $_data);
                $cart['gift_certificates'][$k] = fn_array_merge($v, array('gift_cert_id' => $gift_cert_id, 'gift_cert_code' => $code));
                db_query("UPDATE ?:gift_certificates SET order_ids = ?p WHERE gift_cert_id = ?i", fn_add_to_set('order_ids', $order_id), $gift_cert_id);
                if (defined('ORDER_MANAGEMENT')) {
                    //If the certificate was not removed from the order, it is necessary to check  whether the products and amount have been changed and modify the log.
                    $debit_info = db_get_row("SELECT debit AS amount, debit_products AS products FROM ?:gift_certificates_log WHERE gift_cert_id = ?i ORDER BY timestamp DESC", $gift_cert_id);
                    if (empty($debit_info)) {
                        $debit_info = db_get_row("SELECT amount, products FROM ?:gift_certificates WHERE gift_cert_id = ?i", $gift_cert_id);
                    }
                    if ($_data['amount'] - $debit_info['amount'] != 0 || md5($_data['products']) != md5($debit_info['products'])) {
                        $_info = array('amount' => $_data['amount'], 'products' => $_data['products']);
                        fn_add_gift_certificate_log_record($gift_cert_id, $debit_info, $_info);
                    }
                }
            }
            $order_data = array('order_id' => $order_id, 'type' => ORDER_DATA_PURCHASED_GIFT_CERTIFICATES, 'data' => serialize($cart['gift_certificates']));
            db_query("REPLACE INTO ?:order_data ?e", $order_data);
        }
        //--> FIXME: optimize this code:
        if (!empty($cart['use_gift_certificates_previous_state'])) {
            $flip_ugcps = array_flip(array_keys($cart['use_gift_certificates_previous_state']));
            $flip_ugc = array_flip(array_keys(!empty($cart['use_gift_certificates']) ? $cart['use_gift_certificates'] : array()));
            $diff = array_diff_key($flip_ugcps, $flip_ugc);
            if (!empty($diff)) {
                foreach ($diff as $gift_cert_code => $v) {
                    $gc_data = $cart['use_gift_certificates_previous_state'][$gift_cert_code]['previous_state'];
                    $log_records = db_get_array("SELECT log_id, amount, debit, products, debit_products FROM ?:gift_certificates_log WHERE log_id >= ?i AND gift_cert_id = ?i ORDER BY timestamp ASC", $gc_data['log_id'], $gc_data['gift_cert_id']);
                    foreach ($log_records as $record) {
                        if (!empty($gc_data['products'])) {
                            if ($record['log_id'] != $gc_data['log_id']) {
                                $record['products'] = unserialize($record['products']);
                                foreach ($gc_data['products'] as $po_product_id => $po_quantity) {
                                    if (!isset($record['products'][$po_product_id])) {
                                        $record['products'][$po_product_id] = $po_quantity;
                                    } else {
                                        $record['products'][$po_product_id] += $po_quantity;
                                    }
                                    if (empty($record['products'][$po_product_id])) {
                                        unset($record['products'][$po_product_id]);
                                    }
                                }
                                $record['products'] = serialize($record['products']);
                            }
                            $record['debit_products'] = unserialize($record['debit_products']);
                            foreach ($gc_data['products'] as $po_product_id => $po_quantity) {
                                if (!isset($record['debit_products'][$po_product_id])) {
                                    $record['debit_products'][$po_product_id] = $po_quantity;
                                } else {
                                    $record['debit_products'][$po_product_id] += $po_quantity;
                                }
                                if (empty($record['debit_products'][$po_product_id])) {
                                    unset($record['debit_products'][$po_product_id]);
                                }
                            }
                            $record['debit_products'] = serialize($record['debit_products']);
                        }
                        if ($record['log_id'] != $gc_data['log_id']) {
                            $record['amount'] += $gc_data['cost'];
                        }
                        $record['debit'] += $gc_data['cost'];
                        db_query("UPDATE ?:gift_certificates_log SET ?u WHERE log_id = ?i", $record, $record['log_id']);
                        if (floatval($record['debit']) > 0 || unserialize($record['debit_products']) != array() && db_get_field("SELECT status FROM ?:gift_certificates WHERE gift_cert_id = ?", $gc_data['gift_cert_id']) == 'U') {
                            fn_change_gift_certificate_status($gc_data['gift_cert_id'], 'A');
                        }
                    }
                }
            }
        }
        if (isset($cart['use_gift_certificates'])) {
            $debit_products = array();
            $use_gift_certificates = array();
            if (!empty($cart['deleted_exclude_products'][GIFT_CERTIFICATE_EXCLUDE_PRODUCTS])) {
                foreach ($cart['deleted_exclude_products'][GIFT_CERTIFICATE_EXCLUDE_PRODUCTS] as $cart_id => $v) {
                    foreach ($v['in_use_certificate'] as $gift_cert_code => $amount) {
                        $debit_products[$gift_cert_code]['products'][$v['product_id']] = $amount;
                    }
                }
            }
            $use_gift_certificate_products = array();
            if (!empty($cart['products'])) {
                foreach ($cart['products'] as $product) {
                    if (!empty($product['extra']['exclude_from_calculate']) && $product['extra']['exclude_from_calculate'] == GIFT_CERTIFICATE_EXCLUDE_PRODUCTS) {
                        foreach ($product['extra']['in_use_certificate'] as $gift_cert_code => $quantity) {
                            $use_gift_certificate_products[$gift_cert_code][$product['product_id']] = $quantity;
                        }
                    }
                }
            }
            foreach ($cart['use_gift_certificates'] as $k => $v) {
                if (!empty($v['log_id'])) {
                    $product_odds = array();
                    $amount_odds = $v['previous_state']['cost'] - $v['cost'];
                    $current_state_products = !empty($use_gift_certificate_products[$k]) ? $use_gift_certificate_products[$k] : array();
                    if (sizeof($v['previous_state']['products']) != sizeof($current_state_products) || serialize($v['previous_state']['products']) != serialize($current_state_products)) {
                        if (!empty($v['previous_state']['products'])) {
                            foreach ($v['previous_state']['products'] as $product_id => $quantity) {
                                if (!isset($current_state_products[$product_id])) {
                                    $product_odds[$product_id] = $quantity;
                                } else {
                                    $product_odds[$product_id] = $quantity - $current_state_products[$product_id];
                                }
                                if (empty($product_odds[$product_id])) {
                                    unset($product_odds[$product_id]);
                                }
                            }
                        } elseif (!empty($current_state_products)) {
                            foreach ($current_state_products as $product_id => $quantity) {
                                $product_odds[$product_id] = -$quantity;
                            }
                        }
                    }
                    if ($amount_odds != 0 || !empty($product_odds)) {
                        $log_records = db_get_array("SELECT log_id, amount, debit, products, debit_products FROM ?:gift_certificates_log WHERE log_id >= ?i AND gift_cert_id = ?i ORDER BY timestamp ASC", $v['log_id'], $v['gift_cert_id']);
                        foreach ($log_records as $record) {
                            if (!empty($product_odds)) {
                                if ($record['log_id'] != $v['log_id']) {
                                    $record['products'] = unserialize($record['products']);
                                    foreach ($product_odds as $po_product_id => $po_quantity) {
                                        if (!isset($record['products'][$po_product_id])) {
                                            $record['products'][$po_product_id] = $po_quantity;
                                        } else {
                                            $record['products'][$po_product_id] += $po_quantity;
                                        }
                                        if (empty($record['products'][$po_product_id])) {
                                            unset($record['products'][$po_product_id]);
                                        }
                                    }
                                    $record['products'] = serialize($record['products']);
                                }
                                $record['debit_products'] = unserialize($record['debit_products']);
                                foreach ($product_odds as $po_product_id => $po_quantity) {
                                    if (!isset($record['debit_products'][$po_product_id])) {
                                        $record['debit_products'][$po_product_id] = $po_quantity;
                                    } else {
                                        $record['debit_products'][$po_product_id] += $po_quantity;
                                    }
                                    if (empty($record['debit_products'][$po_product_id])) {
                                        unset($record['debit_products'][$po_product_id]);
                                    }
                                }
                                $record['debit_products'] = serialize($record['debit_products']);
                            } else {
                                if ($record['log_id'] != $v['log_id']) {
                                    $record['amount'] += $amount_odds;
                                }
                                $record['debit'] += $amount_odds;
                            }
                            db_query("UPDATE ?:gift_certificates_log SET ?u WHERE log_id = ?i", $record, $record['log_id']);
                            $use_gift_certificates[$k] = array('gift_cert_id' => $v['gift_cert_id'], 'amount' => $v['previous_state']['amount'], 'cost' => $v['cost'], 'log_id' => $v['log_id']);
                            if (floatval($record['debit']) <= 0 && unserialize($record['debit_products']) == array()) {
                                fn_change_gift_certificate_status($v['gift_cert_id'], 'U');
                            } elseif (floatval($record['debit']) > 0 || unserialize($record['debit_products']) != array() && db_get_field("SELECT status FROM ?:gift_certificates WHERE gift_cert_id = ?i", $v['gift_cert_id']) == 'U') {
                                fn_change_gift_certificate_status($v['gift_cert_id'], 'A');
                            }
                        }
                    }
                    //<-- FIXME: optimize this code
                } else {
                    $before_info = array('amount' => $v['amount'], 'products' => serialize(!empty($v['products']) ? $v['products'] : array()));
                    $after_info = array('amount' => fn_format_price($v['amount'] - $v['cost']), 'products' => serialize(!empty($debit_products[$k]['products']) ? $debit_products[$k]['products'] : array()));
                    $log_id = fn_add_gift_certificate_log_record($v['gift_cert_id'], $before_info, $after_info, $order_id);
                    $use_gift_certificates[$k] = array('gift_cert_id' => $v['gift_cert_id'], 'amount' => $v['amount'], 'cost' => $v['cost'], 'log_id' => $log_id);
                    if (floatval($v['amount'] - $v['cost']) <= 0 && !isset($debit_products[$k]['products'])) {
                        fn_change_gift_certificate_status($v['gift_cert_id'], 'U');
                    }
                }
                db_query("UPDATE ?:gift_certificates SET order_ids = ?p  WHERE gift_cert_id = ?i", fn_add_to_set('order_ids', $order_id), $v['gift_cert_id']);
            }
            $order_data = array('order_id' => $order_id, 'type' => 'U', 'data' => serialize($use_gift_certificates));
            db_query("REPLACE INTO ?:order_data ?e", $order_data);
        }
    }
}
Exemple #12
0
function fn_update_discussion($params)
{
    $_data = fn_check_table_fields($params, 'discussion');
    $discussion = fn_get_discussion($params['object_id'], $params['object_type']);
    if (!empty($discussion['thread_id'])) {
        db_query("UPDATE ?:discussion SET ?u WHERE thread_id = ?i", $_data, $discussion['thread_id']);
    } else {
        db_query("REPLACE INTO ?:discussion ?e", $_data);
    }
    return true;
}
Exemple #13
0
/**
 * Parse query and replace placeholders with data
 *
 * @param string $query unparsed query
 * @param array $data data for placeholders
 * @return parsed query
 */
function db_process($pattern, $data = array(), $replace = true)
{
    static $session_vars_updated = false;
    $command = 'get';
    $group_concat_len = 3000;
    // 3Kb
    // Check if query updates data in the database
    if (preg_match("/^(UPDATE|INSERT INTO|REPLACE INTO|DELETE FROM) \\?\\:(\\w+) /", $pattern, $m)) {
        $table_name = $m[2];
        //str_replace(TABLE_PREFIX, '', $m[2]);
        Registry::set_changed_tables($table_name);
        Registry::register_cache('cached_queries', array(), CACHE_LEVEL_STATIC, true);
        $cached_queries = Registry::if_get('cached_queries', array());
        if (!empty($cached_queries)) {
            foreach ($cached_queries as $cquery => $ctables) {
                if (in_array($table_name, $ctables)) {
                    unset($cached_queries[$cquery]);
                }
            }
            Registry::set('cached_queries', empty($cached_queries) ? array(0 => array()) : $cached_queries);
        }
        $command = $m[1] == 'DELETE FROM' ? 'delete' : 'set';
    }
    if (strpos($pattern, 'GROUP_CONCAT(') !== false && $session_vars_updated == false) {
        db_query('SET SESSION group_concat_max_len = ?i', $group_concat_len);
        $session_vars_updated = true;
    }
    if (!empty($data) && preg_match_all("/\\?(i|s|l|d|a|n|u|e|p|w|f)+/", $pattern, $m)) {
        $offset = 0;
        foreach ($m[0] as $k => $ph) {
            if ($ph == '?u' || $ph == '?e') {
                $data[$k] = fn_check_table_fields($data[$k], $table_name);
                if (empty($data[$k])) {
                    return false;
                }
            }
            if ($ph == '?i') {
                // integer
                $pattern = db_str_replace($ph, db_intval($data[$k]), $pattern, $offset);
                // Trick to convert int's and longint's
            } elseif ($ph == '?s') {
                // string
                $pattern = db_str_replace($ph, "'" . addslashes($data[$k]) . "'", $pattern, $offset);
            } elseif ($ph == '?l') {
                // string for LIKE operator
                $pattern = db_str_replace($ph, "'" . addslashes(str_replace("\\", "\\\\", $data[$k])) . "'", $pattern, $offset);
            } elseif ($ph == '?d') {
                // float
                $pattern = db_str_replace($ph, sprintf('%01.2f', $data[$k]), $pattern, $offset);
            } elseif ($ph == '?a') {
                // array FIXME: add trim
                $data[$k] = !is_array($data[$k]) ? array($data[$k]) : $data[$k];
                $pattern = db_str_replace($ph, "'" . implode("', '", array_map('addslashes', $data[$k])) . "'", $pattern, $offset);
            } elseif ($ph == '?n') {
                // array of integer FIXME: add trim
                $data[$k] = !is_array($data[$k]) ? array($data[$k]) : $data[$k];
                $pattern = db_str_replace($ph, !empty($data[$k]) ? implode(', ', array_map('db_intval', $data[$k])) : "''", $pattern, $offset);
            } elseif ($ph == '?u' || $ph == '?w') {
                // update/condition with and
                $q = '';
                $clue = $ph == '?u' ? ', ' : ' AND ';
                foreach ($data[$k] as $field => $value) {
                    $q .= ($q ? $clue : '') . '`' . db_field($field) . "` = '" . addslashes($value) . "'";
                }
                $pattern = db_str_replace($ph, $q, $pattern, $offset);
            } elseif ($ph == '?e') {
                // insert
                $pattern = db_str_replace($ph, '(`' . implode('`, `', array_map('addslashes', array_keys($data[$k]))) . "`) VALUES ('" . implode("', '", array_map('addslashes', array_values($data[$k]))) . "')", $pattern, $offset);
            } elseif ($ph == '?f') {
                // field/table/database name
                $pattern = db_str_replace($ph, db_field($data[$k]), $pattern, $offset);
            } elseif ($ph == '?p') {
                // prepared statement
                //				$pattern = db_str_replace($ph, str_replace('?:', TABLE_PREFIX, $data[$k]), $pattern, $offset);
                $pattern = db_str_replace($ph, $data[$k], $pattern, $offset);
            }
        }
    }
    if ($replace) {
        if (Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
            if (strpos($pattern, 'SELECT') === 0) {
                fn_revisions_process_select($pattern);
            }
            if (strpos($pattern, 'UPDATE') === 0) {
                fn_revisions_process_update($pattern);
            }
            if (strpos($pattern, 'INSERT') === 0 || strpos($pattern, 'REPLACE') === 0) {
                Registry::set('revisions.db_insert_id', 0);
                fn_revisions_process_insert($pattern);
            }
            if (strpos($pattern, 'DELETE') === 0) {
                fn_revisions_process_delete($pattern);
            }
        }
        // Replace table prefixes
        $pattern = str_replace('?:', TABLE_PREFIX, $pattern);
    }
    return $pattern;
}
 $suffix = ".table.edit?report_id={$_REQUEST['report_id']}&table_id={$_REQUEST['table_id']}";
 // ************************************ TABLE *************************** //
 if ($action == 'add') {
     // Add table
     $table = $_REQUEST['table'];
     if (empty($table['description'])) {
         return array(CONTROLLER_STATUS_REDIRECT, "sales_reports.table.add?report_id={$_REQUEST['report_id']}");
     }
     if ($table['type'] == 'P' || $table['type'] == 'C') {
         $table['interval_id'] = '1';
     }
     $table['report_id'] = $_REQUEST['report_id'];
     $table_id = db_query("REPLACE INTO ?:sales_reports_tables ?e", $table);
     fn_create_description('sales_reports_table_descriptions', "table_id", $table_id, array('description' => $table['description']));
     // Create parameters
     $_data = fn_check_table_fields($_REQUEST['update_element'], 'sales_reports_table_elements');
     $_data['table_id'] = $table_id;
     $_data['report_id'] = $_REQUEST['report_id'];
     $_data['element_hash'] = fn_generate_element_hash($table_id, $_data['element_id'], '');
     db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data);
     foreach ($_REQUEST['conditions'] as $section => $ids) {
         db_query("DELETE FROM ?:sales_reports_table_conditions WHERE table_id = ?i AND code = ?s", $table_id, $section);
         $object_ids = is_array($ids) ? $ids : (empty($ids) ? array() : explode(',', $ids));
         foreach ($object_ids as $o_id) {
             $data = array('sub_element_id' => $o_id, 'table_id' => $table_id, 'code' => $section);
             db_query('REPLACE INTO ?:sales_reports_table_conditions ?e', $data);
         }
     }
     $suffix = ".table.edit?report_id={$_REQUEST['report_id']}&table_id={$table_id}";
 }
 if ($action == 'update') {
Exemple #15
0
function fn_form_cart($order_id, &$cart, &$auth)
{
    $order_info = fn_get_order_info($order_id, false, false);
    if (empty($order_info)) {
        fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('order'))), '', '404');
        return false;
    }
    // Fill the cart
    foreach ($order_info['products'] as $_id => $item) {
        $_item = array($item['product_id'] => array('amount' => $item['amount'], 'product_options' => !empty($item['extra']['product_options']) ? $item['extra']['product_options'] : array(), 'price' => $item['original_price'], 'stored_discount' => 'Y', 'stored_price' => 'Y', 'discount' => !empty($item['extra']['discount']) ? $item['extra']['discount'] : 0, 'original_amount' => $item['amount'], 'original_product_data' => array('cart_id' => $_id, 'amount' => $item['amount'])));
        if (isset($item['extra'])) {
            $_item[$item['product_id']]['extra'] = $item['extra'];
        }
        fn_add_product_to_cart($_item, $cart, $auth);
    }
    // Workaround for the add-ons that do not add a product to cart unless the parent product is already added.
    if (count($order_info['products']) > count($cart['products'])) {
        foreach ($order_info['products'] as $_id => $item) {
            if (empty($cart['products'][$_id])) {
                $_item = array($item['product_id'] => array('amount' => $item['amount'], 'product_options' => !empty($item['extra']['product_options']) ? $item['extra']['product_options'] : array(), 'price' => $item['original_price'], 'stored_discount' => 'Y', 'stored_price' => 'Y', 'discount' => !empty($item['extra']['discount']) ? $item['extra']['discount'] : 0, 'original_amount' => $item['amount'], 'original_product_data' => array('cart_id' => $_id, 'amount' => $item['amount'])));
                if (isset($item['extra'])) {
                    $_item[$item['product_id']]['extra'] = $item['extra'];
                }
                fn_add_product_to_cart($_item, $cart, $auth);
            }
        }
    }
    // Restore custom files
    $dir_path = 'order_data/' . $order_id;
    if (Storage::instance('custom_files')->isExist($dir_path)) {
        Storage::instance('custom_files')->copy($dir_path, 'sess_data');
    }
    $cart['payment_id'] = $order_info['payment_id'];
    $cart['stored_taxes'] = 'Y';
    $cart['stored_discount'] = 'Y';
    $cart['taxes'] = $order_info['taxes'];
    $cart['promotions'] = !empty($order_info['promotions']) ? $order_info['promotions'] : array();
    $cart['shipping'] = !empty($order_info['shipping']) ? $order_info['shipping'] : array();
    $cart['stored_shipping'] = array();
    foreach ($cart['shipping'] as $sh_id => $v) {
        if (!empty($v['rates'])) {
            $cart['stored_shipping'][$sh_id] = array_sum($v['rates']);
        }
    }
    if (!empty($order_info['product_groups'])) {
        $cart['product_groups'] = $order_info['product_groups'];
        foreach ($order_info['product_groups'] as $group) {
            if (!empty($group['chosen_shippings'])) {
                foreach ($group['chosen_shippings'] as $key => $chosen_shipping) {
                    foreach ($group['shippings'] as $shipping_id => $shipping) {
                        if ($shipping_id == $chosen_shipping['shipping_id']) {
                            $cart['chosen_shipping'][$chosen_shipping['group_key']] = $shipping_id;
                        }
                    }
                }
            }
        }
    } else {
        $cart['product_groups'] = array();
    }
    $cart['order_timestamp'] = $order_info['timestamp'];
    $cart['notes'] = $order_info['notes'];
    $cart['details'] = $order_info['details'];
    $cart['payment_info'] = @$order_info['payment_info'];
    $cart['profile_id'] = $order_info['profile_id'];
    // Add order discount
    if (floatval($order_info['subtotal_discount'])) {
        $cart['stored_subtotal_discount'] = 'Y';
        $cart['subtotal_discount'] = $cart['original_subtotal_discount'] = fn_format_price($order_info['subtotal_discount']);
    }
    // Fill the cart with the coupons
    if (!empty($order_info['coupons'])) {
        $cart['coupons'] = $order_info['coupons'];
    }
    // Set the customer if exists
    $_data = array();
    if (!empty($order_info['user_id'])) {
        $_data = db_get_row("SELECT user_id, user_login as login FROM ?:users WHERE user_id = ?i", $order_info['user_id']);
    }
    $auth = fn_fill_auth($_data, array(), false, 'C');
    $auth['tax_exempt'] = $order_info['tax_exempt'];
    // Fill customer info
    $cart['user_data'] = fn_array_merge(fn_check_table_fields($order_info, 'users'), fn_check_table_fields($order_info, 'user_profiles'));
    if (!empty($order_info['fields'])) {
        $cart['user_data']['fields'] = $order_info['fields'];
    }
    fn_add_user_data_descriptions($cart['user_data']);
    fn_set_hook('form_cart', $order_info, $cart, $auth);
    return true;
}
Exemple #16
0
function fn_import($pattern, $import_data, $options)
{
    $processed_data = array('E' => 0, 'N' => 0, 'S' => 0);
    if (defined('COMPANY_ID')) {
        $vendors_import_data = array();
        if ($pattern['pattern_id'] == 'products') {
            // Importing products when in vendor mode:
            // Override company_id with current vendor's company_id
            // If product already exists but belongs to another vendor: skip record
            $product_codes = db_get_fields('SELECT product_code FROM ?:products');
            foreach ($import_data as $v) {
                if (!in_array($v['product_code'], $product_codes) || $v['company_id'] == COMPANY_ID) {
                    $v['company_id'] = COMPANY_ID;
                    $vendors_import_data[] = $v;
                } else {
                    $processed_data['S']++;
                }
            }
        }
        if ($pattern['pattern_id'] == 'product_images' || $pattern['pattern_id'] == 'qty_discounts') {
            // Importing images and qty discounts when in vendor mode:
            // Get a list of current vendor's products codes
            // Leave only current vendor's images and qty discounts
            $product_codes = db_get_fields('SELECT product_code FROM ?:products WHERE company_id = ' . COMPANY_ID);
            foreach ($import_data as $v) {
                if (in_array($v['product_code'], $product_codes)) {
                    $vendors_import_data[] = $v;
                } else {
                    $processed_data['S']++;
                }
            }
        }
        $import_data = $vendors_import_data;
    }
    $alt_keys = array();
    $primary_fields = array();
    $table_groups = array();
    $processing_groups = array();
    $default_groups = array();
    $converting_groups = array();
    $add_fields = array();
    fn_start_scroller();
    if (!empty($pattern['pre_processing'])) {
        $func = $pattern['pre_processing'];
        $function = array_shift($func);
        $args = $func;
        foreach ($args as $k => $v) {
            if (strpos($v, '@') !== false) {
                $_opt = str_replace('@', '', $v);
                $args[$k] = isset($options[$_opt]) ? $options[$_opt] : '';
            }
        }
        call_user_func_array($function, $args);
    }
    fn_echo('<br />' . fn_get_lang_var('importing_data') . '<br />');
    if (!empty($pattern['references'])) {
        foreach ($pattern['references'] as $table => $data) {
            $table_groups[$table] = $data;
        }
    }
    // Get keys to detect primary record
    foreach ($pattern['export_fields'] as $field => $data) {
        $_db_field = empty($data['db_field']) ? $field : $data['db_field'];
        // Collect fields with default values
        if (!empty($data['default'])) {
            if (is_array($data['default'])) {
                $default_groups[$_db_field] = call_user_func_array(array_shift($data['default']), $data['default']);
            } else {
                $default_groups[$_db_field] = $data['default'];
            }
        }
        // Get alt keys for primary table
        if (!empty($data['alt_key'])) {
            $alt_keys[$field] = $_db_field;
        }
        if (!isset($data['linked']) || $data['linked'] == true) {
            // Get fields for primary table
            if (empty($data['table']) || $data['table'] == $pattern['table']) {
                $primary_fields[$field] = $_db_field;
            }
            // Group fields by tables
            if (!empty($data['table'])) {
                $table_groups[$data['table']]['fields'][$_db_field] = true;
            }
        }
        // Create set with fields that must be added to data import if they are not exist
        // %'s are for compatibility with %% field type in "process_put" key
        if (!empty($data['use_put_from'])) {
            $_f = str_replace('%', '', $data['use_put_from']);
            $_f = !empty($pattern['export_fields'][$_f]['db_field']) ? $pattern['export_fields'][$_f]['db_field'] : $_f;
            $add_fields[$_f] = true;
        }
        // Generate processing groups
        if (!empty($data['process_put'])) {
            $args = $data['process_put'];
            $function = array_shift($args);
            $processing_groups[] = array('function' => $function, 'args' => $args, 'this_field' => $_db_field, 'table' => !empty($data['table']) ? $data['table'] : '', 'return_result' => !empty($data['return_result']) ? $data['return_result'] : false);
        }
        // Generate converting groups
        if (!empty($data['convert_put'])) {
            $args = $data['convert_put'];
            $function = array_shift($args);
            $converting_groups[] = array('function' => $function, 'this_field' => $_db_field, 'args' => $args);
        }
    }
    foreach ($import_data as $k => $v) {
        foreach ($add_fields as $_f => $_val) {
            if (!isset($v[$_f])) {
                $v[$_f] = '';
            }
        }
        $_alt_keys = array();
        $object_exists = true;
        // Check if converting groups exist and convert fields if it is so
        if (!empty($converting_groups)) {
            foreach ($converting_groups as $group) {
                if (!isset($v[$group['this_field']])) {
                    continue;
                }
                $params = array();
                $params[] = $v[$group['this_field']];
                foreach ($group['args'] as $arg) {
                    if (strpos($arg, '@') !== false) {
                        $_opt = str_replace('@', '', $arg);
                        $params[] = isset($options[$_opt]) ? $options[$_opt] : '';
                    }
                }
                $v[$group['this_field']] = call_user_func_array($group['function'], $params);
            }
        }
        foreach ($alt_keys as $import_field => $real_field) {
            if (!isset($v[$real_field])) {
                continue;
            }
            $_alt_keys[$real_field] = $v[$real_field];
        }
        foreach ($primary_fields as $import_field => $real_field) {
            if (!isset($v[$real_field])) {
                continue;
            }
            $_primary_fields[$real_field] = $v[$real_field];
        }
        $primary_object_id = db_get_row('SELECT ' . implode(', ', $pattern['key']) . ' FROM ?:' . $pattern['table'] . ' WHERE ?w', $_alt_keys);
        if (!(isset($pattern['import_skip_db_processing']) && $pattern['import_skip_db_processing'])) {
            if (empty($primary_object_id)) {
                // If scheme is used for update objects only, skip this record
                if (!empty($pattern['update_only'])) {
                    fn_echo(fn_get_lang_var('object_does_not_exist') . ' (');
                    $_a = array();
                    foreach ($alt_keys as $_d => $_v) {
                        if (!isset($v[$_v])) {
                            continue;
                        }
                        $_a[] = $_d . ' = ' . $v[$_v];
                    }
                    fn_echo(implode(', ', $_a) . ')...<br />');
                    $processed_data['S']++;
                    continue;
                }
                $object_exists = false;
                fn_echo(fn_get_lang_var('creating') . ' ' . $pattern['name'] . '...');
                $processed_data['N']++;
                // For new objects - fill the default values
                if (!empty($default_groups)) {
                    foreach ($default_groups as $field => $value) {
                        if (empty($v[$field])) {
                            $v[$field] = $value;
                        }
                    }
                }
            } else {
                fn_echo(fn_get_lang_var('updating') . ' ' . $pattern['name'] . '...');
                $processed_data['E']++;
            }
            $_data = fn_check_table_fields($v, $pattern['table']);
            if ($object_exists == true) {
                db_query('UPDATE ?:' . $pattern['table'] . ' SET ?u WHERE ?w', $_data, $primary_object_id);
            } else {
                $o_id = db_query('INSERT INTO ?:' . $pattern['table'] . ' ?e', $_data);
                if ($o_id !== true) {
                    $primary_object_id = array(reset($pattern['key']) => $o_id);
                } else {
                    foreach ($pattern['key'] as $_v) {
                        $primary_object_id[$_v] = $_data[$_v];
                    }
                }
            }
            if ($pattern['table'] == 'products' && $object_exists == false) {
                require_once "products.php";
                fn_add_to_new_items_block($primary_object_id['product_id']);
            }
            fn_echo('<b>' . implode(',', $primary_object_id) . '</b>. ');
        }
        if (!empty($processing_groups)) {
            foreach ($processing_groups as $group) {
                $args = array();
                $use_this_group = true;
                $_refs = array();
                foreach ($group['args'] as $ak => $av) {
                    if ($av == '#key') {
                        $args[$ak] = sizeof($primary_object_id) == 1 ? reset($primary_object_id) : $primary_object_id;
                    } elseif ($av == '#this') {
                        // If we do not have this field in the import data, do not apply the function
                        if (!isset($v[$group['this_field']])) {
                            $use_this_group = false;
                            break;
                        }
                        $args[$ak] = $v[$group['this_field']];
                    } elseif ($av == '#counter') {
                        $args[$ak] =& $processed_data;
                    } elseif (strpos($av, '%') !== false) {
                        $_ref = str_replace('%', '', $av);
                        $_ref = !empty($pattern['export_fields'][$_ref]['db_field']) ? $pattern['export_fields'][$_ref]['db_field'] : $_ref;
                        // FIXME!!! Move to code, which builds processing_groups
                        $args[$ak] = isset($v[$_ref]) ? $v[$_ref] : '';
                        $_refs[] = $_ref;
                    } elseif (strpos($av, '@') !== false) {
                        $_opt = str_replace('@', '', $av);
                        $args[$ak] = $options[$_opt];
                    } else {
                        $args[$ak] = $av;
                    }
                }
                if ($use_this_group == false) {
                    continue;
                }
                $result = call_user_func_array($group['function'], $args);
                // FIXME - add checking for returned value
                if ($group['return_result'] == true) {
                    $v[$group['this_field']] = $result;
                } else {
                    // Remove processed fields from table groups
                    if (!empty($group['table'])) {
                        unset($table_groups[$group['table']]['fields'][$group['this_field']]);
                        foreach ($_refs as $_ref) {
                            unset($table_groups[$group['table']]['fields'][$_ref]);
                        }
                    }
                }
            }
        }
        if (!(isset($pattern['import_skip_db_processing']) && $pattern['import_skip_db_processing'])) {
            // Update referenced tables
            fn_echo(fn_get_lang_var('updating_links') . '... ');
            foreach ($table_groups as $table => $tdata) {
                if (isset($tdata['import_skip_db_processing']) && $tdata['import_skip_db_processing']) {
                    break;
                }
                $_data = array();
                // First, build condition
                $where_insert = array();
                // If alternative key is defined, use it
                if (!empty($tdata['alt_key'])) {
                    foreach ($tdata['alt_key'] as $akey) {
                        if (strval($akey) == '#key') {
                            $where_insert = fn_array_merge($where_insert, $primary_object_id);
                        } elseif (strpos($akey, '@') !== false) {
                            $_opt = str_replace('@', '', $akey);
                            $where_insert[$akey] = $options[$_opt];
                        } else {
                            $where_insert[$akey] = $v[$akey];
                        }
                    }
                    // Otherwise - link by reference fields
                } else {
                    foreach ($tdata['reference_fields'] as $field => $value) {
                        if (strval($value) == '#key') {
                            $_val = sizeof($primary_object_id) == 1 ? reset($primary_object_id) : $primary_object_id;
                        } elseif (strpos($value, '@') !== false) {
                            $_opt = str_replace('@', '', $value);
                            $_val = $options[$_opt];
                        } else {
                            $_val = $value;
                        }
                        $where_insert[$field] = $_val;
                    }
                }
                // Now, build update fields array
                foreach ($tdata['fields'] as $import_field => $set) {
                    if (!isset($v[$import_field])) {
                        continue;
                    }
                    $_data[$import_field] = $v[$import_field];
                }
                // Check if object exists
                $is_exists = db_get_field("SELECT COUNT(*) FROM ?:{$table} WHERE ?w", $where_insert);
                if ($is_exists == true && !empty($_data)) {
                    db_query("UPDATE ?:{$table} SET ?u WHERE ?w", $_data, $where_insert);
                } elseif (empty($is_exists)) {
                    // if reference does not exist, we should insert it anyway to avoid inconsistency
                    $_data = fn_array_merge($_data, $where_insert);
                    if (substr($table, -13) == '_descriptions' && isset($_data['lang_code'])) {
                        // add description for all cart languages when adding object data
                        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $lang_v) {
                            db_query("REPLACE INTO ?:{$table} ?e", $_data);
                        }
                    } else {
                        db_query("INSERT INTO ?:{$table} ?e", $_data);
                    }
                }
            }
            fn_echo('<b>' . fn_get_lang_var('uc_ok') . '</b><br />');
        }
    }
    $msg = fn_get_lang_var('text_exim_data_imported');
    $msg = str_replace('[new]', $processed_data['N'], $msg);
    $msg = str_replace('[exist]', $processed_data['E'], $msg);
    $msg = str_replace('[skipped]', $processed_data['S'], $msg);
    $msg = str_replace('[total]', $processed_data['E'] + $processed_data['N'] + $processed_data['S'], $msg);
    fn_set_notification('N', fn_get_lang_var('notice'), $msg);
    fn_stop_scroller();
    return true;
}
Exemple #17
0
function fn_stat_save_session_data(&$stat_data)
{
    $stat_data['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    $ip = fn_get_ip(true);
    $stat_data['host_ip'] = $ip['host'];
    $stat_data['proxy_ip'] = $ip['proxy'];
    $stat_data['client_language'] = strtoupper(empty($stat_data['client_language']) ? empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? '' : $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $stat_data['client_language']);
    $stat_data['session'] = Session::get_id();
    $stat_data['host_ip'] = $ip['host'];
    $stat_data['proxy_ip'] = $ip['proxy'];
    $stat_data['ip_id'] = fn_stat_ip_exist($ip);
    if (!empty($stat_data['browser'])) {
        $browser_id = db_get_field("SELECT browser_id FROM ?:stat_browsers WHERE browser = ?s AND version = ?s", $stat_data['browser'], $stat_data['browser_version']);
        if (empty($browser_id)) {
            $browser_id = db_query('INSERT INTO ?:stat_browsers ?e', array('browser' => $stat_data['browser'], 'version' => $stat_data['browser_version']));
        }
        $stat_data['browser_id'] = $browser_id;
    }
    $parse_url = parse_url(@$stat_data['referrer']);
    $stat_data['referrer_scheme'] = empty($parse_url['scheme']) ? '' : $parse_url['scheme'];
    $stat_data['referrer_host'] = empty($parse_url['host']) ? '' : $parse_url['host'];
    $search_data = fn_get_search_words(@$stat_data['referrer']);
    if (!empty($search_data['engine'])) {
        //$stat_data['engine'] = $search_data['engine'];
        $engine_id = db_get_field("SELECT engine_id FROM ?:stat_search_engines WHERE engine = ?s", $search_data['engine']);
        if (empty($engine_id)) {
            $engine_id = db_query('INSERT INTO ?:stat_search_engines ?e', array('engine' => $search_data['engine']));
        }
        $stat_data['engine_id'] = empty($engine_id) ? 0 : $engine_id;
    }
    if (!empty($search_data['phrase'])) {
        $phrase_id = db_get_field("SELECT phrase_id FROM ?:stat_search_phrases WHERE phrase = ?s", $search_data['phrase']);
        if (empty($phrase_id)) {
            $phrase_id = db_query('INSERT INTO ?:stat_search_phrases ?e', array('phrase' => $search_data['phrase']));
        }
        $stat_data['phrase_id'] = empty($phrase_id) ? 0 : $phrase_id;
    }
    if (!empty($stat_data['client_language'])) {
        $is_lang = db_get_field("SELECT lang_code FROM ?:stat_languages WHERE lang_code = ?s", $stat_data['client_language']);
        // If there is not long language code in DB then save short language code
        if (empty($is_lang)) {
            $stat_data['client_language'] = substr($stat_data['client_language'], 0, 2);
        }
    }
    $stat_data['expiry'] = TIME + SESSION_ALIVE_TIME;
    $session_data = fn_check_table_fields($stat_data, 'stat_sessions');
    $sess_id = db_query('INSERT INTO ?:stat_sessions ?e', $session_data);
    // Set the cookie 'stat_uniq_code' to identify unique clients.
    $stat_uniq_code = fn_get_cookie('stat_uniq_code');
    if (!empty($sess_id) && (empty($stat_uniq_code) || $stat_uniq_code >= $sess_id)) {
        $stat_uniq_code = $sess_id;
    }
    fn_set_cookie('stat_uniq_code', $stat_uniq_code, 365 * 24 * 3600);
    if (!empty($sess_id)) {
        db_query('UPDATE ?:stat_sessions SET ?u WHERE sess_id = ?i', array('uniq_code' => $stat_uniq_code), $sess_id);
    }
    return $sess_id;
}
Exemple #18
0
function fn_reward_points_clone_product($from_product_id, $to_product_id)
{
    $reward_points = fn_get_reward_points($from_product_id);
    if (!empty($reward_points)) {
        foreach ($reward_points as $v) {
            $_data = fn_check_table_fields($v, 'reward_points');
            fn_add_reward_points($_data, $to_product_id, PRODUCT_REWARD_POINTS);
        }
    }
    $fake = '';
    $price_in_points = fn_get_price_in_points($from_product_id, $fake);
    fn_add_price_in_points(array('point_price' => $price_in_points), $to_product_id);
}
Exemple #19
0
function fn_form_cart($order_id, &$cart, &$auth)
{
    $order_info = fn_get_order_info($order_id, false, false);
    // Fill the cart
    foreach ($order_info['items'] as $_id => $item) {
        $_item = array($item['product_id'] => array('amount' => $item['amount'], 'product_options' => @$item['extra']['product_options'], 'price' => $item['original_price'], 'stored_discount' => 'Y', 'stored_price' => 'Y', 'discount' => @$item['extra']['discount'], 'original_amount' => $item['amount'], 'original_product_data' => array('cart_id' => $_id, 'amount' => $item['amount'])));
        if (isset($item['extra'])) {
            $_item[$item['product_id']]['extra'] = $item['extra'];
        }
        fn_add_product_to_cart($_item, $cart, $auth);
    }
    // Restore custom files
    $dir_path = DIR_CUSTOM_FILES . 'order_data/' . $order_id;
    if (is_dir($dir_path)) {
        fn_mkdir(DIR_CUSTOM_FILES . 'sess_data');
        fn_copy($dir_path, DIR_CUSTOM_FILES . 'sess_data');
    }
    $cart['payment_id'] = $order_info['payment_id'];
    $cart['stored_taxes'] = 'Y';
    $cart['stored_discount'] = 'Y';
    $cart['taxes'] = $order_info['taxes'];
    $cart['promotions'] = !empty($order_info['promotions']) ? $order_info['promotions'] : array();
    $cart['shipping'] = !empty($order_info['shipping']) ? $order_info['shipping'] : array();
    $cart['stored_shipping'] = array();
    foreach ($cart['shipping'] as $sh_id => $v) {
        if (!empty($v['rates'])) {
            $cart['stored_shipping'][$sh_id] = array_sum($v['rates']);
        }
    }
    $cart['notes'] = $order_info['notes'];
    $cart['payment_info'] = @$order_info['payment_info'];
    // Add order discount
    if (floatval($order_info['subtotal_discount'])) {
        $cart['stored_subtotal_discount'] = 'Y';
        $cart['subtotal_discount'] = $cart['original_subtotal_discount'] = fn_format_price($order_info['subtotal_discount']);
    }
    // Fill the cart with the coupons
    if (!empty($order_info['coupons'])) {
        $cart['coupons'] = $order_info['coupons'];
    }
    // Set the customer if exists
    $_data = array();
    if (!empty($order_info['user_id'])) {
        $_data = db_get_row("SELECT user_id, user_login as login FROM ?:users WHERE user_id = ?i", $order_info['user_id']);
    }
    $auth = fn_fill_auth($_data, array(), false, 'C');
    $auth['tax_exempt'] = $order_info['tax_exempt'];
    // Fill customer info
    $cart['user_data'] = fn_check_table_fields($order_info, 'user_profiles');
    $cart['user_data'] = fn_array_merge(fn_check_table_fields($order_info, 'users'), $cart['user_data']);
    if (!empty($order_info['fields'])) {
        $cart['user_data']['fields'] = $order_info['fields'];
    }
    fn_add_user_data_descriptions($cart['user_data']);
    fn_set_hook('form_cart', $order_info, $cart);
}
Exemple #20
0
function fn_altteam_review_attributes_redirect($location)
{
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        if ($_REQUEST['dispatch'] == 'discussion.add') {
            //			$view_mail = Registry::get('view_mail');
            $post_data = Registry::get('view')->getTemplateVars('post_data');
            $rating_data = $post_data['attributes'] ? $post_data['attributes'] : array();
            foreach ($rating_data as $attr_id => $rate) {
                $_data['rating'] = $rate;
                $_data['attr_id'] = $attr_id;
                $_data['post_id'] = $post_data['post_id'];
                $_data = fn_check_table_fields($_data, 'review_rating');
                db_query("REPLACE INTO ?:review_rating ?e", $_data);
            }
        } elseif ($_REQUEST['dispatch'] == 'discussion.delete') {
            if (AREA == 'A' && !empty($_REQUEST['delete_posts']) && is_array($_REQUEST['delete_posts'])) {
                foreach ($_REQUEST['delete_posts'] as $p_id => $v) {
                    db_query("DELETE FROM ?:review_rating WHERE post_id = ?i", $p_id);
                    db_query("DELETE FROM ?:review_likes WHERE post_id = ?i", $p_id);
                }
            }
        }
    }
}
Exemple #21
0
function fn_giftreg_add_field_variants($variants = array(), $field_id = 0)
{
    if (empty($variants) || empty($field_id)) {
        return false;
    }
    foreach ($variants as $_v) {
        if (empty($_v['description'])) {
            continue;
        }
        // Insert main data
        $_data = fn_check_table_fields($_v, 'giftreg_field_variants');
        $_data['field_id'] = $field_id;
        $variant_id = db_query("INSERT INTO ?:giftreg_field_variants ?e", $_data);
        // Insert descriptions
        $_data = array('object_id' => $variant_id, 'object_type' => 'V', 'description' => $_v['description']);
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:giftreg_descriptions ?e", $_data);
        }
    }
    return true;
}
// $Id: gift_certificates.php 10229 2010-07-27 14:21:39Z 2tl $
//
if (!defined('AREA')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Define trusted variables that shouldn't be stripped
    fn_trusted_vars('gift_cert_data');
    if ($mode == 'add') {
        if (!empty($_REQUEST['gift_cert_data'])) {
            do {
                $code = fn_generate_gift_certificate_code();
            } while (true == fn_check_gift_certificate_code($code));
            $gift_cert_data = $_REQUEST['gift_cert_data'];
            fn_correct_gift_certificate($gift_cert_data);
            $_data = fn_check_table_fields($gift_cert_data, 'gift_certificates');
            $_data = fn_array_merge($_data, array('gift_cert_code' => $code, 'timestamp' => TIME));
            if (!empty($_data['products'])) {
                $_data['products'] = serialize($_data['products']);
            }
            $gift_cert_id = db_query("INSERT INTO ?:gift_certificates ?e", $_data);
            $gift_cert_data = fn_get_gift_certificate_info($gift_cert_id);
            fn_gift_certificate_notification($gift_cert_data, fn_get_notification_rules($_REQUEST));
            $suffix = ".update?gift_cert_id={$gift_cert_id}";
        }
    }
    if ($mode == 'update') {
        if (!empty($_REQUEST['gift_cert_data'])) {
            $gift_cert_data = $_REQUEST['gift_cert_data'];
            fn_correct_gift_certificate($gift_cert_data);
            if (!isset($gift_cert_data['products'])) {
Exemple #23
0
function fn_add_partner_action($action, $banner_id, $partner_id, $customer_id = '', $additional_data = '', $amount = '0', $multi_tier_account = false)
{
    $auth =& $_SESSION['auth'];
    $payout_types =& Registry::get('payout_types');
    if (empty($action) || empty($partner_id)) {
        return false;
    }
    if (!$multi_tier_account && AREA != 'A') {
        fn_set_partner_cookie($partner_id);
    }
    $data = array();
    $data['banner_id'] = $banner_id;
    $data['partner_id'] = $partner_id;
    $data['customer_id'] = $customer_id;
    $data['date'] = TIME;
    $data['ip'] = $action == 'init_balance' ? '' : $_SERVER['REMOTE_ADDR'];
    $data['action'] = $action;
    $data['approved'] = Registry::get('addons.affiliate.automatic_approval_commissions') == 'Y' && $action != 'sale' ? 'Y' : 'N';
    $data['plan_id'] = db_get_field("SELECT plan_id FROM ?:aff_partner_profiles WHERE user_id = ?i", $partner_id);
    if (empty($data['plan_id'])) {
        return false;
    }
    if ($multi_tier_account) {
        $data['amount'] = round($amount, 2);
    } elseif (!empty($payout_types[$action])) {
        $plan_data = fn_get_affiliate_plan_data($data['plan_id']);
        $payout_values = $plan_data['payout_types'];
        $p_value = false;
        if ($action == 'sale' && !empty($additional_data['P'])) {
            $p_value = fn_get_payout_value($data['plan_id'], $additional_data['P'], 'product');
            if ($p_value === false) {
                $product_data = fn_get_product_data($additional_data['P'], $auth);
                if (!empty($product_data['main_category'])) {
                    $p_value = fn_get_payout_value($data['plan_id'], $product_data['main_category'], 'category');
                }
            }
        } elseif ($action == 'use_coupon' && !empty($additional_data['D'])) {
            $p_value = fn_get_payout_value($data['plan_id'], $additional_data['D'], 'promotion');
        }
        if ($p_value === false) {
            if (empty($payout_values[$action]) || $action != 'init_balance' && (empty($payout_types[$action]['default']) || $payout_types[$action]['default'] != 'Y')) {
                $p_value = array('value' => 0, 'value_type' => 'A');
            } else {
                $p_value = $payout_values[$action];
            }
        }
        $data['amount'] = @$p_value['value_type'] == 'A' ? @$p_value['value'] : $amount * $p_value['value'] / 100;
        $data['amount'] = round($data['amount'], 2);
    }
    $data = fn_check_table_fields($data, 'aff_partner_actions');
    $action_id = db_query("INSERT INTO ?:aff_partner_actions ?e", $data);
    if (!empty($action_id)) {
        if (Registry::get('addons.affiliate.automatic_approval_commissions') == 'Y' && $action != 'sale') {
            fn_update_partner_balance($data['partner_id'], $data['amount'], '+');
        }
        if (!empty($additional_data) && is_array($additional_data)) {
            foreach ($additional_data as $object_type => $object_data) {
                $object_type = substr($object_type, 0, 1);
                $object_type = strtoupper($object_type);
                $_data = array('action_id' => $action_id, 'object_data' => $object_data, 'object_type' => $object_type);
                $_data = fn_check_table_fields($_data, 'aff_action_links');
                db_query("INSERT INTO ?:aff_action_links ?e", $_data);
            }
        }
        if (!$multi_tier_account && $action != 'init_balance') {
            fn_add_commissions_to_multi_tier_affiliates($action, $data['partner_id'], array('commission' => $data['amount'], 'price' => round($amount, 2)), $action_id, $data['customer_id'], $data['banner_id'], $additional_data);
        }
    }
    return true;
}
                fn_delete_banner($banner_id);
            }
            if (!empty($banners_names)) {
                $banners_names = '&nbsp;-&nbsp;' . implode('<br />&nbsp;-&nbsp;', $banners_names);
                fn_set_notification('N', fn_get_lang_var('information'), fn_get_lang_var('deleted_banners') . ':<br />' . $banners_names);
            }
        } else {
            fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('error_no_data'));
        }
        $suffix = ".manage?banner_type={$_REQUEST['banner_type']}&link_to={$_REQUEST['link_to']}";
    }
    if ($mode == 'm_update') {
        if (!empty($_REQUEST['banners_data']) && is_array($_REQUEST['banners_data'])) {
            $banners_data = $_REQUEST['banners_data'];
            foreach ($banners_data as $banner_id => $b_data) {
                $_b_data = fn_check_table_fields($b_data, 'aff_banners');
                db_query("UPDATE ?:aff_banners SET ?u WHERE banner_id = ?i", $_b_data, $banner_id);
            }
        }
        $suffix = ".manage&banner_type={$_REQUEST['banner_type']}&link_to={$_REQUEST['link_to']}";
    }
    if ($mode == 'update') {
        $banner_id = fn_update_banner($_REQUEST['banner'], $_REQUEST['banner_id'], DESCR_SL);
        $suffix = ".update?banner_id={$banner_id}";
    }
    return array(CONTROLLER_STATUS_OK, "banners_manager{$suffix}");
}
if ($mode == 'update') {
    $banner = fn_get_aff_banner_data($_REQUEST['banner_id'], DESCR_SL);
    if (empty($banner)) {
        return array(CONTROLLER_STATUS_NO_PAGE);
Exemple #25
0
                    continue;
                } else {
                    $v['currency_code'] = strtoupper($v['currency_code']);
                }
                if (empty($v['coefficient']) || floatval($v['coefficient']) <= 0) {
                    fn_set_notification('W', fn_get_lang_var('warning'), fn_get_lang_var('currency_rate_greater_than_null'));
                    continue;
                }
                $is_exists = db_get_field("SELECT COUNT(*) FROM ?:currencies WHERE currency_code = ?s", $v['currency_code']);
                if (!empty($is_exists)) {
                    $msg = fn_get_lang_var('error_currency_exists');
                    $msg = str_replace('[code]', $v['currency_code'], $msg);
                    fn_set_notification('E', fn_get_lang_var('error'), $msg);
                    continue;
                }
                $__data = fn_check_table_fields($v, 'currencies');
                db_query("INSERT INTO ?:currencies ?e", $__data);
                fn_create_description('currency_descriptions', "currency_code", $v['currency_code'], $_REQUEST['currency_description'][$k]);
            }
        }
    }
    return array(CONTROLLER_STATUS_OK, "currencies.manage");
}
// ---------------------- GET routines ---------------------------------------
if ($mode == 'manage') {
    $currencies = db_get_array("SELECT a.*, b.description FROM ?:currencies as a LEFT JOIN ?:currency_descriptions as b ON a.currency_code = b.currency_code AND lang_code = ?s ORDER BY position", DESCR_SL);
    $view->assign('currencies_data', $currencies);
} elseif ($mode == 'delete') {
    if (!empty($_REQUEST['currency_code'])) {
        if ($_REQUEST['currency_code'] != CART_PRIMARY_CURRENCY) {
            db_query("DELETE FROM ?:currencies WHERE currency_code = ?s", $_REQUEST['currency_code']);