fn_delete_profile_field($_REQUEST['field_id']); } } return array(CONTROLLER_STATUS_OK, 'profile_fields' . $_suffix); } if ($mode == 'manage') { $profile_fields = fn_get_profile_fields('ALL', array(), DESCR_SL); Tygh::$app['view']->assign('profile_fields_areas', fn_profile_fields_areas()); Tygh::$app['view']->assign('profile_fields', $profile_fields); } elseif ($mode == 'update' || $mode == 'add') { if ($mode == 'update') { $params['field_id'] = $_REQUEST['field_id']; $field = fn_get_profile_fields('ALL', array(), DESCR_SL, $params); Tygh::$app['view']->assign('field', $field); } Tygh::$app['view']->assign('profile_fields_areas', fn_profile_fields_areas()); } // -------------- Functions ---------------- function fn_add_field_values($values = array(), $field_id = 0) { if (empty($values) || empty($field_id)) { return false; } foreach ($values as $_v) { if (empty($_v['description'])) { continue; } // Insert main data $_v['field_id'] = $field_id; $value_id = db_query("INSERT INTO ?:profile_field_values ?e", $_v); // Insert descriptions
fn_delete_profile_field($_REQUEST['field_id']); } } return array(CONTROLLER_STATUS_OK, 'profile_fields' . $_suffix); } if ($mode == 'manage') { $profile_fields = fn_get_profile_fields('ALL', array(), DESCR_SL); Registry::get('view')->assign('profile_fields_areas', fn_profile_fields_areas()); Registry::get('view')->assign('profile_fields', $profile_fields); } elseif ($mode == 'update' || $mode == 'add') { if ($mode == 'update') { $params['field_id'] = $_REQUEST['field_id']; $field = fn_get_profile_fields('ALL', array(), DESCR_SL, $params); Registry::get('view')->assign('field', $field); } Registry::get('view')->assign('profile_fields_areas', fn_profile_fields_areas()); } // -------------- Functions ---------------- function fn_add_field_values($values = array(), $field_id = 0) { if (empty($values) || empty($field_id)) { return false; } foreach ($values as $_v) { if (empty($_v['description'])) { continue; } // Insert main data $_v['field_id'] = $field_id; $value_id = db_query("INSERT INTO ?:profile_field_values ?e", $_v); // Insert descriptions
} } return array(CONTROLLER_STATUS_OK, "profile_fields.manage"); } if ($mode == 'manage') { $profile_fields = db_get_hash_multi_array("SELECT ?:profile_fields.*, IF(?:profile_fields.section = 'C', 1, IF(?:profile_fields.section = 'B', 2, 3)) as sec, ?:profile_field_descriptions.description FROM ?:profile_fields LEFT JOIN ?:profile_field_descriptions ON ?:profile_field_descriptions.object_id = ?:profile_fields.field_id AND ?:profile_field_descriptions.object_type = 'F' AND ?:profile_field_descriptions.lang_code = ?s ORDER BY sec, ?:profile_fields.position", array('section', 'field_id'), DESCR_SL); if (!empty($profile_fields)) { foreach ($profile_fields as $section => $fields) { foreach ($fields as $k => $v) { if ($v['field_type'] == 'S' || $v['field_type'] == 'R') { $profile_fields[$section][$k]['values'] = db_get_array("SELECT ?:profile_field_values.*, ?:profile_field_descriptions.description FROM ?:profile_field_values LEFT JOIN ?:profile_field_descriptions ON ?:profile_field_descriptions.object_id = ?:profile_field_values.value_id AND ?:profile_field_descriptions.object_type = 'V' AND ?:profile_field_descriptions.lang_code = ?s WHERE ?:profile_field_values.field_id = ?i ORDER BY ?:profile_field_values.position", DESCR_SL, $v['field_id']); } } } } $view->assign('profile_fields_areas', fn_profile_fields_areas()); $view->assign('profile_fields', $profile_fields); } elseif ($mode == 'delete') { if (!empty($_REQUEST['field_id'])) { fn_delete_profile_field($_REQUEST['field_id']); } if (!empty($_REQUEST['value_id'])) { db_query("DELETE FROM ?:profile_field_descriptions WHERE object_id = ?i AND object_type = 'V'", $_REQUEST['value_id']); db_query("DELETE FROM ?:profile_field_values WHERE value_id = ?i", $_REQUEST['value_id']); } if (defined('AJAX_REQUEST')) { exit; } return array(CONTROLLER_STATUS_REDIRECT, "profile_fields.manage"); } // -------------- Functions ----------------