root / trunk / phpBB / includes / functions_profile_fields.php
History | View | Annotate | Download (34.1 kB)
| 1 | 4740 | acydburn | <?php
|
|---|---|---|---|
| 2 | 8142 | acydburn | /**
|
| 3 | 5114 | acydburn | * |
| 4 | 5114 | acydburn | * @package phpBB3 |
| 5 | 8142 | acydburn | * @copyright (c) 2005 phpBB Group |
| 6 | 11653 | git-gate | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
| 7 | 5114 | acydburn | * |
| 8 | 5114 | acydburn | */ |
| 9 | 4740 | acydburn | |
| 10 | 5114 | acydburn | /**
|
| 11 | 8142 | acydburn | * @ignore |
| 12 | 8142 | acydburn | */ |
| 13 | 8142 | acydburn | if (!defined('IN_PHPBB')) |
| 14 | 8142 | acydburn | {
|
| 15 | 8142 | acydburn | exit;
|
| 16 | 8142 | acydburn | } |
| 17 | 8142 | acydburn | |
| 18 | 8142 | acydburn | /**
|
| 19 | 6058 | acydburn | * Custom Profile Fields |
| 20 | 5114 | acydburn | * @package phpBB3 |
| 21 | 5114 | acydburn | */ |
| 22 | 4740 | acydburn | class custom_profile |
| 23 | 4740 | acydburn | {
|
| 24 | 7943 | kellanved | var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date'); |
| 25 | 4984 | acydburn | var $profile_cache = array(); |
| 26 | 4740 | acydburn | var $options_lang = array(); |
| 27 | 4740 | acydburn | |
| 28 | 5135 | acydburn | /**
|
| 29 | 5965 | acydburn | * Assign editable fields to template, mode can be profile (for profile change) or register (for registration) |
| 30 | 5965 | acydburn | * Called by ucp_profile and ucp_register |
| 31 | 6312 | acydburn | * @access public |
| 32 | 5965 | acydburn | */ |
| 33 | 5965 | acydburn | function generate_profile_fields($mode, $lang_id) |
| 34 | 5965 | acydburn | {
|
| 35 | 5965 | acydburn | global $db, $template, $auth; |
| 36 | 5965 | acydburn | |
| 37 | 5965 | acydburn | $sql_where = ''; |
| 38 | 5965 | acydburn | switch ($mode) |
| 39 | 5965 | acydburn | {
|
| 40 | 5965 | acydburn | case 'register': |
| 41 | 9342 | terrafrost | // If the field is required we show it on the registration page
|
| 42 | 9342 | terrafrost | $sql_where .= ' AND f.field_show_on_reg = 1'; |
| 43 | 5965 | acydburn | break;
|
| 44 | 5965 | acydburn | |
| 45 | 5965 | acydburn | case 'profile': |
| 46 | 5965 | acydburn | // Show hidden fields to moderators/admins
|
| 47 | 6708 | naderman | if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) |
| 48 | 5965 | acydburn | {
|
| 49 | 9127 | acydburn | $sql_where .= ' AND f.field_show_profile = 1'; |
| 50 | 5965 | acydburn | } |
| 51 | 5965 | acydburn | break;
|
| 52 | 5965 | acydburn | |
| 53 | 5965 | acydburn | default:
|
| 54 | 5965 | acydburn | trigger_error('Wrong profile mode specified', E_USER_ERROR); |
| 55 | 5965 | acydburn | break;
|
| 56 | 5965 | acydburn | } |
| 57 | 5965 | acydburn | |
| 58 | 5965 | acydburn | $sql = 'SELECT l.*, f.* |
| 59 | 8142 | acydburn | FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f |
| 60 | 5965 | acydburn | WHERE f.field_active = 1 |
| 61 | 5965 | acydburn | $sql_where |
| 62 | 5965 | acydburn | AND l.lang_id = $lang_id |
| 63 | 8142 | acydburn | AND l.field_id = f.field_id |
| 64 | 5965 | acydburn | ORDER BY f.field_order";
|
| 65 | 5965 | acydburn | $result = $db->sql_query($sql); |
| 66 | 5965 | acydburn | |
| 67 | 5965 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 68 | 5965 | acydburn | {
|
| 69 | 5965 | acydburn | // Return templated field
|
| 70 | 5965 | acydburn | $tpl_snippet = $this->process_field_row('change', $row); |
| 71 | 5965 | acydburn | |
| 72 | 7338 | davidmj | // Some types are multivalue, we can't give them a field_id as we would not know which to pick
|
| 73 | 7338 | davidmj | $type = (int) $row['field_type']; |
| 74 | 7338 | davidmj | |
| 75 | 5965 | acydburn | $template->assign_block_vars('profile_fields', array( |
| 76 | 5965 | acydburn | 'LANG_NAME' => $row['lang_name'], |
| 77 | 5965 | acydburn | 'LANG_EXPLAIN' => $row['lang_explain'], |
| 78 | 6022 | acydburn | 'FIELD' => $tpl_snippet, |
| 79 | 7943 | kellanved | 'FIELD_ID' => ($type == FIELD_DATE || ($type == FIELD_BOOL && $row['field_length'] == '1')) ? '' : 'pf_' . $row['field_ident'], |
| 80 | 6022 | acydburn | 'S_REQUIRED' => ($row['field_required']) ? true : false) |
| 81 | 5965 | acydburn | ); |
| 82 | 5965 | acydburn | } |
| 83 | 5965 | acydburn | $db->sql_freeresult($result); |
| 84 | 5965 | acydburn | } |
| 85 | 5965 | acydburn | |
| 86 | 5965 | acydburn | /**
|
| 87 | 5965 | acydburn | * Validate entered profile field data |
| 88 | 6312 | acydburn | * @access public |
| 89 | 5965 | acydburn | */ |
| 90 | 5965 | acydburn | function validate_profile_field($field_type, &$field_value, $field_data) |
| 91 | 5965 | acydburn | {
|
| 92 | 5965 | acydburn | switch ($field_type) |
| 93 | 5965 | acydburn | {
|
| 94 | 5965 | acydburn | case FIELD_DATE: |
| 95 | 5965 | acydburn | $field_validate = explode('-', $field_value); |
| 96 | 9127 | acydburn | |
| 97 | 5965 | acydburn | $day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0; |
| 98 | 5965 | acydburn | $month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0; |
| 99 | 5965 | acydburn | $year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0; |
| 100 | 5965 | acydburn | |
| 101 | 5965 | acydburn | if ((!$day || !$month || !$year) && !$field_data['field_required']) |
| 102 | 5965 | acydburn | {
|
| 103 | 5965 | acydburn | return false; |
| 104 | 5965 | acydburn | } |
| 105 | 5965 | acydburn | |
| 106 | 5965 | acydburn | if ((!$day || !$month || !$year) && $field_data['field_required']) |
| 107 | 5965 | acydburn | {
|
| 108 | 5965 | acydburn | return 'FIELD_REQUIRED'; |
| 109 | 5965 | acydburn | } |
| 110 | 5965 | acydburn | |
| 111 | 8138 | acydburn | if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50) |
| 112 | 5965 | acydburn | {
|
| 113 | 5965 | acydburn | return 'FIELD_INVALID_DATE'; |
| 114 | 5965 | acydburn | } |
| 115 | 6070 | acydburn | |
| 116 | 6073 | acydburn | if (checkdate($month, $day, $year) === false) |
| 117 | 6070 | acydburn | {
|
| 118 | 6070 | acydburn | return 'FIELD_INVALID_DATE'; |
| 119 | 6070 | acydburn | } |
| 120 | 5965 | acydburn | break;
|
| 121 | 5965 | acydburn | |
| 122 | 6069 | acydburn | case FIELD_BOOL: |
| 123 | 9788 | toonarmy | $field_value = (bool) $field_value; |
| 124 | 9788 | toonarmy | |
| 125 | 6069 | acydburn | if (!$field_value && $field_data['field_required']) |
| 126 | 6069 | acydburn | {
|
| 127 | 6069 | acydburn | return 'FIELD_REQUIRED'; |
| 128 | 6069 | acydburn | } |
| 129 | 6069 | acydburn | break;
|
| 130 | 6069 | acydburn | |
| 131 | 5965 | acydburn | case FIELD_INT: |
| 132 | 9788 | toonarmy | if (trim($field_value) === '' && !$field_data['field_required']) |
| 133 | 5965 | acydburn | {
|
| 134 | 5965 | acydburn | return false; |
| 135 | 5965 | acydburn | } |
| 136 | 9788 | toonarmy | |
| 137 | 9788 | toonarmy | $field_value = (int) $field_value; |
| 138 | 5965 | acydburn | |
| 139 | 5965 | acydburn | if ($field_value < $field_data['field_minlen']) |
| 140 | 5965 | acydburn | {
|
| 141 | 5965 | acydburn | return 'FIELD_TOO_SMALL'; |
| 142 | 5965 | acydburn | } |
| 143 | 8142 | acydburn | else if ($field_value > $field_data['field_maxlen']) |
| 144 | 5965 | acydburn | {
|
| 145 | 5965 | acydburn | return 'FIELD_TOO_LARGE'; |
| 146 | 5965 | acydburn | } |
| 147 | 5965 | acydburn | break;
|
| 148 | 9127 | acydburn | |
| 149 | 5965 | acydburn | case FIELD_DROPDOWN: |
| 150 | 9788 | toonarmy | $field_value = (int) $field_value; |
| 151 | 11181 | git-gate | |
| 152 | 11181 | git-gate | // retrieve option lang data if necessary
|
| 153 | 11181 | git-gate | if (!isset($this->options_lang[$field_data['field_id']]) || !isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']]) || !sizeof($this->options_lang[$file_data['field_id']][$field_data['lang_id']])) |
| 154 | 11181 | git-gate | {
|
| 155 | 11181 | git-gate | $this->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); |
| 156 | 11181 | git-gate | } |
| 157 | 11181 | git-gate | |
| 158 | 11181 | git-gate | if (!isset($this->options_lang[$field_data['field_id']][$field_data['lang_id']][$field_value])) |
| 159 | 11181 | git-gate | {
|
| 160 | 11181 | git-gate | return 'FIELD_INVALID_VALUE'; |
| 161 | 11181 | git-gate | } |
| 162 | 11181 | git-gate | |
| 163 | 5965 | acydburn | if ($field_value == $field_data['field_novalue'] && $field_data['field_required']) |
| 164 | 5965 | acydburn | {
|
| 165 | 5965 | acydburn | return 'FIELD_REQUIRED'; |
| 166 | 5965 | acydburn | } |
| 167 | 5965 | acydburn | break;
|
| 168 | 9127 | acydburn | |
| 169 | 5965 | acydburn | case FIELD_STRING: |
| 170 | 5965 | acydburn | case FIELD_TEXT: |
| 171 | 10342 | acydburn | if (trim($field_value) === '' && !$field_data['field_required']) |
| 172 | 5965 | acydburn | {
|
| 173 | 5965 | acydburn | return false; |
| 174 | 5965 | acydburn | } |
| 175 | 10342 | acydburn | else if (trim($field_value) === '' && $field_data['field_required']) |
| 176 | 5965 | acydburn | {
|
| 177 | 5965 | acydburn | return 'FIELD_REQUIRED'; |
| 178 | 5965 | acydburn | } |
| 179 | 5965 | acydburn | |
| 180 | 6452 | acydburn | if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen']) |
| 181 | 5965 | acydburn | {
|
| 182 | 5965 | acydburn | return 'FIELD_TOO_SHORT'; |
| 183 | 5965 | acydburn | } |
| 184 | 6452 | acydburn | else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen']) |
| 185 | 5965 | acydburn | {
|
| 186 | 5965 | acydburn | return 'FIELD_TOO_LONG'; |
| 187 | 5965 | acydburn | } |
| 188 | 5965 | acydburn | |
| 189 | 5965 | acydburn | if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*') |
| 190 | 5965 | acydburn | {
|
| 191 | 8050 | naderman | $field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value); |
| 192 | 5965 | acydburn | if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate)) |
| 193 | 5965 | acydburn | {
|
| 194 | 5965 | acydburn | return 'FIELD_INVALID_CHARS'; |
| 195 | 5965 | acydburn | } |
| 196 | 5965 | acydburn | } |
| 197 | 5965 | acydburn | break;
|
| 198 | 5965 | acydburn | } |
| 199 | 5965 | acydburn | |
| 200 | 5965 | acydburn | return false; |
| 201 | 5965 | acydburn | } |
| 202 | 5965 | acydburn | |
| 203 | 5965 | acydburn | /**
|
| 204 | 5135 | acydburn | * Build profile cache, used for display |
| 205 | 6312 | acydburn | * @access private |
| 206 | 5135 | acydburn | */ |
| 207 | 4916 | acydburn | function build_cache() |
| 208 | 4916 | acydburn | {
|
| 209 | 5135 | acydburn | global $db, $user, $auth; |
| 210 | 4916 | acydburn | |
| 211 | 4984 | acydburn | $this->profile_cache = array(); |
| 212 | 9127 | acydburn | |
| 213 | 5135 | acydburn | // Display hidden/no_view fields for admin/moderator
|
| 214 | 4916 | acydburn | $sql = 'SELECT l.*, f.* |
| 215 | 8142 | acydburn | FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f |
| 216 | 4916 | acydburn | WHERE l.lang_id = ' . $user->get_iso_lang_id() . ' |
| 217 | 5135 | acydburn | AND f.field_active = 1 ' .
|
| 218 | 6708 | naderman | ((!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . ' |
| 219 | 5965 | acydburn | AND f.field_no_view = 0 |
| 220 | 8142 | acydburn | AND l.field_id = f.field_id |
| 221 | 4916 | acydburn | ORDER BY f.field_order';
|
| 222 | 4916 | acydburn | $result = $db->sql_query($sql); |
| 223 | 4916 | acydburn | |
| 224 | 4916 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 225 | 4916 | acydburn | {
|
| 226 | 4984 | acydburn | $this->profile_cache[$row['field_ident']] = $row; |
| 227 | 4916 | acydburn | } |
| 228 | 4916 | acydburn | $db->sql_freeresult($result); |
| 229 | 4916 | acydburn | } |
| 230 | 4916 | acydburn | |
| 231 | 5135 | acydburn | /**
|
| 232 | 5135 | acydburn | * Get language entries for options and store them here for later use |
| 233 | 5135 | acydburn | */ |
| 234 | 4984 | acydburn | function get_option_lang($field_id, $lang_id, $field_type, $preview) |
| 235 | 4984 | acydburn | {
|
| 236 | 4984 | acydburn | global $db; |
| 237 | 4984 | acydburn | |
| 238 | 4984 | acydburn | if ($preview) |
| 239 | 4984 | acydburn | {
|
| 240 | 4984 | acydburn | $lang_options = (!is_array($this->vars['lang_options'])) ? explode("\n", $this->vars['lang_options']) : $this->vars['lang_options']; |
| 241 | 9127 | acydburn | |
| 242 | 4984 | acydburn | foreach ($lang_options as $num => $var) |
| 243 | 4984 | acydburn | {
|
| 244 | 5965 | acydburn | $this->options_lang[$field_id][$lang_id][($num + 1)] = $var; |
| 245 | 4984 | acydburn | } |
| 246 | 4984 | acydburn | } |
| 247 | 4984 | acydburn | else
|
| 248 | 4984 | acydburn | {
|
| 249 | 6177 | acydburn | $sql = 'SELECT option_id, lang_value |
| 250 | 4984 | acydburn | FROM ' . PROFILE_FIELDS_LANG_TABLE . " |
| 251 | 4984 | acydburn | WHERE field_id = $field_id |
| 252 | 4984 | acydburn | AND lang_id = $lang_id |
| 253 | 4984 | acydburn | AND field_type = $field_type |
| 254 | 4984 | acydburn | ORDER BY option_id";
|
| 255 | 4984 | acydburn | $result = $db->sql_query($sql); |
| 256 | 4984 | acydburn | |
| 257 | 4984 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 258 | 4984 | acydburn | {
|
| 259 | 6177 | acydburn | $this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value']; |
| 260 | 4984 | acydburn | } |
| 261 | 4984 | acydburn | $db->sql_freeresult($result); |
| 262 | 4984 | acydburn | } |
| 263 | 4984 | acydburn | } |
| 264 | 4984 | acydburn | |
| 265 | 5135 | acydburn | /**
|
| 266 | 9582 | acydburn | * Submit profile field for validation |
| 267 | 6312 | acydburn | * @access public |
| 268 | 5135 | acydburn | */ |
| 269 | 4984 | acydburn | function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error) |
| 270 | 4740 | acydburn | {
|
| 271 | 4984 | acydburn | global $auth, $db, $user; |
| 272 | 4740 | acydburn | |
| 273 | 5965 | acydburn | $sql_where = ''; |
| 274 | 5965 | acydburn | switch ($mode) |
| 275 | 5965 | acydburn | {
|
| 276 | 5965 | acydburn | case 'register': |
| 277 | 9504 | acydburn | // If the field is required we show it on the registration page
|
| 278 | 9504 | acydburn | $sql_where .= ' AND f.field_show_on_reg = 1'; |
| 279 | 5965 | acydburn | break;
|
| 280 | 5965 | acydburn | |
| 281 | 5965 | acydburn | case 'profile': |
| 282 | 5965 | acydburn | // Show hidden fields to moderators/admins
|
| 283 | 6708 | naderman | if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) |
| 284 | 5965 | acydburn | {
|
| 285 | 9127 | acydburn | $sql_where .= ' AND f.field_show_profile = 1'; |
| 286 | 5965 | acydburn | } |
| 287 | 5965 | acydburn | break;
|
| 288 | 5965 | acydburn | |
| 289 | 5965 | acydburn | default:
|
| 290 | 5965 | acydburn | trigger_error('Wrong profile mode specified', E_USER_ERROR); |
| 291 | 5965 | acydburn | break;
|
| 292 | 5965 | acydburn | } |
| 293 | 5965 | acydburn | |
| 294 | 4984 | acydburn | $sql = 'SELECT l.*, f.* |
| 295 | 8142 | acydburn | FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f |
| 296 | 4984 | acydburn | WHERE l.lang_id = $lang_id |
| 297 | 4984 | acydburn | AND f.field_active = 1 |
| 298 | 5965 | acydburn | $sql_where |
| 299 | 8142 | acydburn | AND l.field_id = f.field_id |
| 300 | 5965 | acydburn | ORDER BY f.field_order";
|
| 301 | 4740 | acydburn | $result = $db->sql_query($sql); |
| 302 | 5965 | acydburn | |
| 303 | 4740 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 304 | 4740 | acydburn | {
|
| 305 | 6449 | davidmj | $cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row); |
| 306 | 6449 | davidmj | $check_value = $cp_data['pf_' . $row['field_ident']]; |
| 307 | 4800 | psotfx | |
| 308 | 5076 | bartvb | if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false) |
| 309 | 5076 | bartvb | {
|
| 310 | 4984 | acydburn | // If not and only showing common error messages, use this one
|
| 311 | 4984 | acydburn | $error = ''; |
| 312 | 4984 | acydburn | switch ($cp_result) |
| 313 | 4984 | acydburn | {
|
| 314 | 4984 | acydburn | case 'FIELD_INVALID_DATE': |
| 315 | 11181 | git-gate | case 'FIELD_INVALID_VALUE': |
| 316 | 4984 | acydburn | case 'FIELD_REQUIRED': |
| 317 | 11603 | git-gate | $error = $user->lang($cp_result, $row['lang_name']); |
| 318 | 5965 | acydburn | break;
|
| 319 | 5965 | acydburn | |
| 320 | 4984 | acydburn | case 'FIELD_TOO_SHORT': |
| 321 | 4984 | acydburn | case 'FIELD_TOO_SMALL': |
| 322 | 11603 | git-gate | $error = $user->lang($cp_result, (int) $row['field_minlen'], $row['lang_name']); |
| 323 | 5965 | acydburn | break;
|
| 324 | 9127 | acydburn | |
| 325 | 4984 | acydburn | case 'FIELD_TOO_LONG': |
| 326 | 4984 | acydburn | case 'FIELD_TOO_LARGE': |
| 327 | 11603 | git-gate | $error = $user->lang($cp_result, (int) $row['field_maxlen'], $row['lang_name']); |
| 328 | 5965 | acydburn | break;
|
| 329 | 9127 | acydburn | |
| 330 | 4984 | acydburn | case 'FIELD_INVALID_CHARS': |
| 331 | 4987 | acydburn | switch ($row['field_validation']) |
| 332 | 4984 | acydburn | {
|
| 333 | 4984 | acydburn | case '[0-9]+': |
| 334 | 11603 | git-gate | $error = $user->lang($cp_result . '_NUMBERS_ONLY', $row['lang_name']); |
| 335 | 5965 | acydburn | break;
|
| 336 | 5965 | acydburn | |
| 337 | 4984 | acydburn | case '[\w]+': |
| 338 | 11603 | git-gate | $error = $user->lang($cp_result . '_ALPHA_ONLY', $row['lang_name']); |
| 339 | 5965 | acydburn | break;
|
| 340 | 5965 | acydburn | |
| 341 | 4984 | acydburn | case '[\w_\+\. \-\[\]]+': |
| 342 | 11603 | git-gate | $error = $user->lang($cp_result . '_SPACERS_ONLY', $row['lang_name']); |
| 343 | 5965 | acydburn | break;
|
| 344 | 4984 | acydburn | } |
| 345 | 5965 | acydburn | break;
|
| 346 | 4984 | acydburn | } |
| 347 | 9127 | acydburn | |
| 348 | 5163 | bartvb | if ($error != '') |
| 349 | 5163 | bartvb | {
|
| 350 | 5163 | bartvb | $cp_error[] = $error; |
| 351 | 5163 | bartvb | } |
| 352 | 4740 | acydburn | } |
| 353 | 4740 | acydburn | } |
| 354 | 4740 | acydburn | $db->sql_freeresult($result); |
| 355 | 4740 | acydburn | } |
| 356 | 4740 | acydburn | |
| 357 | 5135 | acydburn | /**
|
| 358 | 9582 | acydburn | * Update profile field data directly |
| 359 | 9582 | acydburn | */ |
| 360 | 9582 | acydburn | function update_profile_field_data($user_id, &$cp_data) |
| 361 | 9582 | acydburn | {
|
| 362 | 9582 | acydburn | global $db; |
| 363 | 9582 | acydburn | |
| 364 | 9582 | acydburn | if (!sizeof($cp_data)) |
| 365 | 9582 | acydburn | {
|
| 366 | 9582 | acydburn | return;
|
| 367 | 9582 | acydburn | } |
| 368 | 9582 | acydburn | |
| 369 | 9582 | acydburn | switch ($db->sql_layer) |
| 370 | 9582 | acydburn | {
|
| 371 | 9582 | acydburn | case 'oracle': |
| 372 | 9582 | acydburn | case 'firebird': |
| 373 | 9582 | acydburn | case 'postgres': |
| 374 | 9582 | acydburn | $right_delim = $left_delim = '"'; |
| 375 | 9582 | acydburn | break;
|
| 376 | 9582 | acydburn | |
| 377 | 9582 | acydburn | case 'sqlite': |
| 378 | 9582 | acydburn | case 'mssql': |
| 379 | 9582 | acydburn | case 'mssql_odbc': |
| 380 | 10635 | git-gate | case 'mssqlnative': |
| 381 | 9582 | acydburn | $right_delim = ']'; |
| 382 | 9582 | acydburn | $left_delim = '['; |
| 383 | 9582 | acydburn | break;
|
| 384 | 9582 | acydburn | |
| 385 | 9582 | acydburn | case 'mysql': |
| 386 | 9582 | acydburn | case 'mysql4': |
| 387 | 9582 | acydburn | case 'mysqli': |
| 388 | 9582 | acydburn | $right_delim = $left_delim = '`'; |
| 389 | 9582 | acydburn | break;
|
| 390 | 9582 | acydburn | } |
| 391 | 9582 | acydburn | |
| 392 | 9716 | Kellanved | // use new array for the UPDATE; changes in the key do not affect the original array
|
| 393 | 9716 | Kellanved | $cp_data_sql = array(); |
| 394 | 9582 | acydburn | foreach ($cp_data as $key => $value) |
| 395 | 9582 | acydburn | {
|
| 396 | 9582 | acydburn | // Firebird is case sensitive with delimiter
|
| 397 | 9716 | Kellanved | $cp_data_sql[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value; |
| 398 | 9582 | acydburn | } |
| 399 | 9582 | acydburn | |
| 400 | 9582 | acydburn | $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . ' |
| 401 | 9716 | Kellanved | SET ' . $db->sql_build_array('UPDATE', $cp_data_sql) . " |
| 402 | 9582 | acydburn | WHERE user_id = $user_id"; |
| 403 | 9582 | acydburn | $db->sql_query($sql); |
| 404 | 9582 | acydburn | |
| 405 | 9582 | acydburn | if (!$db->sql_affectedrows()) |
| 406 | 9582 | acydburn | {
|
| 407 | 9717 | Kellanved | $cp_data_sql['user_id'] = (int) $user_id; |
| 408 | 9582 | acydburn | |
| 409 | 9582 | acydburn | $db->sql_return_on_error(true); |
| 410 | 9582 | acydburn | |
| 411 | 9716 | Kellanved | $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data_sql); |
| 412 | 9582 | acydburn | $db->sql_query($sql); |
| 413 | 9582 | acydburn | |
| 414 | 9582 | acydburn | $db->sql_return_on_error(false); |
| 415 | 9582 | acydburn | } |
| 416 | 9582 | acydburn | } |
| 417 | 9582 | acydburn | |
| 418 | 9582 | acydburn | /**
|
| 419 | 5135 | acydburn | * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled) |
| 420 | 5135 | acydburn | * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template |
| 421 | 6312 | acydburn | * @access public |
| 422 | 5135 | acydburn | */ |
| 423 | 4901 | acydburn | function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false) |
| 424 | 4901 | acydburn | {
|
| 425 | 4901 | acydburn | global $db; |
| 426 | 4901 | acydburn | |
| 427 | 4901 | acydburn | if ($mode == 'grab') |
| 428 | 4901 | acydburn | {
|
| 429 | 4901 | acydburn | if (!is_array($user_id)) |
| 430 | 4901 | acydburn | {
|
| 431 | 4901 | acydburn | $user_id = array($user_id); |
| 432 | 4901 | acydburn | } |
| 433 | 5965 | acydburn | |
| 434 | 4984 | acydburn | if (!sizeof($this->profile_cache)) |
| 435 | 4901 | acydburn | {
|
| 436 | 4901 | acydburn | $this->build_cache();
|
| 437 | 4901 | acydburn | } |
| 438 | 4901 | acydburn | |
| 439 | 6271 | acydburn | if (!sizeof($user_id)) |
| 440 | 4901 | acydburn | {
|
| 441 | 4901 | acydburn | return array(); |
| 442 | 4901 | acydburn | } |
| 443 | 4901 | acydburn | |
| 444 | 4901 | acydburn | $sql = 'SELECT * |
| 445 | 6021 | acydburn | FROM ' . PROFILE_FIELDS_DATA_TABLE . ' |
| 446 | 6271 | acydburn | WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id)); |
| 447 | 4901 | acydburn | $result = $db->sql_query($sql); |
| 448 | 4901 | acydburn | |
| 449 | 6022 | acydburn | $field_data = array(); |
| 450 | 5995 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 451 | 4901 | acydburn | {
|
| 452 | 6022 | acydburn | $field_data[$row['user_id']] = $row; |
| 453 | 6022 | acydburn | } |
| 454 | 6022 | acydburn | $db->sql_freeresult($result); |
| 455 | 6022 | acydburn | |
| 456 | 6022 | acydburn | $user_fields = array(); |
| 457 | 6022 | acydburn | |
| 458 | 6022 | acydburn | // Go through the fields in correct order
|
| 459 | 6022 | acydburn | foreach (array_keys($this->profile_cache) as $used_ident) |
| 460 | 6022 | acydburn | {
|
| 461 | 6022 | acydburn | foreach ($field_data as $user_id => $row) |
| 462 | 4901 | acydburn | {
|
| 463 | 6449 | davidmj | $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident]; |
| 464 | 6022 | acydburn | $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident]; |
| 465 | 4901 | acydburn | } |
| 466 | 5995 | acydburn | } |
| 467 | 4901 | acydburn | |
| 468 | 4901 | acydburn | return $user_fields; |
| 469 | 4901 | acydburn | } |
| 470 | 4901 | acydburn | else if ($mode == 'show') |
| 471 | 4901 | acydburn | {
|
| 472 | 5076 | bartvb | // $profile_row == $user_fields[$row['user_id']];
|
| 473 | 4901 | acydburn | $tpl_fields = array(); |
| 474 | 5135 | acydburn | $tpl_fields['row'] = $tpl_fields['blockrow'] = array(); |
| 475 | 5965 | acydburn | |
| 476 | 4901 | acydburn | foreach ($profile_row as $ident => $ident_ary) |
| 477 | 4901 | acydburn | {
|
| 478 | 5965 | acydburn | $value = $this->get_profile_value($ident_ary); |
| 479 | 5965 | acydburn | |
| 480 | 5965 | acydburn | if ($value === NULL) |
| 481 | 5965 | acydburn | {
|
| 482 | 5965 | acydburn | continue;
|
| 483 | 5965 | acydburn | } |
| 484 | 5965 | acydburn | |
| 485 | 5135 | acydburn | $tpl_fields['row'] += array( |
| 486 | 5965 | acydburn | 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value, |
| 487 | 4984 | acydburn | 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'], |
| 488 | 4984 | acydburn | 'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'], |
| 489 | 4984 | acydburn | 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'], |
| 490 | 4984 | acydburn | |
| 491 | 4984 | acydburn | 'S_PROFILE_' . strtoupper($ident) => true |
| 492 | 4984 | acydburn | ); |
| 493 | 5135 | acydburn | |
| 494 | 5135 | acydburn | $tpl_fields['blockrow'][] = array( |
| 495 | 5965 | acydburn | 'PROFILE_FIELD_VALUE' => $value, |
| 496 | 5135 | acydburn | 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'], |
| 497 | 5135 | acydburn | 'PROFILE_FIELD_NAME' => $ident_ary['data']['lang_name'], |
| 498 | 5135 | acydburn | 'PROFILE_FIELD_EXPLAIN' => $ident_ary['data']['lang_explain'], |
| 499 | 5135 | acydburn | |
| 500 | 5135 | acydburn | 'S_PROFILE_' . strtoupper($ident) => true |
| 501 | 5135 | acydburn | ); |
| 502 | 4901 | acydburn | } |
| 503 | 9127 | acydburn | |
| 504 | 4901 | acydburn | return $tpl_fields; |
| 505 | 4901 | acydburn | } |
| 506 | 5967 | acydburn | else
|
| 507 | 5967 | acydburn | {
|
| 508 | 5967 | acydburn | trigger_error('Wrong mode for custom profile', E_USER_ERROR); |
| 509 | 5967 | acydburn | } |
| 510 | 4901 | acydburn | } |
| 511 | 4901 | acydburn | |
| 512 | 5965 | acydburn | /**
|
| 513 | 5965 | acydburn | * Get Profile Value for display |
| 514 | 5965 | acydburn | */ |
| 515 | 5076 | bartvb | function get_profile_value($ident_ary) |
| 516 | 4740 | acydburn | {
|
| 517 | 5076 | bartvb | $value = $ident_ary['value']; |
| 518 | 5076 | bartvb | $field_type = $ident_ary['data']['field_type']; |
| 519 | 5076 | bartvb | |
| 520 | 4901 | acydburn | switch ($this->profile_types[$field_type]) |
| 521 | 4901 | acydburn | {
|
| 522 | 4901 | acydburn | case 'int': |
| 523 | 9788 | toonarmy | if ($value === '') |
| 524 | 5995 | acydburn | {
|
| 525 | 5995 | acydburn | return NULL; |
| 526 | 5995 | acydburn | } |
| 527 | 4901 | acydburn | return (int) $value; |
| 528 | 5603 | acydburn | break;
|
| 529 | 5603 | acydburn | |
| 530 | 4901 | acydburn | case 'string': |
| 531 | 4901 | acydburn | case 'text': |
| 532 | 5965 | acydburn | if (!$value) |
| 533 | 5076 | bartvb | {
|
| 534 | 5965 | acydburn | return NULL; |
| 535 | 5076 | bartvb | } |
| 536 | 5712 | acydburn | |
| 537 | 5712 | acydburn | $value = make_clickable($value); |
| 538 | 5712 | acydburn | $value = censor_text($value); |
| 539 | 8050 | naderman | $value = bbcode_nl2br($value); |
| 540 | 5712 | acydburn | return $value; |
| 541 | 5965 | acydburn | break;
|
| 542 | 5712 | acydburn | |
| 543 | 6022 | acydburn | // case 'datetime':
|
| 544 | 4901 | acydburn | case 'date': |
| 545 | 5965 | acydburn | $date = explode('-', $value); |
| 546 | 7805 | acydburn | $day = (isset($date[0])) ? (int) $date[0] : 0; |
| 547 | 7805 | acydburn | $month = (isset($date[1])) ? (int) $date[1] : 0; |
| 548 | 5965 | acydburn | $year = (isset($date[2])) ? (int) $date[2] : 0; |
| 549 | 5965 | acydburn | |
| 550 | 5965 | acydburn | if (!$day && !$month && !$year) |
| 551 | 5965 | acydburn | {
|
| 552 | 5965 | acydburn | return NULL; |
| 553 | 5965 | acydburn | } |
| 554 | 5965 | acydburn | else if ($day && $month && $year) |
| 555 | 5965 | acydburn | {
|
| 556 | 7805 | acydburn | global $user; |
| 557 | 10761 | git-gate | // Date should display as the same date for every user regardless of timezone, so remove offset
|
| 558 | 10761 | git-gate | // to compensate for the offset added by user::format_date()
|
| 559 | 10761 | git-gate | return $user->format_date(gmmktime(0, 0, 0, $month, $day, $year) - ($user->timezone + $user->dst), $user->lang['DATE_FORMAT'], true); |
| 560 | 5965 | acydburn | } |
| 561 | 5965 | acydburn | |
| 562 | 5965 | acydburn | return $value; |
| 563 | 5603 | acydburn | break;
|
| 564 | 6022 | acydburn | |
| 565 | 4901 | acydburn | case 'dropdown': |
| 566 | 5076 | bartvb | $field_id = $ident_ary['data']['field_id']; |
| 567 | 5076 | bartvb | $lang_id = $ident_ary['data']['lang_id']; |
| 568 | 5076 | bartvb | if (!isset($this->options_lang[$field_id][$lang_id])) |
| 569 | 4901 | acydburn | {
|
| 570 | 4901 | acydburn | $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); |
| 571 | 4901 | acydburn | } |
| 572 | 4901 | acydburn | |
| 573 | 5965 | acydburn | if ($value == $ident_ary['data']['field_novalue']) |
| 574 | 5965 | acydburn | {
|
| 575 | 5965 | acydburn | return NULL; |
| 576 | 5965 | acydburn | } |
| 577 | 5965 | acydburn | |
| 578 | 6232 | acydburn | $value = (int) $value; |
| 579 | 6232 | acydburn | |
| 580 | 6232 | acydburn | // User not having a value assigned
|
| 581 | 6232 | acydburn | if (!isset($this->options_lang[$field_id][$lang_id][$value])) |
| 582 | 6232 | acydburn | {
|
| 583 | 6232 | acydburn | return NULL; |
| 584 | 6232 | acydburn | } |
| 585 | 6232 | acydburn | |
| 586 | 6232 | acydburn | return $this->options_lang[$field_id][$lang_id][$value]; |
| 587 | 5603 | acydburn | break;
|
| 588 | 6022 | acydburn | |
| 589 | 4901 | acydburn | case 'bool': |
| 590 | 5965 | acydburn | $field_id = $ident_ary['data']['field_id']; |
| 591 | 5965 | acydburn | $lang_id = $ident_ary['data']['lang_id']; |
| 592 | 5965 | acydburn | if (!isset($this->options_lang[$field_id][$lang_id])) |
| 593 | 5965 | acydburn | {
|
| 594 | 5965 | acydburn | $this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false); |
| 595 | 5965 | acydburn | } |
| 596 | 5965 | acydburn | |
| 597 | 5965 | acydburn | if ($ident_ary['data']['field_length'] == 1) |
| 598 | 5965 | acydburn | {
|
| 599 | 5995 | acydburn | return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL; |
| 600 | 5965 | acydburn | } |
| 601 | 5965 | acydburn | else if (!$value) |
| 602 | 5965 | acydburn | {
|
| 603 | 5965 | acydburn | return NULL; |
| 604 | 5965 | acydburn | } |
| 605 | 5965 | acydburn | else
|
| 606 | 5965 | acydburn | {
|
| 607 | 7943 | kellanved | return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1]; |
| 608 | 5965 | acydburn | } |
| 609 | 5603 | acydburn | break;
|
| 610 | 6022 | acydburn | |
| 611 | 5076 | bartvb | default:
|
| 612 | 5965 | acydburn | trigger_error('Unknown profile type', E_USER_ERROR); |
| 613 | 5603 | acydburn | break;
|
| 614 | 4901 | acydburn | } |
| 615 | 4901 | acydburn | } |
| 616 | 4901 | acydburn | |
| 617 | 5965 | acydburn | /**
|
| 618 | 5965 | acydburn | * Get field value for registration/profile |
| 619 | 6312 | acydburn | * @access private |
| 620 | 5965 | acydburn | */ |
| 621 | 4901 | acydburn | function get_var($field_validation, &$profile_row, $default_value, $preview) |
| 622 | 4901 | acydburn | {
|
| 623 | 4740 | acydburn | global $user; |
| 624 | 10801 | git-gate | global $request; |
| 625 | 4740 | acydburn | |
| 626 | 5076 | bartvb | $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; |
| 627 | 7943 | kellanved | $user_ident = $profile_row['field_ident']; |
| 628 | 4984 | acydburn | // checkbox - only testing for isset
|
| 629 | 4984 | acydburn | if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2) |
| 630 | 4984 | acydburn | {
|
| 631 | 5973 | acydburn | $value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]); |
| 632 | 4984 | acydburn | } |
| 633 | 5995 | acydburn | else if ($profile_row['field_type'] == FIELD_INT) |
| 634 | 5995 | acydburn | {
|
| 635 | 5995 | acydburn | if (isset($_REQUEST[$profile_row['field_ident']])) |
| 636 | 5995 | acydburn | {
|
| 637 | 10801 | git-gate | $value = ($request->variable($profile_row['field_ident'], '') === '') ? NULL : $request->variable($profile_row['field_ident'], $default_value); |
| 638 | 5995 | acydburn | } |
| 639 | 5995 | acydburn | else
|
| 640 | 5995 | acydburn | {
|
| 641 | 10342 | acydburn | if (!$preview && array_key_exists($user_ident, $user->profile_fields) && is_null($user->profile_fields[$user_ident])) |
| 642 | 5995 | acydburn | {
|
| 643 | 5995 | acydburn | $value = NULL; |
| 644 | 5995 | acydburn | } |
| 645 | 5995 | acydburn | else if (!isset($user->profile_fields[$user_ident]) || $preview) |
| 646 | 5995 | acydburn | {
|
| 647 | 5995 | acydburn | $value = $default_value; |
| 648 | 5995 | acydburn | } |
| 649 | 5995 | acydburn | else
|
| 650 | 5995 | acydburn | {
|
| 651 | 5995 | acydburn | $value = $user->profile_fields[$user_ident]; |
| 652 | 5995 | acydburn | } |
| 653 | 5995 | acydburn | } |
| 654 | 5995 | acydburn | |
| 655 | 9788 | toonarmy | return (is_null($value) || $value === '') ? '' : (int) $value; |
| 656 | 5995 | acydburn | } |
| 657 | 4984 | acydburn | else
|
| 658 | 4984 | acydburn | {
|
| 659 | 5973 | acydburn | $value = (isset($_REQUEST[$profile_row['field_ident']])) ? request_var($profile_row['field_ident'], $default_value, true) : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]); |
| 660 | 9127 | acydburn | |
| 661 | 6569 | naderman | if (gettype($value) == 'string') |
| 662 | 6569 | naderman | {
|
| 663 | 6584 | acydburn | $value = utf8_normalize_nfc($value); |
| 664 | 6569 | naderman | } |
| 665 | 4984 | acydburn | } |
| 666 | 4740 | acydburn | |
| 667 | 4740 | acydburn | switch ($field_validation) |
| 668 | 4740 | acydburn | {
|
| 669 | 4740 | acydburn | case 'int': |
| 670 | 4740 | acydburn | return (int) $value; |
| 671 | 5965 | acydburn | break;
|
| 672 | 4740 | acydburn | } |
| 673 | 4740 | acydburn | |
| 674 | 4740 | acydburn | return $value; |
| 675 | 4740 | acydburn | } |
| 676 | 5965 | acydburn | |
| 677 | 5965 | acydburn | /**
|
| 678 | 5965 | acydburn | * Process int-type |
| 679 | 6312 | acydburn | * @access private |
| 680 | 5965 | acydburn | */ |
| 681 | 4740 | acydburn | function generate_int($profile_row, $preview = false) |
| 682 | 4740 | acydburn | {
|
| 683 | 4740 | acydburn | global $template; |
| 684 | 4740 | acydburn | |
| 685 | 5965 | acydburn | $profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); |
| 686 | 5965 | acydburn | $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); |
| 687 | 4740 | acydburn | } |
| 688 | 4740 | acydburn | |
| 689 | 5965 | acydburn | /**
|
| 690 | 5965 | acydburn | * Process date-type |
| 691 | 6312 | acydburn | * @access private |
| 692 | 5965 | acydburn | */ |
| 693 | 4740 | acydburn | function generate_date($profile_row, $preview = false) |
| 694 | 4740 | acydburn | {
|
| 695 | 5965 | acydburn | global $user, $template; |
| 696 | 4740 | acydburn | |
| 697 | 5076 | bartvb | $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; |
| 698 | 7943 | kellanved | $user_ident = $profile_row['field_ident']; |
| 699 | 5973 | acydburn | |
| 700 | 4740 | acydburn | $now = getdate(); |
| 701 | 4740 | acydburn | |
| 702 | 5076 | bartvb | if (!isset($_REQUEST[$profile_row['field_ident'] . '_day'])) |
| 703 | 4740 | acydburn | {
|
| 704 | 4740 | acydburn | if ($profile_row['field_default_value'] == 'now') |
| 705 | 4740 | acydburn | {
|
| 706 | 4740 | acydburn | $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); |
| 707 | 4740 | acydburn | } |
| 708 | 5973 | acydburn | list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident])); |
| 709 | 4740 | acydburn | } |
| 710 | 4740 | acydburn | else
|
| 711 | 4740 | acydburn | {
|
| 712 | 4740 | acydburn | if ($preview && $profile_row['field_default_value'] == 'now') |
| 713 | 4740 | acydburn | {
|
| 714 | 4740 | acydburn | $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); |
| 715 | 5973 | acydburn | list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident])); |
| 716 | 4740 | acydburn | } |
| 717 | 4740 | acydburn | else
|
| 718 | 4740 | acydburn | {
|
| 719 | 5076 | bartvb | $day = request_var($profile_row['field_ident'] . '_day', 0); |
| 720 | 5076 | bartvb | $month = request_var($profile_row['field_ident'] . '_month', 0); |
| 721 | 5076 | bartvb | $year = request_var($profile_row['field_ident'] . '_year', 0); |
| 722 | 4740 | acydburn | } |
| 723 | 4740 | acydburn | } |
| 724 | 4740 | acydburn | |
| 725 | 4740 | acydburn | $profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>'; |
| 726 | 4740 | acydburn | for ($i = 1; $i < 32; $i++) |
| 727 | 4740 | acydburn | {
|
| 728 | 4740 | acydburn | $profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>"; |
| 729 | 4740 | acydburn | } |
| 730 | 4740 | acydburn | |
| 731 | 4740 | acydburn | $profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>'; |
| 732 | 4740 | acydburn | for ($i = 1; $i < 13; $i++) |
| 733 | 4740 | acydburn | {
|
| 734 | 4740 | acydburn | $profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>"; |
| 735 | 4740 | acydburn | } |
| 736 | 4740 | acydburn | |
| 737 | 4740 | acydburn | $profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>'; |
| 738 | 8291 | kellanved | for ($i = $now['year'] - 100; $i <= $now['year'] + 100; $i++) |
| 739 | 4740 | acydburn | {
|
| 740 | 4740 | acydburn | $profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>"; |
| 741 | 4740 | acydburn | } |
| 742 | 4740 | acydburn | unset($now); |
| 743 | 9127 | acydburn | |
| 744 | 5965 | acydburn | $profile_row['field_value'] = 0; |
| 745 | 5965 | acydburn | $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); |
| 746 | 4740 | acydburn | } |
| 747 | 4740 | acydburn | |
| 748 | 5965 | acydburn | /**
|
| 749 | 5965 | acydburn | * Process bool-type |
| 750 | 6312 | acydburn | * @access private |
| 751 | 5965 | acydburn | */ |
| 752 | 4740 | acydburn | function generate_bool($profile_row, $preview = false) |
| 753 | 4740 | acydburn | {
|
| 754 | 4740 | acydburn | global $template; |
| 755 | 4740 | acydburn | |
| 756 | 4901 | acydburn | $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); |
| 757 | 4984 | acydburn | |
| 758 | 5965 | acydburn | $profile_row['field_value'] = $value; |
| 759 | 5965 | acydburn | $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); |
| 760 | 4740 | acydburn | |
| 761 | 4740 | acydburn | if ($profile_row['field_length'] == 1) |
| 762 | 4740 | acydburn | {
|
| 763 | 4984 | acydburn | if (!isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) |
| 764 | 4740 | acydburn | {
|
| 765 | 6022 | acydburn | $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview); |
| 766 | 4740 | acydburn | } |
| 767 | 4740 | acydburn | |
| 768 | 4740 | acydburn | foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) |
| 769 | 4740 | acydburn | {
|
| 770 | 4740 | acydburn | $template->assign_block_vars('bool.options', array( |
| 771 | 5965 | acydburn | 'OPTION_ID' => $option_id, |
| 772 | 5965 | acydburn | 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '', |
| 773 | 5965 | acydburn | 'VALUE' => $option_value) |
| 774 | 4740 | acydburn | ); |
| 775 | 4740 | acydburn | } |
| 776 | 4740 | acydburn | } |
| 777 | 4740 | acydburn | } |
| 778 | 4740 | acydburn | |
| 779 | 5965 | acydburn | /**
|
| 780 | 5965 | acydburn | * Process string-type |
| 781 | 6312 | acydburn | * @access private |
| 782 | 5965 | acydburn | */ |
| 783 | 4740 | acydburn | function generate_string($profile_row, $preview = false) |
| 784 | 4740 | acydburn | {
|
| 785 | 4740 | acydburn | global $template; |
| 786 | 4740 | acydburn | |
| 787 | 5965 | acydburn | $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); |
| 788 | 5965 | acydburn | $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); |
| 789 | 4740 | acydburn | } |
| 790 | 4740 | acydburn | |
| 791 | 5965 | acydburn | /**
|
| 792 | 5965 | acydburn | * Process text-type |
| 793 | 6312 | acydburn | * @access private |
| 794 | 5965 | acydburn | */ |
| 795 | 4740 | acydburn | function generate_text($profile_row, $preview = false) |
| 796 | 4740 | acydburn | {
|
| 797 | 4740 | acydburn | global $template; |
| 798 | 5154 | bartvb | global $user, $phpEx, $phpbb_root_path; |
| 799 | 4740 | acydburn | |
| 800 | 4740 | acydburn | $field_length = explode('|', $profile_row['field_length']); |
| 801 | 4740 | acydburn | $profile_row['field_rows'] = $field_length[0]; |
| 802 | 4740 | acydburn | $profile_row['field_cols'] = $field_length[1]; |
| 803 | 4740 | acydburn | |
| 804 | 5965 | acydburn | $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview); |
| 805 | 5965 | acydburn | $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); |
| 806 | 4740 | acydburn | } |
| 807 | 4740 | acydburn | |
| 808 | 5965 | acydburn | /**
|
| 809 | 5965 | acydburn | * Process dropdown-type |
| 810 | 6312 | acydburn | * @access private |
| 811 | 5965 | acydburn | */ |
| 812 | 4740 | acydburn | function generate_dropdown($profile_row, $preview = false) |
| 813 | 4740 | acydburn | {
|
| 814 | 4740 | acydburn | global $user, $template; |
| 815 | 4740 | acydburn | |
| 816 | 4901 | acydburn | $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview); |
| 817 | 4740 | acydburn | |
| 818 | 5325 | acydburn | if (!isset($this->options_lang[$profile_row['field_id']]) || !isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']])) |
| 819 | 4740 | acydburn | {
|
| 820 | 6022 | acydburn | $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview); |
| 821 | 4740 | acydburn | } |
| 822 | 4740 | acydburn | |
| 823 | 5965 | acydburn | $profile_row['field_value'] = $value; |
| 824 | 5965 | acydburn | $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER)); |
| 825 | 4740 | acydburn | |
| 826 | 4740 | acydburn | foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value) |
| 827 | 4740 | acydburn | {
|
| 828 | 4740 | acydburn | $template->assign_block_vars('dropdown.options', array( |
| 829 | 5965 | acydburn | 'OPTION_ID' => $option_id, |
| 830 | 5965 | acydburn | 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '', |
| 831 | 5965 | acydburn | 'VALUE' => $option_value) |
| 832 | 4740 | acydburn | ); |
| 833 | 4740 | acydburn | } |
| 834 | 4740 | acydburn | } |
| 835 | 4740 | acydburn | |
| 836 | 5965 | acydburn | /**
|
| 837 | 5965 | acydburn | * Return Templated value/field. Possible values for $mode are: |
| 838 | 5965 | acydburn | * change == user is able to set/enter profile values; preview == just show the value |
| 839 | 6312 | acydburn | * @access private |
| 840 | 5965 | acydburn | */ |
| 841 | 4740 | acydburn | function process_field_row($mode, $profile_row) |
| 842 | 4740 | acydburn | {
|
| 843 | 5965 | acydburn | global $template; |
| 844 | 4740 | acydburn | |
| 845 | 5965 | acydburn | $preview = ($mode == 'preview') ? true : false; |
| 846 | 5965 | acydburn | |
| 847 | 5965 | acydburn | // set template filename
|
| 848 | 5965 | acydburn | $template->set_filenames(array( |
| 849 | 5965 | acydburn | 'cp_body' => 'custom_profile_fields.html') |
| 850 | 5965 | acydburn | ); |
| 851 | 5965 | acydburn | |
| 852 | 5965 | acydburn | // empty previously filled blockvars
|
| 853 | 5965 | acydburn | foreach ($this->profile_types as $field_case => $field_type) |
| 854 | 4740 | acydburn | {
|
| 855 | 5965 | acydburn | $template->destroy_block_vars($field_type); |
| 856 | 4740 | acydburn | } |
| 857 | 4740 | acydburn | |
| 858 | 5965 | acydburn | // Assign template variables
|
| 859 | 5965 | acydburn | $type_func = 'generate_' . $this->profile_types[$profile_row['field_type']]; |
| 860 | 5965 | acydburn | $this->$type_func($profile_row, $preview); |
| 861 | 5965 | acydburn | |
| 862 | 5965 | acydburn | // Return templated data
|
| 863 | 5965 | acydburn | return $template->assign_display('cp_body'); |
| 864 | 4740 | acydburn | } |
| 865 | 4740 | acydburn | |
| 866 | 5965 | acydburn | /**
|
| 867 | 5965 | acydburn | * Build Array for user insertion into custom profile fields table |
| 868 | 5965 | acydburn | */ |
| 869 | 4740 | acydburn | function build_insert_sql_array($cp_data) |
| 870 | 4740 | acydburn | {
|
| 871 | 4740 | acydburn | global $db, $user, $auth; |
| 872 | 4740 | acydburn | |
| 873 | 5965 | acydburn | $sql_not_in = array(); |
| 874 | 5965 | acydburn | foreach ($cp_data as $key => $null) |
| 875 | 5965 | acydburn | {
|
| 876 | 6449 | davidmj | $sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key; |
| 877 | 5965 | acydburn | } |
| 878 | 5965 | acydburn | |
| 879 | 4740 | acydburn | $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value |
| 880 | 8142 | acydburn | FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f |
| 881 | 8142 | acydburn | WHERE l.lang_id = ' . $user->get_iso_lang_id() . ' |
| 882 | 6271 | acydburn | ' . ((sizeof($sql_not_in)) ? ' AND ' . $db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . ' |
| 883 | 5712 | acydburn | AND l.field_id = f.field_id';
|
| 884 | 4740 | acydburn | $result = $db->sql_query($sql); |
| 885 | 4740 | acydburn | |
| 886 | 4740 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 887 | 4740 | acydburn | {
|
| 888 | 4740 | acydburn | if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE) |
| 889 | 4740 | acydburn | {
|
| 890 | 4740 | acydburn | $now = getdate(); |
| 891 | 4740 | acydburn | $row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); |
| 892 | 4740 | acydburn | } |
| 893 | 10840 | git-gate | else if ($row['field_default_value'] === '' && $row['field_type'] == FIELD_INT) |
| 894 | 10840 | git-gate | {
|
| 895 | 10840 | git-gate | // We cannot insert an empty string into an integer column.
|
| 896 | 10840 | git-gate | $row['field_default_value'] = NULL; |
| 897 | 10840 | git-gate | } |
| 898 | 6228 | acydburn | |
| 899 | 6449 | davidmj | $cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value']; |
| 900 | 4740 | acydburn | } |
| 901 | 4740 | acydburn | $db->sql_freeresult($result); |
| 902 | 9127 | acydburn | |
| 903 | 4740 | acydburn | return $cp_data; |
| 904 | 4740 | acydburn | } |
| 905 | 4740 | acydburn | |
| 906 | 5965 | acydburn | /**
|
| 907 | 5965 | acydburn | * Get profile field value on submit |
| 908 | 6312 | acydburn | * @access private |
| 909 | 5965 | acydburn | */ |
| 910 | 4740 | acydburn | function get_profile_field($profile_row) |
| 911 | 4740 | acydburn | {
|
| 912 | 5076 | bartvb | global $phpbb_root_path, $phpEx; |
| 913 | 5076 | bartvb | global $config; |
| 914 | 10801 | git-gate | global $request; |
| 915 | 9127 | acydburn | |
| 916 | 5076 | bartvb | $var_name = 'pf_' . $profile_row['field_ident']; |
| 917 | 9127 | acydburn | |
| 918 | 4740 | acydburn | switch ($profile_row['field_type']) |
| 919 | 4740 | acydburn | {
|
| 920 | 4740 | acydburn | case FIELD_DATE: |
| 921 | 5603 | acydburn | |
| 922 | 4740 | acydburn | if (!isset($_REQUEST[$var_name . '_day'])) |
| 923 | 4740 | acydburn | {
|
| 924 | 4740 | acydburn | if ($profile_row['field_default_value'] == 'now') |
| 925 | 4740 | acydburn | {
|
| 926 | 4740 | acydburn | $now = getdate(); |
| 927 | 4740 | acydburn | $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']); |
| 928 | 4740 | acydburn | } |
| 929 | 4740 | acydburn | list($day, $month, $year) = explode('-', $profile_row['field_default_value']); |
| 930 | 4740 | acydburn | } |
| 931 | 4740 | acydburn | else
|
| 932 | 4740 | acydburn | {
|
| 933 | 4740 | acydburn | $day = request_var($var_name . '_day', 0); |
| 934 | 4740 | acydburn | $month = request_var($var_name . '_month', 0); |
| 935 | 4740 | acydburn | $year = request_var($var_name . '_year', 0); |
| 936 | 4740 | acydburn | } |
| 937 | 9127 | acydburn | |
| 938 | 4740 | acydburn | $var = sprintf('%2d-%2d-%4d', $day, $month, $year); |
| 939 | 5603 | acydburn | break;
|
| 940 | 5603 | acydburn | |
| 941 | 5965 | acydburn | case FIELD_BOOL: |
| 942 | 5965 | acydburn | // Checkbox
|
| 943 | 5965 | acydburn | if ($profile_row['field_length'] == 2) |
| 944 | 5965 | acydburn | {
|
| 945 | 5965 | acydburn | $var = (isset($_REQUEST[$var_name])) ? 1 : 0; |
| 946 | 5965 | acydburn | } |
| 947 | 5965 | acydburn | else
|
| 948 | 5965 | acydburn | {
|
| 949 | 8389 | acydburn | $var = request_var($var_name, (int) $profile_row['field_default_value']); |
| 950 | 5965 | acydburn | } |
| 951 | 5965 | acydburn | break;
|
| 952 | 5965 | acydburn | |
| 953 | 5965 | acydburn | case FIELD_STRING: |
| 954 | 5076 | bartvb | case FIELD_TEXT: |
| 955 | 8389 | acydburn | $var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true)); |
| 956 | 5603 | acydburn | break;
|
| 957 | 5603 | acydburn | |
| 958 | 5995 | acydburn | case FIELD_INT: |
| 959 | 10801 | git-gate | if (isset($_REQUEST[$var_name]) && $request->variable($var_name, '') === '') |
| 960 | 5995 | acydburn | {
|
| 961 | 5995 | acydburn | $var = NULL; |
| 962 | 5995 | acydburn | } |
| 963 | 5995 | acydburn | else
|
| 964 | 5995 | acydburn | {
|
| 965 | 8389 | acydburn | $var = request_var($var_name, (int) $profile_row['field_default_value']); |
| 966 | 5995 | acydburn | } |
| 967 | 5995 | acydburn | break;
|
| 968 | 5995 | acydburn | |
| 969 | 8389 | acydburn | case FIELD_DROPDOWN: |
| 970 | 8389 | acydburn | $var = request_var($var_name, (int) $profile_row['field_default_value']); |
| 971 | 8389 | acydburn | break;
|
| 972 | 8389 | acydburn | |
| 973 | 4740 | acydburn | default:
|
| 974 | 5965 | acydburn | $var = request_var($var_name, $profile_row['field_default_value']); |
| 975 | 5603 | acydburn | break;
|
| 976 | 4740 | acydburn | } |
| 977 | 4740 | acydburn | |
| 978 | 4740 | acydburn | return $var; |
| 979 | 4740 | acydburn | } |
| 980 | 4740 | acydburn | } |
| 981 | 4740 | acydburn | |
| 982 | 5114 | acydburn | /**
|
| 983 | 6058 | acydburn | * Custom Profile Fields ACP |
| 984 | 5114 | acydburn | * @package phpBB3 |
| 985 | 5114 | acydburn | */ |
| 986 | 4740 | acydburn | class custom_profile_admin extends custom_profile |
| 987 | 4740 | acydburn | {
|
| 988 | 4740 | acydburn | var $vars = array(); |
| 989 | 4740 | acydburn | |
| 990 | 5965 | acydburn | /**
|
| 991 | 5965 | acydburn | * Return possible validation options |
| 992 | 5965 | acydburn | */ |
| 993 | 4916 | acydburn | function validate_options() |
| 994 | 4740 | acydburn | {
|
| 995 | 4740 | acydburn | global $user; |
| 996 | 4740 | acydburn | |
| 997 | 4916 | acydburn | $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+'); |
| 998 | 4740 | acydburn | |
| 999 | 4740 | acydburn | $validate_options = ''; |
| 1000 | 4740 | acydburn | foreach ($validate_ary as $lang => $value) |
| 1001 | 4740 | acydburn | {
|
| 1002 | 4740 | acydburn | $selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : ''; |
| 1003 | 4740 | acydburn | $validate_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>'; |
| 1004 | 4740 | acydburn | } |
| 1005 | 4740 | acydburn | |
| 1006 | 4916 | acydburn | return $validate_options; |
| 1007 | 4916 | acydburn | } |
| 1008 | 9127 | acydburn | |
| 1009 | 5965 | acydburn | /**
|
| 1010 | 5965 | acydburn | * Get string options for second step in ACP |
| 1011 | 5965 | acydburn | */ |
| 1012 | 4916 | acydburn | function get_string_options() |
| 1013 | 4916 | acydburn | {
|
| 1014 | 4916 | acydburn | global $user; |
| 1015 | 4916 | acydburn | |
| 1016 | 4740 | acydburn | $options = array( |
| 1017 | 5965 | acydburn | 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'), |
| 1018 | 5965 | acydburn | 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'), |
| 1019 | 5965 | acydburn | 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'), |
| 1020 | 5965 | acydburn | 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>') |
| 1021 | 4740 | acydburn | ); |
| 1022 | 4740 | acydburn | |
| 1023 | 4740 | acydburn | return $options; |
| 1024 | 4740 | acydburn | } |
| 1025 | 4740 | acydburn | |
| 1026 | 5965 | acydburn | /**
|
| 1027 | 5965 | acydburn | * Get text options for second step in ACP |
| 1028 | 5965 | acydburn | */ |
| 1029 | 4740 | acydburn | function get_text_options() |
| 1030 | 4740 | acydburn | {
|
| 1031 | 4740 | acydburn | global $user; |
| 1032 | 4740 | acydburn | |
| 1033 | 4740 | acydburn | $options = array( |
| 1034 | 5965 | acydburn | 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input name="rows" size="5" value="' . $this->vars['rows'] . '" /> ' . $user->lang['ROWS'] . '</dd><dd><input name="columns" size="5" value="' . $this->vars['columns'] . '" /> ' . $user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $this->vars['field_length'] . '" />'), |
| 1035 | 5965 | acydburn | 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars['field_minlen'] . '" />'), |
| 1036 | 5965 | acydburn | 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars['field_maxlen'] . '" />'), |
| 1037 | 5965 | acydburn | 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>') |
| 1038 | 4740 | acydburn | ); |
| 1039 | 4740 | acydburn | |
| 1040 | 4740 | acydburn | return $options; |
| 1041 | 4740 | acydburn | } |
| 1042 | 4740 | acydburn | |
| 1043 | 5965 | acydburn | /**
|
| 1044 | 5965 | acydburn | * Get int options for second step in ACP |
| 1045 | 5965 | acydburn | */ |
| 1046 | 4740 | acydburn | function get_int_options() |
| 1047 | 4740 | acydburn | {
|
| 1048 | 4740 | acydburn | global $user; |
| 1049 | 4740 | acydburn | |
| 1050 | 4740 | acydburn | $options = array( |
| 1051 | 5965 | acydburn | 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'), |
| 1052 | 5965 | acydburn | 1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'), |
| 1053 | 5965 | acydburn | 2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'), |
| 1054 | 5965 | acydburn | 3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />') |
| 1055 | 4740 | acydburn | ); |
| 1056 | 4740 | acydburn | |
| 1057 | 4740 | acydburn | return $options; |
| 1058 | 4740 | acydburn | } |
| 1059 | 4740 | acydburn | |
| 1060 | 5965 | acydburn | /**
|
| 1061 | 5965 | acydburn | * Get bool options for second step in ACP |
| 1062 | 5965 | acydburn | */ |
| 1063 | 4740 | acydburn | function get_bool_options() |
| 1064 | 4740 | acydburn | {
|
| 1065 | 4916 | acydburn | global $user, $config, $lang_defs; |
| 1066 | 4740 | acydburn | |
| 1067 | 4916 | acydburn | $default_lang_id = $lang_defs['iso'][$config['default_lang']]; |
| 1068 | 4740 | acydburn | |
| 1069 | 4740 | acydburn | $profile_row = array( |
| 1070 | 4916 | acydburn | 'var_name' => 'field_default_value', |
| 1071 | 4984 | acydburn | 'field_id' => 1, |
| 1072 | 4916 | acydburn | 'lang_name' => $this->vars['lang_name'], |
| 1073 | 4916 | acydburn | 'lang_explain' => $this->vars['lang_explain'], |
| 1074 | 4916 | acydburn | 'lang_id' => $default_lang_id, |
| 1075 | 4916 | acydburn | 'field_default_value' => $this->vars['field_default_value'], |
| 1076 | 4916 | acydburn | 'field_ident' => 'field_default_value', |
| 1077 | 4916 | acydburn | 'field_type' => FIELD_BOOL, |
| 1078 | 4916 | acydburn | 'field_length' => $this->vars['field_length'], |
| 1079 | 4916 | acydburn | 'lang_options' => $this->vars['lang_options'] |
| 1080 | 4740 | acydburn | ); |
| 1081 | 4740 | acydburn | |
| 1082 | 4740 | acydburn | $options = array( |
| 1083 | 7943 | kellanved | 0 => array('TITLE' => $user->lang['FIELD_TYPE'], 'EXPLAIN' => $user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<label><input type="radio" class="radio" name="field_length" value="1"' . (($this->vars['field_length'] == 1) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['RADIO_BUTTONS'] . '</label><label><input type="radio" class="radio" name="field_length" value="2"' . (($this->vars['field_length'] == 2) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['CHECKBOX'] . '</label>'), |
| 1084 | 5965 | acydburn | 1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)) |
| 1085 | 4740 | acydburn | ); |
| 1086 | 4740 | acydburn | |
| 1087 | 4740 | acydburn | return $options; |
| 1088 | 4740 | acydburn | } |
| 1089 | 4740 | acydburn | |
| 1090 | 5965 | acydburn | /**
|
| 1091 | 5965 | acydburn | * Get dropdown options for second step in ACP |
| 1092 | 5965 | acydburn | */ |
| 1093 | 4740 | acydburn | function get_dropdown_options() |
| 1094 | 4740 | acydburn | {
|
| 1095 | 4916 | acydburn | global $user, $config, $lang_defs; |
| 1096 | 4740 | acydburn | |
| 1097 | 4916 | acydburn | $default_lang_id = $lang_defs['iso'][$config['default_lang']]; |
| 1098 | 4740 | acydburn | |
| 1099 | 4740 | acydburn | $profile_row[0] = array( |
| 1100 | 4916 | acydburn | 'var_name' => 'field_default_value', |
| 1101 | 4916 | acydburn | 'field_id' => 1, |
| 1102 | 4916 | acydburn | 'lang_name' => $this->vars['lang_name'], |
| 1103 | 4916 | acydburn | 'lang_explain' => $this->vars['lang_explain'], |
| 1104 | 4916 | acydburn | 'lang_id' => $default_lang_id, |
| 1105 | 4916 | acydburn | 'field_default_value' => $this->vars['field_default_value'], |
| 1106 | 4916 | acydburn | 'field_ident' => 'field_default_value', |
| 1107 | 4916 | acydburn | 'field_type' => FIELD_DROPDOWN, |
| 1108 | 4916 | acydburn | 'lang_options' => $this->vars['lang_options'] |
| 1109 | 4740 | acydburn | ); |
| 1110 | 4740 | acydburn | |
| 1111 | 4740 | acydburn | $profile_row[1] = $profile_row[0]; |
| 1112 | 4984 | acydburn | $profile_row[1]['var_name'] = 'field_novalue'; |
| 1113 | 4984 | acydburn | $profile_row[1]['field_ident'] = 'field_novalue'; |
| 1114 | 4984 | acydburn | $profile_row[1]['field_default_value'] = $this->vars['field_novalue']; |
| 1115 | 4740 | acydburn | |
| 1116 | 4740 | acydburn | $options = array( |
| 1117 | 5965 | acydburn | 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])), |
| 1118 | 5965 | acydburn | 1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1])) |
| 1119 | 4740 | acydburn | ); |
| 1120 | 4740 | acydburn | |
| 1121 | 4740 | acydburn | return $options; |
| 1122 | 4740 | acydburn | } |
| 1123 | 4740 | acydburn | |
| 1124 | 5965 | acydburn | /**
|
| 1125 | 5965 | acydburn | * Get date options for second step in ACP |
| 1126 | 5965 | acydburn | */ |
| 1127 | 4740 | acydburn | function get_date_options() |
| 1128 | 4740 | acydburn | {
|
| 1129 | 4916 | acydburn | global $user, $config, $lang_defs; |
| 1130 | 4740 | acydburn | |
| 1131 | 4916 | acydburn | $default_lang_id = $lang_defs['iso'][$config['default_lang']]; |
| 1132 | 4740 | acydburn | |
| 1133 | 4740 | acydburn | $profile_row = array( |
| 1134 | 4916 | acydburn | 'var_name' => 'field_default_value', |
| 1135 | 4916 | acydburn | 'lang_name' => $this->vars['lang_name'], |
| 1136 | 4916 | acydburn | 'lang_explain' => $this->vars['lang_explain'], |
| 1137 | 4916 | acydburn | 'lang_id' => $default_lang_id, |
| 1138 | 4916 | acydburn | 'field_default_value' => $this->vars['field_default_value'], |
| 1139 | 4916 | acydburn | 'field_ident' => 'field_default_value', |
| 1140 | 4916 | acydburn | 'field_type' => FIELD_DATE, |
| 1141 | 4916 | acydburn | 'field_length' => $this->vars['field_length'] |
| 1142 | 4740 | acydburn | ); |
| 1143 | 4740 | acydburn | |
| 1144 | 8236 | kellanved | $always_now = request_var('always_now', -1); |
| 1145 | 8236 | kellanved | if ($always_now == -1) |
| 1146 | 8236 | kellanved | {
|
| 1147 | 8236 | kellanved | $s_checked = ($this->vars['field_default_value'] == 'now') ? true : false; |
| 1148 | 8236 | kellanved | } |
| 1149 | 8236 | kellanved | else
|
| 1150 | 8236 | kellanved | {
|
| 1151 | 8236 | kellanved | $s_checked = ($always_now) ? true : false; |
| 1152 | 8236 | kellanved | } |
| 1153 | 5965 | acydburn | |
| 1154 | 4740 | acydburn | $options = array( |
| 1155 | 5965 | acydburn | 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)), |
| 1156 | 7608 | acydburn | 1 => array('TITLE' => $user->lang['ALWAYS_TODAY'], 'FIELD' => '<label><input type="radio" class="radio" name="always_now" value="1"' . (($s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['YES'] . '</label><label><input type="radio" class="radio" name="always_now" value="0"' . ((!$s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['NO'] . '</label>'), |
| 1157 | 4740 | acydburn | ); |
| 1158 | 4740 | acydburn | |
| 1159 | 4740 | acydburn | return $options; |
| 1160 | 4740 | acydburn | } |
| 1161 | 4740 | acydburn | } |

