Example #1
0
 private static function _removeAddonsSettings($addons)
 {
     $table_fields = fn_get_table_fields('addons');
     if (!isset($table_fields['options'])) {
         $addons_objects = db_get_fields("SELECT object_id FROM ?:settings_objects WHERE section_id IN (SELECT section_id FROM ?:settings_sections WHERE name IN (?a))", $addons);
         if (!empty($addons_objects)) {
             db_query("DELETE FROM ?:settings_descriptions WHERE object_id IN (?a) AND object_type = 'O'", $addons_objects);
             db_query("DELETE FROM ?:settings_variants WHERE object_id IN (?a)", $addons_objects);
             if (db_get_array("SHOW TABLES LIKE '?:settings_vendor_values'")) {
                 db_query("DELETE FROM ?:settings_vendor_values WHERE object_id IN (?a)", $addons_objects);
             }
         }
     }
     return true;
 }
Example #2
0
function fn_fill_user_fields(&$user_data)
{
    $exclude = array('user_login', 'password', 'user_type', 'status', 'cart_content', 'timestamp', 'referer', 'last_login', 'lang_code', 'user_id', 'profile_id', 'profile_type', 'profile_name', 'tax_exempt', 'salt', 'company_id');
    fn_set_hook('fill_user_fields', $exclude);
    $profile_fields = fn_get_table_fields('user_profiles', $exclude);
    $fields = fn_array_merge($profile_fields, fn_get_table_fields('users', $exclude), false);
    $fill = array('b_firstname' => array('firstname', 's_firstname'), 'b_lastname' => array('lastname', 's_lastname'), 's_firstname' => array('b_firstname'), 's_lastname' => array('b_lastname'), 'firstname' => array('b_firstname', 's_firstname'), 'lastname' => array('b_lastname', 's_lastname'));
    foreach ($fill as $k => $v) {
        if (!isset($user_data[$k])) {
            @(list($f, $s) = $v);
            $user_data[$k] = !empty($user_data[$f]) ? $user_data[$f] : (!empty($s) && !empty($user_data[$s]) ? $user_data[$s] : '');
        }
    }
    // Fill empty fields to avoid php notices
    foreach ($fields as $field) {
        if (empty($user_data[$field])) {
            $user_data[$field] = '';
        }
    }
    // Fill address with default data
    if (!fn_is_empty($user_data)) {
        $default = array('s_country' => 'default_country', 'b_country' => 'default_country');
        foreach ($default as $k => $v) {
            if (empty($user_data[$k])) {
                $user_data[$k] = Registry::get('settings.General.' . $v);
            }
        }
    }
    return true;
}
Example #3
0
 /**
  * Clones language depended data from one language to other for $table
  *
  * @param  string $table     table name to clone values
  * @param  string $to_lang   2 letters destination language code
  * @param  string $from_lang 2 letters source language code
  * @return bool   Always true
  */
 public static function cloneLanguageValues($table, $to_lang, $from_lang = CART_LANGUAGE)
 {
     $fields_select = fn_get_table_fields($table, array(), true);
     $fields_insert = fn_get_table_fields($table, array(), true);
     $k = array_search('`lang_code`', $fields_select);
     $fields_select[$k] = db_quote("?s as lang_code", $to_lang);
     db_query("INSERT IGNORE INTO ?:{$table} (" . implode(', ', $fields_insert) . ") " . "SELECT " . implode(', ', $fields_select) . " FROM ?:{$table} WHERE lang_code = ?s", $from_lang);
     return true;
 }
function fn_ult_update_share_objects($share_data)
{
    static $sharing_schema;
    if (empty($sharing_schema) && Registry::get('addons_initiated') === true) {
        $sharing_schema = fn_get_schema('sharing', 'schema');
    }
    foreach ($share_data['share_objects'] as $object_type => $object_data) {
        if (!empty($object_data)) {
            foreach ($object_data as $object_id => $companies) {
                if (empty($companies)) {
                    $companies = array();
                }
                if (!empty($sharing_schema[$object_type]['pre_processing']) && function_exists($sharing_schema[$object_type]['pre_processing'])) {
                    call_user_func_array($sharing_schema[$object_type]['pre_processing'], array('object_id' => $object_id, 'object_type' => $object_type, 'companies' => $companies));
                }
                db_query('DELETE FROM ?:ult_objects_sharing WHERE share_object_id = ?s AND share_object_type = ?s', $object_id, $object_type);
                if (!empty($sharing_schema[$object_type]['table'])) {
                    $company_id = Registry::get('sharing_owner.' . $object_type);
                    if (empty($company_id)) {
                        $fields = fn_get_table_fields($sharing_schema[$object_type]['table']['name']);
                        if (in_array('company_id', $fields)) {
                            $owner_id = db_get_field('SELECT company_id' . ' FROM ?:' . $sharing_schema[$object_type]['table']['name'] . ' WHERE ' . $sharing_schema[$object_type]['table']['key_field'] . ' = ?s', $object_id);
                            if (!in_array($owner_id, $companies)) {
                                $companies[] = $owner_id;
                            }
                        }
                    } else {
                        $companies[] = $company_id;
                    }
                }
                if (!empty($companies)) {
                    $companies = array_unique($companies);
                    $query = array();
                    // Get new object id if it was updated
                    if (!empty($share_data[$object_type][$object_id][$sharing_schema[$object_type]['table']['key_field']])) {
                        $object_id = $share_data[$object_type][$object_id][$sharing_schema[$object_type]['table']['key_field']];
                    }
                    foreach ($companies as $company_id) {
                        if (!empty($company_id)) {
                            $query[] = db_quote('(?s, ?s, ?i)', $object_id, $object_type, $company_id);
                        }
                    }
                    if (!empty($query)) {
                        db_query('REPLACE INTO ?:ult_objects_sharing (share_object_id, share_object_type, share_company_id) VALUES ' . implode(', ', $query));
                    }
                }
                if (!empty($sharing_schema[$object_type]['post_processing']) && function_exists($sharing_schema[$object_type]['post_processing'])) {
                    call_user_func_array($sharing_schema[$object_type]['post_processing'], array('object_id' => $object_id, 'object_type' => $object_type, 'companies' => $companies));
                }
            }
        }
    }
}
/**
 * Enable/disable Temando
 */
function fn_settings_actions_shippings_temando_enabled(&$new_value, $old_value)
{
    if ($new_value == 'Y') {
        $fields = fn_get_table_fields('user_profiles');
        $b_suburb = db_get_field('SHOW COLUMNS FROM ?:user_profiles LIKE ?l', 'b_suburb');
        $s_suburb = db_get_field('SHOW COLUMNS FROM ?:user_profiles LIKE ?l', 's_suburb');
        if (empty($b_suburb)) {
            db_query("ALTER TABLE ?:user_profiles ADD b_suburb varchar(128) NOT NULL AFTER b_zipcode");
        }
        if (empty($s_suburb)) {
            db_query("ALTER TABLE ?:user_profiles ADD s_suburb varchar(128) NOT NULL AFTER s_zipcode");
        }
        $billing_profile_field_id = db_get_field("SELECT field_id FROM ?:profile_fields WHERE field_name = ?s", 'b_suburb');
        if (empty($billing_profile_field_id)) {
            $profile_data = array('field_name' => 'suburb', 'profile_show' => 'Y', 'profile_required' => 'N', 'checkout_show' => 'Y', 'checkout_required' => 'N', 'partner_show' => 'Y', 'partner_required' => 'N', 'field_type' => 'I', 'position' => '170', 'is_default' => 'Y', 'section' => 'BS', 'matching_id' => '', 'class' => '', 'description' => 'Suburb', 'add_values' => array(array('position' => '', 'description' => '')));
            $profile_field = array();
            $profile_field['b'] = fn_update_profile_field($profile_data, 0);
            $profile_field['s'] = db_get_field("SELECT field_id FROM ?:profile_fields WHERE field_name = ?s", 's_suburb');
        }
        //We should just update settings if they was created previously, and create new setting othervise.
        $setting_data_c_suburb = array('name' => 'company_suburb', 'edition_type' => 'ROOT,ULT:VENDOR', 'section_id' => 5, 'type' => 'I', 'position' => 41, 'is_global' => 'Y');
        if (Settings::instance()->isExists('company_suburb', 'Company')) {
            $setting_data_c_suburb['object_id'] = Settings::instance()->getId('company_suburb', 'Company');
        } else {
            $descriptions_c = array();
            foreach (fn_get_translation_languages() as $lang_code => $lang_value) {
                $descriptions_c[] = array('value' => 'Company suburb', 'object_type' => 'O', 'lang_code' => $lang_code);
            }
        }
        Settings::instance()->update($setting_data_c_suburb, null, isset($descriptions_c) ? $descriptions_c : null);
        $setting_data_d_suburb = array('name' => 'default_suburb', 'edition_type' => 'ROOT,ULT:VENDOR', 'section_id' => 2, 'type' => 'I', 'position' => 115, 'is_global' => 'Y');
        if (Settings::instance()->isExists('default_suburb', 'General')) {
            $setting_data_d_suburb['object_id'] = Settings::instance()->getId('default_suburb', 'General');
        } else {
            $descriptions_d = array();
            foreach (fn_get_translation_languages() as $lang_code => $lang_value) {
                $descriptions_d[] = array('value' => 'Default suburb', 'object_type' => 'O', 'lang_code' => $lang_code);
            }
        }
        Settings::instance()->update($setting_data_d_suburb, null, isset($descriptions_d) ? $descriptions_d : null);
    } else {
        //Disable settings
        $c_id = Settings::instance()->getId('company_suburb', 'Company');
        Settings::instance()->update(array('object_id' => $c_id, 'edition_type' => 'NONE'));
        $d_id = Settings::instance()->getId('default_suburb', 'General');
        Settings::instance()->update(array('object_id' => $d_id, 'edition_type' => 'NONE'));
    }
}
Example #6
0
    //
    // Add languages
    //
    if ($mode == 'add_languages') {
        $new_language = $_REQUEST['new_language'];
        if (!empty($new_language['lang_code']) && !empty($new_language['name'])) {
            $is_exists = db_get_field("SELECT COUNT(*) FROM ?:languages WHERE lang_code = ?s", $new_language['lang_code']);
            if (empty($is_exists)) {
                db_query("INSERT INTO ?:languages ?e", $new_language);
                // Adding new language descriptions for all objects
                $db_descr_tables = db_get_fields("SHOW TABLES LIKE '%_descriptions'");
                $db_descr_tables[] = 'language_values';
                $db_descr_tables[] = 'product_features_values';
                foreach ($db_descr_tables as $table) {
                    $table = str_replace(TABLE_PREFIX, '', $table);
                    $fields_insert = $fields_select = fn_get_table_fields($table, array(), true);
                    $k = array_search('`lang_code`', $fields_select);
                    $fields_select[$k] = db_quote("?s as lang_code", $new_language['lang_code']);
                    db_query("REPLACE INTO ?:{$table} (" . implode(', ', $fields_insert) . ") SELECT " . implode(', ', $fields_select) . " FROM ?:{$table} WHERE lang_code = 'EN'");
                }
            } else {
                fn_set_notification('E', fn_get_lang_var('error'), str_replace('[code]', $new_language['lang_code'], fn_get_lang_var('error_lang_code_exists')));
            }
        }
    }
    $q = empty($_REQUEST['q']) ? '' : $_REQUEST['q'];
    return array(CONTROLLER_STATUS_OK, "languages.manage?q={$q}");
}
//
// Get language variables values
//
Example #7
0
/**
 * Check if passed data corresponds columns in table and remove unnecessary data
 *
 * @param array $data data for compare
 * @param array $table_name table name
 * @return mixed array with filtered data or false if fails
 */
function fn_check_table_fields($data, $table_name)
{
    $_fields = fn_get_table_fields($table_name);
    if (is_array($_fields)) {
        foreach ($data as $k => $v) {
            if (!in_array($k, $_fields)) {
                unset($data[$k]);
            }
        }
        if (func_num_args() > 2) {
            for ($i = 2; $i < func_num_args(); $i++) {
                unset($data[func_get_arg($i)]);
            }
        }
        return $data;
    }
    return false;
}
Example #8
0
function fn_fill_user_fields(&$user_data)
{
    $exclude = array('user_login', 'password', 'user_type', 'status', 'cart_content', 'timestamp', 'referer', 'last_login', 'card_name', 'card_type', 'card_expire', 'card_cvv2', 'lang_code', 'user_id', 'profile_id', 'profile_type', 'profile_name', 'tax_exempt');
    fn_set_hook('fill_user_fields', $exclude);
    $profile_fields = fn_get_table_fields('user_profiles', $exclude);
    $fields = fn_array_merge($profile_fields, fn_get_table_fields('users', $exclude), false);
    $fill = array('b_firstname' => array('firstname', 's_firstname'), 'b_lastname' => array('lastname', 's_lastname'), 'b_title' => array('title', 's_title'), 's_firstname' => array('b_firstname'), 's_lastname' => array('b_lastname'), 's_title' => array('b_title'), 'firstname' => array('b_firstname', 's_firstname'), 'lastname' => array('b_lastname', 's_lastname'), 'title' => array('b_title', 's_title'));
    foreach ($fill as $k => $v) {
        if (!isset($user_data[$k])) {
            @(list($f, $s) = $v);
            $user_data[$k] = !empty($user_data[$f]) ? $user_data[$f] : (!empty($s) && !empty($user_data[$s]) ? $user_data[$s] : '');
        }
    }
    // Fill empty fields to avoid php notices
    foreach ($fields as $field) {
        if (empty($user_data[$field])) {
            $user_data[$field] = '';
        }
    }
    // Fill address with default data
    if (!fn_is_empty($user_data)) {
        $default = array('s_country' => 'default_country', 'b_country' => 'default_country');
        foreach ($default as $k => $v) {
            if (empty($user_data[$k])) {
                $user_data[$k] = Registry::get('settings.General.' . $v);
            }
        }
    }
    // Reformat additional fields
    if (!empty($user_data['fields'])) {
        foreach ($user_data['fields'] as $field_id => $value) {
            if (substr_count($value, '/') == 2) {
                // FIXME: it's date field
                $user_data['fields'][$field_id] = fn_parse_date($value);
            }
        }
    }
    return true;
}