Ejemplo n.º 1
0
/**
 * Update or create profile field. Also can create fields matching.
 *
 * @param array $field_data Array of profile field data
 * @param int $field_id Profile field id to be updated. If empty - new field will be created
 * @param strging $lang_code 2-letters language code
 *
 * @return int $field_id New or updated field id
 */
function fn_update_profile_field($field_data, $field_id, $lang_code = DESCR_SL)
{
    if (empty($field_id)) {
        $add_match = false;
        $field_name = $field_data['field_name'];
        if ($field_data['section'] == 'BS') {
            $field_data['section'] = 'B';
            $field_data['field_name'] = !empty($field_name) ? 'b_' . $field_name : '';
            $add_match = true;
        }
        // Insert main data
        $field_id = db_query("INSERT INTO ?:profile_fields ?e", $field_data);
        // Insert descriptions
        $_data = array('object_id' => $field_id, 'object_type' => 'F', 'description' => $field_data['description']);
        foreach (fn_get_translation_languages() as $_data['lang_code'] => $_v) {
            db_query("INSERT INTO ?:profile_field_descriptions ?e", $_data);
        }
        if (substr_count('SR', $field_data['field_type']) && is_array($field_data['add_values']) && $add_match == false) {
            fn_add_field_values($field_data['add_values'], $field_id);
        }
        if ($add_match == true) {
            $field_data['section'] = 'S';
            $field_data['field_name'] = !empty($field_name) ? 's_' . $field_name : '';
            $field_data['matching_id'] = $field_id;
            // Update match for the billing field
            $s_field_id = fn_update_profile_field($field_data, 0, $lang_code);
            if (!empty($s_field_id)) {
                db_query('UPDATE ?:profile_fields SET matching_id = ?i WHERE field_id = ?i', $s_field_id, $field_id);
            }
        }
    } else {
        db_query("UPDATE ?:profile_fields SET ?u WHERE field_id = ?i", $field_data, $field_id);
        if (!empty($field_data['matching_id']) && $field_data['section'] == 'S') {
            db_query('UPDATE ?:profile_fields SET field_type = ?s WHERE field_id = ?i', $field_data['field_type'], $field_data['matching_id']);
        }
        db_query("UPDATE ?:profile_field_descriptions SET ?u WHERE object_id = ?i AND object_type = 'F' AND lang_code = ?s", $field_data, $field_id, $lang_code);
        if (!empty($field_data['field_type'])) {
            if (strpos('SR', $field_data['field_type']) !== false) {
                if (!empty($field_data['values'])) {
                    foreach ($field_data['values'] as $value_id => $vdata) {
                        db_query("UPDATE ?:profile_field_values SET ?u WHERE value_id = ?i", $vdata, $value_id);
                        db_query("UPDATE ?:profile_field_descriptions SET ?u WHERE object_id = ?i AND object_type = 'V' AND lang_code = ?s", $vdata, $value_id, $lang_code);
                    }
                    // Completely delete removed values
                    $existing_ids = db_get_fields("SELECT value_id FROM ?:profile_field_values WHERE field_id = ?i", $field_id);
                    $val_ids = array_diff($existing_ids, array_keys($field_data['values']));
                    if (!empty($val_ids)) {
                        fn_delete_field_values($field_id, $val_ids);
                    }
                } else {
                    if (isset($field_data['add_values'])) {
                        fn_delete_field_values($field_id);
                    }
                }
                if (!empty($field_data['add_values']) && is_array($field_data['add_values'])) {
                    fn_add_field_values($field_data['add_values'], $field_id);
                }
            } else {
                fn_delete_field_values($field_id);
            }
        }
    }
    return $field_id;
}
Ejemplo n.º 2
0
 if ($mode == 'update') {
     $field_data = $_REQUEST['field_data'];
     $field_id = fn_update_profile_field($field_data, $_REQUEST['field_id'], DESCR_SL);
     $_suffix = '.update?field_id=' . $field_id;
 }
 if ($mode == 'm_update') {
     if (!empty($_REQUEST['fields_data'])) {
         $fields_data = $_REQUEST['fields_data'];
         if (isset($fields_data['email'])) {
             foreach ($fields_data['email'] as $enable_for => $field_id) {
                 $fields_data[$field_id][$enable_for] = 'Y';
             }
             unset($fields_data['email']);
         }
         foreach ($fields_data as $field_id => $data) {
             fn_update_profile_field($data, $field_id, DESCR_SL);
         }
     }
 }
 if ($mode == 'm_delete') {
     if (!empty($_REQUEST['field_ids'])) {
         foreach ($_REQUEST['field_ids'] as $field_id) {
             fn_delete_profile_field($field_id);
         }
     }
     if (!empty($_REQUEST['value_ids'])) {
         foreach ($_REQUEST['value_ids'] as $value_id) {
             db_query("DELETE FROM ?:profile_field_descriptions WHERE object_id = ?i AND object_type = 'V'", $value_id);
             db_query("DELETE FROM ?:profile_field_values WHERE value_id = ?i", $value_id);
         }
     }
/**
 * 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'));
    }
}