Ejemplo n.º 1
0
function fn_settings_actions_addons_banners_banner_multilang($new_value, $old_value)
{
    if ($new_value == 'N') {
        $lang_codes = Languages::getAll();
        unset($lang_codes[DEFAULT_LANGUAGE]);
        $banners_multilang = array();
        foreach ($lang_codes as $lang_code => $lang_data) {
            list($banners) = fn_get_banners(array(), $lang_code);
            foreach ($banners as $banner) {
                $banners_multilang[$lang_code][$banner['banner_id']] = $banner;
            }
        }
        list($banners) = fn_get_banners(array(), DEFAULT_LANGUAGE);
        foreach ($banners as $banner) {
            if ($banner['type'] != 'G') {
                continue;
            }
            $main_image_id = !empty($banner['main_pair']['image_id']) ? $banner['main_pair']['image_id'] : 0;
            foreach ($lang_codes as $lang_code => $lang_data) {
                $banner_lang = $banners_multilang[$lang_code][$banner['banner_id']];
                $lang_image_id = !empty($banner_lang['main_pair']['image_id']) ? $banner_lang['main_pair']['image_id'] : 0;
                if ($lang_image_id != 0 && ($main_image_id == 0 || $main_image_id != $lang_image_id)) {
                    fn_delete_image($lang_image_id, $banner_lang['main_pair']['pair_id'], 'promo');
                    $lang_image_id = 0;
                }
                if ($lang_image_id == 0 && $main_image_id != 0) {
                    $data_banner_image = array('banner_id' => $banner['banner_id'], 'lang_code' => $lang_code);
                    $banner_image_id = db_query("INSERT INTO ?:banner_images ?e", $data_banner_image);
                    fn_add_image_link($banner_image_id, $banner['main_pair']['pair_id']);
                    $data_desc = array('description' => empty($banner['main_pair']['icon']['alt']) ? '' : $banner['main_pair']['icon']['alt'], 'object_holder' => 'images');
                    fn_create_description('common_descriptions', 'object_id', $main_image_id, $data_desc);
                }
                db_query("UPDATE ?:banner_descriptions SET url = ?s WHERE banner_id = ?i", $banner['url'], $banner['banner_id']);
            }
        }
    }
    return true;
}
Ejemplo n.º 2
0
function fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id = 0, $object_type = 'product_lists', $object_ids = array(), $update_alt_desc = true, $lang_code = CART_LANGUAGE)
{
    $pair_ids = array();
    if (!empty($pairs_data)) {
        foreach ($pairs_data as $k => $p_data) {
            $data = array();
            $pair_id = !empty($p_data['pair_id']) ? $p_data['pair_id'] : 0;
            $o_id = !empty($object_id) ? $object_id : (!empty($p_data['object_id']) ? $p_data['object_id'] : 0);
            if ($o_id == 0 && !empty($object_ids[$k])) {
                $o_id = $object_ids[$k];
            } elseif (!empty($object_ids) && empty($object_ids[$k])) {
                continue;
            }
            // Check if main pair is exists
            if (empty($pair_id) && !empty($p_data['type']) && $p_data['type'] == 'M') {
                $pair_data = db_get_row("SELECT pair_id, image_id, detailed_id FROM ?:images_links WHERE object_id = ?i AND object_type = ?s AND type = ?s", $o_id, $object_type, $p_data['type']);
                $pair_id = !empty($pair_data['pair_id']) ? $pair_data['pair_id'] : 0;
            } else {
                $pair_data = db_get_row("SELECT image_id, detailed_id FROM ?:images_links WHERE pair_id = ?i", $pair_id);
                if (empty($pair_data)) {
                    $pair_id = 0;
                }
            }
            // Update detailed image
            if (!empty($detailed[$k]) && !empty($detailed[$k]['size'])) {
                if (fn_get_image_size($detailed[$k]['path'])) {
                    $data['detailed_id'] = fn_update_image($detailed[$k], !empty($pair_data['detailed_id']) ? $pair_data['detailed_id'] : 0, 'detailed');
                }
            }
            // Update icon
            if (!empty($icons[$k]) && !empty($icons[$k]['size'])) {
                if (fn_get_image_size($icons[$k]['path'])) {
                    $data['image_id'] = fn_update_image($icons[$k], !empty($pair_data['image_id']) ? $pair_data['image_id'] : 0, $object_type);
                }
            }
            // Update alt descriptions
            if ((empty($data) && !empty($pair_id) || !empty($data)) && $update_alt_desc == true) {
                $image_ids = array();
                if (!empty($pair_id)) {
                    $image_ids = db_get_row("SELECT image_id, detailed_id FROM ?:images_links WHERE pair_id = ?i", $pair_id);
                }
                $image_ids = fn_array_merge($image_ids, $data);
                $fields = array('detailed', 'image');
                foreach ($fields as $field) {
                    if (!empty($image_ids[$field . '_id']) && isset($p_data[$field . '_alt'])) {
                        if (!is_array($p_data[$field . '_alt'])) {
                            $_data = array('description' => empty($p_data[$field . '_alt']) ? '' : trim($p_data[$field . '_alt']), 'object_holder' => 'images');
                            // check, if this is new record, create new descriptions for all languages
                            $is_exists = db_get_field('SELECT object_id FROM ?:common_descriptions WHERE object_id = ?i AND lang_code = ?s AND object_holder = ?s', $image_ids[$field . '_id'], $lang_code, 'images');
                            if (!$is_exists) {
                                fn_create_description('common_descriptions', 'object_id', $image_ids[$field . '_id'], $_data);
                            } else {
                                db_query('UPDATE ?:common_descriptions SET ?u WHERE object_id = ?i AND lang_code = ?s AND object_holder = ?s', $_data, $image_ids[$field . '_id'], $lang_code, 'images');
                            }
                        } else {
                            foreach ($p_data[$field . '_alt'] as $lc => $_v) {
                                $_data = array('object_id' => $image_ids[$field . '_id'], 'description' => empty($_v) ? '' : trim($_v), 'lang_code' => $lc, 'object_holder' => 'images');
                                db_query("REPLACE INTO ?:common_descriptions ?e", $_data);
                            }
                        }
                    }
                }
            }
            if (empty($data)) {
                continue;
            }
            // Pair is exists
            $data['position'] = !empty($p_data['position']) ? $p_data['position'] : 0;
            // set data position
            if (!empty($pair_id)) {
                db_query("UPDATE ?:images_links SET ?u WHERE pair_id = ?i", $data, $pair_id);
            } else {
                $data['type'] = $p_data['type'];
                // set link type
                $data['object_id'] = $o_id;
                // assign pair to object
                $data['object_type'] = $object_type;
                $pair_id = db_query("INSERT INTO ?:images_links ?e", $data);
            }
            $pairs_data[$k]['pair_id'] = $pair_id;
            $pair_ids[] = $pair_id;
        }
    }
    fn_set_hook('update_image_pairs', $pair_ids, $icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, $update_alt_desc, $lang_code);
    return $pair_ids;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
function fn_sales_report_update_table($table_data, $table_id = 0, $lang_code = DESCR_SL)
{
    if ($table_data['type'] == 'P') {
        $table_data['interval_id'] = '1';
    }
    if (empty($table_id)) {
        $table_id = db_query("INSERT INTO ?:sales_reports_tables ?e", $table_data);
        fn_create_description('sales_reports_table_descriptions', "table_id", $table_id, $table_data);
        // Create parameters
        $_data = $table_data['elements'];
        $_data['table_id'] = $table_id;
        $_data['report_id'] = $table_data['report_id'];
        $_data['element_hash'] = fn_generate_element_hash($table_id, $_data['element_id'], '');
        db_query("INSERT INTO ?:sales_reports_table_elements ?e", $_data);
    } else {
        db_query('UPDATE ?:sales_reports_tables SET ?u WHERE table_id = ?i', $table_data, $table_id);
        db_query('UPDATE ?:sales_reports_table_descriptions SET ?u WHERE table_id = ?i AND lang_code = ?s', $table_data, $table_id, $lang_code);
        // Update parameters
        foreach ($table_data['elements'] as $k => $v) {
            if ($v['element_id'] == '4' && $table_data['interval_id'] != '1') {
                db_query("UPDATE ?:sales_reports_tables SET interval_id = 1 WHERE table_id = ?i", $table_id);
                fn_set_notification('W', __('warning'), __('text_status_is_float'));
            }
            db_query('UPDATE ?:sales_reports_table_elements SET ?u WHERE table_id = ?i AND element_hash = ?s', $v, $table_id, $k);
            if ($table_data['type'] != 'T' && $v['limit_auto'] > 25) {
                db_query("UPDATE ?:sales_reports_table_elements SET limit_auto = 25 WHERE table_id = ?i AND element_hash = ?s", $table_id, $k);
                fn_set_notification('W', __('warning'), __('text_max_limit_of_parameters'));
            }
        }
    }
    foreach ($table_data['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);
        }
    }
    return $table_id;
}
Ejemplo n.º 5
0
if (!defined('AREA')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Define trusted variables that shouldn't be stripped
    fn_trusted_vars('configurator_group_data');
    $suffix = '';
    //************************************ CONFIGURATOR STEPS **********************************\\
    //
    // Add new configurator step
    //
    if ($mode == 'add_steps' && isset($_REQUEST['add_step_data'])) {
        foreach ($_REQUEST['add_step_data'] as $v) {
            if (!empty($v['step_name'])) {
                $step_id = db_query("INSERT INTO ?:conf_steps ?e", $v);
                fn_create_description('conf_step_descriptions', 'step_id', $step_id, $v);
            }
        }
        $suffix = ".manage?selected_section=steps";
    }
    //
    //  Delete configurator step
    //
    if ($mode == 'delete_step') {
        if (is_array($_REQUEST['delete'])) {
            fn_delete_configurator_steps($_REQUEST['delete']);
        }
        $suffix = ".manage?selected_section=steps";
    }
    //
    //  Update configurator steps
Ejemplo n.º 6
0
/**
 * Creates/Updates currency
 *
 * @param array $currency_data Currency information
 * @param int $currency_id Currency id
 * @param string $lang_code 2-letter language code
 * @return int Currency id
 */
function fn_update_currency($currency_data, $currency_id, $lang_code = DESCR_SL)
{
    /**
     * Updates currency data before updating
     *
     * @param array  $currency_data Currency information
     * @param int    $currency_id   Currency id
     * @param string $lang_code     2-letter language code
     */
    fn_set_hook('update_currency_pre', $currency_data, $currency_id, $lang_code);
    $currency_data['currency_code'] = strtoupper($currency_data['currency_code']);
    $currency_data['coefficient'] = !empty($currency_data['is_primary']) || !isset($currency_data['coefficient']) ? 1 : $currency_data['coefficient'];
    $currency_data['symbol'] = empty($currency_data['symbol']) ? '' : SecurityHelper::sanitizeHtml($currency_data['symbol']);
    if (empty($currency_data['coefficient']) || floatval($currency_data['coefficient']) <= 0) {
        fn_set_notification('W', __('warning'), __('currency_rate_greater_than_null'));
        return false;
    }
    $is_exists = db_get_field("SELECT COUNT(*) FROM ?:currencies WHERE currency_code = ?s AND currency_id <> ?i", $currency_data['currency_code'], $currency_id);
    if (!empty($is_exists)) {
        fn_set_notification('E', __('error'), __('error_currency_exists', array('[code]' => $currency_data['currency_code'])));
        return false;
    }
    if (isset($currency_data['decimals']) && $currency_data['decimals'] > 2) {
        fn_set_notification('W', __('warning'), __('notice_too_many_decimals', array('[DECIMALS]' => $currency_data['decimals'], '[CURRENCY]' => $currency_data['currency_code'])));
    }
    if (!empty($currency_data['is_primary'])) {
        db_query("UPDATE ?:currencies SET is_primary = 'N' WHERE is_primary = 'Y'");
    }
    if (empty($currency_id)) {
        $currency_id = db_query("INSERT INTO ?:currencies ?e", $currency_data);
        fn_create_description('currency_descriptions', 'currency_code', $currency_data['currency_code'], $currency_data);
    } else {
        $old_currency_code = db_get_field("SELECT currency_code FROM ?:currencies WHERE currency_id = ?i", $currency_id);
        db_query("UPDATE ?:currencies SET ?u WHERE currency_id = ?i", $currency_data, $currency_id);
        db_query('UPDATE ?:currency_descriptions SET ?u WHERE currency_code = ?s AND lang_code = ?s', $currency_data, $old_currency_code, $lang_code);
    }
    /**
     * Changes result of currency saving
     *
     * @param array  $currency_data Currency information
     * @param int    $currency_id   Currency id
     * @param string $lang_code     2-letter language code
     * @param int Currency id
     */
    fn_set_hook('update_currency_post', $currency_data, $currency_id, $lang_code, $currency_id);
    return $currency_id;
}
Ejemplo n.º 7
0
 //
 if ($mode == 'table') {
     $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}";
Ejemplo n.º 8
0
                    $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']);
            db_query("DELETE FROM ?:currency_descriptions WHERE currency_code = ?s", $_REQUEST['currency_code']);
            fn_set_notification('N', fn_get_lang_var('congratulations'), fn_get_lang_var('currency_deleted'));