Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/functions_profile_fields.php

    r400 r702  
    33*
    44* @package phpBB3
    5 * @version $Id: functions_profile_fields.php 9127 2008-11-26 19:58:35Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    4040                {
    4141                        case 'register':
    42                                 // If the field is required we show it on the registration page and do not show hidden fields
    43                                 $sql_where .= ' AND f.field_show_on_reg = 1 AND f.field_no_view = 0';
     42                                // If the field is required we show it on the registration page
     43                                $sql_where .= ' AND f.field_show_on_reg = 1';
    4444                        break;
    4545
     
    9393                switch ($field_type)
    9494                {
    95                         case FIELD_INT:
    96                         case FIELD_DROPDOWN:
    97                                 $field_value = (int) $field_value;
    98                         break;
    99 
    100                         case FIELD_BOOL:
    101                                 $field_value = (bool) $field_value;
    102                         break;
    103                 }
    104 
    105                 switch ($field_type)
    106                 {
    10795                        case FIELD_DATE:
    10896                                $field_validate = explode('-', $field_value);
     
    134122
    135123                        case FIELD_BOOL:
     124                                $field_value = (bool) $field_value;
     125                       
    136126                                if (!$field_value && $field_data['field_required'])
    137127                                {
     
    141131
    142132                        case FIELD_INT:
    143                                 if (empty($field_value) && !$field_data['field_required'])
     133                                if (trim($field_value) === '' && !$field_data['field_required'])
    144134                                {
    145135                                        return false;
    146136                                }
     137                               
     138                                $field_value = (int) $field_value;
    147139
    148140                                if ($field_value < $field_data['field_minlen'])
     
    157149
    158150                        case FIELD_DROPDOWN:
     151                                $field_value = (int) $field_value;
     152                       
    159153                                if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
    160154                                {
     
    165159                        case FIELD_STRING:
    166160                        case FIELD_TEXT:
    167                                 if (empty($field_value) && !$field_data['field_required'])
     161                                if (trim($field_value) === '' && !$field_data['field_required'])
    168162                                {
    169163                                        return false;
    170164                                }
    171                                 else if (empty($field_value) && $field_data['field_required'])
     165                                else if (trim($field_value) === '' && $field_data['field_required'])
    172166                                {
    173167                                        return 'FIELD_REQUIRED';
     
    260254
    261255        /**
    262         * Submit profile field
     256        * Submit profile field for validation
    263257        * @access public
    264258        */
     
    271265                {
    272266                        case 'register':
    273                                 // If the field is required we show it on the registration page and do not show hidden fields
    274                                 $sql_where .= ' AND f.field_show_on_reg = 1 AND f.field_no_view = 0';
     267                                // If the field is required we show it on the registration page
     268                                $sql_where .= ' AND f.field_show_on_reg = 1';
    275269                        break;
    276270
     
    351345
    352346        /**
     347        * Update profile field data directly
     348        */
     349        function update_profile_field_data($user_id, &$cp_data)
     350        {
     351                global $db;
     352
     353                if (!sizeof($cp_data))
     354                {
     355                        return;
     356                }
     357
     358                switch ($db->sql_layer)
     359                {
     360                        case 'oracle':
     361                        case 'firebird':
     362                        case 'postgres':
     363                                $right_delim = $left_delim = '"';
     364                        break;
     365
     366                        case 'sqlite':
     367                        case 'mssql':
     368                        case 'mssql_odbc':
     369                                $right_delim = ']';
     370                                $left_delim = '[';
     371                        break;
     372
     373                        case 'mysql':
     374                        case 'mysql4':
     375                        case 'mysqli':
     376                                $right_delim = $left_delim = '`';
     377                        break;
     378                }
     379
     380                // use new array for the UPDATE; changes in the key do not affect the original array
     381                $cp_data_sql = array();
     382                foreach ($cp_data as $key => $value)
     383                {
     384                        // Firebird is case sensitive with delimiter
     385                        $cp_data_sql[$left_delim . (($db->sql_layer == 'firebird' || $db->sql_layer == 'oracle') ? strtoupper($key) : $key) . $right_delim] = $value;
     386                }
     387
     388                $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
     389                        SET ' . $db->sql_build_array('UPDATE', $cp_data_sql) . "
     390                        WHERE user_id = $user_id";
     391                $db->sql_query($sql);
     392
     393                if (!$db->sql_affectedrows())
     394                {
     395                        $cp_data_sql['user_id'] = (int) $user_id;
     396
     397                        $db->sql_return_on_error(true);
     398
     399                        $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data_sql);
     400                        $db->sql_query($sql);
     401
     402                        $db->sql_return_on_error(false);
     403                }
     404        }
     405
     406        /**
    353407        * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
    354408        * 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
     
    455509                {
    456510                        case 'int':
    457                                 if ($value == '')
     511                                if ($value === '')
    458512                                {
    459513                                        return NULL;
     
    571625                        else
    572626                        {
    573                                 if (!$preview && isset($user->profile_fields[$user_ident]) && is_null($user->profile_fields[$user_ident]))
     627                                if (!$preview && array_key_exists($user_ident, $user->profile_fields) && is_null($user->profile_fields[$user_ident]))
    574628                                {
    575629                                        $value = NULL;
     
    585639                        }
    586640
    587                         return (is_null($value)) ? '' : (int) $value;
     641                        return (is_null($value) || $value === '') ? '' : (int) $value;
    588642                }
    589643                else
Note: See TracChangeset for help on using the changeset viewer.